[llvm] r320002 - [WebAssembly] section kind can be code

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 18:55:51 PST 2017


Author: sbc
Date: Wed Dec  6 18:55:51 2017
New Revision: 320002

URL: http://llvm.org/viewvc/llvm-project?rev=320002&view=rev
Log:
[WebAssembly] section kind can be code

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

Added:
    llvm/trunk/test/MC/WebAssembly/custom-code-section.ll
Modified:
    llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp

Modified: llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp?rev=320002&r1=320001&r2=320002&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp (original)
+++ llvm/trunk/lib/CodeGen/TargetLoweringObjectFileImpl.cpp Wed Dec  6 18:55:51 2017
@@ -1265,11 +1265,22 @@ static void checkWasmComdat(const Global
                      "' 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(

Added: llvm/trunk/test/MC/WebAssembly/custom-code-section.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/WebAssembly/custom-code-section.ll?rev=320002&view=auto
==============================================================================
--- llvm/trunk/test/MC/WebAssembly/custom-code-section.ll (added)
+++ llvm/trunk/test/MC/WebAssembly/custom-code-section.ll Wed Dec  6 18:55:51 2017
@@ -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
+}




More information about the llvm-commits mailing list