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