summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lld/ELF/OutputSections.cpp8
-rw-r--r--lld/test/elf2/relative-dynamic-reloc.s12
2 files changed, 19 insertions, 1 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp
index 8e14311a4f0..ee2d87c1d10 100644
--- a/lld/ELF/OutputSections.cpp
+++ b/lld/ELF/OutputSections.cpp
@@ -92,6 +92,12 @@ RelocationSection<ELFT>::RelocationSection(SymbolTableSection<ELFT> &DynSymSec,
this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4;
}
+static bool isLocalDefinition(const SymbolBody *Body) {
+ if (!Body)
+ return true;
+ return !Body->isShared() && !Body->isUndefined();
+}
+
template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) {
const unsigned EntrySize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel);
bool IsMips64EL = Relocs[0].C.getFile()->getObj().isMips64EL();
@@ -118,7 +124,7 @@ template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) {
if (IsRela)
Addent = static_cast<const Elf_Rela &>(RI).r_addend;
- if (Body && Body->isShared()) {
+ if (!isLocalDefinition(Body)) {
P->setSymbolAndType(Body->getDynamicSymbolTableIndex(), Type,
IsMips64EL);
} else {
diff --git a/lld/test/elf2/relative-dynamic-reloc.s b/lld/test/elf2/relative-dynamic-reloc.s
index 821881db6f4..e55a44fbb20 100644
--- a/lld/test/elf2/relative-dynamic-reloc.s
+++ b/lld/test/elf2/relative-dynamic-reloc.s
@@ -12,6 +12,7 @@
// CHECK-NEXT: 0x2010 R_X86_64_RELATIVE - 0x2009
// CHECK-NEXT: 0x{{.*}} R_X86_64_RELATIVE - 0x[[ZED_ADDR:.*]]
// CHECK-NEXT: 0x{{.*}} R_X86_64_RELATIVE - 0x[[FOO_ADDR]]
+// CHECK-NEXT: 0x1008 R_X86_64_64 external 0x0
// CHECK-NEXT: }
// CHECK-NEXT: ]
@@ -34,6 +35,15 @@
// CHECK-NEXT: Other: 0
// CHECK-NEXT: Section: Undefined
// CHECK-NEXT: }
+// CHECK-NEXT: Symbol {
+// CHECK-NEXT: Name: external@
+// CHECK-NEXT: Value: 0x0
+// CHECK-NEXT: Size: 0
+// CHECK-NEXT: Binding: Global
+// CHECK-NEXT: Type: None
+// CHECK-NEXT: Other: 0
+// CHECK-NEXT: Section: Undefined
+// CHECK-NEXT: }
// CHECK-NEXT: ]
foo:
@@ -51,3 +61,5 @@ bar:
.section abc,"a"
.quad foo
+
+ .quad external
OpenPOWER on IntegriCloud