Skip to content

Commit 72d5f5a

Browse files
Sterling-Augustinemahesh-attarde
authored andcommitted
Reapply "Support SFrame command-line and .cfi_section syntax (llvm#150316) (llvm#150509)
This reverts commit ad36e42, fixing a single uninitialized bit (which cannot be detected with Address Sanitizer). This PR adds support for the llvm-mc command-line flag "--gsframe" and adds ".sframe" to the legal values passed ".cfi_section". It plumbs the option through the cfi handling code a fair amount. Code to support actual section generation follows in a future PR. These options match the gnu-assembler's support syntax for sframes, on both the command line and in assembly files. First in a series of changes that will allow llvm-mc to produce sframe .cfi sections. For more information about sframes, see https://sourceware.org/binutils/docs-2.44/sframe-spec.html and the llvm-RFC here: https://discourse.llvm.org/t/rfc-adding-sframe-support-to-llvm/86900
1 parent 9fd9839 commit 72d5f5a

File tree

14 files changed

+53
-20
lines changed

14 files changed

+53
-20
lines changed

llvm/include/llvm/MC/MCObjectStreamer.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ class MCObjectStreamer : public MCStreamer {
4040
std::unique_ptr<MCAssembler> Assembler;
4141
bool EmitEHFrame;
4242
bool EmitDebugFrame;
43+
bool EmitSFrame;
4344

4445
struct PendingAssignment {
4546
MCSymbol *Symbol;
@@ -70,7 +71,7 @@ class MCObjectStreamer : public MCStreamer {
7071

7172
void emitFrames(MCAsmBackend *MAB);
7273
MCSymbol *emitCFILabel() override;
73-
void emitCFISections(bool EH, bool Debug) override;
74+
void emitCFISections(bool EH, bool Debug, bool SFrame) override;
7475

7576
public:
7677
void visitUsedSymbol(const MCSymbol &Sym) override;

llvm/include/llvm/MC/MCStreamer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,7 @@ class LLVM_ABI MCStreamer {
986986
const MCSymbol *Lo);
987987

988988
virtual MCSymbol *getDwarfLineTableSymbol(unsigned CUID);
989-
virtual void emitCFISections(bool EH, bool Debug);
989+
virtual void emitCFISections(bool EH, bool Debug, bool SFrame);
990990
void emitCFIStartProc(bool IsSimple, SMLoc Loc = SMLoc());
991991
void emitCFIEndProc();
992992
virtual void emitCFIDefCfa(int64_t Register, int64_t Offset, SMLoc Loc = {});

llvm/include/llvm/MC/MCTargetOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ class MCTargetOptions {
102102
// functions on Darwins.
103103
bool EmitCompactUnwindNonCanonical : 1;
104104

105+
// Whether to emit SFrame unwind sections.
106+
bool EmitSFrameUnwind : 1;
107+
105108
// Whether or not to use full register names on PowerPC.
106109
bool PPCUseFullRegisterNames : 1;
107110

llvm/include/llvm/MC/MCTargetOptionsCommandFlags.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ LLVM_ABI EmitDwarfUnwindType getEmitDwarfUnwind();
4040

4141
LLVM_ABI bool getEmitCompactUnwindNonCanonical();
4242

43+
LLVM_ABI bool getEmitSFrameUnwind();
44+
4345
LLVM_ABI bool getShowMCInst();
4446

4547
LLVM_ABI bool getFatalWarnings();

llvm/lib/CodeGen/AsmPrinter/ARMException.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void ARMException::beginFunction(const MachineFunction *MF) {
3939
if (CFISecType == AsmPrinter::CFISection::Debug) {
4040
if (!hasEmittedCFISections) {
4141
if (Asm->getModuleCFISectionType() == AsmPrinter::CFISection::Debug)
42-
Asm->OutStreamer->emitCFISections(false, true);
42+
Asm->OutStreamer->emitCFISections(false, true, false);
4343
hasEmittedCFISections = true;
4444
}
4545

llvm/lib/CodeGen/AsmPrinter/DwarfCFIException.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,11 @@ void DwarfCFIException::beginBasicBlockSection(const MachineBasicBlock &MBB) {
109109
// chose not to be verbose in that case. And with `ForceDwarfFrameSection`,
110110
// we should always emit .debug_frame.
111111
if (CFISecType == AsmPrinter::CFISection::Debug ||
112-
Asm->TM.Options.ForceDwarfFrameSection)
112+
Asm->TM.Options.ForceDwarfFrameSection ||
113+
Asm->TM.Options.MCOptions.EmitSFrameUnwind)
113114
Asm->OutStreamer->emitCFISections(
114-
CFISecType == AsmPrinter::CFISection::EH, true);
115+
CFISecType == AsmPrinter::CFISection::EH, true,
116+
Asm->TM.Options.MCOptions.EmitSFrameUnwind);
115117
hasEmittedCFISections = true;
116118
}
117119

llvm/lib/MC/MCAsmStreamer.cpp

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ class MCAsmStreamer final : public MCStreamer {
345345
void emitIdent(StringRef IdentString) override;
346346
void emitCFIBKeyFrame() override;
347347
void emitCFIMTETaggedFrame() override;
348-
void emitCFISections(bool EH, bool Debug) override;
348+
void emitCFISections(bool EH, bool Debug, bool SFrame) override;
349349
void emitCFIDefCfa(int64_t Register, int64_t Offset, SMLoc Loc) override;
350350
void emitCFIDefCfaOffset(int64_t Offset, SMLoc Loc) override;
351351
void emitCFIDefCfaRegister(int64_t Register, SMLoc Loc) override;
@@ -1906,15 +1906,24 @@ void MCAsmStreamer::emitIdent(StringRef IdentString) {
19061906
EmitEOL();
19071907
}
19081908

1909-
void MCAsmStreamer::emitCFISections(bool EH, bool Debug) {
1910-
MCStreamer::emitCFISections(EH, Debug);
1909+
void MCAsmStreamer::emitCFISections(bool EH, bool Debug, bool SFrame) {
1910+
MCStreamer::emitCFISections(EH, Debug, SFrame);
19111911
OS << "\t.cfi_sections ";
1912+
bool C = false;
19121913
if (EH) {
19131914
OS << ".eh_frame";
1914-
if (Debug)
1915-
OS << ", .debug_frame";
1916-
} else if (Debug) {
1915+
C = true;
1916+
}
1917+
if (Debug) {
1918+
if (C)
1919+
OS << ", ";
19171920
OS << ".debug_frame";
1921+
C = true;
1922+
}
1923+
if (SFrame) {
1924+
if (C)
1925+
OS << ", ";
1926+
OS << ".sframe";
19181927
}
19191928

19201929
EmitEOL();

llvm/lib/MC/MCObjectStreamer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ void MCObjectStreamer::visitUsedSymbol(const MCSymbol &Sym) {
129129
Assembler->registerSymbol(Sym);
130130
}
131131

132-
void MCObjectStreamer::emitCFISections(bool EH, bool Debug) {
133-
MCStreamer::emitCFISections(EH, Debug);
132+
void MCObjectStreamer::emitCFISections(bool EH, bool Debug, bool SFrame) {
133+
MCStreamer::emitCFISections(EH, Debug, SFrame);
134134
EmitEHFrame = EH;
135135
EmitDebugFrame = Debug;
136+
EmitSFrame = SFrame;
136137
}
137138

138139
void MCObjectStreamer::emitValueImpl(const MCExpr *Value, unsigned Size,

llvm/lib/MC/MCParser/AsmParser.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4093,27 +4093,30 @@ bool AsmParser::parseDirectiveCVFPOData() {
40934093
}
40944094

40954095
/// parseDirectiveCFISections
4096-
/// ::= .cfi_sections section [, section]
4096+
/// ::= .cfi_sections section [, section][, section]
40974097
bool AsmParser::parseDirectiveCFISections() {
40984098
StringRef Name;
40994099
bool EH = false;
41004100
bool Debug = false;
4101+
bool SFrame = false;
41014102

41024103
if (!parseOptionalToken(AsmToken::EndOfStatement)) {
41034104
for (;;) {
41044105
if (parseIdentifier(Name))
4105-
return TokError("expected .eh_frame or .debug_frame");
4106+
return TokError("expected .eh_frame, .debug_frame, or .sframe");
41064107
if (Name == ".eh_frame")
41074108
EH = true;
41084109
else if (Name == ".debug_frame")
41094110
Debug = true;
4111+
else if (Name == ".sframe")
4112+
SFrame = true;
41104113
if (parseOptionalToken(AsmToken::EndOfStatement))
41114114
break;
41124115
if (parseComma())
41134116
return true;
41144117
}
41154118
}
4116-
getStreamer().emitCFISections(EH, Debug);
4119+
getStreamer().emitCFISections(EH, Debug, SFrame);
41174120
return false;
41184121
}
41194122

llvm/lib/MC/MCStreamer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ void MCStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
415415
void MCStreamer::emitConditionalAssignment(MCSymbol *Symbol,
416416
const MCExpr *Value) {}
417417

418-
void MCStreamer::emitCFISections(bool EH, bool Debug) {}
418+
void MCStreamer::emitCFISections(bool EH, bool Debug, bool SFrame) {}
419419

420420
void MCStreamer::emitCFIStartProc(bool IsSimple, SMLoc Loc) {
421421
if (!FrameInfoStack.empty() &&

0 commit comments

Comments
 (0)