Skip to content

Commit aa86f4f

Browse files
committed
[MC] Remove unnecessary DWARFMustBeAtTheEnd check
36a15cb introduced the DWARFMustBeAtTheEnd check to ensure DWARF sections were placed after all text sections to help avoid out-of-range branches for Darwin ARM. The commit removed a Darwin ARM hack from 20e5f5e (2009), likely due to a no-longer-relevant assembler limitation. However, this check is no longer relevant due to the following: * Our CodeGen approach reliably places DWARF sections at the end. * Darwin AArch32 is less relevant today. Removing this check also addresses a minor clang cc1as crash that could occur when text sections were placed after DWARF sections (e9ad54b (2015)).
1 parent 29be889 commit aa86f4f

File tree

5 files changed

+19
-71
lines changed

5 files changed

+19
-71
lines changed

llvm/include/llvm/MC/TargetRegistry.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,7 @@ class Target {
201201
using MachOStreamerCtorTy =
202202
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
203203
std::unique_ptr<MCObjectWriter> &&OW,
204-
std::unique_ptr<MCCodeEmitter> &&Emitter,
205-
bool DWARFMustBeAtTheEnd);
204+
std::unique_ptr<MCCodeEmitter> &&Emitter);
206205
using COFFStreamerCtorTy =
207206
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
208207
std::unique_ptr<MCObjectWriter> &&OW,
@@ -559,7 +558,7 @@ class Target {
559558
std::unique_ptr<MCObjectWriter> &&OW,
560559
std::unique_ptr<MCCodeEmitter> &&Emitter,
561560
const MCSubtargetInfo &STI, bool, bool,
562-
bool DWARFMustBeAtTheEnd) const {
561+
bool) const {
563562
MCStreamer *S = nullptr;
564563
switch (T.getObjectFormat()) {
565564
case Triple::UnknownObjectFormat:
@@ -573,10 +572,10 @@ class Target {
573572
case Triple::MachO:
574573
if (MachOStreamerCtorFn)
575574
S = MachOStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
576-
std::move(Emitter), DWARFMustBeAtTheEnd);
575+
std::move(Emitter));
577576
else
578577
S = createMachOStreamer(Ctx, std::move(TAB), std::move(OW),
579-
std::move(Emitter), DWARFMustBeAtTheEnd);
578+
std::move(Emitter), false);
580579
break;
581580
case Triple::ELF:
582581
if (ELFStreamerCtorFn)

llvm/lib/CodeGen/LLVMTargetMachine.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,8 @@ Expected<std::unique_ptr<MCStreamer>> LLVMTargetMachine::createMCStreamer(
208208
T, Context, std::unique_ptr<MCAsmBackend>(MAB),
209209
DwoOut ? MAB->createDwoObjectWriter(Out, *DwoOut)
210210
: MAB->createObjectWriter(Out),
211-
std::unique_ptr<MCCodeEmitter>(MCE), STI, Options.MCOptions.MCRelaxAll,
212-
Options.MCOptions.MCIncrementalLinkerCompatible,
213-
/*DWARFMustBeAtTheEnd*/ true));
211+
std::unique_ptr<MCCodeEmitter>(MCE), STI, /*ignore=*/false, false,
212+
false));
214213
break;
215214
}
216215
case CodeGenFileType::Null:
@@ -284,9 +283,7 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
284283
const Triple &T = getTargetTriple();
285284
std::unique_ptr<MCStreamer> AsmStreamer(getTarget().createMCObjectStreamer(
286285
T, *Ctx, std::move(MAB), MAB->createObjectWriter(Out), std::move(MCE),
287-
STI, Options.MCOptions.MCRelaxAll,
288-
Options.MCOptions.MCIncrementalLinkerCompatible,
289-
/*DWARFMustBeAtTheEnd*/ true));
286+
STI, /*ignore=*/false, false, false));
290287

291288
// Create the AsmPrinter, which takes ownership of AsmStreamer if successful.
292289
FunctionPass *Printer =

llvm/lib/MC/MCMachOStreamer.cpp

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ class MCMachOStreamer : public MCObjectStreamer {
5454
/// need for local relocations. False by default.
5555
bool LabelSections;
5656

57-
bool DWARFMustBeAtTheEnd;
58-
bool CreatedADWARFSection;
59-
6057
/// HasSectionLabel - map of which sections have already had a non-local
6158
/// label emitted to them. Used so we don't emit extraneous linker local
6259
/// labels in the middle of the section.
@@ -70,16 +67,13 @@ class MCMachOStreamer : public MCObjectStreamer {
7067
public:
7168
MCMachOStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
7269
std::unique_ptr<MCObjectWriter> OW,
73-
std::unique_ptr<MCCodeEmitter> Emitter,
74-
bool DWARFMustBeAtTheEnd, bool label)
70+
std::unique_ptr<MCCodeEmitter> Emitter, bool label)
7571
: MCObjectStreamer(Context, std::move(MAB), std::move(OW),
7672
std::move(Emitter)),
77-
LabelSections(label), DWARFMustBeAtTheEnd(DWARFMustBeAtTheEnd),
78-
CreatedADWARFSection(false) {}
73+
LabelSections(label) {}
7974

8075
/// state management
8176
void reset() override {
82-
CreatedADWARFSection = false;
8377
HasSectionLabel.clear();
8478
MCObjectStreamer::reset();
8579
}
@@ -141,48 +135,9 @@ class MCMachOStreamer : public MCObjectStreamer {
141135

142136
} // end anonymous namespace.
143137

144-
static bool canGoAfterDWARF(const MCSectionMachO &MSec) {
145-
// These sections are created by the assembler itself after the end of
146-
// the .s file.
147-
StringRef SegName = MSec.getSegmentName();
148-
StringRef SecName = MSec.getName();
149-
150-
if (SegName == "__LD" && SecName == "__compact_unwind")
151-
return true;
152-
153-
if (SegName == "__IMPORT") {
154-
if (SecName == "__jump_table")
155-
return true;
156-
157-
if (SecName == "__pointers")
158-
return true;
159-
}
160-
161-
if (SegName == "__TEXT" && SecName == "__eh_frame")
162-
return true;
163-
164-
if (SegName == "__DATA" &&
165-
(SecName == "__llvm_addrsig" || SecName == "__nl_symbol_ptr" ||
166-
SecName == "__thread_ptr"))
167-
return true;
168-
if (SegName == "__LLVM" && (SecName == "__cg_profile"))
169-
return true;
170-
171-
if (SegName == "__DATA" && SecName == "__auth_ptr")
172-
return true;
173-
174-
return false;
175-
}
176-
177138
void MCMachOStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
178139
// Change the section normally.
179-
bool Created = changeSectionImpl(Section, Subsection);
180-
const MCSectionMachO &MSec = *cast<MCSectionMachO>(Section);
181-
StringRef SegName = MSec.getSegmentName();
182-
if (SegName == "__DWARF")
183-
CreatedADWARFSection = true;
184-
else if (Created && DWARFMustBeAtTheEnd && !canGoAfterDWARF(MSec))
185-
assert(!CreatedADWARFSection && "Creating regular section after DWARF");
140+
changeSectionImpl(Section, Subsection);
186141

187142
// Output a linker-local symbol so we don't need section-relative local
188143
// relocations. The linker hates us when we do that.
@@ -576,9 +531,8 @@ MCStreamer *llvm::createMachOStreamer(MCContext &Context,
576531
std::unique_ptr<MCCodeEmitter> &&CE,
577532
bool DWARFMustBeAtTheEnd,
578533
bool LabelSections) {
579-
MCMachOStreamer *S =
580-
new MCMachOStreamer(Context, std::move(MAB), std::move(OW), std::move(CE),
581-
DWARFMustBeAtTheEnd, LabelSections);
534+
MCMachOStreamer *S = new MCMachOStreamer(
535+
Context, std::move(MAB), std::move(OW), std::move(CE), LabelSections);
582536
const Triple &Target = Context.getTargetTriple();
583537
S->emitVersionForTarget(
584538
Target, Context.getObjectFileInfo()->getSDKVersion(),

llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -386,13 +386,12 @@ static MCStreamer *createELFStreamer(const Triple &T, MCContext &Ctx,
386386
std::move(Emitter));
387387
}
388388

389-
static MCStreamer *createMachOStreamer(MCContext &Ctx,
390-
std::unique_ptr<MCAsmBackend> &&TAB,
391-
std::unique_ptr<MCObjectWriter> &&OW,
392-
std::unique_ptr<MCCodeEmitter> &&Emitter,
393-
bool DWARFMustBeAtTheEnd) {
389+
static MCStreamer *
390+
createMachOStreamer(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
391+
std::unique_ptr<MCObjectWriter> &&OW,
392+
std::unique_ptr<MCCodeEmitter> &&Emitter) {
394393
return createMachOStreamer(Ctx, std::move(TAB), std::move(OW),
395-
std::move(Emitter), DWARFMustBeAtTheEnd,
394+
std::move(Emitter), /*ignore=*/false,
396395
/*LabelSections*/ true);
397396
}
398397

llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,9 @@ static MCStreamer *createELFStreamer(const Triple &T, MCContext &Ctx,
369369
static MCStreamer *
370370
createARMMachOStreamer(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&MAB,
371371
std::unique_ptr<MCObjectWriter> &&OW,
372-
std::unique_ptr<MCCodeEmitter> &&Emitter,
373-
bool DWARFMustBeAtTheEnd) {
372+
std::unique_ptr<MCCodeEmitter> &&Emitter) {
374373
return createMachOStreamer(Ctx, std::move(MAB), std::move(OW),
375-
std::move(Emitter), DWARFMustBeAtTheEnd);
374+
std::move(Emitter), false);
376375
}
377376

378377
static MCInstPrinter *createARMMCInstPrinter(const Triple &T,

0 commit comments

Comments
 (0)