diff options
author | Fangrui Song <i@maskray.me> | 2024-06-14 09:39:32 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-14 09:39:32 -0700 |
commit | f808abf508a6b890b40fc2594ea36ce896bb1f37 (patch) | |
tree | 9f21f531de19567e57fd793f9675538ea34bca6c /llvm/lib/MC/MCMachOStreamer.cpp | |
parent | 8b9dce333f71bc21b3534e89a41e1ea8672aa063 (diff) | |
download | llvm-f808abf508a6b890b40fc2594ea36ce896bb1f37.zip llvm-f808abf508a6b890b40fc2594ea36ce896bb1f37.tar.gz llvm-f808abf508a6b890b40fc2594ea36ce896bb1f37.tar.bz2 |
[MC] Add MCFragment allocation helpers
`allocFragment` might be changed to a placement new when the allocation
strategy changes.
`allocInitialFragment` is to deduplicate the following pattern
```
auto *F = new MCDataFragment();
Result->addFragment(*F);
F->setParent(Result);
```
Pull Request: https://github.com/llvm/llvm-project/pull/95197
Diffstat (limited to 'llvm/lib/MC/MCMachOStreamer.cpp')
-rw-r--r-- | llvm/lib/MC/MCMachOStreamer.cpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp index 466aa63..6b2e411 100644 --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -199,7 +199,7 @@ void MCMachOStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) { // We have to create a new fragment if this is an atom defining symbol, // fragments cannot span atoms. if (getAssembler().isSymbolLinkerVisible(*Symbol)) - insert(new MCDataFragment()); + insert(getContext().allocFragment<MCDataFragment>()); MCObjectStreamer::emitLabel(Symbol, Loc); @@ -555,7 +555,9 @@ void MCMachOStreamer::finalizeCGProfile() { MCSection *CGProfileSection = Asm.getContext().getMachOSection( "__LLVM", "__cg_profile", 0, SectionKind::getMetadata()); Asm.registerSection(*CGProfileSection); - auto *Frag = new MCDataFragment(CGProfileSection); + auto *Frag = getContext().allocFragment<MCDataFragment>(); + Frag->setParent(CGProfileSection); + CGProfileSection->addFragment(*Frag); // For each entry, reserve space for 2 32-bit indices and a 64-bit count. size_t SectionBytes = Asm.CGProfile.size() * (2 * sizeof(uint32_t) + sizeof(uint64_t)); @@ -595,7 +597,9 @@ void MCMachOStreamer::createAddrSigSection() { MCSection *AddrSigSection = Asm.getContext().getObjectFileInfo()->getAddrSigSection(); Asm.registerSection(*AddrSigSection); - auto *Frag = new MCDataFragment(AddrSigSection); + auto *Frag = getContext().allocFragment<MCDataFragment>(); + Frag->setParent(AddrSigSection); + AddrSigSection->addFragment(*Frag); // We will generate a series of pointer-sized symbol relocations at offset // 0x0. Set the section size to be large enough to contain a single pointer // (instead of emitting a zero-sized section) so these relocations are |