diff --git a/lld/test/wasm/compress-relocs.ll b/lld/test/wasm/compress-relocs.ll --- a/lld/test/wasm/compress-relocs.ll +++ b/lld/test/wasm/compress-relocs.ll @@ -1,5 +1,5 @@ ; RUN: llc -filetype=obj %s -o %t.o -; RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/call-indirect.s -o %t2.o +; RUN: llvm-mc -mattr=+reference-types -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/call-indirect.s -o %t2.o ; RUN: wasm-ld --export-dynamic -o %t.wasm %t2.o %t.o ; RUN: obj2yaml %t.wasm | FileCheck %s ; RUN: wasm-ld --export-dynamic -O2 -o %t-opt.wasm %t2.o %t.o @@ -22,5 +22,5 @@ ; ERROR: wasm-ld: error: --compress-relocations is incompatible with output debug information. Please pass --strip-debug or --strip-all -; CHECK: Body: 410028028088808000118080808000001A410028028488808000118180808000001A0B +; CHECK: Body: 41002802808880800011808080800080808080001A41002802848880800011818080800080808080001A0B ; COMPRESS: Body: 4100280280081100001A4100280284081101001A0B diff --git a/llvm/lib/MC/WasmObjectWriter.cpp b/llvm/lib/MC/WasmObjectWriter.cpp --- a/llvm/lib/MC/WasmObjectWriter.cpp +++ b/llvm/lib/MC/WasmObjectWriter.cpp @@ -409,8 +409,11 @@ // referencing the indirect function table via TABLE_NUMBER relocs, ensure // that the indirect function table import makes it to the output if anything // in the compilation unit has caused it to be present. - if (auto *Sym = Asm.getContext().lookupSymbol("__indirect_function_table")) - Asm.registerSymbol(*Sym); + if (auto *Sym = Asm.getContext().lookupSymbol("__indirect_function_table")) { + auto *WasmSym = static_cast(Sym); + if (WasmSym->isNoStrip()) + Asm.registerSymbol(*Sym); + } // Build a map of sections to the function that defines them, for use // in recordRelocation. @@ -504,6 +507,10 @@ Type == wasm::R_WASM_TABLE_INDEX_SLEB64 || Type == wasm::R_WASM_TABLE_INDEX_I32 || Type == wasm::R_WASM_TABLE_INDEX_I64) { + auto *Frag = cast(Fragment); + auto *STI = Frag->getSubtargetInfo(); + // FIXME: STI is sometimes NULL here!!!! + bool HasReferenceTypes = STI && STI->checkFeatures("+reference-types"); // TABLE_INDEX relocs implicitly use the default indirect function table. auto TableName = "__indirect_function_table"; MCSymbolWasm *Sym = cast_or_null(Ctx.lookupSymbol(TableName)); @@ -518,7 +525,10 @@ // The default function table is synthesized by the linker. Sym->setUndefined(); } - Sym->setUsedInReloc(); + // If the reference-types feature is enabled, ensure that the the table + // symbol has a symtab entry. + if (HasReferenceTypes) + Sym->setUsedInReloc(); // Any time we have a TABLE_INDEX relocation against a function symbol, we // need to ensure that table itself is part of the final output too. In the // future we may want to define a new kind of reloc against both the @@ -1217,6 +1227,12 @@ if (Sym.isSection()) return false; + // There can only be relocations against table symbols if the reference-types + // feature is available. Tables that aren't used in relocs shouldn't get + // symtab entries, to avoid confusing older wasm-ld. + if (Sym.isTable()) + return false; + return true; } diff --git a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp --- a/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp +++ b/llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp @@ -472,6 +472,31 @@ WebAssemblyOperand::IntOp{static_cast(BT)})); } + bool addFunctionTableOperand(OperandVector &Operands, StringRef TableName, + SMLoc StartLoc, SMLoc EndLoc) { + MCSymbolWasm *Sym = GetOrCreateFunctionTableSymbol(getContext(), TableName); + if (STI->checkFeatures("+reference-types")) { + auto *Val = MCSymbolRefExpr::create(Sym, getContext()); + Operands.push_back(std::make_unique( + WebAssemblyOperand::Symbol, StartLoc, EndLoc, + WebAssemblyOperand::SymOp{Val})); + Sym->setUsedInReloc(); + return false; + } else { + if (TableName != "__indirect_function_table") { + return error("missing feature: reference-types"); + } + // For the MVP there is at most one table whose number is 0, but we can't + // write a table symbol or issue relocations. Instead we just ensure the + // table is live and write a zero. + Sym->setNoStrip(); + Operands.push_back(std::make_unique( + WebAssemblyOperand::Integer, StartLoc, EndLoc, + WebAssemblyOperand::IntOp{0})); + return false; + } + } + bool ParseInstruction(ParseInstructionInfo & /*Info*/, StringRef Name, SMLoc NameLoc, OperandVector &Operands) override { // Note: Name does NOT point into the sourcecode, but to a local, so @@ -508,6 +533,7 @@ bool ExpectBlockType = false; bool ExpectFuncType = false; bool ExpectHeapType = false; + bool ExpectFunctionTable = false; if (Name == "block") { push(Block); ExpectBlockType = true; @@ -547,15 +573,7 @@ return true; } else if (Name == "call_indirect" || Name == "return_call_indirect") { ExpectFuncType = true; - // Ensure that the object file has a __indirect_function_table import, as - // we call_indirect against it. - auto &Ctx = getStreamer().getContext(); - MCSymbolWasm *Sym = - GetOrCreateFunctionTableSymbol(Ctx, "__indirect_function_table"); - // Until call_indirect emits TABLE_NUMBER relocs against this symbol, mark - // it as NO_STRIP so as to ensure that the indirect function table makes - // it to linked output. - Sym->setNoStrip(); + ExpectFunctionTable = true; } else if (Name == "ref.null") { ExpectHeapType = true; } @@ -571,7 +589,7 @@ return true; // Got signature as block type, don't need more ExpectBlockType = false; - auto &Ctx = getStreamer().getContext(); + auto &Ctx = getContext(); // The "true" here will cause this to be a nameless symbol. MCSymbol *Sym = Ctx.createTempSymbol("typeindex", true); auto *WasmSym = cast(Sym); @@ -583,6 +601,16 @@ Operands.push_back(std::make_unique( WebAssemblyOperand::Symbol, Loc.getLoc(), Loc.getEndLoc(), WebAssemblyOperand::SymOp{Expr})); + + // Allow additional operands after the signature, notably for + // call_indirect against a named table. + if (Lexer.isNot(AsmToken::EndOfStatement)) { + if (expect(AsmToken::Comma, ",")) + return true; + if (Lexer.is(AsmToken::EndOfStatement)) { + return error("Unexpected trailing comma"); + } + } } while (Lexer.isNot(AsmToken::EndOfStatement)) { @@ -608,8 +636,12 @@ WebAssemblyOperand::Integer, Id.getLoc(), Id.getEndLoc(), WebAssemblyOperand::IntOp{static_cast(HeapType)})); Parser.Lex(); + } else if (ExpectFunctionTable) { + if (addFunctionTableOperand(Operands, Id.getString(), Id.getLoc(), + Id.getEndLoc())) + return true; + Parser.Lex(); } else { - // Assume this identifier is a label. const MCExpr *Val; SMLoc End; if (Parser.parseExpression(Val, End)) @@ -674,6 +706,12 @@ // Support blocks with no operands as default to void. addBlockTypeOperand(Operands, NameLoc, WebAssembly::BlockType::Void); } + if (ExpectFunctionTable && Operands.size() == 2) { + // If call_indirect doesn't specify a target table, supply one. + if (addFunctionTableOperand(Operands, "__indirect_function_table", + NameLoc, SMLoc::getFromPointer(Name.end()))) + return true; + } Parser.Lex(); return false; } @@ -785,6 +823,7 @@ auto WasmSym = cast(Ctx.getOrCreateSymbol(SymName)); WasmSym->setType(wasm::WASM_SYMBOL_TYPE_TABLE); WasmSym->setTableType(Type.getValue()); + WasmSym->setUsedInReloc(); TOut.emitTableType(WasmSym); return expect(AsmToken::EndOfStatement, "EOL"); } diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyInstPrinter.cpp @@ -68,7 +68,7 @@ for (auto I = Start, E = MI->getNumOperands(); I < E; ++I) { if (MI->getOpcode() == WebAssembly::CALL_INDIRECT && I - Start == NumVariadicDefs) { - // Skip type and flags arguments when printing for tests + // Skip type and table arguments when printing for tests. ++I; continue; } diff --git a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h --- a/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h +++ b/llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h @@ -401,6 +401,16 @@ } } +inline bool isRetCallIndirect(unsigned Opc) { + switch (Opc) { + case WebAssembly::RET_CALL_INDIRECT: + case WebAssembly::RET_CALL_INDIRECT_S: + return true; + default: + return false; + } +} + inline bool isBrTable(const MachineInstr &MI) { switch (MI.getOpcode()) { case WebAssembly::BR_TABLE_I32: diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp @@ -869,18 +869,20 @@ if (IsDirect) { MIB.addGlobalAddress(Func); } else { - // Add placeholders for the type index and immediate flags + // Placehoder for the type index. MIB.addImm(0); - MIB.addImm(0); - - // Ensure that the object file has a __indirect_function_table import, as we - // call_indirect against it. - MCSymbolWasm *Sym = WebAssembly::getOrCreateFunctionTableSymbol( + // The table into which this call_indirect indexes. + MCSymbolWasm *Table = WebAssembly::getOrCreateFunctionTableSymbol( MF->getMMI().getContext(), "__indirect_function_table"); - // Until call_indirect emits TABLE_NUMBER relocs against this symbol, mark - // it as NO_STRIP so as to ensure that the indirect function table makes it - // to linked output. - Sym->setNoStrip(); + if (Subtarget->hasReferenceTypes()) { + MIB.addSym(Table); + } else { + // Otherwise for the MVP there is at most one table whose number is 0, but + // we can't write a table symbol or issue relocations. Instead we just + // ensure the table is live. + Table->setNoStrip(); + MIB.addImm(0); + } } for (unsigned ArgReg : Args) diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp @@ -426,9 +426,10 @@ return DoneMBB; } -static MachineBasicBlock *LowerCallResults(MachineInstr &CallResults, - DebugLoc DL, MachineBasicBlock *BB, - const TargetInstrInfo &TII) { +static MachineBasicBlock * +LowerCallResults(MachineInstr &CallResults, DebugLoc DL, MachineBasicBlock *BB, + const WebAssemblySubtarget *Subtarget, + const TargetInstrInfo &TII) { MachineInstr &CallParams = *CallResults.getPrevNode(); assert(CallParams.getOpcode() == WebAssembly::CALL_PARAMS); assert(CallResults.getOpcode() == WebAssembly::CALL_RESULTS || @@ -475,19 +476,21 @@ for (auto Def : CallResults.defs()) MIB.add(Def); - // Add placeholders for the type index and immediate flags if (IsIndirect) { + // Placehoder for the type index. MIB.addImm(0); - MIB.addImm(0); - - // Ensure that the object file has a __indirect_function_table import, as we - // call_indirect against it. - MCSymbolWasm *Sym = WebAssembly::getOrCreateFunctionTableSymbol( + // The table into which this call_indirect indexes. + MCSymbolWasm *Table = WebAssembly::getOrCreateFunctionTableSymbol( MF.getContext(), "__indirect_function_table"); - // Until call_indirect emits TABLE_NUMBER relocs against this symbol, mark - // it as NO_STRIP so as to ensure that the indirect function table makes it - // to linked output. - Sym->setNoStrip(); + if (Subtarget->hasReferenceTypes()) { + MIB.addSym(Table); + } else { + // For the MVP there is at most one table whose number is 0, but we can't + // write a table symbol or issue relocations. Instead we just ensure the + // table is live and write a zero. + Table->setNoStrip(); + MIB.addImm(0); + } } for (auto Use : CallParams.uses()) @@ -534,7 +537,7 @@ WebAssembly::I64_TRUNC_U_F64); case WebAssembly::CALL_RESULTS: case WebAssembly::RET_CALL_RESULTS: - return LowerCallResults(MI, DL, BB, TII); + return LowerCallResults(MI, DL, BB, Subtarget, TII); } } diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td b/llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td --- a/llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td +++ b/llvm/lib/Target/WebAssembly/WebAssemblyInstrCall.td @@ -48,6 +48,9 @@ I<(outs), (ins variable_ops), (outs), (ins), [], "return_call_results", "return_call_results", -1>; +// Note that instructions with variable_ops have custom printers in +// WebAssemblyInstPrinter.cpp. + let variadicOpsAreDefs = 1 in defm CALL : I<(outs), (ins function32_op:$callee, variable_ops), @@ -56,9 +59,12 @@ let variadicOpsAreDefs = 1 in defm CALL_INDIRECT : - I<(outs), (ins TypeIndex:$type, i32imm:$flags, variable_ops), - (outs), (ins TypeIndex:$type, i32imm:$flags), [], - "call_indirect", "call_indirect\t$type", 0x11>; + I<(outs), + (ins TypeIndex:$type, table32_op:$table, variable_ops), + (outs), + (ins TypeIndex:$type, table32_op:$table), + [], + "call_indirect", "call_indirect\t$type, $table", 0x11>; let isReturn = 1, isTerminator = 1, hasCtrlDep = 1, isBarrier = 1 in defm RET_CALL : @@ -69,9 +75,9 @@ let isReturn = 1 in defm RET_CALL_INDIRECT : - I<(outs), (ins TypeIndex:$type, i32imm:$flags, variable_ops), - (outs), (ins TypeIndex:$type, i32imm:$flags), [], - "return_call_indirect\t", "return_call_indirect\t$type", + I<(outs), (ins TypeIndex:$type, table32_op:$table, variable_ops), + (outs), (ins TypeIndex:$type, table32_op:$table), [], + "return_call_indirect\t", "return_call_indirect\t$type, $table", 0x13>, Requires<[HasTailCall]>; diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp --- a/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp +++ b/llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp @@ -161,6 +161,8 @@ report_fatal_error("Global indexes with offsets not supported"); if (WasmSym->isEvent()) report_fatal_error("Event indexes with offsets not supported"); + if (WasmSym->isTable()) + report_fatal_error("Table indexes with offsets not supported"); Expr = MCBinaryExpr::createAdd( Expr, MCConstantExpr::create(MO.getOffset(), Ctx), Ctx); @@ -259,7 +261,7 @@ // return_call_indirect instructions have the return type of the // caller - if (MI->getOpcode() == WebAssembly::RET_CALL_INDIRECT) + if (WebAssembly::isRetCallIndirect(MI->getOpcode())) getFunctionReturns(MI, Returns); MCOp = lowerTypeIndexOperand(std::move(Returns), std::move(Params)); diff --git a/llvm/test/CodeGen/WebAssembly/function-pointer64.ll b/llvm/test/CodeGen/WebAssembly/function-pointer64.ll --- a/llvm/test/CodeGen/WebAssembly/function-pointer64.ll +++ b/llvm/test/CodeGen/WebAssembly/function-pointer64.ll @@ -1,4 +1,5 @@ ; RUN: llc < %s -asm-verbose=false -O2 | FileCheck %s +; RUN: llc < %s -asm-verbose=false -mattr=+reference-types -O2 | FileCheck --check-prefix=REF %s ; RUN: llc < %s -asm-verbose=false -O2 --filetype=obj | obj2yaml | FileCheck --check-prefix=YAML %s ; This tests pointer features that may codegen differently in wasm64. @@ -34,14 +35,16 @@ ; CHECK-NEXT: i32.const 1 ; CHECK-NEXT: local.get 0 ; CHECK-NEXT: i32.wrap_i64 -; CHECK-NEXT: call_indirect (i32) -> () +; CHECK-NEXT: call_indirect (i32) -> (), 0 +; REF: call_indirect (i32) -> (), __indirect_function_table ; CHECK: .functype test () -> () ; CHECK-NEXT: i64.const bar ; CHECK-NEXT: call foo -; Check we're emitting a 64-bit reloc for `i64.const bar` and the global. +; Check we're emitting a 64-bit relocs for the call_indirect, the +; `i64.const bar` reference in code, and the global. ; YAML: Memory: ; YAML-NEXT: Flags: [ IS_64 ] @@ -51,6 +54,9 @@ ; YAML: - Type: R_WASM_TABLE_INDEX_SLEB64 ; YAML-NEXT: Index: 0 ; YAML-NEXT: Offset: 0x16 +; YAML: - Type: R_WASM_TABLE_INDEX_SLEB64 +; YAML-NEXT: Index: 0 +; YAML-NEXT: Offset: 0x29 ; YAML: - Type: DATA ; YAML: - Type: R_WASM_TABLE_INDEX_I64 diff --git a/llvm/test/CodeGen/WebAssembly/multivalue.ll b/llvm/test/CodeGen/WebAssembly/multivalue.ll --- a/llvm/test/CodeGen/WebAssembly/multivalue.ll +++ b/llvm/test/CodeGen/WebAssembly/multivalue.ll @@ -1,4 +1,5 @@ ; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -mattr=+multivalue,+tail-call | FileCheck %s +; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -mattr=+reference-types,+multivalue,+tail-call | FileCheck --check-prefix REF %s ; RUN: llc < %s -asm-verbose=false -verify-machineinstrs -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+multivalue,+tail-call | FileCheck %s --check-prefix REGS ; RUN: llc < %s --filetype=obj -mattr=+multivalue,+tail-call | obj2yaml | FileCheck %s --check-prefix OBJ @@ -57,7 +58,8 @@ ; CHECK-LABEL: pair_call_indirect: ; CHECK-NEXT: .functype pair_call_indirect (i32) -> (i32, i64) ; CHECK-NEXT: local.get 0{{$}} -; CHECK-NEXT: call_indirect () -> (i32, i64){{$}} +; CHECK-NEXT: call_indirect () -> (i32, i64), 0{{$}} +; REF: call_indirect () -> (i32, i64), __indirect_function_table{{$}} ; CHECK-NEXT: end_function{{$}} ; REGS: call_indirect $push{{[0-9]+}}=, $push{{[0-9]+}}=, $0{{$}} define %pair @pair_call_indirect(%pair()* %f) { diff --git a/llvm/test/MC/WebAssembly/basic-assembly.s b/llvm/test/MC/WebAssembly/basic-assembly.s --- a/llvm/test/MC/WebAssembly/basic-assembly.s +++ b/llvm/test/MC/WebAssembly/basic-assembly.s @@ -1,4 +1,4 @@ -# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+atomics,+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | FileCheck %s +# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+reference-types,atomics,+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | FileCheck %s # Check that it converts to .o without errors, but don't check any output: # RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -mattr=+atomics,+unimplemented-simd128,+nontrapping-fptoint,+exception-handling -o %t.o < %s @@ -153,7 +153,7 @@ # CHECK-NEXT: i64.const 1234 # CHECK-NEXT: call something2 # CHECK-NEXT: i32.const 0 -# CHECK-NEXT: call_indirect (i32, f64) -> () +# CHECK-NEXT: call_indirect (i32, f64) -> (), __indirect_function_table # CHECK-NEXT: i32.const 1 # CHECK-NEXT: i32.add # CHECK-NEXT: local.tee 0 diff --git a/llvm/test/MC/WebAssembly/call-indirect-relocs.s b/llvm/test/MC/WebAssembly/call-indirect-relocs.s new file mode 100644 --- /dev/null +++ b/llvm/test/MC/WebAssembly/call-indirect-relocs.s @@ -0,0 +1,83 @@ +# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+reference-types < %s | FileCheck --check-prefix=CHECK %s +# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+reference-types -filetype=obj < %s | obj2yaml | FileCheck -check-prefix=BIN %s + +test0: + .functype test0 () -> () + i32.const 42 + f64.const 2.5 + i32.const 0 + call_indirect (i32, f64) -> (), empty_fref_table + end_function + +.tabletype empty_fref_table, funcref +empty_fref_table: + + +# CHECK: .text +# CHECK-LABEL: test0: +# CHECK-NEXT: .functype test0 () -> () +# CHECK-NEXT: i32.const 42 +# CHECK-NEXT: f64.const 0x1.4p1 +# CHECK-NEXT: i32.const 0 +# CHECK-NEXT: call_indirect (i32, f64) -> (), empty_fref_table +# CHECK-NEXT: end_function + +# CHECK: .tabletype empty_fref_table, funcref +# CHECK: empty_fref_table: + +# BIN: --- !WASM +# BIN-NEXT: FileHeader: +# BIN-NEXT: Version: 0x1 +# BIN-NEXT: Sections: +# BIN-NEXT: - Type: TYPE +# BIN-NEXT: Signatures: +# BIN-NEXT: - Index: 0 +# BIN-NEXT: ParamTypes: [] +# BIN-NEXT: ReturnTypes: [] +# BIN-NEXT: - Index: 1 +# BIN-NEXT: ParamTypes: +# BIN-NEXT: - I32 +# BIN-NEXT: - F64 +# BIN-NEXT: ReturnTypes: [] +# BIN-NEXT: - Type: IMPORT +# BIN-NEXT: Imports: +# BIN-NEXT: - Module: env +# BIN-NEXT: Field: __linear_memory +# BIN-NEXT: Kind: MEMORY +# BIN-NEXT: Memory: +# BIN-NEXT: Initial: 0x0 +# BIN-NEXT: - Type: FUNCTION +# BIN-NEXT: FunctionTypes: [ 0 ] +# BIN-NEXT: - Type: TABLE +# BIN-NEXT: Tables: +# BIN-NEXT: - Index: 0 +# BIN-NEXT: ElemType: FUNCREF +# BIN-NEXT: Limits: +# BIN-NEXT: Initial: 0x0 +# BIN-NEXT: - Type: CODE +# BIN-NEXT: Relocations: +# BIN-NEXT: - Type: R_WASM_TYPE_INDEX_LEB +# BIN-NEXT: Index: 1 +# BIN-NEXT: Offset: 0x11 +# BIN-NEXT: - Type: R_WASM_TABLE_NUMBER_LEB +# BIN-NEXT: Index: 1 +# BIN-NEXT: Offset: 0x16 +# BIN-NEXT: Functions: +# BIN-NEXT: - Index: 0 +# BIN-NEXT: Locals: [] +# BIN-NEXT: Body: 412A440000000000000440410011818080800080808080000B +# BIN-NEXT: - Type: CUSTOM +# BIN-NEXT: Name: linking +# BIN-NEXT: Version: 2 +# BIN-NEXT: SymbolTable: +# BIN-NEXT: - Index: 0 +# BIN-NEXT: Kind: FUNCTION +# BIN-NEXT: Name: test0 +# BIN-NEXT: Flags: [ BINDING_LOCAL ] +# BIN-NEXT: Function: 0 +# BIN-NEXT: - Index: 1 +# BIN-NEXT: Kind: TABLE +# BIN-NEXT: Name: empty_fref_table +# BIN-NEXT: Flags: [ BINDING_LOCAL ] +# BIN-NEXT: Table: 0 +# BIN-NEXT: ... diff --git a/llvm/test/MC/WebAssembly/debug-info.ll b/llvm/test/MC/WebAssembly/debug-info.ll --- a/llvm/test/MC/WebAssembly/debug-info.ll +++ b/llvm/test/MC/WebAssembly/debug-info.ll @@ -89,44 +89,44 @@ ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) -; CHECK-NEXT: Size: 95 +; CHECK-NEXT: Size: 91 ; CHECK-NEXT: Offset: 731 ; CHECK-NEXT: Name: linking ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 9 -; CHECK-NEXT: Offset: 840 +; CHECK-NEXT: Offset: 836 ; CHECK-NEXT: Name: reloc.DATA ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 61 -; CHECK-NEXT: Offset: 866 +; CHECK-NEXT: Offset: 862 ; CHECK-NEXT: Name: reloc..debug_info ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 6 -; CHECK-NEXT: Offset: 951 +; CHECK-NEXT: Offset: 947 ; CHECK-NEXT: Name: reloc..debug_pubnames ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 6 -; CHECK-NEXT: Offset: 985 +; CHECK-NEXT: Offset: 981 ; CHECK-NEXT: Name: reloc..debug_pubtypes ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 6 -; CHECK-NEXT: Offset: 1019 +; CHECK-NEXT: Offset: 1015 ; CHECK-NEXT: Name: reloc..debug_line ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 77 -; CHECK-NEXT: Offset: 1049 +; CHECK-NEXT: Offset: 1045 ; CHECK-NEXT: Name: producers ; CHECK-NEXT: } ; CHECK-NEXT:] @@ -238,16 +238,6 @@ ; CHECK-NEXT: ] ; CHECK-NEXT: ElementIndex: 0xC ; CHECK-NEXT: } -; CHECK-NEXT: Symbol { -; CHECK-NEXT: Name: __indirect_function_table -; CHECK-NEXT: Type: TABLE (0x5) -; CHECK-NEXT: Flags [ (0x90) -; CHECK-NEXT: NO_STRIP (0x80) -; CHECK-NEXT: UNDEFINED (0x10) -; CHECK-NEXT: ] -; CHECK-NEXT: ImportModule: env -; CHECK-NEXT: ElementIndex: 0x0 -; CHECK-NEXT: } ; CHECK-NEXT:] ; generated from the following C code using: clang --target=wasm32 -g -O0 -S -emit-llvm test.c diff --git a/llvm/test/MC/WebAssembly/debug-info64.ll b/llvm/test/MC/WebAssembly/debug-info64.ll --- a/llvm/test/MC/WebAssembly/debug-info64.ll +++ b/llvm/test/MC/WebAssembly/debug-info64.ll @@ -89,44 +89,44 @@ ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) -; CHECK-NEXT: Size: 95 +; CHECK-NEXT: Size: 91 ; CHECK-NEXT: Offset: 759 ; CHECK-NEXT: Name: linking ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 9 -; CHECK-NEXT: Offset: 868 +; CHECK-NEXT: Offset: 864 ; CHECK-NEXT: Name: reloc.DATA ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 61 -; CHECK-NEXT: Offset: 894 +; CHECK-NEXT: Offset: 890 ; CHECK-NEXT: Name: reloc..debug_info ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 6 -; CHECK-NEXT: Offset: 979 +; CHECK-NEXT: Offset: 975 ; CHECK-NEXT: Name: reloc..debug_pubnames ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 6 -; CHECK-NEXT: Offset: 1013 +; CHECK-NEXT: Offset: 1009 ; CHECK-NEXT: Name: reloc..debug_pubtypes ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 6 -; CHECK-NEXT: Offset: 1047 +; CHECK-NEXT: Offset: 1043 ; CHECK-NEXT: Name: reloc..debug_line ; CHECK-NEXT: } ; CHECK-NEXT: Section { ; CHECK-NEXT: Type: CUSTOM (0x0) ; CHECK-NEXT: Size: 77 -; CHECK-NEXT: Offset: 1077 +; CHECK-NEXT: Offset: 1073 ; CHECK-NEXT: Name: producers ; CHECK-NEXT: } ; CHECK-NEXT: ] @@ -238,16 +238,6 @@ ; CHECK-NEXT: ] ; CHECK-NEXT: ElementIndex: 0xC ; CHECK-NEXT: } -; CHECK-NEXT: Symbol { -; CHECK-NEXT: Name: __indirect_function_table -; CHECK-NEXT: Type: TABLE (0x5) -; CHECK-NEXT: Flags [ (0x90) -; CHECK-NEXT: NO_STRIP (0x80) -; CHECK-NEXT: UNDEFINED (0x10) -; CHECK-NEXT: ] -; CHECK-NEXT: ImportModule: env -; CHECK-NEXT: ElementIndex: 0x0 -; CHECK-NEXT: } ; CHECK-NEXT: ] ; generated from the following C code using: clang --target=wasm64 -g -O0 -S -emit-llvm test.c diff --git a/llvm/test/MC/WebAssembly/function-alias.ll b/llvm/test/MC/WebAssembly/function-alias.ll --- a/llvm/test/MC/WebAssembly/function-alias.ll +++ b/llvm/test/MC/WebAssembly/function-alias.ll @@ -1,4 +1,5 @@ ; RUN: llc -filetype=obj %s -o - | llvm-readobj --symbols - | FileCheck %s +; RUN: llc -filetype=obj %s -mattr=+reference-types -o - | llvm-readobj --symbols - | FileCheck --check-prefix=REF %s target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" target triple = "wasm32-unknown-unknown-wasm" @@ -41,14 +42,45 @@ ; CHECK-NEXT: ] ; CHECK-NEXT: ElementIndex: 0x0 ; CHECK-NEXT: } -; CHECK-NEXT: Symbol { -; CHECK-NEXT: Name: __indirect_function_table -; CHECK-NEXT: Type: TABLE (0x5) -; CHECK-NEXT: Flags [ (0x90) -; CHECK-NEXT: NO_STRIP (0x80) -; CHECK-NEXT: UNDEFINED (0x10) -; CHECK-NEXT: ] -; CHECK-NEXT: ImportModule: env -; CHECK-NEXT: ElementIndex: 0x0 -; CHECK-NEXT: } ; CHECK-NEXT: ] + +; REF: Symbols [ +; REF-NEXT: Symbol { +; REF-NEXT: Name: func +; REF-NEXT: Type: FUNCTION (0x0) +; REF-NEXT: Flags [ (0x0) +; REF-NEXT: ] +; REF-NEXT: ElementIndex: 0x0 +; REF-NEXT: } +; REF-NEXT: Symbol { +; REF-NEXT: Name: bar2 +; REF-NEXT: Type: FUNCTION (0x0) +; REF-NEXT: Flags [ (0x0) +; REF-NEXT: ] +; REF-NEXT: ElementIndex: 0x0 +; REF-NEXT: } +; REF-NEXT: Symbol { +; REF-NEXT: Name: foo +; REF-NEXT: Type: FUNCTION (0x0) +; REF-NEXT: Flags [ (0x0) +; REF-NEXT: ] +; REF-NEXT: ElementIndex: 0x0 +; REF-NEXT: } +; REF-NEXT: Symbol { +; REF-NEXT: Name: bar +; REF-NEXT: Type: FUNCTION (0x0) +; REF-NEXT: Flags [ (0x0) +; REF-NEXT: ] +; REF-NEXT: ElementIndex: 0x0 +; REF-NEXT: } +; REF-NEXT: Symbol { +; REF-NEXT: Name: __indirect_function_table +; REF-NEXT: Type: TABLE (0x5) +; REF-NEXT: Flags [ (0x90) +; REF-NEXT: NO_STRIP (0x80) +; REF-NEXT: UNDEFINED (0x10) +; REF-NEXT: ] +; REF-NEXT: ImportModule: env +; REF-NEXT: ElementIndex: 0x0 +; REF-NEXT: } +; REF-NEXT: ] diff --git a/llvm/test/MC/WebAssembly/global-ctor-dtor.ll b/llvm/test/MC/WebAssembly/global-ctor-dtor.ll --- a/llvm/test/MC/WebAssembly/global-ctor-dtor.ll +++ b/llvm/test/MC/WebAssembly/global-ctor-dtor.ll @@ -170,11 +170,6 @@ ; CHECK-NEXT: Name: func0 ; CHECK-NEXT: Flags: [ UNDEFINED ] ; CHECK-NEXT: Function: 4 -; CHECK-NEXT: - Index: 11 -; CHECK-NEXT: Kind: TABLE -; CHECK-NEXT: Name: __indirect_function_table -; CHECK-NEXT: Flags: [ UNDEFINED, NO_STRIP ] -; CHECK-NEXT: Table: 0 ; CHECK-NEXT: SegmentInfo: ; CHECK-NEXT: - Index: 0 ; CHECK-NEXT: Name: .data.global1 diff --git a/llvm/test/MC/WebAssembly/reloc-code.ll b/llvm/test/MC/WebAssembly/reloc-code.ll --- a/llvm/test/MC/WebAssembly/reloc-code.ll +++ b/llvm/test/MC/WebAssembly/reloc-code.ll @@ -1,4 +1,5 @@ ; RUN: llc -filetype=obj %s -o - | llvm-readobj -r --expand-relocs - | FileCheck %s +; RUN: llc -filetype=obj -mattr=+reference-types %s -o - | llvm-readobj -r --expand-relocs - | FileCheck --check-prefix=REF %s target triple = "wasm32-unknown-unknown" @@ -59,3 +60,51 @@ ; CHECK-NEXT: } ; CHECK-NEXT: } ; CHECK-NEXT: ] + +; REF: Format: WASM +; REF: Relocations [ +; REF-NEXT: Section (5) CODE { +; REF-NEXT: Relocation { +; REF-NEXT: Type: R_WASM_MEMORY_ADDR_LEB (3) +; REF-NEXT: Offset: 0x9 +; REF-NEXT: Symbol: b +; REF-NEXT: Addend: 0 +; REF-NEXT: } +; REF-NEXT: Relocation { +; REF-NEXT: Type: R_WASM_MEMORY_ADDR_LEB (3) +; REF-NEXT: Offset: 0x14 +; REF-NEXT: Symbol: a +; REF-NEXT: Addend: 0 +; REF-NEXT: } +; REF-NEXT: Relocation { +; REF-NEXT: Type: R_WASM_TYPE_INDEX_LEB (6) +; REF-NEXT: Offset: 0x1A +; REF-NEXT: Index: 0x1 +; REF-NEXT: } +; REF-NEXT: Relocation { +; REF-NEXT: Type: R_WASM_TABLE_NUMBER_LEB (20) +; REF-NEXT: Offset: 0x1F +; REF-NEXT: Symbol: __indirect_function_table +; REF-NEXT: } +; REF-NEXT: Relocation { +; REF-NEXT: Type: R_WASM_TYPE_INDEX_LEB (6) +; REF-NEXT: Offset: 0x28 +; REF-NEXT: Index: 0x0 +; REF-NEXT: } +; REF-NEXT: Relocation { +; REF-NEXT: Type: R_WASM_TABLE_NUMBER_LEB (20) +; REF-NEXT: Offset: 0x2D +; REF-NEXT: Symbol: __indirect_function_table +; REF-NEXT: } +; REF-NEXT: Relocation { +; REF-NEXT: Type: R_WASM_FUNCTION_INDEX_LEB (0) +; REF-NEXT: Offset: 0x35 +; REF-NEXT: Symbol: c +; REF-NEXT: } +; REF-NEXT: Relocation { +; REF-NEXT: Type: R_WASM_FUNCTION_INDEX_LEB (0) +; REF-NEXT: Offset: 0x3C +; REF-NEXT: Symbol: d +; REF-NEXT: } +; REF-NEXT: } +; REF-NEXT: ] diff --git a/llvm/test/MC/WebAssembly/reloc-pic.s b/llvm/test/MC/WebAssembly/reloc-pic.s --- a/llvm/test/MC/WebAssembly/reloc-pic.s +++ b/llvm/test/MC/WebAssembly/reloc-pic.s @@ -1,4 +1,5 @@ # RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj < %s | obj2yaml | FileCheck %s +# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+reference-types -filetype=obj < %s | obj2yaml | FileCheck --check-prefix=REF %s # Verify that @GOT relocation entryes result in R_WASM_GLOBAL_INDEX_LEB against # against the corrsponding function or data symbol and that the corresponding @@ -190,11 +191,11 @@ # CHECK-NEXT: Name: hidden_func # CHECK-NEXT: Flags: [ BINDING_LOCAL ] # CHECK-NEXT: Function: 5 -# CHECK-NEXT: - Index: 10 -# CHECK-NEXT: Kind: TABLE -# CHECK-NEXT: Name: __indirect_function_table -# CHECK-NEXT: Flags: [ UNDEFINED, NO_STRIP ] -# CHECK-NEXT: Table: 0 +# REF: - Index: 10 +# REF-NEXT: Kind: TABLE +# REF-NEXT: Name: __indirect_function_table +# REF-NEXT: Flags: [ UNDEFINED, NO_STRIP ] +# REF-NEXT: Table: 0 # CHECK-NEXT: SegmentInfo: # CHECK-NEXT: - Index: 0 # CHECK-NEXT: Name: .rodata.hidden_data diff --git a/llvm/test/MC/WebAssembly/tail-call-encodings.s b/llvm/test/MC/WebAssembly/tail-call-encodings.s --- a/llvm/test/MC/WebAssembly/tail-call-encodings.s +++ b/llvm/test/MC/WebAssembly/tail-call-encodings.s @@ -1,4 +1,5 @@ # RUN: llvm-mc -show-encoding -triple=wasm32-unknown-unknown -mattr=+tail-call < %s | FileCheck %s +# RUN: llvm-mc -show-encoding -triple=wasm32-unknown-unknown -mattr=+reference-types,+tail-call < %s | FileCheck --check-prefix=REF %s bar1: .functype bar1 () -> () @@ -16,7 +17,8 @@ foo2: .functype foo2 () -> () - # CHECK: return_call_indirect (i32) -> (i32) # encoding: [0x13, + # REF: return_call_indirect (i32) -> (i32), __indirect_function_table # encoding: [0x13, + # CHECK: return_call_indirect (i32) -> (i32), 0 # encoding: [0x13, # CHECK-NEXT: fixup A - offset: 1, value: .Ltypeindex0@TYPEINDEX, kind: fixup_uleb128_i32 return_call_indirect (i32) -> (i32) diff --git a/llvm/test/MC/WebAssembly/type-index.s b/llvm/test/MC/WebAssembly/type-index.s --- a/llvm/test/MC/WebAssembly/type-index.s +++ b/llvm/test/MC/WebAssembly/type-index.s @@ -1,8 +1,8 @@ -# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | FileCheck %s +# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+reference-types,+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | FileCheck %s # Check that it converts to .o without errors: -# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -mattr=+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | obj2yaml | FileCheck -check-prefix=BIN %s +# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -mattr=+reference-types,+unimplemented-simd128,+nontrapping-fptoint,+exception-handling < %s | obj2yaml | FileCheck -check-prefix=BIN %s -# Minimal test for type indices in call_indirect. +# Minimal test for type indices and table references in call_indirect. test0: .functype test0 (i32) -> (i32) @@ -53,10 +53,13 @@ # BIN-NEXT: - Type: R_WASM_TYPE_INDEX_LEB # BIN-NEXT: Index: 1 # BIN-NEXT: Offset: 0x4 +# BIN-NEXT: - Type: R_WASM_TABLE_NUMBER_LEB +# BIN-NEXT: Index: 1 +# BIN-NEXT: Offset: 0x9 # BIN-NEXT: Functions: # BIN-NEXT: - Index: 0 # BIN-NEXT: Locals: [] -# BIN-NEXT: Body: 118180808000000B +# BIN-NEXT: Body: 11818080800080808080000B # BIN-NEXT: - Type: CUSTOM # BIN-NEXT: Name: linking # BIN-NEXT: Version: 2 @@ -69,6 +72,6 @@ # BIN-NEXT: - Index: 1 # BIN-NEXT: Kind: TABLE # BIN-NEXT: Name: __indirect_function_table -# BIN-NEXT: Flags: [ UNDEFINED, NO_STRIP ] +# BIN-NEXT: Flags: [ UNDEFINED ] # BIN-NEXT: Table: 0 # BIN-NEXT: ... diff --git a/llvm/test/MC/WebAssembly/weak-alias.s b/llvm/test/MC/WebAssembly/weak-alias.s --- a/llvm/test/MC/WebAssembly/weak-alias.s +++ b/llvm/test/MC/WebAssembly/weak-alias.s @@ -1,5 +1,5 @@ -# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj -o %t.o < %s -# RUN: obj2yaml %t.o | FileCheck %s +# RUN: llvm-mc -triple=wasm32-unknown-unknown -filetype=obj < %s | obj2yaml | FileCheck --check-prefix=CHECK %s +# RUN: llvm-mc -triple=wasm32-unknown-unknown -mattr=+reference-types -filetype=obj < %s | obj2yaml | FileCheck --check-prefix=REF %s # 'foo_alias()' is weak alias of function 'foo()' # 'bar_alias' is weak alias of global variable 'bar' @@ -78,7 +78,7 @@ # CHECK: - Type: TYPE # CHECK-NEXT: Signatures: # CHECK-NEXT: - Index: 0 -# CHECK-NEXT: ParamTypes: +# CHECK-NEXT: ParamTypes: [] # CHECK-NEXT: ReturnTypes: # CHECK-NEXT: - I32 # CHECK-NEXT: - Type: IMPORT @@ -128,19 +128,19 @@ # CHECK-NEXT: Offset: 0x37 # CHECK-NEXT: Functions: # CHECK-NEXT: - Index: 0 -# CHECK-NEXT: Locals: +# CHECK-NEXT: Locals: [] # CHECK-NEXT: Body: 41000B # CHECK-NEXT: - Index: 1 -# CHECK-NEXT: Locals: +# CHECK-NEXT: Locals: [] # CHECK-NEXT: Body: 1080808080000B # CHECK-NEXT: - Index: 2 -# CHECK-NEXT: Locals: +# CHECK-NEXT: Locals: [] # CHECK-NEXT: Body: 1080808080000B # CHECK-NEXT: - Index: 3 -# CHECK-NEXT: Locals: +# CHECK-NEXT: Locals: [] # CHECK-NEXT: Body: 410028028880808000118080808000000B # CHECK-NEXT: - Index: 4 -# CHECK-NEXT: Locals: +# CHECK-NEXT: Locals: [] # CHECK-NEXT: Body: 410028029080808000118080808000000B # CHECK-NEXT: - Type: DATA # CHECK-NEXT: Relocations: @@ -227,26 +227,199 @@ # CHECK-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN, NO_STRIP ] # CHECK-NEXT: Segment: 0 # CHECK-NEXT: Size: 4 -# CHECK-NEXT: - Index: 10 -# CHECK-NEXT: Kind: TABLE -# CHECK-NEXT: Name: __indirect_function_table -# CHECK-NEXT: Flags: [ UNDEFINED, NO_STRIP ] -# CHECK-NEXT: Table: 0 # CHECK-NEXT: SegmentInfo: # CHECK-NEXT: - Index: 0 # CHECK-NEXT: Name: .data.bar # CHECK-NEXT: Alignment: 3 -# CHECK-NEXT: Flags: [ ] +# CHECK-NEXT: Flags: [ ] # CHECK-NEXT: - Index: 1 # CHECK-NEXT: Name: .data.direct_address # CHECK-NEXT: Alignment: 3 -# CHECK-NEXT: Flags: [ ] +# CHECK-NEXT: Flags: [ ] # CHECK-NEXT: - Index: 2 # CHECK-NEXT: Name: .data.alias_address # CHECK-NEXT: Alignment: 3 -# CHECK-NEXT: Flags: [ ] +# CHECK-NEXT: Flags: [ ] # CHECK-NEXT: ... +# REF: - Type: TYPE +# REF-NEXT: Signatures: +# REF-NEXT: - Index: 0 +# REF-NEXT: ParamTypes: [] +# REF-NEXT: ReturnTypes: +# REF-NEXT: - I32 +# REF-NEXT: - Type: IMPORT +# REF-NEXT: Imports: +# REF-NEXT: - Module: env +# REF-NEXT: Field: __linear_memory +# REF-NEXT: Kind: MEMORY +# REF-NEXT: Memory: +# REF-NEXT: Initial: 0x1 +# REF-NEXT: - Module: env +# REF-NEXT: Field: __indirect_function_table +# REF-NEXT: Kind: TABLE +# REF-NEXT: Table: +# REF-NEXT: Index: 0 +# REF-NEXT: ElemType: FUNCREF +# REF-NEXT: Limits: +# REF-NEXT: Initial: 0x1 +# REF-NEXT: - Type: FUNCTION +# REF-NEXT: FunctionTypes: [ 0, 0, 0, 0, 0 ] +# REF-NEXT: - Type: ELEM +# REF-NEXT: Segments: +# REF-NEXT: - Offset: +# REF-NEXT: Opcode: I32_CONST +# REF-NEXT: Value: 1 +# REF-NEXT: Functions: [ 0 ] +# REF-NEXT: - Type: DATACOUNT +# REF-NEXT: Count: 3 +# REF-NEXT: - Type: CODE +# REF-NEXT: Relocations: +# REF-NEXT: - Type: R_WASM_FUNCTION_INDEX_LEB +# REF-NEXT: Index: 0 +# REF-NEXT: Offset: 0x9 +# REF-NEXT: - Type: R_WASM_FUNCTION_INDEX_LEB +# REF-NEXT: Index: 3 +# REF-NEXT: Offset: 0x12 +# REF-NEXT: - Type: R_WASM_MEMORY_ADDR_LEB +# REF-NEXT: Index: 5 +# REF-NEXT: Offset: 0x1E +# REF-NEXT: - Type: R_WASM_TYPE_INDEX_LEB +# REF-NEXT: Index: 0 +# REF-NEXT: Offset: 0x24 +# REF-NEXT: - Type: R_WASM_TABLE_NUMBER_LEB +# REF-NEXT: Index: 6 +# REF-NEXT: Offset: 0x29 +# REF-NEXT: - Type: R_WASM_MEMORY_ADDR_LEB +# REF-NEXT: Index: 8 +# REF-NEXT: Offset: 0x35 +# REF-NEXT: - Type: R_WASM_TYPE_INDEX_LEB +# REF-NEXT: Index: 0 +# REF-NEXT: Offset: 0x3B +# REF-NEXT: - Type: R_WASM_TABLE_NUMBER_LEB +# REF-NEXT: Index: 6 +# REF-NEXT: Offset: 0x40 +# REF-NEXT: Functions: +# REF-NEXT: - Index: 0 +# REF-NEXT: Locals: [] +# REF-NEXT: Body: 41000B +# REF-NEXT: - Index: 1 +# REF-NEXT: Locals: [] +# REF-NEXT: Body: 1080808080000B +# REF-NEXT: - Index: 2 +# REF-NEXT: Locals: [] +# REF-NEXT: Body: 1080808080000B +# REF-NEXT: - Index: 3 +# REF-NEXT: Locals: [] +# REF-NEXT: Body: 41002802888080800011808080800080808080000B +# REF-NEXT: - Index: 4 +# REF-NEXT: Locals: [] +# REF-NEXT: Body: 41002802908080800011808080800080808080000B +# REF-NEXT: - Type: DATA +# REF-NEXT: Relocations: +# REF-NEXT: - Type: R_WASM_TABLE_INDEX_I32 +# REF-NEXT: Index: 0 +# REF-NEXT: Offset: 0x13 +# REF-NEXT: - Type: R_WASM_TABLE_INDEX_I32 +# REF-NEXT: Index: 3 +# REF-NEXT: Offset: 0x20 +# REF-NEXT: Segments: +# REF-NEXT: - SectionOffset: 6 +# REF-NEXT: InitFlags: 0 +# REF-NEXT: Offset: +# REF-NEXT: Opcode: I32_CONST +# REF-NEXT: Value: 0 +# REF-NEXT: Content: '0700000000000000' +# REF-NEXT: - SectionOffset: 19 +# REF-NEXT: InitFlags: 0 +# REF-NEXT: Offset: +# REF-NEXT: Opcode: I32_CONST +# REF-NEXT: Value: 8 +# REF-NEXT: Content: '0100000000000000' +# REF-NEXT: - SectionOffset: 32 +# REF-NEXT: InitFlags: 0 +# REF-NEXT: Offset: +# REF-NEXT: Opcode: I32_CONST +# REF-NEXT: Value: 16 +# REF-NEXT: Content: '0100000000000000' +# REF-NEXT: - Type: CUSTOM +# REF-NEXT: Name: linking +# REF-NEXT: Version: 2 +# REF-NEXT: SymbolTable: +# REF-NEXT: - Index: 0 +# REF-NEXT: Kind: FUNCTION +# REF-NEXT: Name: foo +# REF-NEXT: Flags: [ VISIBILITY_HIDDEN ] +# REF-NEXT: Function: 0 +# REF-NEXT: - Index: 1 +# REF-NEXT: Kind: FUNCTION +# REF-NEXT: Name: call_direct +# REF-NEXT: Flags: [ VISIBILITY_HIDDEN ] +# REF-NEXT: Function: 1 +# REF-NEXT: - Index: 2 +# REF-NEXT: Kind: FUNCTION +# REF-NEXT: Name: call_alias +# REF-NEXT: Flags: [ VISIBILITY_HIDDEN ] +# REF-NEXT: Function: 2 +# REF-NEXT: - Index: 3 +# REF-NEXT: Kind: FUNCTION +# REF-NEXT: Name: foo_alias +# REF-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN, NO_STRIP ] +# REF-NEXT: Function: 0 +# REF-NEXT: - Index: 4 +# REF-NEXT: Kind: FUNCTION +# REF-NEXT: Name: call_direct_ptr +# REF-NEXT: Flags: [ VISIBILITY_HIDDEN ] +# REF-NEXT: Function: 3 +# REF-NEXT: - Index: 5 +# REF-NEXT: Kind: DATA +# REF-NEXT: Name: direct_address +# REF-NEXT: Flags: [ ] +# REF-NEXT: Segment: 1 +# REF-NEXT: Size: 4 +# REF-NEXT: - Index: 6 +# REF-NEXT: Kind: TABLE +# REF-NEXT: Name: __indirect_function_table +# REF-NEXT: Flags: [ UNDEFINED, NO_STRIP ] +# REF-NEXT: Table: 0 +# REF-NEXT: - Index: 7 +# REF-NEXT: Kind: FUNCTION +# REF-NEXT: Name: call_alias_ptr +# REF-NEXT: Flags: [ VISIBILITY_HIDDEN ] +# REF-NEXT: Function: 4 +# REF-NEXT: - Index: 8 +# REF-NEXT: Kind: DATA +# REF-NEXT: Name: alias_address +# REF-NEXT: Flags: [ ] +# REF-NEXT: Segment: 2 +# REF-NEXT: Size: 4 +# REF-NEXT: - Index: 9 +# REF-NEXT: Kind: DATA +# REF-NEXT: Name: bar +# REF-NEXT: Flags: [ ] +# REF-NEXT: Segment: 0 +# REF-NEXT: Size: 4 +# REF-NEXT: - Index: 10 +# REF-NEXT: Kind: DATA +# REF-NEXT: Name: bar_alias +# REF-NEXT: Flags: [ BINDING_WEAK, VISIBILITY_HIDDEN, NO_STRIP ] +# REF-NEXT: Segment: 0 +# REF-NEXT: Size: 4 +# REF-NEXT: SegmentInfo: +# REF-NEXT: - Index: 0 +# REF-NEXT: Name: .data.bar +# REF-NEXT: Alignment: 3 +# REF-NEXT: Flags: [ ] +# REF-NEXT: - Index: 1 +# REF-NEXT: Name: .data.direct_address +# REF-NEXT: Alignment: 3 +# REF-NEXT: Flags: [ ] +# REF-NEXT: - Index: 2 +# REF-NEXT: Name: .data.alias_address +# REF-NEXT: Alignment: 3 +# REF-NEXT: Flags: [ ] +# REF-NEXT: ... + # CHECK-SYMS: SYMBOL TABLE: # CHECK-SYMS-NEXT: 00000001 g F CODE .hidden foo # CHECK-SYMS-NEXT: 00000006 g F CODE .hidden call_direct