xref: /minix/sys/sys/cdefs_elf.h (revision 84d9c625)
1 /*	$NetBSD: cdefs_elf.h,v 1.43 2013/02/07 18:53:34 gdt Exp $	*/
2 
3 /*
4  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
5  * All rights reserved.
6  *
7  * Author: Chris G. Demetriou
8  *
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.
14  *
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.
18  *
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 
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
40 
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
51 
52 #define	__indr_reference(sym,alias)	/* nada, since we do weak refs */
53 
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));
58 
59 #if defined(__minix) && !defined(__weak_alias) /* For bitcode support */
60 #define	__weak_alias(alias,sym)						\
61     __asm(".weak " _C_LABEL_STRING(#alias) "\n"			\
62 	    _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
63 #endif
64 
65 /* Do not use __weak_extern, use __weak_reference instead */
66 #define	__weak_extern(sym)						\
67     __asm(".weak " _C_LABEL_STRING(#sym));
68 
69 #if __GNUC_PREREQ__(4, 0)
70 #define	__weak_reference(sym)	__attribute__((__weakref__(#sym)))
71 #else
72 #define	__weak_reference(sym)	; __asm(".weak " _C_LABEL_STRING(#sym))
73 #endif
74 
75 #if __GNUC_PREREQ__(4, 2)
76 #define	__weakref_visible	static
77 #else
78 #define	__weakref_visible	extern
79 #endif
80 
81 #define	__warn_references(sym,msg)					\
82     __asm(".pushsection .gnu.warning." #sym "\n"			\
83 	  ".ascii \"" msg "\"\n"					\
84 	  ".popsection");
85 
86 #else /* !__STDC__ */
87 
88 #ifdef __LEADING_UNDERSCORE
89 #define __weak_alias(alias,sym) ___weak_alias(_/**/alias,_/**/sym)
90 #define	___weak_alias(alias,sym)					\
91     __asm(".weak alias\nalias = sym");
92 #else
93 #define	__weak_alias(alias,sym)						\
94     __asm(".weak alias\nalias = sym");
95 #endif
96 #ifdef __LEADING_UNDERSCORE
97 #define __weak_extern(sym) ___weak_extern(_/**/sym)
98 #define	___weak_extern(sym)						\
99     __asm(".weak sym");
100 #else
101 #define	__weak_extern(sym)						\
102     __asm(".weak sym");
103 #endif
104 #define	__warn_references(sym,msg)					\
105     __asm(".pushsection .gnu.warning.sym\n"				\
106 	  ".ascii \"" msg "\"\n"					\
107 	  ".popsection");
108 
109 #endif /* !__STDC__ */
110 
111 #if __STDC__
112 #define	__SECTIONSTRING(_sec, _str)					\
113 	__asm(".pushsection " #_sec "\n"				\
114 	      ".asciz \"" _str "\"\n"					\
115 	      ".popsection")
116 #else
117 #define	__SECTIONSTRING(_sec, _str)					\
118 	__asm(".pushsection _sec\n"					\
119 	      ".asciz \"" _str "\"\n"					\
120 	      ".popsection")
121 #endif
122 
123 #define	__IDSTRING(_n,_s)		__SECTIONSTRING(.ident,_s)
124 
125 #define	__RCSID(_s)			__IDSTRING(rcsid,_s)
126 #define	__SCCSID(_s)
127 #define __SCCSID2(_s)
128 #define	__COPYRIGHT(_s)			__SECTIONSTRING(.copyright,_s)
129 
130 #define	__KERNEL_RCSID(_n, _s)		__RCSID(_s)
131 #define	__KERNEL_SCCSID(_n, _s)
132 #define	__KERNEL_COPYRIGHT(_n, _s)	__COPYRIGHT(_s)
133 
134 #ifndef __lint__
135 #define	__link_set_make_entry(set, sym)					\
136 	static void const * const __link_set_##set##_sym_##sym		\
137 	    __section("link_set_" #set) __used = (const void *)&sym
138 #define	__link_set_make_entry2(set, sym, n)				\
139 	static void const * const __link_set_##set##_sym_##sym##_##n	\
140 	    __section("link_set_" #set) __used = (const void *)&sym[n]
141 #else
142 #define	__link_set_make_entry(set, sym)					\
143 	extern void const * const __link_set_##set##_sym_##sym
144 #define	__link_set_make_entry2(set, sym, n)				\
145 	extern void const * const __link_set_##set##_sym_##sym##_##n
146 #endif /* __lint__ */
147 
148 #define	__link_set_add_text(set, sym)	__link_set_make_entry(set, sym)
149 #define	__link_set_add_rodata(set, sym)	__link_set_make_entry(set, sym)
150 #define	__link_set_add_data(set, sym)	__link_set_make_entry(set, sym)
151 #define	__link_set_add_bss(set, sym)	__link_set_make_entry(set, sym)
152 #define	__link_set_add_text2(set, sym, n)   __link_set_make_entry2(set, sym, n)
153 #define	__link_set_add_rodata2(set, sym, n) __link_set_make_entry2(set, sym, n)
154 #define	__link_set_add_data2(set, sym, n)   __link_set_make_entry2(set, sym, n)
155 #define	__link_set_add_bss2(set, sym, n)    __link_set_make_entry2(set, sym, n)
156 
157 #define	__link_set_decl(set, ptype)					\
158 	extern ptype * const __start_link_set_##set[] __dso_hidden;	\
159 	extern ptype * const __stop_link_set_##set[] __dso_hidden
160 
161 #define	__link_set_start(set)	(__start_link_set_##set)
162 #define	__link_set_end(set)	(__stop_link_set_##set)
163 
164 #define	__link_set_count(set)						\
165 	(__link_set_end(set) - __link_set_start(set))
166 
167 
168 #ifdef _KERNEL
169 
170 /*
171  * On multiprocessor systems we can gain an improvement in performance
172  * by being mindful of which cachelines data is placed in.
173  *
174  * __read_mostly:
175  *
176  *	It makes sense to ensure that rarely modified data is not
177  *	placed in the same cacheline as frequently modified data.
178  *	To mitigate the phenomenon known as "false-sharing" we
179  *	can annotate rarely modified variables with __read_mostly.
180  *	All such variables are placed into the .data.read_mostly
181  *	section in the kernel ELF.
182  *
183  *	Prime candidates for __read_mostly annotation are variables
184  *	which are hardly ever modified and which are used in code
185  *	hot-paths, e.g. pmap_initialized.
186  *
187  * __cacheline_aligned:
188  *
189  *	Some data structures (mainly locks) benefit from being aligned
190  *	on a cacheline boundary, and having a cacheline to themselves.
191  *	This way, the modification of other data items cannot adversely
192  *	affect the lock and vice versa.
193  *
194  *	Any variables annotated with __cacheline_aligned will be
195  *	placed into the .data.cacheline_aligned ELF section.
196  */
197 #define	__read_mostly						\
198     __attribute__((__section__(".data.read_mostly")))
199 
200 #define	__cacheline_aligned					\
201     __attribute__((__aligned__(COHERENCY_UNIT),			\
202 		 __section__(".data.cacheline_aligned")))
203 
204 #endif /* _KERNEL */
205 
206 #endif /* !_SYS_CDEFS_ELF_H_ */
207