/* Initialize the file descriptor table at startup. */
-static void
+static void attribute_used_retain
init_dtable (void)
{
int i;
/* 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. */
#include <hurd.h>
#include <hurd/id.h>
+#include "set-hooks.h"
struct hurd_id_data _hurd_id;
return 0;
}
-static void
+static void attribute_used_retain
init_id (void)
{
__mutex_init (&_hurd_id.lock);
_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);
/* 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)
/* 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
/* 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)
{
#include <stdlib.h>
#include <string.h>
+#include "set-hooks.h"
#include "hurdmalloc.h" /* XXX see that file */
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;
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
}
\f
-text_set_element (_hurd_preinit_hook, malloc_init);
+SET_RELHOOK (_hurd_preinit_hook, malloc_init);
#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,
__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);
\f
#include <hurd/msg_server.h>
#include "set-hooks.h"
#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. */
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;
}
#undef I
}
-
- (void) &init_rlimit;
}
-text_set_element (_hurd_preinit_hook, init_rlimit);
+SET_RELHOOK (_hurd_preinit_hook, init_rlimit);
#include <_itoa.h>
#include <lock-intern.h> /* For `struct mutex'. */
#include "hurdmalloc.h" /* XXX */
+#include "set-hooks.h"
static struct mutex lock;
return server;
}
\f
-static void
+static void attribute_used_retain
init (void)
{
int i;
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);
#include <sys/cdefs.h>
#include <libc-symbols.h>
+#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)'
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. */
# define DEFINE_HOOK_RUNNER(name, runner, proto, args)
+# define SET_RELHOOK(NAME, HOOK)
+
+# define RUN_RELHOOK(NAME, ARGS)
+
#endif
#endif /* set-hooks.h */
--- /dev/null
+/* Machine-dependent macros for using symbol sets for running lists of
+ functions. Generic/stub version.
+ Copyright (C) 2021 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/>. */
+
+#ifndef _SET_HOOKS_ARCH_H
+#define _SET_HOOKS_ARCH_H
+
+/* Define SET_RELHOOK to a variant of text_set_element that records a relative
+ offset rather than an absolute address. See sysdeps/i386/set-hooks-arch.h
+ for an example.
+
+#define SET_RELHOOK(NAME, HOOK) ...
+
+ */
+
+#endif /* set_hooks_arch.h */
--- /dev/null
+/* Machine-dependent macros for using symbol sets for running lists of
+ functions. i386 version.
+ Copyright (C) 2021 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/>. */
+
+#ifndef _SET_HOOKS_ARCH_H
+#define _SET_HOOKS_ARCH_H
+
+#define SET_RELHOOK(NAME, HOOK) \
+ asm(".section " #NAME",\"aR\"\n" \
+ ".long "#HOOK" - .\n" \
+ ".section .text");
+
+#endif /* set_hooks_arch.h */
#include <lock-intern.h> /* For `struct mutex'. */
#include <vm_param.h>
+#include "set-hooks.h"
+
/* Initial maximum size of the data segment (this is arbitrary). */
#define DATA_SIZE (128 * 1024 * 1024)
return 0;
}
-static void
+static void attribute_used_retain
init_brk (void)
{
vm_address_t pagend;
/* Couldn't allocate the memory. The break will be very short. */
_hurd_data_end = pagend;
}
-
- (void) &init_brk; /* Avoid ``defined but not used'' warning. */
}
-text_set_element (_hurd_preinit_hook, init_brk);
+SET_RELHOOK (_hurd_preinit_hook, init_brk);
check_one_fd (STDERR_FILENO, O_RDWR);
}
-static void
+static void attribute_used_retain
init_standard_fds (void)
{
/* Now that we have FDs, make sure that, if this is a SUID program,
ourselves. If that's not possible we stop the program. */
if (__builtin_expect (__libc_enable_secure, 0))
check_standard_fds ();
-
- (void) &init_standard_fds; /* Avoid "defined but not used" warning. */
}
-text_set_element (_hurd_fd_subinit, init_standard_fds);
+SET_RELHOOK (_hurd_fd_subinit, init_standard_fds);
\f
#ifndef SHARED
/* Initialize data structures so we can do RPCs. */
__mach_init ();
- RUN_HOOK (_hurd_preinit_hook, ());
+ RUN_RELHOOK (_hurd_preinit_hook, ());
}
#ifdef SHARED
--- /dev/null
+/* Machine-dependent macros for using symbol sets for running lists of
+ functions. x86-64 version.
+ Copyright (C) 2021 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/>. */
+
+#ifndef _SET_HOOKS_ARCH_H
+#define _SET_HOOKS_ARCH_H
+
+#define SET_RELHOOK(NAME, HOOK) \
+ asm(".section " #NAME",\"aR\"\n" \
+ ".quad "#HOOK" - .\n" \
+ ".section .text");
+
+#endif /* set_hooks_arch.h */