diff options
Diffstat (limited to 'llvm/lib/MC/MachObjectWriter.cpp')
-rw-r--r-- | llvm/lib/MC/MachObjectWriter.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp index 0ef4495..cecca54 100644 --- a/llvm/lib/MC/MachObjectWriter.cpp +++ b/llvm/lib/MC/MachObjectWriter.cpp @@ -12,6 +12,7 @@ #include "llvm/BinaryFormat/MachO.h" #include "llvm/MC/MCAsmBackend.h" #include "llvm/MC/MCAsmLayout.h" +#include "llvm/MC/MCAsmInfoDarwin.h" #include "llvm/MC/MCAssembler.h" #include "llvm/MC/MCContext.h" #include "llvm/MC/MCDirectives.h" @@ -132,6 +133,36 @@ uint64_t MachObjectWriter::getPaddingSize(const MCSection *Sec, return offsetToAlignment(EndAddr, NextSec.getAlign()); } +static bool isSymbolLinkerVisible(const MCSymbol &Symbol) { + // Non-temporary labels should always be visible to the linker. + if (!Symbol.isTemporary()) + return true; + + if (Symbol.isUsedInReloc()) + return true; + + return false; +} + +const MCSymbol *MachObjectWriter::getAtom(const MCSymbol &S) const { + // Linker visible symbols define atoms. + if (isSymbolLinkerVisible(S)) + return &S; + + // Absolute and undefined symbols have no defining atom. + if (!S.isInSection()) + return nullptr; + + // Non-linker visible symbols in sections which can't be atomized have no + // defining atom. + if (!MCAsmInfoDarwin::isSectionAtomizableBySymbols( + *S.getFragment()->getParent())) + return nullptr; + + // Otherwise, return the atom for the containing fragment. + return S.getFragment()->getAtom(); +} + void MachObjectWriter::writeHeader(MachO::HeaderFileType Type, unsigned NumLoadCommands, unsigned LoadCommandsSize, |