aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCMachOStreamer.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-06-13 14:37:15 -0700
committerGitHub <noreply@github.com>2024-06-13 14:37:15 -0700
commit27588fe2057a3e6b69c1d6e4885a7a539b3123ff (patch)
tree8d84f4de112e3c48885524088ece4364df7ebf00 /llvm/lib/MC/MCMachOStreamer.cpp
parent597cde155a008364c83870b24306fbae93e80cf8 (diff)
downloadllvm-27588fe2057a3e6b69c1d6e4885a7a539b3123ff.zip
llvm-27588fe2057a3e6b69c1d6e4885a7a539b3123ff.tar.gz
llvm-27588fe2057a3e6b69c1d6e4885a7a539b3123ff.tar.bz2
[MC] Move MCFragment::Atom to MCSectionMachO::Atoms
Mach-O's `.subsections_via_symbols` mechanism associates a fragment with an atom (a non-temporary defined symbol). The current approach (`MCFragment::Atom`) wastes space for other object file formats. After #95077, `MCFragment::LayoutOrder` is only used by `AttemptToFoldSymbolOffsetDifference`. While it could be removed, we might explore future uses for `LayoutOrder`. @aengelke suggests one use case: move `Atom` into MCSection. This works because Mach-O doesn't support `.subsection`, and `LayoutOrder`, as the index into the fragment list, is unchanged. This patch moves MCFragment::Atom to MCSectionMachO::Atoms. `getAtom` may be called at parse time before `Atoms` is initialized, so a bound checking is needed to keep the hack working. Pull Request: https://github.com/llvm/llvm-project/pull/95341
Diffstat (limited to 'llvm/lib/MC/MCMachOStreamer.cpp')
-rw-r--r--llvm/lib/MC/MCMachOStreamer.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp
index 10f9988..466aa63 100644
--- a/llvm/lib/MC/MCMachOStreamer.cpp
+++ b/llvm/lib/MC/MCMachOStreamer.cpp
@@ -519,11 +519,13 @@ void MCMachOStreamer::finishImpl() {
// Set the fragment atom associations by tracking the last seen atom defining
// symbol.
for (MCSection &Sec : getAssembler()) {
+ cast<MCSectionMachO>(Sec).allocAtoms();
const MCSymbol *CurrentAtom = nullptr;
+ size_t I = 0;
for (MCFragment &Frag : Sec) {
if (const MCSymbol *Symbol = DefiningSymbolMap.lookup(&Frag))
CurrentAtom = Symbol;
- Frag.setAtom(CurrentAtom);
+ cast<MCSectionMachO>(Sec).setAtom(I++, CurrentAtom);
}
}