1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
6 Center for Software Science
7 Department of Computer Science
10 This file is part of BFD, the Binary File Descriptor library.
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
33 /* ELF32/HPPA relocation support
35 This file contains ELF32/HPPA relocation support as specified
36 in the Stratus FTX/Golf Object File Format (SED-1762) dated
40 #include "elf32-hppa.h"
42 #include "aout/aout64.h"
43 #include "hppa_stubs.h"
45 /* ELF/PA relocation howto entries */
47 static bfd_reloc_status_type hppa_elf_reloc
48 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
50 static reloc_howto_type elf_hppa_howto_table
[ELF_HOWTO_TABLE_SIZE
] =
52 /* 'bitpos' and 'abs' are obsolete */
53 /* type rs sz bsz pcrel bpos abs ovrf sf name */
54 /* 9.3.4. Address relocation types */
55 {R_HPPA_NONE
, 0, 3, 19, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_NONE"},
56 {R_HPPA_32
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_32"},
57 {R_HPPA_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_11"},
58 {R_HPPA_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_14"},
59 {R_HPPA_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_17"},
60 {R_HPPA_L21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_L21"},
61 {R_HPPA_R11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_R11"},
62 {R_HPPA_R14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_R14"},
63 {R_HPPA_R17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_R17"},
64 {R_HPPA_LS21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LS21"},
65 {R_HPPA_RS11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RS11"},
66 {R_HPPA_RS14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RS14"},
67 {R_HPPA_RS17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RS17"},
68 {R_HPPA_LD21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LD21"},
69 {R_HPPA_RD11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RD11"},
70 {R_HPPA_RD14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RD14"},
71 {R_HPPA_RD17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RD17"},
72 {R_HPPA_LR21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LR21"},
73 {R_HPPA_RR14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RR14"},
74 {R_HPPA_RR17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RR17"},
75 /* 9.3.5. GOTOFF address relocation types */
76 {R_HPPA_GOTOFF_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_11"},
77 {R_HPPA_GOTOFF_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_14"},
78 {R_HPPA_GOTOFF_L21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_L21"},
79 {R_HPPA_GOTOFF_R11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_R11"},
80 {R_HPPA_GOTOFF_R14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_R14"},
81 {R_HPPA_GOTOFF_LS21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_LS21"},
82 {R_HPPA_GOTOFF_RS11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RS11"},
83 {R_HPPA_GOTOFF_RS14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RS14"},
84 {R_HPPA_GOTOFF_LD21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_LD21"},
85 {R_HPPA_GOTOFF_RD11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RD11"},
86 {R_HPPA_GOTOFF_RD14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RD14"},
87 {R_HPPA_GOTOFF_LR21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_LR21"},
88 {R_HPPA_GOTOFF_RR14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RR14"},
89 /* 9.3.6. Absolute call relocation types */
90 {R_HPPA_ABS_CALL_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_11"},
91 {R_HPPA_ABS_CALL_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_14"},
92 {R_HPPA_ABS_CALL_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_17"},
93 {R_HPPA_ABS_CALL_L21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_L21"},
94 {R_HPPA_ABS_CALL_R11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_R11"},
95 {R_HPPA_ABS_CALL_R14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_R14"},
96 {R_HPPA_ABS_CALL_R17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_R17"},
97 {R_HPPA_ABS_CALL_LS21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_LS21"},
98 {R_HPPA_ABS_CALL_RS11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RS11"},
99 {R_HPPA_ABS_CALL_RS14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RS14"},
100 {R_HPPA_ABS_CALL_RS17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RS17"},
101 {R_HPPA_ABS_CALL_LD21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_LD21"},
102 {R_HPPA_ABS_CALL_RD11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RD11"},
103 {R_HPPA_ABS_CALL_RD14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RD14"},
104 {R_HPPA_ABS_CALL_RD17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RD17"},
105 {R_HPPA_ABS_CALL_LR21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_LR21"},
106 {R_HPPA_ABS_CALL_RR14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RR14"},
107 {R_HPPA_ABS_CALL_RR17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RR17"},
108 /* 9.3.7. PC-relative call relocation types */
109 {R_HPPA_PCREL_CALL_11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_11"},
110 {R_HPPA_PCREL_CALL_14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_14"},
111 {R_HPPA_PCREL_CALL_17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_17"},
112 {R_HPPA_PCREL_CALL_12
, 0, 3, 12, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_12"},
113 {R_HPPA_PCREL_CALL_L21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_L21"},
114 {R_HPPA_PCREL_CALL_R11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_R11"},
115 {R_HPPA_PCREL_CALL_R14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_R14"},
116 {R_HPPA_PCREL_CALL_R17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_R17"},
117 {R_HPPA_PCREL_CALL_LS21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_LS21"},
118 {R_HPPA_PCREL_CALL_RS11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RS11"},
119 {R_HPPA_PCREL_CALL_RS14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RS14"},
120 {R_HPPA_PCREL_CALL_RS17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RS17"},
121 {R_HPPA_PCREL_CALL_LD21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_LD21"},
122 {R_HPPA_PCREL_CALL_RD11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RD11"},
123 {R_HPPA_PCREL_CALL_RD14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RD14"},
124 {R_HPPA_PCREL_CALL_RD17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RD17"},
125 {R_HPPA_PCREL_CALL_LR21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_LR21"},
126 {R_HPPA_PCREL_CALL_RR14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RR14"},
127 {R_HPPA_PCREL_CALL_RR17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RR17"},
129 /* 9.3.8. Plabel relocation types */
130 {R_HPPA_PLABEL_32
, 0, 3, 32, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_32"},
131 {R_HPPA_PLABEL_11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_11"},
132 {R_HPPA_PLABEL_14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_14"},
133 {R_HPPA_PLABEL_L21
, 0, 3, 21, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_L21"},
134 {R_HPPA_PLABEL_R11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_R11"},
135 {R_HPPA_PLABEL_R14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_R14"},
137 /* 9.3.9. Data linkage table (DLT) relocation types */
138 {R_HPPA_DLT_32
, 0, 3, 32, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_32"},
139 {R_HPPA_DLT_11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_11"},
140 {R_HPPA_DLT_14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_14"},
141 {R_HPPA_DLT_L21
, 0, 3, 21, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_L21"},
142 {R_HPPA_DLT_R11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_R11"},
143 {R_HPPA_DLT_R14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_R14"},
145 /* 9.3.10. Relocations for unwinder tables */
146 {R_HPPA_UNWIND_ENTRY
, 0, 3, 32, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_UNWIND_ENTRY"},
147 {R_HPPA_UNWIND_ENTRIES
, 0, 3, 32, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_UNWIND_ENTRIES"},
149 /* 9.3.11. Relocation types for complex expressions */
150 {R_HPPA_PUSH_CONST
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_CONST"},
151 {R_HPPA_PUSH_PC
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_PC"},
152 {R_HPPA_PUSH_SYM
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_SYM"},
153 {R_HPPA_PUSH_GOTOFF
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_GOTOFF"},
154 {R_HPPA_PUSH_ABS_CALL
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_ABS_CALL"},
155 {R_HPPA_PUSH_PCREL_CALL
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_PCREL_CALL"},
156 {R_HPPA_PUSH_PLABEL
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_PLABEL"},
157 {R_HPPA_MAX
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MAX"},
158 {R_HPPA_MIN
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MIN"},
159 {R_HPPA_ADD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ADD"},
160 {R_HPPA_SUB
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_SUB"},
161 {R_HPPA_MULT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MULT"},
162 {R_HPPA_DIV
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_DIV"},
163 {R_HPPA_MOD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MOD"},
164 {R_HPPA_AND
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_AND"},
165 {R_HPPA_OR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_OR"},
166 {R_HPPA_XOR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_XOR"},
167 {R_HPPA_NOT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_NOT"},
168 {R_HPPA_LSHIFT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LSHIFT"},
169 {R_HPPA_ARITH_RSHIFT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ARITH_RSHIFT"},
170 {R_HPPA_LOGIC_RSHIFT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LOGIC_RSHIFT"},
171 {R_HPPA_EXPR_F
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_L"},
172 {R_HPPA_EXPR_L
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_L"},
173 {R_HPPA_EXPR_R
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_R"},
174 {R_HPPA_EXPR_LS
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_LS"},
175 {R_HPPA_EXPR_RS
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_RS"},
176 {R_HPPA_EXPR_LD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_LD"},
177 {R_HPPA_EXPR_RD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_RD"},
178 {R_HPPA_EXPR_LR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_LR"},
179 {R_HPPA_EXPR_RR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_RR"},
181 {R_HPPA_EXPR_32
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_32"},
182 {R_HPPA_EXPR_21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_21"},
183 {R_HPPA_EXPR_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_11"},
184 {R_HPPA_EXPR_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_14"},
185 {R_HPPA_EXPR_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_17"},
186 {R_HPPA_EXPR_12
, 0, 3, 12, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_12"},
187 {R_HPPA_STUB_CALL_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_STUB_CALL_17"},
188 {R_HPPA_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_dont
, NULL
, "R_HPPA_UNIMPLEMENTED"},
191 static symext_chainS
*symext_rootP
;
192 static symext_chainS
*symext_lastP
;
193 static boolean symext_chain_built
;
196 DEFUN (hppa_elf_rebuild_insn
, (abfd
, insn
, value
, r_type
, r_field
, r_format
),
198 unsigned long insn AND
199 unsigned long value AND
200 unsigned short r_type AND
201 unsigned short r_field AND
202 unsigned short r_format
)
204 unsigned long const_part
; /* part of the instruction that does not change */
205 unsigned long rebuilt_part
;
213 const_part
= insn
& 0xffffe002;
214 dis_assemble_12 (value
, &w1
, &w
);
215 rebuilt_part
= (w1
<< 2) | w
;
216 return const_part
| rebuilt_part
;
223 const_part
= insn
& 0xffffe002;
224 dis_assemble_12 (value
, &w1
, &w
);
225 rebuilt_part
= (w1
<< 2) | w
;
226 return const_part
| rebuilt_part
;
230 const_part
= insn
& 0xffffc000;
231 low_sign_unext (value
, 14, &rebuilt_part
);
232 return const_part
| rebuilt_part
;
238 const_part
= insn
& 0xffe0e002;
239 dis_assemble_17 (value
, &w1
, &w2
, &w
);
240 rebuilt_part
= (w2
<< 2) | (w1
<< 16) | w
;
241 return const_part
| rebuilt_part
;
245 const_part
= insn
& 0xffe00000;
246 dis_assemble_21 (value
, &rebuilt_part
);
247 return const_part
| rebuilt_part
;
254 fprintf (stderr
, "Relocation problem : ");
256 "Unrecognized reloc type %d (fmt=%d,fld=%d), in module %s\n",
257 r_type
, r_format
, r_field
, abfd
->filename
);
263 DEFUN (hppa_elf_relocate_insn
,
265 insn
, address
, symp
, sym_value
, r_addend
,
266 r_type
, r_format
, r_field
, pcrel
),
268 asection
* input_sect AND
269 unsigned long insn AND
270 unsigned long address AND
274 unsigned short r_type AND
275 unsigned short r_format AND
276 unsigned short r_field AND
279 unsigned char opcode
= get_opcode (insn
);
294 constant_value
= HPPA_R_CONSTANT (r_addend
);
295 BFD_ASSERT (r_format
== 14);
298 sym_value
-= address
;
299 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
300 return hppa_elf_rebuild_insn (abfd
, insn
, sym_value
, r_type
, r_field
, r_format
);
303 case SUBI
: /* case SUBIO: */
304 case ADDIT
: /* case ADDITO: */
305 case ADDI
: /* case ADDIO: */
306 BFD_ASSERT (r_format
== 11);
308 constant_value
= HPPA_R_CONSTANT(r_addend
);
309 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
310 return hppa_elf_rebuild_insn (abfd
, insn
, sym_value
, r_type
, r_field
, r_format
);
314 BFD_ASSERT (r_format
== 21);
316 constant_value
= HPPA_R_CONSTANT (r_addend
);
317 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
318 return hppa_elf_rebuild_insn (abfd
, insn
, sym_value
, r_type
, r_field
, r_format
);
323 arg_reloc
= HPPA_R_ARG_RELOC (r_addend
);
325 BFD_ASSERT (r_format
== 17);
327 /* XXX computing constant_value is not needed??? */
328 constant_value
= assemble_17 ((insn
& 0x001f0000) >> 16,
329 (insn
& 0x00001ffc) >> 2,
331 /* @@ Assumes only 32 bits. */
332 constant_value
= (constant_value
<< 15) >> 15;
336 address
+ input_sect
->output_offset
337 + input_sect
->output_section
->vma
;
338 sym_value
= hppa_field_adjust (sym_value
, -8, r_field
);
341 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
343 return hppa_elf_rebuild_insn (abfd
, insn
, sym_value
>> 2, r_type
, r_field
, r_format
);
348 BFD_ASSERT (r_format
== 32);
349 constant_value
= HPPA_R_CONSTANT (r_addend
);
351 return hppa_field_adjust (sym_value
, constant_value
, r_field
);
356 "Unrecognized opcode 0x%02x (fmt=%x,field=%x)\n",
357 opcode
, r_format
, r_field
);
364 DEFUN (hppa_elf_relocate_unwind_table
,
366 data
, address
, symp
, sym_value
, r_addend
,
367 r_type
, r_format
, r_field
, pcrel
),
369 asection
* input_sect AND
371 unsigned long address AND
375 unsigned short r_type AND
376 unsigned short r_format AND
377 unsigned short r_field AND
380 bfd_byte
*hit_data
= address
+ (bfd_byte
*) (data
);
383 long relocated_value
;
386 BFD_ASSERT (r_format
== 32);
387 BFD_ASSERT (r_field
== e_fsel
);
390 case R_HPPA_UNWIND_ENTRY
:
391 start_offset
= bfd_get_32 (abfd
, hit_data
);
392 relocated_value
= hppa_field_adjust (sym_value
, start_offset
, r_field
);
393 bfd_put_32 (abfd
, relocated_value
, hit_data
);
395 hit_data
+= sizeof (unsigned long);
396 end_offset
= bfd_get_32 (abfd
, hit_data
);
397 relocated_value
= hppa_field_adjust (sym_value
, end_offset
, r_field
);
398 bfd_put_32 (abfd
, relocated_value
, hit_data
);
401 case R_HPPA_UNWIND_ENTRIES
:
402 for (i
= 0; i
< r_addend
; i
++, hit_data
+= 3 * sizeof (unsigned long))
404 unsigned int adjustment
;
405 start_offset
= bfd_get_32 (abfd
, hit_data
);
406 /* Stuff the symbol value into the first word */
407 /* of the unwind descriptor */
408 bfd_put_32 (abfd
, sym_value
, hit_data
);
409 adjustment
= sym_value
- start_offset
;
411 hit_data
+= sizeof (unsigned long);
412 end_offset
= adjustment
+ bfd_get_32 (abfd
, hit_data
);
413 bfd_put_32 (abfd
, end_offset
, hit_data
);
415 /* If this is not the last unwind entry, */
416 /* adjust the symbol value. */
417 if (i
+ 1 < r_addend
)
419 start_offset
= bfd_get_32 (abfd
, hit_data
+ 3 * sizeof (unsigned long));
420 sym_value
= start_offset
+ adjustment
;
427 "Unrecognized relocation type 0x%02x (fmt=%x,field=%x)\n",
428 r_type
, r_format
, r_field
);
432 /* Provided the symbol, returns the value reffed */
434 get_symbol_value (symbol
)
439 if (symbol
== (asymbol
*) NULL
)
441 else if (symbol
->section
== &bfd_com_section
)
447 relocation
= symbol
->value
+
448 symbol
->section
->output_section
->vma
+
449 symbol
->section
->output_offset
;
455 /* This function provides a pretty straight-forward mapping between a */
456 /* base relocation type, format and field into the relocation type */
457 /* that will be emitted in an object file. The only wrinkle in the */
458 /* mapping is that when the T, TR, TL, P, PR, or PL expression */
459 /* prefixes are involved, the type gets promoted to a *_GOTOFF_* */
460 /* relocation (in the case of T, TR, and TL) or a PLABEL relocation */
461 /* (in the case of P, PR, and PL). */
463 /* NOTE: XXX the T, TR, TL, P, PR, and PL expression prefixes are not */
467 hppa_elf_gen_reloc_error (base_type
, fmt
, field
)
468 elf32_hppa_reloc_type base_type
;
472 fprintf (stderr
, "undefined relocation: base=0x%x,fmt=0x%x,field=0x%x\n",
473 base_type
, fmt
, field
);
476 elf32_hppa_reloc_type
**
477 hppa_elf_gen_reloc_type (abfd
, base_type
, format
, field
)
479 elf32_hppa_reloc_type base_type
;
483 #define UNDEFINED hppa_elf_gen_reloc_error(base_type,format,field)
485 elf32_hppa_reloc_type
*finaltype
;
486 elf32_hppa_reloc_type
**final_types
;
489 final_types
= (elf32_hppa_reloc_type
**) bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
*) * 2);
490 BFD_ASSERT (final_types
!= 0);
492 finaltype
= (elf32_hppa_reloc_type
*) bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
));
493 BFD_ASSERT (finaltype
!= 0);
495 final_types
[0] = finaltype
;
496 final_types
[1] = NULL
;
498 #define final_type finaltype[0]
500 final_type
= base_type
;
511 final_type
= R_HPPA_11
;
514 final_type
= R_HPPA_R11
;
517 final_type
= R_HPPA_RS11
;
520 final_type
= R_HPPA_RD11
;
524 final_type
= R_HPPA_PLABEL_11
;
527 final_type
= R_HPPA_PLABEL_R11
;
530 final_type
= R_HPPA_DLT_11
;
533 final_type
= R_HPPA_DLT_R11
;
544 final_type
= base_type
;
555 final_type
= R_HPPA_R14
;
558 final_type
= R_HPPA_RS14
;
561 final_type
= R_HPPA_RD14
;
564 final_type
= R_HPPA_RR14
;
568 final_type
= R_HPPA_PLABEL_14
;
571 final_type
= R_HPPA_PLABEL_R14
;
574 final_type
= R_HPPA_DLT_14
;
577 final_type
= R_HPPA_DLT_R14
;
590 final_type
= base_type
;
598 final_type
= R_HPPA_17
;
601 final_type
= R_HPPA_R17
;
604 final_type
= R_HPPA_RS17
;
607 final_type
= R_HPPA_RD17
;
610 final_type
= R_HPPA_RR17
;
618 final_type
= base_type
;
626 final_type
= R_HPPA_L21
;
629 final_type
= R_HPPA_LS21
;
632 final_type
= R_HPPA_LD21
;
635 final_type
= R_HPPA_LR21
;
638 final_type
= R_HPPA_PLABEL_L21
;
641 final_type
= R_HPPA_PLABEL_L21
;
650 final_type
= base_type
;
658 final_type
= R_HPPA_32
;
661 final_type
= R_HPPA_PLABEL_32
;
664 final_type
= R_HPPA_DLT_32
;
668 final_type
= base_type
;
674 final_type
= base_type
;
685 final_type
= R_HPPA_GOTOFF_R11
;
688 final_type
= R_HPPA_GOTOFF_RS11
;
691 final_type
= R_HPPA_GOTOFF_RD11
;
694 final_type
= R_HPPA_GOTOFF_11
;
702 final_type
= base_type
;
708 final_type
= base_type
;
714 final_type
= R_HPPA_GOTOFF_R14
;
717 final_type
= R_HPPA_GOTOFF_RS14
;
720 final_type
= R_HPPA_GOTOFF_RD14
;
723 final_type
= R_HPPA_GOTOFF_RR14
;
726 final_type
= R_HPPA_GOTOFF_14
;
734 final_type
= base_type
;
740 final_type
= base_type
;
746 final_type
= R_HPPA_GOTOFF_L21
;
749 final_type
= R_HPPA_GOTOFF_LS21
;
752 final_type
= R_HPPA_GOTOFF_LD21
;
755 final_type
= R_HPPA_GOTOFF_LR21
;
764 final_type
= base_type
;
770 final_type
= base_type
;
774 final_type
= base_type
;
778 case R_HPPA_PCREL_CALL
:
785 final_type
= R_HPPA_PCREL_CALL_R11
;
788 final_type
= R_HPPA_PCREL_CALL_RS11
;
791 final_type
= R_HPPA_PCREL_CALL_RD11
;
794 final_type
= R_HPPA_PCREL_CALL_11
;
802 final_type
= base_type
;
808 final_type
= base_type
;
814 final_type
= R_HPPA_PCREL_CALL_R14
;
817 final_type
= R_HPPA_PCREL_CALL_RS14
;
820 final_type
= R_HPPA_PCREL_CALL_RD14
;
823 final_type
= R_HPPA_PCREL_CALL_RR14
;
826 final_type
= R_HPPA_PCREL_CALL_14
;
834 final_type
= base_type
;
842 final_type
= R_HPPA_PCREL_CALL_R17
;
845 final_type
= R_HPPA_PCREL_CALL_RS17
;
848 final_type
= R_HPPA_PCREL_CALL_RD17
;
851 final_type
= R_HPPA_PCREL_CALL_RR17
;
854 final_type
= R_HPPA_PCREL_CALL_17
;
862 final_type
= base_type
;
870 final_type
= R_HPPA_PCREL_CALL_L21
;
873 final_type
= R_HPPA_PCREL_CALL_LS21
;
876 final_type
= R_HPPA_PCREL_CALL_LD21
;
879 final_type
= R_HPPA_PCREL_CALL_LR21
;
888 final_type
= base_type
;
894 final_type
= base_type
;
898 final_type
= base_type
;
909 final_type
= R_HPPA_PLABEL_11
;
912 final_type
= R_HPPA_PLABEL_R11
;
916 final_type
= base_type
;
924 final_type
= R_HPPA_PLABEL_14
;
927 final_type
= R_HPPA_PLABEL_R14
;
931 final_type
= base_type
;
939 final_type
= R_HPPA_PLABEL_L21
;
943 final_type
= base_type
;
951 final_type
= R_HPPA_PLABEL_32
;
955 final_type
= base_type
;
961 final_type
= base_type
;
964 case R_HPPA_ABS_CALL
:
971 final_type
= R_HPPA_ABS_CALL_R11
;
974 final_type
= R_HPPA_ABS_CALL_RS11
;
977 final_type
= R_HPPA_ABS_CALL_RD11
;
980 final_type
= R_HPPA_ABS_CALL_11
;
988 final_type
= base_type
;
994 final_type
= base_type
;
1000 final_type
= R_HPPA_ABS_CALL_R14
;
1003 final_type
= R_HPPA_ABS_CALL_RS14
;
1006 final_type
= R_HPPA_ABS_CALL_RD14
;
1009 final_type
= R_HPPA_ABS_CALL_RR14
;
1012 final_type
= R_HPPA_ABS_CALL_14
;
1020 final_type
= base_type
;
1028 final_type
= R_HPPA_ABS_CALL_R17
;
1031 final_type
= R_HPPA_ABS_CALL_RS17
;
1034 final_type
= R_HPPA_ABS_CALL_RD17
;
1037 final_type
= R_HPPA_ABS_CALL_RR17
;
1040 final_type
= R_HPPA_ABS_CALL_17
;
1048 final_type
= base_type
;
1056 final_type
= R_HPPA_ABS_CALL_L21
;
1059 final_type
= R_HPPA_ABS_CALL_LS21
;
1062 final_type
= R_HPPA_ABS_CALL_LD21
;
1065 final_type
= R_HPPA_ABS_CALL_LR21
;
1074 final_type
= base_type
;
1080 final_type
= base_type
;
1084 final_type
= base_type
;
1089 final_type
= R_HPPA_UNWIND_ENTRY
;
1091 case R_HPPA_COMPLEX
:
1092 case R_HPPA_COMPLEX_PCREL_CALL
:
1093 case R_HPPA_COMPLEX_ABS_CALL
:
1094 final_types
= (elf32_hppa_reloc_type
**) bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
*) * 6);
1095 BFD_ASSERT (final_types
!= 0);
1097 finaltype
= (elf32_hppa_reloc_type
*) bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
) * 5);
1098 BFD_ASSERT (finaltype
!= 0);
1100 for (i
= 0; i
< 5; i
++)
1101 final_types
[i
] = &finaltype
[i
];
1103 final_types
[5] = NULL
;
1105 finaltype
[0] = R_HPPA_PUSH_SYM
;
1107 if (base_type
== R_HPPA_COMPLEX
)
1108 finaltype
[1] = R_HPPA_PUSH_SYM
;
1109 else if (base_type
== R_HPPA_COMPLEX_PCREL_CALL
)
1110 finaltype
[1] = R_HPPA_PUSH_PCREL_CALL
;
1111 else /* base_type == R_HPPA_COMPLEX_ABS_CALL */
1112 finaltype
[1] = R_HPPA_PUSH_ABS_CALL
;
1114 finaltype
[2] = R_HPPA_SUB
;
1119 finaltype
[3] = R_HPPA_EXPR_F
;
1122 finaltype
[3] = R_HPPA_EXPR_L
;
1125 finaltype
[3] = R_HPPA_EXPR_R
;
1128 finaltype
[3] = R_HPPA_EXPR_LS
;
1131 finaltype
[3] = R_HPPA_EXPR_RS
;
1134 finaltype
[3] = R_HPPA_EXPR_LD
;
1137 finaltype
[3] = R_HPPA_EXPR_RD
;
1140 finaltype
[3] = R_HPPA_EXPR_LR
;
1143 finaltype
[3] = R_HPPA_EXPR_RR
;
1150 finaltype
[4] = R_HPPA_EXPR_11
;
1153 finaltype
[4] = R_HPPA_EXPR_12
;
1156 finaltype
[4] = R_HPPA_EXPR_14
;
1159 finaltype
[4] = R_HPPA_EXPR_17
;
1162 finaltype
[4] = R_HPPA_EXPR_21
;
1165 finaltype
[4] = R_HPPA_EXPR_32
;
1172 final_type
= base_type
;
1182 /* this function is in charge of performing all the HP PA relocations */
1183 static long global_value
;
1184 static long GOT_value
; /* XXX: need to calculate this! For HPUX, GOT == DP */
1185 static asymbol
*global_symbol
;
1186 static int global_sym_defined
;
1188 static bfd_reloc_status_type
1189 hppa_elf_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
1192 arelent
*reloc_entry
;
1195 asection
*input_section
;
1197 char **error_message
;
1201 unsigned long addr
= reloc_entry
->address
;
1202 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) (data
);
1203 unsigned short r_type
= reloc_entry
->howto
->type
& 0xFF;
1204 unsigned short r_field
= e_fsel
;
1205 boolean r_pcrel
= reloc_entry
->howto
->pc_relative
;
1206 unsigned r_format
= reloc_entry
->howto
->bitsize
;
1207 long r_addend
= reloc_entry
->addend
;
1211 /* Partial linking - do nothing */
1212 reloc_entry
->address
+= input_section
->output_offset
;
1213 return bfd_reloc_ok
;
1216 /* If performing final link and the symbol we're relocating against
1217 is undefined, then return an error. */
1218 if (symbol_in
&& symbol_in
->section
== &bfd_und_section
)
1219 return bfd_reloc_undefined
;
1221 sym_value
= get_symbol_value (symbol_in
);
1223 /* Compute the value of $global$. */
1224 if (!global_sym_defined
)
1228 global_value
= (global_symbol
->value
1229 + global_symbol
->section
->output_section
->vma
1230 + global_symbol
->section
->output_offset
);
1231 GOT_value
= global_value
;
1232 global_sym_defined
++;
1236 /* Get the instruction word. */
1237 insn
= bfd_get_32 (abfd
, hit_data
);
1239 /* Relocate the value based on one of the basic relocation types
1241 basic_type_1: relocation is relative to $global$
1242 basic_type_2: relocation is relative to the current GOT
1243 basic_type_3: relocation is an absolute call
1244 basic_type_4: relocation is an PC-relative call
1245 basic_type_5: relocation is plabel reference
1246 basic_type_6: relocation is an unwind table relocation
1247 extended_type: unimplemented */
1254 /* Handle all the basic type 1 relocations. */
1257 goto do_basic_type_1
;
1260 goto do_basic_type_1
;
1263 goto do_basic_type_1
;
1266 goto do_basic_type_1
;
1269 goto do_basic_type_1
;
1272 goto do_basic_type_1
;
1275 goto do_basic_type_1
;
1278 goto do_basic_type_1
;
1281 goto do_basic_type_1
;
1284 goto do_basic_type_1
;
1287 goto do_basic_type_1
;
1290 goto do_basic_type_1
;
1293 goto do_basic_type_1
;
1296 goto do_basic_type_1
;
1299 goto do_basic_type_1
;
1302 goto do_basic_type_1
;
1305 goto do_basic_type_1
;
1308 goto do_basic_type_1
;
1313 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1314 symbol_in
, sym_value
, r_addend
,
1315 r_type
, r_format
, r_field
, r_pcrel
);
1318 /* Handle all the basic type 2 relocations. */
1319 case R_HPPA_GOTOFF_11
:
1321 goto do_basic_type_2
;
1322 case R_HPPA_GOTOFF_14
:
1324 goto do_basic_type_2
;
1325 case R_HPPA_GOTOFF_L21
:
1327 goto do_basic_type_2
;
1328 case R_HPPA_GOTOFF_R11
:
1330 goto do_basic_type_2
;
1331 case R_HPPA_GOTOFF_R14
:
1333 goto do_basic_type_2
;
1334 case R_HPPA_GOTOFF_LS21
:
1336 goto do_basic_type_2
;
1337 case R_HPPA_GOTOFF_RS11
:
1339 goto do_basic_type_2
;
1340 case R_HPPA_GOTOFF_RS14
:
1342 goto do_basic_type_2
;
1343 case R_HPPA_GOTOFF_LD21
:
1345 goto do_basic_type_2
;
1346 case R_HPPA_GOTOFF_RD11
:
1348 goto do_basic_type_2
;
1349 case R_HPPA_GOTOFF_RD14
:
1351 goto do_basic_type_2
;
1352 case R_HPPA_GOTOFF_LR21
:
1354 goto do_basic_type_2
;
1355 case R_HPPA_GOTOFF_RR14
:
1359 sym_value
-= GOT_value
;
1360 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1361 symbol_in
, sym_value
, r_addend
,
1362 r_type
, r_format
, r_field
, r_pcrel
);
1365 /* Handle all the basic type 3 relocations. */
1366 case R_HPPA_ABS_CALL_11
:
1368 goto do_basic_type_3
;
1369 case R_HPPA_ABS_CALL_14
:
1371 goto do_basic_type_3
;
1372 case R_HPPA_ABS_CALL_17
:
1374 goto do_basic_type_3
;
1375 case R_HPPA_ABS_CALL_L21
:
1377 goto do_basic_type_3
;
1378 case R_HPPA_ABS_CALL_R11
:
1380 goto do_basic_type_3
;
1381 case R_HPPA_ABS_CALL_R14
:
1383 goto do_basic_type_3
;
1384 case R_HPPA_ABS_CALL_R17
:
1386 goto do_basic_type_3
;
1387 case R_HPPA_ABS_CALL_LS21
:
1389 goto do_basic_type_3
;
1390 case R_HPPA_ABS_CALL_RS11
:
1392 goto do_basic_type_3
;
1393 case R_HPPA_ABS_CALL_RS14
:
1395 goto do_basic_type_3
;
1396 case R_HPPA_ABS_CALL_RS17
:
1398 goto do_basic_type_3
;
1399 case R_HPPA_ABS_CALL_LD21
:
1401 goto do_basic_type_3
;
1402 case R_HPPA_ABS_CALL_RD11
:
1404 goto do_basic_type_3
;
1405 case R_HPPA_ABS_CALL_RD14
:
1407 goto do_basic_type_3
;
1408 case R_HPPA_ABS_CALL_RD17
:
1410 goto do_basic_type_3
;
1411 case R_HPPA_ABS_CALL_LR21
:
1413 goto do_basic_type_3
;
1414 case R_HPPA_ABS_CALL_RR14
:
1416 goto do_basic_type_3
;
1417 case R_HPPA_ABS_CALL_RR17
:
1421 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1422 symbol_in
, sym_value
, r_addend
,
1423 r_type
, r_format
, r_field
, r_pcrel
);
1426 /* Handle all the basic type 4 relocations. */
1427 case R_HPPA_PCREL_CALL_11
:
1429 goto do_basic_type_4
;
1430 case R_HPPA_PCREL_CALL_14
:
1432 goto do_basic_type_4
;
1433 case R_HPPA_PCREL_CALL_17
:
1435 goto do_basic_type_4
;
1436 case R_HPPA_PCREL_CALL_L21
:
1438 goto do_basic_type_4
;
1439 case R_HPPA_PCREL_CALL_R11
:
1441 goto do_basic_type_4
;
1442 case R_HPPA_PCREL_CALL_R14
:
1444 goto do_basic_type_4
;
1445 case R_HPPA_PCREL_CALL_R17
:
1447 goto do_basic_type_4
;
1448 case R_HPPA_PCREL_CALL_LS21
:
1450 goto do_basic_type_4
;
1451 case R_HPPA_PCREL_CALL_RS11
:
1453 goto do_basic_type_4
;
1454 case R_HPPA_PCREL_CALL_RS14
:
1456 goto do_basic_type_4
;
1457 case R_HPPA_PCREL_CALL_RS17
:
1459 goto do_basic_type_4
;
1460 case R_HPPA_PCREL_CALL_LD21
:
1462 goto do_basic_type_4
;
1463 case R_HPPA_PCREL_CALL_RD11
:
1465 goto do_basic_type_4
;
1466 case R_HPPA_PCREL_CALL_RD14
:
1468 goto do_basic_type_4
;
1469 case R_HPPA_PCREL_CALL_RD17
:
1471 goto do_basic_type_4
;
1472 case R_HPPA_PCREL_CALL_LR21
:
1474 goto do_basic_type_4
;
1475 case R_HPPA_PCREL_CALL_RR14
:
1477 goto do_basic_type_4
;
1478 case R_HPPA_PCREL_CALL_RR17
:
1482 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1483 symbol_in
, sym_value
, r_addend
,
1484 r_type
, r_format
, r_field
, r_pcrel
);
1487 /* Handle all the basic type 5 relocations. */
1488 case R_HPPA_PLABEL_32
:
1489 case R_HPPA_PLABEL_11
:
1490 case R_HPPA_PLABEL_14
:
1492 goto do_basic_type_5
;
1493 case R_HPPA_PLABEL_L21
:
1495 goto do_basic_type_5
;
1496 case R_HPPA_PLABEL_R11
:
1497 case R_HPPA_PLABEL_R14
:
1500 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1501 symbol_in
, sym_value
, r_addend
,
1502 r_type
, r_format
, r_field
, r_pcrel
);
1505 /* Handle all basic type 6 relocations. */
1506 case R_HPPA_UNWIND_ENTRY
:
1507 case R_HPPA_UNWIND_ENTRIES
:
1508 hppa_elf_relocate_unwind_table (abfd
, input_section
, data
, addr
,
1509 symbol_in
, sym_value
, r_addend
,
1510 r_type
, r_format
, r_field
, r_pcrel
);
1511 return bfd_reloc_ok
;
1513 /* Handle the stack operations and similar braindamage. */
1514 case R_HPPA_PUSH_CONST
:
1515 case R_HPPA_PUSH_PC
:
1516 case R_HPPA_PUSH_SYM
:
1517 case R_HPPA_PUSH_GOTOFF
:
1518 case R_HPPA_PUSH_ABS_CALL
:
1519 case R_HPPA_PUSH_PCREL_CALL
:
1520 case R_HPPA_PUSH_PLABEL
:
1533 case R_HPPA_ARITH_RSHIFT
:
1534 case R_HPPA_LOGIC_RSHIFT
:
1538 case R_HPPA_EXPR_LS
:
1539 case R_HPPA_EXPR_RS
:
1540 case R_HPPA_EXPR_LD
:
1541 case R_HPPA_EXPR_RD
:
1542 case R_HPPA_EXPR_LR
:
1543 case R_HPPA_EXPR_RR
:
1544 case R_HPPA_EXPR_32
:
1545 case R_HPPA_EXPR_21
:
1546 case R_HPPA_EXPR_11
:
1547 case R_HPPA_EXPR_14
:
1548 case R_HPPA_EXPR_17
:
1549 case R_HPPA_EXPR_12
:
1550 fprintf (stderr
, "Relocation problem: ");
1551 fprintf (stderr
, "Unimplemented reloc type %d, in module %s\n",
1552 r_type
, abfd
->filename
);
1553 return bfd_reloc_notsupported
;
1555 /* This is a linker internal relocation. */
1556 case R_HPPA_STUB_CALL_17
:
1557 /* This relocation is for a branch to a long branch stub.
1558 Change instruction to a BLE,N. It may also be necessary
1559 to change interchange the branch and its delay slot.
1560 The original instruction stream is
1562 bl <foo>,r ; call foo using register r as
1563 ; the return pointer
1564 XXX ; delay slot instruction
1566 The new instruction stream will be:
1568 XXX ; delay slot instruction
1569 ble <foo_stub> ; call the long call stub for foo
1570 ; using r31 as the return pointer
1572 This braindamage is necessary because the compiler may put
1573 an instruction which uses %r31 in the delay slot of the original
1574 call. By changing the call instruction from a "bl" to a "ble"
1575 %r31 gets clobbered before the delay slot executes.
1577 We do not interchange the branch and delay slot if the delay
1578 slot was already nullified, or if the instruction in the delay
1579 slot modifies the return pointer to avoid an unconditional
1580 jump after the call returns (GCC optimization). */
1584 insn
= BLE_N_XXX_0_0
;
1585 bfd_put_32 (abfd
, insn
, hit_data
);
1586 r_type
= R_HPPA_ABS_CALL_17
;
1588 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1589 addr
, symbol_in
, sym_value
,
1590 r_addend
, r_type
, r_format
,
1595 unsigned long old_delay_slot_insn
= bfd_get_32 (abfd
, hit_data
+ 4);
1596 unsigned rtn_reg
= (insn
& 0x03e00000) >> 21;
1598 if (get_opcode (old_delay_slot_insn
) == LDO
)
1600 unsigned ldo_src_reg
= (old_delay_slot_insn
& 0x03e00000) >> 21;
1601 unsigned ldo_target_reg
= (old_delay_slot_insn
& 0x001f0000) >> 16;
1603 /* If the target of the LDO is the same as the return
1604 register then there is no reordering. We can leave the
1605 instuction as a non-nullified BLE in this case. */
1606 if (ldo_target_reg
== rtn_reg
)
1608 unsigned long new_delay_slot_insn
= old_delay_slot_insn
;
1610 BFD_ASSERT(ldo_src_reg
== ldo_target_reg
);
1611 new_delay_slot_insn
&= 0xfc00ffff;
1612 new_delay_slot_insn
|= ((31 << 21) | (31 << 16));
1613 bfd_put_32 (abfd
, new_delay_slot_insn
, hit_data
+ 4);
1615 r_type
= R_HPPA_ABS_CALL_17
;
1617 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1618 addr
, symbol_in
, sym_value
,
1619 r_addend
, r_type
, r_format
,
1621 bfd_put_32 (abfd
, insn
, hit_data
);
1622 return bfd_reloc_ok
;
1624 else if (rtn_reg
== 31)
1626 /* The return register is r31, so this is a millicode
1627 call. Do not perform any instruction reordering. */
1629 r_type
= R_HPPA_ABS_CALL_17
;
1631 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1632 addr
, symbol_in
, sym_value
,
1633 r_addend
, r_type
, r_format
,
1635 bfd_put_32 (abfd
, insn
, hit_data
);
1636 return bfd_reloc_ok
;
1640 /* Check to see if the delay slot instruction has a
1641 relocation. If so, we need to change the address
1642 field of it, because the instruction it relocates
1643 is going to be moved. */
1644 arelent
* next_reloc_entry
= reloc_entry
+1;
1646 if (next_reloc_entry
->address
== reloc_entry
->address
+ 4)
1647 next_reloc_entry
->address
-= 4;
1649 insn
= old_delay_slot_insn
;
1650 bfd_put_32 (abfd
, insn
, hit_data
);
1651 insn
= BLE_N_XXX_0_0
;
1652 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1653 r_type
= R_HPPA_ABS_CALL_17
;
1655 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1656 addr
+ 4, symbol_in
,
1657 sym_value
, r_addend
, r_type
,
1658 r_format
, r_field
, r_pcrel
);
1659 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1660 return bfd_reloc_ok
;
1663 else if (rtn_reg
== 31)
1665 /* The return register is r31, so this is a millicode call.
1666 Perform no instruction reordering in this case. */
1668 r_type
= R_HPPA_ABS_CALL_17
;
1670 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1671 addr
, symbol_in
, sym_value
,
1672 r_addend
, r_type
, r_format
,
1674 bfd_put_32 (abfd
, insn
, hit_data
);
1675 return bfd_reloc_ok
;
1679 /* Check to see if the delay slot instruction has a
1680 relocation. If so, we need to change its address
1681 field because the instruction it relocates is going
1683 arelent
* next_reloc_entry
= reloc_entry
+1;
1685 if (next_reloc_entry
->address
== reloc_entry
->address
+ 4)
1686 next_reloc_entry
->address
-= 4;
1688 insn
= old_delay_slot_insn
;
1689 bfd_put_32 (abfd
, insn
, hit_data
);
1690 insn
= BLE_N_XXX_0_0
;
1691 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1692 r_type
= R_HPPA_ABS_CALL_17
;
1694 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1695 addr
+ 4, symbol_in
, sym_value
,
1696 r_addend
, r_type
, r_format
,
1698 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1699 return bfd_reloc_ok
;
1705 *error_message
= (char *) "Unrecognized reloc";
1706 return bfd_reloc_dangerous
;
1709 /* Update the instruction word. */
1710 bfd_put_32 (abfd
, insn
, hit_data
);
1711 return (bfd_reloc_ok
);
1714 static const reloc_howto_type
*
1715 elf_hppa_reloc_type_lookup (arch
, code
)
1716 bfd_arch_info_type
*arch
;
1717 bfd_reloc_code_real_type code
;
1719 if ((int) code
< (int) R_HPPA_UNIMPLEMENTED
)
1721 BFD_ASSERT ((int) elf_hppa_howto_table
[(int) code
].type
== (int) code
);
1722 return &elf_hppa_howto_table
[(int) code
];
1725 return (reloc_howto_type
*) 0;
1728 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
1732 DEFUN (elf_hppa_tc_symbol
, (abfd
, symbolP
, sym_idx
),
1734 elf_symbol_type
* symbolP AND
1737 symext_chainS
*symextP
;
1738 unsigned int arg_reloc
;
1740 /* Only functions can have argument relocations. */
1741 if (!(symbolP
->symbol
.flags
& BSF_FUNCTION
))
1744 arg_reloc
= symbolP
->tc_data
.hppa_arg_reloc
;
1746 /* If there are no argument relocation bits, then no relocation is
1747 necessary. Do not add this to the symextn section. */
1751 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
1753 symextP
[0].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, sym_idx
);
1754 symextP
[0].next
= &symextP
[1];
1756 symextP
[1].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC
, arg_reloc
);
1757 symextP
[1].next
= NULL
;
1759 if (symext_rootP
== NULL
)
1761 symext_rootP
= &symextP
[0];
1762 symext_lastP
= &symextP
[1];
1766 symext_lastP
->next
= &symextP
[0];
1767 symext_lastP
= &symextP
[1];
1771 /* Accessor function for the list of symbol extension records. */
1772 symext_chainS
*elf32_hppa_get_symextn_chain()
1774 return symext_rootP
;
1777 static symext_entryS
*symextn_contents
;
1778 static unsigned int symextn_contents_real_size
;
1781 DEFUN (elf_hppa_tc_make_sections
, (abfd
, ignored
),
1785 symext_chainS
*symextP
;
1789 void hppa_elf_stub_finish (); /* forward declaration */
1790 asection
*symextn_sec
;
1792 hppa_elf_stub_finish (abfd
);
1794 if (symext_rootP
== NULL
)
1797 for (n
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++n
)
1800 size
= sizeof (symext_entryS
) * n
;
1801 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1802 if (symextn_sec
== (asection
*) 0)
1804 symextn_sec
= bfd_make_section (abfd
, SYMEXTN_SECTION_NAME
);
1805 bfd_set_section_flags (abfd
,
1807 SEC_HAS_CONTENTS
| SEC_LOAD
| SEC_ALLOC
| SEC_CODE
| SEC_READONLY
);
1808 symextn_sec
->output_section
= symextn_sec
;
1809 symextn_sec
->output_offset
= 0;
1810 bfd_set_section_alignment (abfd
, symextn_sec
, 2);
1812 symextn_contents
= (symext_entryS
*) bfd_alloc (abfd
, size
);
1814 for (i
= 0, symextP
= symext_rootP
; symextP
; symextP
= symextP
->next
, ++i
)
1815 symextn_contents
[i
] = symextP
->entry
;
1816 symextn_contents_real_size
= size
;
1817 bfd_set_section_size (abfd
, symextn_sec
, symextn_contents_real_size
);
1822 /* Support for HP PA-RISC stub generation.
1826 Center for Software Science
1827 Department of Computer Science
1833 HP-PA calling conventions state:
1835 1. an argument relocation stub is required whenever the callee and
1836 caller argument relocation bits do not match exactly. The exception
1837 to this rule is if either the caller or callee argument relocation
1838 bit are 00 (do not relocate).
1840 2. The linker can optionally add a symbol record for the stub so that
1841 the stub can be reused. The symbol record will be the same as the
1842 original export symbol record, except that the relocation bits will
1843 reflect the input of the stub, the type would be STUB and the symbol
1844 value will be the location of the relocation stub.
1848 Stubs can be inserted *before* the section of the caller. The stubs
1849 can be treated as calls to code that manipulates the arguments.
1856 HPPA_STUB_ARG_RELOC
,
1857 HPPA_STUB_LONG_BRANCH
1861 elf32_hppa_get_sym_extn (abfd
, sym
, type
)
1866 /* This function finds the symbol extension record of the */
1867 /* specified type for the specified symbol. It returns the */
1868 /* value of the symbol extension record. */
1869 symext_entryS retval
;
1874 retval
= (symext_entryS
) 0;
1876 case HPPA_SXT_SYMNDX
:
1877 retval
= (symext_entryS
) 0; /* XXX: need to fix this */
1879 case HPPA_SXT_ARG_RELOC
:
1881 elf_symbol_type
*esymP
= (elf_symbol_type
*) sym
;
1883 retval
= (symext_entryS
) esymP
->tc_data
.hppa_arg_reloc
;
1886 /* This should never happen. */
1893 typedef struct elf32_hppa_stub_name_list_struct
1895 /* name of this stub */
1897 /* stub description for this stub */
1898 struct elf32_hppa_stub_description_struct
*stub_desc
;
1899 /* pointer into stub contents */
1901 /* size of this stub */
1903 /* next stub name entry */
1904 struct elf32_hppa_stub_name_list_struct
*next
;
1905 } elf32_hppa_stub_name_list
;
1907 typedef struct elf32_hppa_stub_description_struct
1909 struct elf32_hppa_stub_description_struct
*next
;
1910 bfd
*this_bfd
; /* bfd to which this stub applies */
1911 asection
*stub_sec
; /* stub section for this bfd */
1912 unsigned relocs_allocated_cnt
; /* count of relocations for this stub section */
1914 unsigned allocated_size
;
1915 int *stub_secp
; /* pointer to the next available location in the buffer */
1916 char *stub_contents
; /* contents of the stubs for this bfd */
1917 elf32_hppa_stub_name_list
*stub_listP
;
1918 struct bfd_link_info
*link_info
;
1920 elf32_hppa_stub_description
;
1922 static elf32_hppa_stub_description
*elf_hppa_stub_rootP
;
1924 /* Locate the stub section information for the given bfd. */
1925 static elf32_hppa_stub_description
*
1926 find_stubs (abfd
, stub_sec
)
1930 elf32_hppa_stub_description
*stubP
;
1932 for (stubP
= elf_hppa_stub_rootP
; stubP
; stubP
= stubP
->next
)
1934 if (stubP
->this_bfd
== abfd
1935 && stubP
->stub_sec
== stub_sec
)
1939 return (elf32_hppa_stub_description
*) NULL
;
1942 static elf32_hppa_stub_description
*
1943 new_stub (abfd
, stub_sec
, link_info
)
1946 struct bfd_link_info
*link_info
;
1948 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1953 stub
= (elf32_hppa_stub_description
*) bfd_zalloc (abfd
, sizeof (elf32_hppa_stub_description
));
1956 stub
->this_bfd
= abfd
;
1957 stub
->stub_sec
= stub_sec
;
1958 stub
->real_size
= 0;
1959 stub
->allocated_size
= 0;
1960 stub
->stub_contents
= NULL
;
1961 stub
->stub_secp
= NULL
;
1962 stub
->link_info
= link_info
;
1964 stub
->next
= elf_hppa_stub_rootP
;
1965 elf_hppa_stub_rootP
= stub
;
1969 bfd_error
= no_memory
;
1970 bfd_perror ("new_stub");
1976 /* Locate the stub by the given name. */
1977 static elf32_hppa_stub_name_list
*
1978 find_stub_by_name (abfd
, stub_sec
, name
)
1983 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1987 elf32_hppa_stub_name_list
*name_listP
;
1989 for (name_listP
= stub
->stub_listP
; name_listP
; name_listP
= name_listP
->next
)
1991 if (!strcmp (name_listP
->sym
->name
, name
))
1999 /* Locate the stub by the given name. */
2000 static elf32_hppa_stub_name_list
*
2001 add_stub_by_name(abfd
, stub_sec
, sym
, link_info
)
2005 struct bfd_link_info
*link_info
;
2007 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
2008 elf32_hppa_stub_name_list
*stub_entry
;
2011 stub
= new_stub(abfd
, stub_sec
, link_info
);
2015 stub_entry
= (elf32_hppa_stub_name_list
*)
2016 bfd_zalloc (abfd
, sizeof (elf32_hppa_stub_name_list
));
2020 stub_entry
->size
= 0;
2021 stub_entry
->sym
= sym
;
2022 stub_entry
->stub_desc
= stub
;
2023 /* First byte of this stub is the pointer to
2024 the next available location in the stub buffer. */
2025 stub_entry
->stub_secp
= stub
->stub_secp
;
2026 if (stub
->stub_listP
)
2027 stub_entry
->next
= stub
->stub_listP
;
2029 stub_entry
->next
= NULL
;
2030 stub
->stub_listP
= stub_entry
;
2035 bfd_error
= no_memory
;
2036 bfd_perror("add_stub_by_name");
2040 return (elf32_hppa_stub_name_list
*)NULL
;
2044 #define RETURN_VALUE 1
2046 #define NO_ARG_RELOC 0
2053 #define ARG_RELOC_ERR 7
2065 /* FP register in arg0/arg1. This value can only appear in the arg0 location. */
2067 /* FP register in arg2/arg3. This value can only appear in the arg2 location. */
2070 #define AR_WARN(type,loc) \
2071 fprintf(stderr,"WARNING: Illegal argument relocation: %s for %s\n", \
2072 reloc_type_strings[type],reloc_loc_strings[loc])
2074 static CONST
char *CONST reloc_type_strings
[] =
2076 "NONE", "GR->FR", "GR0,GR1->FR1", "GR2,GR3->FR3", "FR->GR", "FR->GR0,GR1", "FR->GR2,GR3", "ERROR"
2079 static CONST
char *CONST reloc_loc_strings
[] =
2081 "ARG0", "ARG1", "ARG2", "ARG3", "RETVAL"
2084 static CONST
char mismatches
[6][6] =
2085 { /* CALLEE NONE CALLEE GR CALLEE FR CALLEE FU CALLEE DBL01 CALLEE DBL23 */
2087 {NO_ARG_RELOC
, NO_ARG_RELOC
, NO_ARG_RELOC
, ARG_RELOC_ERR
, NO_ARG_RELOC
, NO_ARG_RELOC
},
2089 {NO_ARG_RELOC
, NO_ARG_RELOC
, R_TO_FR
, ARG_RELOC_ERR
, R01_TO_FR
, ARG_RELOC_ERR
},
2091 {NO_ARG_RELOC
, FR_TO_R
, NO_ARG_RELOC
, ARG_RELOC_ERR
, ARG_RELOC_ERR
},
2093 {ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
},
2095 {NO_ARG_RELOC
, FR_TO_R01
, NO_ARG_RELOC
, ARG_RELOC_ERR
, NO_ARG_RELOC
, ARG_RELOC_ERR
},
2097 {NO_ARG_RELOC
, FR_TO_R23
, NO_ARG_RELOC
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, NO_ARG_RELOC
},
2100 static CONST
char retval_mismatches
[6][6] =
2101 { /* CALLEE NONE CALLEE GR CALLEE FR CALLEE FU CALLEE DBL01 CALLEE DBL23 */
2103 {NO_ARG_RELOC
, NO_ARG_RELOC
, NO_ARG_RELOC
, ARG_RELOC_ERR
, NO_ARG_RELOC
, NO_ARG_RELOC
},
2105 {NO_ARG_RELOC
, NO_ARG_RELOC
, FR_TO_R
, ARG_RELOC_ERR
, FR_TO_R01
, ARG_RELOC_ERR
},
2107 {NO_ARG_RELOC
, R_TO_FR
, NO_ARG_RELOC
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
},
2109 {ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
},
2111 {NO_ARG_RELOC
, R01_TO_FR
, NO_ARG_RELOC
, ARG_RELOC_ERR
, NO_ARG_RELOC
, ARG_RELOC_ERR
},
2113 {NO_ARG_RELOC
, R23_TO_FR
, NO_ARG_RELOC
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, NO_ARG_RELOC
},
2117 type_of_mismatch (caller_bits
, callee_bits
, type
)
2125 return mismatches
[caller_bits
][callee_bits
];
2127 return retval_mismatches
[caller_bits
][callee_bits
];
2133 #define EXTRACT_ARBITS(ar,which) ((ar) >> (8-(which*2))) & 3
2135 #define NEW_INSTRUCTION(entry,insn) \
2137 *((entry)->stub_desc->stub_secp)++ = (insn); \
2138 (entry)->stub_desc->real_size += sizeof(int); \
2139 (entry)->size += sizeof(int); \
2140 bfd_set_section_size((entry)->stub_desc->this_bfd, \
2141 (entry)->stub_desc->stub_sec, \
2142 (entry)->stub_desc->real_size); \
2145 #define CURRENT_STUB_OFFSET(entry) \
2146 ((int)(entry)->stub_desc->stub_secp \
2147 - (int)(entry)->stub_desc->stub_contents - 4)
2149 static boolean stubs_finished
= false;
2152 hppa_elf_stub_finish (output_bfd
)
2155 elf32_hppa_stub_description
*stub_list
= elf_hppa_stub_rootP
;
2156 /* All the stubs have been built. Finish up building */
2157 /* stub section. Apply relocations to the section. */
2159 if ( stubs_finished
)
2162 for (; stub_list
; stub_list
= stub_list
->next
)
2164 if (stub_list
->real_size
)
2166 bfd
*stub_bfd
= stub_list
->this_bfd
;
2167 asection
*stub_sec
= bfd_get_section_by_name (stub_bfd
, ".hppa_linker_stubs");
2168 bfd_size_type reloc_size
;
2169 arelent
**reloc_vector
;
2171 BFD_ASSERT (stub_sec
== stub_list
->stub_sec
);
2172 reloc_size
= bfd_get_reloc_upper_bound (stub_bfd
, stub_sec
);
2173 reloc_vector
= (arelent
**) alloca (reloc_size
);
2175 BFD_ASSERT (stub_sec
);
2177 /* We are not relaxing the section, so just copy the size info */
2178 stub_sec
->_cooked_size
= stub_sec
->_raw_size
;
2179 stub_sec
->reloc_done
= true;
2182 if (bfd_canonicalize_reloc (stub_bfd
,
2185 output_bfd
->outsymbols
))
2188 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
2191 char *err
= (char *) NULL
;
2192 bfd_reloc_status_type r
=
2193 bfd_perform_relocation (stub_bfd
,
2195 stub_list
->stub_contents
,
2196 stub_sec
, (bfd
*) NULL
, &err
);
2199 if (r
!= bfd_reloc_ok
)
2201 struct bfd_link_info
*link_info
= stub_list
->link_info
;
2205 case bfd_reloc_undefined
:
2206 if (! ((*link_info
->callbacks
->undefined_symbol
)
2208 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
2209 stub_bfd
, stub_sec
, (*parent
)->address
)))
2212 case bfd_reloc_dangerous
:
2213 if (! ((*link_info
->callbacks
->reloc_dangerous
)
2214 (link_info
, err
, stub_bfd
, stub_sec
,
2215 (*parent
)->address
)))
2218 case bfd_reloc_overflow
:
2220 if (! ((*link_info
->callbacks
->reloc_overflow
)
2222 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
2223 (*parent
)->howto
->name
,
2226 (*parent
)->address
)))
2230 case bfd_reloc_outofrange
:
2239 bfd_set_section_contents (output_bfd
,
2241 stub_list
->stub_contents
,
2243 stub_list
->real_size
);
2245 free (reloc_vector
);
2248 stubs_finished
= true;
2252 hppa_elf_stub_branch_reloc (stub_desc
, /* the bfd */
2253 output_bfd
, /* the output bfd */
2254 target_sym
, /* the target symbol */
2255 offset
) /* the offset within the stub buffer (pre-calculated) */
2256 elf32_hppa_stub_description
*stub_desc
;
2258 asymbol
*target_sym
;
2261 /* Allocate a new relocation entry. */
2265 if (stub_desc
->relocs_allocated_cnt
== stub_desc
->stub_sec
->reloc_count
)
2267 if (stub_desc
->stub_sec
->relocation
== NULL
)
2269 stub_desc
->relocs_allocated_cnt
= STUB_RELOC_INCR
;
2270 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
2271 stub_desc
->stub_sec
->relocation
= (arelent
*) zalloc (size
);
2275 stub_desc
->relocs_allocated_cnt
+= STUB_RELOC_INCR
;
2276 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
2277 stub_desc
->stub_sec
->relocation
= (arelent
*) realloc (stub_desc
->stub_sec
->relocation
,
2282 /* Fill in the details. */
2283 relent
.address
= offset
;
2285 relent
.sym_ptr_ptr
= (asymbol
**) bfd_zalloc (stub_desc
->this_bfd
, sizeof (asymbol
*));
2286 BFD_ASSERT (relent
.sym_ptr_ptr
);
2288 relent
.sym_ptr_ptr
[0] = target_sym
;
2289 relent
.howto
= bfd_reloc_type_lookup (stub_desc
->this_bfd
, R_HPPA_PCREL_CALL_17
);
2291 /* Save it in the array of relocations for the stub section. */
2293 memcpy (&stub_desc
->stub_sec
->relocation
[stub_desc
->stub_sec
->reloc_count
++],
2299 hppa_elf_stub_reloc (stub_desc
, /* the bfd */
2300 output_bfd
, /* the output bfd */
2301 target_sym
, /* the target symbol */
2302 offset
, /* the offset within the stub buffer (pre-calculated) */
2304 elf32_hppa_stub_description
*stub_desc
;
2306 asymbol
*target_sym
;
2308 elf32_hppa_reloc_type type
;
2310 /* Allocate a new relocation entry. */
2313 Elf_Internal_Shdr
*rela_hdr
;
2315 if (stub_desc
->relocs_allocated_cnt
== stub_desc
->stub_sec
->reloc_count
)
2317 if (stub_desc
->stub_sec
->relocation
== NULL
)
2319 stub_desc
->relocs_allocated_cnt
= STUB_RELOC_INCR
;
2320 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
2321 stub_desc
->stub_sec
->relocation
= (arelent
*) zalloc (size
);
2325 stub_desc
->relocs_allocated_cnt
+= STUB_RELOC_INCR
;
2326 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
2327 stub_desc
->stub_sec
->relocation
= (arelent
*) realloc (stub_desc
->stub_sec
->relocation
,
2332 rela_hdr
= &elf_section_data(stub_desc
->stub_sec
)->rel_hdr
;
2333 rela_hdr
->sh_size
+= sizeof(Elf32_External_Rela
);
2335 /* Fill in the details. */
2336 relent
.address
= offset
;
2338 relent
.sym_ptr_ptr
= (asymbol
**) bfd_zalloc (stub_desc
->this_bfd
, sizeof (asymbol
*));
2339 BFD_ASSERT (relent
.sym_ptr_ptr
);
2341 relent
.sym_ptr_ptr
[0] = target_sym
;
2342 relent
.howto
= bfd_reloc_type_lookup (stub_desc
->this_bfd
, type
);
2344 /* Save it in the array of relocations for the stub section. */
2346 memcpy (&stub_desc
->stub_sec
->relocation
[stub_desc
->stub_sec
->reloc_count
++],
2352 hppa_elf_build_arg_reloc_stub (abfd
, output_bfd
, link_info
, reloc_entry
,
2353 stub_types
, rtn_adjust
, data
)
2356 struct bfd_link_info
*link_info
;
2357 arelent
*reloc_entry
;
2362 asection
*stub_sec
= bfd_get_section_by_name (abfd
, ".hppa_linker_stubs");
2363 elf32_hppa_stub_description
*stub_desc
= find_stubs (abfd
, stub_sec
);
2364 asymbol
*stub_sym
= NULL
;
2365 asymbol
*target_sym
= reloc_entry
->sym_ptr_ptr
[0];
2366 asection
*output_text_section
= bfd_get_section_by_name (output_bfd
, ".text");
2368 char stub_sym_name
[128];
2369 elf32_hppa_stub_name_list
*stub_entry
;
2370 unsigned insn
= data
[0];
2372 /* Perform some additional checks on whether we should really do the
2373 return adjustment. For example, if the instruction is nullified
2374 or if the delay slot contains an instruction that modifies the return
2375 pointer, then the branch instructions should not be rearranged
2376 (rtn_adjust is false). */
2377 if (insn
& 2 || insn
== 0)
2381 unsigned delay_insn
= data
[1];
2383 if (get_opcode (delay_insn
) == LDO
2384 && (((insn
& 0x03e00000) >> 21) == ((delay_insn
& 0x001f0000) >> 16)))
2388 /* See if the proper stub entry has already been made. */
2391 BFD_ASSERT (stub_desc
== NULL
);
2392 stub_sec
= bfd_make_section (abfd
, ".hppa_linker_stubs");
2393 bfd_set_section_flags (abfd
,
2395 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
2396 | SEC_RELOC
| SEC_CODE
| SEC_READONLY
);
2397 stub_sec
->output_section
= output_text_section
->output_section
;
2398 stub_sec
->output_offset
= 0;
2399 bfd_set_section_alignment (abfd
, stub_sec
, 2);
2400 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
2403 /* Make the stub if we did not find one already. */
2405 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
2407 /* Allocate space to write the stub.
2408 FIXME. Why using realloc?!? */
2409 if (!stub_desc
->stub_contents
)
2411 stub_desc
->allocated_size
= STUB_BUFFER_INCR
;
2412 stub_desc
->stub_contents
= (char *) bfd_xmalloc (STUB_BUFFER_INCR
);
2414 else if ((stub_desc
->allocated_size
- stub_desc
->real_size
) < STUB_MAX_SIZE
)
2416 stub_desc
->allocated_size
= stub_desc
->allocated_size
+ STUB_BUFFER_INCR
;
2417 stub_desc
->stub_contents
= (char *) realloc (stub_desc
->stub_contents
,
2418 stub_desc
->allocated_size
);
2421 stub_desc
->stub_secp
2422 = (int *) (stub_desc
->stub_contents
+ stub_desc
->real_size
);
2424 sprintf (stub_sym_name
,
2425 "_stub_%s_%02d_%02d_%02d_%02d_%02d_%s",
2426 reloc_entry
->sym_ptr_ptr
[0]->name
,
2427 stub_types
[0], stub_types
[1], stub_types
[2],
2428 stub_types
[3], stub_types
[4],
2429 rtn_adjust
? "RA" : "");
2430 stub_entry
= find_stub_by_name (abfd
, stub_sec
, stub_sym_name
);
2434 stub_sym
= stub_entry
->sym
;
2435 /* Redirect the original relocation from the old symbol (a function)
2436 to the stub (the stub calls the function). Should we need to
2437 change the relocation type? */
2438 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (stub_desc
->this_bfd
,
2439 sizeof (asymbol
*));
2440 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
2441 if (reloc_entry
->howto
->type
!= R_HPPA_PLABEL_32
2442 && (get_opcode(insn
) == BLE
2443 || get_opcode (insn
) == BE
2444 || get_opcode (insn
) == BL
))
2445 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_HPPA_STUB_CALL_17
);
2449 /* Create a new symbol to point to this stub. */
2450 stub_sym
= bfd_make_empty_symbol (abfd
);
2451 stub_sym
->name
= bfd_zalloc (abfd
, strlen (stub_sym_name
) + 1);
2452 strcpy ((char *) stub_sym
->name
, stub_sym_name
);
2454 = (int) stub_desc
->stub_secp
- (int) stub_desc
->stub_contents
;
2455 stub_sym
->section
= stub_sec
;
2456 stub_sym
->flags
= BSF_LOCAL
| BSF_FUNCTION
;
2457 stub_entry
= add_stub_by_name (abfd
, stub_sec
, stub_sym
, link_info
);
2459 /* Redirect the original relocation from the old symbol (a function)
2460 to the stub (the stub calls the function). Change the type of
2461 relocation to be the internal use only stub R_HPPA_STUB_CALL_17. */
2462 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (stub_desc
->this_bfd
,
2463 sizeof (asymbol
*));
2464 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
2465 if (reloc_entry
->howto
->type
!= R_HPPA_PLABEL_32
2466 && (get_opcode (insn
) == BLE
2467 || get_opcode (insn
) == BE
2468 || get_opcode (insn
) == BL
))
2469 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_HPPA_STUB_CALL_17
);
2471 /* Generate common code for all stubs. */
2473 NEW_INSTRUCTION (stub_entry
, LDSID_31_1
);
2474 NEW_INSTRUCTION (stub_entry
, MTSP_1_SR0
);
2475 NEW_INSTRUCTION (stub_entry
, ADDI_8_SP
);
2477 /* Generate code to move the arguments around. */
2478 for (i
= ARG0
; i
< ARG3
; i
++)
2480 if (stub_types
[i
] != NO_ARG_RELOC
)
2482 switch (stub_types
[i
])
2488 NEW_INSTRUCTION (stub_entry
, STWS_ARG0_M8SP
);
2489 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG0
);
2492 NEW_INSTRUCTION (stub_entry
, STWS_ARG1_M8SP
);
2493 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG1
);
2496 NEW_INSTRUCTION (stub_entry
, STWS_ARG2_M8SP
);
2497 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG2
);
2500 NEW_INSTRUCTION (stub_entry
, STWS_ARG3_M8SP
);
2501 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG3
);
2510 NEW_INSTRUCTION (stub_entry
, STWS_ARG0_M4SP
);
2511 NEW_INSTRUCTION (stub_entry
, STWS_ARG1_M8SP
);
2512 NEW_INSTRUCTION (stub_entry
, FLDDS_M8SP_FARG1
);
2515 AR_WARN (stub_types
[i
],i
);
2524 NEW_INSTRUCTION (stub_entry
, STWS_ARG2_M4SP
);
2525 NEW_INSTRUCTION (stub_entry
, STWS_ARG3_M8SP
);
2526 NEW_INSTRUCTION (stub_entry
, FLDDS_M8SP_FARG3
);
2529 AR_WARN (stub_types
[i
],i
);
2538 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG0_M8SP
);
2539 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG0
);
2542 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG1_M8SP
);
2543 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG1
);
2546 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG2_M8SP
);
2547 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG2
);
2550 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG3_M8SP
);
2551 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG3
);
2560 NEW_INSTRUCTION (stub_entry
, FSTDS_FARG1_M8SP
);
2561 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG0
);
2562 NEW_INSTRUCTION (stub_entry
, LDWS_M8SP_ARG1
);
2565 AR_WARN (stub_types
[i
],i
);
2574 NEW_INSTRUCTION (stub_entry
, FSTDS_FARG3_M8SP
);
2575 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG2
);
2576 NEW_INSTRUCTION (stub_entry
, LDWS_M8SP_ARG3
);
2579 AR_WARN (stub_types
[i
],i
);
2588 NEW_INSTRUCTION (stub_entry
, ADDI_M8_SP_SP
);
2590 /* Adjust the return address if necessary. */
2593 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_RP
);
2596 NEW_INSTRUCTION (stub_entry
, COPY_31_2
);
2598 /* Save the return address. */
2599 NEW_INSTRUCTION (stub_entry
, STW_RP_M8SP
);
2601 /* Long branch to the target function. */
2602 NEW_INSTRUCTION (stub_entry
, LDIL_XXX_31
);
2603 hppa_elf_stub_reloc (stub_entry
->stub_desc
,
2606 CURRENT_STUB_OFFSET (stub_entry
),
2608 NEW_INSTRUCTION (stub_entry
, BLE_XXX_0_31
);
2609 hppa_elf_stub_reloc (stub_entry
->stub_desc
,
2612 CURRENT_STUB_OFFSET (stub_entry
),
2613 R_HPPA_ABS_CALL_R17
);
2614 NEW_INSTRUCTION (stub_entry
, COPY_31_2
);
2617 /* Restore the return address. */
2618 NEW_INSTRUCTION (stub_entry
, LDW_M8SP_RP
);
2620 /* Generate the code to move the return value around. */
2622 if (stub_types
[i
] != NO_ARG_RELOC
)
2624 switch (stub_types
[i
])
2627 NEW_INSTRUCTION (stub_entry
, STWS_RET0_M8SP
);
2628 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FRET0
);
2632 NEW_INSTRUCTION (stub_entry
, FSTWS_FRET0_M8SP
);
2633 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_RET0
);
2637 NEW_INSTRUCTION (stub_entry
, BV_N_0_RP
);
2644 hppa_elf_arg_reloc_needed_p (abfd
, reloc_entry
, stub_types
, caller_ar
)
2646 arelent
*reloc_entry
;
2648 symext_entryS caller_ar
;
2650 /* If the symbol is still undefined, there is */
2651 /* no way to know if a stub is required. */
2653 if (reloc_entry
->sym_ptr_ptr
[0] && reloc_entry
->sym_ptr_ptr
[0]->section
!= &bfd_und_section
)
2655 symext_entryS callee_ar
= elf32_hppa_get_sym_extn (abfd
,
2656 reloc_entry
->sym_ptr_ptr
[0],
2657 HPPA_SXT_ARG_RELOC
);
2659 /* Now, determine if a stub is */
2660 /* required. A stub is required if they the callee and caller */
2661 /* argument relocation bits are both nonzero and not equal. */
2663 if (caller_ar
&& callee_ar
)
2665 /* Both are non-zero, we need to do further checking. */
2666 /* First, check if there is a return value relocation to be done */
2670 callee_loc
[RETVAL
] = EXTRACT_ARBITS (callee_ar
, RETVAL
);
2671 caller_loc
[RETVAL
] = EXTRACT_ARBITS (caller_ar
, RETVAL
);
2672 callee_loc
[ARG0
] = EXTRACT_ARBITS (callee_ar
, ARG0
);
2673 caller_loc
[ARG0
] = EXTRACT_ARBITS (caller_ar
, ARG0
);
2674 callee_loc
[ARG1
] = EXTRACT_ARBITS (callee_ar
, ARG1
);
2675 caller_loc
[ARG1
] = EXTRACT_ARBITS (caller_ar
, ARG1
);
2676 callee_loc
[ARG2
] = EXTRACT_ARBITS (callee_ar
, ARG2
);
2677 caller_loc
[ARG2
] = EXTRACT_ARBITS (caller_ar
, ARG2
);
2678 callee_loc
[ARG3
] = EXTRACT_ARBITS (callee_ar
, ARG3
);
2679 caller_loc
[ARG3
] = EXTRACT_ARBITS (caller_ar
, ARG3
);
2681 /* Check some special combinations. For */
2682 /* example, if FU appears in ARG1 or ARG3, we */
2683 /* can move it to ARG0 or ARG2, respectively. */
2685 if (caller_loc
[ARG0
] == AR_FU
|| caller_loc
[ARG1
] == AR_FU
)
2687 caller_loc
[ARG0
] = AR_DBL01
;
2688 caller_loc
[ARG1
] = AR_NO
;
2690 if (caller_loc
[ARG2
] == AR_FU
|| caller_loc
[ARG3
] == AR_FU
)
2692 caller_loc
[ARG2
] = AR_DBL23
;
2693 caller_loc
[ARG3
] = AR_NO
;
2695 if (callee_loc
[ARG0
] == AR_FU
|| callee_loc
[ARG1
] == AR_FU
)
2697 callee_loc
[ARG0
] = AR_DBL01
;
2698 callee_loc
[ARG1
] = AR_NO
;
2700 if (callee_loc
[ARG2
] == AR_FU
|| callee_loc
[ARG3
] == AR_FU
)
2702 callee_loc
[ARG2
] = AR_DBL23
;
2703 callee_loc
[ARG3
] = AR_NO
;
2706 stub_types
[ARG0
] = type_of_mismatch (caller_loc
[ARG0
], callee_loc
[ARG0
], ARGUMENTS
);
2707 stub_types
[ARG1
] = type_of_mismatch (caller_loc
[ARG1
], callee_loc
[ARG1
], ARGUMENTS
);
2708 stub_types
[ARG2
] = type_of_mismatch (caller_loc
[ARG2
], callee_loc
[ARG2
], ARGUMENTS
);
2709 stub_types
[ARG3
] = type_of_mismatch (caller_loc
[ARG3
], callee_loc
[ARG3
], ARGUMENTS
);
2710 stub_types
[RETVAL
] = type_of_mismatch (caller_loc
[RETVAL
], callee_loc
[RETVAL
], RETURN_VALUE
);
2712 /* Steps involved in building stubs: */
2713 /* 1. Determine what argument registers need to relocated. This */
2714 /* step is already done here. */
2715 /* 2. Build the appropriate stub in the .hppa_linker_stubs section. */
2716 /* This section should never appear in an object file. It is */
2717 /* only used internally. The output_section of the */
2718 /* .hppa_linker_stubs section is the .text section of the */
2720 /* 3. Build a symbol that is used (internally only) as the entry */
2721 /* point of the stub. */
2722 /* 4. Change the instruction of the original branch into a branch to */
2723 /* the stub routine. */
2724 /* 5. Build a relocation entry for the instruction of the original */
2725 /* branch to be R_HPPA_PCREL_CALL to the stub routine. */
2737 fprintf (stderr
, "Stub needed for %s @ %s+0x%x: callee/caller ar=0x%x/0x%x ",
2738 reloc_entry
->sym_ptr_ptr
[0]->name
,
2739 abfd
->filename
, reloc_entry
->address
,
2740 callee_ar
, caller_ar
);
2741 for (i
= ARG0
; i
< RETVAL
; i
++)
2743 if (stub_types
[i
] != NO_ARG_RELOC
)
2745 fprintf (stderr
, "%s%d: %s ",
2746 i
== RETVAL
? "ret" : "arg",
2747 i
== RETVAL
? 0 : i
,
2748 reloc_type_strings
[stub_types
[i
]]);
2751 fprintf (stderr
, "\n");
2762 hppa_elf_build_long_branch_stub (abfd
, output_bfd
, link_info
, reloc_entry
,
2766 struct bfd_link_info
*link_info
;
2767 arelent
*reloc_entry
;
2771 asection
*stub_sec
= bfd_get_section_by_name (abfd
, ".hppa_linker_stubs");
2772 elf32_hppa_stub_description
*stub_desc
= find_stubs (abfd
, stub_sec
);
2773 asymbol
*stub_sym
= NULL
;
2774 asymbol
*target_sym
= reloc_entry
->sym_ptr_ptr
[0];
2775 asection
*output_text_section
= bfd_get_section_by_name (output_bfd
, ".text");
2776 char stub_sym_name
[128];
2778 int dyncall
= false;
2779 elf32_hppa_stub_name_list
*stub_entry
;
2780 int rtn_adjust
= true;
2784 /* Create the stub section if it does not already exist. */
2787 BFD_ASSERT (stub_desc
== NULL
);
2788 stub_sec
= bfd_make_section (abfd
, ".hppa_linker_stubs");
2789 bfd_set_section_flags (abfd
,
2791 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
2792 | SEC_RELOC
| SEC_CODE
| SEC_READONLY
);
2793 stub_sec
->output_section
= output_text_section
->output_section
;
2794 stub_sec
->output_offset
= 0;
2796 /* Set up the ELF section header for this new section. This
2797 is basically the same processing as elf_make_sections().
2798 elf_make_sections is static and therefore not accessable
2801 Elf_Internal_Shdr
*this_hdr
;
2802 this_hdr
= &elf_section_data (stub_sec
)->this_hdr
;
2804 /* Set the sizes of this section. The contents have already
2806 this_hdr
->sh_addr
= stub_sec
->vma
;
2807 this_hdr
->sh_size
= stub_sec
->_raw_size
;
2809 /* Set appropriate flags for sections with relocations. */
2810 if (stub_sec
->flags
& SEC_RELOC
)
2812 Elf_Internal_Shdr
*rela_hdr
;
2813 int use_rela_p
= get_elf_backend_data (abfd
)->use_rela_p
;
2815 rela_hdr
= &elf_section_data (stub_sec
)->rel_hdr
;
2819 rela_hdr
->sh_type
= SHT_RELA
;
2820 rela_hdr
->sh_entsize
= sizeof (Elf32_External_Rela
);
2824 rela_hdr
->sh_type
= SHT_REL
;
2825 rela_hdr
->sh_entsize
= sizeof (Elf32_External_Rel
);
2827 rela_hdr
->sh_flags
= 0;
2828 rela_hdr
->sh_addr
= 0;
2829 rela_hdr
->sh_offset
= 0;
2830 rela_hdr
->sh_addralign
= 0;
2834 if (stub_sec
->flags
& SEC_ALLOC
)
2836 this_hdr
->sh_flags
|= SHF_ALLOC
;
2837 /* FIXME. If SEC_LOAD is true should we do something with
2841 if (!(stub_sec
->flags
& SEC_READONLY
))
2842 this_hdr
->sh_flags
|= SHF_WRITE
;
2844 if (stub_sec
->flags
& SEC_CODE
)
2845 this_hdr
->sh_flags
|= SHF_EXECINSTR
;
2848 bfd_set_section_alignment (abfd
, stub_sec
, 2);
2849 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
2853 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
2855 /* Allocate memory to contain the stub. FIXME. Why isn't this using
2856 the BFD memory allocation routines? */
2857 if (!stub_desc
->stub_contents
)
2859 stub_desc
->allocated_size
= STUB_BUFFER_INCR
;
2860 stub_desc
->stub_contents
= (char *) malloc (STUB_BUFFER_INCR
);
2862 else if ((stub_desc
->allocated_size
- stub_desc
->real_size
) < STUB_MAX_SIZE
)
2864 stub_desc
->allocated_size
= stub_desc
->allocated_size
+ STUB_BUFFER_INCR
;
2865 stub_desc
->stub_contents
= (char *) realloc (stub_desc
->stub_contents
,
2866 stub_desc
->allocated_size
);
2869 stub_desc
->stub_secp
2870 = (int *) (stub_desc
->stub_contents
+ stub_desc
->real_size
);
2872 /* Is this a millicode call? If so, the return address
2873 comes in on r31 rather than r2 (rp) so a slightly
2874 different code sequence is needed. */
2877 rtn_reg
= (insn
& 0x03e00000) >> 21;
2881 if (strcmp (symbol
->name
, "$$dyncall") == 0)
2884 /* If we are creating a call from a stub to another stub, then
2885 never do the instruction reordering. We can tell if we are
2886 going to be calling one stub from another by the fact that
2887 the symbol name has '_stub_' (arg. reloc. stub) or '_lb_stub_'
2888 prepended to the name. Alternatively, the section of the
2889 symbol will be '.hppa_linker_stubs'. */
2891 if ((strncmp (symbol
->name
, "_stub_", 6) == 0)
2892 || (strncmp (symbol
->name
, "_lb_stub_", 9) == 0))
2894 BFD_ASSERT (strcmp (symbol
->section
->name
, ".hppa_linker_stubs") == 0);
2898 /* Check to see if we modify the return pointer
2899 in the delay slot of the branch. */
2901 unsigned delay_insn
= data
[1];
2903 /* If we nullify the delay slot, or if the delay slot contains an
2904 instruction that modifies the return pointer, then no additional
2905 modification of the return pointer is necessary. */
2906 if (insn
& 2 || insn
== 0)
2910 if (get_opcode (delay_insn
) == LDO
2911 && (((delay_insn
& 0x001f0000) >> 16) == rtn_reg
))
2918 sprintf (stub_sym_name
,
2919 "_lb_stub_%s_%s", reloc_entry
->sym_ptr_ptr
[0]->name
,
2920 rtn_adjust
? "RA" : "");
2921 stub_entry
= find_stub_by_name(abfd
, stub_sec
, stub_sym_name
);
2923 /* If a copy of this stub already exists re-use it. */
2926 stub_sym
= stub_entry
->sym
;
2928 /* Change symbol associated with the original relocation to point
2931 FIXME. Is there a need to change the relocation type too? */
2932 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (stub_desc
->this_bfd
,
2933 sizeof (asymbol
*));
2934 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
2935 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_HPPA_STUB_CALL_17
);
2939 /* We will need to allocate a new stub. */
2940 stub_sym
= bfd_make_empty_symbol (abfd
);
2941 stub_sym
->name
= bfd_zalloc (abfd
, strlen (stub_sym_name
) + 1);
2942 strcpy ((char *) stub_sym
->name
, stub_sym_name
);
2944 = (int) stub_desc
->stub_secp
- (int) stub_desc
->stub_contents
;
2945 stub_sym
->section
= stub_sec
;
2946 stub_sym
->flags
= BSF_LOCAL
| BSF_FUNCTION
;
2947 stub_entry
= add_stub_by_name (abfd
, stub_sec
, stub_sym
, link_info
);
2949 /* Change symbol associated with the original relocation to point
2952 FIXME. Is there a need to change the relocation type too? */
2953 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (stub_desc
->this_bfd
,
2954 sizeof (asymbol
*));
2955 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
2956 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_HPPA_STUB_CALL_17
);
2958 /* Build the stub. */
2960 /* 1. initialization for the call. */
2961 NEW_INSTRUCTION (stub_entry
, LDSID_31_1
);
2962 NEW_INSTRUCTION (stub_entry
, MTSP_1_SR0
);
2970 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_RP
);
2974 NEW_INSTRUCTION (stub_entry
, COPY_31_2
);
2981 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_1
);
2985 NEW_INSTRUCTION (stub_entry
, COPY_31_1
);
2989 NEW_INSTRUCTION (stub_entry
, LDIL_XXX_31
);
2990 hppa_elf_stub_reloc (stub_desc
,
2993 CURRENT_STUB_OFFSET (stub_entry
),
2996 /* 2. Make the call. */
2999 NEW_INSTRUCTION (stub_entry
, BE_XXX_0_31
);
3000 hppa_elf_stub_reloc (stub_desc
,
3003 CURRENT_STUB_OFFSET (stub_entry
),
3004 R_HPPA_ABS_CALL_R17
);
3005 NEW_INSTRUCTION (stub_entry
, COPY_2_31
);
3009 NEW_INSTRUCTION (stub_entry
, BE_XXX_0_31
);
3010 hppa_elf_stub_reloc (stub_desc
,
3013 CURRENT_STUB_OFFSET (stub_entry
),
3014 R_HPPA_ABS_CALL_R17
);
3015 NEW_INSTRUCTION (stub_entry
, COPY_1_31
);
3020 /* 3. Branch back to the original location.
3021 (For non-millicode calls, this is accomplished with the
3022 COPY_31_2 instruction. For millicode calls, the return
3023 location is already in r2.) */
3026 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_RP
);
3028 NEW_INSTRUCTION (stub_entry
, LDIL_XXX_31
);
3029 hppa_elf_stub_reloc (stub_desc
,
3032 CURRENT_STUB_OFFSET (stub_entry
),
3035 NEW_INSTRUCTION (stub_entry
, BE_XXX_0_31
);
3036 hppa_elf_stub_reloc (stub_desc
,
3039 CURRENT_STUB_OFFSET (stub_entry
),
3040 R_HPPA_ABS_CALL_R17
);
3041 NEW_INSTRUCTION (stub_entry
, COPY_2_31
);
3048 hppa_elf_long_branch_needed_p (abfd
, asec
, reloc_entry
, symbol
, insn
)
3051 arelent
*reloc_entry
;
3055 long sym_value
= get_symbol_value(symbol
);
3056 int fmt
= reloc_entry
->howto
->bitsize
;
3057 unsigned char op
= get_opcode(insn
);
3060 #define too_far(val,num_bits) ((int)(val) > (1<<(num_bits))-1) || ((int)(val) < (-1<<(num_bits)))
3066 reloc_entry
->address
+ asec
->output_offset
+ asec
->output_section
->vma
;
3067 if ( too_far(sym_value
- raddr
,fmt
+1) )
3070 fprintf(stderr
,"long_branch needed on BL insn: abfd=%s,sym=%s,distance=0x%x\n",abfd
->filename
,symbol
->name
,sym_value
- reloc_entry
->address
);
3079 #define STUB_SYM_BUFFER_INC 5
3082 hppa_look_for_stubs_in_section (stub_bfd
, abfd
, output_bfd
, asec
,
3083 syms
, new_sym_cnt
, link_info
)
3090 struct bfd_link_info
*link_info
;
3094 asymbol
*new_syms
= (asymbol
*) NULL
;
3098 /* Relocations are in different places depending on whether this is
3099 an output section or an input section. Also, the relocations are
3100 in different forms. Sigh. Luckily, we have
3101 bfd_canonicalize_reloc() to straighten this out for us . */
3103 if (asec
->reloc_count
> 0)
3105 arelent
**reloc_vector
3106 = (arelent
**) alloca (asec
->reloc_count
* (sizeof (arelent
*) + 1));
3108 bfd_canonicalize_reloc (abfd
, asec
, reloc_vector
, syms
);
3109 for (i
= 0; i
< asec
->reloc_count
; i
++)
3111 arelent
*rle
= reloc_vector
[i
];
3113 switch (rle
->howto
->type
)
3115 case R_HPPA_ABS_CALL_11
:
3116 case R_HPPA_ABS_CALL_14
:
3117 case R_HPPA_ABS_CALL_17
:
3118 case R_HPPA_ABS_CALL_L21
:
3119 case R_HPPA_ABS_CALL_R11
:
3120 case R_HPPA_ABS_CALL_R14
:
3121 case R_HPPA_ABS_CALL_R17
:
3122 case R_HPPA_ABS_CALL_LS21
:
3123 case R_HPPA_ABS_CALL_RS11
:
3124 case R_HPPA_ABS_CALL_RS14
:
3125 case R_HPPA_ABS_CALL_RS17
:
3126 case R_HPPA_ABS_CALL_LD21
:
3127 case R_HPPA_ABS_CALL_RD11
:
3128 case R_HPPA_ABS_CALL_RD14
:
3129 case R_HPPA_ABS_CALL_RD17
:
3130 case R_HPPA_ABS_CALL_LR21
:
3131 case R_HPPA_ABS_CALL_RR14
:
3132 case R_HPPA_ABS_CALL_RR17
:
3133 case R_HPPA_PCREL_CALL_11
:
3134 case R_HPPA_PCREL_CALL_14
:
3135 case R_HPPA_PCREL_CALL_17
:
3136 case R_HPPA_PCREL_CALL_12
:
3137 case R_HPPA_PCREL_CALL_L21
:
3138 case R_HPPA_PCREL_CALL_R11
:
3139 case R_HPPA_PCREL_CALL_R14
:
3140 case R_HPPA_PCREL_CALL_R17
:
3141 case R_HPPA_PCREL_CALL_LS21
:
3142 case R_HPPA_PCREL_CALL_RS11
:
3143 case R_HPPA_PCREL_CALL_RS14
:
3144 case R_HPPA_PCREL_CALL_RS17
:
3145 case R_HPPA_PCREL_CALL_LD21
:
3146 case R_HPPA_PCREL_CALL_RD11
:
3147 case R_HPPA_PCREL_CALL_RD14
:
3148 case R_HPPA_PCREL_CALL_RD17
:
3149 case R_HPPA_PCREL_CALL_LR21
:
3150 case R_HPPA_PCREL_CALL_RR14
:
3151 case R_HPPA_PCREL_CALL_RR17
:
3153 symext_entryS caller_ar
3154 = (symext_entryS
) HPPA_R_ARG_RELOC (rle
->addend
);
3157 bfd_get_section_contents (abfd
, asec
, insn
, rle
->address
,
3159 if (hppa_elf_arg_reloc_needed_p (abfd
, rle
, stub_types
,
3162 /* Generate a stub and keep track of the new symbol. */
3165 if (new_cnt
== new_max
)
3167 new_max
+= STUB_SYM_BUFFER_INC
;
3168 new_syms
= (asymbol
*)
3169 realloc (new_syms
, new_max
* sizeof (asymbol
));
3172 /* The rtn_adjust argument is true here because we
3173 know that we have a branch and (with a few exceptions
3174 detailed under the relocation code for relocation type
3175 R_HPPA_STUB_CALL_17) it will be possible to perform
3176 the code reorientation. */
3177 r
= hppa_elf_build_arg_reloc_stub (stub_bfd
, output_bfd
,
3181 new_syms
[new_cnt
++] = *r
;
3184 /* We need to retrieve the section contents to check for
3185 long branch stubs. */
3186 if (hppa_elf_long_branch_needed_p (abfd
, asec
, rle
,
3187 rle
->sym_ptr_ptr
[0],
3190 /* Generate a stub and keep track of the new symbol. */
3193 if (new_cnt
== new_max
)
3195 new_max
+= STUB_SYM_BUFFER_INC
;
3196 new_syms
= (asymbol
*)
3197 realloc (new_syms
, (new_max
* sizeof (asymbol
)));
3199 r
= hppa_elf_build_long_branch_stub (stub_bfd
, output_bfd
,
3201 rle
->sym_ptr_ptr
[0],
3203 new_syms
[new_cnt
++] = *r
;
3208 case R_HPPA_PLABEL_32
:
3209 case R_HPPA_PLABEL_11
:
3210 case R_HPPA_PLABEL_14
:
3211 case R_HPPA_PLABEL_L21
:
3212 case R_HPPA_PLABEL_R11
:
3213 case R_HPPA_PLABEL_R14
:
3215 /* On a plabel relocation, assume the arguments of the
3216 caller are set up in general registers.
3217 NOTE: 0x155 = ARGW0=CR,ARGW1=GR,ARGW2=GR,RETVAL=GR */
3218 symext_entryS caller_ar
= (symext_entryS
) 0x155;
3221 bfd_get_section_contents (abfd
, asec
, insn
, rle
->address
,
3224 if (hppa_elf_arg_reloc_needed_p (abfd
, rle
, stub_types
,
3227 /* Generate a plabel stub and keep track of the
3232 if (new_cnt
== new_max
)
3234 new_max
+= STUB_SYM_BUFFER_INC
;
3235 new_syms
= (asymbol
*) realloc (new_syms
, new_max
3236 * sizeof (asymbol
));
3239 /* Determine whether a return adjustment
3240 (see the relocation code for relocation type
3241 R_HPPA_STUB_CALL_17) is possible. Basically,
3242 determine whether we are looking at a branch or not. */
3244 if (rle
->howto
->type
== R_HPPA_PLABEL_32
)
3248 switch (get_opcode(insn
[0]))
3258 r
= hppa_elf_build_arg_reloc_stub (stub_bfd
, output_bfd
,
3262 new_syms
[new_cnt
++] = *r
;
3273 *new_sym_cnt
= new_cnt
;
3278 char *linker_stubs
= NULL
;
3279 int linker_stubs_size
= 0;
3280 int linker_stubs_max_size
= 0;
3281 #define STUB_ALLOC_INCR 100
3284 DEFUN (hppa_elf_set_section_contents
, (abfd
, section
, location
, offset
, count
),
3289 bfd_size_type count
)
3291 if ( strcmp(section
->name
, ".hppa_linker_stubs") == 0 )
3293 if ( linker_stubs_max_size
< offset
+ count
)
3295 linker_stubs_max_size
= offset
+ count
+ STUB_ALLOC_INCR
;
3296 linker_stubs
= (char *)realloc(linker_stubs
, linker_stubs_max_size
);
3299 if ( offset
+ count
> linker_stubs_size
)
3300 linker_stubs_size
= offset
+ count
;
3302 memcpy(linker_stubs
+ offset
,location
,count
);
3306 return bfd_elf32_set_section_contents (abfd
, section
, location
,
3310 /* Get the contents of the given section.
3312 This is special for PA ELF because some sections (such as linker stubs)
3313 may reside in memory rather than on disk, or in the case of the symbol
3314 extension section, the contents may need to be generated from other
3315 information contained in the BFD. */
3318 hppa_elf_get_section_contents (abfd
, section
, location
, offset
, count
)
3323 bfd_size_type count
;
3325 /* If this is the linker stub section, then its contents are contained
3326 in memory rather than on disk. FIXME. Is that always right? What
3327 about the case where a final executable is read in and a user tries
3328 to get the contents of this section? In that case the contents would
3329 be on disk like everything else. */
3330 if (strcmp (section
->name
, ".hppa_linker_stubs") == 0)
3332 elf32_hppa_stub_description
*stub_desc
= find_stubs (abfd
, section
);
3337 /* Sanity check our arguments. */
3338 if ((bfd_size_type
) (offset
+ count
) > section
->_raw_size
3339 || (bfd_size_type
) (offset
+ count
) > stub_desc
->real_size
)
3342 memcpy (location
, stub_desc
->stub_contents
+ offset
, count
);
3346 /* The symbol extension section also needs special handling. Its
3347 contents might be on the disk, in memory, or still need to
3349 else if (strcmp (section
->name
, ".hppa_symextn") == 0)
3351 /* If there are no output sections, then read the contents of the
3352 symbol extension section from disk. */
3353 if (section
->output_section
== NULL
3354 && abfd
->direction
== read_direction
)
3356 return bfd_generic_get_section_contents (abfd
, section
, location
,
3360 /* If this is the first time through, and there are output sections,
3361 then build the symbol extension section based on other information
3362 contained in the BFD. */
3363 else if (! symext_chain_built
)
3367 (int *) elf_sym_extra(section
->output_section
->owner
);
3369 for (i
= 0; i
< section
->output_section
->owner
->symcount
; i
++ )
3371 elf_hppa_tc_symbol(section
->output_section
->owner
,
3372 ((elf_symbol_type
*)
3373 section
->output_section
->owner
->outsymbols
[i
]),
3376 symext_chain_built
++;
3377 elf_hppa_tc_make_sections (section
->output_section
->owner
, NULL
);
3380 /* At this point we know that the symbol extension section has been
3381 built. We just need to copy it into the user's buffer. */
3385 /* Sanity check our arguments. */
3386 if ((bfd_size_type
) (offset
+ count
) > section
->_raw_size
3387 || (bfd_size_type
) (offset
+ count
) > symextn_contents_real_size
)
3391 ((char *)symextn_contents
+ section
->output_offset
+ offset
),
3396 return bfd_generic_get_section_contents (abfd
, section
, location
,
3401 DEFUN (elf_info_to_howto
, (abfd
, cache_ptr
, dst
),
3403 arelent
* cache_ptr AND
3404 Elf32_Internal_Rela
* dst
)
3406 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_HPPA_UNIMPLEMENTED
);
3407 cache_ptr
->howto
= &elf_hppa_howto_table
[ELF32_R_TYPE(dst
->r_info
)];
3411 DEFUN (elf32_hppa_backend_symbol_processing
, (abfd
, sym
),
3415 /* Is this a definition of $global$? If so, keep it because it will be
3416 needed if any relocations are performed. */
3418 if (!strcmp (sym
->name
, "$global$")
3419 && sym
->section
!= &bfd_und_section
)
3421 global_symbol
= sym
;
3425 #define elf_backend_symbol_processing elf32_hppa_backend_symbol_processing
3427 struct elf32_hppa_symextn_map_struct
3435 static struct elf32_hppa_symextn_map_struct
*elf32_hppa_symextn_map
;
3436 static int elf32_hppa_symextn_map_size
;
3439 DEFUN (elf32_hppa_backend_symbol_table_processing
, (abfd
, esyms
,symcnt
),
3441 elf_symbol_type
*esyms AND
3444 Elf32_Internal_Shdr
*symextn_hdr
= bfd_elf_find_section (abfd
, SYMEXTN_SECTION_NAME
);
3446 int current_sym_idx
= 0;
3448 /* If the symbol extension section does not exist, all the symbol */
3449 /* all the symbol extension information is assumed to be zero. */
3451 if ( symextn_hdr
== NULL
)
3453 for ( i
= 0; i
< symcnt
; i
++ )
3455 esyms
[i
].tc_data
.hppa_arg_reloc
= 0;
3460 /* allocate a buffer of the appropriate size for the symextn section */
3462 symextn_hdr
->contents
= bfd_zalloc(abfd
,symextn_hdr
->sh_size
);
3463 symextn_hdr
->size
= symextn_hdr
->sh_size
;
3465 /* read in the symextn section */
3467 if (bfd_seek (abfd
, symextn_hdr
->sh_offset
, SEEK_SET
) == -1)
3469 bfd_error
= system_call_error
;
3472 if (bfd_read ((PTR
) symextn_hdr
->contents
, 1, symextn_hdr
->size
, abfd
)
3473 != symextn_hdr
->size
)
3475 free ((PTR
)symextn_hdr
->contents
);
3476 bfd_error
= system_call_error
;
3480 /* parse the entries, updating the symtab entries as we go */
3482 for ( i
= 0; i
< symextn_hdr
->size
/ sizeof(symext_entryS
); i
++ )
3484 symext_entryS
*seP
= ((symext_entryS
*)symextn_hdr
->contents
) + i
;
3485 int se_value
= ELF32_HPPA_SX_VAL(*seP
);
3486 int se_type
= ELF32_HPPA_SX_TYPE(*seP
);
3493 case HPPA_SXT_SYMNDX
:
3494 if ( se_value
>= symcnt
)
3496 bfd_error
= bad_value
;
3497 bfd_perror("elf32_hppa_backend_symbol_table_processing -- symbol index");
3500 current_sym_idx
= se_value
- 1;
3503 case HPPA_SXT_ARG_RELOC
:
3504 esyms
[current_sym_idx
].tc_data
.hppa_arg_reloc
= se_value
;
3508 bfd_error
= bad_value
;
3509 bfd_perror("elf32_hppa_backend_symbol_table_processing");
3516 #define elf_backend_symbol_table_processing elf32_hppa_backend_symbol_table_processing
3519 DEFUN (elf32_hppa_backend_section_processing
, (abfd
, secthdr
),
3521 Elf32_Internal_Shdr
*secthdr
)
3525 if ( secthdr
->sh_type
== SHT_HPPA_SYMEXTN
)
3527 for ( i
= 0; i
< secthdr
->size
/ sizeof(symext_entryS
); i
++ )
3529 symext_entryS
*seP
= ((symext_entryS
*)secthdr
->contents
) + i
;
3530 int se_value
= ELF32_HPPA_SX_VAL(*seP
);
3531 int se_type
= ELF32_HPPA_SX_TYPE(*seP
);
3538 case HPPA_SXT_SYMNDX
:
3539 for ( j
= 0; j
< abfd
->symcount
; j
++ )
3541 /* locate the map entry for this symbol, if there is one. */
3542 /* modify the symbol extension section symbol index entry */
3543 /* to reflect the new symbol table index */
3545 for ( k
= 0; k
< elf32_hppa_symextn_map_size
; k
++ )
3547 if ( elf32_hppa_symextn_map
[k
].old_index
== se_value
3548 && elf32_hppa_symextn_map
[k
].bfd
== abfd
->outsymbols
[j
]->the_bfd
3549 && elf32_hppa_symextn_map
[k
].sym
== abfd
->outsymbols
[j
] )
3552 ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, j
),
3559 case HPPA_SXT_ARG_RELOC
:
3563 bfd_error
= bad_value
;
3564 bfd_perror("elf32_hppa_backend_section_processing");
3572 #define elf_backend_section_processing elf32_hppa_backend_section_processing
3575 DEFUN (elf32_hppa_backend_section_from_shdr
, (abfd
, hdr
, name
),
3577 Elf32_Internal_Shdr
*hdr AND
3582 if ( hdr
->sh_type
== SHT_HPPA_SYMEXTN
)
3584 BFD_ASSERT ( strcmp(name
,".hppa_symextn") == 0 );
3586 /* Bits that get saved. This one is real. */
3589 newsect
= bfd_make_section (abfd
, name
);
3590 if (newsect
!= NULL
)
3592 newsect
->vma
= hdr
->sh_addr
;
3593 newsect
->_raw_size
= hdr
->sh_size
;
3594 newsect
->filepos
= hdr
->sh_offset
; /* so we can read back the bits */
3595 newsect
->flags
|= SEC_HAS_CONTENTS
;
3596 newsect
->alignment_power
= hdr
->sh_addralign
;
3598 if (hdr
->sh_flags
& SHF_ALLOC
)
3600 newsect
->flags
|= SEC_ALLOC
;
3601 newsect
->flags
|= SEC_LOAD
;
3604 if (!(hdr
->sh_flags
& SHF_WRITE
))
3605 newsect
->flags
|= SEC_READONLY
;
3607 if (hdr
->sh_flags
& SHF_EXECINSTR
)
3608 newsect
->flags
|= SEC_CODE
; /* FIXME: may only contain SOME code */
3610 newsect
->flags
|= SEC_DATA
;
3612 hdr
->rawdata
= (void *) newsect
;
3620 #define elf_backend_section_from_shdr elf32_hppa_backend_section_from_shdr
3623 DEFUN (elf32_hppa_backend_fake_sections
, (abfd
, secthdr
, asect
),
3625 Elf_Internal_Shdr
*secthdr AND
3629 if ( strcmp(asect
->name
, ".hppa_symextn") == 0 )
3631 secthdr
->sh_type
= SHT_HPPA_SYMEXTN
;
3632 secthdr
->sh_flags
= 0;
3633 secthdr
->sh_info
= elf_section_data(asect
)->rel_hdr
.sh_link
;
3634 secthdr
->sh_link
= elf_onesymtab(abfd
);
3638 if (!strcmp (asect
->name
, ".hppa_unwind"))
3640 secthdr
->sh_type
= SHT_PROGBITS
;
3641 /* Unwind descriptors are not part of the program memory image. */
3642 secthdr
->sh_flags
= 0;
3643 secthdr
->sh_info
= 0;
3644 secthdr
->sh_link
= 0;
3645 secthdr
->sh_entsize
= 16;
3649 /* @@ Should this be CPU specific?? KR */
3650 if (!strcmp (asect
->name
, ".stabstr"))
3652 secthdr
->sh_type
= SHT_STRTAB
;
3653 secthdr
->sh_flags
= 0;
3654 secthdr
->sh_info
= 0;
3655 secthdr
->sh_link
= 0;
3656 secthdr
->sh_entsize
= 0;
3663 #define elf_backend_fake_sections elf32_hppa_backend_fake_sections
3666 DEFUN (elf32_hppa_backend_section_from_bfd_section
, (abfd
, hdr
, asect
, retval
),
3668 Elf32_Internal_Shdr
*hdr AND
3673 if ( hdr
->sh_type
== SHT_HPPA_SYMEXTN
)
3677 if (((struct sec
*) (hdr
->rawdata
)) == asect
)
3679 BFD_ASSERT( strcmp(asect
->name
, ".hppa_symextn") == 0 );
3684 else if ( hdr
->sh_type
== SHT_STRTAB
)
3688 if (((struct sec
*) (hdr
->rawdata
)) == asect
)
3690 BFD_ASSERT ( strcmp (asect
->name
, ".stabstr") == 0);
3699 #define elf_backend_section_from_bfd_section elf32_hppa_backend_section_from_bfd_section
3701 #define bfd_generic_get_section_contents hppa_elf_get_section_contents
3702 #define bfd_elf32_set_section_contents hppa_elf_set_section_contents
3704 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
3705 #define TARGET_BIG_NAME "elf32-hppa"
3706 #define ELF_ARCH bfd_arch_hppa
3707 #define ELF_MACHINE_CODE EM_HPPA
3708 #define ELF_MAXPAGESIZE 0x1000
3710 #include "elf32-target.h"