-
Notifications
You must be signed in to change notification settings - Fork 12k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CompilerRT: Normalize COMPILER_RT_DEFAULT_TARGET_TRIPLE #89234
Conversation
If LLVM is configured with -DLLVM_DEFAULT_TARGET_TRIPLE, or compiler_rt is configured with -DCOMPILER_RT_DEFAULT_TARGET_TRIPLE, while the argument is not normalized, such as Debian-style vendor-less triple, clang will try to find libclang_rt in lib/<normalized_triple>, while libclang_rt is placed into lib/<triple_arg>. Let's also place libclang_rt into lib/<normalized_triple>.
@llvm/pr-subscribers-libcxx Author: YunQiang Su (wzssyqa) ChangesIf LLVM is configured with -DLLVM_DEFAULT_TARGET_TRIPLE, or compiler_rt is configured with -DCOMPILER_RT_DEFAULT_TARGET_TRIPLE, while the argument is not normalized, such as Debian-style vendor-less triple, clang will try to find libclang_rt in lib/<normalized_triple>, while libclang_rt is placed into lib/<triple_arg>. Let's also place libclang_rt into lib/<normalized_triple>. Full diff: https://github.com/llvm/llvm-project/pull/89234.diff 2 Files Affected:
diff --git a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
index e8e5f612d5b03c..a6c6ef93500d53 100644
--- a/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
+++ b/compiler-rt/cmake/Modules/CompilerRTUtils.cmake
@@ -368,6 +368,12 @@ macro(construct_compiler_rt_default_triple)
"Default triple for which compiler-rt runtimes will be built.")
endif()
+ if ("${CMAKE_C_COMPILER_ID}" MATCHES "Clang")
+ execute_process(COMMAND ${CMAKE_C_COMPILER} --target=${COMPILER_RT_DEFAULT_TARGET_TRIPLE} -print-target-triple
+ OUTPUT_VARIABLE COMPILER_RT_DEFAULT_TARGET_TRIPLE
+ OUTPUT_STRIP_TRAILING_WHITESPACE)
+ endif()
+
string(REPLACE "-" ";" LLVM_TARGET_TRIPLE_LIST ${COMPILER_RT_DEFAULT_TARGET_TRIPLE})
list(GET LLVM_TARGET_TRIPLE_LIST 0 COMPILER_RT_DEFAULT_TARGET_ARCH)
diff --git a/libcxx/utils/ci/run-buildbot b/libcxx/utils/ci/run-buildbot
index 23a2a1bbbc63fa..60307a7d4f350a 100755
--- a/libcxx/utils/ci/run-buildbot
+++ b/libcxx/utils/ci/run-buildbot
@@ -217,7 +217,7 @@ function test-armv7m-picolibc() {
"${@}"
${NINJA} -vC "${BUILD_DIR}/compiler-rt" install
- mv "${BUILD_DIR}/install/lib/armv7m-none-eabi"/* "${BUILD_DIR}/install/lib"
+ mv "${BUILD_DIR}/install/lib/armv7m-none-unknown-eabi"/* "${BUILD_DIR}/install/lib"
check-runtimes
}
|
Please expand the commit message to describe your previous confusion with effective triple, and why target triple is ok. Also that this changes some folder names hence the libcxx change. So that we have an audit trail here, as it's turning out to be a tricky change. |
Thanks, this form seems to work fine for me, but I second @DavidSpickett 's requests for more elaboration on earlier attempts and what's changed from them (plus a reference to earlier PRs or commits, for review trail). |
Thanks. I updated the commit msg.
So let's have a wait about how to reproduce it, and have a test. |
@ZijunZhaoCCK said that #89150 is a invalid report. |
This change only covers compiler-rt but it should apply to all runtimes. I've made a similar change that covers all runtimes in https://reviews.llvm.org/D140925 but I forgot to land before the GitHub migration. I reuploaded that change as #89425 and I intend to land unless there are any objects, and after that we could consider undoing this change. |
What I see for baremetal builds is that a target triple of Is this intended? One consequence is that my existing cross compiler setup which uses symlinked clang binaries In response to this change I am currently building compiler-rt with an explicit triple of My expectation was that I should be able to continue to use my old |
I don't think that this PR changes the clang behavior where to search for libclang_rt.builtins. I think that your problem is about how |
What is puzzling is that it's being normalized here to
This also looks suspicious, I'm expecting |
Sound reasonable. I will try to fix |
To be clear, the libcxx change is "make it work" not "is correct". I agree with Peter that the normalisation does not look correct. |
While the normalization probably isn't right, I'm curious about how this change here affected things. As this change in itself only affected compiler-rt, not clang, it shouldn't have changed where clang looks for libraries, right? Or has something else changed that, too? I.e., even before this change, both an |
I'm unclear where the breakage happened. I was building a toolchain with something like: ARGS=(
"-DLLVM_ENABLE_RUNTIMES=compiler-rt"
"-DLLVM_BUILTIN_TARGETS=aarch64-none-elf;aarch64-unknown-linux-gnu;aarch64-unknown-linux-musl"
"-DBUILTINS_aarch64-none-elf_COMPILER_RT_SOME_FLAG=..."
"-DLLVM_RUNTIME_TARGETS=aarch64-none-elf"
"-DRUNTIMES_aarch64-none-elf_COMPILER_RT_SOME_FLAG=..."
) With recent changes landed[0], the installed paths to the binaries changed. I think a different process outside of llvm-project set up to make things work (symlinking some paths into In summary, I think the breakage is caused by this change because there exists other things in the wild which expect [0] (and I suspect this commit specifically we're commenting on but don't have absolute confirmation other than a suspicion from seeing build after the revert of this patch fix it and then it broke again after it relanded). |
Ah, I see! Right, yes, this commit will have changed where files are installed in this case.
Ok, so this is the missing clue that explains it to me. Previously, you didn't have clang actually consume the built libraries from the directory they were installed into, but moved them around into another path that clang does look in (based on another rule). The intent of this commit, was that files are installed into a pathname where clang will look automatically, provided that it is invoked with the same target triple. Previously, it did install files into a directory that clang didn't look into, and hence you need to move/symlink files around.
Hmm, right. There are a couple of different codepaths that add lookup of libraries in a bunch of different directories - some based on the full triple (e.g. what |
I've posted an RFC on the topic to discourse: https://discourse.llvm.org/t/rfc-baremetal-target-triple-normalization/78524 |
This is needed for a workaround to make sure the link later succeeds. I don't know the reason for that but it is definitely needed. llvm#89234 will/wants to correct the triple normalisation for -none- and this means that clang prior to 19, and clang 19 and above will have different answers and therefore different library paths. I don't want to bootstrap a clang just for libcxx CI, or require that anyone building for Arm do the same, so ask the compiler what the triple should be. This will be compatible with 17 and 19 when we do update to that version. I'm assuming $CC is what anyone locally would set to override the compiler, and `cc` is the binary name in our CI containers. It's not perfect but it should cover most use cases.
…90722) This is needed for a workaround to make sure the link later succeeds. I don't know the reason for that but it is definitely needed. #89234 will/wants to correct the triple normalisation for -none- and this means that clang prior to 19, and clang 19 and above will have different answers and therefore different library paths. I don't want to bootstrap a clang just for libcxx CI, or require that anyone building for Arm do the same, so ask the compiler what the triple should be. This will be compatible with 17 and 19 when we do update to that version. I'm assuming $CC is what anyone locally would set to override the compiler, and `cc` is the binary name in our CI containers. It's not perfect but it should cover most use cases.
If LLVM is configured with -DLLVM_DEFAULT_TARGET_TRIPLE, or compiler_rt is configured with -DCOMPILER_RT_DEFAULT_TARGET_TRIPLE, while the argument is not normalized, such as Debian-style vendor-less triple, clang will try to find libclang_rt in lib/<normalized_triple>, while libclang_rt is placed into lib/<triple_arg>.
Let's also place libclang_rt into lib/<normalized_triple>.
libcxx/utils/ci/run-buildbot
is also updated to usearmv7m-none-unknown-eabi
as normalized triple instead ofcurrent
armv7m-none-eabi
.ChangeLog of this PR:
This patch has been applied and revert twice:
The first try is CompilerRT: Normalize COMPILER_RT_DEFAULT_TARGET_TRIPLE #88407, and then it is found that it causes some CI failures.
https://lab.llvm.org/buildbot/#/builders/98/builds/36366
It is then resolved by another commit: 1693009
https://lab.llvm.org/buildbot/#/builders/77/builds/36372
It is caused that
COMPILER_RT_DEFAULT_TARGET_TRIPLE
is overwrite without taking care aboutCACHE
.The second try CompilerRT: Normalize COMPILER_RT_DEFAULT_TARGET_TRIPLE #88835,
resolves https://lab.llvm.org/buildbot/#/builders/77/builds/36372
and in fact only one
execute_process
is needed.Then we find some other CI failures.
https://github.com/mstorsjo/llvm-mingw/actions/runs/8730621159
https://buildkite.com/llvm-project/libcxx-ci/builds/34897#018eec06-612c-47f1-9931-d3bd88bf7ced
It is due to misunderstanding
-print-effective-triple
: which will outputthumbv7-w64-windows-gnu
forarmv7-w64-windows-gnu
or some other thumb-enabled arm triples.In fact we should use
-print-target-triple
.For armv7m-picolibc,
armv7m-none-eabi
is hardcoded in libcxx/utils/ci/run-buildbot, while in factarmv7m-none-unknown-eabi
is the real normalized triple.