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