This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssembly] Add --unresolved-symbols=import-dynamic
ClosedPublic

Authored by sbc100 on Nov 16 2020, 3:47 PM.

Details

Summary

This is a new mode for handling unresolved symbols that allows all
symbols to be imported in the same way they would be in the case of
-fpie or -shared but generating an otherwise fixes/non-relocatable
binary.

Code linked in this way should still be compiled with -fPIC so that
data symbols can be resolved via imports.

This essentially allow the building of static binaries that have dynamic
imports. See:
https://github.com/emscripten-core/emscripten/issues/12682

As with other used of dynamic linking ABI this beviour will produce a
warning unless run with --experimental-pic.

Diff Detail

Event Timeline

sbc100 created this revision.Nov 16 2020, 3:47 PM
Herald added a project: Restricted Project. · View Herald Transcript
sbc100 requested review of this revision.Nov 16 2020, 3:47 PM
sbc100 edited the summary of this revision. (Show Details)Nov 17 2020, 11:23 AM
sbc100 edited the summary of this revision. (Show Details)

What's the use case for 'import-functions' mode after we roll this out?

lld/test/wasm/unresolved-symbols.s
76

shouldn't these runs/checks go in unresolved-symbols-dynamic.s?

What's the use case for 'import-functions' mode after we roll this out?

It allows folks to have the semantics of --allow-undefined which has existing users. We've seen a it bunch of times in bug reports, mostly among users of wasi-sdk.

The semantics of this option are still useful because it allows the binary to import all undefined function while zero-ing out undefined data symbols. The new import-dynamic mode is not a suitable replacement for all users because (a) it requires use of the the experimental PIC ABI and (b) it requires all objects files that reference undefined data symbols to be built with -fPIC.

Indeed this is the default behaviour expected by emscripten, and will continue to be for a while now.

Are are you are asking.. "why bother allowing the --unresolved-symbols= version of this option when we can just use --allow-undefined"?

I was curious about emscripten. You mean that this is the mode that links the final wasm? Does emscripten allow users to inject JS functions that are directly imported by the wasm? (I assume we could use that mode for JS functions that are directly packaged by emscripten if we wanted).

I was curious about emscripten. You mean that this is the mode that links the final wasm? Does emscripten allow users to inject JS functions that are directly imported by the wasm? (I assume we could use that mode for JS functions that are directly packaged by emscripten if we wanted).

Yes, emscripten (almost) always links with --allow-undefined and then reported its undefined symbols later on in the JS library processor. And yes emscripten fills in any imported functions with JS implementations if it can, and errors if it can't.

lld/test/wasm/unresolved-symbols.s
76

I guess you are right.. I'll move these.

sbc100 updated this revision to Diff 305957.Nov 17 2020, 7:23 PM
  • feedback
dschuff accepted this revision.Nov 18 2020, 1:53 PM
This revision is now accepted and ready to land.Nov 18 2020, 1:53 PM
sbc100 updated this revision to Diff 415210.Mar 14 2022, 1:46 PM
  • rebase
Herald added a project: Restricted Project. · View Herald TranscriptMar 14 2022, 1:46 PM
sbc100 edited the summary of this revision. (Show Details)Mar 14 2022, 2:02 PM
sbc100 updated this revision to Diff 415217.Mar 14 2022, 2:06 PM
sbc100 edited the summary of this revision. (Show Details)
  • comments
dschuff added inline comments.Mar 14 2022, 2:43 PM
lld/docs/WebAssembly.rst
97

this is now slightly confusing since --unresolved symbols is no longer completely orthogonal to --import-undefined? Probably at least the doc for --import-undefined should go just above --unresolved-symbols

sbc100 updated this revision to Diff 415569.Mar 15 2022, 1:59 PM
  • update docs
sbc100 edited the summary of this revision. (Show Details)Mar 15 2022, 2:37 PM
sbc100 added inline comments.Mar 15 2022, 3:10 PM
lld/docs/WebAssembly.rst
97

I went back and forth between adding --import-dynamic and --unresolved-symbols=import-dynamic. In the end I think this is more clear since unlike --import-undefined this new option effects all undefined symbols.

This option is currently behind the --experimental-pic flag so revisiting this decision in the future is still possible.

I re-wrote the documentation to make this a little more clear

This revision was landed with ongoing or failed builds.Mar 15 2022, 3:14 PM
This revision was automatically updated to reflect the committed changes.