[PATCH] D57538: [WebAssembly] Fix type of function aliases
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 31 12:44:19 PST 2019
sbc100 updated this revision to Diff 184579.
sbc100 added a comment.
add comment
Repository:
rL LLVM
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D57538/new/
https://reviews.llvm.org/D57538
Files:
lib/MC/WasmObjectWriter.cpp
test/MC/WebAssembly/function-alias.ll
Index: test/MC/WebAssembly/function-alias.ll
===================================================================
--- /dev/null
+++ test/MC/WebAssembly/function-alias.ll
@@ -0,0 +1,29 @@
+; RUN: llc -filetype=obj %s -o - | llvm-readobj -symbols | FileCheck %s
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown-wasm"
+
+ at foo = alias i8, bitcast (void ()* @func to i8*)
+ at bar = alias void (), void ()* @func
+
+define void @func() {
+ ret void
+}
+
+; CHECK: Symbols [
+; CHECK-NEXT: Symbol {
+; CHECK-NEXT: Name: func
+; CHECK-NEXT: Type: FUNCTION (0x0)
+; CHECK-NEXT: Flags: 0x0
+; CHECK-NEXT: }
+; CHECK-NEXT: Symbol {
+; CHECK-NEXT: Name: foo
+; CHECK-NEXT: Type: FUNCTION (0x0)
+; CHECK-NEXT: Flags: 0x0
+; CHECK-NEXT: }
+; CHECK-NEXT: Symbol {
+; CHECK-NEXT: Name: bar
+; CHECK-NEXT: Type: FUNCTION (0x0)
+; CHECK-NEXT: Flags: 0x0
+; CHECK-NEXT: }
+; CHECK-NEXT: ]
Index: lib/MC/WasmObjectWriter.cpp
===================================================================
--- lib/MC/WasmObjectWriter.cpp
+++ lib/MC/WasmObjectWriter.cpp
@@ -1420,7 +1420,7 @@
LLVM_DEBUG(dbgs() << WS.getName() << ": weak alias of '" << *ResolvedSym
<< "'\n");
- if (WS.isFunction()) {
+ if (ResolvedSym->isFunction()) {
assert(WasmIndices.count(ResolvedSym) > 0);
uint32_t WasmIndex = WasmIndices.find(ResolvedSym)->second;
WasmIndices[&WS] = WasmIndex;
@@ -1456,10 +1456,19 @@
Flags |= wasm::WASM_SYMBOL_UNDEFINED;
wasm::WasmSymbolInfo Info;
+ bool isData = WS.isData();
+ if (WS.isVariable()) {
+ // For data symbols that are aliases of function symbols we override
+ // the type here so that the alias has the correct function type.
+ const MCSymbolWasm *ResolvedSym = ResolveSymbol(WS);
+ Info.Kind = ResolvedSym->getType();
+ isData = ResolvedSym->isData();
+ } else {
+ Info.Kind = WS.getType();
+ }
Info.Name = WS.getName();
- Info.Kind = WS.getType();
Info.Flags = Flags;
- if (!WS.isData()) {
+ if (!isData) {
assert(WasmIndices.count(&WS) > 0);
Info.ElementIndex = WasmIndices.find(&WS)->second;
} else if (WS.isDefined()) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57538.184579.patch
Type: text/x-patch
Size: 2270 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190131/05151c88/attachment.bin>
More information about the llvm-commits
mailing list