xref: /openbsd-src/lib/libc/arch/DEFS.h (revision c1a45aed656e7d5627c30c92421893a76f370ccb)
1 /*	$OpenBSD: DEFS.h,v 1.1 2022/01/01 23:47:14 guenther 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 #else
24 # define _FUNC_TYPE	#function
25 #endif
26 
27 /*
28  * We define a hidden alias with the prefix "_libc_" for each global symbol
29  * that may be used internally.  By referencing _libc_x instead of x, other
30  * parts of libc prevent overriding by the application and avoid unnecessary
31  * relocations.
32  */
33 #define _HIDDEN(x)		_libc_##x
34 #define _HIDDEN_ALIAS(x,y)			\
35 	STRONG_ALIAS(_HIDDEN(x),y);		\
36 	.hidden _HIDDEN(x)
37 #define _HIDDEN_FALIAS(x,y)			\
38 	_HIDDEN_ALIAS(x,y);			\
39 	.type _HIDDEN(x),_FUNC_TYPE
40 
41 /*
42  * For functions implemented in ASM that aren't syscalls.
43  *   END_STRONG(x)	Like DEF_STRONG() in C; for standard/reserved C names
44  *   END_WEAK(x)	Like DEF_WEAK() in C; for non-ISO C names
45  *   END_BUILTIN(x)	If compiling with clang, then just END() and
46  *			mark it .protected, else be like END_STRONG();
47  *			for clang builtins like memcpy
48  *
49  * If a 'BUILTIN' function needs be referenced by other ASM code, then use
50  *   _BUILTIN(x)	If compiled with clang, then just x, otherwise
51  *			_HIDDEN(x)
52  *
53  *   _END(x)		Set a size on a symbol, like END(), but even for
54  *			symbols with no matching ENTRY().  (On alpha and
55  *			mips64, END() generates .end which requires a
56  *			matching .ent from ENTRY())
57  */
58 #define	END_STRONG(x)	END(x); _HIDDEN_FALIAS(x,x); _END(_HIDDEN(x))
59 #define	END_WEAK(x)	END_STRONG(x); .weak x
60 
61 #ifdef __clang__
62 #define	END_BUILTIN(x)	END(x); .protected x
63 #define	_BUILTIN(x)	x
64 #else
65 #define	END_BUILTIN(x)	END_STRONG(x)
66 #define	_BUILTIN(x)	_HIDDEN(x)
67 #endif
68 
69 #define _END(x)		.size x, . - x
70