wasi-sdk icon indicating copy to clipboard operation
wasi-sdk copied to clipboard

debug info depends on -Wl,--export=

Open jendrikw opened this issue 4 years ago • 4 comments

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?

jendrikw avatar Apr 27 '20 09:04 jendrikw

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.

sunfishcode avatar Apr 27 '20 15:04 sunfishcode

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.

jendrikw avatar Apr 27 '20 16:04 jendrikw

Also related: "wasm-opt strips symbol names when optimizing" https://bugs.llvm.org/show_bug.cgi?id=45602

jendrikw avatar May 07 '20 07:05 jendrikw

I think this is related to https://github.com/llvm/llvm-project/issues/55781.

abrown avatar Aug 08 '23 22:08 abrown