WebAssembly / lld

Staging repository for upstreaming WebAssembly support into lld
Other
10 stars 10 forks source link

Linking via the "-l" flag results in garbage error message (and fails to link) #11

Closed JohnSully closed 7 years ago

JohnSully commented 7 years ago

Command: "/usr/local/bin/lld" -flavor wasm -L/home/john/wasm_sysroot//lib test.o -allow-undefined-file /home/john/wasm_sysroot//lib/wasm.syms -lc -o a.out

Error: /usr/local/bin/lld: error: cannot open # hn/wasm_� /lib/libc.a: No such file or directory

Linking instead with /home/john/wasm_sysroot/lib/libc.a directly works fine. The libc.a file is attached libc.zip

JohnSully commented 7 years ago

This from the latest in the "wasm" branch.

JohnSully commented 7 years ago

An additional way to narrow this down: It repros even with an empty file at the right spot called libc.a. So it doesn't appear to be based upon the content of the shared lib.

sbc100 commented 7 years ago

Hmm.. that is very strange. I can't seem to reproduce this at all.

Its interesting because the file seems to have been found since otherwise you would see a different error: lld: error: unable to find library -lc

So its finding the library then failing to open it.

Can you run with "--verbose" and "-lllvm -debug" perhaps and post the output?

JohnSully commented 7 years ago

--verbose gives the same output. I get unknown library and unknown argument for -lllvm -debug.

I'm running this on windows subsystem for linux, I'll try on a native linux box.

sbc100 commented 7 years ago

--verbose should give more output if its passed to the linker. If you are running via clang you need to do -Wl,--verbose.

I had typo in the other args. Should have been -mllvm -debug (precede both of these with -Wl, if calling via clang).

JohnSully commented 7 years ago

All commands are passed directly to lld to prevent other issues. --verbose had no effect, the other flags change the output as follows: john@DESKTOP-42MHL48:~/testwebasm$ "/usr/local/bin/lld" -flavor wasm -mllvm -debug -L/home/john/wasm_sysroot//lib test.o -allow-undefined-file /home/john/wasm_sysroot//lib/wasm.syms -lc -o a.out Args: lld-link (LLVM option parsing) -debug addDefinedGlobal: __stack_pointer setOutputIndex __stackpointer -> 0 /usr/local/bin/lld: error: cannot open # hn/wasm`T /lib/libc.a: No such file or directory

JohnSully commented 7 years ago

This repros on a pure linux box as well.

JohnSully commented 7 years ago

I've narrowed it down. The issue only repros when lld was built with gcc. Rebuilding with clang solves the problem.

It looks like there's some undefined behavior that triggers in gcc but not clang.

AndrewScheidecker commented 7 years ago

I also ran into this problem building lld with MSVC, and tracked the problem down to this code, which returns StringRef to a local SmallString<128> that is destructed when the function returns. Changing findFile to return a SmallString<128> solves the problem.

sbc100 commented 7 years ago

Thanks for tracking that down!