Skip to content

Commit abbf3bc

Browse files
committed
[MC] Avoid some registerSection calls
changeSection is preferred to call the changeSectionImpl hook, which registers the section symbol.
1 parent f05fa6e commit abbf3bc

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class MCObjectStreamer : public MCStreamer {
121121
void emitULEB128Value(const MCExpr *Value) override;
122122
void emitSLEB128Value(const MCExpr *Value) override;
123123
void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
124-
void changeSection(MCSection *Section, uint32_t Subsection) override;
124+
void changeSection(MCSection *Section, uint32_t Subsection = 0) override;
125125
void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
126126

127127
/// Emit an instruction to a special fragment, because this instruction

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class MCMachOStreamer : public MCObjectStreamer {
8585
/// @name MCStreamer Interface
8686
/// @{
8787

88-
void changeSection(MCSection *Sect, uint32_t Subsect) override;
88+
void changeSection(MCSection *Sect, uint32_t Subsection = 0) override;
8989
void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
9090
void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
9191
void emitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) override;
@@ -155,10 +155,11 @@ static bool canGoAfterDWARF(const MCSectionMachO &MSec) {
155155
if (SegName == "__TEXT" && SecName == "__eh_frame")
156156
return true;
157157

158-
if (SegName == "__DATA" && (SecName == "__nl_symbol_ptr" ||
159-
SecName == "__thread_ptr"))
158+
if (SegName == "__DATA" &&
159+
(SecName == "__llvm_addrsig" || SecName == "__nl_symbol_ptr" ||
160+
SecName == "__thread_ptr"))
160161
return true;
161-
if (SegName == "__LLVM" && SecName == "__cg_profile")
162+
if (SegName == "__LLVM" && (SecName == "__cg_profile"))
162163
return true;
163164
return false;
164165
}
@@ -553,7 +554,7 @@ void MCMachOStreamer::finalizeCGProfile() {
553554
// and set its size now so that it's accounted for in layout.
554555
MCSection *CGProfileSection = Asm.getContext().getMachOSection(
555556
"__LLVM", "__cg_profile", 0, SectionKind::getMetadata());
556-
Asm.registerSection(*CGProfileSection);
557+
changeSection(CGProfileSection);
557558
// For each entry, reserve space for 2 32-bit indices and a 64-bit count.
558559
size_t SectionBytes =
559560
Asm.CGProfile.size() * (2 * sizeof(uint32_t) + sizeof(uint64_t));
@@ -594,7 +595,7 @@ void MCMachOStreamer::createAddrSigSection() {
594595
// to be computed immediately after in order for it to be exported correctly.
595596
MCSection *AddrSigSection =
596597
Asm.getContext().getObjectFileInfo()->getAddrSigSection();
597-
Asm.registerSection(*AddrSigSection);
598+
changeSection(AddrSigSection);
598599
auto *Frag = getContext().allocFragment<MCDataFragment>();
599600
Frag->setParent(AddrSigSection);
600601
AddrSigSection->addFragment(*Frag);

llvm/lib/MC/MCWinCOFFStreamer.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void MCWinCOFFStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) {
193193
return;
194194

195195
MCSection *SXData = getContext().getObjectFileInfo()->getSXDataSection();
196-
getAssembler().registerSection(*SXData);
196+
changeSection(SXData);
197197
SXData->ensureMinAlignment(Align(4));
198198

199199
auto *F = getContext().allocFragment<MCSymbolIdFragment>(Symbol);
@@ -210,7 +210,6 @@ void MCWinCOFFStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) {
210210

211211
void MCWinCOFFStreamer::emitCOFFSymbolIndex(MCSymbol const *Symbol) {
212212
MCSection *Sec = getCurrentSectionOnly();
213-
getAssembler().registerSection(*Sec);
214213
Sec->ensureMinAlignment(Align(4));
215214

216215
insert(getContext().allocFragment<MCSymbolIdFragment>(Symbol));

0 commit comments

Comments
 (0)