Wed Mar 27 21:53:06 2024 UTC (66d)
Don't try to compile the arch-specific relocation code if we don't have the
built-in headers (for tools)


(christos)
diff -r1.5 -r1.6 src/external/bsd/elftoolchain/dist/libdwarf/libdwarf_reloc.c

cvs diff -r1.5 -r1.6 src/external/bsd/elftoolchain/dist/libdwarf/libdwarf_reloc.c (expand / switch to unified diff)

--- src/external/bsd/elftoolchain/dist/libdwarf/libdwarf_reloc.c 2024/03/03 17:37:32 1.5
+++ src/external/bsd/elftoolchain/dist/libdwarf/libdwarf_reloc.c 2024/03/27 21:53:06 1.6
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: libdwarf_reloc.c,v 1.5 2024/03/03 17:37:32 christos Exp $ */ 1/* $NetBSD: libdwarf_reloc.c,v 1.6 2024/03/27 21:53:06 christos Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2010 Kai Wang 4 * Copyright (c) 2010 Kai Wang
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -18,64 +18,66 @@ @@ -18,64 +18,66 @@
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE. 26 * SUCH DAMAGE.
27 */ 27 */
28 28
29#include "_libdwarf.h" 29#include "_libdwarf.h"
30 30
31__RCSID("$NetBSD: libdwarf_reloc.c,v 1.5 2024/03/03 17:37:32 christos Exp $"); 31__RCSID("$NetBSD: libdwarf_reloc.c,v 1.6 2024/03/27 21:53:06 christos Exp $");
32ELFTC_VCSID("Id: libdwarf_reloc.c 3741 2019-06-07 06:32:01Z jkoshy"); 32ELFTC_VCSID("Id: libdwarf_reloc.c 3741 2019-06-07 06:32:01Z jkoshy");
33 33
34Dwarf_Unsigned 34Dwarf_Unsigned
35_dwarf_get_reloc_type(Dwarf_P_Debug dbg, int is64) 35_dwarf_get_reloc_type(Dwarf_P_Debug dbg, int is64)
36{ 36{
37 37
38 assert(dbg != NULL); 38 assert(dbg != NULL);
39 39#ifdef BUILTIN_ELF_HEADERS
40 switch (dbg->dbgp_isa) { 40 switch (dbg->dbgp_isa) {
41 case DW_ISA_AARCH64: 41 case DW_ISA_AARCH64:
42 return (is64 ? R_AARCH64_ABS64 : R_AARCH64_ABS32); 42 return (is64 ? R_AARCH64_ABS64 : R_AARCH64_ABS32);
43 case DW_ISA_X86: 43 case DW_ISA_X86:
44 return (R_386_32); 44 return (R_386_32);
45 case DW_ISA_X86_64: 45 case DW_ISA_X86_64:
46 return (is64 ? R_X86_64_64 : R_X86_64_32); 46 return (is64 ? R_X86_64_64 : R_X86_64_32);
47 case DW_ISA_SPARC: 47 case DW_ISA_SPARC:
48 return (is64 ? R_SPARC_UA64 : R_SPARC_UA32); 48 return (is64 ? R_SPARC_UA64 : R_SPARC_UA32);
49 case DW_ISA_PPC: 49 case DW_ISA_PPC:
50 return (is64 ? R_PPC64_ADDR64 : R_PPC_ADDR32); 50 return (is64 ? R_PPC64_ADDR64 : R_PPC_ADDR32);
51 case DW_ISA_ARM: 51 case DW_ISA_ARM:
52 return (R_ARM_ABS32); 52 return (R_ARM_ABS32);
53 case DW_ISA_MIPS: 53 case DW_ISA_MIPS:
54 return (is64 ? R_MIPS_64 : R_MIPS_32); 54 return (is64 ? R_MIPS_64 : R_MIPS_32);
55 case DW_ISA_RISCV: 55 case DW_ISA_RISCV:
56 return (is64 ? R_RISCV_64 : R_RISCV_32); 56 return (is64 ? R_RISCV_64 : R_RISCV_32);
57 case DW_ISA_IA64: 57 case DW_ISA_IA64:
58 return (is64 ? R_IA_64_DIR64LSB : R_IA_64_DIR32LSB); 58 return (is64 ? R_IA_64_DIR64LSB : R_IA_64_DIR32LSB);
59 default: 59 default:
60 break; 60 break;
61 } 61 }
 62#endif
62 return (0); /* NOT REACHED */ 63 return (0); /* NOT REACHED */
63} 64}
64 65
65int 66int
66_dwarf_get_reloc_size(Dwarf_Debug dbg, Dwarf_Unsigned rel_type) 67_dwarf_get_reloc_size(Dwarf_Debug dbg, Dwarf_Unsigned rel_type)
67{ 68{
68 69
 70#ifdef BUILTIN_ELF_HEADERS
69 switch (dbg->dbg_machine) { 71 switch (dbg->dbg_machine) {
70 case EM_NONE: 72 case EM_NONE:
71 break; 73 break;
72 case EM_AARCH64: 74 case EM_AARCH64:
73 if (rel_type == R_AARCH64_ABS32) 75 if (rel_type == R_AARCH64_ABS32)
74 return (4); 76 return (4);
75 else if (rel_type == R_AARCH64_ABS64) 77 else if (rel_type == R_AARCH64_ABS64)
76 return (8); 78 return (8);
77 break; 79 break;
78 case EM_ARM: 80 case EM_ARM:
79 if (rel_type == R_ARM_ABS32) 81 if (rel_type == R_ARM_ABS32)
80 return (4); 82 return (4);
81 break; 83 break;
@@ -117,26 +119,27 @@ _dwarf_get_reloc_size(Dwarf_Debug dbg, D @@ -117,26 +119,27 @@ _dwarf_get_reloc_size(Dwarf_Debug dbg, D
117 return (4); 119 return (4);
118 else if (rel_type == R_RISCV_64) 120 else if (rel_type == R_RISCV_64)
119 return (8); 121 return (8);
120 break; 122 break;
121 case EM_IA_64: 123 case EM_IA_64:
122 if (rel_type == R_IA_64_SECREL32LSB) 124 if (rel_type == R_IA_64_SECREL32LSB)
123 return (4); 125 return (4);
124 else if (rel_type == R_IA_64_DIR64LSB) 126 else if (rel_type == R_IA_64_DIR64LSB)
125 return (8); 127 return (8);
126 break; 128 break;
127 default: 129 default:
128 break; 130 break;
129 } 131 }
 132#endif
130 133
131 /* unknown relocation. */ 134 /* unknown relocation. */
132 return (0); 135 return (0);
133} 136}
134 137
135int 138int
136_dwarf_reloc_section_init(Dwarf_P_Debug dbg, Dwarf_Rel_Section *drsp, 139_dwarf_reloc_section_init(Dwarf_P_Debug dbg, Dwarf_Rel_Section *drsp,
137 Dwarf_P_Section ref, Dwarf_Error *error) 140 Dwarf_P_Section ref, Dwarf_Error *error)
138{ 141{
139 Dwarf_Rel_Section drs; 142 Dwarf_Rel_Section drs;
140 char name[128]; 143 char name[128];
141 int pseudo; 144 int pseudo;
142 145