[lld] r249397 - External symbols need a full dynamic reloc, not R_X86_64_RELATIVE.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 6 05:39:58 PDT 2015
Author: rafael
Date: Tue Oct 6 07:39:58 2015
New Revision: 249397
URL: http://llvm.org/viewvc/llvm-project?rev=249397&view=rev
Log:
External symbols need a full dynamic reloc, not R_X86_64_RELATIVE.
We were already doing the right thing if the symbol was seen in a shared
library, but not if it was completely missing.
Modified:
lld/trunk/ELF/OutputSections.cpp
lld/trunk/test/elf2/relative-dynamic-reloc.s
Modified: lld/trunk/ELF/OutputSections.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/OutputSections.cpp?rev=249397&r1=249396&r2=249397&view=diff
==============================================================================
--- lld/trunk/ELF/OutputSections.cpp (original)
+++ lld/trunk/ELF/OutputSections.cpp Tue Oct 6 07:39:58 2015
@@ -92,6 +92,12 @@ RelocationSection<ELFT>::RelocationSecti
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 RelocationSec
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 {
Modified: lld/trunk/test/elf2/relative-dynamic-reloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/relative-dynamic-reloc.s?rev=249397&r1=249396&r2=249397&view=diff
==============================================================================
--- lld/trunk/test/elf2/relative-dynamic-reloc.s (original)
+++ lld/trunk/test/elf2/relative-dynamic-reloc.s Tue Oct 6 07:39:58 2015
@@ -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
More information about the llvm-commits
mailing list