xref: /openbsd-src/lib/libc/arch/DEFS.h (revision 5bcead818ba71dc1c4fad02a24986a5b47ae1c58)
1 /*	$OpenBSD: DEFS.h,v 1.4 2023/12/11 22:24:15 kettenis Exp $	*/
2 /*
3  * Copyright (c) 2015,2018,2021 Philip Guenther <guenther@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #include <machine/asm.h>
19 
20 /* ARM just had to be different... */
21 #ifndef __arm__
22 # define _FUNC_TYPE	@function
23 # define _PROGBITS	@progbits
24 #else
25 # define _FUNC_TYPE	#function
26 # define _PROGBITS	%progbits
27 #endif
28 
29 /*
30  * We define a hidden alias with the prefix "_libc_" for each global symbol
31  * that may be used internally.  By referencing _libc_x instead of x, other
32  * parts of libc prevent overriding by the application and avoid unnecessary
33  * relocations.
34  */
35 #define _HIDDEN(x)		_libc_##x
36 #define _HIDDEN_ALIAS(x,y)			\
37 	STRONG_ALIAS(_HIDDEN(x),y);		\
38 	.hidden _HIDDEN(x)
39 #define _HIDDEN_FALIAS(x,y)			\
40 	_HIDDEN_ALIAS(x,y);			\
41 	.type _HIDDEN(x),_FUNC_TYPE
42 
43 /*
44  * For functions implemented in ASM that aren't syscalls.
45  *   END_STRONG(x)	Like DEF_STRONG() in C; for standard/reserved C names
46  *   END_WEAK(x)	Like DEF_WEAK() in C; for non-ISO C names
47  *   END_BUILTIN(x)	If compiling with clang, then just END() and
48  *			mark it .protected, else be like END_STRONG();
49  *			for clang builtins like memcpy
50  *
51  * If a 'BUILTIN' function needs be referenced by other ASM code, then use
52  *   _BUILTIN(x)	If compiled with clang, then just x, otherwise
53  *			_HIDDEN(x)
54  *
55  *   _END(x)		Set a size on a symbol, like END(), but even for
56  *			symbols with no matching ENTRY().  (On alpha and
57  *			mips64, END() generates .end which requires a
58  *			matching .ent from ENTRY())
59  */
60 #define	END_STRONG(x)	END(x); _HIDDEN_FALIAS(x,x); _END(_HIDDEN(x))
61 #define	END_WEAK(x)	END_STRONG(x); .weak x
62 
63 #ifdef __clang__
64 #define	END_BUILTIN(x)	END(x); .protected x
65 #define	_BUILTIN(x)	x
66 #else
67 #define	END_BUILTIN(x)	END_STRONG(x)
68 #define	_BUILTIN(x)	_HIDDEN(x)
69 #endif
70 
71 #define _END(x)		.size x, . - x
72 
73 #define PINSYSCALL(sysno, label)					\
74 	.pushsection .openbsd.syscalls,"",_PROGBITS;			\
75 	.p2align 2;							\
76 	.long label;							\
77 	.long sysno;							\
78 	.popsection;
79