diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -610,7 +610,8 @@ set(CAN_SYMBOLIZE 1) endif() -find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold ${LLVM_DEFAULT_TARGET_TRIPLE}-ld ld DOC "The gold linker") +find_program(GNU_LD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.bfd ld.bfd DOC "GNU ld") +find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold DOC "GNU gold") if(COMPILER_RT_SUPPORTED_ARCH) list(REMOVE_DUPLICATES COMPILER_RT_SUPPORTED_ARCH) diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py --- a/compiler-rt/test/lit.common.cfg.py +++ b/compiler-rt/test/lit.common.cfg.py @@ -413,19 +413,18 @@ def is_darwin_lto_supported(): return os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO.dylib')) -def is_linux_lto_supported(): - if config.use_lld: - return True - +def is_binutils_lto_supported(): if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')): return False - ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE, env={'LANG': 'C'}) - ld_out = ld_cmd.stdout.read().decode() - ld_cmd.wait() - - if not '-plugin' in ld_out: - return False + # We require both ld.bfd and ld.gold exist and support plugins. They are in + # the same repository 'binutils-gdb' and usually built together. + for exe in (config.gnu_ld_executable, config.gold_executable): + ld_cmd = subprocess.Popen([exe, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'}) + ld_out = ld_cmd.stdout.read().decode() + ld_cmd.wait() + if not '-plugin' in ld_out: + return False return True @@ -436,13 +435,20 @@ config.lto_supported = True config.lto_launch = ["env", "DYLD_LIBRARY_PATH=" + config.llvm_shlib_dir] config.lto_flags = [] -elif config.host_os in ['Linux', 'FreeBSD', 'NetBSD'] and is_linux_lto_supported(): - config.lto_supported = True - config.lto_launch = [] +elif config.host_os in ['Linux', 'FreeBSD', 'NetBSD']: + config.lto_supported = False if config.use_lld: - config.lto_flags = ["-fuse-ld=lld"] - else: - config.lto_flags = ["-fuse-ld=gold"] + config.lto_supported = True + if is_binutils_lto_supported(): + config.available_features.add('binutils_lto') + config.lto_supported = True + + if config.lto_supported: + config.lto_launch = [] + if config.use_lld: + config.lto_flags = ["-fuse-ld=lld"] + else: + config.lto_flags = ["-fuse-ld=gold"] elif config.host_os == 'Windows' and is_windows_lto_supported(): config.lto_supported = True config.lto_launch = [] diff --git a/compiler-rt/test/lit.common.configured.in b/compiler-rt/test/lit.common.configured.in --- a/compiler-rt/test/lit.common.configured.in +++ b/compiler-rt/test/lit.common.configured.in @@ -19,6 +19,7 @@ set_default("enable_per_target_runtime_dir", @LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_PYBOOL@) set_default("llvm_tools_dir", "@LLVM_TOOLS_DIR@") set_default("llvm_shlib_dir", "@LLVM_LIBRARY_OUTPUT_INTDIR@") +set_default("gnu_ld_executable", "@GNU_LD_EXECUTABLE@") set_default("gold_executable", "@GOLD_EXECUTABLE@") set_default("clang", "@COMPILER_RT_RESOLVED_TEST_COMPILER@") set_default("compiler_id", "@COMPILER_RT_TEST_COMPILER_ID@") diff --git a/compiler-rt/test/profile/instrprof-lto-pgogen.c b/compiler-rt/test/profile/instrprof-lto-pgogen.c --- a/compiler-rt/test/profile/instrprof-lto-pgogen.c +++ b/compiler-rt/test/profile/instrprof-lto-pgogen.c @@ -1,13 +1,13 @@ -// REQUIRES: lto -// XFAIL: msvc +// REQUIRES: binutils_lto -// RUN: %clang_pgogen=%t.profraw -flto %s -o %t +// RUN: %clang_pgogen=%t.profraw -fuse-ld=bfd -flto %s -o %t // RUN: %run %t // RUN: llvm-profdata merge %t.profraw -o %t.profdata // RUN: llvm-profdata show %t.profdata | FileCheck %s -// Testing a bug that happens when trying to generate IR -// profile with BFD linker + LTO plugin +/// Test that we work around https://sourceware.org/bugzilla/show_bug.cgi?id=26262 +/// (as of GNU ld 2.35) which happens when trying to generate IR profile with +/// BFD linker + LLVMgold.so // CHECK: Instrumentation level: IR int main() { return 0; }