Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ jobs:
- job_name: Linux aarch64
os: ubuntu-22.04-arm
arch: aarch64
base_cmake_flags: >-
-DCOMPILER_RT_LIBDIR_OS=aarch64-unknown-linux-gnu
extra_cmake_flags: >-
-DCMAKE_C_COMPILER=clang
-DCMAKE_CXX_COMPILER=clang++
Expand All @@ -52,7 +50,6 @@ jobs:
container_image: alpine:3.21
arch: x86_64
base_cmake_flags: >-
-DCOMPILER_RT_LIBDIR_OS=linux
-DLDC_INSTALL_LLVM_RUNTIME_LIBS_ARCH=x86_64
-DLLVM_IS_SHARED=OFF
-DLDC_ENABLE_PLUGINS=OFF
Expand Down Expand Up @@ -261,7 +258,6 @@ jobs:
arch: aarch64
android_x86_arch: x86_64
extra_cmake_flags: >-
-DCOMPILER_RT_LIBDIR_OS=linux
-DLDC_INSTALL_LLVM_RUNTIME_LIBS_ARCH=aarch64-android

name: ${{ matrix.job_name }}
Expand Down
14 changes: 13 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -822,13 +822,25 @@ endif()
set(COMPILER_RT_LIBDIR "${COMPILER_RT_LIBDIR}/lib")
if(APPLE)
set(COMPILER_RT_LIBDIR "${COMPILER_RT_LIBDIR}/darwin")
elseif(ANDROID)
set(COMPILER_RT_LIBDIR "${COMPILER_RT_LIBDIR}/linux")
elseif(UNIX)
set(COMPILER_RT_LIBDIR_OS_DEFAULT "x86_64-unknown-linux-gnu")
set(COMPILER_RT_LIBDIR_OS_DEFAULT "${LLVM_HOST_TARGET}") # default when building compiler-rt alongside LLVM
if(NOT EXISTS "${COMPILER_RT_LIBDIR}/${COMPILER_RT_LIBDIR_OS_DEFAULT}")
# default when building compiler-rt separately: OS name alone in lowercase
string(TOLOWER "${CMAKE_SYSTEM_NAME}" lowercase_CMAKE_SYSTEM_NAME)
if(EXISTS "${COMPILER_RT_LIBDIR}/${lowercase_CMAKE_SYSTEM_NAME}")
set(COMPILER_RT_LIBDIR_OS_DEFAULT "${lowercase_CMAKE_SYSTEM_NAME}")
endif()
endif()
set(COMPILER_RT_LIBDIR_OS "${COMPILER_RT_LIBDIR_OS_DEFAULT}" CACHE STRING "Non-Mac Posix: OS used as directory name for the compiler-rt source libraries, e.g., 'freebsd'.")
set(COMPILER_RT_LIBDIR "${COMPILER_RT_LIBDIR}/${COMPILER_RT_LIBDIR_OS}")
elseif(WIN32)
set(COMPILER_RT_LIBDIR "${COMPILER_RT_LIBDIR}/windows")
endif()
if(NOT EXISTS "${COMPILER_RT_LIBDIR}")
message(WARNING "Expected compiler-rt directory '${COMPILER_RT_LIBDIR}' does not exist. To include PGO and sanitizers support, please set COMPILER_RT_LIBDIR_OS to the correct last component of this path.")
endif()
if(LLVM_IS_SHARED)
set(LDC_INSTALL_LLVM_RUNTIME_LIBS_DEFAULT OFF)
else()
Expand Down
1 change: 1 addition & 0 deletions cmake/Modules/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ else()
llvm_set(INCLUDE_DIRS includedir true)
llvm_set(ROOT_DIR prefix true)
llvm_set(ENABLE_ASSERTIONS assertion-mode)
llvm_set(HOST_TARGET host-target)

# The LLVM version string _may_ contain a git/svn suffix, so match only the x.y.z part
string(REGEX MATCH "^[0-9]+[.][0-9]+[.][0-9]+" LLVM_VERSION_BASE_STRING "${LLVM_VERSION_STRING}")
Expand Down
43 changes: 27 additions & 16 deletions driver/linker-gcc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,9 @@ bool ArgsBuilder::isLldDefaultLinker() {
// Returns the arch name as used in the compiler_rt libs.
// FIXME: implement correctly for non-x86 platforms (e.g. ARM)
// See clang/lib/Driver/Toolchain.cpp.
llvm::StringRef getCompilerRTArchName(const llvm::Triple &triple) {
return triple.getArchName();
std::string getCompilerRTArchName(const llvm::Triple &triple) {
llvm::StringRef archName = triple.getArchName();
return (triple.isAndroid() ? archName + "-android" : archName).str();
}

// Appends arch suffix and extension.
Expand All @@ -269,26 +270,36 @@ std::string getCompilerRTLibFilename(const llvm::Twine &name,
// See clang/lib/Driver/Toolchain.cpp.
std::vector<std::string> getRelativeClangCompilerRTLibPath(
const llvm::Twine &name, const llvm::Triple &triple, bool sharedLibrary) {
llvm::StringRef OSName = triple.isOSDarwin() ? "darwin"
: triple.isOSFreeBSD() ? "freebsd"
: triple.getOSName();

auto llvm_major_version =
llvm::StringRef(ldc::llvm_version_base).take_until([](char c) {
return c == '.';
});
LLSmallVector<llvm::StringRef, 2> llvmVersionCandidates = {
ldc::llvm_version_base, llvm_major_version};

std::string relPath = (llvm::Twine("clang/") + ldc::llvm_version_base +
"/lib/" + OSName + "/" + name)
.str();
std::string relPath_llvm_major_version =
(llvm::Twine("clang/") + llvm_major_version + "/lib/" + OSName + "/" +
name)
.str();
LLSmallVector<llvm::StringRef, 2> osNameCandidates;
if (triple.isOSDarwin()) {
osNameCandidates.emplace_back("darwin");
} else if (triple.isAndroid()) {
osNameCandidates.emplace_back("linux");
} else {
osNameCandidates.emplace_back(triple.str());
Copy link
Member Author

@kinke kinke Apr 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be required for the FreeBSD LLVM 19 port at least.

// using getOSTypeName() to avoid any OS version substring
osNameCandidates.emplace_back(llvm::Triple::getOSTypeName(triple.getOS()));
}

return {getCompilerRTLibFilename(relPath, triple, sharedLibrary),
getCompilerRTLibFilename(relPath_llvm_major_version, triple,
sharedLibrary)};
std::vector<std::string> r;
for (auto osName : osNameCandidates) {
for (auto llvmVersion : llvmVersionCandidates) {
std::string relPath =
(llvm::Twine("clang/") + llvmVersion + "/lib/" + osName + "/" + name)
.str();

r.push_back(getCompilerRTLibFilename(relPath, triple, sharedLibrary));
}
}

return r;
}

void appendFullLibPathCandidates(std::vector<std::string> &paths,
Expand Down
Loading