[compiler-rt] 0b2d5fd - [compiler-rt][Sanitizer] Link sanitizer libs with -latomic on SPARC

Rainer Orth via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 27 03:30:46 PDT 2022


Author: Rainer Orth
Date: 2022-07-27T12:30:18+02:00
New Revision: 0b2d5fd48bc281af89e5e7bfa33a3054b826ed52

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

LOG: [compiler-rt][Sanitizer] Link sanitizer libs with -latomic on SPARC

When building on Linux/sparc64, the 32-bit `libclang_rt.asan.so`,
`libclang_rt.ubsan_minimal.so`, and `libclang_rt.ubsan_standalone.so`
failed to link with undefined references to 64-bit atomics, which `clang`
cannot inline.  Even D130569 <https://reviews.llvm.org/D130569> didn't help
because those libraries are linked with `-nodefaultlibs`, so dependent
libraries need to be added explicitly.

That's what this patch does.

Tested on `sparc64-unknown-linux-gnu` and `sparcv9-sun-solaris2.11`.

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

Added: 
    

Modified: 
    compiler-rt/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index 4a572bc005fe8..62737735695f2 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -479,6 +479,12 @@ append_list_if(MINGW -fms-extensions SANITIZER_COMMON_CFLAGS)
 append_list_if(C_SUPPORTS_NODEFAULTLIBS_FLAG -nodefaultlibs SANITIZER_COMMON_LINK_FLAGS)
 append_list_if(COMPILER_RT_HAS_Z_TEXT -Wl,-z,text SANITIZER_COMMON_LINK_FLAGS)
 
+# Only necessary for 32-bit SPARC.  Solaris 11.2+ ld uses -z ignore/-z record
+# natively, but supports --as-needed/--no-as-needed for GNU ld compatibility.
+if("${COMPILER_RT_DEFAULT_TARGET_ARCH}" MATCHES "sparc")
+  list(APPEND SANITIZER_COMMON_LINK_LIBS -Wl,--as-needed atomic -Wl,--no-as-needed)
+endif()
+
 if (COMPILER_RT_USE_BUILTINS_LIBRARY)
   string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
 else()


        


More information about the llvm-commits mailing list