Skip to content

Move MCSection::LayoutOrder to MCSectionMachO #97474

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Jul 2, 2024

This variable is similar to Ordinal but only used for Mach-O to place
zerofill sections ("virtual sections" in MC term) after non-zerofill ones.

Follow-up to 7840c00.

Created using spr 1.3.5-bogner
@llvmbot llvmbot added the mc Machine (object) code label Jul 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 2, 2024

@llvm/pr-subscribers-mc

Author: Fangrui Song (MaskRay)

Changes

This variable is similar to Ordinal but only used for Mach-O to place
zerofill sections ("virtual sections" in MC term) after non-zerofill ones.

Follow-up to 7840c00.


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

3 Files Affected:

  • (modified) llvm/include/llvm/MC/MCSection.h (-5)
  • (modified) llvm/include/llvm/MC/MCSectionMachO.h (+7)
  • (modified) llvm/lib/MC/MachObjectWriter.cpp (+3-3)
diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h
index 58ba34c07262b..54f7eb1d0fcfc 100644
--- a/llvm/include/llvm/MC/MCSection.h
+++ b/llvm/include/llvm/MC/MCSection.h
@@ -86,8 +86,6 @@ class MCSection {
   Align Alignment;
   /// The section index in the assemblers section list.
   unsigned Ordinal = 0;
-  /// The index of this section in the layout order.
-  unsigned LayoutOrder = 0;
 
   /// Keeping track of bundle-locked state.
   BundleLockStateType BundleLockState = NotBundleLocked;
@@ -167,9 +165,6 @@ class MCSection {
   unsigned getOrdinal() const { return Ordinal; }
   void setOrdinal(unsigned Value) { Ordinal = Value; }
 
-  unsigned getLayoutOrder() const { return LayoutOrder; }
-  void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
-
   BundleLockStateType getBundleLockState() const { return BundleLockState; }
   void setBundleLockState(BundleLockStateType NewState);
   bool isBundleLocked() const { return BundleLockState != NotBundleLocked; }
diff --git a/llvm/include/llvm/MC/MCSectionMachO.h b/llvm/include/llvm/MC/MCSectionMachO.h
index 3b7623fd450e5..1f38d24a20d2e 100644
--- a/llvm/include/llvm/MC/MCSectionMachO.h
+++ b/llvm/include/llvm/MC/MCSectionMachO.h
@@ -32,6 +32,10 @@ class MCSectionMachO final : public MCSection {
   /// for example.
   unsigned Reserved2;
 
+  // The index of this section in MachObjectWriter::SectionOrder, which is
+  // different from MCSection::Ordinal.
+  unsigned LayoutOrder = 0;
+
   // The defining non-temporary symbol for each fragment.
   SmallVector<const MCSymbol *, 0> Atoms;
 
@@ -80,6 +84,9 @@ class MCSectionMachO final : public MCSection {
   const MCSymbol *getAtom(size_t I) const;
   void setAtom(size_t I, const MCSymbol *Sym);
 
+  unsigned getLayoutOrder() const { return LayoutOrder; }
+  void setLayoutOrder(unsigned Value) { LayoutOrder = Value; }
+
   static bool classof(const MCSection *S) {
     return S->getVariant() == SV_MachO;
   }
diff --git a/llvm/lib/MC/MachObjectWriter.cpp b/llvm/lib/MC/MachObjectWriter.cpp
index 3f5bdd88574ac..12048e2e53442 100644
--- a/llvm/lib/MC/MachObjectWriter.cpp
+++ b/llvm/lib/MC/MachObjectWriter.cpp
@@ -125,7 +125,7 @@ uint64_t MachObjectWriter::getSymbolAddress(const MCSymbol &S,
 uint64_t MachObjectWriter::getPaddingSize(const MCAssembler &Asm,
                                           const MCSection *Sec) const {
   uint64_t EndAddr = getSectionAddress(Sec) + Asm.getSectionAddressSize(*Sec);
-  unsigned Next = Sec->getLayoutOrder() + 1;
+  unsigned Next = cast<MCSectionMachO>(Sec)->getLayoutOrder() + 1;
   if (Next >= SectionOrder.size())
     return 0;
 
@@ -676,13 +676,13 @@ void MachObjectWriter::computeSectionAddresses(const MCAssembler &Asm) {
   for (MCSection &Sec : Asm) {
     if (!Sec.isVirtualSection()) {
       SectionOrder.push_back(&Sec);
-      Sec.setLayoutOrder(i++);
+      cast<MCSectionMachO>(Sec).setLayoutOrder(i++);
     }
   }
   for (MCSection &Sec : Asm) {
     if (Sec.isVirtualSection()) {
       SectionOrder.push_back(&Sec);
-      Sec.setLayoutOrder(i++);
+      cast<MCSectionMachO>(Sec).setLayoutOrder(i++);
     }
   }
 

@MaskRay MaskRay merged commit 1490141 into main Jul 2, 2024
7 of 8 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/move-mcsectionlayoutorder-to-mcsectionmacho branch July 2, 2024 21:11
lravenclaw pushed a commit to lravenclaw/llvm-project that referenced this pull request Jul 3, 2024
This variable is similar to `Ordinal` but only used for Mach-O to place
zerofill sections ("virtual sections" in MC term) after non-zerofill ones.

Follow-up to 7840c00.

Pull Request: llvm#97474
kbluck pushed a commit to kbluck/llvm-project that referenced this pull request Jul 6, 2024
This variable is similar to `Ordinal` but only used for Mach-O to place
zerofill sections ("virtual sections" in MC term) after non-zerofill ones.

Follow-up to 7840c00.

Pull Request: llvm#97474
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mc Machine (object) code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants