Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -102,6 +102,8 @@ 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. Index: cmake/Modules/AddCompilerRT.cmake =================================================================== --- cmake/Modules/AddCompilerRT.cmake +++ cmake/Modules/AddCompilerRT.cmake @@ -109,10 +109,14 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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() Index: cmake/Modules/CompilerRTUtils.cmake =================================================================== --- cmake/Modules/CompilerRTUtils.cmake +++ cmake/Modules/CompilerRTUtils.cmake @@ -314,3 +314,33 @@ 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() Index: cmake/Modules/SanitizerUtils.cmake =================================================================== --- cmake/Modules/SanitizerUtils.cmake +++ cmake/Modules/SanitizerUtils.cmake @@ -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 @@ 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 $.syms - DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) + DESTINATION ${install_dir}) if(ARG_PARENT_TARGET) add_dependencies(${ARG_PARENT_TARGET} ${target_name}-symbols) endif() Index: cmake/base-config-ix.cmake =================================================================== --- cmake/base-config-ix.cmake +++ cmake/base-config-ix.cmake @@ -76,10 +76,17 @@ 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 Index: cmake/config-ix.cmake =================================================================== --- cmake/config-ix.cmake +++ cmake/config-ix.cmake @@ -384,7 +384,6 @@ # for list_intersect include(CompilerRTUtils) - list_intersect(SANITIZER_COMMON_SUPPORTED_ARCH ALL_SANITIZER_COMMON_SUPPORTED_ARCH COMPILER_RT_SUPPORTED_ARCH Index: test/asan/lit.cfg =================================================================== --- test/asan/lit.cfg +++ test/asan/lit.cfg @@ -101,7 +101,7 @@ 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 @@ 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") ) Index: test/builtins/Unit/lit.cfg =================================================================== --- test/builtins/Unit/lit.cfg +++ test/builtins/Unit/lit.cfg @@ -26,12 +26,12 @@ # 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( Index: test/fuzzer/lit.cfg =================================================================== --- test/fuzzer/lit.cfg +++ test/fuzzer/lit.cfg @@ -53,10 +53,10 @@ 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: Index: test/fuzzer/lit.site.cfg.in =================================================================== --- test/fuzzer/lit.site.cfg.in +++ test/fuzzer/lit.site.cfg.in @@ -18,4 +18,9 @@ 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") Index: test/lit.common.configured.in =================================================================== --- test/lit.common.configured.in +++ test/lit.common.configured.in @@ -16,6 +16,7 @@ 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("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: Index: test/scudo/lit.cfg =================================================================== --- test/scudo/lit.cfg +++ test/scudo/lit.cfg @@ -9,7 +9,7 @@ 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'] Index: test/xray/lit.cfg =================================================================== --- test/xray/lit.cfg +++ test/xray/lit.cfg @@ -18,9 +18,6 @@ # 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( ('%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']