Brian Silverman | 8649792 | 2018-02-10 19:28:39 -0500 | [diff] [blame] | 1 | /* Return section name. |
| 2 | Copyright (C) 2001, 2002, 2004 Red Hat, Inc. |
| 3 | This file is part of elfutils. |
| 4 | Written by Ulrich Drepper <drepper@redhat.com>, 2001. |
| 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 | #ifdef HAVE_CONFIG_H |
| 31 | # include <config.h> |
| 32 | #endif |
| 33 | |
| 34 | #include <stdio.h> |
| 35 | #include <libeblP.h> |
| 36 | |
| 37 | |
| 38 | const char * |
| 39 | ebl_section_name (Ebl *ebl, int section, int xsection, char *buf, size_t len, |
| 40 | const char *scnnames[], size_t shnum) |
| 41 | { |
| 42 | const char *res = ebl != NULL ? ebl->section_name (section, xsection, |
| 43 | buf, len) : NULL; |
| 44 | |
| 45 | if (res == NULL) |
| 46 | { |
| 47 | if (section == SHN_UNDEF) |
| 48 | res = "UNDEF"; |
| 49 | else if (section == SHN_ABS) |
| 50 | res = "ABS"; |
| 51 | else if (section == SHN_COMMON) |
| 52 | res = "COMMON"; |
| 53 | else if (section == SHN_BEFORE) |
| 54 | res = "BEFORE"; |
| 55 | else if (section == SHN_AFTER) |
| 56 | res = "AFTER"; |
| 57 | else if ((section < SHN_LORESERVE || section == SHN_XINDEX) |
| 58 | && (size_t) section < shnum) |
| 59 | { |
| 60 | int idx = section != SHN_XINDEX ? section : xsection; |
| 61 | |
| 62 | if (scnnames != NULL) |
| 63 | res = scnnames[idx]; |
| 64 | else |
| 65 | { |
| 66 | snprintf (buf, len, "%d", idx); |
| 67 | res = buf; |
| 68 | } |
| 69 | } |
| 70 | else |
| 71 | { |
| 72 | /* Handle OS-specific section names. */ |
| 73 | if (section == SHN_XINDEX) |
| 74 | snprintf (buf, len, "%s: %d", "XINDEX", xsection); |
| 75 | else if (section >= SHN_LOOS && section <= SHN_HIOS) |
| 76 | snprintf (buf, len, "LOOS+%x", section - SHN_LOOS); |
| 77 | /* Handle processor-specific section names. */ |
| 78 | else if (section >= SHN_LOPROC && section <= SHN_HIPROC) |
| 79 | snprintf (buf, len, "LOPROC+%x", section - SHN_LOPROC); |
| 80 | else if (section >= SHN_LORESERVE && section <= SHN_HIRESERVE) |
| 81 | snprintf (buf, len, "LORESERVE+%x", section - SHN_LORESERVE); |
| 82 | else |
| 83 | snprintf (buf, len, "%s: %d", gettext ("<unknown>"), section); |
| 84 | |
| 85 | res = buf; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | return res; |
| 90 | } |