在memcmp意外的段错误 [英] Unexpected segfault in memcmp

查看:2187
本文介绍了在memcmp意外的段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面这个简单的程序出现segfaults对我来说:

The following simple program segfaults for me:

#include <string.h>
int main()
{
    void* voidp = NULL;
    char zeroes[sizeof(void*)];
    memset(zeroes, 0, sizeof(void*));
    int res = memcmp(&voidp, zeroes, sizeof(void*));
    return 0;
}

调试器揭示了段错误是在memcmp。

The debugger reveals the segfault is in the memcmp.

我的机器是运行64位的Ubuntu 8.04,gcc版本4.2.4是

My machine is running 64-bit Ubuntu 8.04, gcc version is 4.2.4.

它可以运行在其他机器罚款,我试过(32位或64位)。

It runs fine on other machines that I've tried (both 32-bit or 64-bit).

任何想法,这是怎么回事?

Any ideas as to what is going on?

更新:这是大会code:

UPDATE: Here's the assembly code:

    .file   "failed.c"
    .text
.globl main
    .type   main, @function
main:
.LFB2:
    pushq   %rbp
.LCFI0:
    movq    %rsp, %rbp
.LCFI1:
    subq    $32, %rsp
.LCFI2:
    movq    %fs:40, %rax
    movq    %rax, -8(%rbp)
    xorl    %eax, %eax
    movq    $0, -32(%rbp)
    leaq    -16(%rbp), %rdi
    movl    $8, %edx
    movl    $0, %esi
    call    memset
    leaq    -16(%rbp), %rsi
    leaq    -32(%rbp), %rdi
    movl    $8, %edx
    call    memcmp
    movl    %eax, -20(%rbp)
    movl    $0, %eax
    movq    -8(%rbp), %rdx
    xorq    %fs:40, %rdx
    je  .L3
    call    __stack_chk_fail
.L3:
    leave
    ret
.LFE2:
    .size   main, .-main
    .section    .eh_frame,"a",@progbits
.Lframe1:
    .long   .LECIE1-.LSCIE1
.LSCIE1:
    .long   0x0
    .byte   0x1
    .string "zR"
    .uleb128 0x1
    .sleb128 -8
    .byte   0x10
    .uleb128 0x1
    .byte   0x3
    .byte   0xc
    .uleb128 0x7
    .uleb128 0x8
    .byte   0x90
    .uleb128 0x1
    .align 8
.LECIE1:
.LSFDE1:
    .long   .LEFDE1-.LASFDE1
.LASFDE1:
    .long   .LASFDE1-.Lframe1
    .long   .LFB2
    .long   .LFE2-.LFB2
    .uleb128 0x0
    .byte   0x4
    .long   .LCFI0-.LFB2
    .byte   0xe
    .uleb128 0x10
    .byte   0x86
    .uleb128 0x2
    .byte   0x4
    .long   .LCFI1-.LCFI0
    .byte   0xd
    .uleb128 0x6
    .align 8
.LEFDE1:
    .ident  "GCC: (GNU) 4.2.4 (Ubuntu 4.2.4-1ubuntu4)"
    .section    .note.GNU-stack,"",@progbits

更新:(这应该是一个评论,但不适合于600个字符)。当我尝试命令和apt-get安装libc6的,我得到:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
libc6 is already the newest version.
You might want to run `apt-get -f install' to correct these:
The following packages have unmet dependencies:
  libc6: Depends: libc-bin (= 2.11.1-0ubuntu7.5) but it is not installable
         Depends: findutils (>= 4.4.0-2ubuntu2) but 4.2.32-1ubuntu2 is to be installed
  libc6-dev: Depends: libc6 (= 2.7-10ubuntu5) but 2.11.1-0ubuntu7.5 is to be installed
  libc6-i386: Depends: libc6 (= 2.7-10ubuntu5) but 2.11.1-0ubuntu7.5 is to be installed
  locales: Depends: belocs-locales-bin (>= 2.4-2.2ubuntu2) but it is not going to be installed
  locales-all: Depends: glibc-2.11-1 but it is not installable
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

最后,如果我尝试做 sudo易于得到-f安装,我得到:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
libc6 is already the newest version.
You might want to run `apt-get -f install' to correct these:
The following packages have unmet dependencies:
  libc6: Depends: libc-bin (= 2.11.1-0ubuntu7.5) but it is not installable
         Depends: findutils (>= 4.4.0-2ubuntu2) but 4.2.32-1ubuntu2 is to be installed
  libc6-dev: Depends: libc6 (= 2.7-10ubuntu5) but 2.11.1-0ubuntu7.5 is to be installed
  libc6-i386: Depends: libc6 (= 2.7-10ubuntu5) but 2.11.1-0ubuntu7.5 is to be installed
  locales: Depends: belocs-locales-bin (>= 2.4-2.2ubuntu2) but it is not going to be installed
  locales-all: Depends: glibc-2.11-1 but it is not installable
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
botond@adaptive1:~$ sudo apt-get -f install
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Correcting dependencies... Done
The following packages were automatically installed and are no longer required:
  vim-runtime linux-libc-dev mysql-common openssh-blacklist
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  libdns35
The following packages will be REMOVED:
  adduser apparmor apparmor-utils apt apt-file apt-utils aptitude at atop base-files base-passwd bash bash-completion bind9-host binutils bsdmainutils bsdutils bzip2 command-not-found
  console-setup console-terminus console-tools coreutils cpio cpp cpp-4.2 cron curl dash debconf debconf-i18n debianutils dhcp3-client dhcp3-common diff dmidecode dmsetup dnsutils dosfstools dpkg
  e2fslibs e2fsprogs ed eject ethtool fdutils file findutils friendly-recovery ftp fuse-utils g++ g++-4.2 g++-4.2-multilib gcc gcc-4.2 gcc-4.2-multilib gdb-minimal gettext-base gnupg gpgv grep
  groff-base grub gzip hdparm hostname ifupdown info initramfs-tools initscripts inputattach iproute iptables iputils-arping iputils-ping iputils-tracepath klogd laptop-detect less lib32gcc1
  lib32gomp1 lib32stdc++6 libacl1 libapr1 libaprutil1 libapt-pkg-perl libatm1 libattr1 libbind9-30 libblkid1 libboost-dev libbz2-1.0 libc6 libc6-dev libc6-dev-i386 libc6-i386 libcap1
  libck-connector0 libcomerr2 libconfig-file-perl libconsole libcurl3 libcurl3-gnutls libcwidget3 libdb-dev libdb4.6 libdb4.6++ libdb4.6++-dev libdb4.6-dev libdbd-mysql-perl libdbi-perl
  libdbus-1-3 libdevmapper1.02.1 libedit2 libelfg0 libexpat1 libfribidi0 libfuse2 libgc1c2 libgcc1 libgcrypt11 libgdbm3 libglib2.0-0 libgnutls13 libgomp1 libgpg-error0 libgpmg1
  libhtml-parser-perl libhtml-tagset-perl libhtml-tree-perl libidn11 libisc35 libisccc30 libisccfg30 libiw29 libkeyutils1 libkrb53 libldap-2.4-2 liblist-moreutils-perl liblocale-gettext-perl
  liblwres30 liblzo2-2 libmagic1 libmysqlclient15off libncurses5 libncursesw5 libneon27 libnet-daemon-perl libnewt0.52 libntfs-3g23 libopencdk10 libpam-modules libpam0g libparted1.7-1 libpcap0.8
  libpcre3 libplrpc-perl libpopt0 libpq5 libreadline5 libreadline6 librpc-xml-perl libsasl2-2 libsasl2-modules libselinux1 libsepol1 libsigc++-2.0-0c2a libslang2 libsqlite3-0 libss2 libssl0.9.8
  libstdc++6 libstdc++6-4.2-dev libsvn1 libsysfs2 libtasn1-3 libterm-readkey-perl libtext-charwidth-perl libtext-iconv-perl libtext-wrapi18n-perl liburi-perl libusb-0.1-4 libuuid1 libvolume-id0
  libwrap0 libwww-perl libx11-6 libx11-data libxau6 libxcb-xlib0 libxcb1 libxdmcp6 libxext6 libxml-parser-perl libxml2 libxmuu1 linux-image-2.6.24-23-server linux-image-server linux-server
  linux-ubuntu-modules-2.6.24-23-server locales locales-all login logrotate lsb-base lsb-release lshw lsof ltrace lvm2 lzma make makedev man-db mawk menu mii-diag mktemp mlocate module-init-tools
  mount mtr-tiny mysql-client-5.0 mysql-server mysql-server-5.0 nano ncurses-base ncurses-bin net-tools netbase netcat netcat-traditional ntfs-3g ntp ntpdate openssh-client openssh-server parted
  passwd pciutils pcmciautils perl perl-base perl-modules popularity-contest ppp pppconfig pppoeconf procps psmisc python python-apt python-central python-cxx python-cxx-dev python-dev
  python-gdbm python-gnupginterface python-minimal python-mysqldb python-pkg-resources python-pycurl python-setuptools python-simplejson python-support python2.5 python2.5-dev python2.5-minimal
  reiserfsprogs rsync screen sed sshfs startup-tasks strace subversion sudo sysklogd system-services sysvutils tar tasksel tasksel-data tcpd tcpdump telnet time tzdata ubuntu-keyring
  ubuntu-minimal ubuntu-standard ucf udev ufw update-inetd update-manager-core upstart upstart-compat-sysv upstart-logd usbutils util-linux util-linux-locales uuid-runtime valgrind vim vim-common
  vim-tiny w3m wget whiptail wireless-tools wpasupplicant x11-common xauth zlib1g
The following packages will be upgraded:
  libdns35
WARNING: The following essential packages will be removed.
This should NOT be done unless you know exactly what you are doing!
  apt libc6 (due to apt) libgcc1 (due to apt) libstdc++6 (due to apt) base-files base-passwd (due to base-files) libpam-modules (due to base-files) bash debianutils (due to bash) libncurses5 (due
  to bash) bsdutils coreutils libacl1 (due to coreutils) libselinux1 (due to coreutils) dash mktemp (due to debianutils) diff dpkg lzma (due to dpkg) e2fsprogs e2fslibs (due to e2fsprogs)
  libblkid1 (due to e2fsprogs) libcomerr2 (due to e2fsprogs) libss2 (due to e2fsprogs) libuuid1 (due to e2fsprogs) findutils grep gzip hostname login libpam0g (due to login) mount ncurses-base
  ncurses-bin perl-base python-minimal python2.5-minimal (due to python-minimal) sed sysvutils libsepol1 (due to sysvutils) tar util-linux lsb-base (due to util-linux) tzdata (due to util-linux)
  libslang2 (due to util-linux) zlib1g (due to util-linux)
1 upgraded, 0 newly installed, 316 to remove and 4 not upgraded.
4 not fully installed or removed.
Need to get 11.3kB of archives.
After this operation, 712MB disk space will be freed.
You are about to do something potentially harmful.
To continue type in the phrase 'Yes, do as I say!'
 ?] 

很显然,我没有键入是的,照我说的!看来事情是真的搞砸了......任何想法如何解决?

Obviously, I didn't type "Yes, do as I say!". It seems something is really screwed up... any idea how to fix it?

推荐答案

我可以肯定,RHEL 5上使用GCC 4.1.2,在code正常工作,同时支持32位和64位(AMD的x86 / 64架构)。

I can affirm that on RHEL 5 with GCC 4.1.2, the code works fine, both 32-bit and 64-bit (AMD x86/64 architecture).

您已经(可能)发现了一个错误。

You've (probably) found a bug.

也许你应该升级到GCC 4.5.2(发布在过去24个小时左右 - 为2010-12-19)。或者,也许你需要升级C库,但这更可能是比库的问题编译器问题。

Maybe you should upgrade to GCC 4.5.2 (released in the last 24 hours or so - as of 2010-12-19). Or maybe you need to upgrade the C library, but this is more likely to be a compiler issue than a library issue.

这篇关于在memcmp意外的段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆