Merge pull request #618 from oneandonlydean/fix/relinker-linux-host-libc-needed

fix(relinker): keep the host libc.prx needed on Linux when a title bundles its own
This commit is contained in:
Dean
2026-10-05 21:26:07 +13:00
committed by GitHub
3 changed files with 70 additions and 0 deletions
+2
View File
@@ -210,6 +210,8 @@ if(BUILD_TESTING)
${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/test_guest_tls.py $<TARGET_FILE:relinker>)
add_test(NAME guest_module_directories COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/test_guest_module_directories.py $<TARGET_FILE:relinker>)
add_test(NAME guest_host_libc COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/test_guest_host_libc.py $<TARGET_FILE:relinker>)
add_test(NAME elf_header COMMAND ${Python3_EXECUTABLE}
${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/test_elf_header.py $<TARGET_FILE:relinker>)
add_test(NAME input_magic COMMAND ${Python3_EXECUTABLE}
@@ -135,6 +135,7 @@ std::vector<GuestArtifact> GuestModuleBuilder::Build(const std::filesystem::path
addHost(std::string(start, end));
}
for (const auto& image : images) for (const auto& dependency : image.Dependencies) addHost(dependency);
if (uniqueHosts.contains("libSceLibcInternal.prx") && uniqueHosts.insert("libc.prx").second) hostLibraries.push_back("libc.prx");
dynamic.DynamicSegmentData.clear();
const auto addNeeded = [&](const std::string& name) {
Io::AppendU64(dynamic.DynamicSegmentData, 1);
@@ -0,0 +1,67 @@
from pathlib import Path
import struct
import subprocess
import sys
import tempfile
from test_guest_intel_trampolines import PLAIN_SITE, guest_fixture, main_fixture
from test_guest_module_directories import needed_libraries
DYNAMIC = 0x4800
STRINGS = 0x4A00
def importing(*libraries):
image = main_fixture()
strings = b"\0" + b"".join(name.encode() + b"\0" for name in libraries)
image[STRINGS:STRINGS + len(strings)] = strings
tags = []
offset = 1
for name in libraries:
tags.append((1, offset))
offset += len(name) + 1
tags += [(5, STRINGS), (10, len(strings)), (6, 0x4620), (11, 24), (7, 0x4700), (8, 0), (9, 24), (0, 0)]
for index, tag in enumerate(tags):
struct.pack_into("<qQ", image, DYNAMIC + index * 16, *tag)
struct.pack_into("<QQQQQ", image, 120 + 8, DYNAMIC, DYNAMIC, DYNAMIC, len(tags) * 16, len(tags) * 16)
return image
def convert(relinker, case, libraries, modules, options=()):
(case / "sce_module").mkdir(parents=True)
source = case / "input.elf"
source.write_bytes(importing(*libraries))
for name in modules:
(case / "sce_module" / name).write_bytes(guest_fixture(PLAIN_SITE))
output = case / "output.elf"
result = subprocess.run([str(relinker), *options, str(source), str(output)],
capture_output=True, text=True, timeout=30)
assert result.returncode == 0, (result.stdout, result.stderr)
return needed_libraries(output.read_bytes())
def main():
relinker = Path(sys.argv[1]).resolve()
imports = ("libkernel.prx", "libc.prx", "libSceLibcInternal.prx")
with tempfile.TemporaryDirectory(prefix="anyps5-guest-host-libc-") as directory:
work = Path(directory)
needed = convert(relinker, work / "bundled", imports, ["libc.prx", "other.prx"])
assert needed == ["$ORIGIN/app0/sce_module/libc.prx.guest.prx",
"$ORIGIN/app0/sce_module/other.prx.guest.prx",
"libkernel.prx", "libSceLibcInternal.prx", "libc.prx"], needed
needed = convert(relinker, work / "without-internal", ("libkernel.prx", "libc.prx"), ["libc.prx"])
assert needed == ["$ORIGIN/app0/sce_module/libc.prx.guest.prx", "libkernel.prx"], needed
needed = convert(relinker, work / "not-bundled", imports, ["other.prx"])
assert needed == ["$ORIGIN/app0/sce_module/other.prx.guest.prx", *imports], needed
needed = convert(relinker, work / "excluded", imports, ["libc.prx", "other.prx"],
["--exclude-sce-module", "libc.prx"])
assert needed == ["$ORIGIN/app0/sce_module/other.prx.guest.prx", *imports], needed
print("Guest host libc integration tests passed")
if __name__ == "__main__":
main()