[PATCH] D58014: [msan][test] Unset LD_LIBRARY_PATH to avoid un-sanitized libc++

Jonas Hahnfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 10 03:58:27 PST 2019


Hahnfeld created this revision.
Hahnfeld added reviewers: phosek, vitalybuka, eugenis.
Herald added subscribers: llvm-commits, Sanitizers, mgorny.
Herald added a reviewer: EricWF.
Herald added projects: LLVM, Sanitizers.

This is another attempt to solve the issues mentioned in D42390 <https://reviews.llvm.org/D42390>: If there is
a libc++.so in LD_LIBRARY_PATH, it will be preferred over rpath set by lld
which uses DT_RUNPATH instead of DT_RPATH (called "new-dtags"). That causes
problems because the libc++ from LD_LIBRARY_PATH is not instrumented for use
with msan which breaks the unit tests.

There are two solutions:

1. Pass --disable-new-dtags but that's not really great, especially going forward.
2. Unset LD_LIBRARY_PATH when executing the tests. This needs to be done with some care to make sure that the compiled unit tests can indeed run without the need for any external library.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D58014

Files:
  compiler-rt/lib/msan/tests/CMakeLists.txt
  compiler-rt/test/msan/Unit/lit.site.cfg.in


Index: compiler-rt/test/msan/Unit/lit.site.cfg.in
===================================================================
--- compiler-rt/test/msan/Unit/lit.site.cfg.in
+++ compiler-rt/test/msan/Unit/lit.site.cfg.in
@@ -11,3 +11,6 @@
 # FIXME: Don't use hardcoded path to MSan unit tests.
 config.test_exec_root = "@COMPILER_RT_BINARY_DIR@/lib/msan/tests"
 config.test_source_root = config.test_exec_root
+
+# Clean LD_LIBRARY_PATH to avoid using un-sanitized libc++ versions.
+config.environment['LD_LIBRARY_PATH'] = ''
Index: compiler-rt/lib/msan/tests/CMakeLists.txt
===================================================================
--- compiler-rt/lib/msan/tests/CMakeLists.txt
+++ compiler-rt/lib/msan/tests/CMakeLists.txt
@@ -114,12 +114,14 @@
   endif()
   get_target_flags_for_arch(${arch} TARGET_LINK_FLAGS)
   add_compiler_rt_test(MsanUnitTests "Msan-${arch}${kind}-Test" ${arch}
-    OBJECTS ${MSAN_TEST_OBJECTS} ${MSAN_LIBCXX_SO}
+    OBJECTS ${MSAN_TEST_OBJECTS} "${MSAN_LIBCXX_SO_DIR}/libc++.so"
     DEPS ${MSAN_TEST_DEPS}
     LINK_FLAGS ${MSAN_UNITTEST_LINK_FLAGS}
                ${TARGET_LINK_FLAGS}
+               "-L${MSAN_LIBCXX_SO_DIR}"
                "-Wl,-rpath=${CMAKE_CURRENT_BINARY_DIR}"
-               "-Wl,-rpath=${LIBCXX_PREFIX}/lib")
+               "-Wl,-rpath=${MSAN_LIBCXX_SO_DIR}"
+               "-Wl,-rpath=${LLVM_LIBRARY_OUTPUT_INTDIR}")
 endmacro()
 
 # We should only build MSan unit tests if we can build instrumented libcxx.
@@ -131,7 +133,7 @@
       DEPS ${MSAN_RUNTIME_LIBRARIES}
       CFLAGS ${MSAN_LIBCXX_CFLAGS} ${TARGET_CFLAGS}
       USE_TOOLCHAIN)
-    set(MSAN_LIBCXX_SO ${LIBCXX_PREFIX}/lib/libc++.so)
+    set(MSAN_LIBCXX_SO_DIR ${LIBCXX_PREFIX}/lib/)
 
     add_msan_tests_for_arch(${arch} "" "")
     add_msan_tests_for_arch(${arch} "-with-call"


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58014.186148.patch
Type: text/x-patch
Size: 1805 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190210/40f95dfe/attachment.bin>


More information about the llvm-commits mailing list