From 254b58dfe343d60bfdbb2e58eafdeaff4f3e2e5f Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 21 Jun 2016 14:47:43 +0000 Subject: [PATCH] Revert "Revert "Add a test showing that lto produces relaxable relocations."" This reverts commit r273247. lld should always use the new relocations. llvm-svn: 273266 --- lld/ELF/LTO.cpp | 4 ++++ lld/test/ELF/lto/relax-relocs.ll | 15 +++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 lld/test/ELF/lto/relax-relocs.ll 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 +}