llvmPackages.llvm: Drop dependency on target through libbfd

Currently the target triple leaks into the clang build via llvm using
libbfd, whose build varies according to the target triple.

LLVM only uses libbfd to enable LTO via the linker plugin (called
LLVMgold.so, though multiple linkers can use the same plugin).

Drop the dependency on the libbfd build, and consume the only needed
source instead.  (This would be a good use of CA-derivations FWIW).

The result of this commit is that these match:

* nix eval --raw nixpkgs#clang.cc
* nix eval --raw nixpkgs#pkgsStatic.pkgsLLVM.stdenv.cc.cc
* nix eval --raw nixpkgs#pkgsCross.aarch64-multiplatform.pkgsLLVM.stdenv.cc.cc

This means fewer clang builds will be needed to support cross
configurations, and users wanting to target an exotic cross
configuration should be able to do so without a rebuild of clang.

Also drops libbfd.hasPluginAPI which no longer has any users.

Signed-off-by: Peter Waller <p@pwaller.net>
This commit is contained in:
Peter Waller
2024-11-14 21:43:26 +00:00
parent 2e21fa2ccb
commit 7903d0b711
4 changed files with 22 additions and 12 deletions
@@ -13,9 +13,6 @@
, python3
, python3Packages
, libffi
# TODO: Can this memory corruption bug still occur?
# <https://github.com/llvm/llvm-project/issues/61350>
, enableGoldPlugin ? libbfd.hasPluginAPI
, ld64
, libbfd
, libpfm
@@ -373,8 +370,13 @@ stdenv.mkDerivation (finalAttrs: {
"-DSPHINX_OUTPUT_MAN=ON"
"-DSPHINX_OUTPUT_HTML=OFF"
"-DSPHINX_WARNINGS_AS_ERRORS=OFF"
] ++ optionals (enableGoldPlugin) [
"-DLLVM_BINUTILS_INCDIR=${libbfd.dev}/include"
] ++ optionals (libbfd != null) [
# LLVM depends on binutils only through libbfd/include/plugin-api.h, which
# is meant to be a stable interface. Depend on that file directly rather
# than through a build of BFD to break the dependency of clang on the target
# triple. The result of this is that a single clang build can be used for
# multiple targets.
"-DLLVM_BINUTILS_INCDIR=${libbfd.plugin-api-header}/include"
] ++ optionals stdenv.hostPlatform.isDarwin [
"-DLLVM_ENABLE_LIBCXX=ON"
"-DCAN_TARGET_i386=false"
@@ -12,6 +12,7 @@ in
, lib
, noSysDirs
, perl
, runCommand
, zlib
, CoreServices
@@ -238,11 +239,18 @@ stdenv.mkDerivation (finalAttrs: {
inherit targetPrefix;
hasGold = enableGold;
isGNU = true;
# Having --enable-plugins is not enough, system has to support
# dlopen() or equivalent. See config/plugins.m4 and configure.ac
# (around PLUGINS) for cases that support or not support plugins.
# No platform specific filters yet here.
hasPluginAPI = enableGold;
# The plugin API is not a function of any targets. Expose it separately,
# currently only used by LLVM for enabling BFD to do LTO with LLVM bitcode.
# (Tar will exit with an error if there are no matches).
plugin-api-header = runCommand "libbfd-plugin-api-header" {} ''
mkdir -p $out
tar --directory=$out \
--extract \
--file=${finalAttrs.src} \
--strip-components=1 \
--wildcards '*'/include/plugin-api.h
'';
};
meta = with lib; {
@@ -15,7 +15,7 @@ stdenv.mkDerivation {
];
passthru = {
inherit (binutils-unwrapped-all-targets) dev hasPluginAPI;
inherit (binutils-unwrapped-all-targets) src dev plugin-api-header;
};
meta = with lib; {
@@ -15,7 +15,7 @@ stdenv.mkDerivation {
];
passthru = {
inherit (binutils-unwrapped-all-targets) dev hasPluginAPI;
inherit (binutils-unwrapped-all-targets) dev;
};
meta = with lib; {