[lld] r266425 - Don't create relocations for non preemptable absolute symbols.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 15 05:22:22 PDT 2016
Author: rafael
Date: Fri Apr 15 07:22:22 2016
New Revision: 266425
URL: http://llvm.org/viewvc/llvm-project?rev=266425&view=rev
Log:
Don't create relocations for non preemptable absolute symbols.
Added:
lld/trunk/test/ELF/Inputs/abs-hidden.s
lld/trunk/test/ELF/abs-hidden.s
Modified:
lld/trunk/ELF/Writer.cpp
Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=266425&r1=266424&r2=266425&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Apr 15 07:22:22 2016
@@ -411,6 +411,16 @@ static int32_t findMipsPairedAddend(cons
return 0;
}
+// True if non-preemptable symbol always has the same value regardless of where
+// the DSO is loaded.
+template <class ELFT> static bool isAbsolute(const SymbolBody &Body) {
+ if (Body.isUndefined() && Body.isWeak())
+ return true; // always 0
+ if (const auto *DR = dyn_cast<DefinedRegular<ELFT>>(&Body))
+ return DR->Section == nullptr; // Absolute symbol.
+ return false;
+}
+
// The reason we have to do this early scan is as follows
// * To mmap the output file, we need to know the size
// * For that, we need to know how many dynamic relocs we will have.
@@ -618,7 +628,7 @@ void Writer<ELFT>::scanRelocs(InputSecti
// can process some of it and and just ask the dynamic linker to add the
// load address.
if (!Config->Pic || Target->isRelRelative(Type) || Expr == R_PC ||
- Expr == R_SIZE || (Body.isUndefined() && Body.isWeak())) {
+ Expr == R_SIZE || isAbsolute<ELFT>(Body)) {
if (Config->EMachine == EM_MIPS && Body.isLocal() &&
(Type == R_MIPS_GPREL16 || Type == R_MIPS_GPREL32))
Expr = R_MIPS_GP0;
Added: lld/trunk/test/ELF/Inputs/abs-hidden.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/abs-hidden.s?rev=266425&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/abs-hidden.s (added)
+++ lld/trunk/test/ELF/Inputs/abs-hidden.s Fri Apr 15 07:22:22 2016
@@ -0,0 +1,3 @@
+.global foo
+.hidden foo
+foo = 0x42
Added: lld/trunk/test/ELF/abs-hidden.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/abs-hidden.s?rev=266425&view=auto
==============================================================================
--- lld/trunk/test/ELF/abs-hidden.s (added)
+++ lld/trunk/test/ELF/abs-hidden.s Fri Apr 15 07:22:22 2016
@@ -0,0 +1,27 @@
+// REQUIRES: x86
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
+// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %p/Inputs/abs-hidden.s -o %t2.o
+// RUN: ld.lld %t.o %t2.o -o %t.so -shared
+// RUN: llvm-readobj -r -s -section-data %t.so | FileCheck %s
+
+ .quad foo
+
+// CHECK: Name: .text
+// CHECK-NEXT: Type: SHT_PROGBITS
+// CHECK-NEXT: Flags [
+// CHECK-NEXT: SHF_ALLOC
+// CHECK-NEXT: SHF_EXECINSTR
+// CHECK-NEXT: ]
+// CHECK-NEXT: Address:
+// CHECK-NEXT: Offset:
+// CHECK-NEXT: Size: 8
+// CHECK-NEXT: Link: 0
+// CHECK-NEXT: Info: 0
+// CHECK-NEXT: AddressAlignment: 4
+// CHECK-NEXT: EntrySize: 0
+// CHECK-NEXT: SectionData (
+// CHECK-NEXT: 0000: 42000000 00000000
+// CHECK-NEXT: )
+
+// CHECK: Relocations [
+// CHECK-NEXT: ]
More information about the llvm-commits
mailing list