mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-27 23:51:56 +00:00
[clang][compiler-rt] Support LLVM_ENABLE_PER_TARGET_RUNTIME_DIR on Arm Linux and BSD
The orginal single folder layout produced libraries in the form: lib/linux/<libname>-<archname>.a That archname for Arm depended on whether you had hard or soft float. This is sometimes shown as "arm" (soft) vs. "armhf" (hard). If this is set in a triple we do it in the final portion, the ABI. "gnueabi" for soft float, "gnueabihf" for hard float. Meaning that the expected triple is: arm-unknown-linux-gnueabihf Not this: armhf-unknown-linux-gnueabihf For the per target layout I have decided to rely on the ABI portion of the triple instead of the arch name used for the old layout (doing that would produce the invalid triple above). This means that building with triple: armv8l-unknown-linux-gnueabihf Will result in libraries in: lib/arm-unknown-linux-gnueabihf/ And clang will now know to look for "arm" instead of "armv8l". Meaning that we can share libraries between an armv8 and armv7 build as we did with the previous layout. In addition to handling spelling differences e.g. "armv8l" with an "l" on some Linux distros. compiler-rt will autodetect that the "armhf" and/or "arm" architecture can be built. We then replace the given triple's architecture with that. Then if the triple's float ABI doesn't match, we change that. That new triple is then used as the folder name. If you select to build only the given triple, with COMPILER_RT_DEFAULT_TARGET_ONLY, compiler-rt will not autodetect the architecture and for that I assume you know what you're doing. In that case the library path will use the unomdified triple. From what I can tell, this is how most large builds e.g Android and Arm's Embedded Toolchain for llvm do things. I assume that big endian "armeb" builds would end up doing this too. Bare metal builds will not be using per target runtime dirs so they remain as they were. Depends on D139536 Reviewed By: MaskRay, phosek Differential Revision: https://reviews.llvm.org/D140011
This commit is contained in:
parent
a6f66d57e1
commit
cd173cbd7c
@ -578,6 +578,27 @@ ToolChain::path_list ToolChain::getRuntimePaths() const {
|
||||
|
||||
addPathForTriple(getTriple());
|
||||
|
||||
// When building with per target runtime directories, various ways of naming
|
||||
// the Arm architecture may have been normalised to simply "arm".
|
||||
// For example "armv8l" (Armv8 AArch32 little endian) is replaced with "arm".
|
||||
// Since an armv8l system can use libraries built for earlier architecture
|
||||
// versions assuming endian and float ABI match.
|
||||
//
|
||||
// Original triple: armv8l-unknown-linux-gnueabihf
|
||||
// Runtime triple: arm-unknown-linux-gnueabihf
|
||||
//
|
||||
// We do not do this for armeb (big endian) because doing so could make us
|
||||
// select little endian libraries. In addition, all known armeb triples only
|
||||
// use the "armeb" architecture name.
|
||||
//
|
||||
// M profile Arm is bare metal and we know they will not be using the per
|
||||
// target runtime directory layout.
|
||||
if (getTriple().getArch() == Triple::arm && !getTriple().isArmMClass()) {
|
||||
llvm::Triple ArmTriple = getTriple();
|
||||
ArmTriple.setArch(Triple::arm);
|
||||
addPathForTriple(ArmTriple);
|
||||
}
|
||||
|
||||
// Android targets may include an API level at the end. We still want to fall
|
||||
// back on a path without the API level.
|
||||
if (getTriple().isAndroid() &&
|
||||
|
33
clang/test/Driver/arm-float-abi-runtime-path.c
Normal file
33
clang/test/Driver/arm-float-abi-runtime-path.c
Normal file
@ -0,0 +1,33 @@
|
||||
/// Check that libraries built with the per target runtime directory layout
|
||||
/// are selected correctly when using variations of Arm triples.
|
||||
|
||||
// REQUIRES: arm-registered-target
|
||||
|
||||
// RUN: %clang %s --target=arm-unknown-linux-gnueabihf -print-runtime-dir \
|
||||
// RUN: -resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=ARMHF %s
|
||||
/// "armv7l" should be normalised to just "arm".
|
||||
// RUN: %clang %s --target=armv7l-unknown-linux-gnueabihf -print-runtime-dir \
|
||||
// RUN: -resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=ARMHF %s
|
||||
|
||||
// RUN: %clang %s --target=arm-unknown-linux-gnueabi -print-runtime-dir \
|
||||
// RUN: -resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=ARM %s
|
||||
// RUN: %clang %s --target=armv7l-unknown-linux-gnueabi -print-runtime-dir \
|
||||
// RUN: -resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=ARM %s
|
||||
|
||||
/// armeb triples should be unmodified.
|
||||
// RUN: %clang %s --target=armeb-unknown-linux-gnueabihf -print-runtime-dir \
|
||||
// RUN: -resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=ARMEBHF %s
|
||||
// RUN: %clang %s --target=armeb-unknown-linux-gnueabi -print-runtime-dir \
|
||||
// RUN: -resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=ARMEB %s
|
||||
|
||||
// RUN: %clang %s --target=arm-pc-windows-msvc -print-runtime-dir \
|
||||
// RUN: -resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=WINDOWS %s
|
||||
/// armhf-pc... isn't recognised so just check that the float-abi option is ignored
|
||||
// RUN: %clang %s --target=arm-pc-windows-msvc -mfloat-abi=hard -print-runtime-dir \
|
||||
// RUN: -resource-dir=%S/Inputs/arm_float_abi_runtime_path 2>&1 | FileCheck -check-prefix=WINDOWS %s
|
||||
|
||||
// ARMHF: lib{{/|\\}}arm-unknown-linux-gnueabihf{{$}}
|
||||
// ARM: lib{{/|\\}}arm-unknown-linux-gnueabi{{$}}
|
||||
// ARMEBHF: lib{{/|\\}}armeb-unknown-linux-gnueabihf{{$}}
|
||||
// ARMEB: lib{{/|\\}}armeb-unknown-linux-gnueabi{{$}}
|
||||
// WINDOWS: lib{{/|\\}}arm-pc-windows-msvc{{$}}
|
@ -433,6 +433,25 @@ function(get_compiler_rt_target arch variable)
|
||||
string(REGEX REPLACE "mipsisa64" "mipsisa32" triple_cpu_mips "${triple_cpu}")
|
||||
string(REGEX REPLACE "mips64" "mips" triple_cpu_mips "${triple_cpu_mips}")
|
||||
set(target "${triple_cpu_mips}${triple_suffix_gnu}")
|
||||
elseif("${arch}" MATCHES "^arm")
|
||||
# Arch is arm, armhf, armv6m (anything else would come from using
|
||||
# COMPILER_RT_DEFAULT_TARGET_ONLY, which is checked above).
|
||||
if (${arch} STREQUAL "armhf")
|
||||
# If we are building for hard float but our ABI is soft float.
|
||||
if ("${triple_suffix}" MATCHES ".*eabi$")
|
||||
# Change "eabi" -> "eabihf"
|
||||
set(triple_suffix "${triple_suffix}hf")
|
||||
endif()
|
||||
# ABI is already set in the triple, don't repeat it in the architecture.
|
||||
set(arch "arm")
|
||||
else ()
|
||||
# If we are building for soft float, but the triple's ABI is hard float.
|
||||
if ("${triple_suffix}" MATCHES ".*eabihf$")
|
||||
# Change "eabihf" -> "eabi"
|
||||
string(REGEX REPLACE "hf$" "" triple_suffix "${triple_suffix}")
|
||||
endif()
|
||||
endif()
|
||||
set(target "${arch}${triple_suffix}")
|
||||
else()
|
||||
set(target "${arch}${triple_suffix}")
|
||||
endif()
|
||||
|
@ -817,8 +817,7 @@ endif()
|
||||
set(LLVM_TARGET_TRIPLE_ENV CACHE STRING "The name of environment variable to override default target. Disabled by blank.")
|
||||
mark_as_advanced(LLVM_TARGET_TRIPLE_ENV)
|
||||
|
||||
# Per target dir not yet supported on Arm 32 bit due to arm vs armhf handling
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "BSD|Linux" AND NOT CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
|
||||
if(CMAKE_SYSTEM_NAME MATCHES "BSD|Linux")
|
||||
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default ON)
|
||||
else()
|
||||
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR_default OFF)
|
||||
|
Loading…
Reference in New Issue
Block a user