Add support for "link sets", which are arrays of pointers to objects

gathered together in named sections by the linker.
This commit is contained in:
thorpej 2002-11-01 22:58:44 +00:00
parent 85b746f61a
commit 4b17905e0f
3 changed files with 102 additions and 3 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cdefs.h,v 1.44 2002/10/10 17:02:23 thorpej Exp $ */
/* $NetBSD: cdefs.h,v 1.45 2002/11/01 22:58:44 thorpej Exp $ */
/*
* Copyright (c) 1991, 1993
@ -272,4 +272,53 @@
#define __predict_false(exp) ((exp) != 0)
#endif
/*
* Macros for manipulating "link sets". Link sets are arrays of pointers
* to objects, which are gathered up by the linker.
*
* Object format-specific code has provided us with the following macros:
*
* __link_set_add_text(set, sym)
* Add a reference to the .text symbol `sym' to `set'.
*
* __link_set_add_rodata(set, sym)
* Add a reference to the .rodata symbol `sym' to `set'.
*
* __link_set_add_data(set, sym)
* Add a reference to the .data symbol `sym' to `set'.
*
* __link_set_add_bss(set, sym)
* Add a reference to the .bss symbol `sym' to `set'.
*
* __link_set_decl(set, ptype)
* Provide an extern declaration of the set `set', which
* contains an array of the pointer type `ptype'. This
* macro must be used by any code which wishes to reference
* the elements of a link set.
*
* __link_set_start(set)
* This points to the first slot in the link set.
*
* __link_set_end(set)
* This points to the (non-existent) slot after the last
* entry in the link set.
*
* __link_set_count(set)
* Count the number of entries in link set `set'.
*
* In addition, we provide the following macros for accessing link sets:
*
* __link_set_foreach(pvar, set)
* Iterate over the link set `set'. Because a link set is
* an array of pointers, pvar must be declared as "type **pvar",
* and the actual entry accessed as "*pvar".
*
* __link_set_entry(set, idx)
* Access the link set entry at index `idx' from set `set'.
*/
#define __link_set_foreach(pvar, set) \
for (pvar = __link_set_start(set); pvar < __link_set_end(set); pvar++)
#define __link_set_entry(set, idx) (__link_set_begin(set)[idx])
#endif /* !_SYS_CDEFS_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: cdefs_aout.h,v 1.10 2002/05/11 11:57:14 itohy Exp $ */
/* $NetBSD: cdefs_aout.h,v 1.11 2002/11/01 22:58:44 thorpej Exp $ */
/*
* Written by J.T. Conklin <jtc@wimsey.com> 01/17/95.
@ -68,4 +68,30 @@
#define __KERNEL_SCCSID(_n,_s)
#define __KERNEL_COPYRIGHT(_n, _s) __IDSTRING(__CONCAT(copyright,_n),_s)
#ifdef __lint__
#define __link_set_make_entry(set, sym, type) \
static void const * const __link_set_##set##_sym_##sym = &sym; \
__asm(".stabs \"___link_set_" #set "\", " #type ", 0, 0, _" #sym)
#else
#define __link_set_make_entry(set, sym, type) \
extern void const * const __link_set_##set##_sym_##sym
#endif /* __lint__ */
#define __link_set_add_text(set, sym) __link_set_make_entry(set, sym, 23)
#define __link_set_add_rodata(set, sym) __link_set_make_entry(set, sym, 23)
#define __link_set_add_data(set, sym) __link_set_make_entry(set, sym, 25)
#define __link_set_add_bss(set, sym) __link_set_make_entry(set, sym, 27)
#define __link_set_decl(set, ptype) \
extern struct { \
int __ls_length; \
ptype *__ls_items[1]; \
} __link_set_##set
#define __link_set_start(set) (&(__link_set_##set).__ls_items[0])
#define __link_set_end(set) \
(&(__link_set_##set).__ls_items[(__link_set_##set).__ls_length])
#define __link_set_count(set) ((__link_set_##set).__ls_length)
#endif /* !_SYS_CDEFS_AOUT_H_ */

View File

@ -1,4 +1,4 @@
/* $NetBSD: cdefs_elf.h,v 1.12 2002/10/10 00:52:47 thorpej Exp $ */
/* $NetBSD: cdefs_elf.h,v 1.13 2002/11/01 22:58:44 thorpej Exp $ */
/*
* Copyright (c) 1995, 1996 Carnegie-Mellon University.
@ -112,4 +112,28 @@
#define __KERNEL_COPYRIGHT(_n, _s) __SECTIONSTRING(.copyright, _s)
#endif
#ifndef __lint__
#define __link_set_make_entry(set, sym) \
static void const * const __link_set_##set##_sym_##sym \
__section("link_set_" #set) __unused = &sym
#else
#define __link_set_make_entry(set, sym) \
extern void const * const __link_set_##set##_sym_##sym
#endif /* __lint__ */
#define __link_set_add_text(set, sym) __link_set_make_entry(set, sym)
#define __link_set_add_rodata(set, sym) __link_set_make_entry(set, sym)
#define __link_set_add_data(set, sym) __link_set_make_entry(set, sym)
#define __link_set_add_bss(set, sym) __link_set_make_entry(set, sym)
#define __link_set_decl(set, ptype) \
extern ptype *__start_link_set_##set; \
extern ptype *__stop_link_set_##set
#define __link_set_start(set) (&__start_link_set_##set)
#define __link_set_end(set) (&__stop_link_set_##set)
#define __link_set_count(set) \
(__link_set_end(set) - __link_set_start(set))
#endif /* !_SYS_CDEFS_ELF_H_ */