xref: /netbsd-src/external/gpl3/binutils.old/dist/bfd/elf-hppa.h (revision e992f068c547fd6e84b3f104dc2340adcc955732)
175fd0b74Schristos /* Common code for PA ELF implementations.
2*e992f068Schristos    Copyright (C) 1999-2022 Free Software Foundation, Inc.
375fd0b74Schristos 
475fd0b74Schristos    This file is part of BFD, the Binary File Descriptor library.
575fd0b74Schristos 
675fd0b74Schristos    This program is free software; you can redistribute it and/or modify
775fd0b74Schristos    it under the terms of the GNU General Public License as published by
875fd0b74Schristos    the Free Software Foundation; either version 3 of the License, or
975fd0b74Schristos    (at your option) any later version.
1075fd0b74Schristos 
1175fd0b74Schristos    This program is distributed in the hope that it will be useful,
1275fd0b74Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1375fd0b74Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1475fd0b74Schristos    GNU General Public License for more details.
1575fd0b74Schristos 
1675fd0b74Schristos    You should have received a copy of the GNU General Public License
1775fd0b74Schristos    along with this program; if not, write to the Free Software
1875fd0b74Schristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
1975fd0b74Schristos    MA 02110-1301, USA.  */
2075fd0b74Schristos 
2175fd0b74Schristos #define ELF_HOWTO_TABLE_SIZE       R_PARISC_UNIMPLEMENTED + 1
2275fd0b74Schristos 
2375fd0b74Schristos /* This file is included by multiple PA ELF BFD backends with different
2475fd0b74Schristos    sizes.
2575fd0b74Schristos 
2675fd0b74Schristos    Most of the routines are written to be size independent, but sometimes
2775fd0b74Schristos    external constraints require 32 or 64 bit specific code.  We remap
2875fd0b74Schristos    the definitions/functions as necessary here.  */
2975fd0b74Schristos #if ARCH_SIZE == 64
3075fd0b74Schristos #define ELF_R_TYPE(X)		      ELF64_R_TYPE(X)
3175fd0b74Schristos #define ELF_R_SYM(X)		      ELF64_R_SYM(X)
3275fd0b74Schristos #define elf_hppa_reloc_final_type     elf64_hppa_reloc_final_type
3375fd0b74Schristos #define _bfd_elf_hppa_gen_reloc_type  _bfd_elf64_hppa_gen_reloc_type
3475fd0b74Schristos #define elf_hppa_relocate_section     elf64_hppa_relocate_section
3575fd0b74Schristos #define elf_hppa_final_link	      elf64_hppa_final_link
3675fd0b74Schristos #endif
3775fd0b74Schristos #if ARCH_SIZE == 32
3875fd0b74Schristos #define ELF_R_TYPE(X)		      ELF32_R_TYPE(X)
3975fd0b74Schristos #define ELF_R_SYM(X)		      ELF32_R_SYM(X)
4075fd0b74Schristos #define elf_hppa_reloc_final_type     elf32_hppa_reloc_final_type
4175fd0b74Schristos #define _bfd_elf_hppa_gen_reloc_type  _bfd_elf32_hppa_gen_reloc_type
4275fd0b74Schristos #define elf_hppa_relocate_section     elf32_hppa_relocate_section
4375fd0b74Schristos #define elf_hppa_final_link	      elf32_hppa_final_link
4475fd0b74Schristos #endif
4575fd0b74Schristos 
4675fd0b74Schristos /* ELF/PA relocation howto entries.  */
4775fd0b74Schristos 
4875fd0b74Schristos static reloc_howto_type elf_hppa_howto_table[ELF_HOWTO_TABLE_SIZE] =
4975fd0b74Schristos {
50012573ebSchristos #define HOW(type, size, bitsize, pc_rel, complain, mask) \
51012573ebSchristos   HOWTO (type, 0, size, bitsize, pc_rel, 0, complain_overflow_ ## complain, \
52*e992f068Schristos 	 bfd_elf_generic_reloc, #type, false, 0, mask, false)
5375fd0b74Schristos 
5475fd0b74Schristos   /* The values in DIR32 are to placate the check in
5575fd0b74Schristos      _bfd_stab_section_find_nearest_line.  */
56*e992f068Schristos   HOW (R_PARISC_NONE,		0,  0, false,     dont, 0),
57*e992f068Schristos   HOW (R_PARISC_DIR32,		4, 32, false, bitfield, 0xffffffff),
58*e992f068Schristos   HOW (R_PARISC_DIR21L,		4, 21, false, bitfield, 0),
59*e992f068Schristos   HOW (R_PARISC_DIR17R,		4, 17, false, bitfield, 0),
60*e992f068Schristos   HOW (R_PARISC_DIR17F,		4, 17, false, bitfield, 0),
61*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
62*e992f068Schristos   HOW (R_PARISC_DIR14R,		4, 14, false, bitfield, 0),
63*e992f068Schristos   HOW (R_PARISC_DIR14F,		4, 14, false, bitfield, 0),
6475fd0b74Schristos   /* 8 */
65*e992f068Schristos   HOW (R_PARISC_PCREL12F,	4, 12,  true, bitfield, 0),
66*e992f068Schristos   HOW (R_PARISC_PCREL32,	4, 32,  true, bitfield, 0),
67*e992f068Schristos   HOW (R_PARISC_PCREL21L,	4, 21,  true, bitfield, 0),
68*e992f068Schristos   HOW (R_PARISC_PCREL17R,	4, 17,  true, bitfield, 0),
69*e992f068Schristos   HOW (R_PARISC_PCREL17F,	4, 17,  true, bitfield, 0),
70*e992f068Schristos   HOW (R_PARISC_PCREL17C,	4, 17,  true, bitfield, 0),
71*e992f068Schristos   HOW (R_PARISC_PCREL14R,	4, 14,  true, bitfield, 0),
72*e992f068Schristos   HOW (R_PARISC_PCREL14F,	4, 14,  true, bitfield, 0),
7375fd0b74Schristos   /* 16 */
74*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
75*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
76*e992f068Schristos   HOW (R_PARISC_DPREL21L,	4, 21, false, bitfield, 0),
77*e992f068Schristos   HOW (R_PARISC_DPREL14WR,	4, 14, false, bitfield, 0),
78*e992f068Schristos   HOW (R_PARISC_DPREL14DR,	4, 14, false, bitfield, 0),
79*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
80*e992f068Schristos   HOW (R_PARISC_DPREL14R,	4, 14, false, bitfield, 0),
81*e992f068Schristos   HOW (R_PARISC_DPREL14F,	4, 14, false, bitfield, 0),
8275fd0b74Schristos   /* 24 */
83*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
84*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
85*e992f068Schristos   HOW (R_PARISC_DLTREL21L,	4, 21, false, bitfield, 0),
86*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
87*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
88*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
89*e992f068Schristos   HOW (R_PARISC_DLTREL14R,	4, 14, false, bitfield, 0),
90*e992f068Schristos   HOW (R_PARISC_DLTREL14F,	4, 14, false, bitfield, 0),
9175fd0b74Schristos   /* 32 */
92*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
93*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
94*e992f068Schristos   HOW (R_PARISC_DLTIND21L,	4, 21, false, bitfield, 0),
95*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
96*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
97*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
98*e992f068Schristos   HOW (R_PARISC_DLTIND14R,	4, 14, false, bitfield, 0),
99*e992f068Schristos   HOW (R_PARISC_DLTIND14F,	4, 14, false, bitfield, 0),
10075fd0b74Schristos   /* 40 */
101*e992f068Schristos   HOW (R_PARISC_SETBASE,	0,  0, false, bitfield, 0),
102*e992f068Schristos   HOW (R_PARISC_SECREL32,	4, 32, false, bitfield, 0xffffffff),
103*e992f068Schristos   HOW (R_PARISC_BASEREL21L,	4, 21, false, bitfield, 0),
104*e992f068Schristos   HOW (R_PARISC_BASEREL17R,	4, 17, false, bitfield, 0),
105*e992f068Schristos   HOW (R_PARISC_BASEREL17F,	4, 17, false, bitfield, 0),
106*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
107*e992f068Schristos   HOW (R_PARISC_BASEREL14R,	4, 14, false, bitfield, 0),
108*e992f068Schristos   HOW (R_PARISC_BASEREL14F,	4, 14, false, bitfield, 0),
10975fd0b74Schristos   /* 48 */
110*e992f068Schristos   HOW (R_PARISC_SEGBASE,	0,  0, false, bitfield, 0),
111*e992f068Schristos   HOW (R_PARISC_SEGREL32,	4, 32, false, bitfield, 0),
112*e992f068Schristos   HOW (R_PARISC_PLTOFF21L,	4, 21, false, bitfield, 0),
113*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
114*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
115*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
116*e992f068Schristos   HOW (R_PARISC_PLTOFF14R,	4, 14, false, bitfield, 0),
117*e992f068Schristos   HOW (R_PARISC_PLTOFF14F,	4, 14, false, bitfield, 0),
11875fd0b74Schristos   /* 56 */
119*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
120*e992f068Schristos   HOW (R_PARISC_LTOFF_FPTR32,	4, 32, false, bitfield, 0),
121*e992f068Schristos   HOW (R_PARISC_LTOFF_FPTR21L,	4, 21, false, bitfield, 0),
122*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
123*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
124*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
125*e992f068Schristos   HOW (R_PARISC_LTOFF_FPTR14R,	4, 14, false, bitfield, 0),
126*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
12775fd0b74Schristos   /* 64 */
128*e992f068Schristos   HOW (R_PARISC_FPTR64,		8, 64, false, bitfield, 0),
129*e992f068Schristos   HOW (R_PARISC_PLABEL32,	4, 32, false, bitfield, 0),
130*e992f068Schristos   HOW (R_PARISC_PLABEL21L,	4, 21, false, bitfield, 0),
131*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
132*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
133*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
134*e992f068Schristos   HOW (R_PARISC_PLABEL14R,	4, 14, false, bitfield, 0),
135*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
13675fd0b74Schristos   /* 72 */
137*e992f068Schristos   HOW (R_PARISC_PCREL64,	8, 64, false, bitfield, 0),
138*e992f068Schristos   HOW (R_PARISC_PCREL22C,	4, 22, false, bitfield, 0),
139*e992f068Schristos   HOW (R_PARISC_PCREL22F,	4, 22, false, bitfield, 0),
140*e992f068Schristos   HOW (R_PARISC_PCREL14WR,	4, 14, false, bitfield, 0),
141*e992f068Schristos   HOW (R_PARISC_PCREL14DR,	4, 14, false, bitfield, 0),
142*e992f068Schristos   HOW (R_PARISC_PCREL16F,	4, 16, false, bitfield, 0),
143*e992f068Schristos   HOW (R_PARISC_PCREL16WF,	4, 16, false, bitfield, 0),
144*e992f068Schristos   HOW (R_PARISC_PCREL16DF,	4, 16, false, bitfield, 0),
14575fd0b74Schristos   /* 80 */
146*e992f068Schristos   HOW (R_PARISC_DIR64,		8, 64, false, bitfield, 0),
147*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
148*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
149*e992f068Schristos   HOW (R_PARISC_DIR14WR,	4, 14, false, bitfield, 0),
150*e992f068Schristos   HOW (R_PARISC_DIR14DR,	4, 14, false, bitfield, 0),
151*e992f068Schristos   HOW (R_PARISC_DIR16F,		4, 16, false, bitfield, 0),
152*e992f068Schristos   HOW (R_PARISC_DIR16WF,	4, 16, false, bitfield, 0),
153*e992f068Schristos   HOW (R_PARISC_DIR16DF,	4, 16, false, bitfield, 0),
15475fd0b74Schristos   /* 88 */
155*e992f068Schristos   HOW (R_PARISC_GPREL64,	8, 64, false, bitfield, 0),
156*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
157*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
158*e992f068Schristos   HOW (R_PARISC_DLTREL14WR,	4, 14, false, bitfield, 0),
159*e992f068Schristos   HOW (R_PARISC_DLTREL14DR,	4, 14, false, bitfield, 0),
160*e992f068Schristos   HOW (R_PARISC_GPREL16F,	4, 16, false, bitfield, 0),
161*e992f068Schristos   HOW (R_PARISC_GPREL16WF,	4, 16, false, bitfield, 0),
162*e992f068Schristos   HOW (R_PARISC_GPREL16DF,	4, 16, false, bitfield, 0),
16375fd0b74Schristos   /* 96 */
164*e992f068Schristos   HOW (R_PARISC_LTOFF64,	8, 64, false, bitfield, 0),
165*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
166*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
167*e992f068Schristos   HOW (R_PARISC_DLTIND14WR,	4, 14, false, bitfield, 0),
168*e992f068Schristos   HOW (R_PARISC_DLTIND14DR,	4, 14, false, bitfield, 0),
169*e992f068Schristos   HOW (R_PARISC_LTOFF16F,	4, 16, false, bitfield, 0),
170*e992f068Schristos   HOW (R_PARISC_LTOFF16WF,	4, 16, false, bitfield, 0),
171*e992f068Schristos   HOW (R_PARISC_LTOFF16DF,	4, 16, false, bitfield, 0),
17275fd0b74Schristos   /* 104 */
173*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
174*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
175*e992f068Schristos   HOW (R_PARISC_BASEREL14WR,	4, 14, false, bitfield, 0),
176*e992f068Schristos   HOW (R_PARISC_BASEREL14DR,	4, 14, false, bitfield, 0),
177*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
178*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
179*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
180*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
18175fd0b74Schristos   /* 112 */
182*e992f068Schristos   HOW (R_PARISC_SEGREL64,	8, 64, false, bitfield, 0),
183*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
184*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
185*e992f068Schristos   HOW (R_PARISC_PLTOFF14WR,	4, 14, false, bitfield, 0),
186*e992f068Schristos   HOW (R_PARISC_PLTOFF14DR,	4, 14, false, bitfield, 0),
187*e992f068Schristos   HOW (R_PARISC_PLTOFF16F,	4, 16, false, bitfield, 0),
188*e992f068Schristos   HOW (R_PARISC_PLTOFF16WF,	4, 16, false, bitfield, 0),
189*e992f068Schristos   HOW (R_PARISC_PLTOFF16DF,	4, 16, false, bitfield, 0),
19075fd0b74Schristos   /* 120 */
191*e992f068Schristos   HOW (R_PARISC_LTOFF_FPTR64,	8, 64, false, bitfield, 0),
192*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
193*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
194*e992f068Schristos   HOW (R_PARISC_LTOFF_FPTR14WR,	4, 14, false, bitfield, 0),
195*e992f068Schristos   HOW (R_PARISC_LTOFF_FPTR14DR,	4, 14, false, bitfield, 0),
196*e992f068Schristos   HOW (R_PARISC_LTOFF_FPTR16F,	4, 16, false, bitfield, 0),
197*e992f068Schristos   HOW (R_PARISC_LTOFF_FPTR16WF,	4, 16, false, bitfield, 0),
198*e992f068Schristos   HOW (R_PARISC_LTOFF_FPTR16DF,	4, 16, false, bitfield, 0),
19975fd0b74Schristos   /* 128 */
200*e992f068Schristos   HOW (R_PARISC_COPY,		0,  0, false, bitfield, 0),
201*e992f068Schristos   HOW (R_PARISC_IPLT,		0,  0, false, bitfield, 0),
202*e992f068Schristos   HOW (R_PARISC_EPLT,		0,  0, false, bitfield, 0),
203*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
204*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
205*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
206*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
207*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
20875fd0b74Schristos   /* 136 */
209*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
210*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
211*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
212*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
213*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
214*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
215*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
216*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
21775fd0b74Schristos   /* 144 */
218*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
219*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
220*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
221*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
222*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
223*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
224*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
225*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
22675fd0b74Schristos   /* 152 */
227*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
228*e992f068Schristos   HOW (R_PARISC_TPREL32,	4, 32, false,     dont, 0),
229*e992f068Schristos   HOW (R_PARISC_TPREL21L,	4, 21, false, bitfield, 0),
230*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
231*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
232*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
233*e992f068Schristos   HOW (R_PARISC_TPREL14R,	4, 14, false, bitfield, 0),
234*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
23575fd0b74Schristos   /* 160 */
236*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
237*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
238*e992f068Schristos   HOW (R_PARISC_LTOFF_TP21L,	4, 21, false, bitfield, 0),
239*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
240*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
241*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
242*e992f068Schristos   HOW (R_PARISC_LTOFF_TP14R,	4, 14, false, bitfield, 0),
243*e992f068Schristos   HOW (R_PARISC_LTOFF_TP14F,	4, 14, false, bitfield, 0),
24475fd0b74Schristos   /* 168 */
245*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
246*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
247*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
248*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
249*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
250*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
251*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
252*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
25375fd0b74Schristos   /* 176 */
254*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
255*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
256*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
257*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
258*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
259*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
260*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
261*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
26275fd0b74Schristos   /* 184 */
263*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
264*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
265*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
266*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
267*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
268*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
269*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
270*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
27175fd0b74Schristos   /* 192 */
272*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
273*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
274*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
275*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
276*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
277*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
278*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
279*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
28075fd0b74Schristos   /* 200 */
281*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
282*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
283*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
284*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
285*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
286*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
287*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
288*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
28975fd0b74Schristos   /* 208 */
290*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
291*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
292*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
293*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
294*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false,     dont, 0),
295*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
296*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
297*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
29875fd0b74Schristos   /* 216 */
299*e992f068Schristos   HOW (R_PARISC_TPREL64,	8, 64, false, bitfield, 0),
300*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
301*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
302*e992f068Schristos   HOW (R_PARISC_TPREL14WR,	4, 14, false,     dont, 0),
303*e992f068Schristos   HOW (R_PARISC_TPREL14DR,	4, 14, false, bitfield, 0),
304*e992f068Schristos   HOW (R_PARISC_TPREL16F,	4, 16, false, bitfield, 0),
305*e992f068Schristos   HOW (R_PARISC_TPREL16WF,	4, 16, false,     dont, 0),
306*e992f068Schristos   HOW (R_PARISC_TPREL16DF,	4, 16, false, bitfield, 0),
30775fd0b74Schristos   /* 224 */
308*e992f068Schristos   HOW (R_PARISC_LTOFF_TP64,	8, 64, false, bitfield, 0),
309*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
310*e992f068Schristos   HOW (R_PARISC_UNIMPLEMENTED,	0,  0, false, bitfield, 0),
311*e992f068Schristos   HOW (R_PARISC_LTOFF_TP14WR,	4, 14, false, bitfield, 0),
312*e992f068Schristos   HOW (R_PARISC_LTOFF_TP14DR,	4, 14, false, bitfield, 0),
313*e992f068Schristos   HOW (R_PARISC_LTOFF_TP16F,	4, 16, false,     dont, 0),
314*e992f068Schristos   HOW (R_PARISC_LTOFF_TP16WF,	4, 16, false, bitfield, 0),
315*e992f068Schristos   HOW (R_PARISC_LTOFF_TP16DF,	4, 16, false, bitfield, 0),
31675fd0b74Schristos   /* 232 */
317*e992f068Schristos   HOW (R_PARISC_GNU_VTENTRY,	0,  0, false,     dont, 0),
318*e992f068Schristos   HOW (R_PARISC_GNU_VTINHERIT,	0,  0, false,     dont, 0),
319*e992f068Schristos   HOW (R_PARISC_TLS_GD21L,	4, 21, false, bitfield, 0),
320*e992f068Schristos   HOW (R_PARISC_TLS_GD14R,	4, 14, false, bitfield, 0),
321*e992f068Schristos   HOW (R_PARISC_TLS_GDCALL,	0,  0, false,     dont, 0),
322*e992f068Schristos   HOW (R_PARISC_TLS_LDM21L,	4, 21, false, bitfield, 0),
323*e992f068Schristos   HOW (R_PARISC_TLS_LDM14R,	4, 14, false, bitfield, 0),
324*e992f068Schristos   HOW (R_PARISC_TLS_LDMCALL,	0,  0, false,     dont, 0),
32575fd0b74Schristos   /* 240 */
326*e992f068Schristos   HOW (R_PARISC_TLS_LDO21L,	4, 21, false, bitfield, 0),
327*e992f068Schristos   HOW (R_PARISC_TLS_LDO14R,	4, 14, false, bitfield, 0),
328*e992f068Schristos   HOW (R_PARISC_TLS_DTPMOD32,	4, 32, false, bitfield, 0),
329*e992f068Schristos   HOW (R_PARISC_TLS_DTPMOD64,	8, 64, false, bitfield, 0),
330*e992f068Schristos   HOW (R_PARISC_TLS_DTPOFF32,	4, 32, false, bitfield, 0),
331*e992f068Schristos   HOW (R_PARISC_TLS_DTPOFF64,	8, 64, false, bitfield, 0)
332012573ebSchristos #undef HOW
33375fd0b74Schristos };
33475fd0b74Schristos 
33575fd0b74Schristos #define OFFSET_14R_FROM_21L 4
33675fd0b74Schristos #define OFFSET_14F_FROM_21L 5
33775fd0b74Schristos 
33875fd0b74Schristos /* Return the final relocation type for the given base type, instruction
33975fd0b74Schristos    format, and field selector.  */
34075fd0b74Schristos 
34175fd0b74Schristos elf_hppa_reloc_type
elf_hppa_reloc_final_type(bfd * abfd,elf_hppa_reloc_type base_type,int format,unsigned int field)34275fd0b74Schristos elf_hppa_reloc_final_type (bfd *abfd,
34375fd0b74Schristos 			   elf_hppa_reloc_type base_type,
34475fd0b74Schristos 			   int format,
34575fd0b74Schristos 			   unsigned int field)
34675fd0b74Schristos {
34775fd0b74Schristos   elf_hppa_reloc_type final_type = base_type;
34875fd0b74Schristos 
34975fd0b74Schristos   /* Just a tangle of nested switch statements to deal with the braindamage
35075fd0b74Schristos      that a different field selector means a completely different relocation
35175fd0b74Schristos      for PA ELF.  */
35275fd0b74Schristos   switch (base_type)
35375fd0b74Schristos     {
35475fd0b74Schristos       /* We have been using generic relocation types.  However, that may not
35575fd0b74Schristos 	 really make sense.  Anyway, we need to support both R_PARISC_DIR64
35675fd0b74Schristos 	 and R_PARISC_DIR32 here.  */
35775fd0b74Schristos     case R_PARISC_DIR32:
35875fd0b74Schristos     case R_PARISC_DIR64:
35975fd0b74Schristos     case R_HPPA_ABS_CALL:
36075fd0b74Schristos       switch (format)
36175fd0b74Schristos 	{
36275fd0b74Schristos 	case 14:
36375fd0b74Schristos 	  switch (field)
36475fd0b74Schristos 	    {
36575fd0b74Schristos 	    case e_fsel:
36675fd0b74Schristos 	      final_type = R_PARISC_DIR14F;
36775fd0b74Schristos 	      break;
36875fd0b74Schristos 	    case e_rsel:
36975fd0b74Schristos 	    case e_rrsel:
37075fd0b74Schristos 	    case e_rdsel:
37175fd0b74Schristos 	      final_type = R_PARISC_DIR14R;
37275fd0b74Schristos 	      break;
37375fd0b74Schristos 	    case e_rtsel:
37475fd0b74Schristos 	      final_type = R_PARISC_DLTIND14R;
37575fd0b74Schristos 	      break;
37675fd0b74Schristos 	    case e_rtpsel:
37775fd0b74Schristos 	      final_type = R_PARISC_LTOFF_FPTR14DR;
37875fd0b74Schristos 	      break;
37975fd0b74Schristos 	    case e_tsel:
38075fd0b74Schristos 	      final_type = R_PARISC_DLTIND14F;
38175fd0b74Schristos 	      break;
38275fd0b74Schristos 	    case e_rpsel:
38375fd0b74Schristos 	      final_type = R_PARISC_PLABEL14R;
38475fd0b74Schristos 	      break;
38575fd0b74Schristos 	    default:
38675fd0b74Schristos 	      return R_PARISC_NONE;
38775fd0b74Schristos 	    }
38875fd0b74Schristos 	  break;
38975fd0b74Schristos 
39075fd0b74Schristos 	case 17:
39175fd0b74Schristos 	  switch (field)
39275fd0b74Schristos 	    {
39375fd0b74Schristos 	    case e_fsel:
39475fd0b74Schristos 	      final_type = R_PARISC_DIR17F;
39575fd0b74Schristos 	      break;
39675fd0b74Schristos 	    case e_rsel:
39775fd0b74Schristos 	    case e_rrsel:
39875fd0b74Schristos 	    case e_rdsel:
39975fd0b74Schristos 	      final_type = R_PARISC_DIR17R;
40075fd0b74Schristos 	      break;
40175fd0b74Schristos 	    default:
40275fd0b74Schristos 	      return R_PARISC_NONE;
40375fd0b74Schristos 	    }
40475fd0b74Schristos 	  break;
40575fd0b74Schristos 
40675fd0b74Schristos 	case 21:
40775fd0b74Schristos 	  switch (field)
40875fd0b74Schristos 	    {
40975fd0b74Schristos 	    case e_lsel:
41075fd0b74Schristos 	    case e_lrsel:
41175fd0b74Schristos 	    case e_ldsel:
41275fd0b74Schristos 	    case e_nlsel:
41375fd0b74Schristos 	    case e_nlrsel:
41475fd0b74Schristos 	      final_type = R_PARISC_DIR21L;
41575fd0b74Schristos 	      break;
41675fd0b74Schristos 	    case e_ltsel:
41775fd0b74Schristos 	      final_type = R_PARISC_DLTIND21L;
41875fd0b74Schristos 	      break;
41975fd0b74Schristos 	    case e_ltpsel:
42075fd0b74Schristos 	      final_type = R_PARISC_LTOFF_FPTR21L;
42175fd0b74Schristos 	      break;
42275fd0b74Schristos 	    case e_lpsel:
42375fd0b74Schristos 	      final_type = R_PARISC_PLABEL21L;
42475fd0b74Schristos 	      break;
42575fd0b74Schristos 	    default:
42675fd0b74Schristos 	      return R_PARISC_NONE;
42775fd0b74Schristos 	    }
42875fd0b74Schristos 	  break;
42975fd0b74Schristos 
43075fd0b74Schristos 	case 32:
43175fd0b74Schristos 	  switch (field)
43275fd0b74Schristos 	    {
43375fd0b74Schristos 	    case e_fsel:
43475fd0b74Schristos 	      final_type = R_PARISC_DIR32;
43575fd0b74Schristos 	      /* When in 64bit mode, a 32bit relocation is supposed to
43675fd0b74Schristos 		 be a section relative relocation.  Dwarf2 (for example)
43775fd0b74Schristos 		 uses 32bit section relative relocations.  */
43875fd0b74Schristos 	      if (bfd_arch_bits_per_address (abfd) != 32)
43975fd0b74Schristos 		final_type = R_PARISC_SECREL32;
44075fd0b74Schristos 	      break;
44175fd0b74Schristos 	    case e_psel:
44275fd0b74Schristos 	      final_type = R_PARISC_PLABEL32;
44375fd0b74Schristos 	      break;
44475fd0b74Schristos 	    default:
44575fd0b74Schristos 	      return R_PARISC_NONE;
44675fd0b74Schristos 	    }
44775fd0b74Schristos 	  break;
44875fd0b74Schristos 
44975fd0b74Schristos 	case 64:
45075fd0b74Schristos 	  switch (field)
45175fd0b74Schristos 	    {
45275fd0b74Schristos 	    case e_fsel:
45375fd0b74Schristos 	      final_type = R_PARISC_DIR64;
45475fd0b74Schristos 	      break;
45575fd0b74Schristos 	    case e_psel:
45675fd0b74Schristos 	      final_type = R_PARISC_FPTR64;
45775fd0b74Schristos 	      break;
45875fd0b74Schristos 	    default:
45975fd0b74Schristos 	      return R_PARISC_NONE;
46075fd0b74Schristos 	    }
46175fd0b74Schristos 	  break;
46275fd0b74Schristos 
46375fd0b74Schristos 	default:
46475fd0b74Schristos 	  return R_PARISC_NONE;
46575fd0b74Schristos 	}
46675fd0b74Schristos       break;
46775fd0b74Schristos 
46875fd0b74Schristos     case R_HPPA_GOTOFF:
46975fd0b74Schristos       switch (format)
47075fd0b74Schristos 	{
47175fd0b74Schristos 	case 14:
47275fd0b74Schristos 	  switch (field)
47375fd0b74Schristos 	    {
47475fd0b74Schristos 	    case e_rsel:
47575fd0b74Schristos 	    case e_rrsel:
47675fd0b74Schristos 	    case e_rdsel:
47775fd0b74Schristos 	      /* R_PARISC_DLTREL14R for elf64, R_PARISC_DPREL14R for elf32.  */
47875fd0b74Schristos 	      final_type = base_type + OFFSET_14R_FROM_21L;
47975fd0b74Schristos 	      break;
48075fd0b74Schristos 	    case e_fsel:
48175fd0b74Schristos 	      /* R_PARISC_DLTREL14F for elf64, R_PARISC_DPREL14F for elf32.  */
48275fd0b74Schristos 	      final_type = base_type + OFFSET_14F_FROM_21L;
48375fd0b74Schristos 	      break;
48475fd0b74Schristos 	    default:
48575fd0b74Schristos 	      return R_PARISC_NONE;
48675fd0b74Schristos 	    }
48775fd0b74Schristos 	  break;
48875fd0b74Schristos 
48975fd0b74Schristos 	case 21:
49075fd0b74Schristos 	  switch (field)
49175fd0b74Schristos 	    {
49275fd0b74Schristos 	    case e_lsel:
49375fd0b74Schristos 	    case e_lrsel:
49475fd0b74Schristos 	    case e_ldsel:
49575fd0b74Schristos 	    case e_nlsel:
49675fd0b74Schristos 	    case e_nlrsel:
49775fd0b74Schristos 	      /* R_PARISC_DLTREL21L for elf64, R_PARISC_DPREL21L for elf32.  */
49875fd0b74Schristos 	      final_type = base_type;
49975fd0b74Schristos 	      break;
50075fd0b74Schristos 	    default:
50175fd0b74Schristos 	      return R_PARISC_NONE;
50275fd0b74Schristos 	    }
50375fd0b74Schristos 	  break;
50475fd0b74Schristos 
50575fd0b74Schristos 	case 64:
50675fd0b74Schristos 	  switch (field)
50775fd0b74Schristos 	    {
50875fd0b74Schristos 	    case e_fsel:
50975fd0b74Schristos 	      final_type = R_PARISC_GPREL64;
51075fd0b74Schristos 	      break;
51175fd0b74Schristos 	    default:
51275fd0b74Schristos 	      return R_PARISC_NONE;
51375fd0b74Schristos 	    }
51475fd0b74Schristos 	  break;
51575fd0b74Schristos 
51675fd0b74Schristos 	default:
51775fd0b74Schristos 	  return R_PARISC_NONE;
51875fd0b74Schristos 	}
51975fd0b74Schristos       break;
52075fd0b74Schristos 
52175fd0b74Schristos     case R_HPPA_PCREL_CALL:
52275fd0b74Schristos       switch (format)
52375fd0b74Schristos 	{
52475fd0b74Schristos 	case 12:
52575fd0b74Schristos 	  switch (field)
52675fd0b74Schristos 	    {
52775fd0b74Schristos 	    case e_fsel:
52875fd0b74Schristos 	      final_type = R_PARISC_PCREL12F;
52975fd0b74Schristos 	      break;
53075fd0b74Schristos 	    default:
53175fd0b74Schristos 	      return R_PARISC_NONE;
53275fd0b74Schristos 	    }
53375fd0b74Schristos 	  break;
53475fd0b74Schristos 
53575fd0b74Schristos 	case 14:
53675fd0b74Schristos 	  /* Contrary to appearances, these are not calls of any sort.
53775fd0b74Schristos 	     Rather, they are loads/stores with a pcrel reloc.  */
53875fd0b74Schristos 	  switch (field)
53975fd0b74Schristos 	    {
54075fd0b74Schristos 	    case e_rsel:
54175fd0b74Schristos 	    case e_rrsel:
54275fd0b74Schristos 	    case e_rdsel:
54375fd0b74Schristos 	      final_type = R_PARISC_PCREL14R;
54475fd0b74Schristos 	      break;
54575fd0b74Schristos 	    case e_fsel:
54675fd0b74Schristos 	      if (bfd_get_mach (abfd) < 25)
54775fd0b74Schristos 		final_type = R_PARISC_PCREL14F;
54875fd0b74Schristos 	      else
54975fd0b74Schristos 		final_type = R_PARISC_PCREL16F;
55075fd0b74Schristos 	      break;
55175fd0b74Schristos 	    default:
55275fd0b74Schristos 	      return R_PARISC_NONE;
55375fd0b74Schristos 	    }
55475fd0b74Schristos 	  break;
55575fd0b74Schristos 
55675fd0b74Schristos 	case 17:
55775fd0b74Schristos 	  switch (field)
55875fd0b74Schristos 	    {
55975fd0b74Schristos 	    case e_rsel:
56075fd0b74Schristos 	    case e_rrsel:
56175fd0b74Schristos 	    case e_rdsel:
56275fd0b74Schristos 	      final_type = R_PARISC_PCREL17R;
56375fd0b74Schristos 	      break;
56475fd0b74Schristos 	    case e_fsel:
56575fd0b74Schristos 	      final_type = R_PARISC_PCREL17F;
56675fd0b74Schristos 	      break;
56775fd0b74Schristos 	    default:
56875fd0b74Schristos 	      return R_PARISC_NONE;
56975fd0b74Schristos 	    }
57075fd0b74Schristos 	  break;
57175fd0b74Schristos 
57275fd0b74Schristos 	case 21:
57375fd0b74Schristos 	  switch (field)
57475fd0b74Schristos 	    {
57575fd0b74Schristos 	    case e_lsel:
57675fd0b74Schristos 	    case e_lrsel:
57775fd0b74Schristos 	    case e_ldsel:
57875fd0b74Schristos 	    case e_nlsel:
57975fd0b74Schristos 	    case e_nlrsel:
58075fd0b74Schristos 	      final_type = R_PARISC_PCREL21L;
58175fd0b74Schristos 	      break;
58275fd0b74Schristos 	    default:
58375fd0b74Schristos 	      return R_PARISC_NONE;
58475fd0b74Schristos 	    }
58575fd0b74Schristos 	  break;
58675fd0b74Schristos 
58775fd0b74Schristos 	case 22:
58875fd0b74Schristos 	  switch (field)
58975fd0b74Schristos 	    {
59075fd0b74Schristos 	    case e_fsel:
59175fd0b74Schristos 	      final_type = R_PARISC_PCREL22F;
59275fd0b74Schristos 	      break;
59375fd0b74Schristos 	    default:
59475fd0b74Schristos 	      return R_PARISC_NONE;
59575fd0b74Schristos 	    }
59675fd0b74Schristos 	  break;
59775fd0b74Schristos 
59875fd0b74Schristos 	case 32:
59975fd0b74Schristos 	  switch (field)
60075fd0b74Schristos 	    {
60175fd0b74Schristos 	    case e_fsel:
60275fd0b74Schristos 	      final_type = R_PARISC_PCREL32;
60375fd0b74Schristos 	      break;
60475fd0b74Schristos 	    default:
60575fd0b74Schristos 	      return R_PARISC_NONE;
60675fd0b74Schristos 	    }
60775fd0b74Schristos 	  break;
60875fd0b74Schristos 
60975fd0b74Schristos 	case 64:
61075fd0b74Schristos 	  switch (field)
61175fd0b74Schristos 	    {
61275fd0b74Schristos 	    case e_fsel:
61375fd0b74Schristos 	      final_type = R_PARISC_PCREL64;
61475fd0b74Schristos 	      break;
61575fd0b74Schristos 	    default:
61675fd0b74Schristos 	      return R_PARISC_NONE;
61775fd0b74Schristos 	    }
61875fd0b74Schristos 	  break;
61975fd0b74Schristos 
62075fd0b74Schristos 	default:
62175fd0b74Schristos 	  return R_PARISC_NONE;
62275fd0b74Schristos 	}
62375fd0b74Schristos       break;
62475fd0b74Schristos 
62575fd0b74Schristos     case R_PARISC_TLS_GD21L:
62675fd0b74Schristos       switch (field)
62775fd0b74Schristos 	{
62875fd0b74Schristos 	  case e_ltsel:
62975fd0b74Schristos 	  case e_lrsel:
63075fd0b74Schristos 	    final_type = R_PARISC_TLS_GD21L;
63175fd0b74Schristos 	    break;
63275fd0b74Schristos 	  case e_rtsel:
63375fd0b74Schristos 	  case e_rrsel:
63475fd0b74Schristos 	    final_type = R_PARISC_TLS_GD14R;
63575fd0b74Schristos 	    break;
63675fd0b74Schristos 	  default:
63775fd0b74Schristos 	    return R_PARISC_NONE;
63875fd0b74Schristos 	}
63975fd0b74Schristos       break;
64075fd0b74Schristos 
64175fd0b74Schristos     case R_PARISC_TLS_LDM21L:
64275fd0b74Schristos       switch (field)
64375fd0b74Schristos 	{
64475fd0b74Schristos 	  case e_ltsel:
64575fd0b74Schristos 	  case e_lrsel:
64675fd0b74Schristos 	    final_type = R_PARISC_TLS_LDM21L;
64775fd0b74Schristos 	    break;
64875fd0b74Schristos 	  case e_rtsel:
64975fd0b74Schristos 	  case e_rrsel:
65075fd0b74Schristos 	    final_type = R_PARISC_TLS_LDM14R;
65175fd0b74Schristos 	    break;
65275fd0b74Schristos 	  default:
65375fd0b74Schristos 	    return R_PARISC_NONE;
65475fd0b74Schristos 	}
65575fd0b74Schristos       break;
65675fd0b74Schristos 
65775fd0b74Schristos     case R_PARISC_TLS_LDO21L:
65875fd0b74Schristos       switch (field)
65975fd0b74Schristos 	{
66075fd0b74Schristos 	  case e_lrsel:
66175fd0b74Schristos 	    final_type = R_PARISC_TLS_LDO21L;
66275fd0b74Schristos 	    break;
66375fd0b74Schristos 	  case e_rrsel:
66475fd0b74Schristos 	    final_type = R_PARISC_TLS_LDO14R;
66575fd0b74Schristos 	    break;
66675fd0b74Schristos 	  default:
66775fd0b74Schristos 	    return R_PARISC_NONE;
66875fd0b74Schristos 	}
66975fd0b74Schristos       break;
67075fd0b74Schristos 
67175fd0b74Schristos     case R_PARISC_TLS_IE21L:
67275fd0b74Schristos       switch (field)
67375fd0b74Schristos 	{
67475fd0b74Schristos 	  case e_ltsel:
67575fd0b74Schristos 	  case e_lrsel:
67675fd0b74Schristos 	    final_type = R_PARISC_TLS_IE21L;
67775fd0b74Schristos 	    break;
67875fd0b74Schristos 	  case e_rtsel:
67975fd0b74Schristos 	  case e_rrsel:
68075fd0b74Schristos 	    final_type = R_PARISC_TLS_IE14R;
68175fd0b74Schristos 	    break;
68275fd0b74Schristos 	  default:
68375fd0b74Schristos 	    return R_PARISC_NONE;
68475fd0b74Schristos 	}
68575fd0b74Schristos       break;
68675fd0b74Schristos 
68775fd0b74Schristos     case R_PARISC_TLS_LE21L:
68875fd0b74Schristos       switch (field)
68975fd0b74Schristos 	{
69075fd0b74Schristos 	  case e_lrsel:
69175fd0b74Schristos 	    final_type = R_PARISC_TLS_LE21L;
69275fd0b74Schristos 	    break;
69375fd0b74Schristos 	  case e_rrsel:
69475fd0b74Schristos 	    final_type = R_PARISC_TLS_LE14R;
69575fd0b74Schristos 	    break;
69675fd0b74Schristos 	  default:
69775fd0b74Schristos 	    return R_PARISC_NONE;
69875fd0b74Schristos 	}
69975fd0b74Schristos       break;
70075fd0b74Schristos 
70175fd0b74Schristos     case R_PARISC_SEGREL32:
70275fd0b74Schristos       switch (format)
70375fd0b74Schristos 	{
70475fd0b74Schristos 	case 32:
70575fd0b74Schristos 	  switch (field)
70675fd0b74Schristos 	    {
70775fd0b74Schristos 	    case e_fsel:
70875fd0b74Schristos 	      final_type = R_PARISC_SEGREL32;
70975fd0b74Schristos 	      break;
71075fd0b74Schristos 	    default:
71175fd0b74Schristos 	      return R_PARISC_NONE;
71275fd0b74Schristos 	    }
71375fd0b74Schristos 	  break;
71475fd0b74Schristos 
71575fd0b74Schristos 	case 64:
71675fd0b74Schristos 	  switch (field)
71775fd0b74Schristos 	    {
71875fd0b74Schristos 	    case e_fsel:
71975fd0b74Schristos 	      final_type = R_PARISC_SEGREL64;
72075fd0b74Schristos 	      break;
72175fd0b74Schristos 	    default:
72275fd0b74Schristos 	      return R_PARISC_NONE;
72375fd0b74Schristos 	    }
72475fd0b74Schristos 	  break;
72575fd0b74Schristos 
72675fd0b74Schristos 	default:
72775fd0b74Schristos 	  return R_PARISC_NONE;
72875fd0b74Schristos 	}
72975fd0b74Schristos       break;
73075fd0b74Schristos 
73175fd0b74Schristos     case R_PARISC_GNU_VTENTRY:
73275fd0b74Schristos     case R_PARISC_GNU_VTINHERIT:
73375fd0b74Schristos     case R_PARISC_SEGBASE:
73475fd0b74Schristos       /* The defaults are fine for these cases.  */
73575fd0b74Schristos       break;
73675fd0b74Schristos 
73775fd0b74Schristos     default:
73875fd0b74Schristos       return R_PARISC_NONE;
73975fd0b74Schristos     }
74075fd0b74Schristos 
74175fd0b74Schristos   return final_type;
74275fd0b74Schristos }
74375fd0b74Schristos 
74475fd0b74Schristos /* Return one (or more) BFD relocations which implement the base
74575fd0b74Schristos    relocation with modifications based on format and field.  */
74675fd0b74Schristos 
74775fd0b74Schristos elf_hppa_reloc_type **
_bfd_elf_hppa_gen_reloc_type(bfd * abfd,elf_hppa_reloc_type base_type,int format,unsigned int field,int ignore ATTRIBUTE_UNUSED,asymbol * sym ATTRIBUTE_UNUSED)74875fd0b74Schristos _bfd_elf_hppa_gen_reloc_type (bfd *abfd,
74975fd0b74Schristos 			      elf_hppa_reloc_type base_type,
75075fd0b74Schristos 			      int format,
75175fd0b74Schristos 			      unsigned int field,
75275fd0b74Schristos 			      int ignore ATTRIBUTE_UNUSED,
75375fd0b74Schristos 			      asymbol *sym ATTRIBUTE_UNUSED)
75475fd0b74Schristos {
75575fd0b74Schristos   elf_hppa_reloc_type *finaltype;
75675fd0b74Schristos   elf_hppa_reloc_type **final_types;
757*e992f068Schristos   size_t amt = sizeof (elf_hppa_reloc_type *) * 2;
75875fd0b74Schristos 
75975fd0b74Schristos   /* Allocate slots for the BFD relocation.  */
76075fd0b74Schristos   final_types = bfd_alloc (abfd, amt);
76175fd0b74Schristos   if (final_types == NULL)
76275fd0b74Schristos     return NULL;
76375fd0b74Schristos 
76475fd0b74Schristos   /* Allocate space for the relocation itself.  */
76575fd0b74Schristos   amt = sizeof (elf_hppa_reloc_type);
76675fd0b74Schristos   finaltype = bfd_alloc (abfd, amt);
76775fd0b74Schristos   if (finaltype == NULL)
76875fd0b74Schristos     return NULL;
76975fd0b74Schristos 
77075fd0b74Schristos   /* Some reasonable defaults.  */
77175fd0b74Schristos   final_types[0] = finaltype;
77275fd0b74Schristos   final_types[1] = NULL;
77375fd0b74Schristos 
77475fd0b74Schristos   *finaltype = elf_hppa_reloc_final_type (abfd, base_type, format, field);
77575fd0b74Schristos 
77675fd0b74Schristos   return final_types;
77775fd0b74Schristos }
77875fd0b74Schristos 
77975fd0b74Schristos /* Translate from an elf into field into a howto relocation pointer.  */
78075fd0b74Schristos 
781*e992f068Schristos static bool
elf_hppa_info_to_howto(bfd * abfd,arelent * bfd_reloc,Elf_Internal_Rela * elf_reloc)782ede78133Schristos elf_hppa_info_to_howto (bfd *abfd,
78375fd0b74Schristos 			arelent *bfd_reloc,
78475fd0b74Schristos 			Elf_Internal_Rela *elf_reloc)
78575fd0b74Schristos {
786ede78133Schristos   unsigned int r_type = ELF32_R_TYPE (elf_reloc->r_info);
787ede78133Schristos   unsigned int type = r_type;
788ede78133Schristos   reloc_howto_type *howto = NULL;
789ede78133Schristos 
790ede78133Schristos   if (r_type < (unsigned int) R_PARISC_UNIMPLEMENTED)
791ede78133Schristos     {
792ede78133Schristos       howto = &elf_hppa_howto_table[r_type];
793ede78133Schristos       type = howto->type;
794ede78133Schristos     }
795ede78133Schristos   if (type >= (unsigned int) R_PARISC_UNIMPLEMENTED)
796ede78133Schristos     {
797ede78133Schristos       /* xgettext:c-format */
798ede78133Schristos       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
799ede78133Schristos 			  abfd, r_type);
800ede78133Schristos       bfd_set_error (bfd_error_bad_value);
801*e992f068Schristos       return false;
802ede78133Schristos     }
803ede78133Schristos   bfd_reloc->howto = howto;
804*e992f068Schristos   return true;
80575fd0b74Schristos }
80675fd0b74Schristos 
80775fd0b74Schristos /* Translate from an elf into field into a howto relocation pointer.  */
80875fd0b74Schristos 
809*e992f068Schristos static bool
elf_hppa_info_to_howto_rel(bfd * abfd,arelent * bfd_reloc,Elf_Internal_Rela * elf_reloc)810ede78133Schristos elf_hppa_info_to_howto_rel (bfd *abfd,
81175fd0b74Schristos 			    arelent *bfd_reloc,
81275fd0b74Schristos 			    Elf_Internal_Rela *elf_reloc)
81375fd0b74Schristos {
814ede78133Schristos   unsigned int r_type = ELF_R_TYPE (elf_reloc->r_info);
815ede78133Schristos   unsigned int type = r_type;
816ede78133Schristos   reloc_howto_type *howto = NULL;
817ede78133Schristos 
818ede78133Schristos   if (r_type < (unsigned int) R_PARISC_UNIMPLEMENTED)
819ede78133Schristos     {
820ede78133Schristos       howto = &elf_hppa_howto_table[r_type];
821ede78133Schristos       type = howto->type;
822ede78133Schristos     }
823ede78133Schristos   if (type >= (unsigned int) R_PARISC_UNIMPLEMENTED)
824ede78133Schristos     {
825ede78133Schristos       /* xgettext:c-format */
826ede78133Schristos       _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
827ede78133Schristos 			  abfd, r_type);
828ede78133Schristos       bfd_set_error (bfd_error_bad_value);
829*e992f068Schristos       return false;
830ede78133Schristos     }
831ede78133Schristos   bfd_reloc->howto = howto;
832*e992f068Schristos   return true;
83375fd0b74Schristos }
83475fd0b74Schristos 
83575fd0b74Schristos /* Return the address of the howto table entry to perform the CODE
83675fd0b74Schristos    relocation for an ARCH machine.  */
83775fd0b74Schristos 
83875fd0b74Schristos static reloc_howto_type *
elf_hppa_reloc_type_lookup(bfd * abfd ATTRIBUTE_UNUSED,bfd_reloc_code_real_type code)83975fd0b74Schristos elf_hppa_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
84075fd0b74Schristos 			    bfd_reloc_code_real_type code)
84175fd0b74Schristos {
84275fd0b74Schristos   if ((int) code < (int) R_PARISC_UNIMPLEMENTED)
84375fd0b74Schristos     {
84475fd0b74Schristos       BFD_ASSERT ((int) elf_hppa_howto_table[(int) code].type == (int) code);
84575fd0b74Schristos       return &elf_hppa_howto_table[(int) code];
84675fd0b74Schristos     }
84775fd0b74Schristos   return NULL;
84875fd0b74Schristos }
84975fd0b74Schristos 
85075fd0b74Schristos static reloc_howto_type *
elf_hppa_reloc_name_lookup(bfd * abfd ATTRIBUTE_UNUSED,const char * r_name)85175fd0b74Schristos elf_hppa_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
85275fd0b74Schristos 			    const char *r_name)
85375fd0b74Schristos {
85475fd0b74Schristos   unsigned int i;
85575fd0b74Schristos 
85675fd0b74Schristos   for (i = 0;
85775fd0b74Schristos        i < sizeof (elf_hppa_howto_table) / sizeof (elf_hppa_howto_table[0]);
85875fd0b74Schristos        i++)
85975fd0b74Schristos     if (elf_hppa_howto_table[i].name != NULL
86075fd0b74Schristos 	&& strcasecmp (elf_hppa_howto_table[i].name, r_name) == 0)
86175fd0b74Schristos       return &elf_hppa_howto_table[i];
86275fd0b74Schristos 
86375fd0b74Schristos   return NULL;
86475fd0b74Schristos }
86575fd0b74Schristos 
86675fd0b74Schristos /* Return TRUE if SYM represents a local label symbol.  */
86775fd0b74Schristos 
868*e992f068Schristos static bool
elf_hppa_is_local_label_name(bfd * abfd ATTRIBUTE_UNUSED,const char * name)86975fd0b74Schristos elf_hppa_is_local_label_name (bfd *abfd ATTRIBUTE_UNUSED, const char *name)
87075fd0b74Schristos {
87175fd0b74Schristos   if (name[0] == 'L' && name[1] == '$')
872*e992f068Schristos     return true;
87375fd0b74Schristos   return _bfd_elf_is_local_label_name (abfd, name);
87475fd0b74Schristos }
87575fd0b74Schristos 
87675fd0b74Schristos /* Set the correct type for an ELF section.  We do this by the
87775fd0b74Schristos    section name, which is a hack, but ought to work.  */
87875fd0b74Schristos 
879*e992f068Schristos static bool
elf_hppa_fake_sections(bfd * abfd,Elf_Internal_Shdr * hdr,asection * sec)88075fd0b74Schristos elf_hppa_fake_sections (bfd *abfd, Elf_Internal_Shdr *hdr, asection *sec)
88175fd0b74Schristos {
88275fd0b74Schristos   const char *name;
88375fd0b74Schristos 
884012573ebSchristos   name = bfd_section_name (sec);
88575fd0b74Schristos 
88675fd0b74Schristos   if (strcmp (name, ".PARISC.unwind") == 0)
88775fd0b74Schristos     {
88875fd0b74Schristos       int indx;
88975fd0b74Schristos       asection *asec;
89075fd0b74Schristos 
89175fd0b74Schristos #if ARCH_SIZE == 64
892012573ebSchristos       hdr->sh_type = SHT_PARISC_UNWIND;
89375fd0b74Schristos #else
894012573ebSchristos       /* Note - it is not clear why this is not SHT_PARISC_UNWIND as well.
895012573ebSchristos 	 Presumably it is a historical constraint, so leave it as it is.  */
896012573ebSchristos       hdr->sh_type = SHT_PROGBITS;
89775fd0b74Schristos #endif
89875fd0b74Schristos       /* ?!? How are unwinds supposed to work for symbols in arbitrary
89975fd0b74Schristos 	 sections?  Or what if we have multiple .text sections in a single
90075fd0b74Schristos 	 .o file?  HP really messed up on this one.
90175fd0b74Schristos 
90275fd0b74Schristos 	 Ugh.  We can not use elf_section_data (sec)->this_idx at this
90375fd0b74Schristos 	 point because it is not initialized yet.
90475fd0b74Schristos 
90575fd0b74Schristos 	 So we (gasp) recompute it here.  Hopefully nobody ever changes the
90675fd0b74Schristos 	 way sections are numbered in elf.c!  */
90775fd0b74Schristos       for (asec = abfd->sections, indx = 1; asec; asec = asec->next, indx++)
90875fd0b74Schristos 	{
90975fd0b74Schristos 	  if (asec->name && strcmp (asec->name, ".text") == 0)
91075fd0b74Schristos 	    {
91175fd0b74Schristos 	      hdr->sh_info = indx;
912ede78133Schristos 	      hdr->sh_flags |= SHF_INFO_LINK;
91375fd0b74Schristos 	      break;
91475fd0b74Schristos 	    }
91575fd0b74Schristos 	}
91675fd0b74Schristos 
917012573ebSchristos       /* The unwind table entries are 16 bytes long, so it is not clear
918012573ebSchristos 	 why this field is set to 4.  (The ELF spec says that the sh_entsize
919012573ebSchristos 	 field is a byte quantity, but this is a processor specific section,
920012573ebSchristos 	 so it is allowed to change the rules).  Leave as it is for now.  */
92175fd0b74Schristos       hdr->sh_entsize = 4;
92275fd0b74Schristos     }
923*e992f068Schristos   return true;
92475fd0b74Schristos }
92575fd0b74Schristos 
926*e992f068Schristos static bool
elf_hppa_final_write_processing(bfd * abfd)927012573ebSchristos elf_hppa_final_write_processing (bfd *abfd)
92875fd0b74Schristos {
92975fd0b74Schristos   int mach = bfd_get_mach (abfd);
93075fd0b74Schristos 
93175fd0b74Schristos   elf_elfheader (abfd)->e_flags &= ~(EF_PARISC_ARCH | EF_PARISC_TRAPNIL
93275fd0b74Schristos 				     | EF_PARISC_EXT | EF_PARISC_LSB
93375fd0b74Schristos 				     | EF_PARISC_WIDE | EF_PARISC_NO_KABP
93475fd0b74Schristos 				     | EF_PARISC_LAZYSWAP);
93575fd0b74Schristos 
93675fd0b74Schristos   if (mach == 10)
93775fd0b74Schristos     elf_elfheader (abfd)->e_flags |= EFA_PARISC_1_0;
93875fd0b74Schristos   else if (mach == 11)
93975fd0b74Schristos     elf_elfheader (abfd)->e_flags |= EFA_PARISC_1_1;
94075fd0b74Schristos   else if (mach == 20)
94175fd0b74Schristos     elf_elfheader (abfd)->e_flags |= EFA_PARISC_2_0;
94275fd0b74Schristos   else if (mach == 25)
94375fd0b74Schristos     elf_elfheader (abfd)->e_flags |= (EF_PARISC_WIDE
94475fd0b74Schristos 				      | EFA_PARISC_2_0
94575fd0b74Schristos 				      /* The GNU tools have trapped without
94675fd0b74Schristos 					 option since 1993, so need to take
94775fd0b74Schristos 					 a step backwards with the ELF
94875fd0b74Schristos 					 based toolchains.  */
94975fd0b74Schristos 				      | EF_PARISC_TRAPNIL);
950012573ebSchristos   return _bfd_elf_final_write_processing (abfd);
95175fd0b74Schristos }
95275fd0b74Schristos 
95375fd0b74Schristos /* Comparison function for qsort to sort unwind section during a
95475fd0b74Schristos    final link.  */
95575fd0b74Schristos 
95675fd0b74Schristos static int
hppa_unwind_entry_compare(const void * a,const void * b)95775fd0b74Schristos hppa_unwind_entry_compare (const void *a, const void *b)
95875fd0b74Schristos {
95975fd0b74Schristos   const bfd_byte *ap, *bp;
96075fd0b74Schristos   unsigned long av, bv;
96175fd0b74Schristos 
96275fd0b74Schristos   ap = a;
96375fd0b74Schristos   av = (unsigned long) ap[0] << 24;
96475fd0b74Schristos   av |= (unsigned long) ap[1] << 16;
96575fd0b74Schristos   av |= (unsigned long) ap[2] << 8;
96675fd0b74Schristos   av |= (unsigned long) ap[3];
96775fd0b74Schristos 
96875fd0b74Schristos   bp = b;
96975fd0b74Schristos   bv = (unsigned long) bp[0] << 24;
97075fd0b74Schristos   bv |= (unsigned long) bp[1] << 16;
97175fd0b74Schristos   bv |= (unsigned long) bp[2] << 8;
97275fd0b74Schristos   bv |= (unsigned long) bp[3];
97375fd0b74Schristos 
97475fd0b74Schristos   return av < bv ? -1 : av > bv ? 1 : 0;
97575fd0b74Schristos }
97675fd0b74Schristos 
977*e992f068Schristos static bool
elf_hppa_sort_unwind(bfd * abfd)97875fd0b74Schristos elf_hppa_sort_unwind (bfd *abfd)
97975fd0b74Schristos {
98075fd0b74Schristos   asection *s;
98175fd0b74Schristos 
98275fd0b74Schristos   /* Magic section names, but this is much safer than having
98375fd0b74Schristos      relocate_section remember where SEGREL32 relocs occurred.
98475fd0b74Schristos      Consider what happens if someone inept creates a linker script
98575fd0b74Schristos      that puts unwind information in .text.  */
98675fd0b74Schristos   s = bfd_get_section_by_name (abfd, ".PARISC.unwind");
98775fd0b74Schristos   if (s != NULL)
98875fd0b74Schristos     {
98975fd0b74Schristos       bfd_size_type size;
99075fd0b74Schristos       bfd_byte *contents;
99175fd0b74Schristos 
99275fd0b74Schristos       if (!bfd_malloc_and_get_section (abfd, s, &contents))
993*e992f068Schristos 	return false;
99475fd0b74Schristos 
99575fd0b74Schristos       size = s->size;
99675fd0b74Schristos       qsort (contents, (size_t) (size / 16), 16, hppa_unwind_entry_compare);
99775fd0b74Schristos 
99875fd0b74Schristos       if (! bfd_set_section_contents (abfd, s, contents, (file_ptr) 0, size))
999*e992f068Schristos 	return false;
100075fd0b74Schristos     }
100175fd0b74Schristos 
1002*e992f068Schristos   return true;
100375fd0b74Schristos }
100475fd0b74Schristos 
100575fd0b74Schristos /* What to do when ld finds relocations against symbols defined in
100675fd0b74Schristos    discarded sections.  */
100775fd0b74Schristos 
100875fd0b74Schristos static unsigned int
elf_hppa_action_discarded(asection * sec)100975fd0b74Schristos elf_hppa_action_discarded (asection *sec)
101075fd0b74Schristos {
101175fd0b74Schristos   /* Ignore relocations in .data.rel.ro.local.  This section can contain
101275fd0b74Schristos      PLABEL32 relocations to functions in discarded COMDAT groups.  */
101375fd0b74Schristos   if (strcmp (".data.rel.ro.local", sec->name) == 0)
101475fd0b74Schristos     return 0;
101575fd0b74Schristos 
101675fd0b74Schristos   if (strcmp (".PARISC.unwind", sec->name) == 0)
101775fd0b74Schristos     return 0;
101875fd0b74Schristos 
101975fd0b74Schristos   return _bfd_elf_default_action_discarded (sec);
102075fd0b74Schristos }
1021