[compiler-rt] r335809 - Support for multiarch runtimes layout

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 27 20:11:53 PDT 2018


Author: phosek
Date: Wed Jun 27 20:11:52 2018
New Revision: 335809

URL: http://llvm.org/viewvc/llvm-project?rev=335809&view=rev
Log:
Support for multiarch runtimes layout

This change adds a support for multiarch style runtimes layout, so in
addition to the existing layout where runtimes get installed to:

lib/clang/$version/lib/$os

Clang now allows runtimes to be installed to:

lib/clang/$version/$target/lib

This also includes libc++, libc++abi and libunwind; today those are
assumed to be in Clang library directory built for host, with the
new layout it is possible to install libc++, libc++abi and libunwind
into the runtime directory built for different targets.

The use of new layout is enabled by setting the
LLVM_ENABLE_RUNTIME_TARGET_DIR CMake variable and is supported by both
projects and runtimes layouts. The runtimes CMake build has been further
modified to use the new layout when building runtimes for multiple
targets.

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

Modified:
    compiler-rt/trunk/CMakeLists.txt
    compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
    compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake
    compiler-rt/trunk/cmake/Modules/SanitizerUtils.cmake
    compiler-rt/trunk/cmake/base-config-ix.cmake
    compiler-rt/trunk/cmake/config-ix.cmake
    compiler-rt/trunk/test/asan/lit.cfg
    compiler-rt/trunk/test/builtins/Unit/lit.cfg
    compiler-rt/trunk/test/fuzzer/lit.cfg
    compiler-rt/trunk/test/fuzzer/lit.site.cfg.in
    compiler-rt/trunk/test/lit.common.configured.in
    compiler-rt/trunk/test/scudo/lit.cfg
    compiler-rt/trunk/test/xray/lit.cfg

Modified: compiler-rt/trunk/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/CMakeLists.txt?rev=335809&r1=335808&r2=335809&view=diff
==============================================================================
--- compiler-rt/trunk/CMakeLists.txt (original)
+++ compiler-rt/trunk/CMakeLists.txt Wed Jun 27 20:11:52 2018
@@ -102,6 +102,8 @@ pythonize_bool(ANDROID)
 set(COMPILER_RT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 set(COMPILER_RT_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
 
+pythonize_bool(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
+
 # We support running instrumented tests when we're not cross compiling
 # and target a UNIX-like system or Windows.
 # We can run tests on Android even when we are cross-compiling.

Modified: compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake?rev=335809&r1=335808&r2=335809&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/AddCompilerRT.cmake Wed Jun 27 20:11:52 2018
@@ -109,10 +109,14 @@ function(add_asm_sources output)
 endfunction()
 
 macro(set_output_name output name arch)
-  if(ANDROID AND ${arch} STREQUAL "i386")
-    set(${output} "${name}-i686${COMPILER_RT_OS_SUFFIX}")
+  if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
+    set(${output} ${name})
   else()
-    set(${output} "${name}-${arch}${COMPILER_RT_OS_SUFFIX}")
+    if(ANDROID AND ${arch} STREQUAL "i386")
+      set(${output} "${name}-i686${COMPILER_RT_OS_SUFFIX}")
+    else()
+      set(${output} "${name}-${arch}${COMPILER_RT_OS_SUFFIX}")
+    endif()
   endif()
 endmacro()
 
@@ -168,6 +172,8 @@ function(add_compiler_rt_runtime name ty
         set(output_name_${libname} ${libname}${COMPILER_RT_OS_SUFFIX})
         set(sources_${libname} ${LIB_SOURCES})
         format_object_libs(sources_${libname} ${os} ${LIB_OBJECT_LIBS})
+        get_compiler_rt_output_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} output_dir_${libname})
+        get_compiler_rt_install_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} install_dir_${libname})
       endif()
     endforeach()
   else()
@@ -193,6 +199,8 @@ function(add_compiler_rt_runtime name ty
       format_object_libs(sources_${libname} ${arch} ${LIB_OBJECT_LIBS})
       set(libnames ${libnames} ${libname})
       set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS} ${NO_LTO_FLAGS} ${LIB_CFLAGS})
+      get_compiler_rt_output_dir(${arch} output_dir_${libname})
+      get_compiler_rt_install_dir(${arch} install_dir_${libname})
     endforeach()
   endif()
 
@@ -245,7 +253,7 @@ function(add_compiler_rt_runtime name ty
     set_target_link_flags(${libname} ${extra_link_flags_${libname}})
     set_property(TARGET ${libname} APPEND PROPERTY
                 COMPILE_DEFINITIONS ${LIB_DEFS})
-    set_target_output_directories(${libname} ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+    set_target_output_directories(${libname} ${output_dir_${libname}})
     set_target_properties(${libname} PROPERTIES
         OUTPUT_NAME ${output_name_${libname}})
     set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Runtime")
@@ -270,11 +278,11 @@ function(add_compiler_rt_runtime name ty
       endif()
     endif()
     install(TARGETS ${libname}
-      ARCHIVE DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
+      ARCHIVE DESTINATION ${install_dir_${libname}}
               ${COMPONENT_OPTION}
-      LIBRARY DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
+      LIBRARY DESTINATION ${install_dir_${libname}}
               ${COMPONENT_OPTION}
-      RUNTIME DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}
+      RUNTIME DESTINATION ${install_dir_${libname}}
               ${COMPONENT_OPTION})
 
     # We only want to generate per-library install targets if you aren't using
@@ -621,8 +629,10 @@ endfunction()
 function(configure_compiler_rt_lit_site_cfg input output)
   set_llvm_build_mode()
 
+  get_compiler_rt_output_dir(${COMPILER_RT_DEFAULT_TARGET_ARCH} output_dir)
+
   string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} COMPILER_RT_RESOLVED_TEST_COMPILER ${COMPILER_RT_TEST_COMPILER})
-  string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR ${COMPILER_RT_LIBRARY_OUTPUT_DIR})
+  string(REPLACE ${CMAKE_CFG_INTDIR} ${LLVM_BUILD_MODE} COMPILER_RT_RESOLVED_LIBRARY_OUTPUT_DIR ${output_dir})
 
   configure_lit_site_cfg(${input} ${output})
 endfunction()

Modified: compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake?rev=335809&r1=335808&r2=335809&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/CompilerRTUtils.cmake Wed Jun 27 20:11:52 2018
@@ -314,3 +314,33 @@ function(filter_builtin_sources output_v
   endforeach ()
   set(${output_var} ${intermediate} PARENT_SCOPE)
 endfunction()
+
+function(get_compiler_rt_target arch variable)
+  if(ANDROID AND ${arch} STREQUAL "i386")
+    set(target "i686${COMPILER_RT_OS_SUFFIX}-${COMPILER_RT_DEFAULT_TARGET_OS}")
+  else()
+    set(target "${arch}-${COMPILER_RT_DEFAULT_TARGET_OS}")
+  endif()
+  if(COMPILER_RT_DEFAULT_TARGET_ABI)
+    set(target "${target}-${COMPILER_RT_DEFAULT_TARGET_ABI}")
+  endif()
+  set(${variable} ${target} PARENT_SCOPE)
+endfunction()
+
+function(get_compiler_rt_install_dir arch install_dir)
+  if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+    get_compiler_rt_target(${arch} target)
+    set(${install_dir} ${COMPILER_RT_INSTALL_PATH}/${target}/lib PARENT_SCOPE)
+  else()
+    set(${install_dir} ${COMPILER_RT_LIBRARY_INSTALL_DIR} PARENT_SCOPE)
+  endif()
+endfunction()
+
+function(get_compiler_rt_output_dir arch output_dir)
+  if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+    get_compiler_rt_target(${arch} target)
+    set(${output_dir} ${COMPILER_RT_OUTPUT_DIR}/${target}/lib PARENT_SCOPE)
+  else()
+    set(${output_dir} ${COMPILER_RT_LIBRARY_OUTPUT_DIR} PARENT_SCOPE)
+  endif()
+endfunction()

Modified: compiler-rt/trunk/cmake/Modules/SanitizerUtils.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/Modules/SanitizerUtils.cmake?rev=335809&r1=335808&r2=335809&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/Modules/SanitizerUtils.cmake (original)
+++ compiler-rt/trunk/cmake/Modules/SanitizerUtils.cmake Wed Jun 27 20:11:52 2018
@@ -1,3 +1,5 @@
+include(CompilerRTUtils)
+
 set(SANITIZER_GEN_DYNAMIC_LIST
   ${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common/scripts/gen_dynamic_list.py)
 
@@ -37,9 +39,9 @@ macro(add_sanitizer_rt_symbols name)
     add_custom_target(${target_name}-symbols ALL
       DEPENDS ${stamp}
       SOURCES ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA})
-
+    get_compiler_rt_install_dir(${arch} install_dir)
     install(FILES $<TARGET_FILE:${target_name}>.syms
-            DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR})
+            DESTINATION ${install_dir})
     if(ARG_PARENT_TARGET)
       add_dependencies(${ARG_PARENT_TARGET} ${target_name}-symbols)
     endif()

Modified: compiler-rt/trunk/cmake/base-config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/base-config-ix.cmake?rev=335809&r1=335808&r2=335809&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/base-config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/base-config-ix.cmake Wed Jun 27 20:11:52 2018
@@ -76,10 +76,17 @@ endif()
 if(NOT DEFINED COMPILER_RT_OS_DIR)
   string(TOLOWER ${CMAKE_SYSTEM_NAME} COMPILER_RT_OS_DIR)
 endif()
-set(COMPILER_RT_LIBRARY_OUTPUT_DIR
-  ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR})
-set(COMPILER_RT_LIBRARY_INSTALL_DIR
-  ${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR})
+if(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR AND NOT APPLE)
+  set(COMPILER_RT_LIBRARY_OUTPUT_DIR
+    ${COMPILER_RT_OUTPUT_DIR})
+  set(COMPILER_RT_LIBRARY_INSTALL_DIR
+    ${COMPILER_RT_INSTALL_PATH})
+else(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR)
+  set(COMPILER_RT_LIBRARY_OUTPUT_DIR
+    ${COMPILER_RT_OUTPUT_DIR}/lib/${COMPILER_RT_OS_DIR})
+  set(COMPILER_RT_LIBRARY_INSTALL_DIR
+    ${COMPILER_RT_INSTALL_PATH}/lib/${COMPILER_RT_OS_DIR})
+endif()
 
 if(APPLE)
   # On Darwin if /usr/include doesn't exist, the user probably has Xcode but not

Modified: compiler-rt/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/cmake/config-ix.cmake?rev=335809&r1=335808&r2=335809&view=diff
==============================================================================
--- compiler-rt/trunk/cmake/config-ix.cmake (original)
+++ compiler-rt/trunk/cmake/config-ix.cmake Wed Jun 27 20:11:52 2018
@@ -384,7 +384,6 @@ if(APPLE)
   # for list_intersect
   include(CompilerRTUtils)
 
-
   list_intersect(SANITIZER_COMMON_SUPPORTED_ARCH
     ALL_SANITIZER_COMMON_SUPPORTED_ARCH
     COMPILER_RT_SUPPORTED_ARCH

Modified: compiler-rt/trunk/test/asan/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/asan/lit.cfg?rev=335809&r1=335808&r2=335809&view=diff
==============================================================================
--- compiler-rt/trunk/test/asan/lit.cfg (original)
+++ compiler-rt/trunk/test/asan/lit.cfg Wed Jun 27 20:11:52 2018
@@ -101,7 +101,7 @@ config.substitutions.append( ("%clang ",
 config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) )
 config.substitutions.append( ("%clang_asan ", build_invocation(clang_asan_cflags)) )
 config.substitutions.append( ("%clangxx_asan ", build_invocation(clang_asan_cxxflags)) )
-config.substitutions.append( ("%shared_libasan", "libclang_rt.asan-%s.so" % config.target_arch))
+config.substitutions.append( ("%shared_libasan", "libclang_rt.asan%s.so" % config.target_suffix))
 if config.asan_dynamic:
   config.substitutions.append( ("%clang_asan_static ", build_invocation(clang_asan_static_cflags)) )
   config.substitutions.append( ("%clangxx_asan_static ", build_invocation(clang_asan_static_cxxflags)) )
@@ -124,7 +124,7 @@ if platform.system() == 'Windows':
   clang_cl_asan_invocation = clang_cl_asan_invocation.replace("clang.exe","clang-cl.exe")
   config.substitutions.append( ("%clang_cl_asan ", clang_cl_asan_invocation) )
 
-  base_lib = os.path.join(config.compiler_rt_libdir, "clang_rt.asan%%s-%s.lib" % config.target_arch)
+  base_lib = os.path.join(config.compiler_rt_libdir, "clang_rt.asan%%s%s.lib" % config.target_suffix)
   config.substitutions.append( ("%asan_lib", base_lib % "") )
   config.substitutions.append( ("%asan_cxx_lib", base_lib % "_cxx") )
   config.substitutions.append( ("%asan_dll_thunk", base_lib % "_dll_thunk") )

Modified: compiler-rt/trunk/test/builtins/Unit/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/builtins/Unit/lit.cfg?rev=335809&r1=335808&r2=335809&view=diff
==============================================================================
--- compiler-rt/trunk/test/builtins/Unit/lit.cfg (original)
+++ compiler-rt/trunk/test/builtins/Unit/lit.cfg Wed Jun 27 20:11:52 2018
@@ -26,12 +26,12 @@ config.test_source_root = os.path.dirnam
 # Path to the static library
 is_msvc = get_required_attr(config, "builtins_is_msvc")
 if is_msvc:
-  base_lib = os.path.join(config.compiler_rt_libdir, "clang_rt.builtins-%s.lib "
-                          % config.target_arch)
+  base_lib = os.path.join(config.compiler_rt_libdir, "clang_rt.builtins%s.lib "
+                          % config.target_suffix)
   config.substitutions.append( ("%librt ", base_lib) )
 else:
-  base_lib = os.path.join(config.compiler_rt_libdir, "libclang_rt.builtins-%s.a"
-                          % config.target_arch)
+  base_lib = os.path.join(config.compiler_rt_libdir, "libclang_rt.builtins%s.a"
+                          % config.target_suffix)
   config.substitutions.append( ("%librt ", base_lib + ' -lc -lm ') )
 
 builtins_source_dir = os.path.join(

Modified: compiler-rt/trunk/test/fuzzer/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/lit.cfg?rev=335809&r1=335808&r2=335809&view=diff
==============================================================================
--- compiler-rt/trunk/test/fuzzer/lit.cfg (original)
+++ compiler-rt/trunk/test/fuzzer/lit.cfg Wed Jun 27 20:11:52 2018
@@ -53,10 +53,10 @@ def generate_compiler_cmd(is_cpp=True, f
   compiler_cmd = config.clang
   extra_cmd = config.target_flags
   if config.clang and config.stdlib == 'libc++':
-    link_cmd = '-stdlib=libc++ -Wl,-rpath=%s' % config.llvm_library_dir
+    link_cmd = '-stdlib=libc++ -Wl,-rpath=%s' % config.runtime_library_dir
   elif config.clang and config.stdlib == 'static-libc++':
     link_cmd = '-stdlib=libc++ -lc++abi -static-libstdc++ -Wl,-rpath=%s' % (
-        config.llvm_library_dir)
+        config.runtime_library_dir)
   elif any(x in config.target_triple for x in ('darwin', 'freebsd')):
     link_cmd = '-lc++'
   else:

Modified: compiler-rt/trunk/test/fuzzer/lit.site.cfg.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/fuzzer/lit.site.cfg.in?rev=335809&r1=335808&r2=335809&view=diff
==============================================================================
--- compiler-rt/trunk/test/fuzzer/lit.site.cfg.in (original)
+++ compiler-rt/trunk/test/fuzzer/lit.site.cfg.in Wed Jun 27 20:11:52 2018
@@ -18,4 +18,9 @@ config.target_triple = "@TARGET_TRIPLE@"
 lit_config.load_config(config,
     "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
 
+if config.enable_per_target_runtime_dir:
+  config.runtime_library_dir = config.compiler_rt_libdir
+else:
+  config.runtime_library_dir = "@LLVM_LIBRARY_DIR@"
+
 lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")

Modified: compiler-rt/trunk/test/lit.common.configured.in
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/lit.common.configured.in?rev=335809&r1=335808&r2=335809&view=diff
==============================================================================
--- compiler-rt/trunk/test/lit.common.configured.in (original)
+++ compiler-rt/trunk/test/lit.common.configured.in Wed Jun 27 20:11:52 2018
@@ -16,6 +16,7 @@ set_default("llvm_src_root", "@LLVM_MAIN
 set_default("llvm_obj_root", "@LLVM_BINARY_DIR@")
 set_default("compiler_rt_src_root", "@COMPILER_RT_SOURCE_DIR@")
 set_default("compiler_rt_obj_root", "@COMPILER_RT_BINARY_DIR@")
+set_default("enable_per_target_runtime_dir", @LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_PYBOOL@)
 set_default("llvm_tools_dir", "@LLVM_TOOLS_DIR@")
 set_default("llvm_shlib_dir", "@LLVM_LIBRARY_OUTPUT_INTDIR@")
 set_default("gold_executable", "@GOLD_EXECUTABLE@")
@@ -36,6 +37,11 @@ set_default("use_lto", config.use_thinlt
 set_default("android", @ANDROID_PYBOOL@)
 config.available_features.add('target-is-%s' % config.target_arch)
 
+if config.enable_per_target_runtime_dir:
+  set_default("target_suffix", "")
+else:
+  set_default("target_suffix", "-%s" % config.target_arch)
+
 # LLVM tools dir can be passed in lit parameters, so try to
 # apply substitution.
 try:

Modified: compiler-rt/trunk/test/scudo/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/scudo/lit.cfg?rev=335809&r1=335808&r2=335809&view=diff
==============================================================================
--- compiler-rt/trunk/test/scudo/lit.cfg (original)
+++ compiler-rt/trunk/test/scudo/lit.cfg Wed Jun 27 20:11:52 2018
@@ -9,7 +9,7 @@ config.name = 'Scudo' + config.name_suff
 config.test_source_root = os.path.dirname(__file__)
 
 # Path to the shared library
-shared_libscudo = os.path.join(config.compiler_rt_libdir, "libclang_rt.scudo-%s.so" % config.target_arch)
+shared_libscudo = os.path.join(config.compiler_rt_libdir, "libclang_rt.scudo%s.so" % config.target_suffix)
 
 # Test suffixes.
 config.suffixes = ['.c', '.cc', '.cpp']

Modified: compiler-rt/trunk/test/xray/lit.cfg
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/xray/lit.cfg?rev=335809&r1=335808&r2=335809&view=diff
==============================================================================
--- compiler-rt/trunk/test/xray/lit.cfg (original)
+++ compiler-rt/trunk/test/xray/lit.cfg Wed Jun 27 20:11:52 2018
@@ -18,9 +18,6 @@ def build_invocation(compile_flags):
 
 # Assume that llvm-xray is in the config.llvm_tools_dir.
 llvm_xray = os.path.join(config.llvm_tools_dir, 'llvm-xray')
-host_arch = config.host_arch
-if host_arch == 'amd64':
-  host_arch = 'x86_64'
 
 # Setup substitutions.
 if config.host_os == "Linux":
@@ -42,8 +39,8 @@ config.substitutions.append(
 config.substitutions.append(
     ('%xraylib',
         ('-lm -lpthread %s -lrt -L%s '
-         '-Wl,-whole-archive -lclang_rt.xray-%s -Wl,-no-whole-archive')
-        % (libdl_flag, config.compiler_rt_libdir, host_arch)))
+         '-Wl,-whole-archive -lclang_rt.xray%s -Wl,-no-whole-archive')
+        % (libdl_flag, config.compiler_rt_libdir, config.target_suffix)))
 
 # Default test suffixes.
 config.suffixes = ['.c', '.cc', '.cpp']




More information about the llvm-commits mailing list