Page MenuHomePhabricator

[Clang] Accept absolute paths in the -fuse-ld option
ClosedPublic

Authored by whitequark on Mar 7 2016, 6:54 PM.

Details

Summary

This patch extends the -fuse-ld option to accept a full path to an executable
and use it verbatim to invoke the linker. There are generally two reasons
to desire this.

The first reason relates to the sad truth is that Clang is retargetable,
Binutils are not.

While any Clang from a binary distribution is sufficient to compile code
for a wide range of architectures and prefixed BFD linkers (e.g.
installed as /usr/bin/arm-none-linux-gnueabi-ld) as well as cross-compiled
libc's (for non-bare-metal targets) are widely available, including on all
Debian derivatives, it is impossible to use them together because
the -fuse-ld= option allows to specify neither a linker prefix nor
a full path to one.

The second reason is linker development, both when porting existing linkers
to new architectures and when working on a new linker such as LLD.

Diff Detail

Repository
rL LLVM

Event Timeline

whitequark updated this revision to Diff 50020.Mar 7 2016, 6:54 PM
whitequark retitled this revision from to [Clang] Accept absolute paths in the -fuse-ld option.
whitequark updated this object.
whitequark added a reviewer: majnemer.
whitequark set the repository for this revision to rL LLVM.
whitequark added a subscriber: cfe-commits.
silvas added a subscriber: silvas.Mar 7 2016, 7:27 PM

Some nits but this looks fine to me. I've been wanting this for a while now.

cfe/trunk/lib/Driver/ToolChain.cpp
347

Use llvm::sys::path::is_absolute so that this works on windows.

352

No need for else after return.

whitequark marked an inline comment as done.Mar 7 2016, 7:31 PM
whitequark added inline comments.
cfe/trunk/lib/Driver/ToolChain.cpp
352

This would change behavior when an absolute path is passed but doesn't exist; clang will try to append it to "ld." and display some silly error message.

whitequark updated this revision to Diff 50021.Mar 7 2016, 7:32 PM

Windows compatibility

silvas added inline comments.Mar 7 2016, 7:43 PM
cfe/trunk/lib/Driver/ToolChain.cpp
352

Makes sense.

Needs a testcase, but otherwise should be fine.

whitequark updated this revision to Diff 50097.Mar 8 2016, 5:54 PM

Added a test

echristo accepted this revision.Mar 8 2016, 9:12 PM
echristo added a reviewer: echristo.

LGTM, thanks.

-eric

This revision is now accepted and ready to land.Mar 8 2016, 9:12 PM
This revision was automatically updated to reflect the committed changes.