Page MenuHomeFreeBSD

Pass -fuse-ld=/path/to/ld if ${LD} != "ld"
ClosedPublic

Authored by arichardson on Aug 13 2020, 2:09 PM.
Tags
None
Referenced Files
Unknown Object (File)
Oct 10 2024, 11:34 PM
Unknown Object (File)
Oct 10 2024, 3:05 PM
Unknown Object (File)
Oct 3 2024, 6:16 PM
Unknown Object (File)
Oct 3 2024, 1:20 PM
Unknown Object (File)
Oct 2 2024, 11:04 PM
Unknown Object (File)
Oct 2 2024, 5:19 PM
Unknown Object (File)
Sep 8 2024, 6:59 AM
Unknown Object (File)
Sep 6 2024, 1:04 AM
Subscribers
None

Details

Summary

This is needed so that setting LD/XLD is not ignored when linking with $CC
instead of directly using $LD. Currently only clang accepts an absolute
path for -fuse-ld= (Clang 12+ will add a new --ld-path flag), so we now
warn when building with GCC and $LD != "ld" since that might result in the
wrong linker being used.

We have been XLD=/path/to/cheri/ld.lld in CheriBSD for a long time and
used a similar version of this patch to avoid linking with /usr/bin/ld.
This change is also required when building FreeBSD on an Ubuntu with Clang:
In that case we set XCC=/usr/lib/llvm-10/bin/clang and since
/usr/lib/llvm-10/bin/ does not contain a "ld" binary the build fails with
clang: error: unable to execute command: Executable "ld" doesn't exist!
unless we pass -fuse-ld=/usr/lib/llvm-10/bin/ld.lld.

Test Plan

buildworld+buildkernel failed on Ubuntu without this patch, now succeeds.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

arichardson created this revision.
This revision is now accepted and ready to land.Aug 13 2020, 10:32 PM

I'm fine with this change, although I wonder if we could/should start installing a (cross-)ld in our tools dir?

I'm fine with this change, although I wonder if we could/should start installing a (cross-)ld in our tools dir?

Shouldn't it already contain a ld -> ld.lld symlink by default?

Shouldn't it already contain a ld -> ld.lld symlink by default?

Does the build work if we just pass a -B argument instead then?

Shouldn't it already contain a ld -> ld.lld symlink by default?

Does the build work if we just pass a -B argument instead then?

It won't work on Ubuntu unless we pass -B <COMPILER_DIR> -fuse-ld=$(basename $XLD) since clang defaults to executing plain ld. Passing the full value of ${XLD} seems less fragile to me.

I guess we could also add ${XLD} to WOLRDTMP/bin/ld but then we have to ensure that this file does not exist while building the bootstrap tools since the cross-linker might not be compatible with the host linker (e.g. when building on macos: host-linker= Mach-O /usr/bin/ld, cross-linker=LLVM ld.lld).

OK - I have no objection to this version, just wondered if we could simplify it. Good point about copying in the XLD.

This revision was automatically updated to reflect the committed changes.