mirror of
https://github.com/boykopovar/AnyPS5.git
synced 2026-10-10 01:28:44 +02:00
Merge pull request #1454 from mrk1987/fix/windows-internal-guest-libc
fix(relinker): resolve internal libc imports from guest libc
This commit is contained in:
@@ -105,6 +105,13 @@ WindowsEntryStub WindowsEntryStubBuilder::Build(const std::uint32_t dataRva, con
|
||||
for (std::size_t index = guestModules.size(); index < libraries.size(); ++index) {
|
||||
if (libraries[index] == "libc.prx" && import.Library != "libc.prx") order.push_back(CheckedRva(index));
|
||||
}
|
||||
if (import.Library == "libSceLibcInternal.prx") {
|
||||
for (std::size_t index = 0; index < guestModules.size(); ++index) {
|
||||
const auto& names = guestModules[index].Names;
|
||||
if (std::find(names.begin(), names.end(), "libc.prx") != names.end())
|
||||
order.push_back(CheckedRva(index));
|
||||
}
|
||||
}
|
||||
}
|
||||
Io::AlignBuffer(data, 4);
|
||||
platformTlsResolvers.push_back(std::none_of(order.begin(), order.end(), [&](auto index) {
|
||||
|
||||
@@ -31,6 +31,38 @@ def provider(value, soname=None):
|
||||
return image
|
||||
|
||||
|
||||
def check_internal_guest_libc(convert, work, relinker):
|
||||
result, dummy = convert('empty-native-provider', 'c.prx')
|
||||
assert result.returncode == 0, result.stderr
|
||||
result, shared = convert('shared-native-provider', 'a.prx')
|
||||
assert result.returncode == 0, result.stderr
|
||||
empty_provider = dummy.parent / 'app0' / 'prx' / 'c.prx.guest.prx'
|
||||
shared_provider = shared.parent / 'app0' / 'prx' / 'a.prx.guest.prx'
|
||||
for name, native_owner, symbol, expected in (
|
||||
('guest-only', None, 'shared#A#B', 22),
|
||||
('internal-first', 'libSceLibcInternal.prx', 'shared#A#B', 11),
|
||||
('native-libc-first', 'libc.prx', 'shared#A#B', 11),
|
||||
('unresolved', None, 'absent#A#B', None)):
|
||||
case = work / ('internal-guest-libc-' + name)
|
||||
(case / 'sce_module').mkdir(parents=True)
|
||||
(case / 'sce_module' / 'libc.prx').write_bytes(provider(22))
|
||||
source = case / 'input.elf'
|
||||
source.write_bytes(executable('libSceLibcInternal.prx', symbol, extra_dependencies=('libc.prx',)))
|
||||
output = case / 'output.exe'
|
||||
result = subprocess.run([str(relinker), '--windows', str(source), str(output)], capture_output=True, text=True, timeout=30)
|
||||
assert result.returncode == 0, result.stderr
|
||||
(case / 'libs').mkdir()
|
||||
for owner in ('libSceLibcInternal.prx', 'libc.prx'):
|
||||
selected = shared_provider if owner == native_owner else empty_provider
|
||||
(case / 'libs' / owner).write_bytes(selected.read_bytes())
|
||||
if os.name == 'nt':
|
||||
run = subprocess.run([str(output)], capture_output=True, text=True, timeout=30)
|
||||
if expected is None:
|
||||
assert run.returncode != 0 and 'unresolved ELF import absent' in run.stderr, (run.returncode, run.stdout, run.stderr)
|
||||
else:
|
||||
assert run.returncode == expected, (run.returncode, run.stdout, run.stderr)
|
||||
|
||||
|
||||
def consumer(owner, symbol='shared#A#B', expected=22, module_name=None):
|
||||
image = module_with_symbol(False)
|
||||
strings = b'\0' + symbol.encode() + b'\0' + owner.encode() + b'\0'
|
||||
@@ -170,6 +202,8 @@ def main():
|
||||
run = subprocess.run([str(output)], capture_output=True, text=True, timeout=30)
|
||||
assert run.returncode == (11 if owner == 'a.prx' else 22), (run.returncode, run.stdout, run.stderr)
|
||||
|
||||
check_internal_guest_libc(convert, work, relinker)
|
||||
|
||||
for filename, module_name in [('foo.native.prx', 'foo_native'),
|
||||
('libSceFont-module.prx', 'libSceFont')]:
|
||||
result, output = convert(module_name, filename, guest_owner=filename,
|
||||
|
||||
Reference in New Issue
Block a user