]> granicus.if.org Git - llvm/commitdiff
[WebAssembly] section kind can be code
authorSam Clegg <sbc@chromium.org>
Thu, 7 Dec 2017 02:55:51 +0000 (02:55 +0000)
committerSam Clegg <sbc@chromium.org>
Thu, 7 Dec 2017 02:55:51 +0000 (02:55 +0000)
Currently, when creating a named section, the Wasm
frontend forces it to use `SectionKind::Data`, whereas
in fact C++ does generate code sections with custom
names.

Patch by Nicholas Wilson

Differential Revision: https://reviews.llvm.org/D40906

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320002 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/TargetLoweringObjectFileImpl.cpp
test/MC/WebAssembly/custom-code-section.ll [new file with mode: 0644]

index 910ca4682b9295528be00218bf9459c5740c754d..925e67b01f613a312f8ac9867cdb88f91aa6f2b3 100644 (file)
@@ -1265,11 +1265,22 @@ static void checkWasmComdat(const GlobalValue *GV) {
                      "' cannot be lowered.");
 }
 
+static SectionKind getWasmKindForNamedSection(StringRef Name, SectionKind K) {
+  // If we're told we have function data, then use that.
+  if (K.isText())
+    return SectionKind::getText();
+
+  // Otherwise, ignore whatever section type the generic impl detected and use
+  // a plain data section.
+  return SectionKind::getData();
+}
+
 MCSection *TargetLoweringObjectFileWasm::getExplicitSectionGlobal(
     const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
   StringRef Name = GO->getSection();
   checkWasmComdat(GO);
-  return getContext().getWasmSection(Name, SectionKind::getData());
+  Kind = getWasmKindForNamedSection(Name, Kind);
+  return getContext().getWasmSection(Name, Kind);
 }
 
 static MCSectionWasm *selectWasmSectionForGlobal(
diff --git a/test/MC/WebAssembly/custom-code-section.ll b/test/MC/WebAssembly/custom-code-section.ll
new file mode 100644 (file)
index 0000000..d528d42
--- /dev/null
@@ -0,0 +1,9 @@
+; RUN: llc -mtriple wasm32-unknown-unknown-wasm -O2 -filetype=obj %s -o %t.o
+
+; Wasm silently ignores custom sections for code.
+; We had a bug where this cause a crash
+
+define hidden void @call_indirect() section "some_section_name" {
+entry:
+  ret void
+}