From eb3acb2ce66c4fd51db2f46528696ade590a55c8 Mon Sep 17 00:00:00 2001 From: maxjivi05 Date: Sat, 5 Dec 2026 15:22:30 -0500 Subject: [PATCH] Keep the session preload loadable when spare static TLS runs out The syscall-dispatch selector pointer in the zram preload used the initial-exec TLS model. That marks the whole libddsession TLS block (about 1.8 KB) as static, so loading it at runtime needs that much spare static TLS. Under proot there is not enough, and every guest program failed with "cannot allocate memory in static TLS block". The default model keeps the same per-thread behaviour without that requirement. --- tools/linuxfs/preload/zram.c | 2 +- tools/tests/test_zram_preload.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/tools/linuxfs/preload/zram.c b/tools/linuxfs/preload/zram.c index 446996a06e..3b3611dba5 100644 --- a/tools/linuxfs/preload/zram.c +++ b/tools/linuxfs/preload/zram.c @@ -542,7 +542,7 @@ static int zr_start(void) { return 0; } -static __thread volatile unsigned char *zr_dispatch __attribute__((tls_model("initial-exec"))); +static __thread volatile unsigned char *zr_dispatch; int prctl(int option, ...) { va_list ap; diff --git a/tools/tests/test_zram_preload.py b/tools/tests/test_zram_preload.py index 3d6b7d6126..774274c2b9 100644 --- a/tools/tests/test_zram_preload.py +++ b/tools/tests/test_zram_preload.py @@ -773,6 +773,20 @@ class ZramPreloadTest(unittest.TestCase): self.assertEqual([1], out["trimmed"], out) self.assertEqual([1], out["named"], out) + def test_loads_at_runtime_without_spare_static_tls(self): + loader = self.dir / "loader" + source = self.dir / "loader.c" + source.write_text("#include \n#include \n" + "int main(int c, char **v) { (void)c; void *h = dlopen(v[1], RTLD_NOW);" + " puts(h ? \"loaded\" : dlerror()); return h == NULL; }\n") + subprocess.run(["cc", "-O2", "-o", str(loader), str(source), "-ldl"], check=True) + environment = dict(os.environ, GLIBC_TUNABLES="glibc.rtld.optional_static_tls=0") + environment.pop("LD_PRELOAD", None) + result = subprocess.run([str(loader), str(self.lib)], env=environment, capture_output=True, text=True, + timeout=60) + self.assertEqual(0, result.returncode, result.stdout + result.stderr) + self.assertEqual("loaded", result.stdout.strip()) + if __name__ == "__main__": unittest.main()