[lld] [lld][WebAssembly] Match the ELF linker in transitioning away from archive indexes. (PR #78658)

Alex Crichton via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 23 10:19:03 PST 2024


alexcrichton wrote:

The `lib.rmeta` file present in `*.rlib` files is metadata for the Rust compiler, think a binary-encoded C/C++ header file of sorts. That's present because rustc consumes this to know how to link against it at the Rust level (e.g. it can typecheck your code) and then it also passes the same `*.rlib` to the linker since it also contains all the object code as well. (background if anyone finds this helpful)

Historically AFAIK rustc relied on the index, if present, being used. It would then never look at `lib.rmeta` since `--whole-archive` for rlibs isn't passed and there are no symbols in `lib.rmeta`. That means that so long as the linker only looked at files the index pointed at rustc could get away putting its metadata in the rlib archive. If, however, indexes are no longer used this may present a problem for rustc.

I don't know what ELF LLD does when it encounters files like this. If it also emits a warning then the reason it works there and not on wasm is the code that @nikic pointed out. When I originally implemented the wasm target in Rust I thought passing `--fatal-warnings` would be a good idea because rustc does not output the linker output when a failure does not occur. This means that all warnings are squelched by default, and this may explain why ELF "works" where wasm doesn't.

As for why rustc squelches linker output by default, I think that's a historical accident that no one ever went back to fix (very historical) and has probably become somewhat load bearing at this point unfortunately (e.g. if `--fatal-warnings` is removed then no Rust developer will be aware that LLD is producing all these warnings about `lib.rmeta` files, not that they could do anything about it anyway though)

https://github.com/llvm/llvm-project/pull/78658


More information about the llvm-commits mailing list