Compile ELF worker runtime units with the initial-exec TLS model

Worker runtime variants link only into executables, whose own TLS block
holds every runtime thread-local, but they were compiled with the
default general-dynamic model. The linker relaxes each __tls_get_addr
call to a %fs-relative address, yet the compiler had already treated it
as a call: hot runtime leaves saved and restored extra registers around
every thread-local access (scr_mg_visit pushed five registers instead
of one). With -ftls-model=initial-exec each access is one %fs-relative
operand. Darwin, Windows and wasm variants are unchanged.

tsc-ts self-check, Linux sandbox, Worker build vs non-worker build:
1.04x -> 1.03x (9 interleaved runs).
This commit is contained in:
Malte Ubl
2026-10-09 17:43:51 -07:00
parent c3c59ccf1c
commit 37d19e2a42
@@ -229,11 +229,22 @@ async function build() {
? ["-I", zlib]
: []),
];
// Worker variants link only into executables, whose own TLS block
// holds every runtime thread-local: on ELF the initial-exec model
// makes each access one %fs-relative load, where the default
// general-dynamic model compiles to a __tls_get_addr call (the
// linker relaxes the call away, but the callers already spilled
// their registers around it).
const tlsFlags =
variant.defines.includes("SCR_WORKERS") && matrix.target.object_format === "elf"
? ["-ftls-model=initial-exec"]
: [];
const unitFlags = [
...commonFlags,
flavorSpec.optimization,
...debugFlags,
...variant.defines.map((define) => `-D${define}`),
...tlsFlags,
...includeFlags,
];
let bitcode;