1 /* BFD back-end for HP PA-RISC ELF files.
2 Copyright (C) 1990, 91, 92, 93, 94 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 /* Note there isn't much error handling code in here yet. Unexpected
34 conditions are handled by just calling abort. FIXME damnit! */
36 /* ELF32/HPPA relocation support
38 This file contains ELF32/HPPA relocation support as specified
39 in the Stratus FTX/Golf Object File Format (SED-1762) dated
42 #include "elf32-hppa.h"
44 #include "aout/aout64.h"
45 #include "hppa_stubs.h"
47 /* ELF/PA relocation howto entries. */
49 static bfd_reloc_status_type hppa_elf_reloc
50 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
52 static unsigned long hppa_elf_relocate_insn
53 PARAMS ((bfd
*, asection
*, unsigned long, unsigned long, long,
54 long, unsigned long, unsigned long, unsigned long));
56 static void hppa_elf_relocate_unwind_table
57 PARAMS ((bfd
*, PTR
, unsigned long, long, long,
58 unsigned long, unsigned long));
60 static long get_symbol_value
PARAMS ((asymbol
*));
61 static bfd_reloc_status_type hppa_elf_reloc
62 PARAMS ((bfd
*, arelent
*, asymbol
*, PTR
, asection
*, bfd
*, char **));
64 static CONST reloc_howto_type
* elf_hppa_reloc_type_lookup
65 PARAMS ((bfd_arch_info_type
*, bfd_reloc_code_real_type
));
67 static reloc_howto_type elf_hppa_howto_table
[ELF_HOWTO_TABLE_SIZE
] =
69 {R_HPPA_NONE
, 0, 3, 19, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_NONE"},
70 {R_HPPA_32
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_32"},
71 {R_HPPA_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_11"},
72 {R_HPPA_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_14"},
73 {R_HPPA_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_17"},
74 {R_HPPA_L21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_L21"},
75 {R_HPPA_R11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_R11"},
76 {R_HPPA_R14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_R14"},
77 {R_HPPA_R17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_R17"},
78 {R_HPPA_LS21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LS21"},
79 {R_HPPA_RS11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RS11"},
80 {R_HPPA_RS14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RS14"},
81 {R_HPPA_RS17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RS17"},
82 {R_HPPA_LD21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LD21"},
83 {R_HPPA_RD11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RD11"},
84 {R_HPPA_RD14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RD14"},
85 {R_HPPA_RD17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RD17"},
86 {R_HPPA_LR21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LR21"},
87 {R_HPPA_RR14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RR14"},
88 {R_HPPA_RR17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_RR17"},
89 {R_HPPA_GOTOFF_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_11"},
90 {R_HPPA_GOTOFF_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_14"},
91 {R_HPPA_GOTOFF_L21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_L21"},
92 {R_HPPA_GOTOFF_R11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_R11"},
93 {R_HPPA_GOTOFF_R14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_R14"},
94 {R_HPPA_GOTOFF_LS21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_LS21"},
95 {R_HPPA_GOTOFF_RS11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RS11"},
96 {R_HPPA_GOTOFF_RS14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RS14"},
97 {R_HPPA_GOTOFF_LD21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_LD21"},
98 {R_HPPA_GOTOFF_RD11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RD11"},
99 {R_HPPA_GOTOFF_RD14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RD14"},
100 {R_HPPA_GOTOFF_LR21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_LR21"},
101 {R_HPPA_GOTOFF_RR14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_GOTOFF_RR14"},
102 {R_HPPA_ABS_CALL_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_11"},
103 {R_HPPA_ABS_CALL_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_14"},
104 {R_HPPA_ABS_CALL_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_17"},
105 {R_HPPA_ABS_CALL_L21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_L21"},
106 {R_HPPA_ABS_CALL_R11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_R11"},
107 {R_HPPA_ABS_CALL_R14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_R14"},
108 {R_HPPA_ABS_CALL_R17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_R17"},
109 {R_HPPA_ABS_CALL_LS21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_LS21"},
110 {R_HPPA_ABS_CALL_RS11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RS11"},
111 {R_HPPA_ABS_CALL_RS14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RS14"},
112 {R_HPPA_ABS_CALL_RS17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RS17"},
113 {R_HPPA_ABS_CALL_LD21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_LD21"},
114 {R_HPPA_ABS_CALL_RD11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RD11"},
115 {R_HPPA_ABS_CALL_RD14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RD14"},
116 {R_HPPA_ABS_CALL_RD17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RD17"},
117 {R_HPPA_ABS_CALL_LR21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_LR21"},
118 {R_HPPA_ABS_CALL_RR14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RR14"},
119 {R_HPPA_ABS_CALL_RR17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ABS_CALL_RR17"},
120 {R_HPPA_PCREL_CALL_11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_11"},
121 {R_HPPA_PCREL_CALL_14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_14"},
122 {R_HPPA_PCREL_CALL_17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_17"},
123 {R_HPPA_PCREL_CALL_12
, 0, 3, 12, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_12"},
124 {R_HPPA_PCREL_CALL_L21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_L21"},
125 {R_HPPA_PCREL_CALL_R11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_R11"},
126 {R_HPPA_PCREL_CALL_R14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_R14"},
127 {R_HPPA_PCREL_CALL_R17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_R17"},
128 {R_HPPA_PCREL_CALL_LS21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_LS21"},
129 {R_HPPA_PCREL_CALL_RS11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RS11"},
130 {R_HPPA_PCREL_CALL_RS14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RS14"},
131 {R_HPPA_PCREL_CALL_RS17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RS17"},
132 {R_HPPA_PCREL_CALL_LD21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_LD21"},
133 {R_HPPA_PCREL_CALL_RD11
, 0, 3, 11, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RD11"},
134 {R_HPPA_PCREL_CALL_RD14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RD14"},
135 {R_HPPA_PCREL_CALL_RD17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RD17"},
136 {R_HPPA_PCREL_CALL_LR21
, 0, 3, 21, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_LR21"},
137 {R_HPPA_PCREL_CALL_RR14
, 0, 3, 14, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RR14"},
138 {R_HPPA_PCREL_CALL_RR17
, 0, 3, 17, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PCREL_CALL_RR17"},
139 {R_HPPA_PLABEL_32
, 0, 3, 32, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_32"},
140 {R_HPPA_PLABEL_11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_11"},
141 {R_HPPA_PLABEL_14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_14"},
142 {R_HPPA_PLABEL_L21
, 0, 3, 21, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_L21"},
143 {R_HPPA_PLABEL_R11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_R11"},
144 {R_HPPA_PLABEL_R14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_PLABEL_R14"},
145 {R_HPPA_DLT_32
, 0, 3, 32, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_32"},
146 {R_HPPA_DLT_11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_11"},
147 {R_HPPA_DLT_14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_14"},
148 {R_HPPA_DLT_L21
, 0, 3, 21, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_L21"},
149 {R_HPPA_DLT_R11
, 0, 3, 11, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_R11"},
150 {R_HPPA_DLT_R14
, 0, 3, 14, false, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_DLT_R14"},
151 {R_HPPA_UNWIND_ENTRY
, 0, 3, 32, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_UNWIND_ENTRY"},
152 {R_HPPA_UNWIND_ENTRIES
, 0, 3, 32, true, 0, complain_overflow_signed
, hppa_elf_reloc
, "R_HPPA_UNWIND_ENTRIES"},
153 {R_HPPA_PUSH_CONST
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_CONST"},
154 {R_HPPA_PUSH_PC
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_PC"},
155 {R_HPPA_PUSH_SYM
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_SYM"},
156 {R_HPPA_PUSH_GOTOFF
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_GOTOFF"},
157 {R_HPPA_PUSH_ABS_CALL
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_ABS_CALL"},
158 {R_HPPA_PUSH_PCREL_CALL
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_PCREL_CALL"},
159 {R_HPPA_PUSH_PLABEL
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_PUSH_PLABEL"},
160 {R_HPPA_MAX
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MAX"},
161 {R_HPPA_MIN
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MIN"},
162 {R_HPPA_ADD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ADD"},
163 {R_HPPA_SUB
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_SUB"},
164 {R_HPPA_MULT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MULT"},
165 {R_HPPA_DIV
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_DIV"},
166 {R_HPPA_MOD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_MOD"},
167 {R_HPPA_AND
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_AND"},
168 {R_HPPA_OR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_OR"},
169 {R_HPPA_XOR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_XOR"},
170 {R_HPPA_NOT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_NOT"},
171 {R_HPPA_LSHIFT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LSHIFT"},
172 {R_HPPA_ARITH_RSHIFT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_ARITH_RSHIFT"},
173 {R_HPPA_LOGIC_RSHIFT
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_LOGIC_RSHIFT"},
174 {R_HPPA_EXPR_F
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_L"},
175 {R_HPPA_EXPR_L
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_L"},
176 {R_HPPA_EXPR_R
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_R"},
177 {R_HPPA_EXPR_LS
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_LS"},
178 {R_HPPA_EXPR_RS
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_RS"},
179 {R_HPPA_EXPR_LD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_LD"},
180 {R_HPPA_EXPR_RD
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_RD"},
181 {R_HPPA_EXPR_LR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_LR"},
182 {R_HPPA_EXPR_RR
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_RR"},
183 {R_HPPA_EXPR_32
, 0, 3, 32, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_32"},
184 {R_HPPA_EXPR_21
, 0, 3, 21, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_21"},
185 {R_HPPA_EXPR_11
, 0, 3, 11, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_11"},
186 {R_HPPA_EXPR_14
, 0, 3, 14, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_14"},
187 {R_HPPA_EXPR_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_17"},
188 {R_HPPA_EXPR_12
, 0, 3, 12, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_EXPR_12"},
189 {R_HPPA_STUB_CALL_17
, 0, 3, 17, false, 0, complain_overflow_bitfield
, hppa_elf_reloc
, "R_HPPA_STUB_CALL_17"},
190 {R_HPPA_UNIMPLEMENTED
, 0, 0, 0, false, 0, complain_overflow_dont
, NULL
, "R_HPPA_UNIMPLEMENTED"},
193 static symext_chainS
*symext_rootP
;
194 static symext_chainS
*symext_lastP
;
195 static boolean symext_chain_built
;
196 static long global_value
;
197 static long GOT_value
;
198 static asymbol
*global_symbol
;
199 static int global_sym_defined
;
201 static symext_entryS
*symextn_contents
;
202 static unsigned int symextn_contents_real_size
;
204 /* Relocate the given INSN given the various input parameters.
206 FIXME: endianness and sizeof (long) issues abound here. */
209 hppa_elf_relocate_insn (abfd
, input_sect
, insn
, address
, sym_value
,
210 r_addend
, r_format
, r_field
, pcrel
)
212 asection
*input_sect
;
214 unsigned long address
;
217 unsigned long r_format
;
218 unsigned long r_field
;
221 unsigned char opcode
= get_opcode (insn
);
242 constant_value
= HPPA_R_CONSTANT (r_addend
);
245 sym_value
-= address
;
247 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
248 return hppa_rebuild_insn (abfd
, insn
, sym_value
, r_format
);
253 arg_reloc
= HPPA_R_ARG_RELOC (r_addend
);
255 /* XXX computing constant_value is not needed??? */
256 constant_value
= assemble_17 ((insn
& 0x001f0000) >> 16,
257 (insn
& 0x00001ffc) >> 2,
260 constant_value
= (constant_value
<< 15) >> 15;
264 address
+ input_sect
->output_offset
265 + input_sect
->output_section
->vma
;
266 sym_value
= hppa_field_adjust (sym_value
, -8, r_field
);
269 sym_value
= hppa_field_adjust (sym_value
, constant_value
, r_field
);
271 return hppa_rebuild_insn (abfd
, insn
, sym_value
>> 2, r_format
);
276 constant_value
= HPPA_R_CONSTANT (r_addend
);
279 sym_value
-= address
;
281 return hppa_field_adjust (sym_value
, constant_value
, r_field
);
288 /* Relocate a single unwind entry, or an entire table of them. */
291 hppa_elf_relocate_unwind_table (abfd
, data
, address
, sym_value
,
292 r_addend
, r_type
, r_field
)
295 unsigned long address
;
298 unsigned long r_type
;
299 unsigned long r_field
;
301 bfd_byte
*hit_data
= address
+ (bfd_byte
*) data
;
304 long relocated_value
;
309 case R_HPPA_UNWIND_ENTRY
:
310 /* Need to relocate the first two 32bit fields in the unwind. They
311 correspond to a function's start and end address. */
312 start_offset
= bfd_get_32 (abfd
, hit_data
);
313 relocated_value
= hppa_field_adjust (sym_value
, start_offset
, r_field
);
314 bfd_put_32 (abfd
, relocated_value
, hit_data
);
316 hit_data
+= sizeof (unsigned long);
317 end_offset
= bfd_get_32 (abfd
, hit_data
);
318 relocated_value
= hppa_field_adjust (sym_value
, end_offset
, r_field
);
319 bfd_put_32 (abfd
, relocated_value
, hit_data
);
322 case R_HPPA_UNWIND_ENTRIES
:
323 /* Relocate a mass of unwind entires. The count is passed in r_addend
324 (who's braindamaged idea was this anyway? */
325 for (i
= 0; i
< r_addend
; i
++, hit_data
+= 3 * sizeof (unsigned long))
327 unsigned int adjustment
;
328 /* Adjust the first 32bit field in the unwind entry. It's
329 the starting offset of a function. */
330 start_offset
= bfd_get_32 (abfd
, hit_data
);
331 bfd_put_32 (abfd
, sym_value
, hit_data
);
332 adjustment
= sym_value
- start_offset
;
334 /* Now adjust the second 32bit field, it's the ending offset
336 hit_data
+= sizeof (unsigned long);
337 end_offset
= adjustment
+ bfd_get_32 (abfd
, hit_data
);
338 bfd_put_32 (abfd
, end_offset
, hit_data
);
340 /* Prepare for the next iteration. */
341 start_offset
= bfd_get_32 (abfd
,
342 hit_data
+ 3 * sizeof (unsigned long));
343 sym_value
= start_offset
+ adjustment
;
352 /* Return the relocated value of the given symbol. */
355 get_symbol_value (symbol
)
359 || symbol
->section
== &bfd_com_section
)
362 return symbol
->value
+ symbol
->section
->output_section
->vma
363 + symbol
->section
->output_offset
;
366 /* Return one (or more) BFD relocations which implement the base
367 relocation with modifications based on format and field.
369 FIXME: Needs a decl in elf32-hppa.h. */
371 elf32_hppa_reloc_type
**
372 hppa_elf_gen_reloc_type (abfd
, base_type
, format
, field
)
374 elf32_hppa_reloc_type base_type
;
378 elf32_hppa_reloc_type
*finaltype
;
379 elf32_hppa_reloc_type
**final_types
;
381 /* Allocate slots for the BFD relocation. */
382 final_types
= (elf32_hppa_reloc_type
**)
383 bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
*) * 2);
384 BFD_ASSERT (final_types
!= 0); /* FIXME */
386 /* Allocate space for the relocation itself. */
387 finaltype
= (elf32_hppa_reloc_type
*)
388 bfd_alloc_by_size_t (abfd
, sizeof (elf32_hppa_reloc_type
));
389 BFD_ASSERT (finaltype
!= 0); /* FIXME */
391 /* Some reasonable defaults. */
392 final_types
[0] = finaltype
;
393 final_types
[1] = NULL
;
395 #define final_type finaltype[0]
397 final_type
= base_type
;
399 /* Just a tangle of nested switch statements to deal with the braindamage
400 that a different field selector means a completely different relocation
411 final_type
= R_HPPA_11
;
414 final_type
= R_HPPA_R11
;
417 final_type
= R_HPPA_RS11
;
420 final_type
= R_HPPA_RD11
;
423 final_type
= R_HPPA_PLABEL_11
;
426 final_type
= R_HPPA_PLABEL_R11
;
429 final_type
= R_HPPA_DLT_11
;
432 final_type
= R_HPPA_DLT_R11
;
444 final_type
= R_HPPA_R14
;
447 final_type
= R_HPPA_RS14
;
450 final_type
= R_HPPA_RD14
;
453 final_type
= R_HPPA_RR14
;
456 final_type
= R_HPPA_PLABEL_14
;
459 final_type
= R_HPPA_PLABEL_R14
;
462 final_type
= R_HPPA_DLT_14
;
465 final_type
= R_HPPA_DLT_R14
;
477 final_type
= R_HPPA_17
;
480 final_type
= R_HPPA_R17
;
483 final_type
= R_HPPA_RS17
;
486 final_type
= R_HPPA_RD17
;
489 final_type
= R_HPPA_RR17
;
501 final_type
= R_HPPA_L21
;
504 final_type
= R_HPPA_LS21
;
507 final_type
= R_HPPA_LD21
;
510 final_type
= R_HPPA_LR21
;
513 final_type
= R_HPPA_PLABEL_L21
;
516 final_type
= R_HPPA_PLABEL_L21
;
528 final_type
= R_HPPA_32
;
531 final_type
= R_HPPA_PLABEL_32
;
534 final_type
= R_HPPA_DLT_32
;
556 final_type
= R_HPPA_GOTOFF_R11
;
559 final_type
= R_HPPA_GOTOFF_RS11
;
562 final_type
= R_HPPA_GOTOFF_RD11
;
565 final_type
= R_HPPA_GOTOFF_11
;
577 final_type
= R_HPPA_GOTOFF_R14
;
580 final_type
= R_HPPA_GOTOFF_RS14
;
583 final_type
= R_HPPA_GOTOFF_RD14
;
586 final_type
= R_HPPA_GOTOFF_RR14
;
589 final_type
= R_HPPA_GOTOFF_14
;
601 final_type
= R_HPPA_GOTOFF_L21
;
604 final_type
= R_HPPA_GOTOFF_LS21
;
607 final_type
= R_HPPA_GOTOFF_LD21
;
610 final_type
= R_HPPA_GOTOFF_LR21
;
625 case R_HPPA_PCREL_CALL
:
632 final_type
= R_HPPA_PCREL_CALL_R11
;
635 final_type
= R_HPPA_PCREL_CALL_RS11
;
638 final_type
= R_HPPA_PCREL_CALL_RD11
;
641 final_type
= R_HPPA_PCREL_CALL_11
;
653 final_type
= R_HPPA_PCREL_CALL_R14
;
656 final_type
= R_HPPA_PCREL_CALL_RS14
;
659 final_type
= R_HPPA_PCREL_CALL_RD14
;
662 final_type
= R_HPPA_PCREL_CALL_RR14
;
665 final_type
= R_HPPA_PCREL_CALL_14
;
677 final_type
= R_HPPA_PCREL_CALL_R17
;
680 final_type
= R_HPPA_PCREL_CALL_RS17
;
683 final_type
= R_HPPA_PCREL_CALL_RD17
;
686 final_type
= R_HPPA_PCREL_CALL_RR17
;
689 final_type
= R_HPPA_PCREL_CALL_17
;
701 final_type
= R_HPPA_PCREL_CALL_L21
;
704 final_type
= R_HPPA_PCREL_CALL_LS21
;
707 final_type
= R_HPPA_PCREL_CALL_LD21
;
710 final_type
= R_HPPA_PCREL_CALL_LR21
;
732 final_type
= R_HPPA_PLABEL_11
;
735 final_type
= R_HPPA_PLABEL_R11
;
747 final_type
= R_HPPA_PLABEL_14
;
750 final_type
= R_HPPA_PLABEL_R14
;
762 final_type
= R_HPPA_PLABEL_L21
;
774 final_type
= R_HPPA_PLABEL_32
;
788 case R_HPPA_ABS_CALL
:
795 final_type
= R_HPPA_ABS_CALL_R11
;
798 final_type
= R_HPPA_ABS_CALL_RS11
;
801 final_type
= R_HPPA_ABS_CALL_RD11
;
804 final_type
= R_HPPA_ABS_CALL_11
;
816 final_type
= R_HPPA_ABS_CALL_R14
;
819 final_type
= R_HPPA_ABS_CALL_RS14
;
822 final_type
= R_HPPA_ABS_CALL_RD14
;
825 final_type
= R_HPPA_ABS_CALL_RR14
;
828 final_type
= R_HPPA_ABS_CALL_14
;
840 final_type
= R_HPPA_ABS_CALL_R17
;
843 final_type
= R_HPPA_ABS_CALL_RS17
;
846 final_type
= R_HPPA_ABS_CALL_RD17
;
849 final_type
= R_HPPA_ABS_CALL_RR17
;
852 final_type
= R_HPPA_ABS_CALL_17
;
864 final_type
= R_HPPA_ABS_CALL_L21
;
867 final_type
= R_HPPA_ABS_CALL_LS21
;
870 final_type
= R_HPPA_ABS_CALL_LD21
;
873 final_type
= R_HPPA_ABS_CALL_LR21
;
889 final_type
= R_HPPA_UNWIND_ENTRY
;
894 case R_HPPA_COMPLEX_PCREL_CALL
:
895 case R_HPPA_COMPLEX_ABS_CALL
:
896 /* The code originally here was horribly broken, and apparently
897 never used. Zap it. When we need complex relocations rewrite
903 final_type
= base_type
;
913 /* Actually perform a relocation. */
915 static bfd_reloc_status_type
916 hppa_elf_reloc (abfd
, reloc_entry
, symbol_in
, data
, input_section
, output_bfd
,
919 arelent
*reloc_entry
;
922 asection
*input_section
;
924 char **error_message
;
928 unsigned long addr
= reloc_entry
->address
;
929 bfd_byte
*hit_data
= addr
+ (bfd_byte
*) data
;
930 unsigned long r_type
= reloc_entry
->howto
->type
;
931 unsigned long r_field
= e_fsel
;
932 boolean r_pcrel
= reloc_entry
->howto
->pc_relative
;
933 unsigned r_format
= reloc_entry
->howto
->bitsize
;
934 long r_addend
= reloc_entry
->addend
;
936 /* If only performing a partial link, get out early. */
939 reloc_entry
->address
+= input_section
->output_offset
;
943 /* If performing final link and the symbol we're relocating against
944 is undefined, then return an error. */
945 if (symbol_in
&& symbol_in
->section
== &bfd_und_section
)
946 return bfd_reloc_undefined
;
948 /* Get the final relocated value. */
949 sym_value
= get_symbol_value (symbol_in
);
951 /* Compute the value of $global$.
952 FIXME: None of this should be necessary. $global$ is just a
953 marker and shouldn't really figure into these computations.
955 Once that's fixed we'll need to teach this backend to change
956 DP-relative relocations involving symbols in the text section
957 to be simple absolute relocations. */
958 if (!global_sym_defined
)
962 global_value
= (global_symbol
->value
963 + global_symbol
->section
->output_section
->vma
964 + global_symbol
->section
->output_offset
);
965 GOT_value
= global_value
;
966 global_sym_defined
++;
970 /* Get the instruction word. */
971 insn
= bfd_get_32 (abfd
, hit_data
);
973 /* Relocate the value based on one of the basic relocation types
975 basic_type_1: relocation is relative to $global$
976 basic_type_2: relocation is relative to the current GOT
977 basic_type_3: relocation is an absolute call
978 basic_type_4: relocation is an PC-relative call
979 basic_type_5: relocation is plabel reference
980 basic_type_6: relocation is an unwind table relocation
981 extended_type: unimplemented */
988 /* Handle all the basic type 1 relocations. */
994 goto do_basic_type_1
;
997 goto do_basic_type_1
;
1002 goto do_basic_type_1
;
1005 goto do_basic_type_1
;
1010 goto do_basic_type_1
;
1013 goto do_basic_type_1
;
1018 goto do_basic_type_1
;
1021 goto do_basic_type_1
;
1027 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1028 sym_value
, r_addend
, r_format
,
1032 /* Handle all the basic type 2 relocations. */
1033 case R_HPPA_GOTOFF_11
:
1034 case R_HPPA_GOTOFF_14
:
1036 goto do_basic_type_2
;
1037 case R_HPPA_GOTOFF_L21
:
1039 goto do_basic_type_2
;
1040 case R_HPPA_GOTOFF_R11
:
1041 case R_HPPA_GOTOFF_R14
:
1043 goto do_basic_type_2
;
1044 case R_HPPA_GOTOFF_LS21
:
1046 goto do_basic_type_2
;
1047 case R_HPPA_GOTOFF_RS11
:
1048 case R_HPPA_GOTOFF_RS14
:
1050 goto do_basic_type_2
;
1051 case R_HPPA_GOTOFF_LD21
:
1053 goto do_basic_type_2
;
1054 case R_HPPA_GOTOFF_RD11
:
1055 case R_HPPA_GOTOFF_RD14
:
1057 goto do_basic_type_2
;
1058 case R_HPPA_GOTOFF_LR21
:
1060 goto do_basic_type_2
;
1061 case R_HPPA_GOTOFF_RR14
:
1065 sym_value
-= GOT_value
;
1066 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1067 sym_value
, r_addend
, r_format
,
1071 /* Handle all the basic type 3 relocations. */
1072 case R_HPPA_ABS_CALL_11
:
1073 case R_HPPA_ABS_CALL_14
:
1074 case R_HPPA_ABS_CALL_17
:
1076 goto do_basic_type_3
;
1077 case R_HPPA_ABS_CALL_L21
:
1079 goto do_basic_type_3
;
1080 case R_HPPA_ABS_CALL_R11
:
1081 case R_HPPA_ABS_CALL_R14
:
1082 case R_HPPA_ABS_CALL_R17
:
1084 goto do_basic_type_3
;
1085 case R_HPPA_ABS_CALL_LS21
:
1087 goto do_basic_type_3
;
1088 case R_HPPA_ABS_CALL_RS11
:
1089 case R_HPPA_ABS_CALL_RS14
:
1090 case R_HPPA_ABS_CALL_RS17
:
1092 goto do_basic_type_3
;
1093 case R_HPPA_ABS_CALL_LD21
:
1095 goto do_basic_type_3
;
1096 case R_HPPA_ABS_CALL_RD11
:
1097 case R_HPPA_ABS_CALL_RD14
:
1098 case R_HPPA_ABS_CALL_RD17
:
1100 goto do_basic_type_3
;
1101 case R_HPPA_ABS_CALL_LR21
:
1103 goto do_basic_type_3
;
1104 case R_HPPA_ABS_CALL_RR14
:
1105 case R_HPPA_ABS_CALL_RR17
:
1109 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1110 sym_value
, r_addend
, r_format
,
1114 /* Handle all the basic type 4 relocations. */
1115 case R_HPPA_PCREL_CALL_11
:
1116 case R_HPPA_PCREL_CALL_14
:
1117 case R_HPPA_PCREL_CALL_17
:
1119 goto do_basic_type_4
;
1120 case R_HPPA_PCREL_CALL_L21
:
1122 goto do_basic_type_4
;
1123 case R_HPPA_PCREL_CALL_R11
:
1124 case R_HPPA_PCREL_CALL_R14
:
1125 case R_HPPA_PCREL_CALL_R17
:
1127 goto do_basic_type_4
;
1128 case R_HPPA_PCREL_CALL_LS21
:
1130 goto do_basic_type_4
;
1131 case R_HPPA_PCREL_CALL_RS11
:
1132 case R_HPPA_PCREL_CALL_RS14
:
1133 case R_HPPA_PCREL_CALL_RS17
:
1135 goto do_basic_type_4
;
1136 case R_HPPA_PCREL_CALL_LD21
:
1138 goto do_basic_type_4
;
1139 case R_HPPA_PCREL_CALL_RD11
:
1140 case R_HPPA_PCREL_CALL_RD14
:
1141 case R_HPPA_PCREL_CALL_RD17
:
1143 goto do_basic_type_4
;
1144 case R_HPPA_PCREL_CALL_LR21
:
1146 goto do_basic_type_4
;
1147 case R_HPPA_PCREL_CALL_RR14
:
1148 case R_HPPA_PCREL_CALL_RR17
:
1152 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1153 sym_value
, r_addend
, r_format
,
1157 /* Handle all the basic type 5 relocations. */
1158 case R_HPPA_PLABEL_32
:
1159 case R_HPPA_PLABEL_11
:
1160 case R_HPPA_PLABEL_14
:
1162 goto do_basic_type_5
;
1163 case R_HPPA_PLABEL_L21
:
1165 goto do_basic_type_5
;
1166 case R_HPPA_PLABEL_R11
:
1167 case R_HPPA_PLABEL_R14
:
1170 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
, addr
,
1171 sym_value
, r_addend
, r_format
,
1175 /* Handle all basic type 6 relocations. */
1176 case R_HPPA_UNWIND_ENTRY
:
1177 case R_HPPA_UNWIND_ENTRIES
:
1178 hppa_elf_relocate_unwind_table (abfd
, data
, addr
,
1179 sym_value
, r_addend
,
1181 return bfd_reloc_ok
;
1183 /* This is a linker internal relocation. */
1184 case R_HPPA_STUB_CALL_17
:
1185 /* This relocation is for a branch to a long branch stub.
1186 Change instruction to a BLE,N. It may also be necessary
1187 to interchange the branch and its delay slot.
1188 The original instruction stream is
1190 bl <foo>,r ; call foo using register r as
1191 ; the return pointer
1192 XXX ; delay slot instruction
1194 The new instruction stream will be:
1196 XXX ; delay slot instruction
1197 ble <foo_stub> ; call the long call stub for foo
1198 ; using r31 as the return pointer
1200 This braindamage is necessary because the compiler may put
1201 an instruction which uses %r31 in the delay slot of the original
1202 call. By changing the call instruction from a "bl" to a "ble"
1203 %r31 gets clobbered before the delay slot executes. This
1204 also means the stub has to play funny games to make sure
1205 we return to the instruction just after the BLE rather than
1206 two instructions after the BLE.
1208 We do not interchange the branch and delay slot if the delay
1209 slot was already nullified, or if the instruction in the delay
1210 slot modifies the return pointer to avoid an unconditional
1211 jump after the call returns (GCC optimization).
1213 None of this horseshit would be necessary if we put the
1214 stubs between functions and just redirected the "bl" to
1215 the stub. Live and learn. */
1217 /* Is this instruction nullified? (does this ever happen?) */
1220 insn
= BLE_N_XXX_0_0
;
1221 bfd_put_32 (abfd
, insn
, hit_data
);
1222 r_type
= R_HPPA_ABS_CALL_17
;
1224 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1225 addr
, sym_value
, r_addend
,
1226 r_format
, r_field
, r_pcrel
);
1230 /* So much for the trivial case... */
1231 unsigned long old_delay_slot_insn
= bfd_get_32 (abfd
, hit_data
+ 4);
1232 unsigned rtn_reg
= (insn
& 0x03e00000) >> 21;
1234 if (get_opcode (old_delay_slot_insn
) == LDO
)
1236 unsigned ldo_src_reg
= (old_delay_slot_insn
& 0x03e00000) >> 21;
1237 unsigned ldo_target_reg
= (old_delay_slot_insn
& 0x001f0000) >> 16;
1239 /* If the target of the LDO is the same as the return
1240 register then there is no reordering. We can leave the
1241 instuction as a non-nullified BLE in this case.
1243 FIXME: This test looks wrong. If we had a ble using
1244 ldo_target_reg as the *source* we'd fuck this up. */
1245 if (ldo_target_reg
== rtn_reg
)
1247 unsigned long new_delay_slot_insn
= old_delay_slot_insn
;
1249 BFD_ASSERT (ldo_src_reg
== ldo_target_reg
);
1250 new_delay_slot_insn
&= 0xfc00ffff;
1251 new_delay_slot_insn
|= ((31 << 21) | (31 << 16));
1252 bfd_put_32 (abfd
, new_delay_slot_insn
, hit_data
+ 4);
1254 r_type
= R_HPPA_ABS_CALL_17
;
1256 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1257 addr
, sym_value
, r_addend
,
1258 r_format
, r_field
, r_pcrel
);
1259 bfd_put_32 (abfd
, insn
, hit_data
);
1260 return bfd_reloc_ok
;
1262 else if (rtn_reg
== 31)
1264 /* The return register is r31, so this is a millicode
1265 call. Do not perform any instruction reordering. */
1267 r_type
= R_HPPA_ABS_CALL_17
;
1269 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1273 bfd_put_32 (abfd
, insn
, hit_data
);
1274 return bfd_reloc_ok
;
1278 /* Check to see if the delay slot instruction has a
1279 relocation. If so, we need to change the address
1280 field of it because the instruction it relocates
1281 is going to be moved. Oh what a mess. */
1282 arelent
* next_reloc_entry
= reloc_entry
+1;
1284 if (next_reloc_entry
->address
== reloc_entry
->address
+ 4)
1285 next_reloc_entry
->address
-= 4;
1287 insn
= old_delay_slot_insn
;
1288 bfd_put_32 (abfd
, insn
, hit_data
);
1289 insn
= BLE_N_XXX_0_0
;
1290 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1291 r_type
= R_HPPA_ABS_CALL_17
;
1293 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1295 sym_value
, r_addend
,
1296 r_format
, r_field
, r_pcrel
);
1297 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1298 return bfd_reloc_ok
;
1301 /* Same comments as above regarding incorrect test. */
1302 else if (rtn_reg
== 31)
1304 /* The return register is r31, so this is a millicode call.
1305 Perform no instruction reordering in this case. */
1307 r_type
= R_HPPA_ABS_CALL_17
;
1309 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1313 bfd_put_32 (abfd
, insn
, hit_data
);
1314 return bfd_reloc_ok
;
1318 /* Check to see if the delay slot instruction has a
1319 relocation. If so, we need to change its address
1320 field because the instruction it relocates is going
1322 arelent
* next_reloc_entry
= reloc_entry
+1;
1324 if (next_reloc_entry
->address
== reloc_entry
->address
+ 4)
1325 next_reloc_entry
->address
-= 4;
1327 insn
= old_delay_slot_insn
;
1328 bfd_put_32 (abfd
, insn
, hit_data
);
1329 insn
= BLE_N_XXX_0_0
;
1330 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1331 r_type
= R_HPPA_ABS_CALL_17
;
1333 insn
= hppa_elf_relocate_insn (abfd
, input_section
, insn
,
1334 addr
+ 4, sym_value
,
1337 bfd_put_32 (abfd
, insn
, hit_data
+ 4);
1338 return bfd_reloc_ok
;
1343 /* Something we don't know how to handle. */
1345 *error_message
= (char *) "Unrecognized reloc";
1346 return bfd_reloc_notsupported
;
1349 /* Update the instruction word. */
1350 bfd_put_32 (abfd
, insn
, hit_data
);
1351 return (bfd_reloc_ok
);
1354 /* Return the address of the howto table entry to perform the CODE
1355 relocation for an ARCH machine. */
1357 static CONST reloc_howto_type
*
1358 elf_hppa_reloc_type_lookup (arch
, code
)
1359 bfd_arch_info_type
*arch
;
1360 bfd_reloc_code_real_type code
;
1362 if ((int) code
< (int) R_HPPA_UNIMPLEMENTED
)
1364 BFD_ASSERT ((int) elf_hppa_howto_table
[(int) code
].type
== (int) code
);
1365 return &elf_hppa_howto_table
[(int) code
];
1371 /* Update the symbol extention chain to include the symbol pointed to
1372 by SYMBOLP if SYMBOLP is a function symbol. Used internally and by GAS. */
1375 elf_hppa_tc_symbol (abfd
, symbolP
, sym_idx
, symext_root
, symext_last
)
1377 elf_symbol_type
*symbolP
;
1379 symext_chainS
**symext_root
;
1380 symext_chainS
**symext_last
;
1382 symext_chainS
*symextP
;
1383 unsigned int arg_reloc
;
1385 /* Only functions can have argument relocations. */
1386 if (!(symbolP
->symbol
.flags
& BSF_FUNCTION
))
1389 arg_reloc
= symbolP
->tc_data
.hppa_arg_reloc
;
1391 /* If there are no argument relocation bits, then no relocation is
1392 necessary. Do not add this to the symextn section. */
1396 /* Allocate memory and initialize this entry. */
1397 symextP
= (symext_chainS
*) bfd_alloc (abfd
, sizeof (symext_chainS
) * 2);
1400 bfd_set_error (bfd_error_no_memory
);
1401 abort(); /* FIXME */
1404 symextP
[0].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, sym_idx
);
1405 symextP
[0].next
= &symextP
[1];
1407 symextP
[1].entry
= ELF32_HPPA_SX_WORD (HPPA_SXT_ARG_RELOC
, arg_reloc
);
1408 symextP
[1].next
= NULL
;
1410 /* Now update the chain itself so it can be walked later to build
1411 the symbol extension section. */
1412 if (*symext_root
== NULL
)
1414 *symext_root
= &symextP
[0];
1415 *symext_last
= &symextP
[1];
1419 (*symext_last
)->next
= &symextP
[0];
1420 *symext_last
= &symextP
[1];
1424 /* Build the symbol extension section. Used internally and by GAS. */
1427 elf_hppa_tc_make_sections (abfd
, symext_root
)
1429 symext_chainS
*symext_root
;
1431 symext_chainS
*symextP
;
1433 asection
*symextn_sec
;
1435 /* FIXME: Huh? I don't see what this is supposed to do for us. */
1436 hppa_elf_stub_finish (abfd
);
1438 /* If there are no entries in the symbol extension chain, then
1439 there is no symbol extension section. */
1440 if (symext_root
== NULL
)
1443 /* Count the number of entries on the chain. */
1444 for (n
= 0, symextP
= symext_root
; symextP
; symextP
= symextP
->next
, ++n
)
1447 /* Create the symbol extension section and set some appropriate
1449 size
= sizeof (symext_entryS
) * n
;
1450 symextn_sec
= bfd_get_section_by_name (abfd
, SYMEXTN_SECTION_NAME
);
1451 if (symextn_sec
== (asection
*) 0)
1453 symextn_sec
= bfd_make_section (abfd
, SYMEXTN_SECTION_NAME
);
1454 bfd_set_section_flags (abfd
,
1456 SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_DATA
);
1457 symextn_sec
->output_section
= symextn_sec
;
1458 symextn_sec
->output_offset
= 0;
1459 bfd_set_section_alignment (abfd
, symextn_sec
, 2);
1461 bfd_set_section_size (abfd
, symextn_sec
, symextn_contents_real_size
);
1462 symextn_contents_real_size
= size
;
1464 /* Grab some memory for the contents of the symbol extension section
1466 symextn_contents
= (symext_entryS
*) bfd_alloc (abfd
, size
);
1467 if (!symextn_contents
)
1469 bfd_set_error (bfd_error_no_memory
);
1470 abort(); /* FIXME */
1473 /* Fill in the contents of the symbol extension section. */
1474 for (i
= 0, symextP
= symext_root
; symextP
; symextP
= symextP
->next
, ++i
)
1475 symextn_contents
[i
] = symextP
->entry
;
1480 /* Support for HP PA-RISC stub generation.
1484 Center for Software Science
1485 Department of Computer Science
1491 HP-PA calling conventions state:
1493 1. an argument relocation stub is required whenever the callee and
1494 caller argument relocation bits do not match exactly. The exception
1495 to this rule is if either the caller or callee argument relocation
1496 bit are 00 (do not relocate).
1498 2. The linker can optionally add a symbol record for the stub so that
1499 the stub can be reused. The symbol record will be the same as the
1500 original export symbol record, except that the relocation bits will
1501 reflect the input of the stub, the type would be STUB and the symbol
1502 value will be the location of the relocation stub.
1506 Stubs can be inserted *before* the section of the caller. The stubs
1507 can be treated as calls to code that manipulates the arguments.
1514 HPPA_STUB_ARG_RELOC
,
1515 HPPA_STUB_LONG_BRANCH
1519 elf32_hppa_get_sym_extn (abfd
, sym
, type
)
1524 /* This function finds the symbol extension record of the */
1525 /* specified type for the specified symbol. It returns the */
1526 /* value of the symbol extension record. */
1527 symext_entryS retval
;
1532 retval
= (symext_entryS
) 0;
1534 case HPPA_SXT_SYMNDX
:
1535 retval
= (symext_entryS
) 0; /* XXX: need to fix this */
1537 case HPPA_SXT_ARG_RELOC
:
1539 elf_symbol_type
*esymP
= (elf_symbol_type
*) sym
;
1541 retval
= (symext_entryS
) esymP
->tc_data
.hppa_arg_reloc
;
1544 /* This should never happen. */
1551 typedef struct elf32_hppa_stub_name_list_struct
1553 /* name of this stub */
1555 /* stub description for this stub */
1556 struct elf32_hppa_stub_description_struct
*stub_desc
;
1557 /* pointer into stub contents */
1559 /* size of this stub */
1561 /* next stub name entry */
1562 struct elf32_hppa_stub_name_list_struct
*next
;
1563 } elf32_hppa_stub_name_list
;
1565 typedef struct elf32_hppa_stub_description_struct
1567 struct elf32_hppa_stub_description_struct
*next
;
1568 bfd
*this_bfd
; /* bfd to which this stub applies */
1569 asection
*stub_sec
; /* stub section for this bfd */
1570 unsigned relocs_allocated_cnt
; /* count of relocations for this stub section */
1572 unsigned allocated_size
;
1573 int *stub_secp
; /* pointer to the next available location in the buffer */
1574 char *stub_contents
; /* contents of the stubs for this bfd */
1575 elf32_hppa_stub_name_list
*stub_listP
;
1576 struct bfd_link_info
*link_info
;
1578 elf32_hppa_stub_description
;
1580 static elf32_hppa_stub_description
*elf_hppa_stub_rootP
;
1582 /* Locate the stub section information for the given bfd. */
1583 static elf32_hppa_stub_description
*
1584 find_stubs (abfd
, stub_sec
)
1588 elf32_hppa_stub_description
*stubP
;
1590 for (stubP
= elf_hppa_stub_rootP
; stubP
; stubP
= stubP
->next
)
1592 if (stubP
->this_bfd
== abfd
1593 && stubP
->stub_sec
== stub_sec
)
1597 return (elf32_hppa_stub_description
*) NULL
;
1600 static elf32_hppa_stub_description
*
1601 new_stub (abfd
, stub_sec
, link_info
)
1604 struct bfd_link_info
*link_info
;
1606 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1611 stub
= (elf32_hppa_stub_description
*) bfd_zalloc (abfd
, sizeof (elf32_hppa_stub_description
));
1614 stub
->this_bfd
= abfd
;
1615 stub
->stub_sec
= stub_sec
;
1616 stub
->real_size
= 0;
1617 stub
->allocated_size
= 0;
1618 stub
->stub_contents
= NULL
;
1619 stub
->stub_secp
= NULL
;
1620 stub
->link_info
= link_info
;
1622 stub
->next
= elf_hppa_stub_rootP
;
1623 elf_hppa_stub_rootP
= stub
;
1627 bfd_set_error (bfd_error_no_memory
);
1628 abort(); /* FIXME */
1634 /* Locate the stub by the given name. */
1635 static elf32_hppa_stub_name_list
*
1636 find_stub_by_name (abfd
, stub_sec
, name
)
1641 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1645 elf32_hppa_stub_name_list
*name_listP
;
1647 for (name_listP
= stub
->stub_listP
; name_listP
; name_listP
= name_listP
->next
)
1649 if (!strcmp (name_listP
->sym
->name
, name
))
1657 /* Locate the stub by the given name. */
1658 static elf32_hppa_stub_name_list
*
1659 add_stub_by_name(abfd
, stub_sec
, sym
, link_info
)
1663 struct bfd_link_info
*link_info
;
1665 elf32_hppa_stub_description
*stub
= find_stubs (abfd
, stub_sec
);
1666 elf32_hppa_stub_name_list
*stub_entry
;
1669 stub
= new_stub(abfd
, stub_sec
, link_info
);
1673 stub_entry
= (elf32_hppa_stub_name_list
*)
1674 bfd_zalloc (abfd
, sizeof (elf32_hppa_stub_name_list
));
1678 stub_entry
->size
= 0;
1679 stub_entry
->sym
= sym
;
1680 stub_entry
->stub_desc
= stub
;
1681 /* First byte of this stub is the pointer to
1682 the next available location in the stub buffer. */
1683 stub_entry
->stub_secp
= stub
->stub_secp
;
1684 if (stub
->stub_listP
)
1685 stub_entry
->next
= stub
->stub_listP
;
1687 stub_entry
->next
= NULL
;
1688 stub
->stub_listP
= stub_entry
;
1693 bfd_set_error (bfd_error_no_memory
);
1694 abort(); /* FIXME */
1698 return (elf32_hppa_stub_name_list
*)NULL
;
1702 #define RETURN_VALUE 1
1704 #define NO_ARG_RELOC 0
1711 #define ARG_RELOC_ERR 7
1723 /* FP register in arg0/arg1. This value can only appear in the arg0 location. */
1725 /* FP register in arg2/arg3. This value can only appear in the arg2 location. */
1728 #define AR_WARN(type,loc) \
1729 fprintf(stderr,"WARNING: Illegal argument relocation: %s for %s\n", \
1730 reloc_type_strings[type],reloc_loc_strings[loc])
1732 static CONST
char *CONST reloc_type_strings
[] =
1734 "NONE", "GR->FR", "GR0,GR1->FR1", "GR2,GR3->FR3", "FR->GR", "FR->GR0,GR1", "FR->GR2,GR3", "ERROR"
1737 static CONST
char *CONST reloc_loc_strings
[] =
1739 "ARG0", "ARG1", "ARG2", "ARG3", "RETVAL"
1742 static CONST
char mismatches
[6][6] =
1743 { /* CALLEE NONE CALLEE GR CALLEE FR CALLEE FU CALLEE DBL01 CALLEE DBL23 */
1745 {NO_ARG_RELOC
, NO_ARG_RELOC
, NO_ARG_RELOC
, ARG_RELOC_ERR
, NO_ARG_RELOC
, NO_ARG_RELOC
},
1747 {NO_ARG_RELOC
, NO_ARG_RELOC
, R_TO_FR
, ARG_RELOC_ERR
, R01_TO_FR
, ARG_RELOC_ERR
},
1749 {NO_ARG_RELOC
, FR_TO_R
, NO_ARG_RELOC
, ARG_RELOC_ERR
, ARG_RELOC_ERR
},
1751 {ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
},
1753 {NO_ARG_RELOC
, FR_TO_R01
, NO_ARG_RELOC
, ARG_RELOC_ERR
, NO_ARG_RELOC
, ARG_RELOC_ERR
},
1755 {NO_ARG_RELOC
, FR_TO_R23
, NO_ARG_RELOC
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, NO_ARG_RELOC
},
1758 static CONST
char retval_mismatches
[6][6] =
1759 { /* CALLEE NONE CALLEE GR CALLEE FR CALLEE FU CALLEE DBL01 CALLEE DBL23 */
1761 {NO_ARG_RELOC
, NO_ARG_RELOC
, NO_ARG_RELOC
, ARG_RELOC_ERR
, NO_ARG_RELOC
, NO_ARG_RELOC
},
1763 {NO_ARG_RELOC
, NO_ARG_RELOC
, FR_TO_R
, ARG_RELOC_ERR
, FR_TO_R01
, ARG_RELOC_ERR
},
1765 {NO_ARG_RELOC
, R_TO_FR
, NO_ARG_RELOC
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
},
1767 {ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, ARG_RELOC_ERR
},
1769 {NO_ARG_RELOC
, R01_TO_FR
, NO_ARG_RELOC
, ARG_RELOC_ERR
, NO_ARG_RELOC
, ARG_RELOC_ERR
},
1771 {NO_ARG_RELOC
, R23_TO_FR
, NO_ARG_RELOC
, ARG_RELOC_ERR
, ARG_RELOC_ERR
, NO_ARG_RELOC
},
1775 type_of_mismatch (caller_bits
, callee_bits
, type
)
1783 return mismatches
[caller_bits
][callee_bits
];
1785 return retval_mismatches
[caller_bits
][callee_bits
];
1791 #define EXTRACT_ARBITS(ar,which) ((ar) >> (8-(which*2))) & 3
1793 #define NEW_INSTRUCTION(entry,insn) \
1795 *((entry)->stub_desc->stub_secp)++ = (insn); \
1796 (entry)->stub_desc->real_size += sizeof(int); \
1797 (entry)->size += sizeof(int); \
1798 bfd_set_section_size((entry)->stub_desc->this_bfd, \
1799 (entry)->stub_desc->stub_sec, \
1800 (entry)->stub_desc->real_size); \
1803 #define CURRENT_STUB_OFFSET(entry) \
1804 ((char *)(entry)->stub_desc->stub_secp \
1805 - (char *)(entry)->stub_desc->stub_contents - 4)
1807 static boolean stubs_finished
= false;
1810 hppa_elf_stub_finish (output_bfd
)
1813 elf32_hppa_stub_description
*stub_list
= elf_hppa_stub_rootP
;
1814 /* All the stubs have been built. Finish up building */
1815 /* stub section. Apply relocations to the section. */
1820 for (; stub_list
; stub_list
= stub_list
->next
)
1822 if (stub_list
->real_size
)
1824 bfd
*stub_bfd
= stub_list
->this_bfd
;
1825 asection
*stub_sec
= bfd_get_section_by_name (stub_bfd
, ".hppa_linker_stubs");
1826 bfd_size_type reloc_size
;
1827 arelent
**reloc_vector
;
1829 BFD_ASSERT (stub_sec
== stub_list
->stub_sec
);
1830 reloc_size
= bfd_get_reloc_upper_bound (stub_bfd
, stub_sec
);
1831 reloc_vector
= (arelent
**) alloca (reloc_size
);
1833 BFD_ASSERT (stub_sec
);
1835 /* We are not relaxing the section, so just copy the size info */
1836 stub_sec
->_cooked_size
= stub_sec
->_raw_size
;
1837 stub_sec
->reloc_done
= true;
1840 if (bfd_canonicalize_reloc (stub_bfd
,
1843 output_bfd
->outsymbols
))
1846 for (parent
= reloc_vector
; *parent
!= (arelent
*) NULL
;
1849 char *err
= (char *) NULL
;
1850 bfd_reloc_status_type r
=
1851 bfd_perform_relocation (stub_bfd
,
1853 stub_list
->stub_contents
,
1854 stub_sec
, (bfd
*) NULL
, &err
);
1857 if (r
!= bfd_reloc_ok
)
1859 struct bfd_link_info
*link_info
= stub_list
->link_info
;
1863 case bfd_reloc_undefined
:
1864 if (! ((*link_info
->callbacks
->undefined_symbol
)
1866 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
1867 stub_bfd
, stub_sec
, (*parent
)->address
)))
1870 case bfd_reloc_dangerous
:
1871 if (! ((*link_info
->callbacks
->reloc_dangerous
)
1872 (link_info
, err
, stub_bfd
, stub_sec
,
1873 (*parent
)->address
)))
1876 case bfd_reloc_overflow
:
1878 if (! ((*link_info
->callbacks
->reloc_overflow
)
1880 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
1881 (*parent
)->howto
->name
,
1884 (*parent
)->address
)))
1888 case bfd_reloc_outofrange
:
1897 bfd_set_section_contents (output_bfd
,
1899 stub_list
->stub_contents
,
1901 stub_list
->real_size
);
1903 free (reloc_vector
);
1906 stubs_finished
= true;
1910 hppa_elf_stub_branch_reloc (stub_desc
, /* the bfd */
1911 output_bfd
, /* the output bfd */
1912 target_sym
, /* the target symbol */
1913 offset
) /* the offset within the stub buffer (pre-calculated) */
1914 elf32_hppa_stub_description
*stub_desc
;
1916 asymbol
*target_sym
;
1919 /* Allocate a new relocation entry. */
1923 if (stub_desc
->relocs_allocated_cnt
== stub_desc
->stub_sec
->reloc_count
)
1925 if (stub_desc
->stub_sec
->relocation
== NULL
)
1927 stub_desc
->relocs_allocated_cnt
= STUB_RELOC_INCR
;
1928 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
1929 stub_desc
->stub_sec
->relocation
= (arelent
*) bfd_zmalloc (size
);
1933 stub_desc
->relocs_allocated_cnt
+= STUB_RELOC_INCR
;
1934 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
1935 stub_desc
->stub_sec
->relocation
= (arelent
*) realloc (stub_desc
->stub_sec
->relocation
,
1938 if (!stub_desc
->stub_sec
->relocation
)
1940 bfd_set_error (bfd_error_no_memory
);
1941 abort(); /* FIXME */
1945 /* Fill in the details. */
1946 relent
.address
= offset
;
1948 relent
.sym_ptr_ptr
= (asymbol
**) bfd_zalloc (stub_desc
->this_bfd
, sizeof (asymbol
*));
1949 BFD_ASSERT (relent
.sym_ptr_ptr
); /* FIXME */
1951 relent
.sym_ptr_ptr
[0] = target_sym
;
1952 relent
.howto
= bfd_reloc_type_lookup (stub_desc
->this_bfd
, R_HPPA_PCREL_CALL_17
);
1954 /* Save it in the array of relocations for the stub section. */
1956 memcpy (&stub_desc
->stub_sec
->relocation
[stub_desc
->stub_sec
->reloc_count
++],
1962 hppa_elf_stub_reloc (stub_desc
, /* the bfd */
1963 output_bfd
, /* the output bfd */
1964 target_sym
, /* the target symbol */
1965 offset
, /* the offset within the stub buffer (pre-calculated) */
1967 elf32_hppa_stub_description
*stub_desc
;
1969 asymbol
*target_sym
;
1971 elf32_hppa_reloc_type type
;
1973 /* Allocate a new relocation entry. */
1976 Elf_Internal_Shdr
*rela_hdr
;
1978 if (stub_desc
->relocs_allocated_cnt
== stub_desc
->stub_sec
->reloc_count
)
1980 if (stub_desc
->stub_sec
->relocation
== NULL
)
1982 stub_desc
->relocs_allocated_cnt
= STUB_RELOC_INCR
;
1983 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
1984 stub_desc
->stub_sec
->relocation
= (arelent
*) bfd_zmalloc (size
);
1988 stub_desc
->relocs_allocated_cnt
+= STUB_RELOC_INCR
;
1989 size
= sizeof (arelent
) * stub_desc
->relocs_allocated_cnt
;
1990 stub_desc
->stub_sec
->relocation
= (arelent
*) realloc (stub_desc
->stub_sec
->relocation
,
1993 if (!stub_desc
->stub_sec
->relocation
)
1995 bfd_set_error (bfd_error_no_memory
);
1996 abort(); /* FIXME */
2000 rela_hdr
= &elf_section_data(stub_desc
->stub_sec
)->rel_hdr
;
2001 rela_hdr
->sh_size
+= sizeof(Elf32_External_Rela
);
2003 /* Fill in the details. */
2004 relent
.address
= offset
;
2006 relent
.sym_ptr_ptr
= (asymbol
**) bfd_zalloc (stub_desc
->this_bfd
, sizeof (asymbol
*));
2007 BFD_ASSERT (relent
.sym_ptr_ptr
); /* FIXME */
2009 relent
.sym_ptr_ptr
[0] = target_sym
;
2010 relent
.howto
= bfd_reloc_type_lookup (stub_desc
->this_bfd
, type
);
2012 /* Save it in the array of relocations for the stub section. */
2014 memcpy (&stub_desc
->stub_sec
->relocation
[stub_desc
->stub_sec
->reloc_count
++],
2020 hppa_elf_build_arg_reloc_stub (abfd
, output_bfd
, link_info
, reloc_entry
,
2021 stub_types
, rtn_adjust
, data
)
2024 struct bfd_link_info
*link_info
;
2025 arelent
*reloc_entry
;
2030 asection
*stub_sec
= bfd_get_section_by_name (abfd
, ".hppa_linker_stubs");
2031 elf32_hppa_stub_description
*stub_desc
= find_stubs (abfd
, stub_sec
);
2032 asymbol
*stub_sym
= NULL
;
2033 asymbol
*target_sym
= reloc_entry
->sym_ptr_ptr
[0];
2034 asection
*output_text_section
= bfd_get_section_by_name (output_bfd
, ".text");
2036 char stub_sym_name
[128];
2037 elf32_hppa_stub_name_list
*stub_entry
;
2038 unsigned insn
= data
[0];
2040 /* Perform some additional checks on whether we should really do the
2041 return adjustment. For example, if the instruction is nullified
2042 or if the delay slot contains an instruction that modifies the return
2043 pointer, then the branch instructions should not be rearranged
2044 (rtn_adjust is false). */
2045 if (insn
& 2 || insn
== 0)
2049 unsigned delay_insn
= data
[1];
2051 if (get_opcode (delay_insn
) == LDO
2052 && (((insn
& 0x03e00000) >> 21) == ((delay_insn
& 0x001f0000) >> 16)))
2056 /* See if the proper stub entry has already been made. */
2059 BFD_ASSERT (stub_desc
== NULL
);
2060 stub_sec
= bfd_make_section (abfd
, ".hppa_linker_stubs");
2061 bfd_set_section_flags (abfd
,
2063 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
2064 | SEC_RELOC
| SEC_CODE
| SEC_READONLY
);
2065 stub_sec
->output_section
= output_text_section
->output_section
;
2066 stub_sec
->output_offset
= 0;
2067 bfd_set_section_alignment (abfd
, stub_sec
, 2);
2068 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
2071 /* Make the stub if we did not find one already. */
2073 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
2075 /* Allocate space to write the stub.
2076 FIXME. Why using realloc?!? */
2077 if (!stub_desc
->stub_contents
)
2079 stub_desc
->allocated_size
= STUB_BUFFER_INCR
;
2080 stub_desc
->stub_contents
= (char *) malloc (STUB_BUFFER_INCR
);
2081 if (!stub_desc
->stub_contents
)
2083 bfd_set_error (bfd_error_no_memory
);
2087 else if ((stub_desc
->allocated_size
- stub_desc
->real_size
) < STUB_MAX_SIZE
)
2089 stub_desc
->allocated_size
= stub_desc
->allocated_size
+ STUB_BUFFER_INCR
;
2090 stub_desc
->stub_contents
= (char *) realloc (stub_desc
->stub_contents
,
2091 stub_desc
->allocated_size
);
2094 stub_desc
->stub_secp
2095 = (int *) (stub_desc
->stub_contents
+ stub_desc
->real_size
);
2097 sprintf (stub_sym_name
,
2098 "_stub_%s_%02d_%02d_%02d_%02d_%02d_%s",
2099 reloc_entry
->sym_ptr_ptr
[0]->name
,
2100 stub_types
[0], stub_types
[1], stub_types
[2],
2101 stub_types
[3], stub_types
[4],
2102 rtn_adjust
? "RA" : "");
2103 stub_entry
= find_stub_by_name (abfd
, stub_sec
, stub_sym_name
);
2107 stub_sym
= stub_entry
->sym
;
2108 /* Redirect the original relocation from the old symbol (a function)
2109 to the stub (the stub calls the function). Should we need to
2110 change the relocation type? */
2111 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (stub_desc
->this_bfd
,
2112 sizeof (asymbol
*));
2113 if (!reloc_entry
->sym_ptr_ptr
)
2115 bfd_set_error (bfd_error_no_memory
);
2118 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
2119 if (reloc_entry
->howto
->type
!= R_HPPA_PLABEL_32
2120 && (get_opcode(insn
) == BLE
2121 || get_opcode (insn
) == BE
2122 || get_opcode (insn
) == BL
))
2123 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_HPPA_STUB_CALL_17
);
2127 /* Create a new symbol to point to this stub. */
2128 stub_sym
= bfd_make_empty_symbol (abfd
);
2131 bfd_set_error (bfd_error_no_memory
);
2134 stub_sym
->name
= bfd_zalloc (abfd
, strlen (stub_sym_name
) + 1);
2135 if (!stub_sym
->name
)
2137 bfd_set_error (bfd_error_no_memory
);
2140 strcpy ((char *) stub_sym
->name
, stub_sym_name
);
2142 = (char *) stub_desc
->stub_secp
- (char *) stub_desc
->stub_contents
;
2143 stub_sym
->section
= stub_sec
;
2144 stub_sym
->flags
= BSF_LOCAL
| BSF_FUNCTION
;
2145 stub_entry
= add_stub_by_name (abfd
, stub_sec
, stub_sym
, link_info
);
2147 /* Redirect the original relocation from the old symbol (a function)
2148 to the stub (the stub calls the function). Change the type of
2149 relocation to be the internal use only stub R_HPPA_STUB_CALL_17. */
2150 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (stub_desc
->this_bfd
,
2151 sizeof (asymbol
*));
2152 if (!reloc_entry
->sym_ptr_ptr
)
2154 bfd_set_error (bfd_error_no_memory
);
2157 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
2158 if (reloc_entry
->howto
->type
!= R_HPPA_PLABEL_32
2159 && (get_opcode (insn
) == BLE
2160 || get_opcode (insn
) == BE
2161 || get_opcode (insn
) == BL
))
2162 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_HPPA_STUB_CALL_17
);
2164 /* Generate common code for all stubs. */
2166 NEW_INSTRUCTION (stub_entry
, LDSID_31_1
);
2167 NEW_INSTRUCTION (stub_entry
, MTSP_1_SR0
);
2168 NEW_INSTRUCTION (stub_entry
, ADDI_8_SP
);
2170 /* Generate code to move the arguments around. */
2171 for (i
= ARG0
; i
< ARG3
; i
++)
2173 if (stub_types
[i
] != NO_ARG_RELOC
)
2175 switch (stub_types
[i
])
2181 NEW_INSTRUCTION (stub_entry
, STWS_ARG0_M8SP
);
2182 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG0
);
2185 NEW_INSTRUCTION (stub_entry
, STWS_ARG1_M8SP
);
2186 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG1
);
2189 NEW_INSTRUCTION (stub_entry
, STWS_ARG2_M8SP
);
2190 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG2
);
2193 NEW_INSTRUCTION (stub_entry
, STWS_ARG3_M8SP
);
2194 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FARG3
);
2203 NEW_INSTRUCTION (stub_entry
, STWS_ARG0_M4SP
);
2204 NEW_INSTRUCTION (stub_entry
, STWS_ARG1_M8SP
);
2205 NEW_INSTRUCTION (stub_entry
, FLDDS_M8SP_FARG1
);
2208 AR_WARN (stub_types
[i
],i
);
2217 NEW_INSTRUCTION (stub_entry
, STWS_ARG2_M4SP
);
2218 NEW_INSTRUCTION (stub_entry
, STWS_ARG3_M8SP
);
2219 NEW_INSTRUCTION (stub_entry
, FLDDS_M8SP_FARG3
);
2222 AR_WARN (stub_types
[i
],i
);
2231 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG0_M8SP
);
2232 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG0
);
2235 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG1_M8SP
);
2236 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG1
);
2239 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG2_M8SP
);
2240 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG2
);
2243 NEW_INSTRUCTION (stub_entry
, FSTWS_FARG3_M8SP
);
2244 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG3
);
2253 NEW_INSTRUCTION (stub_entry
, FSTDS_FARG1_M8SP
);
2254 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG0
);
2255 NEW_INSTRUCTION (stub_entry
, LDWS_M8SP_ARG1
);
2258 AR_WARN (stub_types
[i
],i
);
2267 NEW_INSTRUCTION (stub_entry
, FSTDS_FARG3_M8SP
);
2268 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_ARG2
);
2269 NEW_INSTRUCTION (stub_entry
, LDWS_M8SP_ARG3
);
2272 AR_WARN (stub_types
[i
],i
);
2281 NEW_INSTRUCTION (stub_entry
, ADDI_M8_SP_SP
);
2283 /* Adjust the return address if necessary. */
2286 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_RP
);
2289 NEW_INSTRUCTION (stub_entry
, COPY_31_2
);
2291 /* Save the return address. */
2292 NEW_INSTRUCTION (stub_entry
, STW_RP_M8SP
);
2294 /* Long branch to the target function. */
2295 NEW_INSTRUCTION (stub_entry
, LDIL_XXX_31
);
2296 hppa_elf_stub_reloc (stub_entry
->stub_desc
,
2299 CURRENT_STUB_OFFSET (stub_entry
),
2301 NEW_INSTRUCTION (stub_entry
, BLE_XXX_0_31
);
2302 hppa_elf_stub_reloc (stub_entry
->stub_desc
,
2305 CURRENT_STUB_OFFSET (stub_entry
),
2306 R_HPPA_ABS_CALL_R17
);
2307 NEW_INSTRUCTION (stub_entry
, COPY_31_2
);
2310 /* Restore the return address. */
2311 NEW_INSTRUCTION (stub_entry
, LDW_M8SP_RP
);
2313 /* Generate the code to move the return value around. */
2315 if (stub_types
[i
] != NO_ARG_RELOC
)
2317 switch (stub_types
[i
])
2320 NEW_INSTRUCTION (stub_entry
, STWS_RET0_M8SP
);
2321 NEW_INSTRUCTION (stub_entry
, FLDWS_M8SP_FRET0
);
2325 NEW_INSTRUCTION (stub_entry
, FSTWS_FRET0_M8SP
);
2326 NEW_INSTRUCTION (stub_entry
, LDWS_M4SP_RET0
);
2330 NEW_INSTRUCTION (stub_entry
, BV_N_0_RP
);
2337 hppa_elf_arg_reloc_needed_p (abfd
, reloc_entry
, stub_types
, caller_ar
)
2339 arelent
*reloc_entry
;
2341 symext_entryS caller_ar
;
2343 /* If the symbol is still undefined, there is */
2344 /* no way to know if a stub is required. */
2346 if (reloc_entry
->sym_ptr_ptr
[0] && reloc_entry
->sym_ptr_ptr
[0]->section
!= &bfd_und_section
)
2348 symext_entryS callee_ar
= elf32_hppa_get_sym_extn (abfd
,
2349 reloc_entry
->sym_ptr_ptr
[0],
2350 HPPA_SXT_ARG_RELOC
);
2352 /* Now, determine if a stub is */
2353 /* required. A stub is required if they the callee and caller */
2354 /* argument relocation bits are both nonzero and not equal. */
2356 if (caller_ar
&& callee_ar
)
2358 /* Both are non-zero, we need to do further checking. */
2359 /* First, check if there is a return value relocation to be done */
2363 callee_loc
[RETVAL
] = EXTRACT_ARBITS (callee_ar
, RETVAL
);
2364 caller_loc
[RETVAL
] = EXTRACT_ARBITS (caller_ar
, RETVAL
);
2365 callee_loc
[ARG0
] = EXTRACT_ARBITS (callee_ar
, ARG0
);
2366 caller_loc
[ARG0
] = EXTRACT_ARBITS (caller_ar
, ARG0
);
2367 callee_loc
[ARG1
] = EXTRACT_ARBITS (callee_ar
, ARG1
);
2368 caller_loc
[ARG1
] = EXTRACT_ARBITS (caller_ar
, ARG1
);
2369 callee_loc
[ARG2
] = EXTRACT_ARBITS (callee_ar
, ARG2
);
2370 caller_loc
[ARG2
] = EXTRACT_ARBITS (caller_ar
, ARG2
);
2371 callee_loc
[ARG3
] = EXTRACT_ARBITS (callee_ar
, ARG3
);
2372 caller_loc
[ARG3
] = EXTRACT_ARBITS (caller_ar
, ARG3
);
2374 /* Check some special combinations. For */
2375 /* example, if FU appears in ARG1 or ARG3, we */
2376 /* can move it to ARG0 or ARG2, respectively. */
2378 if (caller_loc
[ARG0
] == AR_FU
|| caller_loc
[ARG1
] == AR_FU
)
2380 caller_loc
[ARG0
] = AR_DBL01
;
2381 caller_loc
[ARG1
] = AR_NO
;
2383 if (caller_loc
[ARG2
] == AR_FU
|| caller_loc
[ARG3
] == AR_FU
)
2385 caller_loc
[ARG2
] = AR_DBL23
;
2386 caller_loc
[ARG3
] = AR_NO
;
2388 if (callee_loc
[ARG0
] == AR_FU
|| callee_loc
[ARG1
] == AR_FU
)
2390 callee_loc
[ARG0
] = AR_DBL01
;
2391 callee_loc
[ARG1
] = AR_NO
;
2393 if (callee_loc
[ARG2
] == AR_FU
|| callee_loc
[ARG3
] == AR_FU
)
2395 callee_loc
[ARG2
] = AR_DBL23
;
2396 callee_loc
[ARG3
] = AR_NO
;
2399 stub_types
[ARG0
] = type_of_mismatch (caller_loc
[ARG0
], callee_loc
[ARG0
], ARGUMENTS
);
2400 stub_types
[ARG1
] = type_of_mismatch (caller_loc
[ARG1
], callee_loc
[ARG1
], ARGUMENTS
);
2401 stub_types
[ARG2
] = type_of_mismatch (caller_loc
[ARG2
], callee_loc
[ARG2
], ARGUMENTS
);
2402 stub_types
[ARG3
] = type_of_mismatch (caller_loc
[ARG3
], callee_loc
[ARG3
], ARGUMENTS
);
2403 stub_types
[RETVAL
] = type_of_mismatch (caller_loc
[RETVAL
], callee_loc
[RETVAL
], RETURN_VALUE
);
2405 /* Steps involved in building stubs: */
2406 /* 1. Determine what argument registers need to relocated. This */
2407 /* step is already done here. */
2408 /* 2. Build the appropriate stub in the .hppa_linker_stubs section. */
2409 /* This section should never appear in an object file. It is */
2410 /* only used internally. The output_section of the */
2411 /* .hppa_linker_stubs section is the .text section of the */
2413 /* 3. Build a symbol that is used (internally only) as the entry */
2414 /* point of the stub. */
2415 /* 4. Change the instruction of the original branch into a branch to */
2416 /* the stub routine. */
2417 /* 5. Build a relocation entry for the instruction of the original */
2418 /* branch to be R_HPPA_PCREL_CALL to the stub routine. */
2430 fprintf (stderr
, "Stub needed for %s @ %s+0x%x: callee/caller ar=0x%x/0x%x ",
2431 reloc_entry
->sym_ptr_ptr
[0]->name
,
2432 abfd
->filename
, reloc_entry
->address
,
2433 callee_ar
, caller_ar
);
2434 for (i
= ARG0
; i
< RETVAL
; i
++)
2436 if (stub_types
[i
] != NO_ARG_RELOC
)
2438 fprintf (stderr
, "%s%d: %s ",
2439 i
== RETVAL
? "ret" : "arg",
2440 i
== RETVAL
? 0 : i
,
2441 reloc_type_strings
[stub_types
[i
]]);
2444 fprintf (stderr
, "\n");
2455 hppa_elf_build_long_branch_stub (abfd
, output_bfd
, link_info
, reloc_entry
,
2459 struct bfd_link_info
*link_info
;
2460 arelent
*reloc_entry
;
2464 asection
*stub_sec
= bfd_get_section_by_name (abfd
, ".hppa_linker_stubs");
2465 elf32_hppa_stub_description
*stub_desc
= find_stubs (abfd
, stub_sec
);
2466 asymbol
*stub_sym
= NULL
;
2467 asymbol
*target_sym
= reloc_entry
->sym_ptr_ptr
[0];
2468 asection
*output_text_section
= bfd_get_section_by_name (output_bfd
, ".text");
2469 char stub_sym_name
[128];
2471 int dyncall
= false;
2472 elf32_hppa_stub_name_list
*stub_entry
;
2473 int rtn_adjust
= true;
2477 /* Create the stub section if it does not already exist. */
2480 BFD_ASSERT (stub_desc
== NULL
);
2481 stub_sec
= bfd_make_section (abfd
, ".hppa_linker_stubs");
2482 bfd_set_section_flags (abfd
,
2484 SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
2485 | SEC_RELOC
| SEC_CODE
| SEC_READONLY
);
2486 stub_sec
->output_section
= output_text_section
->output_section
;
2487 stub_sec
->output_offset
= 0;
2489 /* Set up the ELF section header for this new section. This
2490 is basically the same processing as elf_make_sections().
2491 elf_make_sections is static and therefore not accessable
2494 Elf_Internal_Shdr
*this_hdr
;
2495 this_hdr
= &elf_section_data (stub_sec
)->this_hdr
;
2497 /* Set the sizes of this section. The contents have already
2499 this_hdr
->sh_addr
= stub_sec
->vma
;
2500 this_hdr
->sh_size
= stub_sec
->_raw_size
;
2502 /* Set appropriate flags for sections with relocations. */
2503 if (stub_sec
->flags
& SEC_RELOC
)
2505 Elf_Internal_Shdr
*rela_hdr
;
2506 int use_rela_p
= get_elf_backend_data (abfd
)->use_rela_p
;
2508 rela_hdr
= &elf_section_data (stub_sec
)->rel_hdr
;
2512 rela_hdr
->sh_type
= SHT_RELA
;
2513 rela_hdr
->sh_entsize
= sizeof (Elf32_External_Rela
);
2517 rela_hdr
->sh_type
= SHT_REL
;
2518 rela_hdr
->sh_entsize
= sizeof (Elf32_External_Rel
);
2520 rela_hdr
->sh_flags
= 0;
2521 rela_hdr
->sh_addr
= 0;
2522 rela_hdr
->sh_offset
= 0;
2523 rela_hdr
->sh_addralign
= 0;
2527 if (stub_sec
->flags
& SEC_ALLOC
)
2529 this_hdr
->sh_flags
|= SHF_ALLOC
;
2530 /* FIXME. If SEC_LOAD is true should we do something with
2534 if (!(stub_sec
->flags
& SEC_READONLY
))
2535 this_hdr
->sh_flags
|= SHF_WRITE
;
2537 if (stub_sec
->flags
& SEC_CODE
)
2538 this_hdr
->sh_flags
|= SHF_EXECINSTR
;
2541 bfd_set_section_alignment (abfd
, stub_sec
, 2);
2542 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
2546 stub_desc
= new_stub (abfd
, stub_sec
, link_info
);
2548 /* Allocate memory to contain the stub. FIXME. Why isn't this using
2549 the BFD memory allocation routines? */
2550 if (!stub_desc
->stub_contents
)
2552 stub_desc
->allocated_size
= STUB_BUFFER_INCR
;
2553 stub_desc
->stub_contents
= (char *) malloc (STUB_BUFFER_INCR
);
2555 else if ((stub_desc
->allocated_size
- stub_desc
->real_size
) < STUB_MAX_SIZE
)
2557 stub_desc
->allocated_size
= stub_desc
->allocated_size
+ STUB_BUFFER_INCR
;
2558 stub_desc
->stub_contents
= (char *) realloc (stub_desc
->stub_contents
,
2559 stub_desc
->allocated_size
);
2562 stub_desc
->stub_secp
2563 = (int *) (stub_desc
->stub_contents
+ stub_desc
->real_size
);
2565 /* Is this a millicode call? If so, the return address
2566 comes in on r31 rather than r2 (rp) so a slightly
2567 different code sequence is needed. */
2570 rtn_reg
= (insn
& 0x03e00000) >> 21;
2574 if (strcmp (symbol
->name
, "$$dyncall") == 0)
2577 /* If we are creating a call from a stub to another stub, then
2578 never do the instruction reordering. We can tell if we are
2579 going to be calling one stub from another by the fact that
2580 the symbol name has '_stub_' (arg. reloc. stub) or '_lb_stub_'
2581 prepended to the name. Alternatively, the section of the
2582 symbol will be '.hppa_linker_stubs'. */
2584 if ((strncmp (symbol
->name
, "_stub_", 6) == 0)
2585 || (strncmp (symbol
->name
, "_lb_stub_", 9) == 0))
2587 BFD_ASSERT (strcmp (symbol
->section
->name
, ".hppa_linker_stubs") == 0);
2591 /* Check to see if we modify the return pointer
2592 in the delay slot of the branch. */
2594 unsigned delay_insn
= data
[1];
2596 /* If we nullify the delay slot, or if the delay slot contains an
2597 instruction that modifies the return pointer, then no additional
2598 modification of the return pointer is necessary. */
2599 if (insn
& 2 || insn
== 0)
2603 if (get_opcode (delay_insn
) == LDO
2604 && (((delay_insn
& 0x001f0000) >> 16) == rtn_reg
))
2611 sprintf (stub_sym_name
,
2612 "_lb_stub_%s_%s", reloc_entry
->sym_ptr_ptr
[0]->name
,
2613 rtn_adjust
? "RA" : "");
2614 stub_entry
= find_stub_by_name(abfd
, stub_sec
, stub_sym_name
);
2616 /* If a copy of this stub already exists re-use it. */
2619 stub_sym
= stub_entry
->sym
;
2621 /* Change symbol associated with the original relocation to point
2624 FIXME. Is there a need to change the relocation type too? */
2625 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (stub_desc
->this_bfd
,
2626 sizeof (asymbol
*));
2627 if (!reloc_entry
->sym_ptr_ptr
)
2629 bfd_set_error (bfd_error_no_memory
);
2632 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
2633 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_HPPA_STUB_CALL_17
);
2637 /* We will need to allocate a new stub. */
2638 stub_sym
= bfd_make_empty_symbol (abfd
);
2641 bfd_set_error (bfd_error_no_memory
);
2644 stub_sym
->name
= bfd_zalloc (abfd
, strlen (stub_sym_name
) + 1);
2645 if (!stub_sym
->name
)
2647 bfd_set_error (bfd_error_no_memory
);
2650 strcpy ((char *) stub_sym
->name
, stub_sym_name
);
2652 = (char *) stub_desc
->stub_secp
- (char *) stub_desc
->stub_contents
;
2653 stub_sym
->section
= stub_sec
;
2654 stub_sym
->flags
= BSF_LOCAL
| BSF_FUNCTION
;
2655 stub_entry
= add_stub_by_name (abfd
, stub_sec
, stub_sym
, link_info
);
2657 /* Change symbol associated with the original relocation to point
2660 FIXME. Is there a need to change the relocation type too? */
2661 reloc_entry
->sym_ptr_ptr
= (asymbol
**) bfd_zalloc (stub_desc
->this_bfd
,
2662 sizeof (asymbol
*));
2663 if (!reloc_entry
->sym_ptr_ptr
)
2665 bfd_set_error (bfd_error_no_memory
);
2668 reloc_entry
->sym_ptr_ptr
[0] = stub_sym
;
2669 reloc_entry
->howto
= bfd_reloc_type_lookup (abfd
, R_HPPA_STUB_CALL_17
);
2671 /* Build the stub. */
2673 /* 1. initialization for the call. */
2674 NEW_INSTRUCTION (stub_entry
, LDSID_31_1
);
2675 NEW_INSTRUCTION (stub_entry
, MTSP_1_SR0
);
2683 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_RP
);
2687 NEW_INSTRUCTION (stub_entry
, COPY_31_2
);
2694 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_1
);
2698 NEW_INSTRUCTION (stub_entry
, COPY_31_1
);
2702 NEW_INSTRUCTION (stub_entry
, LDIL_XXX_31
);
2703 hppa_elf_stub_reloc (stub_desc
,
2706 CURRENT_STUB_OFFSET (stub_entry
),
2709 /* 2. Make the call. */
2712 NEW_INSTRUCTION (stub_entry
, BE_XXX_0_31
);
2713 hppa_elf_stub_reloc (stub_desc
,
2716 CURRENT_STUB_OFFSET (stub_entry
),
2717 R_HPPA_ABS_CALL_R17
);
2718 NEW_INSTRUCTION (stub_entry
, COPY_2_31
);
2722 NEW_INSTRUCTION (stub_entry
, BE_XXX_0_31
);
2723 hppa_elf_stub_reloc (stub_desc
,
2726 CURRENT_STUB_OFFSET (stub_entry
),
2727 R_HPPA_ABS_CALL_R17
);
2728 NEW_INSTRUCTION (stub_entry
, COPY_1_31
);
2733 /* 3. Branch back to the original location.
2734 (For non-millicode calls, this is accomplished with the
2735 COPY_31_2 instruction. For millicode calls, the return
2736 location is already in r2.) */
2739 NEW_INSTRUCTION (stub_entry
, ADDI_M4_31_RP
);
2741 NEW_INSTRUCTION (stub_entry
, LDIL_XXX_31
);
2742 hppa_elf_stub_reloc (stub_desc
,
2745 CURRENT_STUB_OFFSET (stub_entry
),
2748 NEW_INSTRUCTION (stub_entry
, BE_XXX_0_31
);
2749 hppa_elf_stub_reloc (stub_desc
,
2752 CURRENT_STUB_OFFSET (stub_entry
),
2753 R_HPPA_ABS_CALL_R17
);
2754 NEW_INSTRUCTION (stub_entry
, COPY_2_31
);
2761 hppa_elf_long_branch_needed_p (abfd
, asec
, reloc_entry
, symbol
, insn
)
2764 arelent
*reloc_entry
;
2768 long sym_value
= get_symbol_value(symbol
);
2769 int fmt
= reloc_entry
->howto
->bitsize
;
2770 unsigned char op
= get_opcode(insn
);
2773 #define too_far(val,num_bits) ((int)(val) > (1<<(num_bits))-1) || ((int)(val) < (-1<<(num_bits)))
2779 reloc_entry
->address
+ asec
->output_offset
+ asec
->output_section
->vma
;
2780 if (too_far(sym_value
- raddr
,fmt
+1))
2783 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
);
2792 #define STUB_SYM_BUFFER_INC 5
2795 hppa_look_for_stubs_in_section (stub_bfd
, abfd
, output_bfd
, asec
,
2796 syms
, new_sym_cnt
, link_info
)
2803 struct bfd_link_info
*link_info
;
2807 asymbol
*new_syms
= (asymbol
*) NULL
;
2811 /* Relocations are in different places depending on whether this is
2812 an output section or an input section. Also, the relocations are
2813 in different forms. Sigh. Luckily, we have
2814 bfd_canonicalize_reloc() to straighten this out for us . */
2816 if (asec
->reloc_count
> 0)
2818 arelent
**reloc_vector
2819 = (arelent
**) alloca (asec
->reloc_count
* (sizeof (arelent
*) + 1));
2821 bfd_canonicalize_reloc (abfd
, asec
, reloc_vector
, syms
);
2822 for (i
= 0; i
< asec
->reloc_count
; i
++)
2824 arelent
*rle
= reloc_vector
[i
];
2826 switch (rle
->howto
->type
)
2828 case R_HPPA_ABS_CALL_11
:
2829 case R_HPPA_ABS_CALL_14
:
2830 case R_HPPA_ABS_CALL_17
:
2831 case R_HPPA_ABS_CALL_L21
:
2832 case R_HPPA_ABS_CALL_R11
:
2833 case R_HPPA_ABS_CALL_R14
:
2834 case R_HPPA_ABS_CALL_R17
:
2835 case R_HPPA_ABS_CALL_LS21
:
2836 case R_HPPA_ABS_CALL_RS11
:
2837 case R_HPPA_ABS_CALL_RS14
:
2838 case R_HPPA_ABS_CALL_RS17
:
2839 case R_HPPA_ABS_CALL_LD21
:
2840 case R_HPPA_ABS_CALL_RD11
:
2841 case R_HPPA_ABS_CALL_RD14
:
2842 case R_HPPA_ABS_CALL_RD17
:
2843 case R_HPPA_ABS_CALL_LR21
:
2844 case R_HPPA_ABS_CALL_RR14
:
2845 case R_HPPA_ABS_CALL_RR17
:
2846 case R_HPPA_PCREL_CALL_11
:
2847 case R_HPPA_PCREL_CALL_14
:
2848 case R_HPPA_PCREL_CALL_17
:
2849 case R_HPPA_PCREL_CALL_12
:
2850 case R_HPPA_PCREL_CALL_L21
:
2851 case R_HPPA_PCREL_CALL_R11
:
2852 case R_HPPA_PCREL_CALL_R14
:
2853 case R_HPPA_PCREL_CALL_R17
:
2854 case R_HPPA_PCREL_CALL_LS21
:
2855 case R_HPPA_PCREL_CALL_RS11
:
2856 case R_HPPA_PCREL_CALL_RS14
:
2857 case R_HPPA_PCREL_CALL_RS17
:
2858 case R_HPPA_PCREL_CALL_LD21
:
2859 case R_HPPA_PCREL_CALL_RD11
:
2860 case R_HPPA_PCREL_CALL_RD14
:
2861 case R_HPPA_PCREL_CALL_RD17
:
2862 case R_HPPA_PCREL_CALL_LR21
:
2863 case R_HPPA_PCREL_CALL_RR14
:
2864 case R_HPPA_PCREL_CALL_RR17
:
2866 symext_entryS caller_ar
2867 = (symext_entryS
) HPPA_R_ARG_RELOC (rle
->addend
);
2870 bfd_get_section_contents (abfd
, asec
, insn
, rle
->address
,
2872 if (hppa_elf_arg_reloc_needed_p (abfd
, rle
, stub_types
,
2875 /* Generate a stub and keep track of the new symbol. */
2878 if (new_cnt
== new_max
)
2880 new_max
+= STUB_SYM_BUFFER_INC
;
2881 new_syms
= (asymbol
*)
2882 realloc (new_syms
, new_max
* sizeof (asymbol
));
2885 /* The rtn_adjust argument is true here because we
2886 know that we have a branch and (with a few exceptions
2887 detailed under the relocation code for relocation type
2888 R_HPPA_STUB_CALL_17) it will be possible to perform
2889 the code reorientation. */
2890 r
= hppa_elf_build_arg_reloc_stub (stub_bfd
, output_bfd
,
2894 new_syms
[new_cnt
++] = *r
;
2897 /* We need to retrieve the section contents to check for
2898 long branch stubs. */
2899 if (hppa_elf_long_branch_needed_p (abfd
, asec
, rle
,
2900 rle
->sym_ptr_ptr
[0],
2903 /* Generate a stub and keep track of the new symbol. */
2906 if (new_cnt
== new_max
)
2908 new_max
+= STUB_SYM_BUFFER_INC
;
2909 new_syms
= (asymbol
*)
2910 realloc (new_syms
, (new_max
* sizeof (asymbol
)));
2912 r
= hppa_elf_build_long_branch_stub (stub_bfd
, output_bfd
,
2914 rle
->sym_ptr_ptr
[0],
2916 new_syms
[new_cnt
++] = *r
;
2921 case R_HPPA_PLABEL_32
:
2922 case R_HPPA_PLABEL_11
:
2923 case R_HPPA_PLABEL_14
:
2924 case R_HPPA_PLABEL_L21
:
2925 case R_HPPA_PLABEL_R11
:
2926 case R_HPPA_PLABEL_R14
:
2928 /* On a plabel relocation, assume the arguments of the
2929 caller are set up in general registers.
2930 NOTE: 0x155 = ARGW0=CR,ARGW1=GR,ARGW2=GR,RETVAL=GR */
2931 symext_entryS caller_ar
= (symext_entryS
) 0x155;
2934 bfd_get_section_contents (abfd
, asec
, insn
, rle
->address
,
2937 if (hppa_elf_arg_reloc_needed_p (abfd
, rle
, stub_types
,
2940 /* Generate a plabel stub and keep track of the
2945 if (new_cnt
== new_max
)
2947 new_max
+= STUB_SYM_BUFFER_INC
;
2948 new_syms
= (asymbol
*) realloc (new_syms
, new_max
2949 * sizeof (asymbol
));
2952 /* Determine whether a return adjustment
2953 (see the relocation code for relocation type
2954 R_HPPA_STUB_CALL_17) is possible. Basically,
2955 determine whether we are looking at a branch or not. */
2957 if (rle
->howto
->type
== R_HPPA_PLABEL_32
)
2961 switch (get_opcode(insn
[0]))
2971 r
= hppa_elf_build_arg_reloc_stub (stub_bfd
, output_bfd
,
2975 new_syms
[new_cnt
++] = *r
;
2986 *new_sym_cnt
= new_cnt
;
2991 char *linker_stubs
= NULL
;
2992 int linker_stubs_size
= 0;
2993 int linker_stubs_max_size
= 0;
2994 #define STUB_ALLOC_INCR 100
2997 hppa_elf_set_section_contents (abfd
, section
, location
, offset
, count
)
3002 bfd_size_type count
;
3004 if (strcmp(section
->name
, ".hppa_linker_stubs") == 0)
3006 if (linker_stubs_max_size
< offset
+ count
)
3008 linker_stubs_max_size
= offset
+ count
+ STUB_ALLOC_INCR
;
3009 linker_stubs
= (char *)realloc(linker_stubs
, linker_stubs_max_size
);
3012 if (offset
+ count
> linker_stubs_size
)
3013 linker_stubs_size
= offset
+ count
;
3015 memcpy(linker_stubs
+ offset
,location
,count
);
3019 return bfd_elf32_set_section_contents (abfd
, section
, location
,
3023 /* Get the contents of the given section.
3025 This is special for PA ELF because some sections (such as linker stubs)
3026 may reside in memory rather than on disk, or in the case of the symbol
3027 extension section, the contents may need to be generated from other
3028 information contained in the BFD. */
3031 hppa_elf_get_section_contents (abfd
, section
, location
, offset
, count
)
3036 bfd_size_type count
;
3038 /* If this is the linker stub section, then its contents are contained
3039 in memory rather than on disk. FIXME. Is that always right? What
3040 about the case where a final executable is read in and a user tries
3041 to get the contents of this section? In that case the contents would
3042 be on disk like everything else. */
3043 if (strcmp (section
->name
, ".hppa_linker_stubs") == 0)
3045 elf32_hppa_stub_description
*stub_desc
= find_stubs (abfd
, section
);
3050 /* Sanity check our arguments. */
3051 if ((bfd_size_type
) (offset
+ count
) > section
->_raw_size
3052 || (bfd_size_type
) (offset
+ count
) > stub_desc
->real_size
)
3055 memcpy (location
, stub_desc
->stub_contents
+ offset
, count
);
3059 /* The symbol extension section also needs special handling. Its
3060 contents might be on the disk, in memory, or still need to
3062 else if (strcmp (section
->name
, ".hppa_symextn") == 0)
3064 /* If there are no output sections, then read the contents of the
3065 symbol extension section from disk. */
3066 if (section
->output_section
== NULL
3067 && abfd
->direction
== read_direction
)
3069 return bfd_generic_get_section_contents (abfd
, section
, location
,
3073 /* If this is the first time through, and there are output sections,
3074 then build the symbol extension section based on other information
3075 contained in the BFD. */
3076 else if (! symext_chain_built
)
3080 (int *) elf_sym_extra(section
->output_section
->owner
);
3082 for (i
= 0; i
< section
->output_section
->owner
->symcount
; i
++)
3084 elf_hppa_tc_symbol(section
->output_section
->owner
,
3085 ((elf_symbol_type
*)
3086 section
->output_section
->owner
->outsymbols
[i
]),
3087 symtab_map
[i
], &symext_rootP
, &symext_lastP
);
3089 symext_chain_built
++;
3090 elf_hppa_tc_make_sections (section
->output_section
->owner
,
3094 /* At this point we know that the symbol extension section has been
3095 built. We just need to copy it into the user's buffer. */
3099 /* Sanity check our arguments. */
3100 if ((bfd_size_type
) (offset
+ count
) > section
->_raw_size
3101 || (bfd_size_type
) (offset
+ count
) > symextn_contents_real_size
)
3105 ((char *)symextn_contents
+ section
->output_offset
+ offset
),
3110 return bfd_generic_get_section_contents (abfd
, section
, location
,
3115 elf_info_to_howto (abfd
, cache_ptr
, dst
)
3118 Elf32_Internal_Rela
*dst
;
3120 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_HPPA_UNIMPLEMENTED
);
3121 cache_ptr
->howto
= &elf_hppa_howto_table
[ELF32_R_TYPE(dst
->r_info
)];
3125 elf32_hppa_backend_symbol_processing (abfd
, sym
)
3129 /* Is this a definition of $global$? If so, keep it because it will be
3130 needed if any relocations are performed. */
3132 if (!strcmp (sym
->name
, "$global$")
3133 && sym
->section
!= &bfd_und_section
)
3135 global_symbol
= sym
;
3139 #define elf_backend_symbol_processing elf32_hppa_backend_symbol_processing
3141 struct elf32_hppa_symextn_map_struct
3149 static struct elf32_hppa_symextn_map_struct
*elf32_hppa_symextn_map
;
3150 static int elf32_hppa_symextn_map_size
;
3153 elf32_hppa_backend_symbol_table_processing (abfd
, esyms
,symcnt
)
3155 elf_symbol_type
*esyms
;
3158 Elf32_Internal_Shdr
*symextn_hdr
= bfd_elf_find_section (abfd
, SYMEXTN_SECTION_NAME
);
3160 int current_sym_idx
= 0;
3162 /* If the symbol extension section does not exist, all the symbol */
3163 /* all the symbol extension information is assumed to be zero. */
3165 if (symextn_hdr
== NULL
)
3167 for (i
= 0; i
< symcnt
; i
++)
3169 esyms
[i
].tc_data
.hppa_arg_reloc
= 0;
3174 /* allocate a buffer of the appropriate size for the symextn section */
3176 symextn_hdr
->contents
= bfd_zalloc(abfd
,symextn_hdr
->sh_size
);
3177 if (!symextn_hdr
->contents
)
3179 bfd_set_error (bfd_error_no_memory
);
3182 symextn_hdr
->size
= symextn_hdr
->sh_size
;
3184 /* read in the symextn section */
3186 if (bfd_seek (abfd
, symextn_hdr
->sh_offset
, SEEK_SET
) == -1)
3188 bfd_set_error (bfd_error_system_call
);
3191 if (bfd_read ((PTR
) symextn_hdr
->contents
, 1, symextn_hdr
->size
, abfd
)
3192 != symextn_hdr
->size
)
3194 free ((PTR
)symextn_hdr
->contents
);
3195 bfd_set_error (bfd_error_system_call
);
3199 /* parse the entries, updating the symtab entries as we go */
3201 for (i
= 0; i
< symextn_hdr
->size
/ sizeof(symext_entryS
); i
++)
3203 symext_entryS
*seP
= ((symext_entryS
*)symextn_hdr
->contents
) + i
;
3204 int se_value
= ELF32_HPPA_SX_VAL(*seP
);
3205 int se_type
= ELF32_HPPA_SX_TYPE(*seP
);
3212 case HPPA_SXT_SYMNDX
:
3213 if (se_value
>= symcnt
)
3215 bfd_set_error (bfd_error_bad_value
);
3216 bfd_perror("elf32_hppa_backend_symbol_table_processing -- symbol index");
3219 current_sym_idx
= se_value
- 1;
3222 case HPPA_SXT_ARG_RELOC
:
3223 esyms
[current_sym_idx
].tc_data
.hppa_arg_reloc
= se_value
;
3227 bfd_set_error (bfd_error_bad_value
);
3228 bfd_perror("elf32_hppa_backend_symbol_table_processing");
3235 #define elf_backend_symbol_table_processing elf32_hppa_backend_symbol_table_processing
3238 elf32_hppa_backend_section_processing (abfd
, secthdr
)
3240 Elf32_Internal_Shdr
*secthdr
;
3244 if (secthdr
->sh_type
== SHT_HPPA_SYMEXTN
)
3246 for (i
= 0; i
< secthdr
->size
/ sizeof(symext_entryS
); i
++)
3248 symext_entryS
*seP
= ((symext_entryS
*)secthdr
->contents
) + i
;
3249 int se_value
= ELF32_HPPA_SX_VAL(*seP
);
3250 int se_type
= ELF32_HPPA_SX_TYPE(*seP
);
3257 case HPPA_SXT_SYMNDX
:
3258 for (j
= 0; j
< abfd
->symcount
; j
++)
3260 /* locate the map entry for this symbol, if there is one. */
3261 /* modify the symbol extension section symbol index entry */
3262 /* to reflect the new symbol table index */
3264 for (k
= 0; k
< elf32_hppa_symextn_map_size
; k
++)
3266 if (elf32_hppa_symextn_map
[k
].old_index
== se_value
3267 && elf32_hppa_symextn_map
[k
].bfd
== abfd
->outsymbols
[j
]->the_bfd
3268 && elf32_hppa_symextn_map
[k
].sym
== abfd
->outsymbols
[j
])
3271 ELF32_HPPA_SX_WORD (HPPA_SXT_SYMNDX
, j
),
3278 case HPPA_SXT_ARG_RELOC
:
3282 bfd_set_error (bfd_error_bad_value
);
3283 bfd_perror("elf32_hppa_backend_section_processing");
3291 #define elf_backend_section_processing elf32_hppa_backend_section_processing
3294 elf32_hppa_backend_section_from_shdr (abfd
, hdr
, name
)
3296 Elf32_Internal_Shdr
*hdr
;
3301 if (hdr
->sh_type
== SHT_HPPA_SYMEXTN
)
3303 BFD_ASSERT (strcmp(name
,".hppa_symextn") == 0);
3305 /* Bits that get saved. This one is real. */
3308 newsect
= bfd_make_section (abfd
, name
);
3309 if (newsect
!= NULL
)
3311 newsect
->vma
= hdr
->sh_addr
;
3312 newsect
->_raw_size
= hdr
->sh_size
;
3313 newsect
->filepos
= hdr
->sh_offset
; /* so we can read back the bits */
3314 newsect
->flags
|= SEC_HAS_CONTENTS
;
3315 newsect
->alignment_power
= hdr
->sh_addralign
;
3317 if (hdr
->sh_flags
& SHF_ALLOC
)
3319 newsect
->flags
|= SEC_ALLOC
;
3320 newsect
->flags
|= SEC_LOAD
;
3323 if (!(hdr
->sh_flags
& SHF_WRITE
))
3324 newsect
->flags
|= SEC_READONLY
;
3326 if (hdr
->sh_flags
& SHF_EXECINSTR
)
3327 newsect
->flags
|= SEC_CODE
; /* FIXME: may only contain SOME code */
3329 newsect
->flags
|= SEC_DATA
;
3331 hdr
->rawdata
= (void *) newsect
;
3339 #define elf_backend_section_from_shdr elf32_hppa_backend_section_from_shdr
3342 elf32_hppa_backend_fake_sections (abfd
, secthdr
, asect
)
3344 Elf_Internal_Shdr
*secthdr
;
3348 if (strcmp(asect
->name
, ".hppa_symextn") == 0)
3350 secthdr
->sh_type
= SHT_HPPA_SYMEXTN
;
3351 secthdr
->sh_flags
= 0;
3352 secthdr
->sh_info
= elf_section_data(asect
)->rel_hdr
.sh_link
;
3353 secthdr
->sh_link
= elf_onesymtab(abfd
);
3357 if (!strcmp (asect
->name
, ".hppa_unwind"))
3359 secthdr
->sh_type
= SHT_PROGBITS
;
3360 /* Unwind descriptors are not part of the program memory image. */
3361 secthdr
->sh_flags
= 0;
3362 secthdr
->sh_info
= 0;
3363 secthdr
->sh_link
= 0;
3364 secthdr
->sh_entsize
= 16;
3368 /* @@ Should this be CPU specific?? KR */
3369 if (!strcmp (asect
->name
, ".stabstr"))
3371 secthdr
->sh_type
= SHT_STRTAB
;
3372 secthdr
->sh_flags
= 0;
3373 secthdr
->sh_info
= 0;
3374 secthdr
->sh_link
= 0;
3375 secthdr
->sh_entsize
= 0;
3382 #define elf_backend_fake_sections elf32_hppa_backend_fake_sections
3385 elf32_hppa_backend_section_from_bfd_section (abfd
, hdr
, asect
, retval
)
3387 Elf32_Internal_Shdr
*hdr
;
3391 if (hdr
->sh_type
== SHT_HPPA_SYMEXTN
)
3395 if (((struct sec
*) (hdr
->rawdata
)) == asect
)
3397 BFD_ASSERT (strcmp(asect
->name
, ".hppa_symextn") == 0);
3402 else if (hdr
->sh_type
== SHT_STRTAB
)
3406 if (((struct sec
*) (hdr
->rawdata
)) == asect
)
3408 BFD_ASSERT (strcmp (asect
->name
, ".stabstr") == 0);
3417 #define bfd_elf32_bfd_reloc_type_lookup elf_hppa_reloc_type_lookup
3418 #define elf_backend_section_from_bfd_section elf32_hppa_backend_section_from_bfd_section
3420 #define bfd_generic_get_section_contents hppa_elf_get_section_contents
3421 #define bfd_elf32_set_section_contents hppa_elf_set_section_contents
3423 #define TARGET_BIG_SYM bfd_elf32_hppa_vec
3424 #define TARGET_BIG_NAME "elf32-hppa"
3425 #define ELF_ARCH bfd_arch_hppa
3426 #define ELF_MACHINE_CODE EM_HPPA
3427 #define ELF_MAXPAGESIZE 0x1000
3429 #include "elf32-target.h"