This is an archive of the discontinued LLVM Phabricator instance.

LinkerScript: Add -T <scriptfile> option
ClosedPublic

Authored by meadori on Mar 7 2015, 10:59 AM.

Details

Reviewers
meadori
Group Reviewers
lld
Summary

GNU LD has an option named -T/--script which allows a user to specify
a linker script to be used [1]. LLD already accepts linker scripts
without this option, but the option is widely used. Therefore it is
best to support it in LLD as well.

[1] https://sourceware.org/binutils/docs-2.25/ld/Options.html#Options

Diff Detail

Event Timeline

meadori updated this revision to Diff 21424.Mar 7 2015, 10:59 AM
meadori retitled this revision from to LinkerScript: Add -T <scriptfile> option.
meadori updated this object.
meadori edited the test plan for this revision. (Show Details)
meadori added a reviewer: lld.
meadori added a project: lld.
meadori added a subscriber: Unknown Object (MLST).
davide added a subscriber: davide.Mar 7 2015, 11:32 AM
davide added inline comments.
lib/Driver/GnuLdOptions.td
262

is 'defm' a valid keyword in python?
Why are you not following the convention for the other options?

davide added inline comments.Mar 7 2015, 11:40 AM
lib/Driver/GnuLdOptions.td
262

OK, you can use defm here, apparently.

This is the tablegen language, not Python :)

http://llvm.org/docs/TableGen/

I'm curious about why is "-T" being handled here as an alias for "-l". "-T" is exclusive for linker scripts and cannot accept any other input files.

Actually, currently, lld does handle -T, but in a weird way. "-T" is not recognized, thus it generates a warning, but then the parameter to "-T" is handled as a regular input and eventually gets parsed as a regular linker script.

Currently there is no difference between a script that overrides the "default linker script" and one that does not, but we need this for the future (well, mostly producing an error if the linker script contains special commands that are reserved for either the default linker script or the script that replaces it).

I'm curious about why is "-T" being handled here as an alias for "-l". "-T" is exclusive for linker scripts and cannot
accept any other input files.

That is an oversight on my part. I will fix it on a later revision. After taking a more detailed look at the expected
behavior of -l and -T I see where we have a related bug with -l. The following will find 'test.ls':

lld -flavor gnu -target x86_64  -ltest.ls

This is due to how we implement findFile in GnuLdDriver.cpp.
However, the colon form should work (assuming the script is in the find path
it will append to the default script):

lld -flavor gnu -target x86_64  -l:test.ls

Actually, currently, lld does handle -T, but in a weird way. "-T" is not recognized, thus it generates a warning,
but then the parameter to "-T" is handled as a regular input and eventually gets parsed as a regular linker script.

I suspect that is accidental. *Any* unrecognized options issue that warning. Not sure if that is a good idea.

Currently there is no difference between a script that overrides the "default linker script" and one that does not,
but we need this for the future (well, mostly producing an error if the linker script contains special commands that
are reserved for either the default linker script or the script that replaces it).

Exactly. Right now there isn't much of difference, but to provide a proper distinction between default and user provided
it will matter.

meadori updated this revision to Diff 21773.Mar 11 2015, 3:05 PM

Update to fix the -lfilename bug mentioned earlier in the review and add more tests. Note that input, -l, and -T still share the same code path in the option switch, *but* the correct checking is in place (and was before) to determine when we have a linker script in the case of input and -l.

Any other comments on this one?

No more comments, Meador, LGTM. Thanks for working on this.

meadori accepted this revision.May 4 2015, 2:10 PM
meadori added a reviewer: meadori.
This revision is now accepted and ready to land.May 4 2015, 2:10 PM
meadori closed this revision.May 4 2015, 2:10 PM