[llvm] Move MCSection::LayoutOrder to MCSectionMachO (PR #97474)
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 2 13:17:41 PDT 2024
https://github.com/MaskRay created https://github.com/llvm/llvm-project/pull/97474
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 7840c0066837797cdeb62aab63044b964aa7f372.
>From 78b30ce5118d2e895eb968294ad5b15902a68e09 Mon Sep 17 00:00:00 2001
From: Fangrui Song <i at maskray.me>
Date: Tue, 2 Jul 2024 13:17:31 -0700
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
=?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.5-bogner
---
llvm/include/llvm/MC/MCSection.h | 5 -----
llvm/include/llvm/MC/MCSectionMachO.h | 7 +++++++
llvm/lib/MC/MachObjectWriter.cpp | 6 +++---
3 files changed, 10 insertions(+), 8 deletions(-)
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++);
}
}
More information about the llvm-commits
mailing list