diff --git a/core/relinker/main.cpp b/core/relinker/main.cpp index 6b967356a536..1f143afb7faa 100644 --- a/core/relinker/main.cpp +++ b/core/relinker/main.cpp @@ -290,6 +290,7 @@ int Run(const int argc, char* argv[]) { for (const auto& executable : executables) outputPaths.push_back(Io::NativePath(executable.OutputPath)); for (const auto& artifact : guestArtifacts) outputPaths.push_back(artifact.Path); outputPaths.insert(outputPaths.end(), registryPaths.begin(), registryPaths.end()); + outputPaths.insert(outputPaths.end(), neededPaths.begin(), neededPaths.end()); if (desktopEntry) { outputPaths.push_back(desktopEntry->IconPath); outputPaths.push_back(desktopEntry->EntryPath); diff --git a/core/relinker/relinker/tests/test_output_collisions.py b/core/relinker/relinker/tests/test_output_collisions.py index 2026412310a5..16466abcbecc 100644 --- a/core/relinker/relinker/tests/test_output_collisions.py +++ b/core/relinker/relinker/tests/test_output_collisions.py @@ -25,6 +25,8 @@ def prepare(case, windows): "module": case / "app0/sce_module/sample.prx.guest.prx", "registry": case / "output.registry.json", "module-registry": case / "output.sample.prx.guest.prx.registry.json", + "needed": case / "output.needed.json", + "module-needed": case / "output.sample.prx.guest.prx.needed.json", } if windows: paths["diagnostics"] = case / "windows-diagnostics-imports.txt" @@ -53,6 +55,34 @@ def main(): checked = 0 with tempfile.TemporaryDirectory(prefix="anyps5-output-collisions-") as directory: work = Path(directory) + for windows, existing in itertools.product((False, True), repeat=2): + case = work / f"needed-secondary-{windows}-{existing}" + case.mkdir() + source = case / "input.elf" + secondary = case / "output.needed" + source.write_bytes(main_fixture()) + secondary.write_bytes(main_fixture()) + module = case / "sce_module/sample.prx" + module.parent.mkdir() + module.write_bytes(guest_fixture(PLAIN_SITE)) + outputs = [case / name for name in ("output.json", "output.needed.json", "output.registry.json", + "output.needed.registry.json", "output.needed.needed.json", + "app0/sce_module/sample.prx.guest.prx", + "output.sample.prx.guest.prx.registry.json", + "output.sample.prx.guest.prx.needed.json")] + if existing: + for path in outputs: + path.parent.mkdir(parents=True, exist_ok=True) + path.write_bytes(b"previous output") + result = subprocess.run([str(relinker), *(["--windows"] if windows else []), "--registry", + "--executable", secondary.name, str(source), str(outputs[0])], cwd=case, + capture_output=True, text=True, timeout=20) + assert result.returncode == 2 and "Output paths collide" in result.stderr, ( + windows, existing, result.returncode, result.stdout, result.stderr) + for path in outputs: + assert path.read_bytes() == b"previous output" if existing else not path.exists(), path + assert source.read_bytes() == secondary.read_bytes() == main_fixture() + assert module.read_bytes() == guest_fixture(PLAIN_SITE) for windows in (False, True): command, paths, inputs = prepare(work / f"{windows}-control", windows) links = paths["executable"].parent / "separate-links" @@ -65,7 +95,7 @@ def main(): assert result.returncode == 0, (result.stdout, result.stderr) for name in ("executable", "module"): assert paths[name].read_bytes().startswith(b"MZ" if windows else b"\x7fELF") - for name in ("registry", "module-registry"): + for name in ("registry", "module-registry", "needed", "module-needed"): json.loads(paths[name].read_text()) for path, original in inputs.items(): assert path.read_bytes() == original diff --git a/core/relinker/relinker/tests/test_secondary_output_collisions.py b/core/relinker/relinker/tests/test_secondary_output_collisions.py index a0db558788b8..070536466c34 100644 --- a/core/relinker/relinker/tests/test_secondary_output_collisions.py +++ b/core/relinker/relinker/tests/test_secondary_output_collisions.py @@ -20,6 +20,7 @@ def prepare_secondary(case, windows): options.extend(["--executable", source.name]) paths[name] = case / f"{source.name}{paths['executable'].suffix}" paths[f"{name}-registry"] = case / f"{source.name}.registry.json" + paths[f"{name}-needed"] = case / f"{source.name}.needed.json" if not windows: icon = case / "sce_sys/icon0.png" inputs[icon] = icon.read_bytes() @@ -46,7 +47,7 @@ def main(): for name in ("executable", "module", *sorted(secondary)): assert paths[name].read_bytes().startswith(b"MZ" if windows else b"\x7fELF"), paths[name] for name, path in paths.items(): - if "registry" in name: + if "registry" in name or "needed" in name: json.loads(path.read_text()) for path, original in inputs.items(): assert path.read_bytes() == original, path