[dlfcn] Resolve libraries in dependency order (#2128)#6
Draft
esaurez wants to merge 1 commit into
Draft
Conversation
320bbc8 to
1b171ce
Compare
1677feb to
0b657d1
Compare
22f7ba4 to
17e93ab
Compare
Replace arbitrary-order relocation resolution with a topological sort that resolves dependencies before their dependents (leaves first, root last). This ensures that when a library's relocations reference symbols from its dependencies, those dependencies are already fully resolved. Changes: - resolve_all_symbols(): topological sort over new handles. - dependency_handles(): new method on DynamicLibrary. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
17e93ab to
01a51f4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace arbitrary-order relocation resolution with a topological sort that resolves dependencies before their dependents (leaves first, root last).
Fixes nanvix#2128. Depends on #3 (atomic registry rollback).
Problem
resolve_all_symbols()resolved libraries in arbitraryBTreeMaphandle order (sorted by file descriptor number). If a root library was resolved before its dependencies, and those dependencies had their own relocations that needed patching, the resolution could fail.Expected Behavior (Linux/musl Reference)
Dynamic linkers resolve dependencies before their dependents:
elf/dl-deps.c(_dl_map_object_deps). Leaf dependencies appear earlier and are relocated first inelf/dl-open.c.dlopeninldso/dynlink.cresolves dependencies before their dependents during relocation.Fix
dlopencall) have been resolved.dependency_handles()method toDynamicLibrary.Affected Files
src/libs/syscall/src/dlfcn/syscall/dlopen.rs— topo-sortresolve_all_symbols()src/libs/syscall/src/dlfcn/syscall/dynlib.rs—dependency_handles()Testing
All existing integration tests pass (both HTTP and terminal executors).