Replies: 2 comments 4 replies
-
I think this is a great idea! It seems similar to having some sort of "virtual object file" for JS code that participates in symbol resolution and gc but doesn't actually link in any code. I get why the libraries would need to be processed before linking to get a list of their symbols and dependencies, but why would they need to be processed again after linking? |
Beta Was this translation helpful? Give feedback.
-
The "virtual object file" idea exists in ELF (it's called a stub object) and I think there may also be some kind of equivalent in MachO too?). We almost got around to using something like that for PNaCl to solve similar problems with bitcode/native dependencies and the 2-phase linking that PNaCl had. |
Beta Was this translation helpful? Give feedback.
-
The reverse dependencies from JS symbols back to native symbols have caused a lot of problems over the years and it would be great to handle a better way. The current system of using
deps_info.py
has several problems/downsides:llvm-nm
(there have been correctness and performance issues with this code over time).@juj has PR (#15982) that tries to extent support to user libraries. It does this by processing the libraries twice, once before and one after linking.
As it happens, the existing
LLD_REPORT_UNDEFINED
also process the libraries an extra time before calling the linker. It does this to produce a list of all possible JS symbols which it can then pass to wasm-ld as valid undefined symbols.LLD_REPORT_UNDEFINED
is designed to allow wasm-ld to do all symbol resolution and report undefined symbols, as opposed to delaying this until later in JS (where the error message less useful/actionable because they don't refer to individual object files).While reviewing #15982 I came up with an idea to extend
LLD_REPORT_UNDEFINED
to include support for reverse dependences. The idea is to give wasm-ld enough information that is aware of all symbols and their dependencies (including all JS symbols).Today, if you use
LLD_REPORT_UNDEFINED
we generate a simple list of symbols from the JS library files and pass that to the linker with--allow-undefined-file=all.syms
. For example given the follow JS library file:We would generate
all.syms
containing:So the linker can know that foo and bar are external, and any other missing symbols should result in an error.
My idea would to exten this format to include dependencies. e.g.:
Would generate:
Then the linker would know that if
foo
is undefined in the program (and therefore imported) it would be required to also exportnative_func
andother_native_func
.Adding this extra would not incur additional performance overhead on top of that already uncured by
LLD_REPORT_UNDEFINED
, but it would require:--allow-undefined-file
file format inwasm-ld
. Since this would more likely be emscripten-specific that could be contravertial.LLD_REPORT_UNDEFINED
the default, and accepting the performance code of processing libraries twice.What we stand to gain:
Beta Was this translation helpful? Give feedback.
All reactions