rtld: Add missing DT_NEEDED DSOs to needed_list
PATCH 1/1 rtld: Add missing DT_NEEDED DSOs to needed_list
prelink-rtld may report an "error while loading shared libraries" for the wrong library.
If some set of DT_NEEDED DSOs are not in the default search path, they may have a dso_list entry added, but no matching entry is added to the needed_list. This causes the linker to miscalculate the max number of dsos during build_local_scope(), which later causes find_needed() to not search the entire l_local_scope[0]->r_list during _dl_check_map_versions() (since the max from build_local_scope() becomes l_local_scope[0]->r_nlist).
Since find_needed() searches through the r_list, which would have the dso_list entries for the libraries that weren't found earlier, this cuts the search short, meaning libraries near the end of the local scope don't get included in the map version search.
As the comment in _dl_check_map_versions() suggests, if needed is NULL, that means a dependency was not found and no stub entry created, which should never happen.
--- src/rtld/rtld.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-)
src/rtld/rtld.c +22 -14
@@ -686,6 +686,25 @@ find_lib_by_soname (const char *soname, struct dso_list *loader,return NULL ; } +static void +add_dso_to_needed (struct dso_list *cur_dso_ent,struct dso_list *new_dso_ent) +{ +if (!cur_dso_ent->needed) + { + cur_dso_ent->needed =malloc (sizeof (struct needed_list )); + cur_dso_ent->needed_tail = cur_dso_ent->needed; + cur_dso_ent->needed_tail->ent = new_dso_ent; + cur_dso_ent->needed_tail->next =NULL ; + } +else if (!in_needed_list (cur_dso_ent->needed, new_dso_ent->name)) + { + cur_dso_ent->needed_tail->next =malloc (sizeof (struct needed_list )); + cur_dso_ent->needed_tail = cur_dso_ent->needed_tail->next; + cur_dso_ent->needed_tail->ent = new_dso_ent; + cur_dso_ent->needed_tail->next =NULL ; + } +} +static struct dso_list *load_dsos (DSO *dso,int host_paths) {
@@ -812,6 +831,8 @@ load_dsos (DSO *dso, int host_paths) dso_list_tail->canon_filename =strdup (soname); dso_list_tail->err_no = errno; +add_dso_to_needed (cur_dso_ent, new_dso_ent); +continue ; }
@@ -854,20 +875,7 @@ load_dsos (DSO *dso, int host_paths) dso_list_tail->name = new_dso->soname; } -if (!cur_dso_ent->needed) - { - cur_dso_ent->needed =malloc (sizeof (struct needed_list )); - cur_dso_ent->needed_tail = cur_dso_ent->needed; - cur_dso_ent->needed_tail->ent = new_dso_ent; - cur_dso_ent->needed_tail->next =NULL ; - } -else if (!in_needed_list (cur_dso_ent->needed, soname)) - { - cur_dso_ent->needed_tail->next =malloc (sizeof (struct needed_list )); - cur_dso_ent->needed_tail = cur_dso_ent->needed_tail->next; - cur_dso_ent->needed_tail->ent = new_dso_ent; - cur_dso_ent->needed_tail->next =NULL ; - } +add_dso_to_needed (cur_dso_ent, new_dso_ent);continue ; }
Signature · 1 line
2.7.4
Thanks! I'll try to get this included soon.
--Mark
Quoted 87 lines · Kyle Russell
prelink-rtld may report an "error while loading shared libraries" for the wrong library.
If some set of
DT_NEEDEDDSOs are not in the default search path, they may have adso_listentry added, but no matching entry is added to theneeded_list. This causes the linker to miscalculate the max number of dsos duringbuild_local_scope(), which later causesfind_needed()to not search the entire l_local_scope[0]->r_list during_dl_check_map_versions()(since the max frombuild_local_scope()becomes l_local_scope[0]->r_nlist).Since
find_needed()searches through ther_list, which would have thedso_listentries for the libraries that weren't found earlier, this cuts the search short, meaning libraries near the end of the local scope don't get included in the map version search.As the comment in
_dl_check_map_versions()suggests, if needed is NULL, that means a dependency was not found and no stub entry created, which should never happen.Signed-off-by Kyle Russell <[email protected]>--- src/rtld/rtld.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-)src/rtld/rtld.c +22
-14@@ -686,6 +686,25 @@ find_lib_by_soname (const char *soname, struct dso_list *loader,return NULL ; } +static void +add_dso_to_needed (struct dso_list *cur_dso_ent,struct dso_list *new_dso_ent) +{ +if (!cur_dso_ent->needed) + { + cur_dso_ent->needed =malloc (sizeof (struct needed_list )); + cur_dso_ent->needed_tail = cur_dso_ent->needed; + cur_dso_ent->needed_tail->ent = new_dso_ent; + cur_dso_ent->needed_tail->next =NULL ; + } +else if (!in_needed_list (cur_dso_ent->needed, new_dso_ent->name)) + { + cur_dso_ent->needed_tail->next =malloc (sizeof (struct needed_list )); + cur_dso_ent->needed_tail = cur_dso_ent->needed_tail->next; + cur_dso_ent->needed_tail->ent = new_dso_ent; + cur_dso_ent->needed_tail->next =NULL ; + } +} +static struct dso_list *load_dsos (DSO *dso,int host_paths) {@@ -812,6 +831,8 @@ load_dsos (DSO *dso, int host_paths) dso_list_tail->canon_filename =strdup (soname); dso_list_tail->err_no = errno; +add_dso_to_needed (cur_dso_ent, new_dso_ent); +continue ; }@@ -854,20 +875,7 @@ load_dsos (DSO *dso, int host_paths) dso_list_tail->name = new_dso->soname; } -if (!cur_dso_ent->needed) - { - cur_dso_ent->needed =malloc (sizeof (struct needed_list )); - cur_dso_ent->needed_tail = cur_dso_ent->needed; - cur_dso_ent->needed_tail->ent = new_dso_ent; - cur_dso_ent->needed_tail->next =NULL ; - } -else if (!in_needed_list (cur_dso_ent->needed, soname)) - { - cur_dso_ent->needed_tail->next =malloc (sizeof (struct needed_list )); - cur_dso_ent->needed_tail = cur_dso_ent->needed_tail->next; - cur_dso_ent->needed_tail->ent = new_dso_ent; - cur_dso_ent->needed_tail->next =NULL ; - } +add_dso_to_needed (cur_dso_ent, new_dso_ent);continue ; }
Just wanted to follow-up on this so it doesn't get lost. Any chance this could be included in cross_prelink_staging?
Quoted 100 lines · Mark Hatle
Thanks! I'll try to get this included soon.
--Mark
src/rtld/rtld.c find_lib_by_soname (const char *soname, struct
Quoted 30 lines · Kyle Russell
prelink-rtld may report an "error while loading shared libraries" for the wrong library.
If some set of
DT_NEEDEDDSOs are not in the default search path, they may have adso_listentry added, but no matching entry is added to theneeded_list. This causes the linker to miscalculate the max number of dsos duringbuild_local_scope(), which later causesfind_needed()to not search the entire l_local_scope[0]->r_list during_dl_check_map_versions()(since the max frombuild_local_scope()becomes l_local_scope[0]->r_nlist).Since
find_needed()searches through ther_list, which would have thedso_listentries for the libraries that weren't found earlier, this cuts the search short, meaning libraries near the end of the local scope don't get included in the map version search.As the comment in
_dl_check_map_versions()suggests, if needed is NULL, that means a dependency was not found and no stub entry created, which should never happen.Signed-off-by Kyle Russell <[email protected]>--- src/rtld/rtld.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-)src/rtld/rtld.c +0
-0@@ -686,6 +686,25 @@ find_lib_by_soname (const char *soname, struct
dso_list*loader,src/rtld/rtld.c find_lib_by_soname (const char *soname, struct dso_list *loader,
Quoted 5 lines
src/rtld/rtld.c +2
-0return NULL ; } +static void +add_dso_to_needed (struct dso_list *cur_dso_ent, struct dso_list
*new_dso_ent)src/rtld/rtld.c find_lib_by_soname (const char *soname, struct dso_list *loader,
Quoted 11 lines
src/rtld/rtld.c +11
-0+{ +if (!cur_dso_ent->needed) + { + cur_dso_ent->needed =malloc (sizeof (struct needed_list )); + cur_dso_ent->needed_tail = cur_dso_ent->needed; + cur_dso_ent->needed_tail->ent = new_dso_ent; + cur_dso_ent->needed_tail->next =NULL ; + } +else if (!in_needed_list (cur_dso_ent->needed, new_dso_ent->name)) + { + cur_dso_ent->needed_tail->next = malloc (sizeof (struct
needed_list));Quoted 19 lines
src/rtld/rtld.c +8
-0+ cur_dso_ent->needed_tail = cur_dso_ent->needed_tail->next; + cur_dso_ent->needed_tail->ent = new_dso_ent; + cur_dso_ent->needed_tail->next =NULL ; + } +} +static struct dso_list *load_dsos (DSO *dso,int host_paths) {@@ -812,6 +831,8 @@ load_dsos (DSO *dso, int host_paths) dso_list_tail->canon_filename =strdup (soname); dso_list_tail->err_no = errno; +add_dso_to_needed (cur_dso_ent, new_dso_ent); +continue ; }src/rtld/rtld.c load_dsos (DSO *dso, int host_paths) · line 859
Quoted 6 lines
src/rtld/rtld.c +0
-3@@ -854,20 +875,7 @@ load_dsos (DSO *dso, int host_paths) dso_list_tail->name = new_dso->soname; } -if (!cur_dso_ent->needed) - { - cur_dso_ent->needed = malloc (sizeof (struct
needed_list));src/rtld/rtld.c load_dsos (DSO *dso, int host_paths)
Quoted 7 lines
src/rtld/rtld.c +0
-7- cur_dso_ent->needed_tail = cur_dso_ent->needed; - cur_dso_ent->needed_tail->ent = new_dso_ent; - cur_dso_ent->needed_tail->next =NULL ; - } -else if (!in_needed_list (cur_dso_ent->needed, soname)) - { - cur_dso_ent->needed_tail->next = malloc (sizeof(struct
needed_list));src/rtld/rtld.c load_dsos (DSO *dso, int host_paths) · line 867
Quoted 1 line
src/rtld/rtld.c +0
-1- cur_dso_ent->needed_tail = cur_dso_ent->needed_tail->next;
Quoted 8 lines
src/rtld/rtld.c +1
-3- cur_dso_ent->needed_tail->ent = new_dso_ent; - cur_dso_ent->needed_tail->next =NULL ; - } +add_dso_to_needed (cur_dso_ent, new_dso_ent);continue ; }
Quoted 2 lines · Kyle Russell
Just wanted to follow-up on this so it doesn't get lost. Any chance this could be included in
cross_prelink_staging?
I just finished the sanity checking on it. It should be in staging in a few minutes.
(There are a couple of x32 patches as well, however I'm currently not able to test those. Something is wrong when the master x32 that there are missing headers -- and even when that is resolved the testsuite doesn't appear to properly find the ld.so and such.)
--Mark
Quoted 102 lines
On Thu, Aug 25, 2016 at 1:03 PM, Mark Hatle <[email protected] <mailto:[email protected]>> wrote:
Thanks! I'll try to get this included soon. --Mark On 8/25/16 10:39 AM, Kyle Russell wrote: > prelink-rtld may report an "error while loading shared libraries" for > the wrong library. > > If some set of DT_NEEDED DSOs are not in the default search path, they > may have a dso_list entry added, but no matching entry is added to the > needed_list. This causes the linker to miscalculate the max number of > dsos during build_local_scope(), which later causes find_needed() to not > search the entire l_local_scope[0]->r_list during > _dl_check_map_versions() (since the max from build_local_scope() becomes > l_local_scope[0]->r_nlist). > > Since find_needed() searches through the r_list, which would have the > dso_list entries for the libraries that weren't found earlier, this cuts > the search short, meaning libraries near the end of the local scope don't > get included in the map version search. > > As the comment in _dl_check_map_versions() suggests, if needed is NULL, > that means a dependency was not found and no stub entry created, which > should never happen. > > Signed-off-by: Kyle Russell <[email protected] <mailto:[email protected]>> > --- > src/rtld/rtld.c | 36 ++++++++++++++++++++++-------------- > 1 file changed, 22 insertions(+), 14 deletions(-) > > diff --git a/src/rtld/rtld.c b/src/rtld/rtld.c > index 8d7d760..d9a0862 100644 > --- a/src/rtld/rtld.c > +++ b/src/rtld/rtld.c > @@ -686,6 +686,25 @@ find_lib_by_soname (const char *soname, struct dso_list *loader, > return NULL; > } > > +static void > +add_dso_to_needed (struct dso_list *cur_dso_ent, struct dso_list *new_dso_ent) > +{ > + if (!cur_dso_ent->needed) > + { > + cur_dso_ent->needed = malloc (sizeof (struct needed_list)); > + cur_dso_ent->needed_tail = cur_dso_ent->needed; > + cur_dso_ent->needed_tail->ent = new_dso_ent; > + cur_dso_ent->needed_tail->next = NULL; > + } > + else if (!in_needed_list (cur_dso_ent->needed, new_dso_ent->name)) > + { > + cur_dso_ent->needed_tail->next = malloc (sizeof (struct needed_list)); > + cur_dso_ent->needed_tail = cur_dso_ent->needed_tail->next; > + cur_dso_ent->needed_tail->ent = new_dso_ent; > + cur_dso_ent->needed_tail->next = NULL; > + } > +} > + > static struct dso_list * > load_dsos (DSO *dso, int host_paths) > { > @@ -812,6 +831,8 @@ load_dsos (DSO *dso, int host_paths) > dso_list_tail->canon_filename = strdup(soname); > dso_list_tail->err_no = errno; > > + add_dso_to_needed(cur_dso_ent, new_dso_ent); > + > continue; > } > > @@ -854,20 +875,7 @@ load_dsos (DSO *dso, int host_paths) > dso_list_tail->name = new_dso->soname; > } > > - if (!cur_dso_ent->needed) > - { > - cur_dso_ent->needed = malloc (sizeof (struct needed_list)); > - cur_dso_ent->needed_tail = cur_dso_ent->needed; > - cur_dso_ent->needed_tail->ent = new_dso_ent; > - cur_dso_ent->needed_tail->next = NULL; > - } > - else if (!in_needed_list (cur_dso_ent->needed, soname)) > - { > - cur_dso_ent->needed_tail->next = malloc (sizeof (struct needed_list)); > - cur_dso_ent->needed_tail = cur_dso_ent->needed_tail->next; > - cur_dso_ent->needed_tail->ent = new_dso_ent; > - cur_dso_ent->needed_tail->next = NULL; > - } > + add_dso_to_needed(cur_dso_ent, new_dso_ent); > > continue; > } >