From: Kristian V. <kri...@xe...> - 2004-11-10 13:47:39
|
I'm currently testing Glibc 2.3.3, and as part of that I am trying to rebuild Gcc 3.3.4 against the new libs. I've run into a problem which is now beginning to look like a bug with Glibc 2.3.3, but I'm totally stumped. I've got it down to the following testcase: #include <stdlib.h> #include <stdio.h> FILE *y; int main( int argc, char *argv[] ) { FILE *x; printf("x\n"); x = fopen(argv[0],"r"); fclose(x); printf("x closed\n"); if( NULL == y ) { printf("y is NULL\n"); return EXIT_FAILURE; } printf("y\n"); y = fopen(argv[0],"r"); fclose(y); printf("y closed\n"); return EXIT_SUCCESS; } Output is: $ ./fopen x x closed y Segmentation fault (core dumped) $ If you're paying attention, it actually crashes when it gets the the if( NULL == y ) with a NULL pointer: 0:fopen::fopen : Invalid pagefault at 00000000 (NOTP:READ:USER) 0:fopen::fopen : EAX = 00000000 : EBX = 8000185c : ECX = 00000009 : EDX = a00e4aa0 0:fopen::fopen : ESI = 00000001 : EDI = ffffbb2c : EBP = ffffbaac 0:fopen::fopen : SS::ESP = 0023::ffffba90 0:fopen::fopen : CS::EIP = 0013::800006b5 0:fopen::fopen : DS = 0023 : ES = 0023 : FS = 0023 : GS = 00d0 0:fopen::fopen : EFLAGS = 00213286 (PF SF IF RF ID ) 0:fopen::fopen : CPU ID = 0 : kernel stack = 051c5014 0:fopen::fopen : 0 -> 800006b5 0:fopen::fopen : fopen + 000006b5 -> __gmon_start__ + 800006b5 0:fopen::fopen : 1 -> a00143e1 0:fopen::fopen : libc.so.2 + 000143e1 -> __libc_start_main + 000000a1 0:fopen::fopen : 2 -> 80000435 0:fopen::fopen : fopen + 00000435 -> __gmon_start__ + 80000435 0:fopen::fopen : verify_area() got kernel address 00000000 0:fopen::fopen : 0:fopen::fopen : Areas : 0:fopen::fopen : Area 0000 (10239) -> 80000000-80000fff 04ca7cd8 01 ro_fopen 0:fopen::fopen : Area 0001 (10240) -> 80001000-80001fff 04ca7cd8 01 rw_fopen 0:fopen::fopen : Area 0002 (10244) -> 88000000-88022fff 00000000 01 heap 0:fopen::fopen : Area 0003 (10241) -> a0000000-a00e3fff 04ca7ad8 01 ro_libc.so.2 0:fopen::fopen : Area 0004 (10242) -> a00e4000-a00eafff 04ca7ad8 01 rw_libc.so.2 0:fopen::fopen : Area 0005 (10243) -> ffc00000-ffffffff 00000000 01 main_stack 0:fopen::fopen : 0 -> 800006b5 0:fopen::fopen : fopen + 000006b5 -> __gmon_start__ + 800006b5 0:fopen::fopen : 1 -> a00143e1 0:fopen::fopen : libc.so.2 + 000143e1 -> __libc_start_main + 000000a1 0:fopen::fopen : 2 -> 80000435 0:fopen::fopen : fopen + 00000435 -> __gmon_start__ + 80000435 0:fopen::fopen : verify_area() got kernel address 00000000 0:fopen::fopen : Killed by signal 11 Through experimentation I've found: o If the declaration of y is moved inside main() it works. o If y is declared as static FILE *y, it works. This is what is causing me so much trouble; the scope of the variable is relevent to the bug. I could understand it if the crash was being caused when fopen() tries to assign the value to y, but it crashes *whenever the code goes anywhere near y*. This, of course, is impossible. At least, it is highly improbable. I need a linker/asm guru fast. Can anyone explain why the scope of the variable would have any relevence, and how it could cause this? -- Vanders http://www.syllable.org http://www.liqwyd.com _____________________________________________________________________ This message has been checked for all known viruses by Xenicom delivered through the MessageLabs Virus Control Centre. |