[PATCH] D92952: [WebAssembly] Support COMDAT sections in assembly syntax
Derek Schuff via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 9 18:02:27 PST 2020
dschuff updated this revision to Diff 310735.
dschuff added a comment.
Simplify WebAssemblyAsmParser, add test for its behavior, add TODO
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D92952/new/
https://reviews.llvm.org/D92952
Files:
llvm/lib/MC/MCParser/WasmAsmParser.cpp
llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
llvm/test/MC/WebAssembly/comdat-sections.s
Index: llvm/test/MC/WebAssembly/comdat-sections.s
===================================================================
--- llvm/test/MC/WebAssembly/comdat-sections.s
+++ llvm/test/MC/WebAssembly/comdat-sections.s
@@ -7,12 +7,22 @@
.functype foo () -> ()
return
end_function
+
+ .globl bar
+ .type bar, at function
+bar:
+ .functype bar () -> ()
+ return
+ end_function
+
.section .debug_foo,"G",@,abc123,comdat
.int32 42
.section .debug_foo,"G",@,duplicate,comdat
.int64 234
+
+
# Check that there are 2 identically-named custom sections, with the desired
# contents
# CHECK: - Type: CUSTOM
@@ -31,6 +41,11 @@
# CHECK-NEXT: Entries:
# CHECK-NEXT: - Kind: FUNCTION
# CHECK-NEXT: Index: 0
+
+# If the user forgets to create a new section for a function, one is created for
+# them by the assembler. Check that it is also in the same group.
+# CHECK-NEXT: - Kind: FUNCTION
+# CHECK-NEXT: Index: 1
# CHECK-NEXT: - Kind: SECTION
# CHECK-NEXT: Index: 4
# CHECK-NEXT: - Name: duplicate
Index: llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
===================================================================
--- llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
+++ llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
@@ -971,23 +971,21 @@
auto SymName = Symbol->getName();
if (SymName.startswith(".L"))
return; // Local Symbol.
+
// Only create a new text section if we're already in one.
+ // TODO: If the user explicitly creates a new function section, we ignore
+ // its name when we create this one. It would be nice to honor their
+ // choice, while still ensuring that we create one if they forget.
+ // (that requires coordination with WasmAsmParser::parseSectionDirective)
auto CWS = cast<MCSectionWasm>(getStreamer().getCurrentSection().first);
if (!CWS || !CWS->getKind().isText())
return;
auto SecName = ".text." + SymName;
- MCSectionWasm *WS = CWS;
- if (cast<MCSymbolWasm>(Symbol)->isComdat()) {
- // If the function is a comdat function, then the user must have already
- // declared the section as such (because that's the only way the asm
- // parser can tell). In that case, just use the current section.
- assert(CWS->getGroup() &&
- "Current section for comdat function has no group");
- } else {
- WS = getContext().getWasmSection(SecName, SectionKind::getText());
- getStreamer().SwitchSection(WS);
- }
+ auto WS = getContext().getWasmSection(SecName, SectionKind::getText(),
+ CWS->getGroup(),
+ MCContext::GenericSectionID, nullptr);
+ getStreamer().SwitchSection(WS);
// Also generate DWARF for this section if requested.
if (getContext().getGenDwarfForAssembly())
getContext().addGenDwarfSection(WS);
Index: llvm/lib/MC/MCParser/WasmAsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/WasmAsmParser.cpp
+++ llvm/lib/MC/MCParser/WasmAsmParser.cpp
@@ -185,7 +185,6 @@
"Only data sections can be passive");
WS->setPassive();
}
-
getStreamer().SwitchSection(WS);
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92952.310735.patch
Type: text/x-patch
Size: 3527 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201210/0e6c221c/attachment.bin>
More information about the llvm-commits
mailing list