[gold]new test script_test_12 is broken

Jing Yu jingyu@google.com
Thu Jun 11 00:14:00 GMT 2015


Hi Cary,

The new gold test script_test_12 is broken on some x86_64 machines.
The reason is that the test assumes sections are placed by compiler in
the same order as they appear in the source file. However it is not
true.

For example, on my x86_64 machine, with gcc (version 4.8.2) -O2,
sections .x1, .x2, .x3 are in placed in a reverse order.
$gcc -O2 script_test_12a.c -c -o /tmp/script_test_12a.o
$readelf -S /tmp/script_test_12a.o
...
  [ 6] .x3               PROGBITS         0000000000000000  00000090
       0000000000000010  0000000000000000  WA       0     0     16
  [ 7] .x2               PROGBITS         0000000000000000  000000a0
       0000000000000010  0000000000000000  WA       0     0     16
  [ 8] .x1               PROGBITS         0000000000000000  000000b0
       0000000000000010  0000000000000000  WA       0     0     16

Therefore, after linking with script script_test_12.t, the resulting
contents in .test are
.x3
.x2
.x1
.x3
.x2
.x1
The test breaks.

The linker does the right job. And the compiler is also doing right
because we don't tell it to keep the order of .x1 .x2 .x3. I think we
should fix the test itself.

I am thinking of adding "-O0" to Makefile for this test (it uses -O2
by default on my box). gcc -O0 is supposed not to do any optimization
and should keep the order.
$gcc -O0 script_test_12a.c -c -o /tmp/script_test_12a.o
$readelf -S /tmp/script_test_12a.o
...
  [ 5] .x1               PROGBITS         0000000000000000  000000b0
       0000000000000010  0000000000000000  WA       0     0     16
  [ 6] .x2               PROGBITS         0000000000000000  000000c0
       0000000000000010  0000000000000000  WA       0     0     16
  [ 7] .x3               PROGBITS         0000000000000000  000000d0
       0000000000000010  0000000000000000  WA       0     0     16

The patch is attached.
I tested the patch on my machine. All gold tests pass. What do you think?

Thanks,
Jing
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.patch
Type: text/x-patch
Size: 1815 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20150611/eb787976/attachment.bin>


More information about the Binutils mailing list