aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MachObjectWriter.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-06-30 10:23:13 -0700
committerFangrui Song <i@maskray.me>2024-06-30 10:23:13 -0700
commit41a08e764aeec92703285754b5e8acd85283b1a6 (patch)
treeddd0b73498d2a720f423c8e75c82eee893b100b0 /llvm/lib/MC/MachObjectWriter.cpp
parent4066a3206012cded6de2e286732dca721d37bcd3 (diff)
downloadllvm-41a08e764aeec92703285754b5e8acd85283b1a6.zip
llvm-41a08e764aeec92703285754b5e8acd85283b1a6.tar.gz
llvm-41a08e764aeec92703285754b5e8acd85283b1a6.tar.bz2
[MC] Move Mach-O specific getAtom and isSectionAtomizableBySymbols to Mach-O files
and devirtualize isSectionAtomizableBySymbols.
Diffstat (limited to 'llvm/lib/MC/MachObjectWriter.cpp')
-rw-r--r--llvm/lib/MC/MachObjectWriter.cpp31
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,