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
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 = []
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@")
-// 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; }