Page MenuHomeFreeBSD

Add WITH_LLVM_BINUTILS to install LLVM binutils instead of Elftoolchain

Authored by arichardson on Jul 5 2021, 5:45 PM.
Referenced Files
F62117368: D31060.id94710.diff
Thu, Jun 1, 4:26 AM
Unknown Object (File)
Tue, May 30, 8:02 PM
Unknown Object (File)
Apr 23 2023, 11:18 PM
Unknown Object (File)
Mar 5 2023, 7:33 AM
Unknown Object (File)
Feb 15 2023, 9:42 PM
Unknown Object (File)
Feb 14 2023, 9:24 AM
Unknown Object (File)
Feb 14 2023, 8:49 AM
Unknown Object (File)
Jan 17 2023, 12:11 AM



When WITH_LLVM_BINUTILS is set, we will install the LLVM binutils as
ar/ranlib/nm/objcopy/etc. instead of the elftoolchain ones.
Having the LLVM binutils instead of the elftoolchain ones allows us to use
features such as LTO that depend on binutils that understand LLVM IR.
Another benefit will be an improved user-experience when compiling with
AddressSanitizer, since ASAN does not symbolize backtraces correctly if
addr2line is elftoolchain addr2line instead of llvm-symbolizer.
for more details.

This is currently off by default but will be turned on by default at some
point in the near future.

Depends on D31058 (to apply cleanly)

Diff Detail

rG FreeBSD src repository
Lint Not Applicable
Tests Not Applicable

Event Timeline


This seems a bit dated given MK_LLD and MK_LLDB exist


Yeah I'm not sure how happy the build will be if you try -DWITH_LLD -DWITHOUT_CLANG.


This part (clang-tblgen, lldb-tblgen) lgtm, and I think you can commit it first


I'm not 100% sure about this one - I pulled strings out of WITH_/WITHOUT_TOOLCHAIN because it's often used outside of the context of a build toolchain, and ELF Tool Chain's strings will be much smaller.


Happy to drop strings from this change. Will update shortly.

arichardson marked 2 inline comments as done.

drop strings

emaste added a subscriber: sjg.

LGTM, we might have a few things to iterate on with this in the tree


Would we want to split out knobs for bootstrap and installed system? (If so, as a later step.)


As an aside usr.bin/clang/ (now) seems like the wrong top-level directory name for the various LLVM components, but beyond the scope of this change.

This revision is now accepted and ready to land.Jul 26 2021, 3:34 PM

I always build with an external toolchain, but I think adding MK_LLVM_BINUTILS_BOOTSTRAP sounds reasonable.

From hardenedbsd IRC, an issue that has come up in discussion before (and will iterate on via exp-runs):

14:47 < gehmehgeh> emaste: careful, though, when switching to llvm-ar: there is 
                   at least one "elftc" option it doesn't support. I forget 
                   which flag it was, but I've a section in my make.conf 
                   instructing the FreeBSD ports to use elftc's ar when 
                   building everything Haskell related-- exactly because their 
                   build script do something unsupported

From @mhorne via 4d0dc60f14019eab08f6d9dc656c9f9f1ebdde02, llvm-strip does not parse --
Now worked around in the base system, but we ought to support it in llvm-strip.

From @mhorne via 4d0dc60f14019eab08f6d9dc656c9f9f1ebdde02, llvm-strip does not parse --
Now worked around in the base system, but we ought to support it in llvm-strip.

Is there an upstream LLVM bugreport for this?

Is there an upstream LLVM bugreport for this?

I have not (yet) submitted one and did not find one after a quick look. I was planning to do a more holistic check of option parsing. Also, an exp-run with this change enabled should help find real-world issues.

It looks like llvm-strip (main) supports -- now:

llvm pkg

$ llvm-strip11 -o /dev/null -- /usr/bin/true
llvm-strip: error: unknown argument '--'

llvm-strip built from src today:

$ ~/src/llvm-project/build/bin/llvm-strip -o /dev/null -- /usr/bin/true
$ echo $?
This revision now requires review to proceed.Sep 6 2021, 8:49 AM
This revision was not accepted when it landed; it landed in state Needs Review.Sep 6 2021, 9:25 AM
This revision was automatically updated to reflect the committed changes.