Skip to content

WebAssembly tables + global variables + debug info = invalid binaries #143934

Open
@feedab1e

Description

@feedab1e

creating a WebAssembly table and another global variable, then compiling with debug info, yields a binary that cannot be read or linked by any llvm tool (link):

// 1.cpp
int a;
inline static __externref_t table[0];

int main() {
    __externref_t get();
    __builtin_wasm_table_set(table, 0, get());
}

if compiled with

clang++ -g --target=wasm32 1.cpp -c -o 1.o

and used like following:

llvm-dwarfdump 1.o

will yield

error: 1.o: invalid data relocation: _ZL5table

The same issue occurs when trying to link:

wasm-ld --no-entry 1.o -o 1.wasm

yields

wasm-ld: error: 1.o: invalid data relocation: _ZL5table

Notably, the same issue does not occur when we remove the declaration of a:

// 1.cpp
inline static __externref_t table[0];

int main() {
    __externref_t get();
    __builtin_wasm_table_set(table, 0, get());
}

links successfully.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions