[llvm] 2aedfdd - [CodeGen] Default TargetOptions::RelaxELFRelocations to true
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 5 13:28:52 PST 2023
Author: Fangrui Song
Date: 2023-01-05T13:28:48-08:00
New Revision: 2aedfdd9b82e6c72a28576d0e8ea854f1300ff4e
URL: https://github.com/llvm/llvm-project/commit/2aedfdd9b82e6c72a28576d0e8ea854f1300ff4e
DIFF: https://github.com/llvm/llvm-project/commit/2aedfdd9b82e6c72a28576d0e8ea854f1300ff4e.diff
LOG: [CodeGen] Default TargetOptions::RelaxELFRelocations to true
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)
Added:
Modified:
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
Removed:
################################################################################
diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp
index 4d94c50c5a911..787329388a2c6 100644
--- a/lld/ELF/LTO.cpp
+++ b/lld/ELF/LTO.cpp
@@ -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());
diff --git a/llvm/include/llvm/Target/TargetOptions.h b/llvm/include/llvm/Target/TargetOptions.h
index 6083d18d96f73..d8a4159189394 100644
--- a/llvm/include/llvm/Target/TargetOptions.h
+++ b/llvm/include/llvm/Target/TargetOptions.h
@@ -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),
diff --git a/llvm/lib/CodeGen/CommandFlags.cpp b/llvm/lib/CodeGen/CommandFlags.cpp
index 9ad7c350a9594..48cd8e998ec9a 100644
--- a/llvm/lib/CodeGen/CommandFlags.cpp
+++ b/llvm/lib/CodeGen/CommandFlags.cpp
@@ -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(
diff --git a/llvm/test/LTO/Resolution/X86/not-prevailing-variables.ll b/llvm/test/LTO/Resolution/X86/not-prevailing-variables.ll
index 33c8e435b9ecb..55be50f069fd3 100644
--- a/llvm/test/LTO/Resolution/X86/not-prevailing-variables.ll
+++ b/llvm/test/LTO/Resolution/X86/not-prevailing-variables.ll
@@ -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
diff --git a/llvm/test/ThinLTO/X86/cache-config.ll b/llvm/test/ThinLTO/X86/cache-config.ll
index ccc730d35e5e1..dfdb0aca0beb2 100644
--- a/llvm/test/ThinLTO/X86/cache-config.ll
+++ b/llvm/test/ThinLTO/X86/cache-config.ll
@@ -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
More information about the llvm-commits
mailing list