• 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 <system.h>
34 
35 #include <elf.h>
36 #include <stddef.h>
37 #include <string.h>
38 
39 #define BACKEND		arm_
40 #include "libebl_CPU.h"
41 
42 
43 const char *
arm_segment_type_name(int segment,char * buf,size_t len)44 arm_segment_type_name (int segment, char *buf __attribute__ ((unused)),
45 		       size_t len __attribute__ ((unused)))
46 {
47   switch (segment)
48     {
49     case PT_ARM_EXIDX:
50       return "ARM_EXIDX";
51     }
52   return NULL;
53 }
54 
55 /* Return symbolic representation of section type.  */
56 const char *
arm_section_type_name(int type,char * buf,size_t len)57 arm_section_type_name (int type,
58 		       char *buf __attribute__ ((unused)),
59 		       size_t len __attribute__ ((unused)))
60 {
61   switch (type)
62     {
63     case SHT_ARM_EXIDX:
64       return "ARM_EXIDX";
65     case SHT_ARM_PREEMPTMAP:
66       return "ARM_PREEMPTMAP";
67     case SHT_ARM_ATTRIBUTES:
68       return "ARM_ATTRIBUTES";
69     }
70 
71   return NULL;
72 }
73 
74 /* Check whether machine flags are valid.  */
75 bool
arm_machine_flag_check(GElf_Word flags)76 arm_machine_flag_check (GElf_Word flags)
77 {
78   switch (flags & EF_ARM_EABIMASK)
79     {
80     case EF_ARM_EABI_UNKNOWN:
81     case EF_ARM_EABI_VER1:
82     case EF_ARM_EABI_VER2:
83     case EF_ARM_EABI_VER3:
84     case EF_ARM_EABI_VER4:
85     case EF_ARM_EABI_VER5:
86       break;
87     default:
88       return false;
89     }
90 
91   return ((flags &~ (EF_ARM_EABIMASK
92 		     | EF_ARM_RELEXEC
93 		     | EF_ARM_HASENTRY
94 		     | EF_ARM_INTERWORK
95 		     | EF_ARM_APCS_26
96 		     | EF_ARM_APCS_FLOAT
97 		     | EF_ARM_PIC
98 		     | EF_ARM_ALIGN8
99 		     | EF_ARM_NEW_ABI
100 		     | EF_ARM_OLD_ABI
101 		     | EF_ARM_SOFT_FLOAT
102 		     | EF_ARM_VFP_FLOAT
103 		     | EF_ARM_MAVERICK_FLOAT
104 		     | EF_ARM_SYMSARESORTED
105 		     | EF_ARM_DYNSYMSUSESEGIDX
106 		     | EF_ARM_MAPSYMSFIRST
107 		     | EF_ARM_EABIMASK
108 		     | EF_ARM_BE8
109 		     | EF_ARM_LE8)) == 0);
110 }
111 
112 /* Check for the simple reloc types.  */
113 Elf_Type
arm_reloc_simple_type(Ebl * ebl,int type,int * addsub)114 arm_reloc_simple_type (Ebl *ebl __attribute__ ((unused)), int type,
115 		       int *addsub __attribute__ ((unused)))
116 {
117   switch (type)
118     {
119     case R_ARM_ABS32:
120       return ELF_T_WORD;
121     case R_ARM_ABS16:
122       return ELF_T_HALF;
123     case R_ARM_ABS8:
124       return ELF_T_BYTE;
125     default:
126       return ELF_T_NUM;
127     }
128 }
129 
130 /* The SHT_ARM_EXIDX section type is a valid target for relocation.  */
131 bool
arm_check_reloc_target_type(Ebl * ebl,Elf64_Word sh_type)132 arm_check_reloc_target_type (Ebl *ebl __attribute__ ((unused)), Elf64_Word sh_type)
133 {
134   return sh_type == SHT_ARM_EXIDX;
135 }
136 
137 const char *
arm_symbol_type_name(int type,char * buf,size_t len)138 arm_symbol_type_name (int type,
139 		      char *buf __attribute__ ((unused)),
140 		      size_t len __attribute__ ((unused)))
141 {
142   switch (type)
143     {
144     case STT_ARM_TFUNC:
145       return "ARM_TFUNC";
146     }
147   return NULL;
148 }
149 
150 /* A data mapping symbol is a symbol with "$d" name or "$d.<any...>" name,
151  *    STT_NOTYPE, STB_LOCAL and st_size of zero. The indicate the stat of a
152  *       sequence of data items.  */
153 bool
arm_data_marker_symbol(const GElf_Sym * sym,const char * sname)154 arm_data_marker_symbol (const GElf_Sym *sym, const char *sname)
155 {
156   return (sym != NULL && sname != NULL
157           && sym->st_size == 0 && GELF_ST_BIND (sym->st_info) == STB_LOCAL
158           && GELF_ST_TYPE (sym->st_info) == STT_NOTYPE
159           && (strcmp (sname, "$d") == 0 || startswith (sname, "$d.")));
160 }
161