diff options
author | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2022-08-22 22:34:31 +0200 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2022-08-22 22:34:31 +0200 |
commit | af6b1cce9812273c7f597be6536d28eaec6fb89b (patch) | |
tree | a4e6e3eaa478ec9435a4669fed252a543dc466ab /sysdeps/mach/hurd/i386/init-first.c | |
parent | 4565083abc972bffe810e4151f8f3cb48531e526 (diff) | |
download | glibc-af6b1cce9812273c7f597be6536d28eaec6fb89b.tar.gz glibc-af6b1cce9812273c7f597be6536d28eaec6fb89b.tar.xz glibc-af6b1cce9812273c7f597be6536d28eaec6fb89b.zip |
hurd: Fix starting static binaries with stack protection enabled
gcc introduces gs:0x14 accesses in most functions, so we need some tcbhead to be ready very early during initialization. This configures a static area which can be referenced by various protected functions, until proper TLS is set up.
Diffstat (limited to 'sysdeps/mach/hurd/i386/init-first.c')
-rw-r--r-- | sysdeps/mach/hurd/i386/init-first.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c index f10d4a1bc2..7d8721856b 100644 --- a/sysdeps/mach/hurd/i386/init-first.c +++ b/sysdeps/mach/hurd/i386/init-first.c @@ -42,6 +42,11 @@ extern int __libc_argc attribute_hidden; extern char **__libc_argv attribute_hidden; extern char **_dl_argv; +#ifndef SHARED +unsigned short __init1_desc; +static tcbhead_t __init1_tcbhead; +#endif + /* Things that want to be run before _hurd_init or much anything else. Importantly, these are called before anything tries to use malloc. */ DEFINE_HOOK (_hurd_preinit_hook, (void)); @@ -243,6 +248,13 @@ first_init (void) /* Initialize data structures so we can do RPCs. */ __mach_init (); +#ifndef SHARED + /* In the static case, we need to set up TLS early so that the stack + protection guard can be read at gs:0x14 by the gcc-generated snippets. */ + _hurd_tls_init(&__init1_tcbhead); + asm ("movw %%gs,%w0" : "=m" (__init1_desc)); +#endif + RUN_RELHOOK (_hurd_preinit_hook, ()); } @@ -285,6 +297,7 @@ strong_alias (posixland_init, __libc_init_first); This poorly-named function is called by static-start.S, which should not exist at all. */ void +inhibit_stack_protector _hurd_stack_setup (void) { intptr_t caller = (intptr_t) __builtin_return_address (0); |