[PATCH] D95838: [WebAssembly] Prevent data inside text sections in assembly
Wouter van Oortmerssen via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 1 17:22:49 PST 2021
aardappel created this revision.
aardappel added reviewers: dschuff, sbc100.
Herald added subscribers: ecnelises, sunfish, hiraditya, jgravelle-google.
aardappel requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.
This is not supported in Wasm, unless the data was encoded instructions, but that wouldn't work with the assembler's other functionality (enforcing nesting etc.).
Fixes: https://bugs.llvm.org/show_bug.cgi?id=48971
https://reviews.llvm.org/D95838
Files:
llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
llvm/lib/MC/MCParser/WasmAsmParser.cpp
llvm/lib/MC/WasmObjectWriter.cpp
llvm/test/MC/WebAssembly/debug-byval-struct.ll
Index: llvm/test/MC/WebAssembly/debug-byval-struct.ll
===================================================================
--- llvm/test/MC/WebAssembly/debug-byval-struct.ll
+++ llvm/test/MC/WebAssembly/debug-byval-struct.ll
@@ -103,11 +103,11 @@
; CHECK-NEXT: DW_AT_name ("x")
; CHECK-LABEL: DW_TAG_formal_parameter
-; CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x1, DW_OP_deref, DW_OP_stack_value)
+; CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x1, DW_OP_deref)
; CHECK-NEXT: DW_AT_name ("some_union")
; CHECK-LABEL: DW_TAG_formal_parameter
-; CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x2, DW_OP_deref, DW_OP_stack_value)
+; CHECK-NEXT: DW_AT_location (DW_OP_WASM_location 0x0 0x2, DW_OP_deref)
; CHECK-NEXT: DW_AT_name ("some_struct")
; CHECK-LABEL: DW_TAG_formal_parameter
Index: llvm/lib/MC/WasmObjectWriter.cpp
===================================================================
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -488,10 +488,14 @@
const MCSymbol *SectionSymbol = nullptr;
const MCSection &SecA = SymA->getSection();
- if (SecA.getKind().isText())
- SectionSymbol = SectionFunctions.find(&SecA)->second;
- else
+ if (SecA.getKind().isText()) {
+ auto &SecSymIt = SectionFunctions.find(&SecA);
+ if (SecSymIt == SectionFunctions.end())
+ report_fatal_error("section doesn\'t have defining symbol");
+ SectionSymbol = SecSymIt->second;
+ } else {
SectionSymbol = SecA.getBeginSymbol();
+ }
if (!SectionSymbol)
report_fatal_error("section symbol is required for relocation");
Index: llvm/lib/MC/MCParser/WasmAsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/WasmAsmParser.cpp
+++ llvm/lib/MC/MCParser/WasmAsmParser.cpp
@@ -221,18 +221,22 @@
Lexer->is(AsmToken::Identifier)))
return error("Expected label, at type declaration, got: ", Lexer->getTok());
auto TypeName = Lexer->getTok().getString();
+ auto *Current =
+ cast<MCSectionWasm>(getStreamer().getCurrentSection().first);
if (TypeName == "function") {
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION);
- auto *Current =
- cast<MCSectionWasm>(getStreamer().getCurrentSection().first);
if (Current->getGroup())
WasmSym->setComdat(true);
- } else if (TypeName == "global")
+ } else if (TypeName == "global") {
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL);
- else if (TypeName == "object")
+ } else if (TypeName == "object") {
+ if (Current->getKind().isText())
+ return error("WASM doesn\'t support data symbols in text sections: ",
+ Lexer->getTok());
WasmSym->setType(wasm::WASM_SYMBOL_TYPE_DATA);
- else
+ } else {
return error("Unknown WASM symbol type: ", Lexer->getTok());
+ }
Lex();
return expect(AsmToken::EndOfStatement, "EOL");
}
Index: llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
+++ llvm/lib/CodeGen/AsmPrinter/DwarfExpression.cpp
@@ -664,11 +664,15 @@
}
void DwarfExpression::addWasmLocation(unsigned Index, uint64_t Offset) {
- assert(LocationKind == Implicit || LocationKind == Unknown);
- LocationKind = Implicit;
emitOp(dwarf::DW_OP_WASM_location);
emitUnsigned(Index == 4/*TI_LOCAL_INDIRECT*/ ? 0/*TI_LOCAL*/ : Index);
emitUnsigned(Offset);
- if (Index == 4/*TI_LOCAL_INDIRECT*/)
+ if (Index == 4 /*TI_LOCAL_INDIRECT*/) {
emitOp(dwarf::DW_OP_deref);
+ assert(LocationKind == Unknown);
+ LocationKind = Memory;
+ } else {
+ assert(LocationKind == Implicit || LocationKind == Unknown);
+ LocationKind = Implicit;
+ }
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95838.320639.patch
Type: text/x-patch
Size: 3899 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210202/5714c8cc/attachment.bin>
More information about the llvm-commits
mailing list