xref: /openbsd/lib/libc/arch/i386/DEFS.h (revision 73471bf0)
1 /*	$OpenBSD: DEFS.h,v 1.3 2017/11/29 05:13:57 guenther Exp $ */
2 /*
3  * Copyright (c) 2017 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 /*
21  * We define a hidden alias with the prefix "_libc_" for each global symbol
22  * that may be used internally.  By referencing _libc_x instead of x, other
23  * parts of libc prevent overriding by the application and avoid unnecessary
24  * relocations.
25  */
26 #define _HIDDEN(x)		_libc_##x
27 #define _HIDDEN_ALIAS(x,y)			\
28 	STRONG_ALIAS(_HIDDEN(x),y);		\
29 	.hidden _HIDDEN(x)
30 #define _HIDDEN_FALIAS(x,y)			\
31 	_HIDDEN_ALIAS(x,y);			\
32 	.type _HIDDEN(x),@function
33 
34 /*
35  * For functions implemented in ASM that aren't syscalls.
36  *   END_STRONG(x)	Like DEF_STRONG() in C; for standard/reserved C names
37  *   END_WEAK(x)	Like DEF_WEAK() in C; for non-ISO C names
38  *   END_BUILTIN(x)	If compiling with clang, then just END() and
39  *			mark it .protected, else be like END_STRONG();
40  *			for clang builtins like memcpy
41  */
42 #define	END_STRONG(x)	END(x); _HIDDEN_FALIAS(x,x); END(_HIDDEN(x))
43 #define	END_WEAK(x)	END_STRONG(x); .weak x
44 
45 #ifdef __clang__
46 #define	END_BUILTIN(x)	END(x); .protected x
47 #else
48 #define	END_BUILTIN(x)	END_STRONG(x)
49 #endif
50