• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Arm specific symbolic name handling.
2    Copyright (C) 2002-2009, 2014, 2015, 2017 Red Hat, Inc.
3    This file is part of elfutils.
4 
5    This file is free software; you can redistribute it and/or modify
6    it under the terms of either
7 
8      * the GNU Lesser General Public License as published by the Free
9        Software Foundation; either version 3 of the License, or (at
10        your option) any later version
11 
12    or
13 
14      * the GNU General Public License as published by the Free
15        Software Foundation; either version 2 of the License, or (at
16        your option) any later version
17 
18    or both in parallel, as here.
19 
20    elfutils is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
23    General Public License for more details.
24 
25    You should have received copies of the GNU General Public License and
26    the GNU Lesser General Public License along with this program.  If
27    not, see <http://www.gnu.org/licenses/>.  */
28 
29 #ifdef HAVE_CONFIG_H
30 # include <config.h>
31 #endif
32 
33 #include <elf.h>
34 #include <stddef.h>
35 #include <string.h>
36 
37 #define BACKEND		arm_
38 #include "libebl_CPU.h"
39 
40 
41 const char *
arm_segment_type_name(int segment,char * buf,size_t len)42 arm_segment_type_name (int segment, char *buf __attribute__ ((unused)),
43 		       size_t len __attribute__ ((unused)))
44 {
45   switch (segment)
46     {
47     case PT_ARM_EXIDX:
48       return "ARM_EXIDX";
49     }
50   return NULL;
51 }
52 
53 /* Return symbolic representation of section type.  */
54 const char *
arm_section_type_name(int type,char * buf,size_t len)55 arm_section_type_name (int type,
56 		       char *buf __attribute__ ((unused)),
57 		       size_t len __attribute__ ((unused)))
58 {
59   switch (type)
60     {
61     case SHT_ARM_EXIDX:
62       return "ARM_EXIDX";
63     case SHT_ARM_PREEMPTMAP:
64       return "ARM_PREEMPTMAP";
65     case SHT_ARM_ATTRIBUTES:
66       return "ARM_ATTRIBUTES";
67     }
68 
69   return NULL;
70 }
71 
72 /* Check whether machine flags are valid.  */
73 bool
arm_machine_flag_check(GElf_Word flags)74 arm_machine_flag_check (GElf_Word flags)
75 {
76   switch (flags & EF_ARM_EABIMASK)
77     {
78     case EF_ARM_EABI_UNKNOWN:
79     case EF_ARM_EABI_VER1:
80     case EF_ARM_EABI_VER2:
81     case EF_ARM_EABI_VER3:
82     case EF_ARM_EABI_VER4:
83     case EF_ARM_EABI_VER5:
84       break;
85     default:
86       return false;
87     }
88 
89   return ((flags &~ (EF_ARM_EABIMASK
90 		     | EF_ARM_RELEXEC
91 		     | EF_ARM_HASENTRY
92 		     | EF_ARM_INTERWORK
93 		     | EF_ARM_APCS_26
94 		     | EF_ARM_APCS_FLOAT
95 		     | EF_ARM_PIC
96 		     | EF_ARM_ALIGN8
97 		     | EF_ARM_NEW_ABI
98 		     | EF_ARM_OLD_ABI
99 		     | EF_ARM_SOFT_FLOAT
100 		     | EF_ARM_VFP_FLOAT
101 		     | EF_ARM_MAVERICK_FLOAT
102 		     | EF_ARM_SYMSARESORTED
103 		     | EF_ARM_DYNSYMSUSESEGIDX
104 		     | EF_ARM_MAPSYMSFIRST
105 		     | EF_ARM_EABIMASK
106 		     | EF_ARM_BE8
107 		     | EF_ARM_LE8)) == 0);
108 }
109 
110 /* Check for the simple reloc types.  */
111 Elf_Type
arm_reloc_simple_type(Ebl * ebl,int type,int * addsub)112 arm_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
113 		       int *addsub __attribute__ ((unused)))
114 {
115   switch (type)
116     {
117     case R_ARM_ABS32:
118       return ELF_T_WORD;
119     case R_ARM_ABS16:
120       return ELF_T_HALF;
121     case R_ARM_ABS8:
122       return ELF_T_BYTE;
123     default:
124       return ELF_T_NUM;
125     }
126 }
127 
128 /* The SHT_ARM_EXIDX section type is a valid target for relocation.  */
129 bool
arm_check_reloc_target_type(Ebl * ebl,Elf64_Word sh_type)130 arm_check_reloc_target_type (Ebl *ebl __attribute__ ((unused)), Elf64_Word sh_type)
131 {
132   return sh_type == SHT_ARM_EXIDX;
133 }
134 
135 const char *
arm_symbol_type_name(int type,char * buf,size_t len)136 arm_symbol_type_name (int type,
137 		      char *buf __attribute__ ((unused)),
138 		      size_t len __attribute__ ((unused)))
139 {
140   switch (type)
141     {
142     case STT_ARM_TFUNC:
143       return "ARM_TFUNC";
144     }
145   return NULL;
146 }
147 
148 /* A data mapping symbol is a symbol with "$d" name or "$d.<any...>" name,
149  *    STT_NOTYPE, STB_LOCAL and st_size of zero. The indicate the stat of a
150  *       sequence of data items.  */
151 bool
arm_data_marker_symbol(const GElf_Sym * sym,const char * sname)152 arm_data_marker_symbol (const GElf_Sym *sym, const char *sname)
153 {
154   return (sym != NULL && sname != NULL
155           && sym->st_size == 0 && GELF_ST_BIND (sym->st_info) == STB_LOCAL
156           && GELF_ST_TYPE (sym->st_info) == STT_NOTYPE
157           && (strcmp (sname, "$d") == 0 || strncmp (sname, "$d.", 3) == 0));
158 }
159