xref: /freebsd/sys/sys/elf_generic.h (revision 95ee2897)
1ca0154bcSJohn Polstra /*-
24d846d26SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
3c4e20cadSPedro F. Giffuni  *
4ca0154bcSJohn Polstra  * Copyright (c) 1998 John D. Polstra.
5ca0154bcSJohn Polstra  * All rights reserved.
6ca0154bcSJohn Polstra  *
7ca0154bcSJohn Polstra  * Redistribution and use in source and binary forms, with or without
8ca0154bcSJohn Polstra  * modification, are permitted provided that the following conditions
9ca0154bcSJohn Polstra  * are met:
10ca0154bcSJohn Polstra  * 1. Redistributions of source code must retain the above copyright
11ca0154bcSJohn Polstra  *    notice, this list of conditions and the following disclaimer.
12ca0154bcSJohn Polstra  * 2. Redistributions in binary form must reproduce the above copyright
13ca0154bcSJohn Polstra  *    notice, this list of conditions and the following disclaimer in the
14ca0154bcSJohn Polstra  *    documentation and/or other materials provided with the distribution.
15ca0154bcSJohn Polstra  *
16ca0154bcSJohn Polstra  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17ca0154bcSJohn Polstra  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18ca0154bcSJohn Polstra  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19ca0154bcSJohn Polstra  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20ca0154bcSJohn Polstra  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21ca0154bcSJohn Polstra  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22ca0154bcSJohn Polstra  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23ca0154bcSJohn Polstra  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24ca0154bcSJohn Polstra  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25ca0154bcSJohn Polstra  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26ca0154bcSJohn Polstra  * SUCH DAMAGE.
27ca0154bcSJohn Polstra  */
28ca0154bcSJohn Polstra 
29ca0154bcSJohn Polstra #ifndef _SYS_ELF_GENERIC_H_
30ca0154bcSJohn Polstra #define	_SYS_ELF_GENERIC_H_ 1
31ca0154bcSJohn Polstra 
32ca0154bcSJohn Polstra #include <sys/cdefs.h>
33ca0154bcSJohn Polstra 
34ca0154bcSJohn Polstra /*
35ca0154bcSJohn Polstra  * Definitions of generic ELF names which relieve applications from
36ca0154bcSJohn Polstra  * needing to know the word size.
37ca0154bcSJohn Polstra  */
38ca0154bcSJohn Polstra 
39ca0154bcSJohn Polstra #if __ELF_WORD_SIZE != 32 && __ELF_WORD_SIZE != 64
40ca0154bcSJohn Polstra #error "__ELF_WORD_SIZE must be defined as 32 or 64"
41ca0154bcSJohn Polstra #endif
42ca0154bcSJohn Polstra 
43c8afdc1dSJohn Polstra #define	ELF_CLASS	__CONCAT(ELFCLASS,__ELF_WORD_SIZE)
44c8afdc1dSJohn Polstra 
45c8afdc1dSJohn Polstra #if BYTE_ORDER == LITTLE_ENDIAN
46c8afdc1dSJohn Polstra #define	ELF_DATA	ELFDATA2LSB
47c8afdc1dSJohn Polstra #elif BYTE_ORDER == BIG_ENDIAN
48c8afdc1dSJohn Polstra #define	ELF_DATA	ELFDATA2MSB
49c8afdc1dSJohn Polstra #else
50c8afdc1dSJohn Polstra #error "Unknown byte order"
51c8afdc1dSJohn Polstra #endif
52c8afdc1dSJohn Polstra 
533ebc1248SPeter Wemm #define	__elfN(x)	__CONCAT(__CONCAT(__CONCAT(elf,__ELF_WORD_SIZE),_),x)
54ca0154bcSJohn Polstra #define	__ElfN(x)	__CONCAT(__CONCAT(__CONCAT(Elf,__ELF_WORD_SIZE),_),x)
55ca0154bcSJohn Polstra #define	__ELFN(x)	__CONCAT(__CONCAT(__CONCAT(ELF,__ELF_WORD_SIZE),_),x)
56ca0154bcSJohn Polstra #define	__ElfType(x)	typedef __ElfN(x) __CONCAT(Elf_,x)
57ca0154bcSJohn Polstra 
5834e7e4b6SDimitry Andric /* Define ElfW for compatibility with Linux, prefer __ElfN() in FreeBSD code */
5934e7e4b6SDimitry Andric #define	ElfW(x)		__ElfN(x)
6034e7e4b6SDimitry Andric 
61ca0154bcSJohn Polstra __ElfType(Addr);
62ca0154bcSJohn Polstra __ElfType(Half);
63ca0154bcSJohn Polstra __ElfType(Off);
64ca0154bcSJohn Polstra __ElfType(Sword);
65ca0154bcSJohn Polstra __ElfType(Word);
66ca0154bcSJohn Polstra __ElfType(Ehdr);
67ca0154bcSJohn Polstra __ElfType(Shdr);
68ca0154bcSJohn Polstra __ElfType(Phdr);
69ca0154bcSJohn Polstra __ElfType(Dyn);
70ca0154bcSJohn Polstra __ElfType(Rel);
71ca0154bcSJohn Polstra __ElfType(Rela);
721cf06333SFangrui Song __ElfType(Relr);
73ca0154bcSJohn Polstra __ElfType(Sym);
740eb88f20SAlexander Kabaev __ElfType(Verdef);
750eb88f20SAlexander Kabaev __ElfType(Verdaux);
760eb88f20SAlexander Kabaev __ElfType(Verneed);
770eb88f20SAlexander Kabaev __ElfType(Vernaux);
780eb88f20SAlexander Kabaev __ElfType(Versym);
79ca0154bcSJohn Polstra 
80757686b1SMarcel Moolenaar /* Non-standard ELF types. */
81757686b1SMarcel Moolenaar __ElfType(Hashelt);
82757686b1SMarcel Moolenaar __ElfType(Size);
83757686b1SMarcel Moolenaar __ElfType(Ssize);
84757686b1SMarcel Moolenaar 
85ca0154bcSJohn Polstra #define	ELF_R_SYM	__ELFN(R_SYM)
86ca0154bcSJohn Polstra #define	ELF_R_TYPE	__ELFN(R_TYPE)
87ca0154bcSJohn Polstra #define	ELF_R_INFO	__ELFN(R_INFO)
88ca0154bcSJohn Polstra #define	ELF_ST_BIND	__ELFN(ST_BIND)
89ca0154bcSJohn Polstra #define	ELF_ST_TYPE	__ELFN(ST_TYPE)
90ca0154bcSJohn Polstra #define	ELF_ST_INFO	__ELFN(ST_INFO)
91148ed9d8SKonstantin Belousov #define	ELF_ST_VISIBILITY	__ELFN(ST_VISIBILITY)
92ca0154bcSJohn Polstra 
93ca0154bcSJohn Polstra #endif /* !_SYS_ELF_GENERIC_H_ */
94