Skip to content

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Jul 23, 2025

registerSection should only be called by
MCObjectStreamer::changeSection. This will be utilized by a pending
change to move initial fragment allocation from MCContext::createSection
to MCStreamer::changeSection, resolving some issues (Fragments should
only be created when using MCSteramer, not during
MCContext::getELFSection calls)

MaskRay added 2 commits July 23, 2025 00:53
Created using spr 1.3.5-bogner

[skip ci]
Created using spr 1.3.5-bogner
@MaskRay MaskRay requested a review from redstar July 23, 2025 07:53
@llvmbot llvmbot added the llvm:mc Machine (object) code label Jul 23, 2025
@MaskRay MaskRay requested a review from uweigand July 23, 2025 07:53
@llvmbot
Copy link
Member

llvmbot commented Jul 23, 2025

@llvm/pr-subscribers-mc

Author: Fangrui Song (MaskRay)

Changes

registerSection should only be called by
MCObjectStreamer::changeSection. This will be utilized by a pending
change to move initial fragment allocation from MCContext::createSection
to MCStreamer::changeSection, resolving some issues (Fragments should
only be created when using MCSteramer, not during
MCContext::getELFSection calls)


Full diff: https://github.com/llvm/llvm-project/pull/150183.diff

1 Files Affected:

  • (modified) llvm/lib/MC/MCGOFFStreamer.cpp (+8-12)
diff --git a/llvm/lib/MC/MCGOFFStreamer.cpp b/llvm/lib/MC/MCGOFFStreamer.cpp
index b7021915e7b70..7828065a7f360 100644
--- a/llvm/lib/MC/MCGOFFStreamer.cpp
+++ b/llvm/lib/MC/MCGOFFStreamer.cpp
@@ -26,19 +26,15 @@ GOFFObjectWriter &MCGOFFStreamer::getWriter() {
   return static_cast<GOFFObjectWriter &>(getAssembler().getWriter());
 }
 
-// Make sure that all section are registered in the correct order.
-static void registerSectionHierarchy(MCAssembler &Asm, MCSectionGOFF *Section) {
-  if (Section->isRegistered())
-    return;
-  if (Section->getParent())
-    registerSectionHierarchy(Asm, Section->getParent());
-  Asm.registerSection(*Section);
-}
-
 void MCGOFFStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
-  registerSectionHierarchy(getAssembler(),
-                           static_cast<MCSectionGOFF *>(Section));
-  MCObjectStreamer::changeSection(Section, Subsection);
+  // Make sure that all section are registered in the correct order.
+  SmallVector<MCSectionGOFF *> Sections;
+  for (auto *S = static_cast<MCSectionGOFF *>(Section); S; S = S->getParent())
+    Sections.push_back(S);
+  while (!Sections.empty()) {
+    auto *S = Sections.pop_back_val();
+    MCObjectStreamer::changeSection(S, 0);
+  }
 }
 
 MCStreamer *llvm::createGOFFStreamer(MCContext &Context,

Sections.push_back(S);
while (!Sections.empty()) {
auto *S = Sections.pop_back_val();
MCObjectStreamer::changeSection(S, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this now completely ignores the Subsection parameter?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

subsection is a GNU Assembler feature. In LLVM only ELF targets use it. Does GOFF use it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not as such in the file format, but the LLVM back-end currently uses subsections to subdivide the text section for proper placement of the PPA annotations, see GOFF::SK_PPA1 and GOFF::SK_PPA2.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated. I think GOFF team needs to add tests to show that incorrect changeSection would lead to PPA1/PPA2 failures.

MaskRay added 2 commits July 23, 2025 19:04
Created using spr 1.3.5-bogner

[skip ci]
Created using spr 1.3.5-bogner
@MaskRay MaskRay requested a review from uweigand July 24, 2025 02:07
MaskRay added 2 commits July 23, 2025 20:19
Created using spr 1.3.5-bogner

[skip ci]
.
Created using spr 1.3.5-bogner
MaskRay added 2 commits July 23, 2025 23:33
Created using spr 1.3.5-bogner

[skip ci]
Created using spr 1.3.5-bogner
@MaskRay MaskRay changed the base branch from users/MaskRay/spr/main.goff-only-register-sections-within-mcobjectstreamerchangesection to main July 24, 2025 06:34
Copy link
Member

@uweigand uweigand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this LGTM now.

@MaskRay MaskRay merged commit b0dea47 into main Jul 25, 2025
12 of 15 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/goff-only-register-sections-within-mcobjectstreamerchangesection branch July 25, 2025 03:12
llvm-sync bot pushed a commit to arm/arm-toolchain that referenced this pull request Jul 25, 2025
…geSection

registerSection should only be called by
MCObjectStreamer::changeSection. This will be utilized by a pending
change to move initial fragment allocation from MCContext::createSection
to MCStreamer::changeSection, resolving some issues (Fragments should
only be created when using MCSteramer, not during
`MCContext::getELFSection` calls)

Pull Request: llvm/llvm-project#150183
mahesh-attarde pushed a commit to mahesh-attarde/llvm-project that referenced this pull request Jul 28, 2025
registerSection should only be called by
MCObjectStreamer::changeSection. This will be utilized by a pending
change to move initial fragment allocation from MCContext::createSection
to MCStreamer::changeSection, resolving some issues (Fragments should
only be created when using MCSteramer, not during
`MCContext::getELFSection` calls)

Pull Request: llvm#150183
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:mc Machine (object) code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants