[PATCH] D46297: MC: Add MCObjectStreamer::addFragmentAtoms and use it with MachO and WebAssembly
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 30 19:13:07 PDT 2018
sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff, jfb.
This code previously existed only in MCMachOStreamer but is
useful for WebAssembly too.
This is part of a large WebAssembly change:
Repository:
rL LLVM
https://reviews.llvm.org/D46297
Files:
include/llvm/MC/MCObjectStreamer.h
lib/MC/MCMachOStreamer.cpp
lib/MC/MCObjectStreamer.cpp
lib/MC/MCWasmStreamer.cpp
Index: lib/MC/MCWasmStreamer.cpp
===================================================================
--- lib/MC/MCWasmStreamer.cpp
+++ lib/MC/MCWasmStreamer.cpp
@@ -198,6 +198,9 @@
void MCWasmStreamer::FinishImpl() {
EmitFrames(nullptr);
+ // Set fragment atoms so we can map from code fragment to defining symbol
+ addFragmentAtoms();
+
this->MCObjectStreamer::FinishImpl();
}
Index: lib/MC/MCObjectStreamer.cpp
===================================================================
--- lib/MC/MCObjectStreamer.cpp
+++ lib/MC/MCObjectStreamer.cpp
@@ -60,6 +60,32 @@
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,
Index: lib/MC/MCMachOStreamer.cpp
===================================================================
--- lib/MC/MCMachOStreamer.cpp
+++ lib/MC/MCMachOStreamer.cpp
@@ -455,30 +455,7 @@
// 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();
}
Index: include/llvm/MC/MCObjectStreamer.h
===================================================================
--- include/llvm/MC/MCObjectStreamer.h
+++ include/llvm/MC/MCObjectStreamer.h
@@ -85,6 +85,8 @@
/// will be used as a symbol offset within the fragment.
void flushPendingLabels(MCFragment *F, uint64_t FOffset = 0);
+ void addFragmentAtoms();
+
public:
void visitUsedSymbol(const MCSymbol &Sym) override;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46297.144668.patch
Type: text/x-patch
Size: 3567 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180501/6d0ce8ef/attachment.bin>
More information about the llvm-commits
mailing list