Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions core/relinker/relinker/src/guest/GuestModuleBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ std::vector<GuestArtifact> GuestModuleBuilder::Build(const std::filesystem::path
}
if (needed != 1) rejectSharedImport(base, Io::Utf8Path(inputPath));
const auto found = exports.find(name);
if (!windows && found != exports.end()) {
const auto declared = windows || executableModules[offset / 24].empty() ? guestNames.end() : findGuest(executableModules[offset / 24]);
if (!windows && found != exports.end() && (declared == guestNames.end() || std::any_of(found->second.begin(), found->second.end(), [&](const auto& candidate) { return candidate.Provider == declared->second; }))) {
rename(dynamic.DynSymData, dynamic.DynStrData, offset / 24, name);
if (executableReferences[offset / 24] && found->second.size() == 1) executableProviders.insert(found->second.front().Provider);
}
Expand Down Expand Up @@ -327,11 +328,12 @@ std::vector<GuestArtifact> GuestModuleBuilder::Build(const std::filesystem::path
};
if (!windows) {
const auto executableExports = macos ? std::set<std::string>{} : ExportedNames(dynamic);
for (auto& image : images) {
for (std::size_t module = 0; module < images.size(); ++module) {
auto& image = images[module];
for (std::size_t index = 1; index < image.Symbols.size(); ++index) {
const auto& symbol = image.Symbols[index];
const bool exported = symbol.Section != 0 && (symbol.Info >> 4) != 0 && symbol.Visibility != 1 && symbol.Visibility != 2;
if (((symbol.Section == 0 && !declaresHost(symbol.Library)) || exported) && exports.contains(symbol.Name)) rename(image.Dynamic.DynSymData, image.Dynamic.DynStrData, index, symbol.Name);
if (((symbol.Section == 0 && !declaresHost(symbol.Library) && !systemImports[module].contains(index)) || exported) && exports.contains(symbol.Name)) rename(image.Dynamic.DynSymData, image.Dynamic.DynStrData, index, symbol.Name);
}
if (!macos) BindNamedImportsByNid(image, executableExports);
}
Expand Down
15 changes: 15 additions & 0 deletions core/relinker/relinker/tests/test_guest_symbol_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,21 @@ def main():
}).parent / "app0" / "sce_module"
importer = module_symbols((guests / "c.prx.guest.prx").read_bytes())
assert "shared#guest" in importer, importer

for exported, expected, unexpected in (("entry", "entry#guest", "entry"), ("other", "entry", "entry#guest")):
guests = relink(relinker, work / f"guest-declared-missing-{exported}", importing_executable([]), {
"provider.prx": guest_module([(exported, True)]),
"third.prx": guest_module([("entry", True)]),
"consumer.prx": needed_module_import("ZZZZZZZZZZZ", "entry#A#B", "provider.prx", (0x61000045,)),
}).parent / "app0" / "sce_module"
importer = module_symbols((guests / "consumer.prx.guest.prx").read_bytes())
assert expected in importer and unexpected not in importer, (exported, importer)
output = relink(relinker, work / f"executable-declared-missing-{exported}", importing_executable(["entry#B#B"], ["provider"]), {
"provider.prx": guest_module([(exported, True)]),
"third.prx": guest_module([("entry", True)]),
})
imports = imported_symbols(output.read_bytes())
assert imports == {expected}, (exported, imports)
print("Guest symbol name tests passed")


Expand Down
Loading