Debian Codegraph @

src/lib/libdwarf/dwarf_elf_rel_detector.c

raw
1 /*
2 Copyright (c) 2019, David Anderson
3 All rights reserved.
4 cc
5 Redistribution and use in source and binary forms, with
6 or without modification, are permitted provided that the
7 following conditions are met:
8
9 Redistributions of source code must retain the above
10 copyright notice, this list of conditions and the following
11 disclaimer.
12
13 Redistributions in binary form must reproduce the above
14 copyright notice, this list of conditions and the following
15 disclaimer in the documentation and/or other materials
16 provided with the distribution.
17
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 #include <config.h>
34
35 #include "dwarf_elf_defines.h"
36 #include "dwarf_elf_rel_detector.h"
37
38 unsigned
39 _dwarf_is_32bit_abs_reloc(unsigned int type, unsigned machine)
40 {
41 unsigned r = 0;
42
43 switch (machine) {
44 #if defined(EM_MIPS) && defined (R_MIPS_32)
45 case EM_MIPS:
46 r = (0
47 #if defined (R_MIPS_32)
48 | (type == R_MIPS_32)
49 #endif
50 #if defined (R_MIPS_TLS_DTPREL32)
51 | (type == R_MIPS_TLS_DTPREL32)
52 #endif /* DTPREL32 */
53 );
54 break;
55 #endif /* MIPS case */
56 #if defined(EM_SPARC32PLUS) && defined (R_SPARC_UA32)
57 case EM_SPARC32PLUS:
58 r = (0
59 #if defined(R_SPARC_UA32)
60 | (type == R_SPARC_UA32)
61 #endif
62 #if defined(R_SPARC_TLS_DTPOFF32)
63 | (type == R_SPARC_TLS_DTPOFF32)
64 #endif
65 );
66 break;
67 #endif
68 #if defined(EM_SPARCV9) && defined (R_SPARC_UA32)
69 case EM_SPARCV9:
70 r = (type == R_SPARC_UA32);
71 break;
72 #endif
73 #if defined(EM_SPARC) && defined (R_SPARC_UA32)
74 case EM_SPARC:
75 r = (0
76 #if defined(R_SPARC_UA32)
77 | (type == R_SPARC_UA32)
78 #endif
79 #if (R_SPARC_TLS_DTPOFF32)
80 | (type == R_SPARC_TLS_DTPOFF32)
81 #endif
82 );
83 break;
84 #endif /* EM_SPARC */
85 #if defined(EM_386) && defined (R_386_32) && defined (R_386_PC32)
86 case EM_386:
87 r = (0
88 #if defined (R_386_32)
89 | (type == R_386_32)
90 #endif
91 #if defined (R_386_GOTOFF)
92 | (type == R_386_GOTOFF)
93 #endif
94 #if defined (R_386_GOTPC)
95 | (type == R_386_GOTPC)
96 #endif
97 #if defined (R_386_PC32)
98 | (type == R_386_PC32)
99 #endif
100 #if defined (R_386_TLS_LDO_32)
101 | (type == R_386_TLS_LDO_32)
102 #endif
103 #if defined (R_386_TLS_DTPOFF32)
104 | (type == R_386_TLS_DTPOFF32)
105 #endif
106 );
107 break;
108 #endif /* EM_386 */
109
110 #if defined (EM_SH) && defined (R_SH_DIR32)
111 case EM_SH:
112 r = (0
113 #if defined (R_SH_DIR32)
114 | (type == R_SH_DIR32)
115 #endif
116 #if defined (R_SH_DTPOFF32)
117 | (type == R_SH_TLS_DTPOFF32)
118 #endif
119 );
120 break;
121 #endif /* SH */
122
123 #if defined(EM_IA_64) && defined (R_IA64_SECREL32LSB)
124 case EM_IA_64: /* 32bit? ! */
125 r = (0
126 #if defined (R_IA64_SECREL32LSB)
127 | (type == R_IA64_SECREL32LSB)
128 #endif
129 #if defined (R_IA64_DIR32LSB)
130 | (type == R_IA64_DIR32LSB)
131 #endif
132 #if defined (R_IA64_DTPREL32LSB)
133 | (type == R_IA64_DTPREL32LSB)
134 #endif
135 );
136 break;
137 #endif /* EM_IA_64 */
138
139 #if defined(EM_ARM) && defined (R_ARM_ABS32)
140 case EM_ARM:
141 case EM_AARCH64:
142 r = (0
143 #if defined (R_ARM_ABS32)
144 | ( type == R_ARM_ABS32)
145 #endif
146 #if defined (R_AARCH64_ABS32)
147 | ( type == R_AARCH64_ABS32)
148 #endif
149 #if defined (R_ARM_TLS_LDO32)
150 | ( type == R_ARM_TLS_LDO32)
151 #endif
152 );
153 break;
154 #endif /* EM_ARM */
155
156 /* On FreeBSD xR_PPC64_ADDR32 not defined
157 so we use the xR_PPC_ names which
158 have the proper value.
159 Our headers have:
160 xR_PPC64_ADDR64 38
161 xR_PPC_ADDR32 1 so we use this one
162 xR_PPC64_ADDR32 R_PPC_ADDR32
163
164 xR_PPC64_DTPREL32 110 which may be wrong/unavailable
165 xR_PPC64_DTPREL64 78
166 xR_PPC_DTPREL32 78
167 */
168 #if defined(EM_PPC64) && defined (R_PPC_ADDR32)
169 case EM_PPC64:
170 r = (0
171 #if defined(R_PPC_ADDR32)
172 | (type == R_PPC_ADDR32)
173 #endif
174 #if defined(R_PPC64_DTPREL32)
175 | (type == R_PPC64_DTPREL32)
176 #endif
177 );
178 break;
179 #endif /* EM_PPC64 */
180
181 #if defined(EM_PPC) && defined (R_PPC_ADDR32)
182 case EM_PPC:
183 r = (0
184 #if defined (R_PPC_ADDR32)
185 | (type == R_PPC_ADDR32)
186 #endif
187 #if defined (R_PPC_DTPREL32)
188 | (type == R_PPC_DTPREL32)
189 #endif
190 );
191 break;
192 #endif /* EM_PPC */
193
194 #if defined(EM_S390) && defined (R_390_32)
195 case EM_S390:
196 r = (0
197 #if defined (R_390_32)
198 | (type == R_390_32)
199 #endif
200 #if defined (R_390_TLS_LDO32)
201 | (type == R_390_TLS_LDO32)
202 #endif
203 );
204 break;
205 #endif /* EM_S390 */
206
207 #if defined(EM_X86_64) && \
208 ( defined(R_X86_64_32) || defined(R_X86_64_PC32) ||\
209 defined(R_X86_64_DTPOFF32) )
210 #if defined(EM_K10M)
211 case EM_K10M:
212 #endif
213 #if defined(EM_L10M)
214 case EM_L10M:
215 #endif
216 case EM_X86_64:
217 r = (0
218 #if defined (R_X86_64_PC32)
219 | (type == R_X86_64_PC32)
220 #endif
221 #if defined (R_X86_64_32)
222 | (type == R_X86_64_32)
223 #endif
224 #if defined (R_X86_64_DTPOFF32)
225 | (type == R_X86_64_DTPOFF32)
226 #endif
227 );
228 break;
229 #endif /* EM_X86_64 */
230
231 case EM_QUALCOMM_DSP6:
232 r = (type == R_QUALCOMM_REL32);
233 break;
234 default: break;
235 }
236 return r;
237 }
238
239 unsigned
240 _dwarf_is_64bit_abs_reloc(unsigned int type, unsigned machine)
241 {
242 unsigned r = 0;
243
244 switch (machine) {
245 #if defined(EM_MIPS) && defined (R_MIPS_64)
246 case EM_MIPS:
247 r = (0
248 #if defined (R_MIPS_64)
249 | (type == R_MIPS_64)
250 #endif
251 #if defined (R_MIPS_32)
252 | (type == R_MIPS_32)
253 #endif
254 #if defined(R_MIPS_TLS_DTPREL64)
255 | (type == R_MIPS_TLS_DTPREL64)
256 #endif
257 );
258 break;
259 #endif /* EM_MIPS */
260 #if defined(EM_SPARC32PLUS) && defined (R_SPARC_UA64)
261 case EM_SPARC32PLUS:
262 r = (type == R_SPARC_UA64);
263 break;
264 #endif
265 #if defined(EM_SPARCV9) && defined (R_SPARC_UA64)
266 case EM_SPARCV9:
267 r = (0
268 #if defined (R_SPARC_UA64)
269 | (type == R_SPARC_UA64)
270 #endif
271 #if defined (R_SPARC_TLS_DTPOFF64)
272 | (type == R_SPARC_TLS_DTPOFF64)
273 #endif
274 );
275 break;
276 #endif
277 #if defined(EM_SPARC) && defined (R_SPARC_UA64)
278 case EM_SPARC:
279 r = (0
280 #if defined(R_SPARC_UA64)
281 | (type == R_SPARC_UA64)
282 #endif
283 #if defined (R_SPARC_TLS_DTPOFF64)
284 | (type == R_SPARC_TLS_DTPOFF64)
285 #endif
286 );
287 break;
288 #endif /* EM_SPARC */
289
290 #if defined(EM_IA_64) && defined (R_IA64_SECREL64LSB)
291 case EM_IA_64: /* 64bit */
292 r = (0
293 #if defined (R_IA64_SECREL64LSB)
294 | (type == R_IA64_SECREL64LSB)
295 #endif
296 #if defined (R_IA64_SECREL32LSB)
297 | (type == R_IA64_SECREL32LSB)
298 #endif
299 #if defined (R_IA64_DIR64LSB)
300 | (type == R_IA64_DIR64LSB)
301 #endif
302 #if defined (R_IA64_DTPREL64LSB)
303 | (type == R_IA64_DTPREL64LSB)
304 #endif
305 #if defined (R_IA64_REL32LSB)
306 | (type == R_IA64_REL32LSB)
307 #endif
308 );
309 break;
310 #endif /* EM_IA_64 */
311
312 #if defined(EM_PPC64) && defined (R_PPC64_ADDR64)
313 case EM_PPC64:
314 r = (0
315 #if defined(R_PPC64_ADDR64)
316 | (type == R_PPC64_ADDR64)
317 #endif
318 #if defined(R_PPC64_DTPREL64)
319 | (type == R_PPC64_DTPREL64)
320 #endif
321 );
322 break;
323 #endif /* EM_PPC64 */
324
325 #if defined(EM_S390) && defined (R_390_64)
326 case EM_S390:
327 r = (0
328 #if defined(R_390_64)
329 | (type == R_390_64)
330 #endif
331 #if defined(R_390_TLS_LDO64)
332 | (type == R_390_TLS_LDO64)
333 #endif
334 );
335 break;
336 #endif /* EM_390 */
337
338 #if defined(EM_X86_64) && defined (R_X86_64_64)
339 #if defined(EM_K10M)
340 case EM_K10M:
341 #endif
342 #if defined(EM_L10M)
343 case EM_L10M:
344 #endif
345 case EM_X86_64:
346 r = (0
347 #if defined (R_X86_64_64)
348 | (type == R_X86_64_64)
349 #endif
350 #if defined (R_X86_64_PC64)
351 | (type == R_X86_64_PC64)
352 #endif
353 #if defined (R_X86_64_DTPOFF32)
354 | (type == R_X86_64_DTPOFF64)
355 #endif
356 );
357 break;
358 #endif /* EM_X86_64 */
359 #if defined(EM_AARCH64) && defined (R_AARCH64_ABS64)
360 case EM_AARCH64:
361 r = (0
362 #if defined (R_AARCH64_ABS64)
363 | ( type == R_AARCH64_ABS64)
364 #endif
365 );
366 break;
367 #endif /* EM_AARCH64 */
368 default: break;
369 }
370 return r;
371 }