OSDN Git Service

fix and overhaul dlsym depedency order, always record direct deps
authorRich Felker <dalias@aerifal.cx>
Tue, 26 Feb 2019 23:05:19 +0000 (18:05 -0500)
committerRich Felker <dalias@aerifal.cx>
Wed, 27 Feb 2019 21:05:37 +0000 (16:05 -0500)
commit403555690775f7c8806372644f543518e6664e3b
treeb911790c70b968e61981355dd77d18eb8d794778
parent71db5dfaa9ddcb65e18ff128c9ed122790d72e2f
fix and overhaul dlsym depedency order, always record direct deps

dlsym with an explicit handle is specified to use "dependency order",
a breadth-first search rooted at the argument. this has always been
implemented by iterating a flattened dependency list built at dlopen
time. however, the logic for building this list was completely wrong
except in trivial cases; it simply used the list of libraries loaded
since a given library, and their direct dependencies, as that
library's dependencies, which could result in misordering, wrongful
omission of deep dependencies from the search, and wrongful inclusion
of unrelated libraries in the search.

further, libraries did not have any recorded list of resolved
dependencies until they were explicitly dlopened, meaning that
DT_NEEDED entries had to be resolved again whenever a library
participated as a dependency of more than one dlopened library.

with this overhaul, the resolved direct dependency list of each
library is always recorded when it is first loaded, and can be
extended to a full flattened breadth-first search list if dlopen is
called on the library. the extension is performed using the direct
dependency list as a queue and appending copies of the direct
dependency list of each dependency in the queue, excluding duplicates,
until the end of the queue is reached. the direct deps remain
available for future use as the initial subarray of the full deps
array.

first-load logic in dlopen is updated to match these changes, and
clarified.
ldso/dynlink.c