This is an archive of the discontinued LLVM Phabricator instance.

All lazy symbols to be exported with --export
AbandonedPublic

Authored by sbc100 on Aug 3 2018, 3:10 PM.

Details

Reviewers
ruiu
dschuff
Summary

This is really a requirement from emscripten but I think it
makes sense in general too.

Event Timeline

sbc100 created this revision.Aug 3 2018, 3:10 PM
ruiu added a comment.Aug 3 2018, 3:15 PM

Doing it probably makes sense, but at the same time this new behavior is subtle. What is the issue with Emscripten without this patch?

sbc100 added a comment.Aug 3 2018, 3:19 PM

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.

ruiu added a comment.Aug 3 2018, 3:21 PM

--undefined doesn't report an error if an argument symbol is missing, at least for Unix. Is this different in lld/wasm?

sbc100 added a comment.Aug 3 2018, 3:23 PM

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".

sbc100 added a comment.Aug 3 2018, 3:24 PM

Oh, I didn't realize that. In that case perhaps we need to bring --undefined in line with the ELF linker?

ruiu added a comment.Aug 3 2018, 3:26 PM

I guess so. There's no reason to be different, I believe.

sbc100 abandoned this revision.Aug 3 2018, 4:01 PM

Ok, lets try that approach: https://reviews.llvm.org/D50279