diff --git a/lld/ELF/LTO.cpp b/lld/ELF/LTO.cpp index 81ffa873f92c..5be2e2ad366a 100644 --- a/lld/ELF/LTO.cpp +++ b/lld/ELF/LTO.cpp @@ -279,6 +279,10 @@ std::vector> BitcodeCompiler::compile() { if (!T) fatal("target not found: " + Msg); TargetOptions Options = InitTargetOptionsFromCodeGenFlags(); + + // lld supports the new relocations. + Options.RelaxELFRelocations = true; + Reloc::Model R = Config->Pic ? Reloc::PIC_ : Reloc::Static; auto CreateTargetMachine = [&]() { diff --git a/lld/test/ELF/lto/relax-relocs.ll b/lld/test/ELF/lto/relax-relocs.ll new file mode 100644 index 000000000000..929e124b2d8e --- /dev/null +++ b/lld/test/ELF/lto/relax-relocs.ll @@ -0,0 +1,15 @@ +; RUN: llvm-as %s -o %t.o +; RUN: ld.lld -m elf_x86_64 -save-temps -shared %t.o -o %t.so +; RUN: llvm-readobj -r %t.so.lto.o | FileCheck %s + +; Test that we produce R_X86_64_REX_GOTPCRELX instead of R_X86_64_GOTPCREL +; CHECK: R_X86_64_REX_GOTPCRELX foo + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@foo = external global i32 +define i32 @bar() { + %t = load i32, i32* @foo + ret i32 %t +}