summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorSam Clegg <sbc@chromium.org>2018-05-16 20:09:05 +0000
committerSam Clegg <sbc@chromium.org>2018-05-16 20:09:05 +0000
commit6ccb59b3e957b61f8d8f717a591a12b9b8ea70ef (patch)
tree0fc93e39f086ea4823468f5eac5773a495efdf84 /llvm/lib
parent35d3398f8dc64727189c99f123aed1467153864b (diff)
downloadbcm5719-llvm-6ccb59b3e957b61f8d8f717a591a12b9b8ea70ef.tar.gz
bcm5719-llvm-6ccb59b3e957b61f8d8f717a591a12b9b8ea70ef.zip
[WebAssembly] MC: Ensure that FUNCTION_OFFSET relocations are always against function symbols.
The getAtom() method wasn't doing what we needed in all cases. We want the symbols for the function which defines that section. We can compute this easily enough and we know that we have at most one function in each section. Once this lands I will revert rL331412 which is no longer needed. Fixes PR37409 Differential Revision: https://reviews.llvm.org/D46970 llvm-svn: 332517
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/MC/WasmObjectWriter.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp
index 9c4371d48ba..c9733328a7b 100644
--- a/llvm/lib/MC/WasmObjectWriter.cpp
+++ b/llvm/lib/MC/WasmObjectWriter.cpp
@@ -225,6 +225,9 @@ class WasmObjectWriter : public MCObjectWriter {
DenseMap<const MCSectionWasm *, std::vector<WasmRelocationEntry>>
CustomSectionsRelocations;
+ // Map from section to fintining function.
+ DenseMap<const MCSection *, const MCSymbol *> SectionFunctions;
+
DenseMap<WasmFunctionType, int32_t, WasmFunctionTypeDenseMapInfo>
FunctionTypeIndices;
SmallVector<WasmFunctionType, 4> FunctionTypes;
@@ -265,6 +268,7 @@ private:
FunctionTypes.clear();
Globals.clear();
DataSegments.clear();
+ SectionFunctions.clear();
MCObjectWriter::reset();
NumFunctionImports = 0;
NumGlobalImports = 0;
@@ -383,6 +387,18 @@ void WasmObjectWriter::writeHeader(const MCAssembler &Asm) {
void WasmObjectWriter::executePostLayoutBinding(MCAssembler &Asm,
const MCAsmLayout &Layout) {
+ // Build a map of sections to the function that defines them, for use
+ // in recordRelocation.
+ for (const MCSymbol &S : Asm.symbols()) {
+ const auto &WS = static_cast<const MCSymbolWasm &>(S);
+ if (WS.isDefined() && WS.isFunction() && !WS.isVariable()) {
+ const auto &Sec = static_cast<const MCSectionWasm &>(S.getSection());
+ auto Pair = SectionFunctions.insert(std::make_pair(&Sec, &S));
+ if (!Pair.second)
+ report_fatal_error("section already has a defining function: " +
+ Sec.getSectionName());
+ }
+ }
}
void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
@@ -475,7 +491,7 @@ void WasmObjectWriter::recordRelocation(MCAssembler &Asm,
const MCSymbol *SectionSymbol = nullptr;
const MCSection &SecA = SymA->getSection();
if (SecA.getKind().isText())
- SectionSymbol = SecA.begin()->getAtom();
+ SectionSymbol = SectionFunctions.find(&SecA)->second;
else
SectionSymbol = SecA.getBeginSymbol();
if (!SectionSymbol)
OpenPOWER on IntegriCloud