Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

thin LTO produces function signature error #91700

Open
yamt opened this issue May 10, 2024 · 1 comment
Open

thin LTO produces function signature error #91700

yamt opened this issue May 10, 2024 · 1 comment
Labels
LTO Link time optimization (regular/full LTO or ThinLTO)

Comments

@yamt
Copy link
Contributor

yamt commented May 10, 2024

a test code: https://github.com/yamt/garbage/tree/1f7dc06dd2f6c63bf0bb27f58ffe2c98fdbaa953/lto2

it fails with -flto=thin.
i'm not sure if the problem is specific to wasm or it's just wasm being picky on function type happened to expose it.

spacetanuki% ./build.sh          
+ CC='/opt/wasi-sdk-22.0/bin/clang -Os -flto=thin'
+ /opt/wasi-sdk-22.0/bin/clang -Os -flto=thin -c a.c
+ /opt/wasi-sdk-22.0/bin/clang -Os -flto=thin -c main.c
+ /opt/wasi-sdk-22.0/bin/clang -Os -flto=thin main.o a.o
wasm-ld: warning: function signature mismatch: f
>>> defined as (i32) -> void in a.o
>>> defined as () -> void in lto.tmp
spacetanuki% toywasm --wasi a.out
Error: [trap] unreachable executed (4): unreachable at 000080
frame[  3] funcpc 000080 (a.out:signature_mismatch:f) callerpc 000108
  param [0] = 00000000
frame[  2] funcpc 000100 (a.out:.Lf_bitcast) callerpc 0000fb
frame[  1] funcpc 0000f5 (a.out:__main_void) callerpc 0000ba
frame[  0] funcpc 000086 (a.out:_start)
  local [0] = 00000000
2024-05-10 14:20:55 (1715318455.896787000): [105704600] instance_execute_func failed with -1
2024-05-10 14:20:55 (1715318455.897278000): [105704600] invoke failed with -1
spacetanuki% 

the same program builds and works fine with full LTO and no LTO.

spacetanuki% CC="/opt/wasi-sdk-22.0/bin/clang -Os -flto=full" ./build.sh
+ CC='/opt/wasi-sdk-22.0/bin/clang -Os -flto=full'
+ /opt/wasi-sdk-22.0/bin/clang -Os -flto=full -c a.c
+ /opt/wasi-sdk-22.0/bin/clang -Os -flto=full -c main.c
+ /opt/wasi-sdk-22.0/bin/clang -Os -flto=full main.o a.o
spacetanuki% CC="/opt/wasi-sdk-22.0/bin/clang -Os" ./build.sh 
+ CC='/opt/wasi-sdk-22.0/bin/clang -Os'
+ /opt/wasi-sdk-22.0/bin/clang -Os -c a.c
+ /opt/wasi-sdk-22.0/bin/clang -Os -c main.c
+ /opt/wasi-sdk-22.0/bin/clang -Os main.o a.o
spacetanuki% 

the same result with clang built from the latest LLVM (46435ac)

i found the issue when trying to build wasi-libc with thin LTO.

@EugeneZelenko EugeneZelenko added LTO Link time optimization (regular/full LTO or ThinLTO) and removed new issue labels May 10, 2024
@EugeneZelenko
Copy link
Contributor

@teresajohnson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LTO Link time optimization (regular/full LTO or ThinLTO)
Projects
None yet
Development

No branches or pull requests

2 participants