From 746b5fad5b53ddbc78d36a6b97dcaff7e52540b2 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 22 Jul 2020 10:15:51 -0700 Subject: [PATCH] [profile][test] Add -fuse-ld=bfd to make instrprof-lto-pgogen.c robust Otherwise if 'ld' is an older system LLD (FreeBSD; or if someone adds 'ld' to point to an LLD from a different installation) which does not support the current ModuleSummaryIndex::BitCodeSummaryVersion, the test will fail. Add lit feature 'binutils_lto'. GNU ld is more common than GNU gold, so we can just require 'is_binutils_lto_supported' to additionally support GNU ld. Reviewed By: myhsu Differential Revision: https://reviews.llvm.org/D84133 --- compiler-rt/cmake/config-ix.cmake | 3 +- compiler-rt/test/lit.common.cfg.py | 38 ++++++++++++++----------- compiler-rt/test/lit.common.configured.in | 1 + compiler-rt/test/profile/instrprof-lto-pgogen.c | 10 +++---- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake index d1e01d9..0a27910 100644 --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -610,7 +610,8 @@ else() 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 index 7c98c38..fdc28a4 100644 --- a/compiler-rt/test/lit.common.cfg.py +++ b/compiler-rt/test/lit.common.cfg.py @@ -413,19 +413,18 @@ if os.path.exists(sancovcc_path): 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 @@ if config.host_os == 'Darwin' and is_darwin_lto_supported(): 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 index 4a3e268..1f746c0 100644 --- a/compiler-rt/test/lit.common.configured.in +++ b/compiler-rt/test/lit.common.configured.in @@ -19,6 +19,7 @@ set_default("compiler_rt_obj_root", "@COMPILER_RT_BINARY_DIR@") 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 index 99870c7..3538f26 100644 --- 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; } -- 2.7.4