Ulrich Drepper | b08d5a8 | 2005-07-26 05:00:05 +0000 | [diff] [blame^] | 1 | /* Check whether section can be stripped. |
| 2 | Copyright (C) 2005 Red Hat, Inc. |
| 3 | |
| 4 | This program is Open Source software; you can redistribute it and/or |
| 5 | modify it under the terms of the Open Software License version 1.0 as |
| 6 | published by the Open Source Initiative. |
| 7 | |
| 8 | You should have received a copy of the Open Software License along |
| 9 | with this program; if not, you may obtain a copy of the Open Software |
| 10 | License version 1.0 from http://www.opensource.org/licenses/osl.php or |
| 11 | by writing the Open Source Initiative c/o Lawrence Rosen, Esq., |
| 12 | 3001 King Ranch Road, Ukiah, CA 95482. */ |
| 13 | |
| 14 | #ifdef HAVE_CONFIG_H |
| 15 | # include <config.h> |
| 16 | #endif |
| 17 | |
| 18 | #include <string.h> |
| 19 | #include "libeblP.h" |
| 20 | |
| 21 | |
| 22 | bool |
| 23 | ebl_section_strip_p (Ebl *ebl, const GElf_Ehdr *ehdr, const GElf_Shdr *shdr, |
| 24 | const char *name, bool remove_comment, |
| 25 | bool only_remove_debug) |
| 26 | { |
| 27 | /* If only debug information should be removed check the name. There |
| 28 | is unfortunately no other way. */ |
| 29 | if (unlikely (only_remove_debug)) |
| 30 | { |
| 31 | if (ebl_debugscn_p (ebl, name)) |
| 32 | return true; |
| 33 | |
| 34 | if (shdr->sh_type == SHT_RELA || shdr->sh_type == SHT_REL) |
| 35 | { |
| 36 | Elf_Scn *scn_l = elf_getscn (ebl->elf, (shdr)->sh_info); |
| 37 | GElf_Shdr shdr_mem_l; |
| 38 | GElf_Shdr *shdr_l = gelf_getshdr (scn_l, &shdr_mem_l); |
| 39 | if (shdr_l == NULL) |
| 40 | { |
| 41 | const char *s_l = elf_strptr (ebl->elf, ehdr->e_shstrndx, |
| 42 | shdr_l->sh_name); |
| 43 | if (s_l != NULL && ebl_debugscn_p (ebl, s_l)) |
| 44 | return true; |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return false; |
| 49 | } |
| 50 | |
| 51 | return SECTION_STRIP_P (shdr, name, remove_comment); |
| 52 | } |