[clang] [clang-repl] Fix PLT offset too large linker error on ARM (PR #78959)

Martin Storsjö via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 23 04:42:52 PST 2024


mstorsjo wrote:

> 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 `-Wl,--long-plt` for ARM targets whenever the used linker supports it. Otherwise we have to assume that it emits such PLTs by default.

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 `__arm__` is defined). CMake doesn't really provide anything out of the box for that though (it does provide `CMAKE_C_COMPILER_ARCHITECTURE_ID` on MSVC like compilers, but not elsewhere, see https://gitlab.kitware.com/cmake/cmake/-/issues/17702), and it feels like overkill to add such a compile test here.

Also note that `CMAKE_SYSTEM_PROCESSOR` is unclear in Darwin universal builds anyway - if I'm compiling with `-DCMAKE_OSX_ARCHITECTURES=x86_64;arm64` what will be set in `CMAKE_SYSTEM_PROCESSOR`? :-)

I think this current form of the check might be ok enough (I don't really know more about the issue that requires `--long-plt` at the moment and why it's only needed for clang-repl). If you'd want it to hit more universally, perhaps just remove the architecture check - if we test that the linker does support `--long-plt` without erroring out, we probably can add it, even if we don't really know the exact architecture we're linking for?

https://github.com/llvm/llvm-project/pull/78959


More information about the cfe-commits mailing list