wasi-sdk
wasi-sdk copied to clipboard
debug info depends on -Wl,--export=
When compiling a C program with -Wl,--export-all
, more debug info is generated.
For example, take this program:
#include <stdio.h>
#include <errno.h>
int main() {
FILE *f = fopen("/etc/issue", "r");
if (!f) {
return errno;
}
return fclose(f);
}
Compile with -g -O3 -Wl,--export-all
and run wasm2wat
(func $main (type $t0) (param $p0 i32) (param $p1 i32) (result i32)
call $__original_main)
Now compile with -g -O3 -Wl,--export=main
and run wasm2wat
(func $main (type $t2) (param $p0 i32) (param $p1 i32) (result i32)
call $f11)
Why is there a difference?
Do you have wasm-opt
in your PATH? If so, clang runs it at -O3
, and it may be doing optimizations which change the names.
Thanks for the hint. I do have wasm-opt
on my path and can confirm that clang
calls it. A discussion about disabling wasm-opt
and how to pass options is happening at https://reviews.llvm.org/D70500. Let's wait for the discussion to settle.
Also related: "wasm-opt strips symbol names when optimizing" https://bugs.llvm.org/show_bug.cgi?id=45602
I think this is related to https://github.com/llvm/llvm-project/issues/55781.