diff --git a/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp b/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp index dae1d7745e..b63ed31554 100644 --- a/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp +++ b/core/relinker/relinker/src/pipeline/RelinkerPipeline.cpp @@ -341,6 +341,8 @@ RelinkResult RelinkerPipeline::Relink() { return std::nullopt; if ((raw[symOff + 4] & 15) != STT_TLS) throw RelinkerException("TLS relocation names a defined symbol that is not STT_TLS", pos); + if (section >= SHN_LORESERVE) + throw RelinkerException("Unsupported executable TLS symbol section", pos); std::uint64_t value = 0; std::memcpy(&value, raw.data() + symOff + 8, sizeof(value)); std::uint64_t size = 0; diff --git a/core/relinker/relinker/tests/test_executable_tls_relocations.py b/core/relinker/relinker/tests/test_executable_tls_relocations.py index cf054f5a1c..f36d44cf6d 100644 --- a/core/relinker/relinker/tests/test_executable_tls_relocations.py +++ b/core/relinker/relinker/tests/test_executable_tls_relocations.py @@ -107,6 +107,25 @@ def macho_bytes_at(data, address, size): def main(): relinker = Path(sys.argv[1]).resolve() with tempfile.TemporaryDirectory(prefix="anyps5-exec-tls-") as directory: + for section in (1, 0xff00, 0xfff1, 0xfff2, 0xffff): + for binding in (0, 1): + for kind in (DTPMOD64, DTPOFF64, TPOFF64): + for flags, target in TARGETS.items(): + data = image([(0x1000, kind, TLS_SYMBOL, 0)]) + struct.pack_into("