Summary: | many unaligned accesses in libgomp tests | ||
---|---|---|---|
Product: | gcc | Reporter: | Jay <jay.krell> |
Component: | libgomp | Assignee: | Rainer Orth <ro> |
Status: | RESOLVED FIXED | ||
Severity: | normal | CC: | gcc-bugs, jakub, ro |
Priority: | P3 | ||
Version: | 4.7.0 | ||
Target Milestone: | 4.7.0 | ||
URL: | http://gcc.gnu.org/ml/gcc-patches/2011-07/msg02162.html | ||
Host: | Target: | alphaev67-dec-osf5.1 | |
Build: | Known to work: | ||
Known to fail: | Last reconfirmed: | 2011-07-19 12:46:17 |
Description
Jay
2010-08-20 06:49:30 UTC
Can you possibly reduce one testcase? Confirmed, easy to see with uac p noprint nofix sigbus, i.e. unaligned accesses not fixed up, but instead generating SIGBUS. Will rebuild libgomp with -g3 -O0 to allow for debugging/investigation. I see what's happening now: the unaligned access is happending inside librt (sem_wait), with uac p noprint nofix sigbus: Program received signal SIGBUS, Bus error. [Switching to Thread 1] 0x000003ff81086c98 in sem_init () from /usr/shlib/librt.so (gdb) Erroneous arithmetic operation. (gdb) where #0 0x000003ff81086c98 in sem_init () from /usr/shlib/librt.so #1 0x000003ffbffefdec in gomp_sem_init (sem=0x3ffbfff02a0, value=536854016) at /vol/gcc/src/hg/trunk/local/libgomp/config/posix/sem.h:72 #2 0x000003ffbfff02a0 in gomp_init_task (task=0x14002bf00, parent_task=0x0, prev_icv=0x3ffffff0020) at /vol/gcc/src/hg/trunk/local/libgomp/task.c:45 #3 0x000003ffbfff1eb4 in gomp_team_start (fn=0x11fffe300, data=0x11fffe310, nthreads=536863560, team=0x11fffe358) at /vol/gcc/src/hg/trunk/local/libgomp/team.c:292 #4 0x000003ffbffef148 in GOMP_parallel_start ( fn=0x120002db4 <sub1._omp_fn.0>, data=0x11fffbfd0, num_threads=1) at /vol/gcc/src/hg/trunk/local/libgomp/parallel.c:108 #5 0x0000000120002cfc in sub1 (n=2) at /vol/gcc/src/hg/trunk/local/libgomp/testsuite/libgomp.c/appendix-a/a.15.1.c:30 #6 0x0000000120002d68 in main () at /vol/gcc/src/hg/trunk/local/libgomp/testsuite/libgomp.c/appendix-a/a.15.1.c:40 The actual unaligned access is one insn before: (gdb) x/i 0x3ff81086c94 0x3ff81086c94 <sem_init+308>: stl zero,0(s0) (gdb) p/x $s0 $17 = 0x14002bf5e Unaligned access pid=391884 <a.15.1.exe> va=0x14002bf5e pc=0x3ff81086c94 ra=0x3ff81086bf4 inst=0xb3e90000 And indeed *s0 isn't 4-byte aligned, as required by the stl insn. I could trace this as follows: * gomp_sem_t is sem_t (config/posix/sem.h) * sem_t is psx4_key_t (from <semaphore.h>) * psx4_key_t is defined in <psx4_nspace_ts.h>: typedef unsigned short psx4_key_version_t; typedef unsigned short psx4_key_index_t; typedef struct psx4_key { psx4_key_index_t index; /* Index of entry */ psx4_key_version_t version; /* Version number of key */ } psx4_key_t; Looking at the Tru64 UNIX V5.1 sources, I find (in src/usr/ccs/lib/librt/psx4_csem.c (sem_init)): int sem_init(sem_t *sem, int pshared, unsigned int value) [...] *(int *)sem = 0; i.e. the code assumes int (4-byte) alignment, but only gets short (2-byte) alignment instead. An appropriate attribute should fix this. Don't know how best to fit this into libgomp. Rainer Jakuk, what would be the best/least intrusive way to handle this target-specific gomp_sem_t alignment requirement? Rainer You mean that __alignof (sem_t) is 2, yet librt assumes it is 4 byte aligned? These proprietary OSes are of terrible quality. You could add config/osf/sem.h, which would be a copy of config/posix/sem.h, just gomp_sem_t would be typedef sem_t gomp_sem_t __attribute__((aligned (__alignof__ (int)))); or something similar, and in configury ensure that this directory is searched on these buggy OSes before config/posix/. > --- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-07-19 14:14:22 UTC --- > You mean that __alignof (sem_t) is 2, yet librt assumes it is 4 byte aligned? > These proprietary OSes are of terrible quality. Perhaps not in general, but this is clearly bullshit ;-) > You could add config/osf/sem.h, which would be a copy of config/posix/sem.h, > just gomp_sem_t would be typedef sem_t gomp_sem_t __attribute__((aligned > (__alignof__ (int)))); > or something similar, and in configury ensure that this directory is searched > on these buggy OSes before config/posix/. Ok, this is probably the least invasive way, especially since the HAVE_BROKEN_POSIX_SEMAPHORES part isn't needed and the file will be quite small. I'll try this. Thanks. Rainer Mine. Is there no annotation in /usr/include/whatever.h to get the required alignment? Maybe that gcc doesn't-but-maybe-should understand? - Jay (phone) On Jul 19, 2011, at 7:33 AM, "ro at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> wrote: > http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45351 > > Rainer Orth <ro at gcc dot gnu.org> changed: > > What |Removed |Added > ---------------------------------------------------------------------------- > Status|NEW |ASSIGNED > AssignedTo|unassigned at gcc dot |ro at gcc dot gnu.org > |gnu.org | > > --- Comment #7 from Rainer Orth <ro at gcc dot gnu.org> 2011-07-19 14:32:25 UTC --- > Mine. > > -- > Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email > ------- You are receiving this mail because: ------- > You reported the bug. > --- Comment #8 from Jay <jay.krell at cornell dot edu> 2011-07-19 15:15:46 UTC ---
> Is there no annotation in /usr/include/whatever.h to get the required
> alignment? Maybe that gcc doesn't-but-maybe-should understand?
No, the section I cited is all there is. No idea why this error doesn't
show up otherwise.
Rainer
>> Is there no annotation in /usr/include/whatever.h to get the required >> alignment? Maybe that gcc doesn't-but-maybe-should understand? > > No, the section I cited is all there is. No idea why this error doesn't > show up otherwise. Do struct alignment rules on Tru64 have an effect? Not that I looked-up/read the ABI details.. I'm not sure I have Tru64 access any longer (and my time/work/money-to-burn has dramatically declined, sorry, it was fun!) But I'd be curious what this does: #include something #include stddef.h int main() { typedef struct { char a; sem_t b; } t1; printf("%u %u\n", sizeof(t1), offsetof(t1, b)); return 0; } 5 or 6 or 8 or other? and 1 or 2 or 4 or other? If the alignment is really only 2, then I'd expect 6 and 2. If the alignment is somehow bumped up, then 8 and 4. The code cited does seem poor. Personally I'm a big fan of memset(p, 0, n) (or #define ZeroMemory(p, n)). - Jay > Do struct alignment rules on Tru64 have an effect? Not that I > looked-up/read the ABI details.. I had a look at `Calling Standard for Alpha Systems', and the rules seemed as expected and straight-forward. > But I'd be curious what this does: > > #include something > #include stddef.h > > > int main() > { > typedef struct { char a; sem_t b; } t1; > printf("%u %u\n", sizeof(t1), offsetof(t1, b)); > return 0; > } > > 5 or 6 or 8 or other? > and 1 or 2 or 4 or other? > If the alignment is really only 2, then I'd expect 6 and 2. This is what I get, with both cc and gcc. Rainer To make completely sure that this isn't a gcc problem of some sort, I've derived a testcase from libgomp. If built with cc -c99 or gcc, it shows the same unaligned access, so this is really just a silly librt bug, nothing else. Rainer Author: ro Date: Mon Jul 25 15:39:52 2011 New Revision: 176755 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=176755 Log: PR libgomp/45351 * config/osf/sem.h: New file. * configure.tgt (alpha*-dec-osf*): Prepend osf to config_path. Added: trunk/libgomp/config/osf/ trunk/libgomp/config/osf/sem.h Modified: trunk/libgomp/ChangeLog trunk/libgomp/configure.tgt Fixed for 4.7.0. |