This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH v3 3/3] elf: avoid stack allocation in dl_open_worker
- From: David Kilroy <David dot Kilroy at arm dot com>
- To: "libc-alpha at sourceware dot org" <libc-alpha at sourceware dot org>
- Cc: nd <nd at arm dot com>
- Date: Tue, 3 Dec 2019 17:30:11 +0000
- Subject: [PATCH v3 3/3] elf: avoid stack allocation in dl_open_worker
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=F2xr7vPj26LCgS8MuKGYrADsk0rWP02s/9tbwORzgRU=; b=TDqoTnXJaw+MvrtS8dd6zmuUGvMELLsLZhzhOCh+HGn0SScstKRkYSTJTqDYVPP/n+Bx6mMX/dVpmkox5es7tdSUZwmdfZMCXTCHE7ObtUzM9AVWhdeVXFdMB+zUSF9KTyw6/z7DJyPoKVdCbOGDaXxmPoavU8Gm2KBQSwJtqIzsi2Y3+1xP+aLrAY/MHgt96+nbuaQIZeGPG4AHUMA8S155vFzWi4SFnOUtwTODongc1aB8+XOK+iyAKlVSiYcvWtJPon9Sk9wrOOHSB7kIAVVg1JaNUIhFC+F9ZdE71c1SuqElhQFFuUR2Txy7VTvxUhefdU8sILGEI+q2iDvS8g==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dby4fmdS7ohvyedsRXloGPI16SlQabrOnn0W7Kt/2oYeWuXEMFv5AVD153lZLtAFHcC/5w235rGo7DawgiER6vzSyxdHHfs1mBRKpebOptFdHxs4YkpUVEZ+qoA+h39bYz92hXDd59HUl0NF0l2+VlNIVVsOss/HrvgNf5TVpQLd80COXCCQuWgKYrpxVFko52XA2FwxUh95OOfT1D2Y8wxPHpu0C9udFd6MiHx0F3t6OxHuQ07kyb8s0JGm8sVNaGSyki7QlRsCX2PowvjPKomfjKJxLohSBmOANumbU5soj23lKV+bDOOMMdmDhP3jEjk7jJGgZy6TjIjm5zYKHw==
- Original-authentication-results: spf=none (sender IP is ) smtp.mailfrom=David dot Kilroy at arm dot com;
- References: <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