This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssembly] Process stub libraries before and after LTO
ClosedPublic

Authored by sbc100 on Mar 29 2023, 5:12 PM.

Details

Summary

There are cases where stub library processing can trigger new exports
which might require them to be included at LTO time.

Specifically processStubLibraries marks symbols as forceExports
which even effect the LTO process.

And since the LTO process can generate new undefined symbols
(specifically libcall function) we need to also process the stub
libraries after LTO.

Diff Detail

Event Timeline

sbc100 created this revision.Mar 29 2023, 5:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2023, 5:12 PM
Herald added subscribers: pmatos, asb, ormris and 8 others. · View Herald Transcript
sbc100 requested review of this revision.Mar 29 2023, 5:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 29 2023, 5:12 PM
sbc100 updated this revision to Diff 509509.Mar 29 2023, 5:14 PM
  • comments
sbc100 retitled this revision from [lld][WebAssembly] Process stub libraries before performing LTO to [lld][WebAssembly] Process stub libraries before and after LTO.

Do we really need to support stub libcalls (i.e. the kind that can be generated at codegen time)? These should just be compiler-rt and maybe a few core libc functions, right? Do we expect those to be implemented in JS and/or the environment?

i.e. it seems like it would be simpler to just support processing the stubs once. or maybe more specifically, to handle them the same as other archive libraries (i.e. participate in the iterate-to-convergence phase of symbol resolution but not get special treatment for LTO?)

Do we really need to support stub libcalls (i.e. the kind that can be generated at codegen time)? These should just be compiler-rt and maybe a few core libc functions, right? Do we expect those to be implemented in JS and/or the environment?

Yes, we have use cases in emscripten where symbols that are created during LTO depend on other native symbols. The one I can remember was emscripten exception handling I believe. The compiler creates references to JS-defined functions at LTO time, which in tern require certain native exports (__cxa_is_pointer_type I believe).

i.e. it seems like it would be simpler to just support processing the stubs once. or maybe more specifically, to handle them the same as other archive libraries (i.e. participate in the iterate-to-convergence phase of symbol resolution but not get special treatment for LTO?)

I think that would require injecting the dependency graph of the stub library into the relocation graph somehow. I did consider trying to do that but this solution ended up being a lot simpler. I don't think we need to worry about the cost of processing these stubs, do you?

dschuff accepted this revision.Mar 30 2023, 11:05 AM

I guess the new test covers the stub->bitcode lib dependence case. Is there a test that covers the codgen->libcall->stub case?

lld/test/wasm/lto/stub-library.s
7
This revision is now accepted and ready to land.Mar 30 2023, 11:05 AM
sbc100 updated this revision to Diff 509737.Mar 30 2023, 11:12 AM
  • feedback

I guess the new test covers the stub->bitcode lib dependence case. Is there a test that covers the codgen->libcall->stub case?

That specific type of test (where LTO generates new undefined symbols) is quite hard to write since it depends on the specifics of codegen/LTO... but I'll give it a go. We have at least one test already for that I think (libcall-archive.ll)