This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH v2 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: Thu, 24 Oct 2019 10:33:49 +0000
- Subject: [PATCH v2 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=WMTkBoYEhkhRi0yTpvSxbOOZ2mX4u+C1BBTPaiyXT/0=; b=R4ZF1vzK4kl+yGRB/m/AGWznK70tcZNkui1wfMbxPnD9w8n5KTW9iEE8VoWREblyx9ndf1DclebqMbBuX2hcptL/k2qD/bjh1jWeXYGbOMdtGI6/SFLdYDARr60Zyl7QMJr+03WLDSRb+xza9RJwq6ekSThqPpAMsgofsgk27WdsN35jAQL/z0LcWnpqqn6uALF4FJINaW5J5YVbzIqTXlIrfVA/Fvc938Yeq2BDgNWCeJtYqII56ljPVT7Etggl+dcbpXKg6/qFMzxhOt+uVmOOfxCof7JG0dOewiK+gizsK1pNxBiYDc+8cz+9uVoLwMVxlCmtsORhKk12+Mr6dA==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nMZe91++sg+f615qUHDh8Py9TqPuIyVlaszAf8UV7cPoGOreBvPhteilO3uopzjA6nKFF8gW/lTdkZerJNhL/TT0Sa5yyavsoGVHy921Sd2X1+GtcjWBNYNrU73W0sDUe4lcBPwBQiTreyxKnsjQN65FSBDbNtlb7DCKwP2swOiZBBekIq2EmYR7AyyHK4lf/Q89lW/QQXExBD+qVYK6g06hBaGKHu2v3cpbBPtuGxa8R/m/1boRA4+B0y/XuaqlCNrWPVaba7qrerATHRyYg8GPOOgIKPpFoqDVso6/KlO0UB4T2kzYl7bgfZ/gx2JFKCsafzSbgkHePcPzMpg/3g==
- Original-authentication-results: spf=none (sender IP is ) smtp.mailfrom=David dot Kilroy at arm dot com;
- References: <cover.1571755115.git.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 4df2e3f..4826e25 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -304,34 +304,30 @@ 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);
int relocation_in_progress = 0;
- 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