This patch implements a fix to recognize global symbols that represent
WebAssembly appropriately and generate the necessary .tabletype
directives.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h | ||
---|---|---|
118 ↗ | (On Diff #393451) | I'm not sure this enumeration is best place to declare that type of a symbols. These other values all refer to how the symbol is used, but what type the symbol is. For example that distinction between function and data symbols does not appear here. |
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp | ||
1540 ↗ | (On Diff #393451) | Why MO_TABLE_BASE_REL here? |
llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp | ||
172 | If you do want to set the symbol type at this point why do it inside this if (MO.getOffset() != 0) { condition? However, it seems like for other symbol types the type is already previously set elsewhere so this maybe is not the place to do it? Looking at all the places where wasm symbols get their types set it looks like a rather mixed bag: $ git grep 'setType(wasm::' llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp: SPSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL); llvm/lib/MC/MCContext.cpp: cast<MCSymbolWasm>(Begin)->setType(wasm::WASM_SYMBOL_TYPE_SECTION); llvm/lib/MC/MCParser/WasmAsmParser.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); llvm/lib/MC/MCParser/WasmAsmParser.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL); llvm/lib/MC/MCParser/WasmAsmParser.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_DATA); llvm/lib/MC/MCWasmStreamer.cpp: Symbol->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL); llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_TABLE); llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); llvm/lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_TAG); llvm/lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); llvm/lib/Target/WebAssembly/Utils/WebAssemblyUtilities.cpp: Sym->setType(wasm::WASM_SYMBOL_TYPE_TABLE); llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp: Sym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL); llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL); llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_DATA); llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_TAG); llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp: Sym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); llvm/lib/Target/WebAssembly/WebAssemblyAsmPrinter.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_GLOBAL); llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp: WasmSym->setType(wasm::WASM_SYMBOL_TYPE_FUNCTION); Do you have any information to do this t WebAssemblyMCInstLower::GetGlobalAddressSymbol? |
llvm/lib/Target/WebAssembly/WebAssemblyISelLowering.cpp | ||
---|---|---|
1540 ↗ | (On Diff #393451) | That's a mistake. It should be MO_SYM_IS_..._TABLE. |
llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp | ||
172 | Yeah - I got the same feeling. Rather confusing about the best place to set this information. I will take a look at WebAssemblyMCInstLower::GetGlobalAddressSymbol. Thanks for the suggestion. |
llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h | ||
---|---|---|
118 ↗ | (On Diff #393451) | This is the place to set TargetFlags, and we cannot set the type of the symbol directly here because we don't have access to the MCSymbol, so as far as I can understand we need to set a TargetFlag and later on set the right MCSymbol type based on the address TargetFlags. Do you have a suggestion on where to set this information if not as a TargetFlag? |
llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h | ||
---|---|---|
118 ↗ | (On Diff #393451) | I'm afraid its been a while since I touched this code.. so I'm not sure I have any useful suggestions other than looking at existing code and practices. |
Fixes the issues found with previous patch.
We needed to ensure that GlobalVariable emissions supports table type
symbols as well as proper lowering.
@sbc100, I didn't ignore your comment regarding MO_SYM_IS_..._TABLE but
at this point I really don't know where to place this information for the
MC layer to act on it.
llvm/lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h | ||
---|---|---|
118 ↗ | (On Diff #393451) | Thanks, I have been looking and didn't find a better place to tag a symbol with a property so that the MC layer can 'fix' the symbol type. I will keep looking, if you think this is an improper place for the symbol type tag. |
llvm/lib/Target/WebAssembly/WebAssemblyMCInstLower.cpp | ||
---|---|---|
172 | Me: Who was the fool who set the type of a table GetGlobalAddressSymbol to WASM_SYMBOL_TYPE_GLOBAL? git blame: That was you... Me: Doh! |
Patch simplification.
@sbc100 Thanks for the pointer to GetGlobalAddressSymbol (even though I should have
recalled my own change). I hope this patch is easier to accept.
Oh nice! This looks way better now. Glad you figured it out, I'm not sure if I would have been much help!
If you do want to set the symbol type at this point why do it inside this if (MO.getOffset() != 0) { condition?
However, it seems like for other symbol types the type is already previously set elsewhere so this maybe is not the place to do it?
Looking at all the places where wasm symbols get their types set it looks like a rather mixed bag:
Do you have any information to do this t WebAssemblyMCInstLower::GetGlobalAddressSymbol?