xref: /netbsd-src/sys/sys/cdefs_aout.h (revision 256d995a314d7add086e744c78ec28176be917e8)
1 /*	$NetBSD: cdefs_aout.h,v 1.21 2024/05/29 02:06:46 riastradh Exp $	*/
2 
3 /*
4  * Written by J.T. Conklin <jtc@wimsey.com> 01/17/95.
5  * Public domain.
6  */
7 
8 #ifndef _SYS_CDEFS_AOUT_H_
9 #define	_SYS_CDEFS_AOUT_H_
10 
11 #define	_C_LABEL(x)		__CONCAT(_,x)
12 #define	_C_LABEL_STRING(x)	"_"x
13 
14 #if __STDC__
15 #define	___RENAME(x)	__asm(___STRING(_C_LABEL(x)))
16 #else
17 #define	___RENAME(x)	____RENAME(_/**/x)
18 #define	____RENAME(x)	__asm(___STRING(x))
19 #endif
20 
21 #define	__indr_reference(sym,alias)	/* nada, since we do weak refs */
22 
23 #ifdef __GNUC__
24 #if __STDC__
25 #define	__strong_alias(alias,sym)	       				\
26     __asm(".global " _C_LABEL_STRING(#alias) "\n"			\
27 	    _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
28 #define	__weak_alias(alias,sym)						\
29     __asm(".weak " _C_LABEL_STRING(#alias) "\n"			\
30 	    _C_LABEL_STRING(#alias) " = " _C_LABEL_STRING(#sym));
31 
32 /* Do not use __weak_extern, use __weak_reference instead */
33 #define	__weak_extern(sym)						\
34     __asm(".weak " _C_LABEL_STRING(#sym));
35 
36 #if __GNUC_PREREQ__(4, 0)
37 #define	__weak_reference(sym)	__attribute__((__weakref__))
38 #else
39 #define	__weak_reference(sym)	; __asm(".weak " _C_LABEL_STRING(#sym))
40 #endif
41 
42 #define	__warn_references(sym,msg)					\
43 	__asm(".stabs \"" msg "\",30,0,0,0");				\
44 	__asm(".stabs \"_" #sym "\",1,0,0,0");
45 #else /* __STDC__ */
46 #define	__weak_alias(alias,sym) ___weak_alias(_/**/alias,_/**/sym)
47 #define	___weak_alias(alias,sym)					\
48     __asm(".weak alias\nalias = sym");
49 /* Do not use __weak_extern, use __weak_reference instead */
50 #define	__weak_extern(sym) ___weak_extern(_/**/sym)
51 #define	___weak_extern(sym)						\
52     __asm(".weak sym");
53 
54 #if __GNUC_PREREQ__(4, 0)
55 #define	__weak_reference(sym)	__attribute__((__weakref__))
56 #else
57 #define	___weak_reference(sym)	; __asm(".weak sym");
58 #define	__weak_reference(sym)	___weak_reference(_/**/sym)
59 #endif
60 
61 #define	__warn_references(sym,msg)					\
62 	__asm(".stabs msg,30,0,0,0");					\
63 	__asm(".stabs \"_/**/sym\",1,0,0,0");
64 #endif /* __STDC__ */
65 #else /* __GNUC__ */
66 #define	__warn_references(sym,msg)
67 #endif /* __GNUC__ */
68 
69 #if defined(__sh__)		/* XXX SH COFF */
70 #undef __indr_reference(sym,alias)
71 #undef __warn_references(sym,msg)
72 #define	__warn_references(sym,msg)
73 #endif
74 
75 #define	__IDSTRING(_n,_s)						\
76 	__asm(".data ; .asciz \"" _s "\" ; .text")
77 
78 #undef __KERNEL_RCSID
79 
80 #ifdef _NETBSD_REVISIONID
81 #define	__RCSID(_s)							      \
82 	__IDSTRING(rcsid,_s);						      \
83 	__IDSTRING(revisionid,						      \
84 	    "$" "NetBSD: " __FILE__ " " _NETBSD_REVISIONID " $")
85 #else
86 #define	__RCSID(_s)	__IDSTRING(rcsid,_s)
87 #endif
88 #define	__SCCSID(_s)
89 #define	__SCCSID2(_s)
90 #if 0	/* XXX userland __COPYRIGHTs have \ns in them */
91 #define	__COPYRIGHT(_s)	__IDSTRING(copyright,_s)
92 #else
93 #define	__COPYRIGHT(_s)							\
94 	static const char copyright[] __attribute__((__unused__)) = _s
95 #endif
96 
97 #if defined(USE_KERNEL_RCSIDS) || !defined(_KERNEL)
98 #define	__KERNEL_RCSID(_n,_s) __IDSTRING(__CONCAT(rcsid,_n),_s)
99 #else
100 #define	__KERNEL_RCSID(_n,_s)
101 #endif
102 #define	__KERNEL_SCCSID(_n,_s)
103 #define	__KERNEL_COPYRIGHT(_n, _s) __IDSTRING(__CONCAT(copyright,_n),_s)
104 
105 #ifndef __lint__
106 #define	__link_set_make_entry(set, sym, type)				\
107 	static void const * const					\
108 	    __link_set_##set##_sym_##sym __used = &sym;		\
109 	__asm(".stabs \"___link_set_" #set "\", " #type ", 0, 0, _" #sym)
110 #else
111 #define	__link_set_make_entry(set, sym, type)				\
112 	extern void const * const __link_set_##set##_sym_##sym
113 #endif /* __lint__ */
114 
115 #define	__link_set_add_text(set, sym)	__link_set_make_entry(set, sym, 23)
116 #define	__link_set_add_rodata(set, sym)	__link_set_make_entry(set, sym, 23)
117 #define	__link_set_add_data(set, sym)	__link_set_make_entry(set, sym, 25)
118 #define	__link_set_add_bss(set, sym)	__link_set_make_entry(set, sym, 27)
119 
120 #define	__link_set_decl(set, ptype)					\
121 extern struct {								\
122 	int	__ls_length;						\
123 	ptype	*__ls_items[1];						\
124 } __link_set_##set
125 
126 #define	__link_set_start(set)	(&(__link_set_##set).__ls_items[0])
127 #define	__link_set_end(set)						\
128 	(&(__link_set_##set).__ls_items[(__link_set_##set).__ls_length])
129 
130 #define	__link_set_count(set)	((__link_set_##set).__ls_length)
131 
132 #endif /* !_SYS_CDEFS_AOUT_H_ */
133