This is an archive of the discontinued LLVM Phabricator instance.

[lld][WebAssembly] Create optional internal symbols only after LTO object as been added
ClosedPublic

Authored by sbc100 on Oct 5 2021, 11:22 AM.

Details

Summary

This is important for the cases where new symbols can be introduced
during LTO. Specifically this happens for during TLS-lowering where
references to __tls_base can be introduced.

Fixes: https://github.com/emscripten-core/emscripten/issues/12489

Diff Detail

Event Timeline

sbc100 created this revision.Oct 5 2021, 11:22 AM
sbc100 requested review of this revision.Oct 5 2021, 11:22 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2021, 11:22 AM
tlively accepted this revision.Oct 5 2021, 11:30 AM
This revision is now accepted and ready to land.Oct 5 2021, 11:30 AM
sbc100 edited the summary of this revision. (Show Details)Oct 5 2021, 11:49 AM

As I mentioned in https://github.com/emscripten-core/emscripten/issues/12489 I'm having trouble reproducing this and thus creating a test for it.

The problem is that in all the tests I've managed to create all the TLS variables get lowered away by https://github.com/llvm/llvm-project/blob/f92961d238efdfeccce27f9bb7b0a6629c376d4a/llvm/lib/Target/WebAssembly/WebAssemblyTargetMachine.cpp#L295.. and therefore WebAssemblyTargetLowering::LowerGlobalTLSAddress is never called.. and AFAICT that is the only reasonable place that those references to __tls_base could be created during LTO.

How about if you create two LTO object files, one with -mattr=+atomics,+bulk-memory and one without, then link them together? In the combined bitcode, the presence of +atomics and +bulk-memory on the functions from the first object file will prevent that stripping from running, and you should get references to __tls_base from code originating in both object files.

How about if you create two LTO object files, one with -mattr=+atomics,+bulk-memory and one without, then link them together? In the combined bitcode, the presence of +atomics and +bulk-memory on the functions from the first object file will prevent that stripping from running, and you should get references to __tls_base from code originating in both object files.

Thanks for the tip. Yes I think I'm somehow not setting -mattr=+atomics,+bulk-memory in the LTO object file. In my test hand written .ll test case how do I enable those.. it seems not on the llvm-as command line? I guess they are embedded in the .ll itself...

sbc100 added a comment.Oct 5 2021, 1:31 PM

Finally got the test working. Fails without this change (undefined symbol __tls_base) .. passed after.

sbc100 updated this revision to Diff 377338.Oct 5 2021, 1:31 PM
sbc100 edited the summary of this revision. (Show Details)
  • fix test
This revision was landed with ongoing or failed builds.Oct 5 2021, 1:33 PM
This revision was automatically updated to reflect the committed changes.