Skip to content

Commit

Permalink
[ELF][MIPS] Use InputSectionBase::getOutputSection() to access outp…
Browse files Browse the repository at this point in the history
…ut sections from the `MipsGotSection`

Follow-up to r294005. This patch restores handling of MISP GOT
relocations against merge sections.

llvm-svn: 295040
  • Loading branch information
atanasyan committed Feb 14, 2017
1 parent 2ec409c commit 7a2a1ff
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lld/ELF/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,8 @@ void MipsGotSection<ELFT>::addEntry(SymbolBody &Sym, uintX_t Addend,
// sections referenced by GOT relocations. Then later in the `finalize`
// method calculate number of "pages" required to cover all saved output
// section and allocate appropriate number of GOT entries.
PageIndexMap.insert({cast<DefinedRegular<ELFT>>(&Sym)->Section->OutSec, 0});
auto *DefSym = cast<DefinedRegular<ELFT>>(&Sym);
PageIndexMap.insert({DefSym->Section->getOutputSection(), 0});
return;
}
if (Sym.isTls()) {
Expand Down Expand Up @@ -564,7 +565,7 @@ typename MipsGotSection<ELFT>::uintX_t
MipsGotSection<ELFT>::getPageEntryOffset(const SymbolBody &B,
uintX_t Addend) const {
const OutputSectionBase *OutSec =
cast<DefinedRegular<ELFT>>(&B)->Section->OutSec;
cast<DefinedRegular<ELFT>>(&B)->Section->getOutputSection();
uintX_t SecAddr = getMipsPageAddr(OutSec->Addr);
uintX_t SymAddr = getMipsPageAddr(B.getVA<ELFT>(Addend));
uintX_t Index = PageIndexMap.lookup(OutSec) + (SymAddr - SecAddr) / 0xffff;
Expand Down
28 changes: 28 additions & 0 deletions lld/test/ELF/mips-got-string.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Check R_MIPS_GOT16 relocation against merge section.

# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux -o %t.o %s
# RUN: ld.lld -shared -o %t.so %t.o
# RUN: llvm-readobj -t -mips-plt-got %t.so | FileCheck %s

# REQUIRES: mips

# CHECK: Symbol {
# CHECK: Name: $.str
# CHECK-NEXT: Value: 0xF4
# CHECK: }

# CHECK: Local entries [
# CHECK-NEXT: Entry {
# CHECK-NEXT: Address:
# CHECK-NEXT: Access: -32744
# CHECK-NEXT: Initial: 0x0
# CHECK: }
# CHECK: ]

.text
lw $t9, %got($.str)($gp)
addiu $a0, $t9, %lo($.str)

.section .rodata.str,"aMS",@progbits,1
$.str:
.asciz "foo"

0 comments on commit 7a2a1ff

Please sign in to comment.