This is really a requirement from emscripten but I think it
makes sense in general too.
Details
Diff Detail
- Repository
- rLLD LLVM Linker
- Build Status
Buildable 21063 Build 21063: arc lint + arc unit
Event Timeline
Doing it probably makes sense, but at the same time this new behavior is subtle. What is the issue with Emscripten without this patch?
Emscripten uses --export in order to choose which symbols to export. It does this for main too with --export=main. We can't use --undefined in general since (for complicated reasons) some of these symbols might actually be missing at link time.
I ran into an issue within google where the main symbol ends up living a library (for gtest-based tests this is aften the case) and that resulting in main not being included in the output binary.
--undefined doesn't report an error if an argument symbol is missing, at least for Unix. Is this different in lld/wasm?
A bit more detail: Emscripten has flag called "-s EXPORTED_FUNCTIONS=<list>". By default this list includes just main. But those symbols can either come from native code or from JS libraries, so they might not exist and link time. Ideally we would know which ones we need at link time and with --export=foo and --undefined=foo which would force all these symbols to exist. But right now we don't have that knowledge so we use --allow-undefined with --export=foo, which roughly equates to "export these symbols if they are found at link time but don't error out if they are not".
Oh, I didn't realize that. In that case perhaps we need to bring --undefined in line with the ELF linker?