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