[clang] fb9a82b - [clang-repl] Refine fix for linker error: PLT offset too large

Stefan Gränitz via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 24 02:45:45 PST 2024


Author: Stefan Gränitz
Date: 2024-01-24T11:45:04+01:00
New Revision: fb9a82b0235713782c1cf9d1eba20ce8d95766f7

URL: https://github.com/llvm/llvm-project/commit/fb9a82b0235713782c1cf9d1eba20ce8d95766f7
DIFF: https://github.com/llvm/llvm-project/commit/fb9a82b0235713782c1cf9d1eba20ce8d95766f7.diff

LOG: [clang-repl] Refine fix for linker error: PLT offset too large

This is a follow-up improvement after the discussion in #78959

Added: 
    

Modified: 
    clang/tools/clang-repl/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/clang/tools/clang-repl/CMakeLists.txt b/clang/tools/clang-repl/CMakeLists.txt
index 031dcaba5e4468..d3dec1984b78d2 100644
--- a/clang/tools/clang-repl/CMakeLists.txt
+++ b/clang/tools/clang-repl/CMakeLists.txt
@@ -23,12 +23,13 @@ if(CLANG_PLUGIN_SUPPORT)
   export_executable_symbols_for_plugins(clang-repl)
 endif()
 
-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)
-  # Linkers without this flag are assumed to have long PLTs by default
-  if(LINKER_HAS_FLAG_LONG_PLT)
-    target_link_options(clang-repl PRIVATE ${FLAG_LONG_PLT})
-  endif()
+# The clang-repl binary can get huge with static linking in debug mode.
+# Some 32-bit targets use PLT slots with limited branch range by default and we
+# start to exceed this limit, e.g. when linking for arm-linux-gnueabihf with
+# gold. This flag tells the linker to build a PLT for the full address range.
+# Linkers without this flag are assumed to support proper PLTs by default.
+set(flag_long_plt "-Wl,--long-plt")
+llvm_check_linker_flag(CXX ${flag_long_plt} HAVE_LINKER_FLAG_LONG_PLT)
+if(HAVE_LINKER_FLAG_LONG_PLT)
+  target_link_options(clang-repl PRIVATE ${flag_long_plt})
 endif()


        


More information about the cfe-commits mailing list