public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/41475]  New: common variables cannot be expected to be aligned
@ 2009-09-26  4:04 mikulas at artax dot karlin dot mff dot cuni dot cz
  2009-09-26  4:05 ` [Bug middle-end/41475] " mikulas at artax dot karlin dot mff dot cuni dot cz
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: mikulas at artax dot karlin dot mff dot cuni dot cz @ 2009-09-26  4:04 UTC (permalink / raw)
  To: gcc-bugs

Hi.

When I compile these two sources, one with -O3 -march=pentium3 and the other
with -Os, the linker warns about nonmatching alignments and the program crashes
because of misaligned SSE accesses.

/usr/bin/ld: Warning: alignment 4 of symbol `array' in commonalign2.o is
smaller than 32 in commonalign1.o
/usr/bin/ld: Warning: alignment 4 of symbol `array2' in commonalign2.o is
smaller than 32 in commonalign1.o

The reson is that gcc aligns arrays in common section to 32 bytes and expects
that they will be aligned so. This expectation is wrong, the common entries may
be resolved pointing to data section in another module that doesn't meet the
alignment (it may be compiled with different compiler or with the same compiler
with different flags (-Os)).

For extern arrays, gcc correctly assumes that they are aligned to their ABI
standard (4 bytes) and generates appropriate SSE code; for common arrays it
should expect 4-byte alignment too.


-- 
           Summary: common variables cannot be expected to be aligned
           Product: gcc
           Version: 4.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: mikulas at artax dot karlin dot mff dot cuni dot cz
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41475


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug middle-end/41475] common variables cannot be expected to be aligned
  2009-09-26  4:04 [Bug middle-end/41475] New: common variables cannot be expected to be aligned mikulas at artax dot karlin dot mff dot cuni dot cz
@ 2009-09-26  4:05 ` mikulas at artax dot karlin dot mff dot cuni dot cz
  2009-09-26  4:06 ` mikulas at artax dot karlin dot mff dot cuni dot cz
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mikulas at artax dot karlin dot mff dot cuni dot cz @ 2009-09-26  4:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from mikulas at artax dot karlin dot mff dot cuni dot cz  2009-09-26 04:05 -------
Created an attachment (id=18653)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18653&action=view)
the first file

The first file of a two-file program. Compile with gcc -c -O3 -march=pentium3.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41475


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug middle-end/41475] common variables cannot be expected to be aligned
  2009-09-26  4:04 [Bug middle-end/41475] New: common variables cannot be expected to be aligned mikulas at artax dot karlin dot mff dot cuni dot cz
  2009-09-26  4:05 ` [Bug middle-end/41475] " mikulas at artax dot karlin dot mff dot cuni dot cz
@ 2009-09-26  4:06 ` mikulas at artax dot karlin dot mff dot cuni dot cz
  2009-09-26  4:14 ` mikulas at artax dot karlin dot mff dot cuni dot cz
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mikulas at artax dot karlin dot mff dot cuni dot cz @ 2009-09-26  4:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from mikulas at artax dot karlin dot mff dot cuni dot cz  2009-09-26 04:06 -------
Created an attachment (id=18654)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18654&action=view)
the second file

The second file. Compile with gcc -c -Os. Then, link both object files together
and run it.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41475


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug middle-end/41475] common variables cannot be expected to be aligned
  2009-09-26  4:04 [Bug middle-end/41475] New: common variables cannot be expected to be aligned mikulas at artax dot karlin dot mff dot cuni dot cz
  2009-09-26  4:05 ` [Bug middle-end/41475] " mikulas at artax dot karlin dot mff dot cuni dot cz
  2009-09-26  4:06 ` mikulas at artax dot karlin dot mff dot cuni dot cz
@ 2009-09-26  4:14 ` mikulas at artax dot karlin dot mff dot cuni dot cz
  2009-09-26 11:24 ` rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mikulas at artax dot karlin dot mff dot cuni dot cz @ 2009-09-26  4:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from mikulas at artax dot karlin dot mff dot cuni dot cz  2009-09-26 04:14 -------
BTW. this bug is in both gcc 4.3 and 4.4


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41475


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug middle-end/41475] common variables cannot be expected to be aligned
  2009-09-26  4:04 [Bug middle-end/41475] New: common variables cannot be expected to be aligned mikulas at artax dot karlin dot mff dot cuni dot cz
                   ` (2 preceding siblings ...)
  2009-09-26  4:14 ` mikulas at artax dot karlin dot mff dot cuni dot cz
@ 2009-09-26 11:24 ` rguenth at gcc dot gnu dot org
  2009-09-26 14:14 ` hjl dot tools at gmail dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-09-26 11:24 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2009-09-26 11:23 -------
Isn't this a linker issue in that it doesn't use the biggest alignment?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41475


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug middle-end/41475] common variables cannot be expected to be aligned
  2009-09-26  4:04 [Bug middle-end/41475] New: common variables cannot be expected to be aligned mikulas at artax dot karlin dot mff dot cuni dot cz
                   ` (3 preceding siblings ...)
  2009-09-26 11:24 ` rguenth at gcc dot gnu dot org
@ 2009-09-26 14:14 ` hjl dot tools at gmail dot com
  2009-09-26 14:38 ` rguenth at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: hjl dot tools at gmail dot com @ 2009-09-26 14:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from hjl dot tools at gmail dot com  2009-09-26 14:14 -------
(In reply to comment #4)
> Isn't this a linker issue in that it doesn't use the biggest alignment?
> 

Linker can't change alignment on non-common symbols. I think it is wrong
to give a different alignment for the same symbol in different files.


-- 

hjl dot tools at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hjl dot tools at gmail dot
                   |                            |com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41475


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug middle-end/41475] common variables cannot be expected to be aligned
  2009-09-26  4:04 [Bug middle-end/41475] New: common variables cannot be expected to be aligned mikulas at artax dot karlin dot mff dot cuni dot cz
                   ` (4 preceding siblings ...)
  2009-09-26 14:14 ` hjl dot tools at gmail dot com
@ 2009-09-26 14:38 ` rguenth at gcc dot gnu dot org
  2009-09-26 15:27 ` mikulas at artax dot karlin dot mff dot cuni dot cz
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-09-26 14:38 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from rguenth at gcc dot gnu dot org  2009-09-26 14:37 -------
The bug is about common symbols.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41475


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug middle-end/41475] common variables cannot be expected to be aligned
  2009-09-26  4:04 [Bug middle-end/41475] New: common variables cannot be expected to be aligned mikulas at artax dot karlin dot mff dot cuni dot cz
                   ` (5 preceding siblings ...)
  2009-09-26 14:38 ` rguenth at gcc dot gnu dot org
@ 2009-09-26 15:27 ` mikulas at artax dot karlin dot mff dot cuni dot cz
  2009-09-26 19:30 ` pinskia at gcc dot gnu dot org
  2009-09-27  9:51 ` mikulas at artax dot karlin dot mff dot cuni dot cz
  8 siblings, 0 replies; 10+ messages in thread
From: mikulas at artax dot karlin dot mff dot cuni dot cz @ 2009-09-26 15:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from mikulas at artax dot karlin dot mff dot cuni dot cz  2009-09-26 15:27 -------
Richard Guenther: the bug caused by common symbol (in file commonalign1.o) with
the same name as data section symbol (in file commonalign2.o). In this case,
the linker redirects the common symbol to the symbol in the data section. But
the linker cannot change the content of the data section, so it cannot make
both symbols array and array2 aligned. Linker is innocent in this and giving a
warning is the best thing it can do.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41475


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug middle-end/41475] common variables cannot be expected to be aligned
  2009-09-26  4:04 [Bug middle-end/41475] New: common variables cannot be expected to be aligned mikulas at artax dot karlin dot mff dot cuni dot cz
                   ` (6 preceding siblings ...)
  2009-09-26 15:27 ` mikulas at artax dot karlin dot mff dot cuni dot cz
@ 2009-09-26 19:30 ` pinskia at gcc dot gnu dot org
  2009-09-27  9:51 ` mikulas at artax dot karlin dot mff dot cuni dot cz
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2009-09-26 19:30 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from pinskia at gcc dot gnu dot org  2009-09-26 19:29 -------
This code is undefined I think (and really it is not valid C90/C99 code).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41475


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug middle-end/41475] common variables cannot be expected to be aligned
  2009-09-26  4:04 [Bug middle-end/41475] New: common variables cannot be expected to be aligned mikulas at artax dot karlin dot mff dot cuni dot cz
                   ` (7 preceding siblings ...)
  2009-09-26 19:30 ` pinskia at gcc dot gnu dot org
@ 2009-09-27  9:51 ` mikulas at artax dot karlin dot mff dot cuni dot cz
  8 siblings, 0 replies; 10+ messages in thread
From: mikulas at artax dot karlin dot mff dot cuni dot cz @ 2009-09-27  9:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from mikulas at artax dot karlin dot mff dot cuni dot cz  2009-09-27 09:51 -------
The common linker definitions were made to exactly to make code like this work
and share the array between two object.

So if you think it is undefined, don't support it (make -fno-common default and
remove -fcommon at all). Or, if you want to support it, support it correctly.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41475


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-09-27  9:51 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-26  4:04 [Bug middle-end/41475] New: common variables cannot be expected to be aligned mikulas at artax dot karlin dot mff dot cuni dot cz
2009-09-26  4:05 ` [Bug middle-end/41475] " mikulas at artax dot karlin dot mff dot cuni dot cz
2009-09-26  4:06 ` mikulas at artax dot karlin dot mff dot cuni dot cz
2009-09-26  4:14 ` mikulas at artax dot karlin dot mff dot cuni dot cz
2009-09-26 11:24 ` rguenth at gcc dot gnu dot org
2009-09-26 14:14 ` hjl dot tools at gmail dot com
2009-09-26 14:38 ` rguenth at gcc dot gnu dot org
2009-09-26 15:27 ` mikulas at artax dot karlin dot mff dot cuni dot cz
2009-09-26 19:30 ` pinskia at gcc dot gnu dot org
2009-09-27  9:51 ` mikulas at artax dot karlin dot mff dot cuni dot cz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).