[PATCH] D126107: [lld][WebAssembly] Allow first-loader to use static TLS region

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 20 16:52:01 PDT 2022


sbc100 created this revision.
Herald added subscribers: pmatos, asb, wingo, ecnelises, sunfish, kristof.beyls, jgravelle-google, dschuff.
Herald added a project: All.
sbc100 requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.

It turns out we were already allocating space to hold TLS data along
with the rest of the static data, but this space was going unused/ignored.

With this change the `__wasm_init_memory` function (which does the work of
loading the passive segments into memory when a module is first loaded) will now
also call `__wasm_init_tls` with a pointer to the start of the statically
allocated region.

This means that calling `__wasm_init_tls` is longer necessary on the thread the
first loads a moudle.  Calling `__wasm_init_tls` again with a different region
should be harmless enough, making this change backwards compatible.

Practically speaking, this will allow emscripten to avoid dynamic allocation
completely for the first-loader of any DLL.  Crutially this includes the main
module where calling user space functions such as `malloc` is dangerous before
TLS is available.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126107

Files:
  lld/test/wasm/data-segments.ll
  lld/test/wasm/tls-align.s
  lld/test/wasm/tls.s
  lld/test/wasm/tls_init_symbols.s
  lld/wasm/Driver.cpp
  lld/wasm/Writer.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126107.431096.patch
Type: text/x-patch
Size: 7061 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220520/e645fb71/attachment.bin>


More information about the llvm-commits mailing list