Created attachment 6987 [details] Testcase We see a failure when building the ppc64 Linux kernel. We require __ftr_alt sections to be placed directly after the object's text section and have the following in our linker script: .text : { *(.text __ftr_alt_*) } The __ftr_alt sections contain instructions that we relocate and copy over the kernel as a part of our runtime patching code. On the bfd linker this works, but on gold all the __ftr_alt sections are placed at the end of the text section. When this happens conditional branches cannot be relocated and the kernel panics. The attached testcase shows this behaviour, ld.bfd behaves as expected by ld.gold fails: # ./testcase test: file format elf64-powerpc Disassembly of section .text: 0000000000000000 <_start>: 0: 60 21 00 01 ori r1,r1,1 4: 60 42 00 02 ori r2,r2,2 8: 60 63 00 03 ori r3,r3,3 c: 60 84 00 04 ori r4,r4,4 10: 60 a5 00 05 ori r5,r5,5 14: 60 c6 00 06 ori r6,r6,6 test: file format elf64-powerpc Disassembly of section .text: 0000000000000024 <_start>: 24: 60 21 00 01 ori r1,r1,1 28: 60 42 00 02 ori r2,r2,2 2c: 60 84 00 04 ori r4,r4,4 30: 60 a5 00 05 ori r5,r5,5 34: 60 63 00 03 ori r3,r3,3 38: 60 c6 00 06 ori r6,r6,6
Gold apparently doesn't make a distinction between *(.text .rdata) and *(.text) *(.rdata). See node Input Section Basics in the ld info docs. Looks to me like Output_section_element_input::set_section_addresses() is the culprit, but I'm going on vacation so will leave it to someone else to fix. ;-)
The master branch has been updated by Cary Coutant <ccoutant@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=374082dfab280123f5a54a23b1c1b2cb893b4d2b commit 374082dfab280123f5a54a23b1c1b2cb893b4d2b Author: Cary Coutant <ccoutant@gmail.com> Date: Wed Jun 3 19:11:42 2015 -0700 Fix gold to group sections correctly via linker script. In PR 15370, it is noted that gold does not distinguish between "*(.foo .bar)" and "*(.foo) *(.bar)" in linker scripts. In both cases, gold groups all .foo sections together, followed by all .bar sections, whereas in the first case, it should collect all .foo and .bar sections in the order seen. If you add sort specs, the Gnu linker has some bizarre corner cases that I do not try to replicate. In particular, "*(SORT_BY_NAME(.foo) SORT_BY_NAME(.bar))" does the same thing as "*(.foo) *(.bar)". But if you apply a sort spec to just one of several patterns, say, "*(SORT_BY_NAME(.foo) .bar)", the Gnu linker will collect any .bar section it sees before the first .foo, then all .foo sections, then all remaining .bar sections. With this patch, if any of the input patterns have a sort spec, gold will group them all as it did before; e.g., all .foo sections followed by all .bar sections. 2015-06-03 Cary Coutant <ccoutant@gmail.com> gold/ PR gold/15370 * script-sections.cc (Output_section_element_input::set_section_addresses): When there are several patterns with no sort spec, put all sections in the same bin. * testsuite/Makefile.am (script_test_12): New testcase. (script_test_12i): New testcase. * testsuite/Makefile.in: Regenerate. * testsuite/script_test_12.t: New test linker script. * testsuite/script_test_12i.t: New test linker script. * testsuite/script_test_12a.c: New test source file. * testsuite/script_test_12b.c: New test source file.
Fixed on trunk.
Thanks Cary, with your fix I was able to boot a ppc64el kernel built with gold.
The master branch has been updated by Cary Coutant <ccoutant@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=3ca25b560af813ca576821b500a0f0885829b500 commit 3ca25b560af813ca576821b500a0f0885829b500 Author: Cary Coutant <ccoutant@gmail.com> Date: Thu Jun 23 09:45:25 2016 -0700 Fix bug with grouping sections. The fix for PR 15370 did not correctly check all patterns in a group, but instead threw all unassigned sections into the group. This patch fixes that. 2016-06-23 Cary Coutant <ccoutant@gmail.com> Igor Kudrin <ikudrin@accesssoftek.com> gold/ PR gold/15370 * script-sections.cc (Output_section_element_input::set_section_addresses): Keep bin_count separate from input_pattern_count. * testsuite/script_test_12.t: Add another section .x4. * testsuite/script_test_12i.t: Likewise. * testsuite/script_test_12a.c: Likewise. * testsuite/script_test_12b.c: Likewise.