aboutsummaryrefslogtreecommitdiff
path: root/hurd
diff options
context:
space:
mode:
authorSamuel Thibault <samuel.thibault@ens-lyon.org>2021-12-28 10:27:06 +0100
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2021-12-28 10:28:22 +0100
commitae49f218daca0b7cab27764da4081e6509bc7345 (patch)
treefef5fa1b87b9bc540c84690c3128c252651f6f34 /hurd
parent2ce0481d26066b7d4e2c950da555a7ca20e313fb (diff)
downloadglibc-ae49f218daca0b7cab27764da4081e6509bc7345.zip
glibc-ae49f218daca0b7cab27764da4081e6509bc7345.tar.gz
glibc-ae49f218daca0b7cab27764da4081e6509bc7345.tar.bz2
hurd: Fix static-PIE startup
hurd initialization stages use RUN_HOOK to run various initialization functions. That is however using absolute addresses which need to be relocated, which is done later by csu. We can however easily make the linker compute relative addresses which thus don't need a relocation. The new SET_RELHOOK and RUN_RELHOOK macros implement this.
Diffstat (limited to 'hurd')
-rw-r--r--hurd/dtable.c8
-rw-r--r--hurd/hurdid.c7
-rw-r--r--hurd/hurdinit.c6
-rw-r--r--hurd/hurdmalloc.c10
-rw-r--r--hurd/hurdpid.c7
-rw-r--r--hurd/hurdrlimit.c7
-rw-r--r--hurd/hurdsock.c7
7 files changed, 21 insertions, 31 deletions
diff --git a/hurd/dtable.c b/hurd/dtable.c
index bbd3bfc..4f081f0 100644
--- a/hurd/dtable.c
+++ b/hurd/dtable.c
@@ -36,7 +36,7 @@ DEFINE_HOOK (_hurd_fd_subinit, (void));
/* Initialize the file descriptor table at startup. */
-static void
+static void attribute_used_retain
init_dtable (void)
{
int i;
@@ -91,12 +91,10 @@ init_dtable (void)
/* Run things that want to run after the file descriptor table
is initialized. */
- RUN_HOOK (_hurd_fd_subinit, ());
-
- (void) &init_dtable; /* Avoid "defined but not used" warning. */
+ RUN_RELHOOK (_hurd_fd_subinit, ());
}
-text_set_element (_hurd_subinit, init_dtable);
+SET_RELHOOK (_hurd_subinit, init_dtable);
/* XXX when the linker supports it, the following functions should all be
elsewhere and just have text_set_elements here. */
diff --git a/hurd/hurdid.c b/hurd/hurdid.c
index 70c46c0..b220532 100644
--- a/hurd/hurdid.c
+++ b/hurd/hurdid.c
@@ -17,6 +17,7 @@
#include <hurd.h>
#include <hurd/id.h>
+#include "set-hooks.h"
struct hurd_id_data _hurd_id;
@@ -74,7 +75,7 @@ _hurd_check_ids (void)
return 0;
}
-static void
+static void attribute_used_retain
init_id (void)
{
__mutex_init (&_hurd_id.lock);
@@ -84,7 +85,5 @@ init_id (void)
_hurd_id.gen.nuids = _hurd_id.aux.nuids = 0;
_hurd_id.gen.gids = _hurd_id.aux.gids = NULL;
_hurd_id.gen.ngids = _hurd_id.aux.ngids = 0;
-
- (void) &init_id; /* Avoid "defined but not used" warning. */
}
-text_set_element (_hurd_preinit_hook, init_id);
+SET_RELHOOK (_hurd_preinit_hook, init_id);
diff --git a/hurd/hurdinit.c b/hurd/hurdinit.c
index d4d219a..9377d90 100644
--- a/hurd/hurdinit.c
+++ b/hurd/hurdinit.c
@@ -108,7 +108,7 @@ _hurd_init (int flags, char **argv,
/* Call other things which want to do some initialization. These are not
on the __libc_subinit hook because things there like to be able to
assume the availability of the POSIX.1 services we provide. */
- RUN_HOOK (_hurd_subinit, ());
+ RUN_RELHOOK (_hurd_subinit, ());
}
libc_hidden_def (_hurd_init)
@@ -190,7 +190,7 @@ _hurd_new_proc_init (char **argv,
/* Call other things which want to do some initialization. These are not
on the _hurd_subinit hook because things there assume that things done
here, like _hurd_pid, are already initialized. */
- RUN_HOOK (_hurd_proc_subinit, ());
+ RUN_RELHOOK (_hurd_proc_subinit, ());
/* XXX This code should probably be removed entirely at some point. This
conditional should make it reasonably usable with old gdb's for a
@@ -242,7 +242,7 @@ _hurd_setproc (process_t procserver)
/* Call these functions again so they can fetch the
new information from the new proc server. */
- RUN_HOOK (_hurd_proc_subinit, ());
+ RUN_RELHOOK (_hurd_proc_subinit, ());
if (_hurd_pgrp != oldpgrp)
{
diff --git a/hurd/hurdmalloc.c b/hurd/hurdmalloc.c
index 7046bce..ccb8fc8 100644
--- a/hurd/hurdmalloc.c
+++ b/hurd/hurdmalloc.c
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <string.h>
+#include "set-hooks.h"
#include "hurdmalloc.h" /* XXX see that file */
@@ -148,7 +149,7 @@ static struct free_list malloc_free_list[NBUCKETS];
It preserves the values of data variables like malloc_free_list, but
does not save the vm_allocate'd space allocated by this malloc. */
-static void
+static void attribute_used_retain
malloc_init (void)
{
int i;
@@ -160,11 +161,6 @@ malloc_init (void)
malloc_free_list[i].in_use = 0;
#endif
}
-
- /* This not only suppresses a `defined but not used' warning,
- but it is ABSOLUTELY NECESSARY to avoid the hyperclever
- compiler from "optimizing out" the entire function! */
- (void) &malloc_init;
}
static void
@@ -445,4 +441,4 @@ _hurd_malloc_fork_child(void)
}
-text_set_element (_hurd_preinit_hook, malloc_init);
+SET_RELHOOK (_hurd_preinit_hook, malloc_init);
diff --git a/hurd/hurdpid.c b/hurd/hurdpid.c
index 9014de5..613ca35 100644
--- a/hurd/hurdpid.c
+++ b/hurd/hurdpid.c
@@ -17,11 +17,12 @@
#include <hurd.h>
#include <lowlevellock.h>
+#include "set-hooks.h"
pid_t _hurd_pid, _hurd_ppid, _hurd_pgrp;
int _hurd_orphaned;
-static void
+static void attribute_used_retain
init_pids (void)
{
__USEPORT (PROC,
@@ -29,11 +30,9 @@ init_pids (void)
__proc_getpids (port, &_hurd_pid, &_hurd_ppid, &_hurd_orphaned);
__proc_getpgrp (port, _hurd_pid, &_hurd_pgrp);
}));
-
- (void) &init_pids; /* Avoid "defined but not used" warning. */
}
-text_set_element (_hurd_proc_subinit, init_pids);
+SET_RELHOOK (_hurd_proc_subinit, init_pids);
#include <hurd/msg_server.h>
#include "set-hooks.h"
diff --git a/hurd/hurdrlimit.c b/hurd/hurdrlimit.c
index 17535c2..4d16bd4 100644
--- a/hurd/hurdrlimit.c
+++ b/hurd/hurdrlimit.c
@@ -19,6 +19,7 @@
#include <hurd.h>
#include <lock-intern.h>
#include <hurd/resource.h>
+#include "set-hooks.h"
/* This must be given an initializer, or the a.out linking rules will
not include the entire file when this symbol is referenced. */
@@ -29,7 +30,7 @@ struct rlimit _hurd_rlimits[RLIM_NLIMITS] = { { 0, }, };
mutex_init is still required below just in case of unexec. */
struct mutex _hurd_rlimit_lock = { SPIN_LOCK_INITIALIZER, };
-static void
+static void attribute_used_retain
init_rlimit (void)
{
int i;
@@ -52,7 +53,5 @@ init_rlimit (void)
}
#undef I
}
-
- (void) &init_rlimit;
}
-text_set_element (_hurd_preinit_hook, init_rlimit);
+SET_RELHOOK (_hurd_preinit_hook, init_rlimit);
diff --git a/hurd/hurdsock.c b/hurd/hurdsock.c
index 04e86b4..116326b 100644
--- a/hurd/hurdsock.c
+++ b/hurd/hurdsock.c
@@ -25,6 +25,7 @@
#include <_itoa.h>
#include <lock-intern.h> /* For `struct mutex'. */
#include "hurdmalloc.h" /* XXX */
+#include "set-hooks.h"
static struct mutex lock;
@@ -109,7 +110,7 @@ retry:
return server;
}
-static void
+static void attribute_used_retain
init (void)
{
int i;
@@ -118,7 +119,5 @@ init (void)
for (i = 0; i < max_domain; ++i)
servers[i] = MACH_PORT_NULL;
-
- (void) &init; /* Avoid "defined but not used" warning. */
}
-text_set_element (_hurd_preinit_hook, init);
+SET_RELHOOK (_hurd_preinit_hook, init);