[lld] r303579 - [lld] Infer relocation model from module flags in relocatable LTO link.
Evgeniy Stepanov via llvm-commits
llvm-commits at lists.llvm.org
Mon May 22 14:11:45 PDT 2017
Author: eugenis
Date: Mon May 22 16:11:44 2017
New Revision: 303579
URL: http://llvm.org/viewvc/llvm-project?rev=303579&view=rev
Log:
[lld] Infer relocation model from module flags in relocatable LTO link.
Fix for PR33096.
Added:
lld/trunk/test/ELF/lto/Inputs/relocation-model-pic.ll
lld/trunk/test/ELF/lto/relocation-model.ll
Modified:
lld/trunk/ELF/LTO.cpp
Modified: lld/trunk/ELF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LTO.cpp?rev=303579&r1=303578&r2=303579&view=diff
==============================================================================
--- lld/trunk/ELF/LTO.cpp (original)
+++ lld/trunk/ELF/LTO.cpp Mon May 22 16:11:44 2017
@@ -73,7 +73,12 @@ static std::unique_ptr<lto::LTO> createL
Conf.Options = InitTargetOptionsFromCodeGenFlags();
Conf.Options.RelaxELFRelocations = true;
- Conf.RelocModel = Config->Pic ? Reloc::PIC_ : Reloc::Static;
+ if (Config->Relocatable)
+ Conf.RelocModel = None;
+ else if (Config->Pic)
+ Conf.RelocModel = Reloc::PIC_;
+ else
+ Conf.RelocModel = Reloc::Static;
Conf.CodeModel = GetCodeModelFromCMModel();
Conf.DisableVerify = Config->DisableVerify;
Conf.DiagHandler = diagnosticHandler;
Added: lld/trunk/test/ELF/lto/Inputs/relocation-model-pic.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/Inputs/relocation-model-pic.ll?rev=303579&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/Inputs/relocation-model-pic.ll (added)
+++ lld/trunk/test/ELF/lto/Inputs/relocation-model-pic.ll Mon May 22 16:11:44 2017
@@ -0,0 +1,11 @@
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at foo = external global i32
+define i32 @main() {
+ %t = load i32, i32* @foo
+ ret i32 %t
+}
+
+!llvm.module.flags = !{!0}
+!0 = !{i32 1, !"PIC Level", i32 2}
Added: lld/trunk/test/ELF/lto/relocation-model.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/lto/relocation-model.ll?rev=303579&view=auto
==============================================================================
--- lld/trunk/test/ELF/lto/relocation-model.ll (added)
+++ lld/trunk/test/ELF/lto/relocation-model.ll Mon May 22 16:11:44 2017
@@ -0,0 +1,46 @@
+; REQUIRES: x86
+
+; RUN: llvm-as %s -o %t.o
+; RUN: llvm-as %p/Inputs/relocation-model-pic.ll -o %t.pic.o
+
+;; Non-PIC source.
+
+; RUN: ld.lld %t.o -o %t-out -save-temps -shared
+; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=PIC
+
+; RUN: ld.lld %t.o -o %t-out -save-temps --export-dynamic --noinhibit-exec -pie
+; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=PIC
+
+; RUN: ld.lld %t.o -o %t-out -save-temps --export-dynamic --noinhibit-exec
+; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=STATIC
+
+; RUN: ld.lld %t.o -o %t-out -save-temps -r --export-dynamic
+; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=STATIC
+
+
+;; PIC source.
+
+; RUN: ld.lld %t.pic.o -o %t-out -save-temps -shared
+; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=PIC
+
+; RUN: ld.lld %t.pic.o -o %t-out -save-temps --export-dynamic --noinhibit-exec -pie
+; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=PIC
+
+; RUN: ld.lld %t.pic.o -o %t-out -save-temps --export-dynamic --noinhibit-exec
+; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=STATIC
+
+; RUN: ld.lld %t.pic.o -o %t-out -save-temps -r --export-dynamic
+; RUN: llvm-readobj -r %t-out.lto.o | FileCheck %s --check-prefix=PIC
+
+
+; PIC: R_X86_64_REX_GOTPCRELX foo
+; STATIC: R_X86_64_PC32 foo
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+ at foo = external global i32
+define i32 @main() {
+ %t = load i32, i32* @foo
+ ret i32 %t
+}
More information about the llvm-commits
mailing list