142645Sjdp/*- 242645Sjdp * Copyright (c) 1999 John D. Polstra 378161Speter * Copyright (c) 1999,2001 Peter Wemm <peter@FreeBSD.org> 442645Sjdp * All rights reserved. 542645Sjdp * 642645Sjdp * Redistribution and use in source and binary forms, with or without 742645Sjdp * modification, are permitted provided that the following conditions 842645Sjdp * are met: 942645Sjdp * 1. Redistributions of source code must retain the above copyright 1042645Sjdp * notice, this list of conditions and the following disclaimer. 1142645Sjdp * 2. Redistributions in binary form must reproduce the above copyright 1242645Sjdp * notice, this list of conditions and the following disclaimer in the 1342645Sjdp * documentation and/or other materials provided with the distribution. 1442645Sjdp * 1542645Sjdp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1642645Sjdp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1742645Sjdp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1842645Sjdp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1942645Sjdp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2042645Sjdp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2142645Sjdp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2242645Sjdp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2342645Sjdp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2442645Sjdp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2542645Sjdp * SUCH DAMAGE. 2642645Sjdp * 2750477Speter * $FreeBSD$ 2842645Sjdp */ 2942645Sjdp 3042645Sjdp#ifndef _SYS_LINKER_SET_H_ 3142645Sjdp#define _SYS_LINKER_SET_H_ 3242645Sjdp 33143063Sjoerg#ifndef _SYS_CDEFS_H_ 34143063Sjoerg#error this file needs sys/cdefs.h as a prerequisite 35143063Sjoerg#endif 36143063Sjoerg 3742645Sjdp/* 3842645Sjdp * The following macros are used to declare global sets of objects, which 3978161Speter * are collected by the linker into a `linker_set' as defined below. 4042645Sjdp * For ELF, this is done by constructing a separate segment for each set. 4178161Speter */ 4278161Speter 4378161Speter/* 4478161Speter * Private macros, not to be used outside this header file. 4578161Speter */ 46143063Sjoerg#ifdef __GNUCLIKE___SECTION 4778161Speter#define __MAKE_SET(set, sym) \ 48215701Sdim __GLOBL(__CONCAT(__start_set_,set)); \ 49215701Sdim __GLOBL(__CONCAT(__stop_set_,set)); \ 5078161Speter static void const * const __set_##set##_sym_##sym \ 51132783Skan __section("set_" #set) __used = &sym 52143063Sjoerg#else /* !__GNUCLIKE___SECTION */ 5395200Smarkm#ifndef lint 54143063Sjoerg#error this file needs to be ported to your compiler 5595200Smarkm#endif /* lint */ 5695200Smarkm#define __MAKE_SET(set, sym) extern void const * const (__set_##set##_sym_##sym) 57143063Sjoerg#endif /* __GNUCLIKE___SECTION */ 5878161Speter 5978161Speter/* 6078161Speter * Public macros. 6178161Speter */ 6278161Speter#define TEXT_SET(set, sym) __MAKE_SET(set, sym) 6378161Speter#define DATA_SET(set, sym) __MAKE_SET(set, sym) 6478161Speter#define BSS_SET(set, sym) __MAKE_SET(set, sym) 6578161Speter#define ABS_SET(set, sym) __MAKE_SET(set, sym) 6678161Speter#define SET_ENTRY(set, sym) __MAKE_SET(set, sym) 6778161Speter 6878161Speter/* 69140231Skeramida * Initialize before referring to a given linker set. 7078161Speter */ 71283326Sian#define SET_DECLARE(set, ptype) \ 72284880Shselasky extern ptype __weak_symbol *__CONCAT(__start_set_,set); \ 73284880Shselasky extern ptype __weak_symbol *__CONCAT(__stop_set_,set) 7478161Speter 7578161Speter#define SET_BEGIN(set) \ 7678161Speter (&__CONCAT(__start_set_,set)) 7778161Speter#define SET_LIMIT(set) \ 7878161Speter (&__CONCAT(__stop_set_,set)) 7978161Speter 8078161Speter/* 8178161Speter * Iterate over all the elements of a set. 8278161Speter * 8378161Speter * Sets always contain addresses of things, and "pvar" points to words 8478161Speter * containing those addresses. Thus is must be declared as "type **pvar", 8578161Speter * and the address of each set item is obtained inside the loop by "*pvar". 8642645Sjdp */ 8778161Speter#define SET_FOREACH(pvar, set) \ 8878161Speter for (pvar = SET_BEGIN(set); pvar < SET_LIMIT(set); pvar++) 8942645Sjdp 9078161Speter#define SET_ITEM(set, i) \ 9178161Speter ((SET_BEGIN(set))[i]) 9242645Sjdp 9378161Speter/* 9478161Speter * Provide a count of the items in a set. 9578161Speter */ 9678161Speter#define SET_COUNT(set) \ 9778161Speter (SET_LIMIT(set) - SET_BEGIN(set)) 9842645Sjdp 9978161Speter#endif /* _SYS_LINKER_SET_H_ */ 100