[llvm] 880c9c5 - [MC] Allow .cfi_sections with empty section list
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 25 22:29:56 PST 2021
Author: Fangrui Song
Date: 2021-02-25T22:29:49-08:00
New Revision: 880c9c56c1172418853cc81eeced492b4f0cefc2
URL: https://github.com/llvm/llvm-project/commit/880c9c56c1172418853cc81eeced492b4f0cefc2
DIFF: https://github.com/llvm/llvm-project/commit/880c9c56c1172418853cc81eeced492b4f0cefc2.diff
LOG: [MC] Allow .cfi_sections with empty section list
GNU as supports this. This mode silently ignores
.cfi_startproc/.cfi_endproc and .cfi_* in between.
Also drop a diagnostic `in '.cfi_sections' directive`: the diagnostic
already includes the line and it is clear the line is a `.cfi_sections` directive.
Added:
llvm/test/MC/ELF/cfi-sections-empty.s
Modified:
llvm/lib/MC/MCParser/AsmParser.cpp
llvm/lib/MC/MCStreamer.cpp
llvm/test/MC/ELF/cfi.s
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 2989041e64b2..3d2f0d83d2ad 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -4073,29 +4073,20 @@ bool AsmParser::parseDirectiveCFISections() {
bool EH = false;
bool Debug = false;
- if (parseIdentifier(Name))
- return TokError("Expected an identifier");
-
- if (Name == ".eh_frame")
- EH = true;
- else if (Name == ".debug_frame")
- Debug = true;
-
- if (getLexer().is(AsmToken::Comma)) {
- Lex();
-
- if (parseIdentifier(Name))
- return TokError("Expected an identifier");
-
- if (Name == ".eh_frame")
- EH = true;
- else if (Name == ".debug_frame")
- Debug = true;
+ if (!parseOptionalToken(AsmToken::EndOfStatement)) {
+ for (;;) {
+ if (parseIdentifier(Name))
+ return TokError("expected .eh_frame or .debug_frame");
+ if (Name == ".eh_frame")
+ EH = true;
+ else if (Name == ".debug_frame")
+ Debug = true;
+ if (parseOptionalToken(AsmToken::EndOfStatement))
+ break;
+ if (parseToken(AsmToken::Comma))
+ return true;
+ }
}
-
- if (parseToken(AsmToken::EndOfStatement))
- return addErrorSuffix(" in '.cfi_sections' directive");
-
getStreamer().emitCFISections(EH, Debug);
return false;
}
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 9b9e5b992316..b2fc54236f7f 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -429,9 +429,7 @@ void MCStreamer::emitLabel(MCSymbol *Symbol, SMLoc Loc) {
TS->emitLabel(Symbol);
}
-void MCStreamer::emitCFISections(bool EH, bool Debug) {
- assert(EH || Debug);
-}
+void MCStreamer::emitCFISections(bool EH, bool Debug) {}
void MCStreamer::emitCFIStartProc(bool IsSimple, SMLoc Loc) {
if (hasUnfinishedDwarfFrameInfo())
diff --git a/llvm/test/MC/ELF/cfi-sections-empty.s b/llvm/test/MC/ELF/cfi-sections-empty.s
new file mode 100644
index 000000000000..2b4b0468275e
--- /dev/null
+++ b/llvm/test/MC/ELF/cfi-sections-empty.s
@@ -0,0 +1,12 @@
+# RUN: llvm-mc -filetype=obj -triple x86_64 %s | llvm-readelf -S - | FileCheck %s
+
+# CHECK: Section Headers:
+# CHECK-NOT: .eh_frame
+# CHECK-NOT: .debug_frame
+
+.cfi_sections
+
+## .cfi_startproc and .cfi_endproc are ignored.
+.cfi_startproc
+nop
+.cfi_endproc
diff --git a/llvm/test/MC/ELF/cfi.s b/llvm/test/MC/ELF/cfi.s
index d1d9029bf493..8d0a28d6da57 100644
--- a/llvm/test/MC/ELF/cfi.s
+++ b/llvm/test/MC/ELF/cfi.s
@@ -438,11 +438,11 @@ f37:
// CHECK: }
.ifdef ERR
-// ERR: [[#@LINE+1]]:15: error: Expected an identifier
+// ERR: [[#@LINE+1]]:15: error: expected .eh_frame or .debug_frame
.cfi_sections $
-// ERR: [[#@LINE+1]]:28: error: unexpected token in '.cfi_sections' directive
+// ERR: [[#@LINE+1]]:28: error: unexpected token
.cfi_sections .debug_frame $
-// ERR: [[#@LINE+1]]:39: error: unexpected token in '.cfi_sections' directive
+// ERR: [[#@LINE+1]]:39: error: unexpected token
.cfi_sections .debug_frame, .eh_frame $
// ERR: [[#@LINE+1]]:16: error: unexpected token in '.cfi_startproc' directive
More information about the llvm-commits
mailing list