diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-10-05 21:23:08 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-10-05 21:23:08 +0000 |
| commit | 9c3e4d2af582bb9c3ef07321bb05a7eb12d6225e (patch) | |
| tree | 59af514168564e3ee4551caaefba1af460c65742 | |
| parent | 808d2a070dad278ef15747c963894b70ed2ae849 (diff) | |
| download | bcm5719-llvm-9c3e4d2af582bb9c3ef07321bb05a7eb12d6225e.tar.gz bcm5719-llvm-9c3e4d2af582bb9c3ef07321bb05a7eb12d6225e.zip | |
Handle a common symbol needing a R_X86_64_RELATIVE.
llvm-svn: 249357
| -rw-r--r-- | lld/ELF/OutputSections.cpp | 8 | ||||
| -rw-r--r-- | lld/ELF/OutputSections.h | 4 | ||||
| -rw-r--r-- | lld/ELF/Writer.cpp | 5 | ||||
| -rw-r--r-- | lld/test/elf2/relative-dynamic-reloc.s | 7 |
4 files changed, 18 insertions, 6 deletions
diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 0cfb89dfaf5..4519dd6f296 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -81,12 +81,13 @@ PltSection<ELFT>::getEntryAddr(const SymbolBody &B) const { template <class ELFT> RelocationSection<ELFT>::RelocationSection(SymbolTableSection<ELFT> &DynSymSec, const GotSection<ELFT> &GotSec, + const OutputSection<ELFT> &BssSec, bool IsRela) : OutputSectionBase<ELFT::Is64Bits>(IsRela ? ".rela.dyn" : ".rel.dyn", IsRela ? llvm::ELF::SHT_RELA : llvm::ELF::SHT_REL, llvm::ELF::SHF_ALLOC), - DynSymSec(DynSymSec), GotSec(GotSec), IsRela(IsRela) { + DynSymSec(DynSymSec), GotSec(GotSec), BssSec(BssSec), IsRela(IsRela) { this->Header.sh_entsize = IsRela ? sizeof(Elf_Rela) : sizeof(Elf_Rel); this->Header.sh_addralign = ELFT::Is64Bits ? 8 : 4; } @@ -120,9 +121,10 @@ template <class ELFT> void RelocationSection<ELFT>::writeTo(uint8_t *Buf) { } else { P->setSymbolAndType(0, Target->getRelativeReloc(), IsMips64EL); if (IsRela) { - Addent += C.getOutputSectionOff() + Out->getVA(); if (Body) - Addent += cast<DefinedRegular<ELFT>>(Body)->Sym.st_value; + Addent += getSymVA(cast<ELFSymbolBody<ELFT>>(*Body), BssSec); + else + Addent += C.getOutputSectionOff() + Out->getVA(); } } if (IsRela) diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index cf6938130ed..96de43700a7 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -193,7 +193,8 @@ class RelocationSection final : public OutputSectionBase<ELFT::Is64Bits> { public: RelocationSection(SymbolTableSection<ELFT> &DynSymSec, - const GotSection<ELFT> &GotSec, bool IsRela); + const GotSection<ELFT> &GotSec, + const OutputSection<ELFT> &BssSec, bool IsRela); void addReloc(const DynamicReloc<ELFT> &Reloc) { Relocs.push_back(Reloc); } void finalize() override; void writeTo(uint8_t *Buf) override; @@ -204,6 +205,7 @@ private: std::vector<DynamicReloc<ELFT>> Relocs; SymbolTableSection<ELFT> &DynSymSec; const GotSection<ELFT> &GotSec; + const OutputSection<ELFT> &BssSec; const bool IsRela; }; diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 66fd48988c4..5adeea94380 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -84,8 +84,9 @@ public: typedef typename ELFFile<ELFT>::Elf_Rela Elf_Rela; Writer(SymbolTable *T) : SymTabSec(*T, StrTabSec, BssSec), DynSymSec(*T, DynStrSec, BssSec), - RelaDynSec(DynSymSec, GotSec, T->shouldUseRela()), PltSec(GotSec), - HashSec(DynSymSec), DynamicSec(*T, HashSec, RelaDynSec, BssSec), + RelaDynSec(DynSymSec, GotSec, BssSec, T->shouldUseRela()), + PltSec(GotSec), HashSec(DynSymSec), + DynamicSec(*T, HashSec, RelaDynSec, BssSec), BssSec(PltSec, GotSec, BssSec, ".bss", SHT_NOBITS, SHF_ALLOC | SHF_WRITE) {} void run(); diff --git a/lld/test/elf2/relative-dynamic-reloc.s b/lld/test/elf2/relative-dynamic-reloc.s index eef6db129a7..faa461ee326 100644 --- a/lld/test/elf2/relative-dynamic-reloc.s +++ b/lld/test/elf2/relative-dynamic-reloc.s @@ -10,6 +10,7 @@ // CHECK-NEXT: 0x[[FOO_ADDR:.*]] R_X86_64_RELATIVE - 0x[[FOO_ADDR]] // CHECK-NEXT: 0x[[BAR_ADDR:.*]] R_X86_64_RELATIVE - 0x[[BAR_ADDR]] // CHECK-NEXT: 0x2010 R_X86_64_RELATIVE - 0x2009 +// CHECK-NEXT: 0x{{.*}} R_X86_64_RELATIVE - 0x[[ZED_ADDR:.*]] // CHECK-NEXT: } // CHECK-NEXT: ] @@ -18,6 +19,8 @@ // CHECK-NEXT: Value: 0x[[FOO_ADDR]] // CHECK: Name: bar // CHECK-NEXT: Value: 0x[[BAR_ADDR]] +// CHECK: Name: zed +// CHECK-NEXT: Value: 0x[[ZED_ADDR]] // CHECK: ] // CHECK: DynamicSymbols [ @@ -40,3 +43,7 @@ foo: bar: .quad bar .quad bar + 1 + + .hidden zed + .comm zed,1 + .quad zed |

