Skip to content

Commit 11903e8

Browse files
authored
[sanitizer][test] Unify LD_LIBRARY_PATH handling (#111498)
When testing on Linux/sparc64 with a `runtimes` build, the `UBSan-Standalone-sparc :: TestCases/Misc/Linux/sigaction.cpp` test `FAIL`s: ``` runtimes/runtimes-bins/compiler-rt/test/ubsan/Standalone-sparc/TestCases/Misc/Linux/Output/sigaction.cpp.tmp: error while loading shared libraries: libclang_rt.ubsan_standalone.so: wrong ELF class: ELFCLASS64 ``` It turns out SPARC needs the same `LD_LIBRARY_PATH` handling as x86. This is what this patch does, at the same time noticing that the current duplication between `lit.common.cfg.py` and `asan/Unit/lit.site.cfg.py.in` isn't necessary. Tested on `sparc64-unknown-linux-gnu` and `x86_64-pc-linux-gnu`.
1 parent e290152 commit 11903e8

File tree

2 files changed

+13
-38
lines changed

2 files changed

+13
-38
lines changed

compiler-rt/test/asan/Unit/lit.site.cfg.py.in

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,6 @@ import shlex
88
# Load common config for all compiler-rt unit tests.
99
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")
1010

11-
def push_ld_library_path(config, new_path):
12-
new_ld_library_path = os.path.pathsep.join(
13-
(new_path, config.environment.get('LD_LIBRARY_PATH', '')))
14-
config.environment['LD_LIBRARY_PATH'] = new_ld_library_path
15-
16-
if platform.system() == 'FreeBSD':
17-
new_ld_32_library_path = os.path.pathsep.join(
18-
(new_path, config.environment.get('LD_32_LIBRARY_PATH', '')))
19-
config.environment['LD_32_LIBRARY_PATH'] = new_ld_32_library_path
20-
21-
if platform.system() == 'SunOS':
22-
new_ld_library_path_32 = os.path.pathsep.join(
23-
(new_path, config.environment.get('LD_LIBRARY_PATH_32', '')))
24-
config.environment['LD_LIBRARY_PATH_32'] = new_ld_library_path_32
25-
26-
new_ld_library_path_64 = os.path.pathsep.join(
27-
(new_path, config.environment.get('LD_LIBRARY_PATH_64', '')))
28-
config.environment['LD_LIBRARY_PATH_64'] = new_ld_library_path_64
29-
3011
# Setup config name.
3112
config.name = 'AddressSanitizer-Unit'
3213

@@ -48,19 +29,5 @@ config.test_exec_root = os.path.join("@COMPILER_RT_BINARY_DIR@",
4829

4930
config.test_source_root = config.test_exec_root
5031

51-
# When LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on, the initial value of
52-
# config.compiler_rt_libdir (COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR) has the
53-
# host triple as the trailing path component. The value is incorrect for i386
54-
# tests on x86_64 hosts and vice versa. Adjust config.compiler_rt_libdir
55-
# accordingly.
56-
if config.enable_per_target_runtime_dir:
57-
if config.target_arch == 'i386':
58-
config.compiler_rt_libdir = re.sub(r'/x86_64(?=-[^/]+$)', '/i386', config.compiler_rt_libdir)
59-
elif config.target_arch == 'x86_64':
60-
config.compiler_rt_libdir = re.sub(r'/i386(?=-[^/]+$)', '/x86_64', config.compiler_rt_libdir)
61-
62-
# Set LD_LIBRARY_PATH to pick dynamic runtime up properly.
63-
push_ld_library_path(config, config.compiler_rt_libdir)
64-
6532
if not config.parallelism_group:
6633
config.parallelism_group = 'shadow-memory'

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,26 @@ def push_dynamic_library_lookup_path(config, new_path):
161161

162162
# When LLVM_ENABLE_PER_TARGET_RUNTIME_DIR=on, the initial value of
163163
# config.compiler_rt_libdir (COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR) has the
164-
# triple as the trailing path component. The value is incorrect for -m32/-m64.
165-
# Adjust config.compiler_rt accordingly.
164+
# host triple as the trailing path component. The value is incorrect for 32-bit
165+
# tests on 64-bit hosts and vice versa. Adjust config.compiler_rt_libdir
166+
# accordingly.
166167
if config.enable_per_target_runtime_dir:
167-
if "-m32" in shlex.split(config.target_cflags):
168+
if config.target_arch == "i386":
168169
config.compiler_rt_libdir = re.sub(
169170
r"/x86_64(?=-[^/]+$)", "/i386", config.compiler_rt_libdir
170171
)
171-
elif "-m64" in shlex.split(config.target_cflags):
172+
elif config.target_arch == "x86_64":
172173
config.compiler_rt_libdir = re.sub(
173174
r"/i386(?=-[^/]+$)", "/x86_64", config.compiler_rt_libdir
174175
)
175-
176+
if config.target_arch == "sparc":
177+
config.compiler_rt_libdir = re.sub(
178+
r"/sparcv9(?=-[^/]+$)", "/sparc", config.compiler_rt_libdir
179+
)
180+
elif config.target_arch == "sparcv9":
181+
config.compiler_rt_libdir = re.sub(
182+
r"/sparc(?=-[^/]+$)", "/sparcv9", config.compiler_rt_libdir
183+
)
176184

177185
# Check if the test compiler resource dir matches the local build directory
178186
# (which happens with -DLLVM_ENABLE_PROJECTS=clang;compiler-rt) or if we are

0 commit comments

Comments
 (0)