From 2aedfdd9b82e6c72a28576d0e8ea854f1300ff4e Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Thu, 5 Jan 2023 13:28:48 -0800 Subject: [PATCH] [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) --- lld/ELF/LTO.cpp | 1 - llvm/include/llvm/Target/TargetOptions.h | 2 +- llvm/lib/CodeGen/CommandFlags.cpp | 2 +- llvm/test/LTO/Resolution/X86/not-prevailing-variables.ll | 2 +- llvm/test/ThinLTO/X86/cache-config.ll | 2 +- 5 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index 4d94c50c5a91..787329388a2c 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 6083d18d96f7..d8a415918939 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 9ad7c350a959..48cd8e998ec9 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 DataSections( diff --git a/llvm/test/LTO/Resolution/X86/not-prevailing-variables.ll b/llvm/test/LTO/Resolution/X86/not-prevailing-variables.ll index 33c8e435b9ec..55be50f069fd 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: : ; 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 ccc730d35e5e..dfdb0aca0beb 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 -- 2.34.1