[llvm] abbf3bc - [MC] Avoid some registerSection calls

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 23 15:21:07 PDT 2024


Author: Fangrui Song
Date: 2024-06-23T15:21:02-07:00
New Revision: abbf3bce94e0848f746e39186d36ebb938c1c5de

URL: https://github.com/llvm/llvm-project/commit/abbf3bce94e0848f746e39186d36ebb938c1c5de
DIFF: https://github.com/llvm/llvm-project/commit/abbf3bce94e0848f746e39186d36ebb938c1c5de.diff

LOG: [MC] Avoid some registerSection calls

changeSection is preferred to call the changeSectionImpl hook, which
registers the section symbol.

Added: 
    

Modified: 
    llvm/include/llvm/MC/MCObjectStreamer.h
    llvm/lib/MC/MCMachOStreamer.cpp
    llvm/lib/MC/MCWinCOFFStreamer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/MC/MCObjectStreamer.h b/llvm/include/llvm/MC/MCObjectStreamer.h
index 1d1af6f48d2ef..a8164494d0de4 100644
--- a/llvm/include/llvm/MC/MCObjectStreamer.h
+++ b/llvm/include/llvm/MC/MCObjectStreamer.h
@@ -121,7 +121,7 @@ class MCObjectStreamer : public MCStreamer {
   void emitULEB128Value(const MCExpr *Value) override;
   void emitSLEB128Value(const MCExpr *Value) override;
   void emitWeakReference(MCSymbol *Alias, const MCSymbol *Symbol) override;
-  void changeSection(MCSection *Section, uint32_t Subsection) override;
+  void changeSection(MCSection *Section, uint32_t Subsection = 0) override;
   void emitInstruction(const MCInst &Inst, const MCSubtargetInfo &STI) override;
 
   /// Emit an instruction to a special fragment, because this instruction

diff  --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp
index 18bfd08aeef11..e2f6508b9c89e 100644
--- a/llvm/lib/MC/MCMachOStreamer.cpp
+++ b/llvm/lib/MC/MCMachOStreamer.cpp
@@ -85,7 +85,7 @@ class MCMachOStreamer : public MCObjectStreamer {
   /// @name MCStreamer Interface
   /// @{
 
-  void changeSection(MCSection *Sect, uint32_t Subsect) override;
+  void changeSection(MCSection *Sect, uint32_t Subsection = 0) override;
   void emitLabel(MCSymbol *Symbol, SMLoc Loc = SMLoc()) override;
   void emitAssignment(MCSymbol *Symbol, const MCExpr *Value) override;
   void emitEHSymAttributes(const MCSymbol *Symbol, MCSymbol *EHSymbol) override;
@@ -155,10 +155,11 @@ static bool canGoAfterDWARF(const MCSectionMachO &MSec) {
   if (SegName == "__TEXT" && SecName == "__eh_frame")
     return true;
 
-  if (SegName == "__DATA" && (SecName == "__nl_symbol_ptr" ||
-                              SecName == "__thread_ptr"))
+  if (SegName == "__DATA" &&
+      (SecName == "__llvm_addrsig" || SecName == "__nl_symbol_ptr" ||
+       SecName == "__thread_ptr"))
     return true;
-  if (SegName == "__LLVM" && SecName == "__cg_profile")
+  if (SegName == "__LLVM" && (SecName == "__cg_profile"))
     return true;
   return false;
 }
@@ -553,7 +554,7 @@ void MCMachOStreamer::finalizeCGProfile() {
   // and set its size now so that it's accounted for in layout.
   MCSection *CGProfileSection = Asm.getContext().getMachOSection(
       "__LLVM", "__cg_profile", 0, SectionKind::getMetadata());
-  Asm.registerSection(*CGProfileSection);
+  changeSection(CGProfileSection);
   // 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));
@@ -594,7 +595,7 @@ void MCMachOStreamer::createAddrSigSection() {
   // to be computed immediately after in order for it to be exported correctly.
   MCSection *AddrSigSection =
       Asm.getContext().getObjectFileInfo()->getAddrSigSection();
-  Asm.registerSection(*AddrSigSection);
+  changeSection(AddrSigSection);
   auto *Frag = getContext().allocFragment<MCDataFragment>();
   Frag->setParent(AddrSigSection);
   AddrSigSection->addFragment(*Frag);

diff  --git a/llvm/lib/MC/MCWinCOFFStreamer.cpp b/llvm/lib/MC/MCWinCOFFStreamer.cpp
index 26b2c6b43e9c6..634524d4df6fe 100644
--- a/llvm/lib/MC/MCWinCOFFStreamer.cpp
+++ b/llvm/lib/MC/MCWinCOFFStreamer.cpp
@@ -193,7 +193,7 @@ void MCWinCOFFStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) {
     return;
 
   MCSection *SXData = getContext().getObjectFileInfo()->getSXDataSection();
-  getAssembler().registerSection(*SXData);
+  changeSection(SXData);
   SXData->ensureMinAlignment(Align(4));
 
   auto *F = getContext().allocFragment<MCSymbolIdFragment>(Symbol);
@@ -210,7 +210,6 @@ void MCWinCOFFStreamer::emitCOFFSafeSEH(MCSymbol const *Symbol) {
 
 void MCWinCOFFStreamer::emitCOFFSymbolIndex(MCSymbol const *Symbol) {
   MCSection *Sec = getCurrentSectionOnly();
-  getAssembler().registerSection(*Sec);
   Sec->ensureMinAlignment(Align(4));
 
   insert(getContext().allocFragment<MCSymbolIdFragment>(Symbol));


        


More information about the llvm-commits mailing list