Bug 927573
Summary: | [RFE] ld.gold fails to recognize some commands in linker script. | ||||||
---|---|---|---|---|---|---|---|
Product: | Red Hat Developer Toolset | Reporter: | J.H.M. Dassen (Ray) <rdassen> | ||||
Component: | binutils | Assignee: | Nick Clifton <nickc> | ||||
Status: | CLOSED WONTFIX | QA Contact: | Martin Cermak <mcermak> | ||||
Severity: | medium | Docs Contact: | |||||
Priority: | medium | ||||||
Version: | DTS 1.1 RHEL 5 | CC: | bhubbard, ismail, law, mcermak, mnewsome, mpolacek, pbhoot, rbinkhor | ||||
Target Milestone: | alpha | Keywords: | FutureFeature | ||||
Target Release: | 8.0 | ||||||
Hardware: | All | ||||||
OS: | Mac OS | ||||||
Whiteboard: | |||||||
Fixed In Version: | Doc Type: | Enhancement | |||||
Doc Text: | Story Points: | --- | |||||
Clone Of: | Environment: | ||||||
Last Closed: | 2018-06-19 16:02:50 UTC | Type: | Bug | ||||
Regression: | --- | Mount Type: | --- | ||||
Documentation: | --- | CRM: | |||||
Verified Versions: | Category: | --- | |||||
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||
Cloudforms Team: | --- | Target Upstream Version: | |||||
Embargoed: | |||||||
Attachments: |
|
Fails on F18 as well. $ ld -v GNU gold (version 2.23.51.0.1-6.fc18 20120806) 1.11 $ g++ -Wl,--script=./fail.lds -Wl,-v a.c collect2 version 4.7.2 20121109 (Red Hat 4.7.2-8) /usr/bin/ld --build-id --no-add-needed --eh-frame-hdr --hash-style=gnu -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/crt1.o /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/crti.o /usr/lib/gcc/x86_64-redhat-linux/4.7.2/crtbegin.o -L/usr/lib/gcc/x86_64-redhat-linux/4.7.2 -L/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../.. --script=./fail.lds -v /tmp/ccFivrrT.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-redhat-linux/4.7.2/crtend.o /usr/lib/gcc/x86_64-redhat-linux/4.7.2/../../../../lib64/crtn.o /usr/bin/ld: error: ./fail.lds:6:8: syntax error, unexpected STRING /usr/bin/ld: fatal error: unable to parse script file ./fail.lds collect2: error: ld returned 1 exit status The INSERT command was added to the BFD linker a few years ago, but no corresponding support was added to the gold linker. The INSERT command was designed to make it easier to augment the default linker script; gold, to the best of my knowledge, does not have a default linker script, so the INSERT command may not make sense for gold. I've opened an upstream bug report to get this clarified. I looked at the BFD linker's code to support INPUT and as far as I can tell it'd have to be completely rewritten to work with gold. The earliest this would likely get addressed would be DTS 3.0 (assuming upstream agrees that INPUT has value for a gold linker script). FWIW Apple's swift on Linux uses this functionality in its linker script and fails with gold as expected. (In reply to İsmail Dönmez from comment #14) It would be helpful to have some more examples of how the INSERT linker script directive is being used. That said, it is unlikely that the GOLD linker will ever support the INSERT directive. The reason being that GOLD does not have a default linker script, and so there is nothing into which script fragments can be INSERTed. Note - the decision not to have a default linker script is a fundamental part of the design of GOLD and it is not going to change. There are a couple of possible workarounds: * Use a full linker script. Instead of trying to insert fragments into a non-existent script, create a full script, with all of the extra symbols, alignments and other things as needed. You can start with the default linker script built in the BFD linker (viewable via the "ld.bfd --verbose" command), and then add in the extra bits you need. This solution has the added benefit that you can be sure that exactly the same section layout will be used by GOLD and LD. * Use object files instead of script fragments. For example the Reproducer script supplied as an example for this BZ attempts to insert two fragments into the linker script: SECTIONS { . = ALIGN(0x2000); PROVIDE_HIDDEN(__text_begin = .); } INSERT BEFORE .text SECTIONS { . = ALIGN(0x2000); PROVIDE_HIDDEN(__text_end = .); } INSERT AFTER .text This functionality could be replicated by creating two small assembly files: % cat before.s .text .align 0x2000 .global __text_begin .hidden __text_begin __text_begin: % cat after.s .text .align 0x2000 .global __text_end .hidden __text_end __text_end: and then including them in link stage as the first and last object files respectively. This is the method recommended by the GOLD developers. Cheers Nick Nick, thanks for your comments & example. FWIW here is what Swift uses atm: λ cat stdlib/public/runtime/swift.ld SECTIONS { .swift2_protocol_conformances : { .swift2_protocol_conformances_start = . ; QUAD(SIZEOF(.swift2_protocol_conformances) - 8) ; *(.swift2_protocol_conformances) ; } } INSERT AFTER .dtors (In reply to İsmail Dönmez from comment #16) Assuming that it is not really essential that the .swift2_protocol_conformances section immediately follows the .dtors section, (and that it is OK for GOLD to place it where it thinks is best) then something like this might work: % cat swift_start.s .section .swift2_protocol_conformances, "awx",@fini_array .global .swift2_protocol_conformances_start .swift2_protocol_conformances_start: .quad (.swift2_protocol_conformances_end - .swift2_protocol_conformances_start) - 8 % cat swift_end.s .section .swift2_protocol_conformances, "awx",@fini_array .global .swift2_protocol_conformances_end .swift2_protocol_conformances_end: and then link in swift_start.o before any swift-containing object files and swift_end.o after all swift-containing object files. Untested of course, but worth investigating maybe ? Development Management has reviewed and declined this request. You may appeal this decision by reopening this request. |
Created attachment 716384 [details] Reproducer script Description of problem: ld.gold fails to recognize some commands in linker script. (while good with ld.bfd) Version-Release number of selected component (if applicable): devtoolset-1.1-binutils-2.23.51.0.3-3.el5 How reproducible: 100% Steps to Reproduce: Refer to attached reproducer script. Actual results: [ray@rhel5 ~]$ ./reproducer + echo 'Testing ld.bfd (default):' Testing ld.bfd (default): + sudo ln -sf /opt/rh/devtoolset-1.1/root/usr/bin/ld.bfd /opt/rh/devtoolset-1.1/root/etc/alternatives/ld + ls -l /opt/rh/devtoolset-1.1/root/etc/alternatives/ld lrwxrwxrwx 1 root root 42 Mar 26 10:12 /opt/rh/devtoolset-1.1/root/etc/alternatives/ld -> /opt/rh/devtoolset-1.1/root/usr/bin/ld.bfd + /opt/rh/devtoolset-1.1/root/usr/bin/g++ -Wl,--script=./fail.lds a.c + echo 'Testing ld.gold (default):' Testing ld.gold (default): + sudo ln -sf /opt/rh/devtoolset-1.1/root/usr/bin/ld.gold /opt/rh/devtoolset-1.1/root/etc/alternatives/ld + /opt/rh/devtoolset-1.1/root/usr/bin/g++ -Wl,--script=./fail.lds a.c /opt/rh/devtoolset-1.1/root/usr/libexec/gcc/x86_64-redhat-linux/4.7.2/ld: error: ./fail.lds:6:8: syntax error, unexpected STRING /opt/rh/devtoolset-1.1/root/usr/libexec/gcc/x86_64-redhat-linux/4.7.2/ld: fatal error: unable to parse script file ./fail.lds collect2: error: ld returned 1 exit status + sudo ln -sf /opt/rh/devtoolset-1.1/root/usr/bin/ld.bfd /opt/rh/devtoolset-1.1/root/etc/alternatives/ld Expected results: No linker error when using ld.gold