-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[llvm] Disable HandleLLVMOptions in runtimes mode #73031
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
Conversation
runtimes/CMakeLists.txt
Outdated
@@ -151,6 +151,9 @@ endif() | |||
# Avoid checking whether the compiler is working. | |||
set(LLVM_COMPILER_CHECKED ON) | |||
|
|||
# This can be used to detect whether we're in the runtimes build. | |||
set(LLVM_RUNTIMES_BUILD ON) | |||
|
|||
# Handle common options used by all runtimes. | |||
include(AddLLVM) | |||
include(HandleLLVMOptions) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually don't know what we're picking up from HandleLLVMOptions
but it all sounds like just dangerous to do in the context of the runtimes build. A naive build locally seems to work if we remove include(HandleLLVMOptions)
entirely -- this is what I would try doing instead.
@petrhosek might know more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my first inclination, but I figured this would be the less destructive option. I'm assuming that many of these options are not required for projects that consume the LLVM static / shared libraries such as openmp
, but I don't know the intention here strictly enough to make an accurate judgement there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know for certain that I ran into a lot of issues back in the days where we used the LLVM_ENABLE_PROJECTS
build caused by the rest of LLVM sneaking in flags via these kinds of CMake files. This is actively harmful. I think it's much better to remove it if we can, and normally our CI would tell us if we missed something.
So I'd support making the naive change that takes us closer to where we should be, and then figuring out where we went wrong in case it breaks something. You can always blame it on me :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been a few years since I last looked into this, but I tried removing it (since I agree that it can be actively harmful) and the issue I hit was that many of the runtimes builds were assuming variables and options set by HandleLLVMOptions
because those were always present when building with LLVM_ENABLE_PROJECTS
.
I'm not sure how much the situation has improved since then, I expect it won't be a big issue for libunwind, libc++abi, libc++ which no longer support LLVM_ENABLE_PROJECTS
, but might still be an issue for compiler-rt and libc which do support building with LLVM_ENABLE_PROJECTS
(although I hope that won't be the case for too long).
Probably the best path forward would be to try and remove it, see what fails and address each of those cases separately. The main issue is that many of those failures would be silent (e.g. a check that was passing before might be failing now but the build itself would still continue, except the build outputs might be different).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add the include
in compiler-rt and in libc if we expect those to rely on it perhaps? For libc++, libc++abi and libunwind, I am fairly confident that if we remove it and our CI doesn't break, we're okay. It might break something, but if that's the case and if it's actively being used then we have pretty good systems in place to fix it quickly, and I'm willing to take responsibility to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was initially to unblock me on some issues with GPU compilation, but I'm happy to expand the scope if others are in agreement.
There's a handful of clang options we may want to keep to remove some regressions? Here's the set of flags that the libc
project has right now:
-fPIC
-fno-semantic-interposition
-fvisibility-inlines-hidden
-Werror=date-time
-Werror=unguarded-availability-new
-Wall -Wextra
-Wno-unused-parameter
-Wwrite-strings -Wcast-qual
-Wmissing-field-initializers
-Wimplicit-fallthrough
-Wcovered-switch-default
-Wno-noexcept-type
-Wnon-virtual-dtor
-Wdelete-non-virtual-dtor
-Wsuggest-override
-Wstring-conversion
-Wmisleading-indentation
-Wctad-maybe-unsupported
-fdiagnostics-color
-ffunction-sections
-fdata-sections
Do any of these look integral? We probably want to keep -fPIC -ffunction-sections -fdata-sections
if nothing else. Warnings should probably also be somewhat consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could add the
include
in compiler-rt and in libc if we expect those to rely on it perhaps? For libc++, libc++abi and libunwind, I am fairly confident that if we remove it and our CI doesn't break, we're okay. It might break something, but if that's the case and if it's actively being used then we have pretty good systems in place to fix it quickly, and I'm willing to take responsibility to fix it.
The impetus for this was attempting to get math tests working in libc
for the NVPTX GPU build. The automatic inclusion of -Wl,
caused the linker to error as Nvidia's linker doesn't support pretty much anything. The other project I'd be interested in is openmp
, which is a full runtime that statically links a lot of the LLVM libraries. I appreciate the help on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW, I think this is the right way to go. We'll handle the fallout as it shows up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michaelrj-google Any thoughts about libc?
Basically, I want to avoid creating a haunted graveyard around these flags. We all agree they're undesirable and can be harmful, so let's do our best to remove them and see what needs to be fixed in addition. Let's not do the easy thing (this PR as-is) because it just sweeps future problems under the rug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That depends whether we just want to do the minimal thing now and clean up later or whether we want to try and do both at the same time. For example, I'd like to leverage native CMake option where possible, so instead of manually adding -fPIC
to compiler flags, we should set POSITION_INDEPENDENT_CODE
property on targets that actually need it. Feel free to make only the necessary minimum of changes you need and leave a TODO
; we can follow up with more clean up changes later.
1676111
to
d4a8729
Compare
runtimes/CMakeLists.txt
Outdated
@@ -151,9 +151,11 @@ endif() | |||
# Avoid checking whether the compiler is working. | |||
set(LLVM_COMPILER_CHECKED ON) | |||
|
|||
# This can be used to detect whether we're in the runtimes build. | |||
set(LLVM_RUNTIMES_BUILD ON) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you still need this part of the patch now? I don't think you do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't hurt to set it earlier, but I can remove it to make it cleaner.
7330ba4
to
c357105
Compare
Seems some of the tests fail, but I'm not seeing any information from the CI. Any ideas? |
When I try to investigate the CI output it just says "error", seems to be a libc++ thing. |
The CI issues kind of look like infrastructure difficulties to me. Do you mind re triggering the checks by pushing to your branch again? |
c357105
to
d52a3b7
Compare
Seems to fail with the same issue. |
The problem is that we don't install a linker script for Edit: BTW this is exactly the reason why I think this is the right way to go about this patch. It shakes out these kinds of dependencies that we didn't know about and really shouldn't have. Edit: See #73151. |
If you rebase onto |
I'll give it a shot. |
Summary: There are a few default options that LLVM adds that can be problematic for runtimes builds. These options are generally intended to handle building LLVM itself, but are also added when building in a runtimes mode. One such issue I've run into is that in `libc` we deliberately use `--target` to use a different device toolchain, which doesn't support some linker arguments passed via `-Wl`. This is observed in llvm#73030 when attempting to use these options.
d52a3b7
to
ce45273
Compare
Seems to have passed with the exception of the sanitizers. Assuming that's unrelated. |
I'll land this, and see how it goes. |
This reverts commit 79b0330. I am seeing very confusing errors with the `libomptarget` test suite when using dlopen / other flags. Reverting to investigate why this is.
Summary: There are a few default options that LLVM adds that can be problematic for runtimes builds. These options are generally intended to handle building LLVM itself, but are also added when building in a runtimes mode. One such issue I've run into is that in `libc` we deliberately use `--target` to use a different device toolchain, which doesn't support some linker arguments passed via `-Wl`. This is observed in #73030 when attempting to use these options. This patch completely removes these default arguments. The consensus is that any issues created by this patch should ultimately be solved on a per-runtime basis.
@jhuber6 This change seems to be causing a linking failure in a sanitizer test https://lab.llvm.org/buildbot/#/builders/247/builds/11523
Note that the first build with your original change (79b0330) the test started to fail (https://lab.llvm.org/buildbot/#/builders/247/builds/11523). Then the first build after the revert, the test started to pass again (https://lab.llvm.org/buildbot/#/builders/247/builds/11529). And finally when the change was re-applied, the test started to fail again (https://lab.llvm.org/buildbot/#/builders/247/builds/11533). This is causing issues on 2 similarly configured build bots: Can you take a look fix the test or revert if you need time to investigate? |
I've also bisected issues with sanitizer builds back to this commit. This is likely because part of the handling of LLVM_USE_SANITIZER happens in HandleLLVMOptions. |
Chromium is seeing build failures in runtimes builds (https://crbug.com/1505689) and this commit is in the range. I'm trying to come up with some kind of reproducer. |
Here's a reproducer for Chromium's problem. On Linux, at ee922e6, in a build directory under llvm-project, e.g.
I think the clue is in the last line: |
This appears to have caused a variety of breakages, see comments on the PR. > Summary: > There are a few default options that LLVM adds that can be problematic > for runtimes builds. These options are generally intended to handle > building LLVM itself, but are also added when building in a runtimes > mode. One such issue I've run into is that in `libc` we deliberately use > `--target` to use a different device toolchain, which doesn't support > some linker arguments passed via `-Wl`. This is observed in > #73030 when attempting to use > these options. > > This patch completely removes these default arguments. > > The consensus is that any issues created by this patch should ultimately > be solved on a per-runtime basis. This reverts commit ee922e6.
Seems so, anything that appended flags will cause a regression since they are no longer handled. So, things like For now, we could try to fix it in-place, or we can revert it to get the bots green and we can try again later. |
I reverted in ea64047 already (I thought GitHub would notify this thread, but maybe it didn't do that.) |
Github's really awful about handling reverted patches, the PR just stays closed. We can look into how to solve this better and track the regressions. |
I'd suggest moving the handling of these common options to a global module in https://github.com/llvm/llvm-project/tree/4a294b5806417aa88c91aa05735b2d557ea5dfe5/cmake/Modules (akin to https://github.com/llvm/llvm-project/blob/4a294b5806417aa88c91aa05735b2d557ea5dfe5/cmake/Modules/HandleOutOfTreeLLVM.cmake). |
Summary:
There are a few default options that LLVM adds that can be problematic
for runtimes builds. These options are generally intended to handle
building LLVM itself, but are also added when building in a runtimes
mode. One such issue I've run into is that in
libc
we deliberately use--target
to use a different device toolchain, which doesn't supportsome linker arguments passed via
-Wl
. This is observed in#73030 when attempting to use
these options.
This patch completely removes these default arguments.
The consensus is that any issues created by this patch should ultimately be solved on a per-runtime basis.