From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: fee84,c639e73bdad25695,start X-Google-Attributes: gidfee84,public From: Andrew Gentles Subject: unaligned access with added confusion Date: 1997/07/02 Message-ID: <33BA769A.41C6@evol.nott.ac.uk>#1/1 X-Deja-AN: 254144995 Organization: Cripps Computing Centre, The University of Nottingham Newsgroups: comp.unix.osf.osf1 I'm having problems with an unaligned access error, followed by a segmentation fault. I followed the suggestions in the Digital FAQ to track down the error, and ended up with the useful information that it was occuring outside of my program. In fact, after some poking about it seems that the problem is connected with libc.so. (If I generate a call tree and machine code, the memory location at which the segmentation fault occurs seems to be attached to libc.so) Running under dbx produced the following : --------------------------------------------------------------- evol$ dbx common dbx version 3.11.8 Type 'help' for help. main: 582 opts = (struct nm_opts *) malloc(sizeof(struct nm_opts)); db>run Completed 10910 noncoding sequences Unaligned access pid=29969 va=14010222c pc=3ff8104c308 ra=3ff8104d760 type=ldq Unaligned access pid=29969 va=14010222c pc=3ff8104c350 ra=3ff8104d760 type=stq Unaligned access pid=29969 va=140102234 pc=3ff8104c354 ra=3ff8104d760 type=ldq Unaligned access pid=29969 va=14010223c pc=3ff8104c358 ra=3ff8104d760 type=ldq signal Segmentation fault at >*[(unknown), 0x3ff8104c178] ldq r0, 0(r16) db>where where > 0 (unknown)(0x11ffff2ee, 0x3ffc0084070, 0x102, 0x3ff00000000, 0x11ffff2c8) [0x3ff8104c178] 1 (unknown)(0x1e000, 0x1, 0x140122000, 0x3ffc00840c0, 0x0) [0x3ff8104c360] 2 free(0x3ff8105a48c, 0x0, 0x3ff8104d904, 0x0, 0x0) [0x3ff8104d75c] 3 (unknown)(0x2010, 0x10, 0x3ff8000f038, 0x140140000, 0x0) [0x3ff8104d970] 4 malloc(0x2, 0x3ffc1000360, 0x140023eb0, 0x11ffff608, 0x140069e00) [0x3ff8104de80] 5 _findbuf(0x487033ba539d, 0x487033ba539d, 0xf35000002000, 0x80e900000000, 0x3ff00002000) [0x3ff81066078] 6 __filbuf(0x3ff8105b4b4, 0x3ffc1000360, 0x2, 0x4f, 0x140023eb0) [0x3ff81061ec4] 7 fgets(0x140023eb0, 0x140022540, 0x3ffc1000360, 0x1, 0x11ffff608) [0x3ff8105b4b0] 8 seq_read_entry(pf = 0x3ffc1000360, seq_entry = 0x14000df80 = "") ["common.c":108, 0x120002144] 9 learn(opts = 0x140002220) ["common.c":395, 0x120003058] 10 ntuple_menu(opts = 0x140002220) ["common.c":559, 0x120003ad8] 11 main(argc = 1, argv = 0x11ffff8c8) ["common.c":586, 0x120003b88] db> ------------------------------------------------------------ from this it seems the culprit is a call to fgets, and is the first read from a newly opened file. This all happens under DU 3.2c with the Digital C compiler, but I have also checked on DU 3.2d and 4.0, also with gcc v 2.7.2 and get the same results. Irritatingly, I get no problems if I compile and run under Solaris 2.x or SunOS 4.1.3 or HP-UX with either cc or gcc. I don't seem to be able to generate any errors at compile time with any of the compilers. Does anyone have any suggestions for narrowing down the problem ? Andrew