Ben Cheng | 25b3c04 | 2013-11-20 14:45:36 -0800 | [diff] [blame^] | 1 | /* SPARC specific symbolic name handling. |
| 2 | Copyright (C) 2002, 2003, 2005, 2007, 2008 Red Hat, Inc. |
| 3 | This file is part of Red Hat elfutils. |
| 4 | Written by Jakub Jelinek <jakub@redhat.com>, 2002. |
| 5 | |
| 6 | Red Hat elfutils is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by the |
| 8 | Free Software Foundation; version 2 of the License. |
| 9 | |
| 10 | Red Hat elfutils is distributed in the hope that it will be useful, but |
| 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along |
| 16 | with Red Hat elfutils; if not, write to the Free Software Foundation, |
| 17 | Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA. |
| 18 | |
| 19 | Red Hat elfutils is an included package of the Open Invention Network. |
| 20 | An included package of the Open Invention Network is a package for which |
| 21 | Open Invention Network licensees cross-license their patents. No patent |
| 22 | license is granted, either expressly or impliedly, by designation as an |
| 23 | included package. Should you wish to participate in the Open Invention |
| 24 | Network licensing program, please visit www.openinventionnetwork.com |
| 25 | <http://www.openinventionnetwork.com>. */ |
| 26 | |
| 27 | #ifdef HAVE_CONFIG_H |
| 28 | # include <config.h> |
| 29 | #endif |
| 30 | |
| 31 | #include <elf.h> |
| 32 | #include <stddef.h> |
| 33 | |
| 34 | #define BACKEND sparc_ |
| 35 | #include "libebl_CPU.h" |
| 36 | |
| 37 | /* Check for the simple reloc types. */ |
| 38 | Elf_Type |
| 39 | sparc_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type) |
| 40 | { |
| 41 | switch (type) |
| 42 | { |
| 43 | case R_SPARC_8: |
| 44 | return ELF_T_BYTE; |
| 45 | case R_SPARC_16: |
| 46 | case R_SPARC_UA16: |
| 47 | return ELF_T_HALF; |
| 48 | case R_SPARC_32: |
| 49 | case R_SPARC_UA32: |
| 50 | return ELF_T_WORD; |
| 51 | case R_SPARC_64: |
| 52 | case R_SPARC_UA64: |
| 53 | return ELF_T_XWORD; |
| 54 | default: |
| 55 | return ELF_T_NUM; |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | /* Check whether machine flags are valid. */ |
| 60 | bool |
| 61 | sparc_machine_flag_check (GElf_Word flags) |
| 62 | { |
| 63 | return ((flags &~ (EF_SPARCV9_MM |
| 64 | | EF_SPARC_LEDATA |
| 65 | | EF_SPARC_32PLUS |
| 66 | | EF_SPARC_SUN_US1 |
| 67 | | EF_SPARC_SUN_US3)) == 0); |
| 68 | } |
| 69 | |
| 70 | bool |
| 71 | sparc_check_special_section (Ebl *ebl, |
| 72 | int ndx __attribute__ ((unused)), |
| 73 | const GElf_Shdr *shdr, |
| 74 | const char *sname __attribute__ ((unused))) |
| 75 | { |
| 76 | if ((shdr->sh_flags & (SHF_WRITE | SHF_EXECINSTR)) |
| 77 | == (SHF_WRITE | SHF_EXECINSTR)) |
| 78 | { |
| 79 | /* This is ordinarily flagged, but is valid for a PLT on SPARC. |
| 80 | |
| 81 | Look for the SHT_DYNAMIC section and the DT_PLTGOT tag in it. |
| 82 | Its d_ptr should match the .plt section's sh_addr. */ |
| 83 | |
| 84 | Elf_Scn *scn = NULL; |
| 85 | while ((scn = elf_nextscn (ebl->elf, scn)) != NULL) |
| 86 | { |
| 87 | GElf_Shdr scn_shdr; |
| 88 | if (likely (gelf_getshdr (scn, &scn_shdr) != NULL) |
| 89 | && scn_shdr.sh_type == SHT_DYNAMIC |
| 90 | && scn_shdr.sh_entsize != 0) |
| 91 | { |
| 92 | Elf_Data *data = elf_getdata (scn, NULL); |
| 93 | if (data != NULL) |
| 94 | for (size_t i = 0; i < data->d_size / scn_shdr.sh_entsize; ++i) |
| 95 | { |
| 96 | GElf_Dyn dyn; |
| 97 | if (unlikely (gelf_getdyn (data, i, &dyn) == NULL)) |
| 98 | break; |
| 99 | if (dyn.d_tag == DT_PLTGOT) |
| 100 | return dyn.d_un.d_ptr == shdr->sh_addr; |
| 101 | } |
| 102 | break; |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | return false; |
| 108 | } |
| 109 | |
| 110 | const char * |
| 111 | sparc_symbol_type_name (int type, |
| 112 | char *buf __attribute__ ((unused)), |
| 113 | size_t len __attribute__ ((unused))) |
| 114 | { |
| 115 | switch (type) |
| 116 | { |
| 117 | case STT_SPARC_REGISTER: |
| 118 | return "SPARC_REGISTER"; |
| 119 | } |
| 120 | return NULL; |
| 121 | } |
| 122 | |
| 123 | const char * |
| 124 | sparc_dynamic_tag_name (int64_t tag, |
| 125 | char *buf __attribute__ ((unused)), |
| 126 | size_t len __attribute__ ((unused))) |
| 127 | { |
| 128 | switch (tag) |
| 129 | { |
| 130 | case DT_SPARC_REGISTER: |
| 131 | return "SPARC_REGISTER"; |
| 132 | } |
| 133 | return NULL; |
| 134 | } |
| 135 | |
| 136 | bool |
| 137 | sparc_dynamic_tag_check (int64_t tag) |
| 138 | { |
| 139 | switch (tag) |
| 140 | { |
| 141 | case DT_SPARC_REGISTER: |
| 142 | return true; |
| 143 | } |
| 144 | return false; |
| 145 | } |