xref: /aosp_15_r20/external/elfutils/libelf/elf-knowledge.h (revision 7304104da70ce23c86437a01be71edd1a2d7f37e)
1*7304104dSAndroid Build Coastguard Worker /* Accumulation of various pieces of knowledge about ELF.
2*7304104dSAndroid Build Coastguard Worker    Copyright (C) 2000-2012, 2014, 2016 Red Hat, Inc.
3*7304104dSAndroid Build Coastguard Worker    This file is part of elfutils.
4*7304104dSAndroid Build Coastguard Worker    Written by Ulrich Drepper <[email protected]>, 2000.
5*7304104dSAndroid Build Coastguard Worker 
6*7304104dSAndroid Build Coastguard Worker    This file is free software; you can redistribute it and/or modify
7*7304104dSAndroid Build Coastguard Worker    it under the terms of either
8*7304104dSAndroid Build Coastguard Worker 
9*7304104dSAndroid Build Coastguard Worker      * the GNU Lesser General Public License as published by the Free
10*7304104dSAndroid Build Coastguard Worker        Software Foundation; either version 3 of the License, or (at
11*7304104dSAndroid Build Coastguard Worker        your option) any later version
12*7304104dSAndroid Build Coastguard Worker 
13*7304104dSAndroid Build Coastguard Worker    or
14*7304104dSAndroid Build Coastguard Worker 
15*7304104dSAndroid Build Coastguard Worker      * the GNU General Public License as published by the Free
16*7304104dSAndroid Build Coastguard Worker        Software Foundation; either version 2 of the License, or (at
17*7304104dSAndroid Build Coastguard Worker        your option) any later version
18*7304104dSAndroid Build Coastguard Worker 
19*7304104dSAndroid Build Coastguard Worker    or both in parallel, as here.
20*7304104dSAndroid Build Coastguard Worker 
21*7304104dSAndroid Build Coastguard Worker    elfutils is distributed in the hope that it will be useful, but
22*7304104dSAndroid Build Coastguard Worker    WITHOUT ANY WARRANTY; without even the implied warranty of
23*7304104dSAndroid Build Coastguard Worker    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24*7304104dSAndroid Build Coastguard Worker    General Public License for more details.
25*7304104dSAndroid Build Coastguard Worker 
26*7304104dSAndroid Build Coastguard Worker    You should have received copies of the GNU General Public License and
27*7304104dSAndroid Build Coastguard Worker    the GNU Lesser General Public License along with this program.  If
28*7304104dSAndroid Build Coastguard Worker    not, see <http://www.gnu.org/licenses/>.  */
29*7304104dSAndroid Build Coastguard Worker 
30*7304104dSAndroid Build Coastguard Worker #ifndef _ELF_KNOWLEDGE_H
31*7304104dSAndroid Build Coastguard Worker #define _ELF_KNOWLEDGE_H	1
32*7304104dSAndroid Build Coastguard Worker 
33*7304104dSAndroid Build Coastguard Worker #include <stdbool.h>
34*7304104dSAndroid Build Coastguard Worker 
35*7304104dSAndroid Build Coastguard Worker 
36*7304104dSAndroid Build Coastguard Worker /* Test whether a section can be stripped or not.  */
37*7304104dSAndroid Build Coastguard Worker #define SECTION_STRIP_P(shdr, name, remove_comment) \
38*7304104dSAndroid Build Coastguard Worker   /* Sections which are allocated are not removed.  */			      \
39*7304104dSAndroid Build Coastguard Worker   (((shdr)->sh_flags & SHF_ALLOC) == 0					      \
40*7304104dSAndroid Build Coastguard Worker    /* We never remove .note sections.  */				      \
41*7304104dSAndroid Build Coastguard Worker    && (shdr)->sh_type != SHT_NOTE					      \
42*7304104dSAndroid Build Coastguard Worker    && (((shdr)->sh_type) != SHT_PROGBITS				      \
43*7304104dSAndroid Build Coastguard Worker        /* Never remove .gnu.warning.* sections.  */			      \
44*7304104dSAndroid Build Coastguard Worker        || (name != NULL							      \
45*7304104dSAndroid Build Coastguard Worker 	   && strncmp (name, ".gnu.warning.", sizeof ".gnu.warning." - 1) != 0\
46*7304104dSAndroid Build Coastguard Worker 	   /* We remove .comment sections only if explicitly told to do so. */\
47*7304104dSAndroid Build Coastguard Worker 	   && (remove_comment						      \
48*7304104dSAndroid Build Coastguard Worker 	       || strcmp (name, ".comment") != 0))))
49*7304104dSAndroid Build Coastguard Worker 
50*7304104dSAndroid Build Coastguard Worker 
51*7304104dSAndroid Build Coastguard Worker /* Test whether `sh_info' field in section header contains a section
52*7304104dSAndroid Build Coastguard Worker    index.  There are two kinds of sections doing this:
53*7304104dSAndroid Build Coastguard Worker 
54*7304104dSAndroid Build Coastguard Worker    - the sections containing relocation information reference in this
55*7304104dSAndroid Build Coastguard Worker      field the section to which the relocations apply;
56*7304104dSAndroid Build Coastguard Worker 
57*7304104dSAndroid Build Coastguard Worker    - section with the SHF_INFO_LINK flag set to signal that `sh_info'
58*7304104dSAndroid Build Coastguard Worker      references a section.  This allows correct handling of unknown
59*7304104dSAndroid Build Coastguard Worker      sections.  */
60*7304104dSAndroid Build Coastguard Worker #define SH_INFO_LINK_P(Shdr) \
61*7304104dSAndroid Build Coastguard Worker   ((Shdr)->sh_type == SHT_REL || (Shdr)->sh_type == SHT_RELA		      \
62*7304104dSAndroid Build Coastguard Worker    || ((Shdr)->sh_flags & SHF_INFO_LINK) != 0)
63*7304104dSAndroid Build Coastguard Worker 
64*7304104dSAndroid Build Coastguard Worker 
65*7304104dSAndroid Build Coastguard Worker /* Size of an entry in the hash table.  The ELF specification says all
66*7304104dSAndroid Build Coastguard Worker    entries are regardless of platform 32-bits in size.  Early 64-bit
67*7304104dSAndroid Build Coastguard Worker    ports (namely Alpha for Linux) got this wrong.  The wording was not
68*7304104dSAndroid Build Coastguard Worker    clear.
69*7304104dSAndroid Build Coastguard Worker 
70*7304104dSAndroid Build Coastguard Worker    Several years later the ABI for the 64-bit S390s was developed.
71*7304104dSAndroid Build Coastguard Worker    Many things were copied from the IA-64 ABI (which uses the correct
72*7304104dSAndroid Build Coastguard Worker    32-bit entry size) but it does get the SHT_HASH entry size wrong by
73*7304104dSAndroid Build Coastguard Worker    using a 64-bit entry size.  So now we need this macro to special
74*7304104dSAndroid Build Coastguard Worker    case both the alpha and s390x ABIs.  */
75*7304104dSAndroid Build Coastguard Worker #define SH_ENTSIZE_HASH(Ehdr) \
76*7304104dSAndroid Build Coastguard Worker   ((Ehdr)->e_machine == EM_ALPHA					      \
77*7304104dSAndroid Build Coastguard Worker    || ((Ehdr)->e_machine == EM_S390					      \
78*7304104dSAndroid Build Coastguard Worker        && (Ehdr)->e_ident[EI_CLASS] == ELFCLASS64) ? 8 : 4)
79*7304104dSAndroid Build Coastguard Worker 
80*7304104dSAndroid Build Coastguard Worker /* GNU Annobin notes are not fully standardized and abuses the owner name.  */
81*7304104dSAndroid Build Coastguard Worker 
82*7304104dSAndroid Build Coastguard Worker #define ELF_NOTE_GNU_BUILD_ATTRIBUTE_PREFIX "GA"
83*7304104dSAndroid Build Coastguard Worker 
84*7304104dSAndroid Build Coastguard Worker #define NT_GNU_BUILD_ATTRIBUTE_OPEN 0x100
85*7304104dSAndroid Build Coastguard Worker #define NT_GNU_BUILD_ATTRIBUTE_FUNC 0x101
86*7304104dSAndroid Build Coastguard Worker 
87*7304104dSAndroid Build Coastguard Worker #define GNU_BUILD_ATTRIBUTE_TYPE_NUMERIC	'*'
88*7304104dSAndroid Build Coastguard Worker #define GNU_BUILD_ATTRIBUTE_TYPE_STRING		'$'
89*7304104dSAndroid Build Coastguard Worker #define GNU_BUILD_ATTRIBUTE_TYPE_BOOL_TRUE	'+'
90*7304104dSAndroid Build Coastguard Worker #define GNU_BUILD_ATTRIBUTE_TYPE_BOOL_FALSE	'!'
91*7304104dSAndroid Build Coastguard Worker 
92*7304104dSAndroid Build Coastguard Worker #define GNU_BUILD_ATTRIBUTE_VERSION	1
93*7304104dSAndroid Build Coastguard Worker #define GNU_BUILD_ATTRIBUTE_STACK_PROT	2
94*7304104dSAndroid Build Coastguard Worker #define GNU_BUILD_ATTRIBUTE_RELRO	3
95*7304104dSAndroid Build Coastguard Worker #define GNU_BUILD_ATTRIBUTE_STACK_SIZE	4
96*7304104dSAndroid Build Coastguard Worker #define GNU_BUILD_ATTRIBUTE_TOOL	5
97*7304104dSAndroid Build Coastguard Worker #define GNU_BUILD_ATTRIBUTE_ABI		6
98*7304104dSAndroid Build Coastguard Worker #define GNU_BUILD_ATTRIBUTE_PIC		7
99*7304104dSAndroid Build Coastguard Worker #define GNU_BUILD_ATTRIBUTE_SHORT_ENUM	8
100*7304104dSAndroid Build Coastguard Worker 
101*7304104dSAndroid Build Coastguard Worker #endif	/* elf-knowledge.h */
102