From 7903d0b711ec74509ca6ef36bd0d1d0c46f732a5 Mon Sep 17 00:00:00 2001 From: Peter Waller Date: Tue, 12 Nov 2024 21:36:46 +0000 Subject: [PATCH] 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 --- .../compilers/llvm/common/llvm/default.nix | 12 +++++++----- .../tools/misc/binutils/default.nix | 18 +++++++++++++----- .../development/tools/misc/binutils/libbfd.nix | 2 +- .../tools/misc/binutils/libopcodes.nix | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/pkgs/development/compilers/llvm/common/llvm/default.nix b/pkgs/development/compilers/llvm/common/llvm/default.nix index be106b3db295..ce35c039fc8c 100644 --- a/pkgs/development/compilers/llvm/common/llvm/default.nix +++ b/pkgs/development/compilers/llvm/common/llvm/default.nix @@ -13,9 +13,6 @@ , python3 , python3Packages , libffi - # TODO: Can this memory corruption bug still occur? - # -, 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" diff --git a/pkgs/development/tools/misc/binutils/default.nix b/pkgs/development/tools/misc/binutils/default.nix index 4d90fa66ea7d..d9c814dd41b5 100644 --- a/pkgs/development/tools/misc/binutils/default.nix +++ b/pkgs/development/tools/misc/binutils/default.nix @@ -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; { diff --git a/pkgs/development/tools/misc/binutils/libbfd.nix b/pkgs/development/tools/misc/binutils/libbfd.nix index c6ab2a6431d0..f8dc8b5473a7 100644 --- a/pkgs/development/tools/misc/binutils/libbfd.nix +++ b/pkgs/development/tools/misc/binutils/libbfd.nix @@ -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; { diff --git a/pkgs/development/tools/misc/binutils/libopcodes.nix b/pkgs/development/tools/misc/binutils/libopcodes.nix index c8d3b78b29eb..423ab850737d 100644 --- a/pkgs/development/tools/misc/binutils/libopcodes.nix +++ b/pkgs/development/tools/misc/binutils/libopcodes.nix @@ -15,7 +15,7 @@ stdenv.mkDerivation { ]; passthru = { - inherit (binutils-unwrapped-all-targets) dev hasPluginAPI; + inherit (binutils-unwrapped-all-targets) dev; }; meta = with lib; {