Bug 45351 - many unaligned accesses in libgomp tests
Summary: many unaligned accesses in libgomp tests
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libgomp (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.7.0
Assignee: Rainer Orth
URL: http://gcc.gnu.org/ml/gcc-patches/201...
Keywords:
Depends on:
Blocks:
 
Reported: 2010-08-20 06:49 UTC by Jay
Modified: 2011-07-25 15:40 UTC (History)
3 users (show)

See Also:
Host:
Target: alphaev67-dec-osf5.1
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-07-19 12:46:17


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jay 2010-08-20 06:49:30 UTC
I'm not sure if all of these are within libgomp, definitely
some are, maybe all.

alphaev67-dec-osf5.1

		=== libgomp tests ===

Schedule of variations:
    unix

Running target unix
Using /home/jayk/share/dejagnu/baseboards/unix.exp as board description file for target.
Using /home/jayk/share/dejagnu/config/unix.exp as generic interface file for target.
Using /home/jayk/src/gcc-4.5.1/libgomp/testsuite/config/default.exp as tool-and-target-specific interface file.
Running /home/jayk/src/gcc-4.5.1/libgomp/testsuite/libgomp.c/c.exp ...
Unaligned access pid=152418 <a.15.1.exe> va=0x14000a35e pc=0x3ff80ba63d4 ra=0x3ff80ba63

... I removed all the pids and addresses and sort | uniq...

Unaligned access <a.15.1.exe>
Unaligned access <a.16.1.exe>
Unaligned access <a.18.1.exe>
Unaligned access <a.19.1.exe>
Unaligned access <a.2.1.exe>
Unaligned access <a.21.1.exe>
Unaligned access <a.22.7.exe>
Unaligned access <a.22.8.exe>
Unaligned access <a.26.1.exe>
Unaligned access <a.28.1.exe>
Unaligned access <a.28.2.exe>
Unaligned access <a.28.3.exe>
Unaligned access <a.28.4.exe>
Unaligned access <a.29.1.exe>
Unaligned access <a.31.4.exe>
Unaligned access <a.31.5.exe>
Unaligned access <a.36.1.exe>
Unaligned access <a.39.1.exe>
Unaligned access <a.4.1.exe>
Unaligned access <a.5.1.exe>
Unaligned access <a10.1.exe>
Unaligned access <allocatable1.exe>
Unaligned access <allocatable2.exe>
Unaligned access <allocatable3.exe>
Unaligned access <allocatable4.exe>
Unaligned access <allocatable5.exe>
Unaligned access <atomic-3.exe>
Unaligned access <atomic-4.exe>
Unaligned access <atomic-5.exe>
Unaligned access <barrier-1.exe>
Unaligned access <character1.exe>
Unaligned access <character2.exe>
Unaligned access <collapse-1.exe>
Unaligned access <collapse-2.exe>
Unaligned access <collapse-3.exe>
Unaligned access <collapse1.exe>
Unaligned access <collapse2.exe>
Unaligned access <collapse3.exe>
Unaligned access <collapse4.exe>
Unaligned access <copyin-1.exe>
Unaligned access <copyin-2.exe>
Unaligned access <copyin-3.exe>
Unaligned access <crayptr1.exe>
Unaligned access <crayptr2.exe>
Unaligned access <critical-1.exe>
Unaligned access <critical-2.exe>
Unaligned access <ctor-1.exe>
Unaligned access <ctor-10.exe>
Unaligned access <ctor-11.exe>
Unaligned access <ctor-12.exe>
Unaligned access <ctor-2.exe>
Unaligned access <ctor-3.exe>
Unaligned access <ctor-4.exe>
Unaligned access <ctor-5.exe>
Unaligned access <ctor-6.exe>
Unaligned access <ctor-7.exe>
Unaligned access <ctor-8.exe>
Unaligned access <ctor-9.exe>
Unaligned access <debug-1.exe>
Unaligned access <do1.exe>
Unaligned access <do2.exe>
Unaligned access <for-1.exe>
Unaligned access <for-2.exe>
Unaligned access <for-3.exe>
Unaligned access <for-4.exe>
Unaligned access <for-5.exe>
Unaligned access <for-6.exe>
Unaligned access <for-7.exe>
Unaligned access <for-8.exe>
Unaligned access <icv-1.exe>
Unaligned access <jacobi.exe>
Unaligned access <lastprivate1.exe>
Unaligned access <lastprivate2.exe>
Unaligned access <lib-1.exe>
Unaligned access <lib-2.exe>
Unaligned access <lib1.exe>
Unaligned access <lib2.exe>
Unaligned access <lib3.exe>
Unaligned access <lib4.exe>
Unaligned access <lock-1.exe>
Unaligned access <lock-2.exe>
Unaligned access <loop-1.exe>
Unaligned access <loop-10.exe>
Unaligned access <loop-11.exe>
Unaligned access <loop-12.exe>
Unaligned access <loop-2.exe>
Unaligned access <loop-3.exe>
Unaligned access <loop-4.exe>
Unaligned access <loop-5.exe>
Unaligned access <loop-6.exe>
Unaligned access <loop-7.exe>
Unaligned access <loop-8.exe>
Unaligned access <loop-9.exe>
Unaligned access <master-1.exe>
Unaligned access <nested-1.exe>
Unaligned access <nested-2.exe>
Unaligned access <nested-3.exe>
Unaligned access <nested1.exe>
Unaligned access <nestedfn-1.exe>
Unaligned access <nestedfn-3.exe>
Unaligned access <nestedfn-4.exe>
Unaligned access <nestedfn-5.exe>
Unaligned access <nestedfn-6.exe>
Unaligned access <nestedfn1.exe>
Unaligned access <nestedfn2.exe>
Unaligned access <nestedfn3.exe>
Unaligned access <nestedfn4.exe>
Unaligned access <nqueens-1.exe>
Unaligned access <omp-loop01.exe>
Unaligned access <omp-loop02.exe>
Unaligned access <omp-loop03.exe>
Unaligned access <omp-nested-1.exe>
Unaligned access <omp-parallel-for>
Unaligned access <omp-parallel-if.>
Unaligned access <omp-single-1.exe>
Unaligned access <omp-single-2.exe>
Unaligned access <omp-single-3.exe>
Unaligned access <omp_hello.exe>
Unaligned access <omp_matvec.exe>
Unaligned access <omp_orphan.exe>
Unaligned access <omp_parse1.exe>
Unaligned access <omp_parse2.exe>
Unaligned access <omp_parse3.exe>
Unaligned access <omp_parse4.exe>
Unaligned access <omp_reduction.ex>
Unaligned access <omp_workshare1.e>
Unaligned access <omp_workshare2.e>
Unaligned access <omp_workshare4.e>
Unaligned access <ordered-1.exe>
Unaligned access <ordered-2.exe>
Unaligned access <ordered-3.exe>
Unaligned access <parallel-1.exe>
Unaligned access <pr24455.exe>
Unaligned access <pr25162.exe>
Unaligned access <pr25219.exe>
Unaligned access <pr26691.exe>
Unaligned access <pr26943-1.exe>
Unaligned access <pr26943-2.exe>
Unaligned access <pr26943-3.exe>
Unaligned access <pr26943-4.exe>
Unaligned access <pr26943.exe>
Unaligned access <pr27337.exe>
Unaligned access <pr27395-1.exe>
Unaligned access <pr27395-2.exe>
Unaligned access <pr27416-1.exe>
Unaligned access <pr27916-1.exe>
Unaligned access <pr27916-2.exe>
Unaligned access <pr28390.exe>
Unaligned access <pr29629.exe>
Unaligned access <pr29947-1.exe>
Unaligned access <pr29947-2.exe>
Unaligned access <pr30494.exe>
Unaligned access <pr30703.exe>
Unaligned access <pr32362-1.exe>
Unaligned access <pr32362-2.exe>
Unaligned access <pr32362-3.exe>
Unaligned access <pr32468.exe>
Unaligned access <pr32550.exe>
Unaligned access <pr33880.exe>
Unaligned access <pr34020.exe>
Unaligned access <pr34513.exe>
Unaligned access <pr35130.exe>
Unaligned access <pr35185.exe>
Unaligned access <pr35196.exe>
Unaligned access <pr35549.exe>
Unaligned access <pr35625.exe>
Unaligned access <pr36802-1.exe>
Unaligned access <pr36802-2.exe>
Unaligned access <pr36802-3.exe>
Unaligned access <pr38650.exe>
Unaligned access <pr39573.exe>
Unaligned access <pr39591-1.exe>
Unaligned access <pr39591-2.exe>
Unaligned access <pr39591-3.exe>
Unaligned access <pr42029.exe>
Unaligned access <pr42162.exe>
Unaligned access <pr42942.exe>
Unaligned access <pr43893.exe>
Unaligned access <private-1.exe>
Unaligned access <recursion1.exe>
Unaligned access <reduction-1.exe>
Unaligned access <reduction-2.exe>
Unaligned access <reduction-3.exe>
Unaligned access <reduction-4.exe>
Unaligned access <reduction-5.exe>
Unaligned access <reduction1.exe>
Unaligned access <reduction2.exe>
Unaligned access <reduction3.exe>
Unaligned access <reduction4.exe>
Unaligned access <reduction5.exe>
Unaligned access <reduction6.exe>
Unaligned access <reference1.exe>
Unaligned access <reference2.exe>
Unaligned access <retval1.exe>
Unaligned access <retval2.exe>
Unaligned access <sections-1.exe>
Unaligned access <shared-1.exe>
Unaligned access <shared-2.exe>
Unaligned access <shared-3.exe>
Unaligned access <sharing1.exe>
Unaligned access <sharing2.exe>
Unaligned access <single-1.exe>
Unaligned access <single-2.exe>
Unaligned access <single-3.exe>
Unaligned access <sort-1.exe>
Unaligned access <stack.exe>
Unaligned access <strassen.exe>
Unaligned access <task-1.exe>
Unaligned access <task-2.exe>
Unaligned access <task-3.exe>
Unaligned access <task-4.exe>
Unaligned access <task-5.exe>
Unaligned access <task-6.exe>
Unaligned access <task-7.exe>
Unaligned access <task1.exe>
Unaligned access <task2.exe>
Unaligned access <threadprivate1.e>
Unaligned access <threadprivate2.e>
Unaligned access <threadprivate3.e>
Unaligned access <vla-1.exe>
Unaligned access <vla1.exe>
Unaligned access <vla2.exe>
Unaligned access <vla3.exe>
Unaligned access <vla4.exe>
Unaligned access <vla5.exe>
Unaligned access <vla6.exe>
Unaligned access <vla7.exe>
Unaligned access <vla8.exe>
Unaligned access <workshare1.exe>
Unaligned access <workshare2.exe>
Comment 1 Richard Biener 2010-08-23 20:20:40 UTC
Can you possibly reduce one testcase?
Comment 2 Rainer Orth 2011-07-19 12:46:17 UTC
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.
Comment 3 ro@CeBiTec.Uni-Bielefeld.DE 2011-07-19 13:57:43 UTC
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
Comment 4 Rainer Orth 2011-07-19 13:59:22 UTC
Jakuk, what would be the best/least intrusive way to handle this target-specific
gomp_sem_t alignment requirement?

  Rainer
Comment 5 Jakub Jelinek 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.
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 6 ro@CeBiTec.Uni-Bielefeld.DE 2011-07-19 14:29:04 UTC
> --- 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
Comment 7 Rainer Orth 2011-07-19 14:32:25 UTC
Mine.
Comment 8 Jay 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?

 - 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 9 ro@CeBiTec.Uni-Bielefeld.DE 2011-07-19 15:23:47 UTC
> --- 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
Comment 10 Jay 2011-07-19 15:58:04 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.


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
Comment 11 ro@CeBiTec.Uni-Bielefeld.DE 2011-07-19 16:57:00 UTC
> 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
Comment 12 ro@CeBiTec.Uni-Bielefeld.DE 2011-07-22 17:04:33 UTC
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
Comment 13 Rainer Orth 2011-07-25 15:39:58 UTC
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
Comment 14 Rainer Orth 2011-07-25 15:40:44 UTC
Fixed for 4.7.0.