diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake --- a/compiler-rt/cmake/config-ix.cmake +++ b/compiler-rt/cmake/config-ix.cmake @@ -157,6 +157,19 @@ check_linker_flag("-Wl,-z,text" COMPILER_RT_HAS_Z_TEXT) check_linker_flag("-fuse-ld=lld" COMPILER_RT_HAS_FUSE_LD_LLD_FLAG) +set(VERS_COMPAT_OPTION "-Wl,-z,gnu-version-script-compat") +check_linker_flag("${VERS_COMPAT_OPTION}" COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT) + +set(DUMMY_VERS ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/dummy.vers) +file(WRITE ${DUMMY_VERS} "{};") +set(VERS_OPTION "-Wl,--version-script,${DUMMY_VERS}") +if(COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT) + # Solaris 11.4 ld only supports --version-script with + # -z gnu-version-script-compat. + string(APPEND VERS_OPTION " ${VERS_COMPAT_OPTION}") +endif() +check_linker_flag("${VERS_OPTION}" COMPILER_RT_HAS_VERSION_SCRIPT) + if(ANDROID) check_linker_flag("-Wl,-z,global" COMPILER_RT_HAS_Z_GLOBAL) check_library_exists(log __android_log_write "" COMPILER_RT_HAS_LIBLOG) diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt --- a/compiler-rt/lib/asan/CMakeLists.txt +++ b/compiler-rt/lib/asan/CMakeLists.txt @@ -224,7 +224,7 @@ PARENT_TARGET asan) foreach(arch ${ASAN_SUPPORTED_ARCH}) - if (UNIX) + if (UNIX AND COMPILER_RT_HAS_VERSION_SCRIPT) add_sanitizer_rt_version_list(clang_rt.asan-dynamic-${arch} LIBS clang_rt.asan-${arch} clang_rt.asan_cxx-${arch} EXTRA asan.syms.extra) @@ -232,7 +232,7 @@ -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.asan-dynamic-${arch}.vers) # The Solaris 11.4 linker supports a subset of GNU ld version scripts, # but requires a special option to enable it. - if (OS_NAME MATCHES "SunOS") + if (COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT) list(APPEND VERSION_SCRIPT_FLAG -Wl,-z,gnu-version-script-compat) endif() set_property(SOURCE diff --git a/compiler-rt/lib/ubsan/CMakeLists.txt b/compiler-rt/lib/ubsan/CMakeLists.txt --- a/compiler-rt/lib/ubsan/CMakeLists.txt +++ b/compiler-rt/lib/ubsan/CMakeLists.txt @@ -200,7 +200,7 @@ CFLAGS ${UBSAN_CXXFLAGS} PARENT_TARGET ubsan) - if (FUCHSIA OR UNIX) + if ((FUCHSIA OR UNIX) AND COMPILER_RT_HAS_VERSION_SCRIPT) file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/dummy.cpp "") add_compiler_rt_object_libraries(RTUbsan_dynamic_version_script_dummy ARCHS ${UBSAN_SUPPORTED_ARCH} @@ -216,7 +216,7 @@ -Wl,--version-script,${CMAKE_CURRENT_BINARY_DIR}/clang_rt.ubsan_standalone-dynamic-${arch}.vers) # The Solaris 11.4 linker supports a subset of GNU ld version scripts, # but requires a special option to enable it. - if (OS_NAME MATCHES "SunOS") + if (COMPILER_RT_HAS_GNU_VERSION_SCRIPT_COMPAT) list(APPEND VERSION_SCRIPT_FLAG -Wl,-z,gnu-version-script-compat) endif() set_property(SOURCE