diff options
| author | Sam Clegg <sbc@chromium.org> | 2018-05-02 23:01:10 +0000 |
|---|---|---|
| committer | Sam Clegg <sbc@chromium.org> | 2018-05-02 23:01:10 +0000 |
| commit | 87cc4dbde7446bfb5735f03c984ffb3983dc26be (patch) | |
| tree | 72c1497608a7bec8b88a100815ef46f59bf4161b /llvm/lib | |
| parent | 9325c38fdb55db041ac19f24f7cafb5943e58cae (diff) | |
| download | bcm5719-llvm-87cc4dbde7446bfb5735f03c984ffb3983dc26be.tar.gz bcm5719-llvm-87cc4dbde7446bfb5735f03c984ffb3983dc26be.zip | |
[MC] Factor MCObjectStreamer::addFragmentAtoms out of MachO streamer.
This code previously existed only in MCMachOStreamer but is
useful for WebAssembly too. See: D46335
Differential Revision: https://reviews.llvm.org/D46297
llvm-svn: 331412
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/MC/MCMachOStreamer.cpp | 25 | ||||
| -rw-r--r-- | llvm/lib/MC/MCObjectStreamer.cpp | 26 | ||||
| -rw-r--r-- | llvm/lib/MC/MCWasmStreamer.cpp | 3 |
3 files changed, 30 insertions, 24 deletions
diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp index 3969143bb2c..fb29746a158 100644 --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -455,30 +455,7 @@ void MCMachOStreamer::FinishImpl() { // We have to set the fragment atom associations so we can relax properly for // Mach-O. - - // First, scan the symbol table to build a lookup table from fragments to - // defining symbols. - DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap; - for (const MCSymbol &Symbol : getAssembler().symbols()) { - if (getAssembler().isSymbolLinkerVisible(Symbol) && Symbol.isInSection() && - !Symbol.isVariable()) { - // An atom defining symbol should never be internal to a fragment. - assert(Symbol.getOffset() == 0 && - "Invalid offset in atom defining symbol!"); - DefiningSymbolMap[Symbol.getFragment()] = &Symbol; - } - } - - // Set the fragment atom associations by tracking the last seen atom defining - // symbol. - for (MCSection &Sec : getAssembler()) { - const MCSymbol *CurrentAtom = nullptr; - for (MCFragment &Frag : Sec) { - if (const MCSymbol *Symbol = DefiningSymbolMap.lookup(&Frag)) - CurrentAtom = Symbol; - Frag.setAtom(CurrentAtom); - } - } + addFragmentAtoms(); this->MCObjectStreamer::FinishImpl(); } diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp index ebedd9bf815..b2008b3e1bb 100644 --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -60,6 +60,32 @@ void MCObjectStreamer::flushPendingLabels(MCFragment *F, uint64_t FOffset) { PendingLabels.clear(); } +void MCObjectStreamer::addFragmentAtoms() { + // First, scan the symbol table to build a lookup table from fragments to + // defining symbols. + DenseMap<const MCFragment *, const MCSymbol *> DefiningSymbolMap; + for (const MCSymbol &Symbol : getAssembler().symbols()) { + if (getAssembler().isSymbolLinkerVisible(Symbol) && Symbol.isInSection() && + !Symbol.isVariable()) { + // An atom defining symbol should never be internal to a fragment. + assert(Symbol.getOffset() == 0 && + "Invalid offset in atom defining symbol!"); + DefiningSymbolMap[Symbol.getFragment()] = &Symbol; + } + } + + // Set the fragment atom associations by tracking the last seen atom defining + // symbol. + for (MCSection &Sec : getAssembler()) { + const MCSymbol *CurrentAtom = nullptr; + for (MCFragment &Frag : Sec) { + if (const MCSymbol *Symbol = DefiningSymbolMap.lookup(&Frag)) + CurrentAtom = Symbol; + Frag.setAtom(CurrentAtom); + } + } +} + // As a compile-time optimization, avoid allocating and evaluating an MCExpr // tree for (Hi - Lo) when Hi and Lo are offsets into the same fragment. static Optional<uint64_t> absoluteSymbolDiff(const MCSymbol *Hi, diff --git a/llvm/lib/MC/MCWasmStreamer.cpp b/llvm/lib/MC/MCWasmStreamer.cpp index 2c77624b685..504c72cab97 100644 --- a/llvm/lib/MC/MCWasmStreamer.cpp +++ b/llvm/lib/MC/MCWasmStreamer.cpp @@ -198,6 +198,9 @@ void MCWasmStreamer::EmitInstToData(const MCInst &Inst, void MCWasmStreamer::FinishImpl() { EmitFrames(nullptr); + // Set fragment atoms so we can map from code fragment to defining symbol + addFragmentAtoms(); + this->MCObjectStreamer::FinishImpl(); } |

