From 71b9cf3d0df639d148db565dec5e76cee8462c68 Mon Sep 17 00:00:00 2001 From: Hashaam Zafar Date: Wed, 7 Oct 2026 11:52:14 -0700 Subject: [PATCH] test(relinker): run the Windows TLS cases on Linux x86-64 tls_function_coverage ran its execution cases only on Windows; on Linux it checked bytes. windows_image_runner.py maps the relinked PE, points GS at a TEB whose TLS slot holds a block copied from the template, runs the TLS callbacks for process attach with the Windows argument registers and calls the guest entry. convert() uses it on Linux x86-64 and expects 42, as on Windows. Co-Authored-By: Claude Opus 5.5 --- .../tests/test_tls_function_coverage.py | 7 +++ .../relinker/tests/windows_image_runner.py | 48 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 core/relinker/relinker/tests/windows_image_runner.py diff --git a/core/relinker/relinker/tests/test_tls_function_coverage.py b/core/relinker/relinker/tests/test_tls_function_coverage.py index 3a8cae4dd..d0af236cd 100644 --- a/core/relinker/relinker/tests/test_tls_function_coverage.py +++ b/core/relinker/relinker/tests/test_tls_function_coverage.py @@ -1,5 +1,6 @@ import os from pathlib import Path +import platform import struct import subprocess import sys @@ -9,6 +10,8 @@ from test_optional_plt import fixture TLS_LOAD = bytes.fromhex("66 66 66 64 48 8b 04 25 00 00 00 00") +RUNNER = Path(__file__).with_name("windows_image_runner.py") +RUNS_ON_HOST = sys.platform == "linux" and platform.machine() == "x86_64" def register_load(register): @@ -307,6 +310,10 @@ def main(): if os.name == "nt": executed = subprocess.run([str(output)], capture_output=True, timeout=30) assert executed.returncode == 42, (name, executed.returncode, executed.stderr) + elif RUNS_ON_HOST: + entry = 0x10000 + struct.unpack_from("