[CodeGen] Default TargetOptions::RelaxELFRelocations to true
authorFangrui Song <i@maskray.me>
Thu, 5 Jan 2023 21:28:48 +0000 (13:28 -0800)
committerFangrui Song <i@maskray.me>
Thu, 5 Jan 2023 21:28:48 +0000 (13:28 -0800)
MC and lld/ELF defaults were flipped in 2016. For Clang: CMake
ENABLE_X86_RELAX_RELOCATIONS defaults to on in 2020. It makes sense for
the TargetOptions default to be true now.

R_X86_64_GOTPCRELX/R_X86_64_REX_GOTPCRELX require GNU ld newer than 2015-10
(subsumed by the current requirement of -fbinutils-version=).

This should fix `rustc -Z plt=no` PIC relocatable files with GNU ld.
(See https://github.com/rust-lang/rust/pull/106380)

lld/ELF/LTO.cpp
llvm/include/llvm/Target/TargetOptions.h
llvm/lib/CodeGen/CommandFlags.cpp
llvm/test/LTO/Resolution/X86/not-prevailing-variables.ll
llvm/test/ThinLTO/X86/cache-config.ll

index 4d94c50c5a911b86f9a45e7d7905e9ca02c18dd8..787329388a2c660cb3085a30f4b54f03e084fbf3 100644 (file)
@@ -77,7 +77,6 @@ static lto::Config createConfig() {
 
   // LLD supports the new relocations and address-significance tables.
   c.Options = initTargetOptionsFromCodeGenFlags();
-  c.Options.RelaxELFRelocations = true;
   c.Options.EmitAddrsig = true;
   for (StringRef C : config->mllvmOpts)
     c.MllvmArgs.emplace_back(C.str());
index 6083d18d96f73a1facc381c3d59add1e04b76703..d8a4159189394e1378cfe18e416eb54171f1c623 100644 (file)
@@ -131,7 +131,7 @@ namespace llvm {
           GuaranteedTailCallOpt(false), StackSymbolOrdering(true),
           EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false),
           LowerGlobalDtorsViaCxaAtExit(false), DisableIntegratedAS(false),
-          RelaxELFRelocations(false), FunctionSections(false),
+          RelaxELFRelocations(true), FunctionSections(false),
           DataSections(false), IgnoreXCOFFVisibility(false),
           XCOFFTracebackTable(true), UniqueSectionNames(true),
           UniqueBasicBlockSectionNames(false), TrapUnreachable(false),
index 9ad7c350a959472cdfb3b5a7f13245c3b0eb3518..48cd8e998ec9a83acad3c6d612cfb548716f76ea 100644 (file)
@@ -359,7 +359,7 @@ codegen::RegisterCodeGenFlags::RegisterCodeGenFlags() {
       "relax-elf-relocations",
       cl::desc(
           "Emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL on x86-64 ELF"),
-      cl::init(false));
+      cl::init(true));
   CGBINDOPT(RelaxELFRelocations);
 
   static cl::opt<bool> DataSections(
index 33c8e435b9ecbad7a192ae8c4123323da4866b7b..55be50f069fd3c17c70a816aa7aa2b51648ffd1f 100644 (file)
@@ -13,7 +13,7 @@
 ; CHECK-NEXT:   retq
 ; CHECK:      <testVar2>:
 ; CHECK-NEXT:   movq  (%rip), %rax
-; CHECK-NEXT:     R_X86_64_GOTPCREL var2-0x4
+; CHECK-NEXT:     R_X86_64_REX_GOTPCRELX var2-0x4
 ; CHECK-NEXT:   movl  (%rax), %eax
 ; CHECK-NEXT:   retq
 
index ccc730d35e5e1f8b4138a5f7d20d94a8318e6ae6..dfdb0aca0beb2c713eeeffac3751d80eee37b2be 100644 (file)
@@ -3,7 +3,7 @@
 
 ; RUN: llvm-lto2 run -o %t.o %t.bc -cache-dir %t.cache -r=%t.bc,globalfunc,plx
 ; RUN: llvm-lto2 run -o %t.o %t.bc -cache-dir %t.cache -r=%t.bc,globalfunc,plx -mcpu=core2
-; RUN: llvm-lto2 run -o %t.o %t.bc -cache-dir %t.cache -r=%t.bc,globalfunc,plx -relax-elf-relocations
+; RUN: llvm-lto2 run -o %t.o %t.bc -cache-dir %t.cache -r=%t.bc,globalfunc,plx -relax-elf-relocations=0
 ; RUN: llvm-lto2 run -o %t.o %t.bc -cache-dir %t.cache -r=%t.bc,globalfunc,plx -function-sections
 ; RUN: llvm-lto2 run -o %t.o %t.bc -cache-dir %t.cache -r=%t.bc,globalfunc,plx -data-sections
 ; RUN: llvm-lto2 run -o %t.o %t.bc -cache-dir %t.cache -r=%t.bc,globalfunc,plx -debugger-tune=sce