[llvm] aa86f4f - [MC] Remove unnecessary DWARFMustBeAtTheEnd check
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 20 10:43:56 PDT 2024
Author: Fangrui Song
Date: 2024-07-20T10:43:52-07:00
New Revision: aa86f4f18549583f9227276cd116dbaf5625aa78
URL: https://github.com/llvm/llvm-project/commit/aa86f4f18549583f9227276cd116dbaf5625aa78
DIFF: https://github.com/llvm/llvm-project/commit/aa86f4f18549583f9227276cd116dbaf5625aa78.diff
LOG: [MC] Remove unnecessary DWARFMustBeAtTheEnd check
36a15cb975334403216e6145d4abece3026af17a 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
20e5f5ed7930efdf2bd34bf099f24ac88798c5ea (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
(e9ad54b3ee905ea3a77c35ca7d6e843b2c552e0b (2015)).
Added:
Modified:
llvm/include/llvm/MC/TargetRegistry.h
llvm/lib/CodeGen/LLVMTargetMachine.cpp
llvm/lib/MC/MCMachOStreamer.cpp
llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/MC/TargetRegistry.h b/llvm/include/llvm/MC/TargetRegistry.h
index 75387f84149db..68eb02076a8f6 100644
--- a/llvm/include/llvm/MC/TargetRegistry.h
+++ b/llvm/include/llvm/MC/TargetRegistry.h
@@ -201,8 +201,7 @@ class Target {
using MachOStreamerCtorTy =
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&Emitter,
- bool DWARFMustBeAtTheEnd);
+ std::unique_ptr<MCCodeEmitter> &&Emitter);
using COFFStreamerCtorTy =
MCStreamer *(*)(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
std::unique_ptr<MCObjectWriter> &&OW,
@@ -559,7 +558,7 @@ class Target {
std::unique_ptr<MCObjectWriter> &&OW,
std::unique_ptr<MCCodeEmitter> &&Emitter,
const MCSubtargetInfo &STI, bool, bool,
- bool DWARFMustBeAtTheEnd) const {
+ bool) const {
MCStreamer *S = nullptr;
switch (T.getObjectFormat()) {
case Triple::UnknownObjectFormat:
@@ -573,10 +572,10 @@ class Target {
case Triple::MachO:
if (MachOStreamerCtorFn)
S = MachOStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), DWARFMustBeAtTheEnd);
+ std::move(Emitter));
else
S = createMachOStreamer(Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), DWARFMustBeAtTheEnd);
+ std::move(Emitter), false);
break;
case Triple::ELF:
if (ELFStreamerCtorFn)
diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index 1d13173632833..3092177e37e98 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -208,9 +208,8 @@ Expected<std::unique_ptr<MCStreamer>> LLVMTargetMachine::createMCStreamer(
T, Context, std::unique_ptr<MCAsmBackend>(MAB),
DwoOut ? MAB->createDwoObjectWriter(Out, *DwoOut)
: MAB->createObjectWriter(Out),
- std::unique_ptr<MCCodeEmitter>(MCE), STI, Options.MCOptions.MCRelaxAll,
- Options.MCOptions.MCIncrementalLinkerCompatible,
- /*DWARFMustBeAtTheEnd*/ true));
+ std::unique_ptr<MCCodeEmitter>(MCE), STI, /*ignore=*/false, false,
+ false));
break;
}
case CodeGenFileType::Null:
@@ -284,9 +283,7 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
const Triple &T = getTargetTriple();
std::unique_ptr<MCStreamer> AsmStreamer(getTarget().createMCObjectStreamer(
T, *Ctx, std::move(MAB), MAB->createObjectWriter(Out), std::move(MCE),
- STI, Options.MCOptions.MCRelaxAll,
- Options.MCOptions.MCIncrementalLinkerCompatible,
- /*DWARFMustBeAtTheEnd*/ true));
+ STI, /*ignore=*/false, false, false));
// Create the AsmPrinter, which takes ownership of AsmStreamer if successful.
FunctionPass *Printer =
diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp
index c8bc819129850..5231d10626f85 100644
--- a/llvm/lib/MC/MCMachOStreamer.cpp
+++ b/llvm/lib/MC/MCMachOStreamer.cpp
@@ -54,9 +54,6 @@ class MCMachOStreamer : public MCObjectStreamer {
/// need for local relocations. False by default.
bool LabelSections;
- bool DWARFMustBeAtTheEnd;
- bool CreatedADWARFSection;
-
/// HasSectionLabel - map of which sections have already had a non-local
/// label emitted to them. Used so we don't emit extraneous linker local
/// labels in the middle of the section.
@@ -70,16 +67,13 @@ class MCMachOStreamer : public MCObjectStreamer {
public:
MCMachOStreamer(MCContext &Context, std::unique_ptr<MCAsmBackend> MAB,
std::unique_ptr<MCObjectWriter> OW,
- std::unique_ptr<MCCodeEmitter> Emitter,
- bool DWARFMustBeAtTheEnd, bool label)
+ std::unique_ptr<MCCodeEmitter> Emitter, bool label)
: MCObjectStreamer(Context, std::move(MAB), std::move(OW),
std::move(Emitter)),
- LabelSections(label), DWARFMustBeAtTheEnd(DWARFMustBeAtTheEnd),
- CreatedADWARFSection(false) {}
+ LabelSections(label) {}
/// state management
void reset() override {
- CreatedADWARFSection = false;
HasSectionLabel.clear();
MCObjectStreamer::reset();
}
@@ -141,48 +135,9 @@ class MCMachOStreamer : public MCObjectStreamer {
} // end anonymous namespace.
-static bool canGoAfterDWARF(const MCSectionMachO &MSec) {
- // These sections are created by the assembler itself after the end of
- // the .s file.
- StringRef SegName = MSec.getSegmentName();
- StringRef SecName = MSec.getName();
-
- if (SegName == "__LD" && SecName == "__compact_unwind")
- return true;
-
- if (SegName == "__IMPORT") {
- if (SecName == "__jump_table")
- return true;
-
- if (SecName == "__pointers")
- return true;
- }
-
- if (SegName == "__TEXT" && SecName == "__eh_frame")
- return true;
-
- if (SegName == "__DATA" &&
- (SecName == "__llvm_addrsig" || SecName == "__nl_symbol_ptr" ||
- SecName == "__thread_ptr"))
- return true;
- if (SegName == "__LLVM" && (SecName == "__cg_profile"))
- return true;
-
- if (SegName == "__DATA" && SecName == "__auth_ptr")
- return true;
-
- return false;
-}
-
void MCMachOStreamer::changeSection(MCSection *Section, uint32_t Subsection) {
// Change the section normally.
- bool Created = changeSectionImpl(Section, Subsection);
- const MCSectionMachO &MSec = *cast<MCSectionMachO>(Section);
- StringRef SegName = MSec.getSegmentName();
- if (SegName == "__DWARF")
- CreatedADWARFSection = true;
- else if (Created && DWARFMustBeAtTheEnd && !canGoAfterDWARF(MSec))
- assert(!CreatedADWARFSection && "Creating regular section after DWARF");
+ changeSectionImpl(Section, Subsection);
// Output a linker-local symbol so we don't need section-relative local
// relocations. The linker hates us when we do that.
@@ -576,9 +531,8 @@ MCStreamer *llvm::createMachOStreamer(MCContext &Context,
std::unique_ptr<MCCodeEmitter> &&CE,
bool DWARFMustBeAtTheEnd,
bool LabelSections) {
- MCMachOStreamer *S =
- new MCMachOStreamer(Context, std::move(MAB), std::move(OW), std::move(CE),
- DWARFMustBeAtTheEnd, LabelSections);
+ MCMachOStreamer *S = new MCMachOStreamer(
+ Context, std::move(MAB), std::move(OW), std::move(CE), LabelSections);
const Triple &Target = Context.getTargetTriple();
S->emitVersionForTarget(
Target, Context.getObjectFileInfo()->getSDKVersion(),
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
index 1e367be9fa4ae..97c5f96388abe 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MCTargetDesc.cpp
@@ -386,13 +386,12 @@ static MCStreamer *createELFStreamer(const Triple &T, MCContext &Ctx,
std::move(Emitter));
}
-static MCStreamer *createMachOStreamer(MCContext &Ctx,
- std::unique_ptr<MCAsmBackend> &&TAB,
- std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&Emitter,
- bool DWARFMustBeAtTheEnd) {
+static MCStreamer *
+createMachOStreamer(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&TAB,
+ std::unique_ptr<MCObjectWriter> &&OW,
+ std::unique_ptr<MCCodeEmitter> &&Emitter) {
return createMachOStreamer(Ctx, std::move(TAB), std::move(OW),
- std::move(Emitter), DWARFMustBeAtTheEnd,
+ std::move(Emitter), /*ignore=*/false,
/*LabelSections*/ true);
}
diff --git a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
index 20603b6cf1b0b..cf4fc37f84553 100644
--- a/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
+++ b/llvm/lib/Target/ARM/MCTargetDesc/ARMMCTargetDesc.cpp
@@ -369,10 +369,9 @@ static MCStreamer *createELFStreamer(const Triple &T, MCContext &Ctx,
static MCStreamer *
createARMMachOStreamer(MCContext &Ctx, std::unique_ptr<MCAsmBackend> &&MAB,
std::unique_ptr<MCObjectWriter> &&OW,
- std::unique_ptr<MCCodeEmitter> &&Emitter,
- bool DWARFMustBeAtTheEnd) {
+ std::unique_ptr<MCCodeEmitter> &&Emitter) {
return createMachOStreamer(Ctx, std::move(MAB), std::move(OW),
- std::move(Emitter), DWARFMustBeAtTheEnd);
+ std::move(Emitter), false);
}
static MCInstPrinter *createARMMCInstPrinter(const Triple &T,
More information about the llvm-commits
mailing list