This is an archive of the discontinued LLVM Phabricator instance.

Add TARGET(foo) linker script directive.
ClosedPublic

Authored by ruiu on Jun 13 2018, 2:31 PM.

Details

Summary

GNU ld's manual says that TARGET(foo) is basically an alias for
--format foo where foo is a BFD target name such as elf64-x86-64.

Unlike GNU linkers, lld doesn't allow arbitrary BFD target name for
--format. We accept only "default", "elf" or "binary". This makes
situation a bit tricky because we can't simply make TARGET an alias for
--target.

A quick code search revealed that the usage number of TARGET is very
small, and the only meaningful usage is to switch to the binary mode.
Thus, in this patch, we handle only TARGET(elf.*) and TARGET(binary).

Diff Detail

Repository
rL LLVM

Event Timeline

ruiu created this revision.Jun 13 2018, 2:31 PM
rdhindsa added inline comments.Jun 13 2018, 2:54 PM
lld/ELF/ScriptParser.cpp
486 ↗(On Diff #151250)

Should "default" case be handled here as well?

ruiu added inline comments.Jun 13 2018, 2:57 PM
lld/ELF/ScriptParser.cpp
486 ↗(On Diff #151250)

I don't think so. We add features as-needed basis, so we don't add a lot of features ahead of time.

This revision is now accepted and ready to land.Jun 14 2018, 11:15 AM
grimar accepted this revision.Jun 18 2018, 6:37 AM

This is probably OK. LGTM with a nit.

lld/ELF/ScriptParser.cpp
491 ↗(On Diff #151250)

Can you add a test for that error?

MaskRay added a subscriber: MaskRay.Aug 6 2018, 1:55 PM
MaskRay added inline comments.
lld/ELF/ScriptParser.cpp
486 ↗(On Diff #151250)

You have separate commit to change Driver.cpp:isOutputFormatBinary. If we want to proceed with adding the TARGET() linker command, these lines should be better off unified with that function.

ruiu added inline comments.Aug 6 2018, 2:15 PM
lld/ELF/ScriptParser.cpp
486 ↗(On Diff #151250)

Unifying only these few lines code doesn't make much sense to me when I tried it, mainly because the code to share the code is as large as this code, and we need different error message for this.

This revision was automatically updated to reflect the committed changes.