diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-03-19 03:18:15 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-03-19 03:18:15 +0000 |
commit | 6e13bb07fb1520198520105ffc1dc1a99a48a7ce (patch) | |
tree | 2f321e44287e1922bf2c65c3e52a2a64bfb3dc4f /llvm/lib/MC/MCAssembler.cpp | |
parent | 5ec4bdd1b36f279a5fdbf09090b834b1021f6264 (diff) | |
download | bcm5719-llvm-6e13bb07fb1520198520105ffc1dc1a99a48a7ce.tar.gz bcm5719-llvm-6e13bb07fb1520198520105ffc1dc1a99a48a7ce.zip |
MC/Mach-O/x86_64: Add getAtom[ForAddress].
- These find the defining symbol which identifies the containing atom for a symbol or address. They are currently very slow, but will be eliminated eventually.
llvm-svn: 98925
Diffstat (limited to 'llvm/lib/MC/MCAssembler.cpp')
-rw-r--r-- | llvm/lib/MC/MCAssembler.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp index 003f0327137..0d4f98cc030 100644 --- a/llvm/lib/MC/MCAssembler.cpp +++ b/llvm/lib/MC/MCAssembler.cpp @@ -1062,6 +1062,42 @@ bool MCAssembler::isSymbolLinkerVisible(const MCSymbolData *SD) const { SD->getFragment()->getParent()->getSection()); } +const MCSymbolData *MCAssembler::getAtomForAddress(const MCSectionData *Section, + uint64_t Address) const { + const MCSymbolData *Best = 0; + for (MCAssembler::const_symbol_iterator it = symbol_begin(), + ie = symbol_end(); it != ie; ++it) { + // Ignore non-linker visible symbols. + if (!isSymbolLinkerVisible(it)) + continue; + + // Ignore symbols not in the same section. + if (!it->getFragment() || it->getFragment()->getParent() != Section) + continue; + + // Otherwise, find the closest symbol preceding this address (ties are + // resolved in favor of the last defined symbol). + if (it->getAddress() <= Address && + (!Best || it->getAddress() >= Best->getAddress())) + Best = it; + } + + return Best; +} + +const MCSymbolData *MCAssembler::getAtom(const MCSymbolData *SD) const { + // Linker visible symbols define atoms. + if (isSymbolLinkerVisible(SD)) + return SD; + + // Absolute and undefined symbols have no defining atom. + if (!SD->getFragment()) + return 0; + + // Otherwise, search by address. + return getAtomForAddress(SD->getFragment()->getParent(), SD->getAddress()); +} + bool MCAssembler::EvaluateFixup(const MCAsmLayout &Layout, MCAsmFixup &Fixup, MCDataFragment *DF, MCValue &Target, uint64_t &Value) const { |