mirror of
git://sourceware.org/git/glibc.git
synced 2026-09-09 23:58:37 +08:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
04cfa0c448 | ||
|
|
671e2f493e | ||
|
|
3e12f8fc7e | ||
|
|
d6afb31c72 |
+68
-22
@@ -157,16 +157,9 @@ static void dl_main_state_init (struct dl_main_state *state);
|
||||
extern char **_environ attribute_hidden;
|
||||
static void process_envvars (struct dl_main_state *state);
|
||||
|
||||
#ifdef DL_ARGV_NOT_RELRO
|
||||
int _dl_argc attribute_hidden;
|
||||
char **_dl_argv = NULL;
|
||||
/* Nonzero if we were run directly. */
|
||||
unsigned int _dl_skip_args attribute_hidden;
|
||||
#else
|
||||
int _dl_argc attribute_relro attribute_hidden;
|
||||
char **_dl_argv attribute_relro = NULL;
|
||||
unsigned int _dl_skip_args attribute_relro attribute_hidden;
|
||||
#endif
|
||||
rtld_hidden_data_def (_dl_argv)
|
||||
|
||||
#ifndef THREAD_SET_STACK_GUARD
|
||||
@@ -397,7 +390,8 @@ extern struct rtld_global_ro _rtld_local_ro
|
||||
|
||||
|
||||
static void dl_main (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
|
||||
ElfW(Addr) *user_entry, ElfW(auxv_t) *auxv);
|
||||
ElfW(Addr) *user_entry, ElfW(auxv_t) *auxv,
|
||||
void **start_argptr);
|
||||
|
||||
/* These two variables cannot be moved into .data.rel.ro. */
|
||||
static struct libname_list _dl_rtld_libname;
|
||||
@@ -1306,11 +1300,60 @@ rtld_setup_main_map (struct link_map *main_map)
|
||||
return has_interp;
|
||||
}
|
||||
|
||||
static void
|
||||
_dl_start_args_adjust (void **start_argptr, int skip_args)
|
||||
{
|
||||
void **sp = start_argptr;
|
||||
void **p;
|
||||
long argc;
|
||||
char **argv;
|
||||
|
||||
if (skip_args == 0)
|
||||
return;
|
||||
|
||||
/* Adjust argc on stack. */
|
||||
argc = (long) sp[0] - skip_args;
|
||||
sp[0] = (void *) argc;
|
||||
|
||||
argv = (char **) (sp + 1); /* Necessary aliasing violation. */
|
||||
p = sp + skip_args;
|
||||
/* Shuffle argv down. */
|
||||
do
|
||||
*++sp = *++p;
|
||||
while (*p != NULL);
|
||||
|
||||
/* Shuffle envp down. */
|
||||
do
|
||||
*++sp = *++p;
|
||||
while (*p != NULL);
|
||||
|
||||
/* Update globals in rtld. */
|
||||
_dl_argv = argv;
|
||||
_environ = argv + argc + 1;
|
||||
#ifdef HAVE_AUX_VECTOR
|
||||
GLRO(dl_auxv) = (ElfW(auxv_t) *) (sp + 1); /* Aliasing violation. */
|
||||
|
||||
/* Shuffle auxv down. */
|
||||
void *a, *b; /* Use a pair of pointers for an auxv entry. */
|
||||
unsigned long a_type;
|
||||
do
|
||||
{
|
||||
a_type = ((ElfW(auxv_t) *) (p + 1))->a_type;
|
||||
a = *++p;
|
||||
b = *++p;
|
||||
*++sp = a;
|
||||
*++sp = b;
|
||||
}
|
||||
while (a_type != AT_NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
dl_main (const ElfW(Phdr) *phdr,
|
||||
ElfW(Word) phnum,
|
||||
ElfW(Addr) *user_entry,
|
||||
ElfW(auxv_t) *auxv)
|
||||
ElfW(auxv_t) *auxv,
|
||||
void **start_argptr)
|
||||
{
|
||||
struct link_map *main_map;
|
||||
size_t file_size;
|
||||
@@ -1359,6 +1402,7 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
rtld_is_main = true;
|
||||
|
||||
char *argv0 = NULL;
|
||||
int skip_args = 0;
|
||||
|
||||
/* Note the place where the dynamic linker actually came from. */
|
||||
GL(dl_rtld_map).l_name = rtld_progname;
|
||||
@@ -1373,7 +1417,7 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
GLRO(dl_lazy) = -1;
|
||||
}
|
||||
|
||||
++_dl_skip_args;
|
||||
++skip_args;
|
||||
--_dl_argc;
|
||||
++_dl_argv;
|
||||
}
|
||||
@@ -1382,14 +1426,14 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
if (state.mode != rtld_mode_help)
|
||||
state.mode = rtld_mode_verify;
|
||||
|
||||
++_dl_skip_args;
|
||||
++skip_args;
|
||||
--_dl_argc;
|
||||
++_dl_argv;
|
||||
}
|
||||
else if (! strcmp (_dl_argv[1], "--inhibit-cache"))
|
||||
{
|
||||
GLRO(dl_inhibit_cache) = 1;
|
||||
++_dl_skip_args;
|
||||
++skip_args;
|
||||
--_dl_argc;
|
||||
++_dl_argv;
|
||||
}
|
||||
@@ -1399,7 +1443,7 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
state.library_path = _dl_argv[2];
|
||||
state.library_path_source = "--library-path";
|
||||
|
||||
_dl_skip_args += 2;
|
||||
skip_args += 2;
|
||||
_dl_argc -= 2;
|
||||
_dl_argv += 2;
|
||||
}
|
||||
@@ -1408,7 +1452,7 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
{
|
||||
GLRO(dl_inhibit_rpath) = _dl_argv[2];
|
||||
|
||||
_dl_skip_args += 2;
|
||||
skip_args += 2;
|
||||
_dl_argc -= 2;
|
||||
_dl_argv += 2;
|
||||
}
|
||||
@@ -1416,14 +1460,14 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
{
|
||||
audit_list_add_string (&state.audit_list, _dl_argv[2]);
|
||||
|
||||
_dl_skip_args += 2;
|
||||
skip_args += 2;
|
||||
_dl_argc -= 2;
|
||||
_dl_argv += 2;
|
||||
}
|
||||
else if (! strcmp (_dl_argv[1], "--preload") && _dl_argc > 2)
|
||||
{
|
||||
state.preloadarg = _dl_argv[2];
|
||||
_dl_skip_args += 2;
|
||||
skip_args += 2;
|
||||
_dl_argc -= 2;
|
||||
_dl_argv += 2;
|
||||
}
|
||||
@@ -1431,7 +1475,7 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
{
|
||||
argv0 = _dl_argv[2];
|
||||
|
||||
_dl_skip_args += 2;
|
||||
skip_args += 2;
|
||||
_dl_argc -= 2;
|
||||
_dl_argv += 2;
|
||||
}
|
||||
@@ -1439,7 +1483,7 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
&& _dl_argc > 2)
|
||||
{
|
||||
state.glibc_hwcaps_prepend = _dl_argv[2];
|
||||
_dl_skip_args += 2;
|
||||
skip_args += 2;
|
||||
_dl_argc -= 2;
|
||||
_dl_argv += 2;
|
||||
}
|
||||
@@ -1447,7 +1491,7 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
&& _dl_argc > 2)
|
||||
{
|
||||
state.glibc_hwcaps_mask = _dl_argv[2];
|
||||
_dl_skip_args += 2;
|
||||
skip_args += 2;
|
||||
_dl_argc -= 2;
|
||||
_dl_argv += 2;
|
||||
}
|
||||
@@ -1456,7 +1500,7 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
{
|
||||
state.mode = rtld_mode_list_tunables;
|
||||
|
||||
++_dl_skip_args;
|
||||
++skip_args;
|
||||
--_dl_argc;
|
||||
++_dl_argv;
|
||||
}
|
||||
@@ -1465,7 +1509,7 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
{
|
||||
state.mode = rtld_mode_list_diagnostics;
|
||||
|
||||
++_dl_skip_args;
|
||||
++skip_args;
|
||||
--_dl_argc;
|
||||
++_dl_argv;
|
||||
}
|
||||
@@ -1511,7 +1555,7 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
_dl_usage (ld_so_name, NULL);
|
||||
}
|
||||
|
||||
++_dl_skip_args;
|
||||
++skip_args;
|
||||
--_dl_argc;
|
||||
++_dl_argv;
|
||||
|
||||
@@ -1610,6 +1654,8 @@ dl_main (const ElfW(Phdr) *phdr,
|
||||
/* Set the argv[0] string now that we've processed the executable. */
|
||||
if (argv0 != NULL)
|
||||
_dl_argv[0] = argv0;
|
||||
/* Adjust arguments for the application entry point. */
|
||||
_dl_start_args_adjust (start_argptr, skip_args);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -33,6 +33,7 @@ tst-audit27-ENV = LD_AUDIT=$(objpfx)tst-auditmod27.so
|
||||
endif
|
||||
|
||||
ifeq ($(subdir),elf)
|
||||
sysdep-rtld-routines += dl-start
|
||||
sysdep-dl-routines += tlsdesc dl-tlsdesc
|
||||
gen-as-const-headers += dl-link.sym
|
||||
|
||||
|
||||
@@ -105,81 +105,8 @@ elf_machine_runtime_setup (struct link_map *l, struct r_scope_elem *scope[],
|
||||
return lazy;
|
||||
}
|
||||
|
||||
/* Initial entry point for the dynamic linker. The C function
|
||||
_dl_start is the real entry point, its return value is the user
|
||||
program's entry point */
|
||||
#ifdef __LP64__
|
||||
# define RTLD_START RTLD_START_1 ("x", "3", "sp")
|
||||
#else
|
||||
# define RTLD_START RTLD_START_1 ("w", "2", "wsp")
|
||||
#endif
|
||||
|
||||
|
||||
#define RTLD_START_1(PTR, PTR_SIZE_LOG, PTR_SP) asm ("\
|
||||
.text \n\
|
||||
.globl _start \n\
|
||||
.type _start, %function \n\
|
||||
.globl _dl_start_user \n\
|
||||
.type _dl_start_user, %function \n\
|
||||
_start: \n\
|
||||
// bti c \n\
|
||||
hint 34 \n\
|
||||
mov " PTR "0, " PTR_SP " \n\
|
||||
bl _dl_start \n\
|
||||
// returns user entry point in x0 \n\
|
||||
mov x21, x0 \n\
|
||||
_dl_start_user: \n\
|
||||
// get the original arg count \n\
|
||||
ldr " PTR "1, [sp] \n\
|
||||
// get the argv address \n\
|
||||
add " PTR "2, " PTR_SP ", #(1<<" PTR_SIZE_LOG ") \n\
|
||||
// get _dl_skip_args to see if we were \n\
|
||||
// invoked as an executable \n\
|
||||
adrp x4, _dl_skip_args \n\
|
||||
ldr w4, [x4, #:lo12:_dl_skip_args] \n\
|
||||
// do we need to adjust argc/argv \n\
|
||||
cmp w4, 0 \n\
|
||||
beq .L_done_stack_adjust \n\
|
||||
// subtract _dl_skip_args from original arg count \n\
|
||||
sub " PTR "1, " PTR "1, " PTR "4 \n\
|
||||
// store adjusted argc back to stack \n\
|
||||
str " PTR "1, [sp] \n\
|
||||
// find the first unskipped argument \n\
|
||||
mov " PTR "3, " PTR "2 \n\
|
||||
add " PTR "4, " PTR "2, " PTR "4, lsl #" PTR_SIZE_LOG " \n\
|
||||
// shuffle argv down \n\
|
||||
1: ldr " PTR "5, [x4], #(1<<" PTR_SIZE_LOG ") \n\
|
||||
str " PTR "5, [x3], #(1<<" PTR_SIZE_LOG ") \n\
|
||||
cmp " PTR "5, #0 \n\
|
||||
bne 1b \n\
|
||||
// shuffle envp down \n\
|
||||
1: ldr " PTR "5, [x4], #(1<<" PTR_SIZE_LOG ") \n\
|
||||
str " PTR "5, [x3], #(1<<" PTR_SIZE_LOG ") \n\
|
||||
cmp " PTR "5, #0 \n\
|
||||
bne 1b \n\
|
||||
// shuffle auxv down \n\
|
||||
1: ldp " PTR "0, " PTR "5, [x4, #(2<<" PTR_SIZE_LOG ")]! \n\
|
||||
stp " PTR "0, " PTR "5, [x3], #(2<<" PTR_SIZE_LOG ") \n\
|
||||
cmp " PTR "0, #0 \n\
|
||||
bne 1b \n\
|
||||
// Update _dl_argv \n\
|
||||
adrp x3, __GI__dl_argv \n\
|
||||
str " PTR "2, [x3, #:lo12:__GI__dl_argv] \n\
|
||||
.L_done_stack_adjust: \n\
|
||||
// compute envp \n\
|
||||
add " PTR "3, " PTR "2, " PTR "1, lsl #" PTR_SIZE_LOG " \n\
|
||||
add " PTR "3, " PTR "3, #(1<<" PTR_SIZE_LOG ") \n\
|
||||
adrp x16, _rtld_local \n\
|
||||
add " PTR "16, " PTR "16, #:lo12:_rtld_local \n\
|
||||
ldr " PTR "0, [x16] \n\
|
||||
bl _dl_init \n\
|
||||
// load the finalizer function \n\
|
||||
adrp x0, _dl_fini \n\
|
||||
add " PTR "0, " PTR "0, #:lo12:_dl_fini \n\
|
||||
// jump to the user_s entry point \n\
|
||||
mov x16, x21 \n\
|
||||
br x16 \n\
|
||||
");
|
||||
/* In elf/rtld.c _dl_start should be global so dl-start.S can reference it. */
|
||||
#define RTLD_START asm (".globl _dl_start");
|
||||
|
||||
#define elf_machine_type_class(type) \
|
||||
((((type) == AARCH64_R(JUMP_SLOT) \
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/* ld.so _start code.
|
||||
Copyright (C) 2022 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <sysdep.h>
|
||||
|
||||
ENTRY (_start)
|
||||
/* Create an initial frame with 0 LR and FP */
|
||||
cfi_undefined (x30)
|
||||
mov x29, #0
|
||||
mov x30, #0
|
||||
|
||||
mov x0, sp
|
||||
PTR_ARG (0)
|
||||
bl _dl_start
|
||||
/* Returns user entry point in x0. */
|
||||
mov PTR_REG (21), PTR_REG (0)
|
||||
.globl _dl_start_user
|
||||
.type _dl_start_user, %function
|
||||
_dl_start_user:
|
||||
/* Get argc. */
|
||||
ldr PTR_REG (1), [sp]
|
||||
/* Get argv. */
|
||||
add x2, sp, PTR_SIZE
|
||||
/* Compute envp. */
|
||||
add PTR_REG (3), PTR_REG (2), PTR_REG (1), lsl PTR_LOG_SIZE
|
||||
add PTR_REG (3), PTR_REG (3), PTR_SIZE
|
||||
adrp x16, _rtld_local
|
||||
add PTR_REG (16), PTR_REG (16), :lo12:_rtld_local
|
||||
ldr PTR_REG (0), [x16]
|
||||
bl _dl_init
|
||||
/* Load the finalizer function. */
|
||||
adrp x0, _dl_fini
|
||||
add PTR_REG (0), PTR_REG (0), :lo12:_dl_fini
|
||||
/* Jump to the user's entry point. */
|
||||
mov x16, x21
|
||||
br x16
|
||||
END (_start)
|
||||
@@ -18,8 +18,4 @@
|
||||
|
||||
#include_next <dl-sysdep.h>
|
||||
|
||||
/* _dl_argv cannot be attribute_relro, because _dl_start_user
|
||||
might write into it after _dl_start returns. */
|
||||
#define DL_ARGV_NOT_RELRO 1
|
||||
|
||||
#define DL_EXTERN_PROTECTED_DATA
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/* System-specific settings for dynamic linker code. Alpha version.
|
||||
Copyright (C) 2002-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library. If not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include_next <dl-sysdep.h>
|
||||
|
||||
/* _dl_argv cannot be attribute_relro, because _dl_start_user
|
||||
might write into it after _dl_start returns. */
|
||||
#define DL_ARGV_NOT_RELRO 1
|
||||
@@ -18,8 +18,4 @@
|
||||
|
||||
#include_next <dl-sysdep.h>
|
||||
|
||||
/* _dl_argv cannot be attribute_relro, because _dl_start_user
|
||||
might write into it after _dl_start returns. */
|
||||
#define DL_ARGV_NOT_RELRO 1
|
||||
|
||||
#define DL_EXTERN_PROTECTED_DATA
|
||||
|
||||
@@ -18,8 +18,4 @@
|
||||
|
||||
#include_next <dl-sysdep.h>
|
||||
|
||||
/* _dl_argv cannot be attribute_relro, because _dl_start_user
|
||||
might write into it after _dl_start returns. */
|
||||
#define DL_ARGV_NOT_RELRO 1
|
||||
|
||||
#define DL_EXTERN_PROTECTED_DATA
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/* System-specific settings for dynamic linker code. C-SKY version.
|
||||
Copyright (C) 2018-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library. If not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include_next <dl-sysdep.h>
|
||||
|
||||
/* _dl_argv cannot be attribute_relro, because _dl_start_user
|
||||
might write into it after _dl_start returns. */
|
||||
#define DL_ARGV_NOT_RELRO 1
|
||||
@@ -762,18 +762,10 @@ rtld_hidden_proto (__libc_stack_end)
|
||||
|
||||
/* Parameters passed to the dynamic linker. */
|
||||
extern int _dl_argc attribute_hidden attribute_relro;
|
||||
extern char **_dl_argv
|
||||
#ifndef DL_ARGV_NOT_RELRO
|
||||
attribute_relro
|
||||
#endif
|
||||
;
|
||||
extern char **_dl_argv attribute_relro;
|
||||
rtld_hidden_proto (_dl_argv)
|
||||
#if IS_IN (rtld)
|
||||
extern unsigned int _dl_skip_args attribute_hidden
|
||||
# ifndef DL_ARGV_NOT_RELRO
|
||||
attribute_relro
|
||||
# endif
|
||||
;
|
||||
extern unsigned int _dl_skip_args attribute_hidden attribute_relro;
|
||||
#endif
|
||||
#define rtld_progname _dl_argv[0]
|
||||
|
||||
@@ -1165,7 +1157,8 @@ extern ElfW(Addr) _dl_sysdep_start (void **start_argptr,
|
||||
void (*dl_main) (const ElfW(Phdr) *phdr,
|
||||
ElfW(Word) phnum,
|
||||
ElfW(Addr) *user_entry,
|
||||
ElfW(auxv_t) *auxv))
|
||||
ElfW(auxv_t) *auxv,
|
||||
void **start_argptr))
|
||||
attribute_hidden;
|
||||
|
||||
extern void _dl_sysdep_start_cleanup (void) attribute_hidden;
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/* System-specific settings for dynamic linker code. IA-64 version.
|
||||
Copyright (C) 2002-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include_next <dl-sysdep.h>
|
||||
|
||||
/* _dl_argv cannot be attribute_relro, because _dl_start_user
|
||||
might write into it after _dl_start returns. */
|
||||
#define DL_ARGV_NOT_RELRO 1
|
||||
@@ -18,8 +18,4 @@
|
||||
|
||||
#include_next <dl-sysdep.h>
|
||||
|
||||
/* _dl_argv cannot be attribute_relro, because _dl_start_user
|
||||
might write into it after _dl_start returns. */
|
||||
#define DL_ARGV_NOT_RELRO 1
|
||||
|
||||
#define DL_EXTERN_PROTECTED_DATA
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/* System-specific settings for dynamic linker code. S/390 version.
|
||||
Copyright (C) 2014-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library. If not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include_next <dl-sysdep.h>
|
||||
|
||||
/* _dl_argv cannot be attribute_relro, because _dl_start_user
|
||||
might write into it after _dl_start returns. */
|
||||
#define DL_ARGV_NOT_RELRO 1
|
||||
@@ -1,23 +0,0 @@
|
||||
/* System-specific settings for dynamic linker code. SPARC version.
|
||||
Copyright (C) 2002-2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include_next <dl-sysdep.h>
|
||||
|
||||
/* _dl_argv cannot be attribute_relro, because _dl_start_user
|
||||
might write into it after _dl_start returns. */
|
||||
#define DL_ARGV_NOT_RELRO 1
|
||||
@@ -126,6 +126,7 @@ tests += tst-clone tst-clone2 tst-clone3 tst-fanotify tst-personality \
|
||||
tst-prctl \
|
||||
tst-scm_rights \
|
||||
tst-epoll \
|
||||
tst-getauxval \
|
||||
# tests
|
||||
|
||||
# For +depfiles in Makerules.
|
||||
|
||||
@@ -98,7 +98,8 @@ _dl_sysdep_parse_arguments (void **start_argptr,
|
||||
ElfW(Addr)
|
||||
_dl_sysdep_start (void **start_argptr,
|
||||
void (*dl_main) (const ElfW(Phdr) *phdr, ElfW(Word) phnum,
|
||||
ElfW(Addr) *user_entry, ElfW(auxv_t) *auxv))
|
||||
ElfW(Addr) *user_entry, ElfW(auxv_t) *auxv,
|
||||
void **start_argptr))
|
||||
{
|
||||
__libc_stack_end = DL_STACK_END (start_argptr);
|
||||
|
||||
@@ -138,7 +139,7 @@ _dl_sysdep_start (void **start_argptr,
|
||||
__libc_check_standard_fds ();
|
||||
|
||||
(*dl_main) (dl_main_args.phdr, dl_main_args.phnum,
|
||||
&dl_main_args.user_entry, GLRO(dl_auxv));
|
||||
&dl_main_args.user_entry, GLRO(dl_auxv), start_argptr);
|
||||
return dl_main_args.user_entry;
|
||||
}
|
||||
|
||||
|
||||
@@ -48,8 +48,4 @@ extern int _dl_sysinfo_break attribute_hidden;
|
||||
".previous");
|
||||
#endif
|
||||
|
||||
/* _dl_argv cannot be attribute_relro, because _dl_start_user
|
||||
might write into it after _dl_start returns. */
|
||||
#define DL_ARGV_NOT_RELRO 1
|
||||
|
||||
#endif /* dl-sysdep.h */
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
/* Basic test for getauxval.
|
||||
Copyright (C) 2022 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
The GNU C Library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with the GNU C Library; if not, see
|
||||
<https://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <support/check.h>
|
||||
#include <sys/auxv.h>
|
||||
|
||||
static int missing;
|
||||
static int mismatch;
|
||||
|
||||
static void
|
||||
check_nonzero (unsigned long t, const char *s)
|
||||
{
|
||||
unsigned long v = getauxval (t);
|
||||
printf ("%s: %lu (0x%lx)\n", s, v, v);
|
||||
if (v == 0)
|
||||
missing++;
|
||||
}
|
||||
|
||||
static void
|
||||
check_eq (unsigned long t, const char *s, unsigned long want)
|
||||
{
|
||||
unsigned long v = getauxval (t);
|
||||
printf ("%s: %lu want: %lu\n", s, v, want);
|
||||
if (v != want)
|
||||
mismatch++;
|
||||
}
|
||||
|
||||
#define NZ(x) check_nonzero (x, #x)
|
||||
#define EQ(x, want) check_eq (x, #x, want)
|
||||
|
||||
static int
|
||||
do_test (void)
|
||||
{
|
||||
/* These auxv entries should be non-zero on Linux. */
|
||||
NZ (AT_PHDR);
|
||||
NZ (AT_PHENT);
|
||||
NZ (AT_PHNUM);
|
||||
NZ (AT_PAGESZ);
|
||||
NZ (AT_ENTRY);
|
||||
NZ (AT_CLKTCK);
|
||||
NZ (AT_RANDOM);
|
||||
NZ (AT_EXECFN);
|
||||
if (missing)
|
||||
FAIL_EXIT1 ("Found %d missing auxv entries.\n", missing);
|
||||
|
||||
/* Check against syscalls. */
|
||||
EQ (AT_UID, getuid ());
|
||||
EQ (AT_EUID, geteuid ());
|
||||
EQ (AT_GID, getgid ());
|
||||
EQ (AT_EGID, getegid ());
|
||||
if (mismatch)
|
||||
FAIL_EXIT1 ("Found %d mismatching auxv entries.\n", mismatch);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#include <support/test-driver.c>
|
||||
Reference in New Issue
Block a user