This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
[gold]new test script_test_12 is broken
- From: Jing Yu <jingyu at google dot com>
- To: binutils <binutils at sourceware dot org>, Cary Coutant <ccoutant at google dot com>
- Date: Wed, 10 Jun 2015 17:14:24 -0700
- Subject: [gold]new test script_test_12 is broken
- Authentication-results: sourceware.org; auth=none
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
diff --git a/gold/testsuite/Makefile.am b/gold/testsuite/Makefile.am
index 0ae99bd..7669f27 100644
--- a/gold/testsuite/Makefile.am
+++ b/gold/testsuite/Makefile.am
@@ -1669,6 +1669,10 @@ script_test_12: gcctestdir/ld $(srcdir)/script_test_12.t script_test_12a.o scrip
check_PROGRAMS += script_test_12i
script_test_12i: gcctestdir/ld $(srcdir)/script_test_12i.t script_test_12a.o script_test_12b.o
$(LINK) -Bgcctestdir/ -Wl,-T,$(srcdir)/script_test_12i.t script_test_12a.o script_test_12b.o
+script_test_12a.o: script_test_12a.c
+ $(COMPILE) -O0 -c -o $@ $<
+script_test_12b.o: script_test_12b.c
+ $(COMPILE) -O0 -c -o $@ $<
# Test --dynamic-list, --dynamic-list-data, --dynamic-list-cpp-new,
# and --dynamic-list-cpp-typeinfo
diff --git a/gold/testsuite/Makefile.in b/gold/testsuite/Makefile.in
index 5228650..3f8818d 100644
--- a/gold/testsuite/Makefile.in
+++ b/gold/testsuite/Makefile.in
@@ -5659,6 +5659,10 @@ uninstall-am:
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -Wl,-T,$(srcdir)/script_test_12.t script_test_12a.o script_test_12b.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_12i: gcctestdir/ld $(srcdir)/script_test_12i.t script_test_12a.o script_test_12b.o
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(LINK) -Bgcctestdir/ -Wl,-T,$(srcdir)/script_test_12i.t script_test_12a.o script_test_12b.o
+@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_12a.o: script_test_12a.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -O0 -c -o $@ $<
+@GCC_TRUE@@NATIVE_LINKER_TRUE@script_test_12b.o: script_test_12b.c
+@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(COMPILE) -O0 -c -o $@ $<
@GCC_TRUE@@NATIVE_LINKER_TRUE@dynamic_list: basic_test.o gcctestdir/ld $(srcdir)/dynamic_list.t
@GCC_TRUE@@NATIVE_LINKER_TRUE@ $(CXXLINK) -Bgcctestdir/ basic_test.o \
@GCC_TRUE@@NATIVE_LINKER_TRUE@ -Wl,--dynamic-list $(srcdir)/dynamic_list.t \