[llvm-bugs] [Bug 36145] New: WASM - linking functions with missing arguments results in wrong args

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jan 30 01:15:16 PST 2018


https://bugs.llvm.org/show_bug.cgi?id=36145

            Bug ID: 36145
           Summary: WASM - linking functions with missing arguments
                    results in wrong args
           Product: lld
           Version: unspecified
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: cjd at cjdns.fr
                CC: llvm-bugs at lists.llvm.org

I'm unsure of whether to report this here or elsewhere, it might be clang, it
might be an ABI issue, but in any case I assume emscripten doesn't have this
problem because it seems to stop most software from running.

To reproduce:

## missing_args.c
```c
#include <stdio.h>
int callme_maybe(int arg1, int arg2, int arg3);
int main() {
    printf("3 = %d", callme_maybe(1, 2, 3));
}
```

## missing_args2.c
```c
int callme_maybe(int arg1, int arg2) {
    return arg1 + arg2;
}
```

```bash
/Users/user/wrk/play/clang-wasm-toolchain/build/clang/bin/clang
./test/missing_args.c ./test/missing_args2.c -target
wasm32-unknown-unknown-wasm -mthread-model single
-B/Users/user/wrk/play/clang-wasm-toolchain/build/bin/ -idirafter
/Users/user/wrk/play/clang-wasm-toolchain/projects/kernel-headers/generic/include
-I /Users/user/wrk/play/clang-wasm-toolchain/include_asm -D__linux=1
-D__linux__=1 -D__gnu_linux__=1 -Dlinux=1 --sysroot
/Users/user/wrk/play/clang-wasm-toolchain/build/musl -idirafter
/Users/user/wrk/play/clang-wasm-toolchain/build/musl/include
-Wl,--allow-undefined-file=/Users/user/wrk/play/clang-wasm-toolchain/wasm.syms
-rtlib=compiler-rt -resource-dir
/Users/user/wrk/play/clang-wasm-toolchain/build/compiler-rt -o a.out.wasm

<called by clang> /Users/user/wrk/play/clang-wasm-toolchain/build/lld/bin/lld
-flavor wasm -L/Users/user/wrk/play/clang-wasm-toolchain/build/musl/lib
/Users/user/wrk/play/clang-wasm-toolchain/build/musl/lib/crt1.o
/var/folders/z5/1x_ykg5d3bn162n3sm9ph4q00000gn/T/missing_args-707012.o
/var/folders/z5/1x_ykg5d3bn162n3sm9ph4q00000gn/T/missing_args2-83ae6c.o
--allow-undefined-file=/Users/user/wrk/play/clang-wasm-toolchain/wasm.syms -lc
/Users/user/wrk/play/clang-wasm-toolchain/build/compiler-rt/lib/libclang_rt.builtins-wasm32.a
-o a.out.wasm -z relro -z now

node runner.js a.out.wasm
3 = 5
```

Seems that the linker is ordering args in reverse order so if there is a
function definition with missing args, it will pass the wrong args.

You can reproduce this more easily using
https://github.com/cjdelisle/clang-wasm-toolchain where you only need to do
./build/bin/wasm32-unknown-unknown-wasm-cc ./test/missing_args.c
./test/missing_args2.c and then run the resulting a.out.wasm

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180130/a9fcb2ef/attachment.html>


More information about the llvm-bugs mailing list