aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/MC/MCAssembler.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2024-06-23 10:08:51 -0700
committerFangrui Song <i@maskray.me>2024-06-23 10:08:52 -0700
commit21fac2d1d060b0f9b11a746718e58d4cd1ee97e5 (patch)
treee2f32591d8e4044b6a32d8691beb6330b81e4ee9 /llvm/lib/MC/MCAssembler.cpp
parent6dc8de7a0abc7df8295273694fd9b951ed33708f (diff)
downloadllvm-21fac2d1d060b0f9b11a746718e58d4cd1ee97e5.zip
llvm-21fac2d1d060b0f9b11a746718e58d4cd1ee97e5.tar.gz
llvm-21fac2d1d060b0f9b11a746718e58d4cd1ee97e5.tar.bz2
[MC] Ensure all new sections have a MCDataFragment
MCAssembler::layout ensures that every section has at least one fragment, which simplifies MCAsmLayout::getSectionAddressSize (see e73353c7201a3080851d99a16f5fe2c17f7697c6 from 2010). It's better to ensure the condition is satisfied at create time (COFF, GOFF, Mach-O) to simplify more fragment processing.
Diffstat (limited to 'llvm/lib/MC/MCAssembler.cpp')
-rw-r--r--llvm/lib/MC/MCAssembler.cpp12
1 files changed, 2 insertions, 10 deletions
diff --git a/llvm/lib/MC/MCAssembler.cpp b/llvm/lib/MC/MCAssembler.cpp
index fe0419b..f8b7e4b 100644
--- a/llvm/lib/MC/MCAssembler.cpp
+++ b/llvm/lib/MC/MCAssembler.cpp
@@ -126,6 +126,7 @@ void MCAssembler::reset() {
bool MCAssembler::registerSection(MCSection &Section) {
if (Section.isRegistered())
return false;
+ assert(Section.curFragList()->Head && "allocInitialFragment not called");
Sections.push_back(&Section);
Section.setIsRegistered(true);
return true;
@@ -856,17 +857,8 @@ void MCAssembler::layout(MCAsmLayout &Layout) {
// Create dummy fragments and assign section ordinals.
unsigned SectionIndex = 0;
- for (MCSection &Sec : *this) {
- // Create dummy fragments to eliminate any empty sections, this simplifies
- // layout.
- if (Sec.empty()) {
- auto *F = getContext().allocFragment<MCDataFragment>();
- F->setParent(&Sec);
- Sec.addFragment(*F);
- }
-
+ for (MCSection &Sec : *this)
Sec.setOrdinal(SectionIndex++);
- }
// Assign layout order indices to sections and fragments.
for (unsigned i = 0, e = Layout.getSectionOrder().size(); i != e; ++i) {