summaryrefslogtreecommitdiff
path: root/libc/misc/elf/dl-support.c
diff options
context:
space:
mode:
authorGeorg Kotheimer <georg.kotheimer@kernkonzept.com>2025-03-03 16:41:13 +0100
committerWaldemar Brodkorb <wbx@openadk.org>2025-03-04 07:43:56 +0100
commit227b7c825b6c79479f7222be03e83991b927da26 (patch)
tree3e731e65d7dc915ee292d7694514cc254a02714a /libc/misc/elf/dl-support.c
parentd2739d1cd3c6b89f0f4e3b36d2d9b47d5b79e311 (diff)
Make getauxval work with static linking
While for dynamic linking the _dl_auxvt array is provided in dl-startup.c as part of the ldso, is was undefined for statically linked binaries. This resulted in a corresponding linker error if a statically linked program used getauxval. To provide _dl_auxvt also for statically linked binaries, a definition of _dl_auxvt is added to dl-support.c and initialized by _dl_aux_init(). Signed-off-by: Marcus Haehnel <marcus.haehnel@kernkonzept.com>
Diffstat (limited to 'libc/misc/elf/dl-support.c')
-rw-r--r--libc/misc/elf/dl-support.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/libc/misc/elf/dl-support.c b/libc/misc/elf/dl-support.c
index 87cd1bb72..81c78fa55 100644
--- a/libc/misc/elf/dl-support.c
+++ b/libc/misc/elf/dl-support.c
@@ -12,6 +12,7 @@
*/
#include <link.h>
+#include <ldso.h>
#include <elf.h>
#if defined(USE_TLS) && USE_TLS
#include <assert.h>
@@ -31,17 +32,26 @@ ElfW(Phdr) *_dl_phdr;
size_t _dl_phnum;
size_t _dl_pagesize;
+ElfW(auxv_t) _dl_auxvt[AUX_MAX_AT_ID];
+
void internal_function _dl_aux_init (ElfW(auxv_t) *av);
void internal_function _dl_aux_init (ElfW(auxv_t) *av)
{
+ memset(_dl_auxvt, 0x00, sizeof(_dl_auxvt));
+ for (; av->a_type != AT_NULL; av++)
+ {
+ if (av->a_type < AUX_MAX_AT_ID)
+ _dl_auxvt[av->a_type] = *av;
+ }
+
/* Get the program headers base address from the aux vect */
- _dl_phdr = (ElfW(Phdr) *) av[AT_PHDR].a_un.a_val;
+ _dl_phdr = (ElfW(Phdr) *) _dl_auxvt[AT_PHDR].a_un.a_val;
/* Get the number of program headers from the aux vect */
- _dl_phnum = (size_t) av[AT_PHNUM].a_un.a_val;
+ _dl_phnum = (size_t) _dl_auxvt[AT_PHNUM].a_un.a_val;
/* Get the pagesize from the aux vect */
- _dl_pagesize = (av[AT_PAGESZ].a_un.a_val) ? (size_t) av[AT_PAGESZ].a_un.a_val : PAGE_SIZE;
+ _dl_pagesize = (_dl_auxvt[AT_PAGESZ].a_un.a_val) ? (size_t) _dl_auxvt[AT_PAGESZ].a_un.a_val : PAGE_SIZE;
}
#if defined(USE_TLS) && USE_TLS