[compiler-rt] 9657446 - [compiler-rt] Build with correct ABI (PR38025)
Shoaib Meenai via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 3 11:53:52 PDT 2020
Author: Riyaz V Puthiyapurayil
Date: 2020-04-03T11:53:40-07:00
New Revision: 9657446313abd4b3b44f66a30430c0d7f6ccd7b8
URL: https://github.com/llvm/llvm-project/commit/9657446313abd4b3b44f66a30430c0d7f6ccd7b8
DIFF: https://github.com/llvm/llvm-project/commit/9657446313abd4b3b44f66a30430c0d7f6ccd7b8.diff
LOG: [compiler-rt] Build with correct ABI (PR38025)
Summary:
This patch fixes [[ https://bugs.llvm.org/show_bug.cgi?id=38025 | PR38025 ]]:
Wrong ABI used when building compiler-rt
Differential Revision: https://reviews.llvm.org/D74133
Added:
Modified:
compiler-rt/CMakeLists.txt
compiler-rt/cmake/Modules/AddCompilerRT.cmake
compiler-rt/cmake/Modules/HandleCompilerRT.cmake
compiler-rt/cmake/config-ix.cmake
Removed:
################################################################################
diff --git a/compiler-rt/CMakeLists.txt b/compiler-rt/CMakeLists.txt
index bf4d2801b492..0ada717d7c77 100644
--- a/compiler-rt/CMakeLists.txt
+++ b/compiler-rt/CMakeLists.txt
@@ -413,7 +413,6 @@ append_list_if(COMPILER_RT_HAS_NODEFAULTLIBS_FLAG -nodefaultlibs SANITIZER_COMMO
append_list_if(COMPILER_RT_HAS_Z_TEXT -Wl,-z,text SANITIZER_COMMON_LINK_FLAGS)
if (COMPILER_RT_USE_BUILTINS_LIBRARY)
- list(APPEND SANITIZER_COMMON_LINK_LIBS ${COMPILER_RT_BUILTINS_LIBRARY})
string(REPLACE "-Wl,-z,defs" "" CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}")
else()
if (ANDROID)
diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
index f0c8893c42bc..83a972d443b2 100644
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
@@ -1,5 +1,6 @@
include(ExternalProject)
include(CompilerRTUtils)
+include(HandleCompilerRT)
function(set_target_output_directories target output_dir)
# For RUNTIME_OUTPUT_DIRECTORY variable, Multi-configuration generators
@@ -233,6 +234,10 @@ function(add_compiler_rt_runtime name type)
set_output_name(output_name_${libname} ${name} ${arch})
endif()
endif()
+ if(COMPILER_RT_USE_BUILTINS_LIBRARY AND NOT type STREQUAL "OBJECT")
+ get_compiler_rt_target(${arch} target)
+ find_compiler_rt_library(builtins ${target} builtins_${libname})
+ endif()
set(sources_${libname} ${LIB_SOURCES})
format_object_libs(sources_${libname} ${arch} ${LIB_OBJECT_LIBS})
set(libnames ${libnames} ${libname})
@@ -326,6 +331,9 @@ function(add_compiler_rt_runtime name type)
if(LIB_LINK_LIBS)
target_link_libraries(${libname} PRIVATE ${LIB_LINK_LIBS})
endif()
+ if(builtins_${libname})
+ target_link_libraries(${libname} PRIVATE ${builtins_${libname}})
+ endif()
if(${type} STREQUAL "SHARED")
if(COMMAND llvm_setup_rpath)
llvm_setup_rpath(${libname})
diff --git a/compiler-rt/cmake/Modules/HandleCompilerRT.cmake b/compiler-rt/cmake/Modules/HandleCompilerRT.cmake
index 61b7792789e7..ac9e0871489d 100644
--- a/compiler-rt/cmake/Modules/HandleCompilerRT.cmake
+++ b/compiler-rt/cmake/Modules/HandleCompilerRT.cmake
@@ -1,24 +1,65 @@
-function(find_compiler_rt_library name variable)
- set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${SANITIZER_COMMON_CFLAGS}
- "--rtlib=compiler-rt" "--print-libgcc-file-name")
- if (CMAKE_CXX_COMPILER_ID MATCHES Clang AND CMAKE_CXX_COMPILER_TARGET)
- list(APPEND CLANG_COMMAND "--target=${CMAKE_CXX_COMPILER_TARGET}")
+# Check if compile-rt library file path exists.
+# If found, cache the path in:
+# COMPILER_RT_LIBRARY-<name>-<target>
+# If err_flag is true OR path not found, emit a message and set:
+# COMPILER_RT_LIBRARY-<name>-<target> to NOTFOUND
+function(cache_compiler_rt_library err_flag name target library_file)
+ if(err_flag OR NOT EXISTS "${library_file}")
+ message(STATUS "Failed to find compiler-rt ${name} library for ${target}")
+ set(COMPILER_RT_LIBRARY-${name}-${target} "NOTFOUND" CACHE INTERNAL
+ "compiler-rt ${name} library for ${target}")
+ else()
+ message(STATUS "Found compiler-rt ${name} library: ${library_file}")
+ set(COMPILER_RT_LIBRARY-${name}-${target} "${library_file}" CACHE INTERNAL
+ "compiler-rt ${name} library for ${target}")
+ endif()
+endfunction()
+
+# Find the path to compiler-rt library `name` (e.g. "builtins") for
+# the specified `target` (e.g. "x86_64-linux") and return it in `variable`.
+# This calls cache_compiler_rt_library that caches the path to speed up
+# repeated invocations with the same `name` and `target`.
+function(find_compiler_rt_library name target variable)
+ if(NOT CMAKE_CXX_COMPILER_ID MATCHES Clang)
+ set(${variable} "NOTFOUND" PARENT_SCOPE)
+ return()
+ endif()
+ if (NOT target AND CMAKE_CXX_COMPILER_TARGET)
+ set(target "${CMAKE_CXX_COMPILER_TARGET}")
endif()
- get_property(SANITIZER_CXX_FLAGS CACHE CMAKE_CXX_FLAGS PROPERTY VALUE)
- string(REPLACE " " ";" SANITIZER_CXX_FLAGS "${SANITIZER_CXX_FLAGS}")
- list(APPEND CLANG_COMMAND ${SANITIZER_CXX_FLAGS})
- execute_process(
+ if(NOT DEFINED COMPILER_RT_LIBRARY-builtins-${target})
+ # If the cache variable is not defined, invoke clang and then
+ # set it with cache_compiler_rt_library.
+ set(CLANG_COMMAND ${CMAKE_CXX_COMPILER} ${SANITIZER_COMMON_FLAGS}
+ "--rtlib=compiler-rt" "-print-libgcc-file-name")
+ if(target)
+ list(APPEND CLANG_COMMAND "--target=${target}")
+ endif()
+ get_property(SANITIZER_CXX_FLAGS CACHE CMAKE_CXX_FLAGS PROPERTY VALUE)
+ string(REPLACE " " ";" SANITIZER_CXX_FLAGS "${SANITIZER_CXX_FLAGS}")
+ list(APPEND CLANG_COMMAND ${SANITIZER_CXX_FLAGS})
+ execute_process(
COMMAND ${CLANG_COMMAND}
RESULT_VARIABLE HAD_ERROR
OUTPUT_VARIABLE LIBRARY_FILE
- )
- string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE)
- file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE)
- string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}")
- if (NOT HAD_ERROR AND EXISTS "${LIBRARY_FILE}")
- message(STATUS "Found compiler-rt ${name} library: ${LIBRARY_FILE}")
- set(${variable} "${LIBRARY_FILE}" PARENT_SCOPE)
- else()
- message(STATUS "Failed to find compiler-rt ${name} library")
+ )
+ string(STRIP "${LIBRARY_FILE}" LIBRARY_FILE)
+ file(TO_CMAKE_PATH "${LIBRARY_FILE}" LIBRARY_FILE)
+ cache_compiler_rt_library(${HAD_ERROR}
+ builtins "${target}" "${LIBRARY_FILE}")
+ endif()
+ if(NOT COMPILER_RT_LIBRARY-builtins-${target})
+ set(${variable} "NOTFOUND" PARENT_SCOPE)
+ return()
+ endif()
+ if(NOT DEFINED COMPILER_RT_LIBRARY-${name}-${target})
+ # clang gives only the builtins library path. Other library paths are
+ # obtained by substituting "builtins" with ${name} in the builtins
+ # path and then checking if the resultant path exists. The result of
+ # this check is also cached by cache_compiler_rt_library.
+ set(LIBRARY_FILE "${COMPILER_RT_LIBRARY-builtins-${target}}")
+ string(REPLACE "builtins" "${name}" LIBRARY_FILE "${LIBRARY_FILE}")
+ cache_compiler_rt_library(FALSE "${name}" "${target}" "${LIBRARY_FILE}")
endif()
+ set(${variable} "${COMPILER_RT_LIBRARY-${name}-${target}}" PARENT_SCOPE)
endfunction()
diff --git a/compiler-rt/cmake/config-ix.cmake b/compiler-rt/cmake/config-ix.cmake
index 0157011d1ead..8261bc9fcdd5 100644
--- a/compiler-rt/cmake/config-ix.cmake
+++ b/compiler-rt/cmake/config-ix.cmake
@@ -16,7 +16,7 @@ endfunction()
check_library_exists(c fopen "" COMPILER_RT_HAS_LIBC)
if (COMPILER_RT_USE_BUILTINS_LIBRARY)
include(HandleCompilerRT)
- find_compiler_rt_library(builtins COMPILER_RT_BUILTINS_LIBRARY)
+ find_compiler_rt_library(builtins "" COMPILER_RT_BUILTINS_LIBRARY)
else()
if (ANDROID)
check_library_exists(gcc __gcc_personality_v0 "" COMPILER_RT_HAS_GCC_LIB)
More information about the llvm-commits
mailing list