summaryrefslogtreecommitdiffstats
path: root/llvm/lib/MC/ELFObjectWriter.cpp
diff options
context:
space:
mode:
authorDaniel Sanders <daniel.sanders@imgtec.com>2016-05-06 13:49:25 +0000
committerDaniel Sanders <daniel.sanders@imgtec.com>2016-05-06 13:49:25 +0000
commita463d31a64833c24962a38aca79f4d2e12b7f4d0 (patch)
tree3cc5b0da9ebe56b48f09fe40fac820afded14899 /llvm/lib/MC/ELFObjectWriter.cpp
parent6e4695a4df355aa2c4b70bbfcca5f28a6c49b47c (diff)
downloadbcm5719-llvm-a463d31a64833c24962a38aca79f4d2e12b7f4d0.tar.gz
bcm5719-llvm-a463d31a64833c24962a38aca79f4d2e12b7f4d0.zip
[mips] Correct the ordering of HI/LO pairs in the relocation table.
Summary: There seems to have been a misunderstanding as to the meaning of 'offset' in the rules laid down by our ABI. The previous code believed that 'offset' meant the offset within the section that the relocation is applied to. However, it should have meant the offset from the symbol used in the relocation expression. This patch adds two fields to ELFRelocationEntry and uses them to correct the order of relocations for MIPS. These fields contain: * The original symbol before shouldRelocateWithSymbol() is considered. This ensures that R_MIPS_GOT16 is able to correctly distinguish between local and external symbols, allowing us to tell whether %got() requires a matching %lo() or not (local symbols require one, external symbols don't). It also prevents confusing cases where the fuzzy matching rules cause things like %hi(foo)/%lo(foo+3) and %hi(bar)/%lo(bar+1) to swap their %lo()'s. * The original offset before shouldRelocateWithSymbol() is considered. The existing Addend field is always zero when the object uses in place addends (because it's already moved it to the encoding) but MIPS needs to use the original offset to ensure that the linker correctly calculates the carry-in bit for %hi() and %got(). IAS ensures that unmatchable %hi()/%got() relocations are placed at the end of the table to ensure that the linker rejects the table (we're unable to report such errors directly). The alternatives to this risk accidental matching against inappropriate relocations which may silently compute incorrect values due to an incorrect carry bit between the %lo() and %hi()/%got(). Reviewers: sdardis Subscribers: dsanders, sdardis, rafael, llvm-commits Differential Revision: http://reviews.llvm.org/D19718 llvm-svn: 268733
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/ELFObjectWriter.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp
index 4fb583d4ff1..900dcf51a26 100644
--- a/llvm/lib/MC/ELFObjectWriter.cpp
+++ b/llvm/lib/MC/ELFObjectWriter.cpp
@@ -690,6 +690,7 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
}
unsigned Type = getRelocType(Ctx, Target, Fixup, IsPCRel);
+ uint64_t OriginalC = C;
bool RelocateWithSymbol = shouldRelocateWithSymbol(Asm, RefA, SymA, C, Type);
if (!RelocateWithSymbol && SymA && !SymA->isUndefined())
C += Layout.getSymbolOffset(*SymA);
@@ -710,21 +711,24 @@ void ELFObjectWriter::recordRelocation(MCAssembler &Asm,
ELFSec ? cast<MCSymbolELF>(ELFSec->getBeginSymbol()) : nullptr;
if (SectionSymbol)
SectionSymbol->setUsedInReloc();
- ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend);
+ ELFRelocationEntry Rec(FixupOffset, SectionSymbol, Type, Addend, SymA,
+ OriginalC);
Relocations[&FixupSection].push_back(Rec);
return;
}
+ const auto *RenamedSymA = SymA;
if (SymA) {
if (const MCSymbolELF *R = Renames.lookup(SymA))
- SymA = R;
+ RenamedSymA = R;
if (ViaWeakRef)
- SymA->setIsWeakrefUsedInReloc();
+ RenamedSymA->setIsWeakrefUsedInReloc();
else
- SymA->setUsedInReloc();
+ RenamedSymA->setUsedInReloc();
}
- ELFRelocationEntry Rec(FixupOffset, SymA, Type, Addend);
+ ELFRelocationEntry Rec(FixupOffset, RenamedSymA, Type, Addend, SymA,
+ OriginalC);
Relocations[&FixupSection].push_back(Rec);
}
OpenPOWER on IntegriCloud