segfaults on amd64

Robert Millan rmh at aybabtu.com
Sat Feb 25 08:14:58 UTC 2006


Hi!

I made a 64 bit glibc build and it seems to have some trouble:

rmh at orthanc$ cat test.c
main ()
{
  printf ("hello\n");
  exit (56);
}
rmh at orthanc$ amd64-kfreebsd-gnu-gcc test.c -g -o test -static ; brandelf -t FreeBSD test
test.c: In function 'main':
test.c:3: warning: incompatible implicit declaration of built-in function 'printf'
test.c:4: warning: incompatible implicit declaration of built-in function 'exit'
rmh at orthanc$ ./test
hello
Segmentation fault (core dumped)
rmh at orthanc$ gdb ./test
GNU gdb 6.1.1 [FreeBSD]
Copyright 2004 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "amd64-marcel-freebsd"...
(gdb) r
Starting program: /tmp/test
hello

Program received signal SIGSEGV, Segmentation fault.
0x00000000005bdc00 in ?? ()
(gdb) bt
#0  0x00000000005bdc00 in ?? ()
#1  0x000000000040098d in exit (status=56) at exit.c:60
#2  0x000000000040028c in main () at test.c:4
(gdb)

exit.c:60 reads:

            case ef_cxa:
              (*f->func.cxa.fn) (f->func.cxa.arg, status);
              break;

Now running this with a breakpoint (before the stack is fubarred):

Breakpoint 1, exit (status=56) at exit.c:60
60                    (*f->func.cxa.fn) (f->func.cxa.arg, status);
(gdb) p f->func.cxa.fn
$1 = (void (*)(void *, int)) 0x400860 <__libc_csu_fini>
(gdb) p f->func.cxa.arg
$2 = (void *) 0x0

0x400860 is indeed the beginning of __libc_csu_fini, but that NULL looks broken.
Could that be the problem?

Besides, when I added one char to the name, it doesn't get to print "hello":

rmh at orthanc$ cp test.c test0.c
rmh at orthanc$ amd64-kfreebsd-gnu-gcc test0.c -g -o test0 -static ; brandelf -t FreeBSD test0
test0.c: In function 'main':
test0.c:3: warning: incompatible implicit declaration of built-in function 'printf'
test0.c:4: warning: incompatible implicit declaration of built-in function 'exit'
rmh at orthanc$ ./test0
Segmentation fault (core dumped)

I suppose it's because of increased argv[0]?  I'm totaly puzzled.

-- 
Robert Millan



More information about the Glibc-bsd-devel mailing list