[Bug target/81333] New: Bad alignment of global variables on Alpha

mikulas at artax dot karlin.mff.cuni.cz gcc-bugzilla@gcc.gnu.org
Thu Jul 6 00:18:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81333

            Bug ID: 81333
           Summary: Bad alignment of global variables on Alpha
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mikulas at artax dot karlin.mff.cuni.cz
  Target Milestone: ---
              Host: alpha-linux-gnu
            Target: alpha-linux-gnu
             Build: alpha-linux-gnu

Created attachment 41690
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41690&action=edit
A testcase that triggers the bug

The first version of the Alpha architecture doesn't have instructions that can
read or write 1-byte or 2-byte values in memory. When we need to write 1-byte
or 2-byte value, the compiler generates code that reads 8 bytes, modifies a
single byte or two bytes and writes 8 bytes.

GCC packs multiple global byte variables into the same 8-byte area. When we
spawn multiple threads and each thread modifies its own variable, the threads
may end up reading and writing the same 8-byte area, resulting in race
condition and data corruption.

Note that according to the C standard any variable can be accessed through a
char * pointer, thus, to avoid the race condition, all global and static
variables should be aligned on 8-byte boundary.


More information about the Gcc-bugs mailing list