-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang-repl] Fix PLT offset too large linker error on ARM #78959
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
Error in gold linker is: PLT offset too large, try linking with --long-plt
@llvm/pr-subscribers-clang Author: Stefan Gränitz (weliveindetail) ChangesI cross-compile clang-repl with GCC-10 on Ubuntu 20.04 and get this error when linking with gold: PLT offset too large, try linking with --long-plt Full diff: https://github.com/llvm/llvm-project/pull/78959.diff 1 Files Affected:
diff --git a/clang/tools/clang-repl/CMakeLists.txt b/clang/tools/clang-repl/CMakeLists.txt
index 2ccbe292fd49e09..8589e37418354e7 100644
--- a/clang/tools/clang-repl/CMakeLists.txt
+++ b/clang/tools/clang-repl/CMakeLists.txt
@@ -22,3 +22,7 @@ clang_target_link_libraries(clang-repl PRIVATE
if(CLANG_PLUGIN_SUPPORT)
export_executable_symbols_for_plugins(clang-repl)
endif()
+
+if(${CMAKE_SYSTEM_PROCESSOR} MATCHES "ARM")
+ target_link_options(clang-repl PRIVATE LINKER:--long-plt)
+endif()
|
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.
LGTM!
Toolchain files sometimes set a lowercase string, like armv7
Thank for the quick review! Toolchain files seem to set a lowercase string sometimes, so I added a case-conversion. |
This breaks the build on macOS because the linker doesn't support |
Oh, that's unfortunate. Let me add a check for |
It might be better to check linker flag (https://cmake.org/cmake/help/latest/module/CheckLinkerFlag.html). |
Follow-up fix from #78959
@shiltian Does that fix the issue for you? |
Yes, thanks! |
FYI, this change broke all of my cross compilation setups. When cross compiling LLVM, I never have set Anyway, this change makes it fail with the following error:
I can fix it with a trivial change like this though: diff --git a/clang/tools/clang-repl/CMakeLists.txt b/clang/tools/clang-repl/CMakeLists.txt
index 2a0f617a2c0f..031dcaba5e44 100644
--- a/clang/tools/clang-repl/CMakeLists.txt
+++ b/clang/tools/clang-repl/CMakeLists.txt
@@ -23,7 +23,7 @@ if(CLANG_PLUGIN_SUPPORT)
export_executable_symbols_for_plugins(clang-repl)
endif()
-string(TOUPPER ${CMAKE_SYSTEM_PROCESSOR} system_processor)
+string(TOUPPER "${CMAKE_SYSTEM_PROCESSOR}" system_processor)
if(system_processor MATCHES "ARM")
set(FLAG_LONG_PLT "-Wl,--long-plt")
llvm_check_linker_flag(CXX ${FLAG_LONG_PLT} LINKER_HAS_FLAG_LONG_PLT) I'll push this change within a couple hours. |
CMake does always have more surprises to offer :) Thanks @mstorsjo for fixing it right away in e3d73ad
Yes, I am just getting used to it as well. I think it's worth noting that this should be set in a toolchain file, because CMake seems to have special handling for them. When I pass |
I think that's (somewhat?) expected. When you're not cross compiling, cmake explicitly sets This actually makes |
Oh, I usually don't do that, but it's certainly a valid point. Can you think of a better way to express the condition here? We need |
Not sure; architecture detection in CMake generally is problematic. It's possible to infer the actual real destination architecture with a compiler test (like compiling and testing if Also note that I think this current form of the check might be ok enough (I don't really know more about the issue that requires |
clang-repl binary size is ~3.7G in debug mode and this seems to exceed the branch range of default ARM PLT slots. The instruction sequence that's necessary for long-range PLT slots is likely more expensive. I guess this situation is too much of an edge-case to make the effort and detect it upfront, so they just bail out if it happens an ask for the flag.
Yes, that sounds like the better option. We give it a try later today. |
Right, I see. Though - why is this only an issue for the clang-repl binary and not the other clang-based ones? Does it happen to hit some maximum when it uses both everything that is in normal clang, plus all the JIT stuff? (Normally I would expect LLDB to be the largest one, as it includes much of Clang, but that's also always split into a separate liblldb.so.) |
I was wondering as well and checked the codebase for existing uses, but no findings. Yes, clang has no JIT and may not reach the limit. And yes, LLDB is mostly an |
This is a follow-up improvement after the discussion in #78959
The above patch landed after This seems to be the right thing to do. I checked on 32-bit Raspbian @ RPi4b: It correctly defaults to triple It might be a backporting candidate. |
I just noticed that non-arm architectures have a |
I cross-compile clang-repl with GCC-10 on Ubuntu 20.04 and get this error when linking with gold: PLT offset too large, try linking with --long-plt