public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: David Kilroy <David.Kilroy@arm.com>
To: "libc-alpha@sourceware.org" <libc-alpha@sourceware.org>
Cc: nd <nd@arm.com>
Subject: [PATCH v3 3/3] elf: avoid stack allocation in dl_open_worker
Date: Tue, 03 Dec 2019 17:30:00 -0000	[thread overview]
Message-ID: <1575394197-18006-4-git-send-email-david.kilroy@arm.com> (raw)
In-Reply-To: <1575394197-18006-1-git-send-email-david.kilroy@arm.com>

As the sort was removed, there's no need to keep a separate map of
links. Instead, when relocating objects iterate over l_initfini
directly.

This allows us to remove the loop copying l_initfini elements into
map. We still need a loop to identify the first and last elements that
need relocation.

Tested by running the testsuite on x86_64.
---
 elf/dl-open.c | 28 ++++++++++++----------------
 1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/elf/dl-open.c b/elf/dl-open.c
index c4d09c7c..eb36a91 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -636,25 +636,18 @@ dl_open_worker (void *a)
   /* Sort the objects by dependency for the relocation process.  This
      allows IFUNC relocations to work and it also means copy
      relocation of dependencies are if necessary overwritten.  */
-  unsigned int nmaps = 0;
+  unsigned int first = UINT_MAX;
+  unsigned int last = 0;
   unsigned int j = 0;
   struct link_map *l = new->l_initfini[0];
   do
     {
       if (! l->l_real->l_relocated)
-	++nmaps;
-      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;
-  j = 0;
-  l = new->l_initfini[0];
-  do
-    {
-      if (! l->l_real->l_relocated)
-	maps[nmaps++] = l;
+	{
+	  if (first == UINT_MAX)
+	    first = j;
+	  last = j + 1;
+	}
       l = new->l_initfini[++j];
     }
   while (l != NULL);
@@ -669,9 +662,12 @@ dl_open_worker (void *a)
      them.  However, such relocation dependencies in IFUNC resolvers
      are undefined anyway, so this is not a problem.  */
 
-  for (unsigned int i = nmaps; i-- > 0; )
+  for (unsigned int i = last; i-- > first; )
     {
-      l = maps[i];
+      l = new->l_initfini[i];
+
+      if (l->l_real->l_relocated)
+	continue;
 
       if (! relocation_in_progress)
 	{
-- 
2.7.4

  reply	other threads:[~2019-12-03 17:30 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-03 17:30 [PATCH v3 0/3] elf: Allow dlopen of filter object to work [BZ #16272] David Kilroy
2019-12-03 17:30 ` David Kilroy [this message]
2020-01-14 20:04   ` [PATCH v3 3/3] elf: avoid stack allocation in dl_open_worker Adhemerval Zanella
2019-12-03 17:30 ` [PATCH v3 1/3] elf: Allow dlopen of filter object to work [BZ #16272] David Kilroy
2020-01-14 18:31   ` Adhemerval Zanella
2020-01-15 12:37     ` David Kilroy
2020-01-17 14:04       ` Adhemerval Zanella
2020-01-17 17:00     ` David Kilroy
2020-01-21 16:34       ` David Kilroy
2020-01-22 20:39         ` Adhemerval Zanella
2019-12-03 17:30 ` [PATCH v3 2/3] elf: avoid redundant sort in dlopen David Kilroy
2020-01-14 19:42   ` Adhemerval Zanella
2019-12-18 16:32 ` [PATCH v3 0/3] elf: Allow dlopen of filter object to work [BZ #16272] David Kilroy
2019-12-18 19:33   ` Adhemerval Zanella
2019-12-19 11:43     ` 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=1575394197-18006-4-git-send-email-david.kilroy@arm.com \
    --to=david.kilroy@arm.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).