Skip to content

Commit

Permalink
[profile][test] Add -fuse-ld=bfd to make instrprof-lto-pgogen.c robust
Browse files Browse the repository at this point in the history
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
  • Loading branch information
MaskRay committed Jul 22, 2020
1 parent 1fd1bee commit 746b5fa
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
3 changes: 2 additions & 1 deletion compiler-rt/cmake/config-ix.cmake
Expand Up @@ -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)
Expand Down
38 changes: 22 additions & 16 deletions compiler-rt/test/lit.common.cfg.py
Expand Up @@ -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

Expand All @@ -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 = []
Expand Down
1 change: 1 addition & 0 deletions compiler-rt/test/lit.common.configured.in
Expand Up @@ -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@")
Expand Down
10 changes: 5 additions & 5 deletions 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; }

0 comments on commit 746b5fa

Please sign in to comment.