1/* 2 * Copyright 2009 Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 */ 5#ifndef _FBSD_COMPAT_SYS_LINKER_SET_H_ 6#define _FBSD_COMPAT_SYS_LINKER_SET_H_ 7 8 9#ifndef _FBSD_COMPAT_SYS_CDEFS_H_ 10#error this file needs sys/cdefs.h as a prerequisite 11#endif 12 13/* 14 * The following macros are used to declare global sets of objects, which 15 * are collected by the linker into a `linker_set' as defined below. 16 * For ELF, this is done by constructing a separate segment for each set. 17 */ 18 19/* 20 * Private macros, not to be used outside this header file. 21 */ 22#ifdef __GNUCLIKE___SECTION 23#define __MAKE_SET(set, sym) \ 24 static void const * const __set_##set##_sym_##sym \ 25 __section("set_" #set) __used = &sym 26#else /* !__GNUCLIKE___SECTION */ 27#ifndef lint 28#error this file needs to be ported to your compiler 29#endif /* lint */ 30#define __MAKE_SET(set, sym) extern void const * const (__set_##set##_sym_##sym) 31#endif /* __GNUCLIKE___SECTION */ 32 33/* 34 * Public macros. 35 */ 36#define TEXT_SET(set, sym) __MAKE_SET(set, sym) 37#define DATA_SET(set, sym) __MAKE_SET(set, sym) 38#define BSS_SET(set, sym) __MAKE_SET(set, sym) 39#define ABS_SET(set, sym) __MAKE_SET(set, sym) 40#define SET_ENTRY(set, sym) __MAKE_SET(set, sym) 41 42/* 43 * Initialize before referring to a given linker set. 44 */ 45#define SET_DECLARE(set, ptype) \ 46 extern ptype *__CONCAT(__start_set_,set); \ 47 extern ptype *__CONCAT(__stop_set_,set) 48 49#define SET_BEGIN(set) \ 50 (&__CONCAT(__start_set_,set)) 51#define SET_LIMIT(set) \ 52 (&__CONCAT(__stop_set_,set)) 53 54/* 55 * Iterate over all the elements of a set. 56 * 57 * Sets always contain addresses of things, and "pvar" points to words 58 * containing those addresses. Thus is must be declared as "type **pvar", 59 * and the address of each set item is obtained inside the loop by "*pvar". 60 */ 61#define SET_FOREACH(pvar, set) \ 62 for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++) 63 64#endif /* _FBSD_COMPAT_SYS_LINKER_SET_H_ */ 65