From ae49f218daca0b7cab27764da4081e6509bc7345 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Tue, 28 Dec 2021 10:27:06 +0100 Subject: 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. --- include/set-hooks.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'include/set-hooks.h') diff --git a/include/set-hooks.h b/include/set-hooks.h index a60b5ae19f..1a2f6ad56b 100644 --- a/include/set-hooks.h +++ b/include/set-hooks.h @@ -24,6 +24,8 @@ #include #include +#include "set-hooks-arch.h" + #ifdef symbol_set_define /* Define a hook variable called NAME. Functions put on this hook take arguments described by PROTO. Use `text_set_element (NAME, FUNCTION)' @@ -55,6 +57,25 @@ do { \ DEFINE_HOOK (name, proto); \ extern void runner proto; void runner proto { RUN_HOOK (name, args); } +# ifdef SET_RELHOOK +/* This is similar to RUN_RELHOOK, but the hooks were registered with + * SET_RELHOOK so that a relative offset was computed by the linker + * rather than an absolute address by the dynamic linker. */ +# define RUN_RELHOOK(NAME, ARGS) \ +do { \ + void *const *ptr; \ + for (ptr = (void *const *) symbol_set_first_element (NAME); \ + ! symbol_set_end_p (NAME, ptr); ++ptr) { \ + __##NAME##_hook_function_t *f = \ + (void*) ((uintptr_t) ptr + (ptrdiff_t) *ptr); \ + (*f) ARGS; \ + } \ +} while (0) +# else +# define SET_RELHOOK(NAME, HOOK) text_set_element (NAME, HOOK) +# define RUN_RELHOOK(NAME, ARGS) RUN_HOOK(NAME, ARGS) +# endif + #else /* The system does not provide necessary support for this. */ @@ -66,6 +87,10 @@ extern void runner proto; void runner proto { RUN_HOOK (name, args); } # define DEFINE_HOOK_RUNNER(name, runner, proto, args) +# define SET_RELHOOK(NAME, HOOK) + +# define RUN_RELHOOK(NAME, ARGS) + #endif #endif /* set-hooks.h */ -- cgit 1.4.1