This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssembly] Add `--export-if-defined`
ClosedPublic

Authored by sbc100 on Apr 5 2021, 9:02 AM.

Details

Summary

Unlike the existing --export option this will not causes errors
or warnings if the specified symbol is not defined.

See: https://github.com/emscripten-core/emscripten/issues/13736

Diff Detail

Event Timeline

sbc100 created this revision.Apr 5 2021, 9:02 AM
sbc100 requested review of this revision.Apr 5 2021, 9:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2021, 9:02 AM

I dont love the name of this option.. but I failed to come up with any thing nicer.

I did consider weaking the existing --export to mean "export if defined" and then requiring --require-defined (which is an existing GNU ld option) to get the stronger meaning back.. but that has two disadvantages:

  1. Potentially breaking existing users exceptions
  2. Makes the common use case of --export foo --require-defined foo for each export a lot more verbose.

Pre-existing, but what does --export plus --allow-undefined do?

lld/wasm/Driver.cpp
890

should this comment no longer say "if its found"? If it's not found, the whole process should error, right?

Oh also, I think --export-if-defined is an OK name.

I don't know wasm enough... In ELF, --export-dynamic-symbol only affects defined symbols. --export-dynamic affects all defined symbols. They don't have effect on other symbols.

sbc100 added a comment.Apr 5 2021, 4:15 PM

Pre-existing, but what does --export plus --allow-undefined do?

--allow-undefined will not report errors on undefined symbols at all (even those passed via --export). This is true both before and after this change.

One of the reasons for this change is that we would like one day to remove --allow-undefined from emscripten by default which exposes the current limitations of --export.

sbc100 added a comment.Apr 5 2021, 4:16 PM

I don't know wasm enough... In ELF, --export-dynamic-symbol only affects defined symbols. --export-dynamic affects all defined symbols. They don't have effect on other symbols.

Interesting.. aside from not really conveying its meaning clearly --export-dynamic-symbol sounds like it might be what we want here.

I don't know wasm enough... In ELF, --export-dynamic-symbol only affects defined symbols. --export-dynamic affects all defined symbols. They don't have effect on other symbols.

Interesting.. aside from not really conveying its meaning clearly --export-dynamic-symbol sounds like it might be what we want here.

I think the reason is because for non-defined symbols, there is no point specifically mentioning "exported".

An undefined symbol not defined anywhere or defined in a shared object is naturally exported, because otherwise it cannot be resolved to a different module at runtime.
For a defined symbol, there is a distinction whether it should be exported.

sbc100 added a reviewer: sunfish.

Going with this option over re-using --export-dynamic-symbol since the meaning doesn't quite match.

dschuff accepted this revision.Apr 29 2021, 10:51 AM
This revision is now accepted and ready to land.Apr 29 2021, 10:51 AM
This revision was automatically updated to reflect the committed changes.