[PATCH] D43264: [WebAssembly] Add explicit symbol table
Nicholas Wilson via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 15 01:06:29 PST 2018
ncw added a comment.
In https://reviews.llvm.org/D43264#1008031, @ruiu wrote:
> So, InputFunction is a function, InputSegment is a data segment, and what is "wasm global" for? It sounds like it is more like data than a function, but I wonder how "wasm global" is different from regular data section.
It's basically a special type of data section; what makes it special is that it's accessed more like a register than a memory region.
The InputGlobal object represents the allocation of the memory/storage for the symbol, and contains the region of memory to be copied into the output binary with the initial value of the data.
You're right, it's very similar to a data symbol. The InputGlobal has really the same role for a GlobalSymbol as an InputSection does for a DataSymbol.
// Will be stored in ordinary memory, addressable down to individual bytes.
// Creates a 12-byte data section (InputSegment), holding its initial value, which
// the data Symbol points to as its definition.
std::tuple<int,int,int> global_variable = {1,2,3};
// Will create a 4-byte section, but using a "Wasm global". Not addressable down
// to individual bytes, it's like a register. Can't take address-of, can only assign
// and read from the storage. Requests the WebAssembly virtual machine to
// allocate a thread-local register. Constrained to be of register type (int32/float32/
// int64/float64) so the size of an InputGlobal is always a 4- or 8-byte section.
//
// Unlike x86 registers, you can have have as many as you want, they are storage
// slots allocated at program startup, just like ordinary sections are mapped to
// RAM. (NB The WebAssembly interpreter will spill the globals to RAM if the "real"
// CPU doesn't have enough spare registers to use for the Wasm globals). So it's like
// data, in that these are variables with a value, but the mechanics of the storage
// slots are different. There's no analogue in ELF, because x86 has a fixed number of
// registers, and the binary doesn't have to ask for them to be created.
//
// The 4-byte section containing the initial value is represented by an InputGlobal,
// which the Wasm-global symbol points to as its definition. It's written out in a
// different place in the final Wasm object, since it has distinct semantics.
//
// NB. This attribute isn't actually implemented in the C frontend ("Wasm globals"
// are only accessible via intrinsics). Conceptually these are just variables though.
int __attribute__((wasm_global)) wasm_global = 123;
Repository:
rLLD LLVM Linker
https://reviews.llvm.org/D43264
More information about the llvm-commits
mailing list