llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.93k stars 11.53k forks source link

[WebAssembly] mysterious imports of aliases #104576

Open yamt opened 4 weeks ago

yamt commented 4 weeks ago

i noticed a lot of mysterious imports in wasi-libc libc.so. the following is a smaller example of the symptom.

alias.c:

int
add1(int x)
{
        return x + 1;
}

extern int add1_alias(int x)
        __attribute__((visibility("default"), weak, alias("add1")));

build it with:

clang -nostdlib -shared -Wl,--no-entry -o lib.so alias.c

look at the generated lib.so, see env.add1_alias import.

Import[6]:
 - memory[0] pages: initial=0 <- env.memory
 - table[0] type=funcref initial=0 <- env.__indirect_function_table
 - global[0] i32 mutable=1 <- env.__stack_pointer
 - global[1] i32 mutable=0 <- env.__memory_base
 - global[2] i32 mutable=0 <- env.__table_base
 - func[0] sig=0 <add1_alias> <- env.add1_alias

i don't see any obvious reasons to import this symbol. actually, the imported function doesn't seem to be used within the module at all.

fwiw, the export sections of the module look like:

Export[2]:
 - func[2] <__wasm_apply_data_relocs> -> "__wasm_apply_data_relocs"
 - func[3] <add1> -> "add1_alias"
llvmbot commented 4 weeks ago

@llvm/issue-subscribers-backend-webassembly

Author: YAMAMOTO Takashi (yamt)

i noticed a lot of mysterious imports in wasi-libc libc.so. the following is a smaller example of the symptom. alias.c: ```c int add1(int x) { return x + 1; } extern int add1_alias(int x) __attribute__((visibility("default"), weak, alias("add1"))); ``` build it with: ```shell clang -nostdlib -shared -Wl,--no-entry -o lib.so alias.c ``` look at the generated lib.so, see `env.add1_alias` import. ``` Import[6]: - memory[0] pages: initial=0 <- env.memory - table[0] type=funcref initial=0 <- env.__indirect_function_table - global[0] i32 mutable=1 <- env.__stack_pointer - global[1] i32 mutable=0 <- env.__memory_base - global[2] i32 mutable=0 <- env.__table_base - func[0] sig=0 <add1_alias> <- env.add1_alias ``` i don't see any obvious reasons to import this symbol. actually, the imported function doesn't seem to be used within the module at all. fwiw, the export sections of the module look like: ``` Export[2]: - func[2] <__wasm_apply_data_relocs> -> "__wasm_apply_data_relocs" - func[3] <add1> -> "add1_alias" ```
ppenzin commented 1 week ago

These help simulate POSIX and they should be documented in tool conventions. I did a brief check, at least some of them are.

yamt commented 1 week ago

These help simulate POSIX and they should be documented in tool conventions. I did a brief check, at least some of them are.

can you pinpoint the relevant part of tool-conventions?