public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: David Kilroy <David.Kilroy@arm.com>
To: Florian Weimer <fweimer@redhat.com>
Cc: "libc-alpha@sourceware.org" <libc-alpha@sourceware.org>, nd <nd@arm.com>
Subject: RE: [PATCH 1/3] elf: Allow dlopen of filter object to work [BZ #16272]
Date: Tue, 22 Oct 2019 14:29:00 -0000	[thread overview]
Message-ID: <AM0PR08MB406890CE7E5DCA9FE07AEBB891680@AM0PR08MB4068.eurprd08.prod.outlook.com> (raw)
In-Reply-To: <87r23ath25.fsf@oldenburg2.str.redhat.com>


> Florian Weimer
> 
> * David Kilroy:
> 
> > diff --git a/elf/dl-open.c b/elf/dl-open.c index a9fd4cb..7fcfdc0
> > 100644
> > --- a/elf/dl-open.c
> > +++ b/elf/dl-open.c
> > @@ -305,22 +305,25 @@ dl_open_worker (void *a)
> >       allows IFUNC relocations to work and it also means copy
> >       relocation of dependencies are if necessary overwritten.  */
> >    unsigned int nmaps = 0;
> > -  struct link_map *l = new;
> > +  unsigned int j = 0;
> > +  struct link_map *l =  new->l_initfini[0];
> >    do
> >      {
> >        if (! l->l_real->l_relocated)
> >  	++nmaps;
> > -      l = l->l_next;
> > +      l = new->l_initfini[++j];
> >      }
> >    while (l != NULL);
> > +  /* Stack allocation is limited by the number of loaded objects.
> */
> >    struct link_map *maps[nmaps];
> >    nmaps = 0;
> > -  l = new;
> > +  j = 0;
> > +  l = new->l_initfini[0];
> >    do
> >      {
> >        if (! l->l_real->l_relocated)
> >  	maps[nmaps++] = l;
> > -      l = l->l_next;
> > +      l = new->l_initfini[++j];
> >      }
> >    while (l != NULL);
> >    _dl_sort_maps (maps, nmaps, NULL, false);
> 
> I have much more trouble ascertaining whether this change is correct.
> Are we certain that new->l_initfini is not a subset of the maps that
> have been loaded?

I've tried to double check this. Having not seen this code until recently, I
may have some of the details wrong but I've to summarized what I think is
the case below.

In short, as far as I can tell all the libraries in the l_next list also exist
in l_initfini.

If anyone knows otherwise, I'd appreciate a pointer.



Regards,

Dave.

In dl_open_worker the field new->l_next is populated by _dl_map_object_from_fd
(via _dl_map_object), where it calls _dl_add_to_namespace_list. Every loaded
object should be added to the global list.

New->l_initfini is populated in _dl_object_map_deps()

* The list `known` is populated with the binary, followed by preloads

** note: for the call from dlopen_worker, preloads is set to NULL

* dependencies are added to `known`

** each dependency is opened (via openaux and _dl_map_object), so the l_next
   list contains all new dependencies.

** each dependency gets its own map->l_initfini populated

* If the object is an aux or filter object

** the filtee is inserted before the filter in `known`.

** the l_next list is modified to put the filtee before the filter

* l_initfini for the main binary is then redone (even if previously loaded)

** It gets each library in `known`, excluding those with l_faked set
   (library not found in trace mode)

*** l_faked is only set to 1 in dl-load.c:_dl_map_object:2194

** l_initfini is sorted. Note that the sort keeps the main object at the
   head of l_initfini, unlike the sort in _dl_open_worker

  parent reply	other threads:[~2019-10-22 14:29 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 10:33 [PATCH 0/3] " David Kilroy
2019-10-17 10:33 ` [PATCH 1/3] " David Kilroy
2019-10-18 11:43   ` Florian Weimer
2019-10-18 15:09     ` David Kilroy
2019-10-21 11:27       ` Florian Weimer
2019-10-21 14:12         ` David Kilroy
2019-10-21 14:21           ` Florian Weimer
2019-10-21 16:42             ` Szabolcs Nagy
2019-10-22  9:22               ` David Kilroy
2019-10-22  9:49                 ` Florian Weimer
2019-10-22 11:20                   ` David Kilroy
2019-10-22  9:43               ` Florian Weimer
2019-10-22 11:18                 ` David Kilroy
2019-10-22 11:22                   ` Florian Weimer
2019-10-22 11:27                     ` David Kilroy
2019-10-22 11:31                       ` Florian Weimer
2019-10-22  8:28             ` David Kilroy
2019-10-22  8:36               ` Florian Weimer
2019-10-22  9:39                 ` David Kilroy
2019-10-22  9:57                   ` Florian Weimer
2019-10-22 11:24                     ` David Kilroy
2019-10-22 14:29     ` David Kilroy [this message]
2019-10-17 10:33 ` [PATCH 3/3] elf: avoid stack allocation in dl_open_worker David Kilroy
2019-10-17 10:33 ` [PATCH 2/3] elf: avoid redundant sort in dlopen David Kilroy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM0PR08MB406890CE7E5DCA9FE07AEBB891680@AM0PR08MB4068.eurprd08.prod.outlook.com \
    --to=david.kilroy@arm.com \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=nd@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).