[compiler-rt] 746b5fa - [profile][test] Add -fuse-ld=bfd to make instrprof-lto-pgogen.c robust
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 22 10:16:18 PDT 2020
Author: Fangrui Song
Date: 2020-07-22T10:16:08-07:00
New Revision: 746b5fad5b53ddbc78d36a6b97dcaff7e52540b2
URL: https://github.com/llvm/llvm-project/commit/746b5fad5b53ddbc78d36a6b97dcaff7e52540b2
DIFF: https://github.com/llvm/llvm-project/commit/746b5fad5b53ddbc78d36a6b97dcaff7e52540b2.diff
LOG: [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
Added:
Modified:
compiler-rt/cmake/config-ix.cmake
compiler-rt/test/lit.common.cfg.py
compiler-rt/test/lit.common.configured.in
compiler-rt/test/profile/instrprof-lto-pgogen.c
Removed:
################################################################################
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index d1e01d956a7f..0a27910ed494 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 7c98c387c870..fdc28a4637ff 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -413,19 +413,18 @@ def get_apple_min_deploy_target_flag_aligned_with_osx(version):
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 @@ def is_windows_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 4a3e268c8a6f..1f746c067b84 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 99870c70bef3..3538f269f510 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; }
More information about the llvm-commits
mailing list