[PATCH] D77115: [WebAssembly] Emit .llvmcmd and .llvmbc as custom sections
Sam Clegg via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 30 22:22:39 PDT 2020
sbc100 created this revision.
Herald added subscribers: cfe-commits, jfb, sunfish, aheejin, hiraditya, jgravelle-google, dschuff.
Herald added a project: clang.
sbc100 added reviewers: alexcrichton, sunfish.
Fixes: https://bugs.llvm.org/show_bug.cgi?id=45362
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D77115
Files:
clang/test/Driver/embed-bitcode-wasm.c
clang/test/Driver/fembed-bitcode.c
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/MC/WasmObjectWriter.cpp
Index: llvm/lib/MC/WasmObjectWriter.cpp
===================================================================
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -436,10 +436,6 @@
uint64_t FixupOffset = Layout.getFragmentOffset(Fragment) + Fixup.getOffset();
MCContext &Ctx = Asm.getContext();
- // The .init_array isn't translated as data, so don't do relocations in it.
- if (FixupSection.getSectionName().startswith(".init_array"))
- return;
-
if (const MCSymbolRefExpr *RefB = Target.getSymB()) {
// To get here the A - B expression must have failed evaluateAsRelocatable.
// This means either A or B must be undefined and in WebAssembly we can't
@@ -502,6 +498,10 @@
SymA->setUsedInReloc();
}
+ // The .init_array isn't translated as data, so don't do relocations in it.
+ if (FixupSection.getSectionName().startswith(".init_array"))
+ return;
+
if (RefA->getKind() == MCSymbolRefExpr::VK_GOT)
SymA->setUsedInGOT();
@@ -1090,10 +1090,7 @@
if (Sym.isComdat() && !Sym.isDefined())
return false;
- if (Sym.isTemporary() && Sym.getName().empty())
- return false;
-
- if (Sym.isTemporary() && Sym.isData() && !Sym.getSize())
+ if (Sym.isTemporary())
return false;
if (Sym.isSection())
@@ -1565,7 +1562,7 @@
report_fatal_error("fixups in .init_array should be symbol references");
const auto &TargetSym = cast<const MCSymbolWasm>(SymRef->getSymbol());
if (TargetSym.getIndex() == InvalidIndex)
- report_fatal_error("symbols in .init_array should exist in symbtab");
+ report_fatal_error("symbols in .init_array should exist in symtab");
if (!TargetSym.isFunction())
report_fatal_error("symbols in .init_array should be for functions");
InitFuncs.push_back(
Index: llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
===================================================================
--- llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
+++ llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
@@ -1765,6 +1765,14 @@
StringRef Name = GO->getSection();
+ // Certain data sections we treat as custom named section rather than
+ // segments within the data section.
+ // This could be avoided if all data segements in (the wasm sense) were
+ // represented as thier on sections (in the llvm sense).
+ // TODO(sbc): https://github.com/WebAssembly/tool-conventions/issues/138
+ if (Name == ".llvmcmd" || Name == ".llvmbc")
+ Kind = SectionKind::getMetadata();
+
StringRef Group = "";
if (const Comdat *C = getWasmComdat(GO)) {
Group = C->getName();
Index: clang/test/Driver/fembed-bitcode.c
===================================================================
--- clang/test/Driver/fembed-bitcode.c
+++ clang/test/Driver/fembed-bitcode.c
@@ -30,3 +30,12 @@
// RUN: | FileCheck --check-prefix=CHECK-HEXAGON %s
// CHECK-HEXAGON: "-target-feature"
// CHECK-HEXAGON: "+reserved-r19"
+//
+// RUN: %clang -target wasm32-unknown-unknown -fembed-bitcode=all -pthread -c %s -o /dev/null -### 2>&1 \
+// RUN: | FileCheck --check-prefix=CHECK-WASM %s
+
+// CHECK-WASM: "-cc1"
+// CHECK-WASM: "-target-feature" "+atomics"
+
+// CHECK-WASM: "-cc1"
+// CHECK-WASM: "-target-feature" "+atomics"
Index: clang/test/Driver/embed-bitcode-wasm.c
===================================================================
--- /dev/null
+++ clang/test/Driver/embed-bitcode-wasm.c
@@ -0,0 +1,6 @@
+// REQUIRES: webassembly-registered-target
+
+// RUN: %clang -c -target wasm32-unknown-unknown %s -fembed-bitcode -o %t.o
+// RUN: llvm-readobj -S %t.o | FileCheck --check-prefix=CHECK %s
+// CHECK: Name: .llvmbc
+// CHECK: Name: .llvmcmd
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D77115.253780.patch
Type: text/x-patch
Size: 3698 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200331/447e46ab/attachment-0001.bin>
More information about the cfe-commits
mailing list