segfaults on amd64
Hi! I made a 64 bit glibc build and it seems to have some trouble: [EMAIL PROTECTED] cat test.c main () { printf ("hello\n"); exit (56); } [EMAIL PROTECTED] 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' [EMAIL PROTECTED] ./test hello Segmentation fault (core dumped) [EMAIL PROTECTED] 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. 0x005bdc00 in ?? () (gdb) bt #0 0x005bdc00 in ?? () #1 0x0040098d in exit (status=56) at exit.c:60 #2 0x0040028c 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": [EMAIL PROTECTED] cp test.c test0.c [EMAIL PROTECTED] 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' [EMAIL PROTECTED] ./test0 Segmentation fault (core dumped) I suppose it's because of increased argv[0]? I'm totaly puzzled. -- Robert Millan -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: segfaults on amd64
Hi! > I made a 64 bit glibc build and it seems to have some trouble: Please could you: - add headers/prototypes for printf, exit - try it under ktrace - try "make -k check" in glibc build Petr -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: segfaults on amd64
On Sat, Feb 25, 2006 at 09:39:19AM +0100, Petr Salinger wrote: > Hi! > > > I made a 64 bit glibc build and it seems to have some trouble: > > Please could you: > > - add headers/prototypes for printf, exit This revealed some breakage in my headers due to a mistake during manual install and patching. I fixed it, but it isn't related to this bug. > - try it under ktrace Quite interesting, with ktrace it gets SIGILL instead of SIGSEV. (exit is a program that just calls exit function) 76573 ktrace RET ktrace 0 76573 ktrace CALL execve(0x7fffe9ef,0x7fffe828,0x7fffe838) 76573 ktrace NAMI "./exit" 76573 exit RET execve 0 76573 exit CALL break(0x574088) 76573 exit RET break 0 76573 exit CALL sysarch(0x81,0x7fffe7a0) 76573 exit RET sysarch 0 76573 exit CALL geteuid 76573 exit RET geteuid 1001/0x3e9 76573 exit CALL getuid 76573 exit RET getuid 1001/0x3e9 76573 exit CALL getegid 76573 exit RET getegid 1001/0x3e9 76573 exit CALL getgid 76573 exit RET getgid 1001/0x3e9 76573 exit CALL __sysctl(0x7fffe730,0x2,0x572f88,0x7fffe728,0,0) 76573 exit RET __sysctl 0 76573 exit CALL break(0x595088) 76573 exit RET break 0 76573 exit CALL break(0x596000) 76573 exit RET break 0 76573 exit PSIG SIGILL SIG_DFL 76573 exit NAMI "exit.core" I wonder where is the code doing all this. Suposedly the fault is after the malloc() that brings in these brk()s ? I'm using binutils 2.16.1 and gcc 4.0.2 btw. > - try "make -k check" in glibc build I need to fix a bug in binutils for that to work. Will send the info later. -- Robert Millan -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: segfaults on amd64
Don't ask me why, but it seems that fixing the problem in binutils (see my last commit, binutils_elfosabi.diff) solved the segfaults. I got hello.c to work now. -- Robert Millan -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
r1250 - trunk/web/patches
Author: rmh Date: 2006-02-25 14:44:01 + (Sat, 25 Feb 2006) New Revision: 1250 Added: trunk/web/patches/binutils_elfosabi.diff Log: Add binutils_elfosabi.diff Added: trunk/web/patches/binutils_elfosabi.diff === --- trunk/web/patches/binutils_elfosabi.diff2006-02-24 22:57:31 UTC (rev 1249) +++ trunk/web/patches/binutils_elfosabi.diff2006-02-25 14:44:01 UTC (rev 1250) @@ -0,0 +1,16 @@ + +Obtained from FreeBSD (src/contrib/binutils). Without this, upstream binutils +don't work on non-i386 (they set ELFOSABI_SYSV). + +diff -ur binutils-2.16.1cvs20060117.old/bfd/elf.c binutils-2.16.1cvs20060117/bfd/elf.c +--- binutils-2.16.1cvs20060117.old/bfd/elf.c 2006-01-18 03:02:37.0 +0100 binutils-2.16.1cvs20060117/bfd/elf.c 2006-02-25 15:39:28.0 +0100 +@@ -4802,6 +4802,8 @@ + bfd_big_endian (abfd) ? ELFDATA2MSB : ELFDATA2LSB; + i_ehdrp->e_ident[EI_VERSION] = bed->s->ev_current; + ++ i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_FREEBSD; ++ + if ((abfd->flags & DYNAMIC) != 0) + i_ehdrp->e_type = ET_DYN; + else if ((abfd->flags & EXEC_P) != 0) -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: segfaults on amd64
On Sat, Feb 25, 2006 at 03:56:42PM +0100, Robert Millan wrote: > > Don't ask me why, but it seems that fixing the problem in binutils (see my > last > commit, binutils_elfosabi.diff) solved the segfaults. > > I got hello.c to work now. There, it came back. I think to summarise, the problem is: - When strlen(argv[0]) <= 6, it works fine. - When strlen(argv[0]) > 6: - If the executable is dynamicaly linked, runs as if it were ld.so. - If static, segfaults (SIGILL if you run in ktrace). Test example: [EMAIL PROTECTED]:/tmp$ ./test argc = 1 argv[0] = ./test [EMAIL PROTECTED]:/tmp$ /tmp/test Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...] You have invoked `ld.so', the helper program for shared library executables. [...] I suspect it has something to do with missing changes that freebsd didn't push into upstream binutils. -- Robert Millan -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: segfaults on amd64
On Sat, Feb 25, 2006 at 04:45:04PM +0100, Robert Millan wrote: > Test example: > > [EMAIL PROTECTED]:/tmp$ ./test > argc = 1 > argv[0] = ./test > [EMAIL PROTECTED]:/tmp$ /tmp/test > Usage: ld.so [OPTION]... EXECUTABLE-FILE [ARGS-FOR-PROGRAM...] > You have invoked `ld.so', the helper program for shared library executables. > [...] Uhm that might be explained by ld.so being allocated in 0x0. Sounds like a repetition of #336496. Was this a problem in kernel, libc, binutils...? [EMAIL PROTECTED]:/tmp$ /lib/ld-kfreebsd-x86-64.so.1 --list /tmp//h libc.so.0.1 => /gnu/lib/libc.so.0.1 (0x000800117000) /lib64/ld-kfreebsd-x86-64.so.1 => /lib/ld-kfreebsd-x86-64.so.1 (0x) -- Robert Millan -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: segfaults on amd64
> Uhm that might be explained by ld.so being allocated in 0x0. Sounds like a > repetition of #336496. Was this a problem in kernel, libc, binutils...? > > [EMAIL PROTECTED]:/tmp$ /lib/ld-kfreebsd-x86-64.so.1 --list /tmp//h > libc.so.0.1 => /gnu/lib/libc.so.0.1 (0x000800117000) > /lib64/ld-kfreebsd-x86-64.so.1 => /lib/ld-kfreebsd-x86-64.so.1 > (0x) The bug is fixed only partially, it is still in kernel, now it affect only DYN object, EXEC are (on kfreebsd-i386) mapped correctly. Can you, please, test also following: #include #include char buf[4096]; int main() { int fd, cnt; fd = open("/proc/self/maps", O_RDONLY); cnt = read(fd, buf, 4096); write(1, buf, cnt); _exit(123); } Thanks for your work on amd64. Petr -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]