[compiler-rt] f6b2ddb - [compiler-rt] Use ld64 flag -lto_library instead of DYLD_LIBRARY_PATH

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 19 10:55:05 PDT 2022


Author: Nico Weber
Date: 2022-04-19T13:54:57-04:00
New Revision: f6b2ddbf381dda5f201f48a5211fb0d053640225

URL: https://github.com/llvm/llvm-project/commit/f6b2ddbf381dda5f201f48a5211fb0d053640225
DIFF: https://github.com/llvm/llvm-project/commit/f6b2ddbf381dda5f201f48a5211fb0d053640225.diff

LOG: [compiler-rt] Use ld64 flag -lto_library instead of DYLD_LIBRARY_PATH

Makes

 bin/llvm-lit \
  projects/compiler-rt/test/profile/Profile-arm64/instrprof-darwin-dead-strip.c

pass on my machine.

Without this change, ld64 complains that the bitcode was generated by LLVM 15
while the reader is 13.1 -- the version of Xcode on my machine. Looks like the
DYLD_LIBRARY_PATH technique isn't working.

-lto_library was added back in ld64-136, which was in Xcode 4.6, which was
released over 10 years ago. So relying on it should be safe by now.

Differential Revision: https://reviews.llvm.org/D124018

Added: 
    

Modified: 
    compiler-rt/test/lit.common.cfg.py
    compiler-rt/test/profile/lit.cfg.py
    compiler-rt/test/safestack/lit.cfg.py

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py
index 117d5be1b9a1a..00a3adafc01c0 100644
--- a/compiler-rt/test/lit.common.cfg.py
+++ b/compiler-rt/test/lit.common.cfg.py
@@ -520,8 +520,11 @@ def get_macos_aligned_version(macos_vers):
   config.available_features.add("has_sancovcc")
   config.substitutions.append( ("%sancovcc ", sancovcc_path) )
 
+def liblto_path():
+  return os.path.join(config.llvm_shlib_dir, 'libLTO.dylib')
+
 def is_darwin_lto_supported():
-  return os.path.exists(os.path.join(config.llvm_shlib_dir, 'libLTO.dylib'))
+  return os.path.exists(liblto_path())
 
 def is_binutils_lto_supported():
   if not os.path.exists(os.path.join(config.llvm_shlib_dir, 'LLVMgold.so')):
@@ -543,8 +546,7 @@ def is_windows_lto_supported():
 
 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 = []
+  config.lto_flags = [ '-Wl,-lto_library,' + liblto_path() ]
 elif config.host_os in ['Linux', 'FreeBSD', 'NetBSD']:
   config.lto_supported = False
   if config.use_lld:
@@ -554,14 +556,12 @@ def is_windows_lto_supported():
     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 = []
   config.lto_flags = ["-fuse-ld=lld"]
 else:
   config.lto_supported = False
@@ -692,7 +692,6 @@ def is_windows_lto_supported():
 extra_cflags = []
 
 if config.use_lto and config.lto_supported:
-  run_wrapper += config.lto_launch
   extra_cflags += config.lto_flags
 elif config.use_lto and (not config.lto_supported):
   config.unsupported = True

diff  --git a/compiler-rt/test/profile/lit.cfg.py b/compiler-rt/test/profile/lit.cfg.py
index 2efdbacc948d6..5ef4ca0dd05d1 100644
--- a/compiler-rt/test/profile/lit.cfg.py
+++ b/compiler-rt/test/profile/lit.cfg.py
@@ -44,11 +44,9 @@ def get_required_attr(config, attr_name):
 
 def build_invocation(compile_flags, with_lto = False):
   lto_flags = []
-  lto_prefix = []
   if with_lto and config.lto_supported:
     lto_flags += config.lto_flags
-    lto_prefix += config.lto_launch
-  return " " + " ".join(lto_prefix + [config.clang] + lto_flags + compile_flags) + " "
+  return " " + " ".join([config.clang] + lto_flags + compile_flags) + " "
 
 def exclude_unsupported_files_for_aix(dirname):
    for filename in os.listdir(dirname):

diff  --git a/compiler-rt/test/safestack/lit.cfg.py b/compiler-rt/test/safestack/lit.cfg.py
index 95a115986ec7c..b3cf928e4114f 100644
--- a/compiler-rt/test/safestack/lit.cfg.py
+++ b/compiler-rt/test/safestack/lit.cfg.py
@@ -16,7 +16,7 @@
 config.substitutions.append( ("%clang_safestack ", config.clang + " -O0 -fsanitize=safe-stack ") )
 
 if config.lto_supported:
-  config.substitutions.append((r"%clang_lto_safestack ", ' '.join(config.lto_launch + [config.clang] + config.lto_flags + ['-fsanitize=safe-stack '])))
+  config.substitutions.append((r"%clang_lto_safestack ", ' '.join([config.clang] + config.lto_flags + ['-fsanitize=safe-stack '])))
 
 if config.host_os not in ['Linux', 'FreeBSD', 'NetBSD']:
    config.unsupported = True


        


More information about the llvm-commits mailing list