Skip to content

Commit 746b5fa

Browse files
committed
[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
1 parent 1fd1bee commit 746b5fa

File tree

4 files changed

+30
-22
lines changed

4 files changed

+30
-22
lines changed

compiler-rt/cmake/config-ix.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,8 @@ else()
610610
set(CAN_SYMBOLIZE 1)
611611
endif()
612612

613-
find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold ${LLVM_DEFAULT_TARGET_TRIPLE}-ld ld DOC "The gold linker")
613+
find_program(GNU_LD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.bfd ld.bfd DOC "GNU ld")
614+
find_program(GOLD_EXECUTABLE NAMES ${LLVM_DEFAULT_TARGET_TRIPLE}-ld.gold ld.gold DOC "GNU gold")
614615

615616
if(COMPILER_RT_SUPPORTED_ARCH)
616617
list(REMOVE_DUPLICATES COMPILER_RT_SUPPORTED_ARCH)

compiler-rt/test/lit.common.cfg.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -413,19 +413,18 @@ def get_apple_min_deploy_target_flag_aligned_with_osx(version):
413413
def is_darwin_lto_supported():
414414
return os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO.dylib'))
415415

416-
def is_linux_lto_supported():
417-
if config.use_lld:
418-
return True
419-
416+
def is_binutils_lto_supported():
420417
if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
421418
return False
422419

423-
ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE, env={'LANG': 'C'})
424-
ld_out = ld_cmd.stdout.read().decode()
425-
ld_cmd.wait()
426-
427-
if not '-plugin' in ld_out:
428-
return False
420+
# We require both ld.bfd and ld.gold exist and support plugins. They are in
421+
# the same repository 'binutils-gdb' and usually built together.
422+
for exe in (config.gnu_ld_executable, config.gold_executable):
423+
ld_cmd = subprocess.Popen([exe, '--help'], stdout=subprocess.PIPE, env={'LANG': 'C'})
424+
ld_out = ld_cmd.stdout.read().decode()
425+
ld_cmd.wait()
426+
if not '-plugin' in ld_out:
427+
return False
429428

430429
return True
431430

@@ -436,13 +435,20 @@ def is_windows_lto_supported():
436435
config.lto_supported = True
437436
config.lto_launch = ["env", "DYLD_LIBRARY_PATH=" + config.llvm_shlib_dir]
438437
config.lto_flags = []
439-
elif config.host_os in ['Linux', 'FreeBSD', 'NetBSD'] and is_linux_lto_supported():
440-
config.lto_supported = True
441-
config.lto_launch = []
438+
elif config.host_os in ['Linux', 'FreeBSD', 'NetBSD']:
439+
config.lto_supported = False
442440
if config.use_lld:
443-
config.lto_flags = ["-fuse-ld=lld"]
444-
else:
445-
config.lto_flags = ["-fuse-ld=gold"]
441+
config.lto_supported = True
442+
if is_binutils_lto_supported():
443+
config.available_features.add('binutils_lto')
444+
config.lto_supported = True
445+
446+
if config.lto_supported:
447+
config.lto_launch = []
448+
if config.use_lld:
449+
config.lto_flags = ["-fuse-ld=lld"]
450+
else:
451+
config.lto_flags = ["-fuse-ld=gold"]
446452
elif config.host_os == 'Windows' and is_windows_lto_supported():
447453
config.lto_supported = True
448454
config.lto_launch = []

compiler-rt/test/lit.common.configured.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ set_default("compiler_rt_obj_root", "@COMPILER_RT_BINARY_DIR@")
1919
set_default("enable_per_target_runtime_dir", @LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_PYBOOL@)
2020
set_default("llvm_tools_dir", "@LLVM_TOOLS_DIR@")
2121
set_default("llvm_shlib_dir", "@LLVM_LIBRARY_OUTPUT_INTDIR@")
22+
set_default("gnu_ld_executable", "@GNU_LD_EXECUTABLE@")
2223
set_default("gold_executable", "@GOLD_EXECUTABLE@")
2324
set_default("clang", "@COMPILER_RT_RESOLVED_TEST_COMPILER@")
2425
set_default("compiler_id", "@COMPILER_RT_TEST_COMPILER_ID@")
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// REQUIRES: lto
2-
// XFAIL: msvc
1+
// REQUIRES: binutils_lto
32

4-
// RUN: %clang_pgogen=%t.profraw -flto %s -o %t
3+
// RUN: %clang_pgogen=%t.profraw -fuse-ld=bfd -flto %s -o %t
54
// RUN: %run %t
65
// RUN: llvm-profdata merge %t.profraw -o %t.profdata
76
// RUN: llvm-profdata show %t.profdata | FileCheck %s
87

9-
// Testing a bug that happens when trying to generate IR
10-
// profile with BFD linker + LTO plugin
8+
/// Test that we work around https://sourceware.org/bugzilla/show_bug.cgi?id=26262
9+
/// (as of GNU ld 2.35) which happens when trying to generate IR profile with
10+
/// BFD linker + LLVMgold.so
1111

1212
// CHECK: Instrumentation level: IR
1313
int main() { return 0; }

0 commit comments

Comments
 (0)