vm: reduce noise in merged pagetable.c
[minix.git] / include / sys / cdefs_elf.h
blob4872136b65e9ffa1c43e7d3ab3d8e8245129a01f
1 /* $NetBSD: cdefs_elf.h,v 1.34 2010/12/08 01:18:55 joerg Exp $ */
3 /*
4 * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5 * All rights reserved.
7 * Author: Chris G. Demetriou
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.
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 * Carnegie Mellon requests users of this software to return to
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
26 * any improvements or extensions that they make and grant Carnegie the
27 * rights to redistribute these changes.
30 #ifndef _SYS_CDEFS_ELF_H_
31 #define _SYS_CDEFS_ELF_H_
33 #ifdef __LEADING_UNDERSCORE
34 #define _C_LABEL(x) __CONCAT(_,x)
35 #define _C_LABEL_STRING(x) "_"x
36 #else
37 #define _C_LABEL(x) x
38 #define _C_LABEL_STRING(x) x
39 #endif
41 #if __STDC__
42 #define ___RENAME(x) __asm(___STRING(_C_LABEL(x)))
43 #else
44 #ifdef __LEADING_UNDERSCORE
45 #define ___RENAME(x) ____RENAME(_/**/x)
46 #define ____RENAME(x) __asm(___STRING(x))
47 #else
48 #define ___RENAME(x) __asm(___STRING(x))
49 #endif
50 #endif
52 #define __indr_reference(sym,alias) /* nada, since we do weak refs */
54 #if __STDC__
55 #define __strong_alias(alias,sym) \
56 __asm(".global " _C_LABEL_STRING(#alias) "\n" \
57 _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
59 #define __weak_alias(alias,sym) \
60 __asm(".weak " _C_LABEL_STRING(#alias) "\n" \
61 _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
63 /* Do not use __weak_extern, use __weak_reference instead */
64 #define __weak_extern(sym) \
65 __asm(".weak " _C_LABEL_STRING(#sym));
67 #if __GNUC_PREREQ__(4, 0)
68 #define __weak_reference(sym) __attribute__((__weakref__))
69 #else
70 #define __weak_reference(sym) ; __asm(".weak " _C_LABEL_STRING(#sym))
71 #endif
73 #if defined(__clang__)
74 #define __warn_references(sym,msg) \
75 static __attribute__((__used__, __section__(".gnu.warning." #sym))) \
76 const char ___CONCAT(__warn_reference_##sym,__COUNTER__)[] = msg;
77 #else
78 #define __warn_references(sym,msg) \
79 __asm(".pushsection .gnu.warning." #sym "\n" \
80 ".ascii \"" msg "\"\n" \
81 ".popsection");
82 #endif
84 #else /* !__STDC__ */
86 #ifdef __LEADING_UNDERSCORE
87 #define __weak_alias(alias,sym) ___weak_alias(_/**/alias,_/**/sym)
88 #define ___weak_alias(alias,sym) \
89 __asm(".weak alias\nalias = sym");
90 #else
91 #define __weak_alias(alias,sym) \
92 __asm(".weak alias\nalias = sym");
93 #endif
94 #ifdef __LEADING_UNDERSCORE
95 #define __weak_extern(sym) ___weak_extern(_/**/sym)
96 #define ___weak_extern(sym) \
97 __asm(".weak sym");
98 #else
99 #define __weak_extern(sym) \
100 __asm(".weak sym");
101 #endif
102 #define __warn_references(sym,msg) \
103 __asm(".pushsection .gnu.warning.sym\n" \
104 ".ascii \"" msg "\"\n" \
105 ".popsection");
107 #endif /* !__STDC__ */
109 #if defined(__clang__)
110 #define __SECTIONSTRING(_sec, _str) \
111 static __attribute__((__used__, __section__(#_sec))) const char \
112 ___CONCAT(__sectstr,__COUNTER__)[] = _str
113 #elif __STDC__
114 #define __SECTIONSTRING(_sec, _str) \
115 __asm(".pushsection " #_sec "\n" \
116 ".asciz \"" _str "\"\n" \
117 ".popsection")
118 #else
119 #define __SECTIONSTRING(_sec, _str) \
120 __asm(".pushsection _sec\n" \
121 ".asciz \"" _str "\"\n" \
122 ".popsection")
123 #endif
125 #define __IDSTRING(_n,_s) __SECTIONSTRING(.ident,_s)
127 #define __RCSID(_s) __IDSTRING(rcsid,_s)
128 #define __SCCSID(_s)
129 #define __SCCSID2(_s)
130 #define __COPYRIGHT(_s) __SECTIONSTRING(.copyright,_s)
132 #define __KERNEL_RCSID(_n, _s) __RCSID(_s)
133 #define __KERNEL_SCCSID(_n, _s)
134 #define __KERNEL_COPYRIGHT(_n, _s) __COPYRIGHT(_s)
136 #ifndef __lint__
137 #define __link_set_make_entry(set, sym) \
138 static void const * const __link_set_##set##_sym_##sym \
139 __section("link_set_" #set) __used = &sym
140 #define __link_set_make_entry2(set, sym, n) \
141 static void const * const __link_set_##set##_sym_##sym##_##n \
142 __section("link_set_" #set) __used = &sym[n]
143 #else
144 #define __link_set_make_entry(set, sym) \
145 extern void const * const __link_set_##set##_sym_##sym
146 #define __link_set_make_entry2(set, sym, n) \
147 extern void const * const __link_set_##set##_sym_##sym##_##n
148 #endif /* __lint__ */
150 #define __link_set_add_text(set, sym) __link_set_make_entry(set, sym)
151 #define __link_set_add_rodata(set, sym) __link_set_make_entry(set, sym)
152 #define __link_set_add_data(set, sym) __link_set_make_entry(set, sym)
153 #define __link_set_add_bss(set, sym) __link_set_make_entry(set, sym)
154 #define __link_set_add_text2(set, sym, n) __link_set_make_entry2(set, sym, n)
155 #define __link_set_add_rodata2(set, sym, n) __link_set_make_entry2(set, sym, n)
156 #define __link_set_add_data2(set, sym, n) __link_set_make_entry2(set, sym, n)
157 #define __link_set_add_bss2(set, sym, n) __link_set_make_entry2(set, sym, n)
159 #define __link_set_decl(set, ptype) \
160 extern ptype * const __start_link_set_##set[]; \
161 extern ptype * const __stop_link_set_##set[] \
163 #define __link_set_start(set) (__start_link_set_##set)
164 #define __link_set_end(set) (__stop_link_set_##set)
166 #define __link_set_count(set) \
167 (__link_set_end(set) - __link_set_start(set))
170 #ifdef _KERNEL
173 * On multiprocessor systems we can gain an improvement in performance
174 * by being mindful of which cachelines data is placed in.
176 * __read_mostly:
178 * It makes sense to ensure that rarely modified data is not
179 * placed in the same cacheline as frequently modified data.
180 * To mitigate the phenomenon known as "false-sharing" we
181 * can annotate rarely modified variables with __read_mostly.
182 * All such variables are placed into the .data.read_mostly
183 * section in the kernel ELF.
185 * Prime candidates for __read_mostly annotation are variables
186 * which are hardly ever modified and which are used in code
187 * hot-paths, e.g. pmap_initialized.
189 * __cacheline_aligned:
191 * Some data structures (mainly locks) benefit from being aligned
192 * on a cacheline boundary, and having a cacheline to themselves.
193 * This way, the modification of other data items cannot adversely
194 * affect the lock and vice versa.
196 * Any variables annotated with __cacheline_aligned will be
197 * placed into the .data.cacheline_aligned ELF section.
199 #define __read_mostly \
200 __attribute__((__section__(".data.read_mostly")))
202 #define __cacheline_aligned \
203 __attribute__((__aligned__(COHERENCY_UNIT) \
204 __section__(".data.cacheline_aligned")))
206 #endif /* _KERNEL */
208 #endif /* !_SYS_CDEFS_ELF_H_ */