Annotation of src/sys/sys/cdefs_elf.h, Revision 1.44
1.44 ! christos 1: /* $NetBSD: cdefs_elf.h,v 1.43 2013/02/07 18:53:34 gdt Exp $ */
1.1 thorpej 2:
3: /*
4: * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5: * All rights reserved.
6: *
7: * Author: Chris G. Demetriou
1.22 perry 8: *
1.1 thorpej 9: * Permission to use, copy, modify and distribute this software and
10: * its documentation is hereby granted, provided that both the copyright
11: * notice and this permission notice appear in all copies of the
12: * software, derivative works or modified versions, and any portions
13: * thereof, and that both notices appear in supporting documentation.
1.22 perry 14: *
15: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
1.1 thorpej 17: * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
1.22 perry 18: *
1.1 thorpej 19: * Carnegie Mellon requests users of this software to return to
20: *
21: * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22: * School of Computer Science
23: * Carnegie Mellon University
24: * Pittsburgh PA 15213-3890
25: *
26: * any improvements or extensions that they make and grant Carnegie the
27: * rights to redistribute these changes.
28: */
29:
30: #ifndef _SYS_CDEFS_ELF_H_
31: #define _SYS_CDEFS_ELF_H_
32:
1.10 msaitoh 33: #ifdef __LEADING_UNDERSCORE
1.7 itohy 34: #define _C_LABEL(x) __CONCAT(_,x)
1.9 marcus 35: #define _C_LABEL_STRING(x) "_"x
1.5 itojun 36: #else
1.1 thorpej 37: #define _C_LABEL(x) x
1.9 marcus 38: #define _C_LABEL_STRING(x) x
1.7 itohy 39: #endif
40:
1.8 kleink 41: #if __STDC__
1.26 perry 42: #define ___RENAME(x) __asm(___STRING(_C_LABEL(x)))
1.7 itohy 43: #else
1.10 msaitoh 44: #ifdef __LEADING_UNDERSCORE
1.7 itohy 45: #define ___RENAME(x) ____RENAME(_/**/x)
1.26 perry 46: #define ____RENAME(x) __asm(___STRING(x))
1.7 itohy 47: #else
1.26 perry 48: #define ___RENAME(x) __asm(___STRING(x))
1.7 itohy 49: #endif
1.5 itojun 50: #endif
1.1 thorpej 51:
52: #define __indr_reference(sym,alias) /* nada, since we do weak refs */
53:
1.8 kleink 54: #if __STDC__
1.14 thorpej 55: #define __strong_alias(alias,sym) \
1.26 perry 56: __asm(".global " _C_LABEL_STRING(#alias) "\n" \
1.14 thorpej 57: _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
1.1 thorpej 58:
59: #define __weak_alias(alias,sym) \
1.26 perry 60: __asm(".weak " _C_LABEL_STRING(#alias) "\n" \
1.9 marcus 61: _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
1.27 christos 62:
63: /* Do not use __weak_extern, use __weak_reference instead */
1.3 kleink 64: #define __weak_extern(sym) \
1.26 perry 65: __asm(".weak " _C_LABEL_STRING(#sym));
1.27 christos 66:
67: #if __GNUC_PREREQ__(4, 0)
1.36 joerg 68: #define __weak_reference(sym) __attribute__((__weakref__(#sym)))
1.27 christos 69: #else
70: #define __weak_reference(sym) ; __asm(".weak " _C_LABEL_STRING(#sym))
71: #endif
72:
1.36 joerg 73: #if __GNUC_PREREQ__(4, 2)
74: #define __weakref_visible static
75: #else
76: #define __weakref_visible extern
77: #endif
78:
1.1 thorpej 79: #define __warn_references(sym,msg) \
1.28 uwe 80: __asm(".pushsection .gnu.warning." #sym "\n" \
81: ".ascii \"" msg "\"\n" \
82: ".popsection");
1.1 thorpej 83:
84: #else /* !__STDC__ */
85:
1.10 msaitoh 86: #ifdef __LEADING_UNDERSCORE
1.9 marcus 87: #define __weak_alias(alias,sym) ___weak_alias(_/**/alias,_/**/sym)
88: #define ___weak_alias(alias,sym) \
1.26 perry 89: __asm(".weak alias\nalias = sym");
1.9 marcus 90: #else
1.1 thorpej 91: #define __weak_alias(alias,sym) \
1.26 perry 92: __asm(".weak alias\nalias = sym");
1.9 marcus 93: #endif
1.10 msaitoh 94: #ifdef __LEADING_UNDERSCORE
1.9 marcus 95: #define __weak_extern(sym) ___weak_extern(_/**/sym)
96: #define ___weak_extern(sym) \
1.26 perry 97: __asm(".weak sym");
1.9 marcus 98: #else
1.3 kleink 99: #define __weak_extern(sym) \
1.26 perry 100: __asm(".weak sym");
1.9 marcus 101: #endif
1.1 thorpej 102: #define __warn_references(sym,msg) \
1.28 uwe 103: __asm(".pushsection .gnu.warning.sym\n" \
104: ".ascii \"" msg "\"\n" \
105: ".popsection");
1.1 thorpej 106:
107: #endif /* !__STDC__ */
108:
1.35 joerg 109: #if __STDC__
1.1 thorpej 110: #define __SECTIONSTRING(_sec, _str) \
1.28 uwe 111: __asm(".pushsection " #_sec "\n" \
112: ".asciz \"" _str "\"\n" \
113: ".popsection")
1.1 thorpej 114: #else
115: #define __SECTIONSTRING(_sec, _str) \
1.28 uwe 116: __asm(".pushsection _sec\n" \
117: ".asciz \"" _str "\"\n" \
118: ".popsection")
1.1 thorpej 119: #endif
120:
1.2 thorpej 121: #define __IDSTRING(_n,_s) __SECTIONSTRING(.ident,_s)
122:
123: #define __RCSID(_s) __IDSTRING(rcsid,_s)
1.6 explorer 124: #define __SCCSID(_s)
125: #define __SCCSID2(_s)
1.2 thorpej 126: #define __COPYRIGHT(_s) __SECTIONSTRING(.copyright,_s)
1.1 thorpej 127:
128: #define __KERNEL_RCSID(_n, _s) __RCSID(_s)
1.6 explorer 129: #define __KERNEL_SCCSID(_n, _s)
1.1 thorpej 130: #define __KERNEL_COPYRIGHT(_n, _s) __COPYRIGHT(_s)
1.13 thorpej 131:
132: #ifndef __lint__
133: #define __link_set_make_entry(set, sym) \
134: static void const * const __link_set_##set##_sym_##sym \
1.42 matt 135: __section("link_set_" #set) __used = (const void *)&sym
1.18 matt 136: #define __link_set_make_entry2(set, sym, n) \
137: static void const * const __link_set_##set##_sym_##sym##_##n \
1.42 matt 138: __section("link_set_" #set) __used = (const void *)&sym[n]
1.13 thorpej 139: #else
140: #define __link_set_make_entry(set, sym) \
141: extern void const * const __link_set_##set##_sym_##sym
1.18 matt 142: #define __link_set_make_entry2(set, sym, n) \
143: extern void const * const __link_set_##set##_sym_##sym##_##n
1.13 thorpej 144: #endif /* __lint__ */
145:
146: #define __link_set_add_text(set, sym) __link_set_make_entry(set, sym)
147: #define __link_set_add_rodata(set, sym) __link_set_make_entry(set, sym)
148: #define __link_set_add_data(set, sym) __link_set_make_entry(set, sym)
149: #define __link_set_add_bss(set, sym) __link_set_make_entry(set, sym)
1.18 matt 150: #define __link_set_add_text2(set, sym, n) __link_set_make_entry2(set, sym, n)
151: #define __link_set_add_rodata2(set, sym, n) __link_set_make_entry2(set, sym, n)
152: #define __link_set_add_data2(set, sym, n) __link_set_make_entry2(set, sym, n)
153: #define __link_set_add_bss2(set, sym, n) __link_set_make_entry2(set, sym, n)
1.13 thorpej 154:
1.19 matt 155: #define __link_set_start(set) (__start_link_set_##set)
156: #define __link_set_end(set) (__stop_link_set_##set)
1.13 thorpej 157:
1.44 ! christos 158: #define __link_set_decl(set, ptype) \
! 159: extern ptype * const __link_set_start(set)[] __dso_hidden; \
! 160: extern ptype * const __link_set_end(set)[] __dso_hidden
! 161:
1.13 thorpej 162: #define __link_set_count(set) \
163: (__link_set_end(set) - __link_set_start(set))
1.1 thorpej 164:
1.32 cegger 165:
166: #ifdef _KERNEL
167:
1.31 mjf 168: /*
169: * On multiprocessor systems we can gain an improvement in performance
170: * by being mindful of which cachelines data is placed in.
171: *
172: * __read_mostly:
173: *
174: * It makes sense to ensure that rarely modified data is not
175: * placed in the same cacheline as frequently modified data.
176: * To mitigate the phenomenon known as "false-sharing" we
177: * can annotate rarely modified variables with __read_mostly.
178: * All such variables are placed into the .data.read_mostly
179: * section in the kernel ELF.
180: *
181: * Prime candidates for __read_mostly annotation are variables
182: * which are hardly ever modified and which are used in code
183: * hot-paths, e.g. pmap_initialized.
184: *
185: * __cacheline_aligned:
186: *
187: * Some data structures (mainly locks) benefit from being aligned
188: * on a cacheline boundary, and having a cacheline to themselves.
189: * This way, the modification of other data items cannot adversely
190: * affect the lock and vice versa.
191: *
192: * Any variables annotated with __cacheline_aligned will be
193: * placed into the .data.cacheline_aligned ELF section.
194: */
195: #define __read_mostly \
196: __attribute__((__section__(".data.read_mostly")))
197:
198: #define __cacheline_aligned \
1.37 plunky 199: __attribute__((__aligned__(COHERENCY_UNIT), \
1.31 mjf 200: __section__(".data.cacheline_aligned")))
201:
1.32 cegger 202: #endif /* _KERNEL */
203:
1.1 thorpej 204: #endif /* !_SYS_CDEFS_ELF_H_ */
CVSweb <webmaster@jp.NetBSD.org>