Coverage Report

Created: 2023-08-28 06:26

/src/binutils-gdb/bfd/elf64-s390.c
Line
Count
Source (jump to first uncovered line)
1
/* IBM S/390-specific support for 64-bit ELF
2
   Copyright (C) 2000-2023 Free Software Foundation, Inc.
3
   Contributed Martin Schwidefsky (schwidefsky@de.ibm.com).
4
5
   This file is part of BFD, the Binary File Descriptor library.
6
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License as published by
9
   the Free Software Foundation; either version 3 of the License, or
10
   (at your option) any later version.
11
12
   This program is distributed in the hope that it will be useful,
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
   GNU General Public License for more details.
16
17
   You should have received a copy of the GNU General Public License
18
   along with this program; if not, write to the Free Software
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
20
   02110-1301, USA.  */
21
22
#include "sysdep.h"
23
#include "bfd.h"
24
#include "bfdlink.h"
25
#include "libbfd.h"
26
#include "elf-bfd.h"
27
#include "elf/s390.h"
28
#include "elf-s390.h"
29
#include <stdarg.h>
30
31
/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
32
   from smaller values.  Start with zero, widen, *then* decrement.  */
33
#define MINUS_ONE      (((bfd_vma)0) - 1)
34
35
static bfd_reloc_status_type
36
s390_tls_reloc (bfd *, arelent *, asymbol *, void *,
37
    asection *, bfd *, char **);
38
static bfd_reloc_status_type
39
s390_elf_ldisp_reloc (bfd *, arelent *, asymbol *, void *,
40
          asection *, bfd *, char **);
41
42
/* The relocation "howto" table.  */
43
static reloc_howto_type elf_howto_table[] =
44
{
45
  HOWTO (R_390_NONE,    /* type */
46
   0,     /* rightshift */
47
   0,     /* size */
48
   0,     /* bitsize */
49
   false,     /* pc_relative */
50
   0,     /* bitpos */
51
   complain_overflow_dont, /* complain_on_overflow */
52
   bfd_elf_generic_reloc, /* special_function */
53
   "R_390_NONE",    /* name */
54
   false,     /* partial_inplace */
55
   0,     /* src_mask */
56
   0,     /* dst_mask */
57
   false),    /* pcrel_offset */
58
59
  HOWTO(R_390_8,   0, 1,  8, false, 0, complain_overflow_bitfield,
60
  bfd_elf_generic_reloc, "R_390_8",  false, 0,0x000000ff, false),
61
  HOWTO(R_390_12,  0, 2, 12, false, 0, complain_overflow_dont,
62
  bfd_elf_generic_reloc, "R_390_12",   false, 0,0x00000fff, false),
63
  HOWTO(R_390_16,  0, 2, 16, false, 0, complain_overflow_bitfield,
64
  bfd_elf_generic_reloc, "R_390_16",   false, 0,0x0000ffff, false),
65
  HOWTO(R_390_32,  0, 4, 32, false, 0, complain_overflow_bitfield,
66
  bfd_elf_generic_reloc, "R_390_32",   false, 0,0xffffffff, false),
67
  HOWTO(R_390_PC32,  0, 4, 32,  true, 0, complain_overflow_bitfield,
68
  bfd_elf_generic_reloc, "R_390_PC32",   false, 0,0xffffffff, true),
69
  HOWTO(R_390_GOT12,   0, 2, 12, false, 0, complain_overflow_bitfield,
70
  bfd_elf_generic_reloc, "R_390_GOT12",  false, 0,0x00000fff, false),
71
  HOWTO(R_390_GOT32,   0, 4, 32, false, 0, complain_overflow_bitfield,
72
  bfd_elf_generic_reloc, "R_390_GOT32",  false, 0,0xffffffff, false),
73
  HOWTO(R_390_PLT32,   0, 4, 32,  true, 0, complain_overflow_bitfield,
74
  bfd_elf_generic_reloc, "R_390_PLT32",  false, 0,0xffffffff, true),
75
  HOWTO(R_390_COPY,  0, 8, 64, false, 0, complain_overflow_bitfield,
76
  bfd_elf_generic_reloc, "R_390_COPY",   false, 0,MINUS_ONE,  false),
77
  HOWTO(R_390_GLOB_DAT,  0, 8, 64, false, 0, complain_overflow_bitfield,
78
  bfd_elf_generic_reloc, "R_390_GLOB_DAT", false, 0,MINUS_ONE,  false),
79
  HOWTO(R_390_JMP_SLOT,  0, 8, 64, false, 0, complain_overflow_bitfield,
80
  bfd_elf_generic_reloc, "R_390_JMP_SLOT", false, 0,MINUS_ONE,  false),
81
  HOWTO(R_390_RELATIVE,  0, 8, 64,  true, 0, complain_overflow_bitfield,
82
  bfd_elf_generic_reloc, "R_390_RELATIVE", false, 0,MINUS_ONE,  false),
83
  HOWTO(R_390_GOTOFF32,  0, 4, 32, false, 0, complain_overflow_bitfield,
84
  bfd_elf_generic_reloc, "R_390_GOTOFF32", false, 0,MINUS_ONE,  false),
85
  HOWTO(R_390_GOTPC,   0, 8, 64,  true, 0, complain_overflow_bitfield,
86
  bfd_elf_generic_reloc, "R_390_GOTPC",  false, 0,MINUS_ONE,  true),
87
  HOWTO(R_390_GOT16,   0, 2, 16, false, 0, complain_overflow_bitfield,
88
  bfd_elf_generic_reloc, "R_390_GOT16",  false, 0,0x0000ffff, false),
89
  HOWTO(R_390_PC16,  0, 2, 16,  true, 0, complain_overflow_bitfield,
90
  bfd_elf_generic_reloc, "R_390_PC16",   false, 0,0x0000ffff, true),
91
  HOWTO(R_390_PC16DBL,   1, 2, 16,  true, 0, complain_overflow_bitfield,
92
  bfd_elf_generic_reloc, "R_390_PC16DBL",  false, 0,0x0000ffff, true),
93
  HOWTO(R_390_PLT16DBL,  1, 2, 16,  true, 0, complain_overflow_bitfield,
94
  bfd_elf_generic_reloc, "R_390_PLT16DBL", false, 0,0x0000ffff, true),
95
  HOWTO(R_390_PC32DBL,   1, 4, 32,  true, 0, complain_overflow_bitfield,
96
  bfd_elf_generic_reloc, "R_390_PC32DBL",  false, 0,0xffffffff, true),
97
  HOWTO(R_390_PLT32DBL,  1, 4, 32,  true, 0, complain_overflow_bitfield,
98
  bfd_elf_generic_reloc, "R_390_PLT32DBL", false, 0,0xffffffff, true),
99
  HOWTO(R_390_GOTPCDBL,  1, 4, 32,  true, 0, complain_overflow_bitfield,
100
  bfd_elf_generic_reloc, "R_390_GOTPCDBL", false, 0,MINUS_ONE,  true),
101
  HOWTO(R_390_64,  0, 8, 64, false, 0, complain_overflow_bitfield,
102
  bfd_elf_generic_reloc, "R_390_64",   false, 0,MINUS_ONE,  false),
103
  HOWTO(R_390_PC64,  0, 8, 64,  true, 0, complain_overflow_bitfield,
104
  bfd_elf_generic_reloc, "R_390_PC64",   false, 0,MINUS_ONE,  true),
105
  HOWTO(R_390_GOT64,   0, 8, 64, false, 0, complain_overflow_bitfield,
106
  bfd_elf_generic_reloc, "R_390_GOT64",  false, 0,MINUS_ONE,  false),
107
  HOWTO(R_390_PLT64,   0, 8, 64,  true, 0, complain_overflow_bitfield,
108
  bfd_elf_generic_reloc, "R_390_PLT64",  false, 0,MINUS_ONE,  true),
109
  HOWTO(R_390_GOTENT,  1, 4, 32,  true, 0, complain_overflow_bitfield,
110
  bfd_elf_generic_reloc, "R_390_GOTENT",   false, 0,MINUS_ONE,  true),
111
  HOWTO(R_390_GOTOFF16,  0, 2, 16, false, 0, complain_overflow_bitfield,
112
  bfd_elf_generic_reloc, "R_390_GOTOFF16", false, 0,0x0000ffff, false),
113
  HOWTO(R_390_GOTOFF64,  0, 8, 64, false, 0, complain_overflow_bitfield,
114
  bfd_elf_generic_reloc, "R_390_GOTOFF64", false, 0,MINUS_ONE,  false),
115
  HOWTO(R_390_GOTPLT12,  0, 2, 12, false, 0, complain_overflow_dont,
116
  bfd_elf_generic_reloc, "R_390_GOTPLT12", false, 0,0x00000fff, false),
117
  HOWTO(R_390_GOTPLT16,  0, 2, 16, false, 0, complain_overflow_bitfield,
118
  bfd_elf_generic_reloc, "R_390_GOTPLT16", false, 0,0x0000ffff, false),
119
  HOWTO(R_390_GOTPLT32,  0, 4, 32, false, 0, complain_overflow_bitfield,
120
  bfd_elf_generic_reloc, "R_390_GOTPLT32", false, 0,0xffffffff, false),
121
  HOWTO(R_390_GOTPLT64,  0, 8, 64, false, 0, complain_overflow_bitfield,
122
  bfd_elf_generic_reloc, "R_390_GOTPLT64", false, 0,MINUS_ONE,  false),
123
  HOWTO(R_390_GOTPLTENT, 1, 4, 32,  true, 0, complain_overflow_bitfield,
124
  bfd_elf_generic_reloc, "R_390_GOTPLTENT",false, 0,MINUS_ONE,  true),
125
  HOWTO(R_390_PLTOFF16,  0, 2, 16, false, 0, complain_overflow_bitfield,
126
  bfd_elf_generic_reloc, "R_390_PLTOFF16", false, 0,0x0000ffff, false),
127
  HOWTO(R_390_PLTOFF32,  0, 4, 32, false, 0, complain_overflow_bitfield,
128
  bfd_elf_generic_reloc, "R_390_PLTOFF32", false, 0,0xffffffff, false),
129
  HOWTO(R_390_PLTOFF64,  0, 8, 64, false, 0, complain_overflow_bitfield,
130
  bfd_elf_generic_reloc, "R_390_PLTOFF64", false, 0,MINUS_ONE,  false),
131
  HOWTO(R_390_TLS_LOAD, 0, 0, 0, false, 0, complain_overflow_dont,
132
  s390_tls_reloc, "R_390_TLS_LOAD", false, 0, 0, false),
133
  HOWTO(R_390_TLS_GDCALL, 0, 0, 0, false, 0, complain_overflow_dont,
134
  s390_tls_reloc, "R_390_TLS_GDCALL", false, 0, 0, false),
135
  HOWTO(R_390_TLS_LDCALL, 0, 0, 0, false, 0, complain_overflow_dont,
136
  s390_tls_reloc, "R_390_TLS_LDCALL", false, 0, 0, false),
137
  EMPTY_HOWTO (R_390_TLS_GD32), /* Empty entry for R_390_TLS_GD32.  */
138
  HOWTO(R_390_TLS_GD64,  0, 8, 64, false, 0, complain_overflow_bitfield,
139
  bfd_elf_generic_reloc, "R_390_TLS_GD64", false, 0, MINUS_ONE, false),
140
  HOWTO(R_390_TLS_GOTIE12, 0, 2, 12, false, 0, complain_overflow_dont,
141
  bfd_elf_generic_reloc, "R_390_TLS_GOTIE12", false, 0, 0x00000fff, false),
142
  EMPTY_HOWTO (R_390_TLS_GOTIE32),  /* Empty entry for R_390_TLS_GOTIE32.  */
143
  HOWTO(R_390_TLS_GOTIE64, 0, 8, 64, false, 0, complain_overflow_bitfield,
144
  bfd_elf_generic_reloc, "R_390_TLS_GOTIE64", false, 0, MINUS_ONE, false),
145
  EMPTY_HOWTO (R_390_TLS_LDM32),  /* Empty entry for R_390_TLS_LDM32.  */
146
  HOWTO(R_390_TLS_LDM64, 0, 8, 64, false, 0, complain_overflow_bitfield,
147
  bfd_elf_generic_reloc, "R_390_TLS_LDM64", false, 0, MINUS_ONE, false),
148
  EMPTY_HOWTO (R_390_TLS_IE32), /* Empty entry for R_390_TLS_IE32.  */
149
  HOWTO(R_390_TLS_IE64,  0, 8, 64, false, 0, complain_overflow_bitfield,
150
  bfd_elf_generic_reloc, "R_390_TLS_IE64", false, 0, MINUS_ONE, false),
151
  HOWTO(R_390_TLS_IEENT, 1, 4, 32, true, 0, complain_overflow_bitfield,
152
  bfd_elf_generic_reloc, "R_390_TLS_IEENT", false, 0, MINUS_ONE, true),
153
  EMPTY_HOWTO (R_390_TLS_LE32), /* Empty entry for R_390_TLS_LE32.  */
154
  HOWTO(R_390_TLS_LE64,  0, 4, 32, false, 0, complain_overflow_bitfield,
155
  bfd_elf_generic_reloc, "R_390_TLS_LE64", false, 0, MINUS_ONE, false),
156
  EMPTY_HOWTO (R_390_TLS_LDO32),  /* Empty entry for R_390_TLS_LDO32.  */
157
  HOWTO(R_390_TLS_LDO64, 0, 8, 64, false, 0, complain_overflow_bitfield,
158
  bfd_elf_generic_reloc, "R_390_TLS_LDO64", false, 0, MINUS_ONE, false),
159
  HOWTO(R_390_TLS_DTPMOD, 0, 8, 64, false, 0, complain_overflow_bitfield,
160
  bfd_elf_generic_reloc, "R_390_TLS_DTPMOD", false, 0, MINUS_ONE, false),
161
  HOWTO(R_390_TLS_DTPOFF, 0, 8, 64, false, 0, complain_overflow_bitfield,
162
  bfd_elf_generic_reloc, "R_390_TLS_DTPOFF", false, 0, MINUS_ONE, false),
163
  HOWTO(R_390_TLS_TPOFF, 0, 8, 64, false, 0, complain_overflow_bitfield,
164
  bfd_elf_generic_reloc, "R_390_TLS_TPOFF", false, 0, MINUS_ONE, false),
165
  HOWTO(R_390_20,  0, 4, 20, false, 8, complain_overflow_dont,
166
  s390_elf_ldisp_reloc, "R_390_20",      false, 0,0x0fffff00, false),
167
  HOWTO(R_390_GOT20,   0, 4, 20, false, 8, complain_overflow_dont,
168
  s390_elf_ldisp_reloc, "R_390_GOT20",   false, 0,0x0fffff00, false),
169
  HOWTO(R_390_GOTPLT20,  0, 4, 20, false, 8, complain_overflow_dont,
170
  s390_elf_ldisp_reloc, "R_390_GOTPLT20", false, 0,0x0fffff00, false),
171
  HOWTO(R_390_TLS_GOTIE20, 0, 4, 20, false, 8, complain_overflow_dont,
172
  s390_elf_ldisp_reloc, "R_390_TLS_GOTIE20", false, 0,0x0fffff00, false),
173
  HOWTO(R_390_IRELATIVE, 0, 8, 64, false, 0, complain_overflow_bitfield,
174
  bfd_elf_generic_reloc, "R_390_IRELATIVE", false, 0, MINUS_ONE, false),
175
  HOWTO(R_390_PC12DBL,   1, 2, 12,  true, 0, complain_overflow_bitfield,
176
  bfd_elf_generic_reloc, "R_390_PC12DBL",  false, 0,0x00000fff, true),
177
  HOWTO(R_390_PLT12DBL,  1, 2, 12,  true, 0, complain_overflow_bitfield,
178
  bfd_elf_generic_reloc, "R_390_PLT12DBL", false, 0,0x00000fff, true),
179
  HOWTO(R_390_PC24DBL,   1, 4, 24,  true, 0, complain_overflow_bitfield,
180
  bfd_elf_generic_reloc, "R_390_PC24DBL",  false, 0,0x00ffffff, true),
181
  HOWTO(R_390_PLT24DBL,  1, 4, 24,  true, 0, complain_overflow_bitfield,
182
  bfd_elf_generic_reloc, "R_390_PLT24DBL", false, 0,0x00ffffff, true),
183
};
184
185
/* GNU extension to record C++ vtable hierarchy.  */
186
static reloc_howto_type elf64_s390_vtinherit_howto =
187
  HOWTO (R_390_GNU_VTINHERIT, 0,8,0,false,0,complain_overflow_dont, NULL, "R_390_GNU_VTINHERIT", false,0, 0, false);
188
static reloc_howto_type elf64_s390_vtentry_howto =
189
  HOWTO (R_390_GNU_VTENTRY, 0,8,0,false,0,complain_overflow_dont, _bfd_elf_rel_vtable_reloc_fn,"R_390_GNU_VTENTRY", false,0,0, false);
190
191
static reloc_howto_type *
192
elf_s390_reloc_type_lookup (bfd *abfd,
193
          bfd_reloc_code_real_type code)
194
0
{
195
0
  switch (code)
196
0
    {
197
0
    case BFD_RELOC_NONE:
198
0
      return &elf_howto_table[(int) R_390_NONE];
199
0
    case BFD_RELOC_8:
200
0
      return &elf_howto_table[(int) R_390_8];
201
0
    case BFD_RELOC_390_12:
202
0
      return &elf_howto_table[(int) R_390_12];
203
0
    case BFD_RELOC_16:
204
0
      return &elf_howto_table[(int) R_390_16];
205
0
    case BFD_RELOC_32:
206
0
      return &elf_howto_table[(int) R_390_32];
207
0
    case BFD_RELOC_CTOR:
208
0
      return &elf_howto_table[(int) R_390_32];
209
0
    case BFD_RELOC_32_PCREL:
210
0
      return &elf_howto_table[(int) R_390_PC32];
211
0
    case BFD_RELOC_390_GOT12:
212
0
      return &elf_howto_table[(int) R_390_GOT12];
213
0
    case BFD_RELOC_32_GOT_PCREL:
214
0
      return &elf_howto_table[(int) R_390_GOT32];
215
0
    case BFD_RELOC_390_PLT32:
216
0
      return &elf_howto_table[(int) R_390_PLT32];
217
0
    case BFD_RELOC_390_COPY:
218
0
      return &elf_howto_table[(int) R_390_COPY];
219
0
    case BFD_RELOC_390_GLOB_DAT:
220
0
      return &elf_howto_table[(int) R_390_GLOB_DAT];
221
0
    case BFD_RELOC_390_JMP_SLOT:
222
0
      return &elf_howto_table[(int) R_390_JMP_SLOT];
223
0
    case BFD_RELOC_390_RELATIVE:
224
0
      return &elf_howto_table[(int) R_390_RELATIVE];
225
0
    case BFD_RELOC_32_GOTOFF:
226
0
      return &elf_howto_table[(int) R_390_GOTOFF32];
227
0
    case BFD_RELOC_390_GOTPC:
228
0
      return &elf_howto_table[(int) R_390_GOTPC];
229
0
    case BFD_RELOC_390_GOT16:
230
0
      return &elf_howto_table[(int) R_390_GOT16];
231
0
    case BFD_RELOC_16_PCREL:
232
0
      return &elf_howto_table[(int) R_390_PC16];
233
0
    case BFD_RELOC_390_PC12DBL:
234
0
      return &elf_howto_table[(int) R_390_PC12DBL];
235
0
    case BFD_RELOC_390_PLT12DBL:
236
0
      return &elf_howto_table[(int) R_390_PLT12DBL];
237
0
    case BFD_RELOC_390_PC16DBL:
238
0
      return &elf_howto_table[(int) R_390_PC16DBL];
239
0
    case BFD_RELOC_390_PLT16DBL:
240
0
      return &elf_howto_table[(int) R_390_PLT16DBL];
241
0
    case BFD_RELOC_390_PC24DBL:
242
0
      return &elf_howto_table[(int) R_390_PC24DBL];
243
0
    case BFD_RELOC_390_PLT24DBL:
244
0
      return &elf_howto_table[(int) R_390_PLT24DBL];
245
0
    case BFD_RELOC_390_PC32DBL:
246
0
      return &elf_howto_table[(int) R_390_PC32DBL];
247
0
    case BFD_RELOC_390_PLT32DBL:
248
0
      return &elf_howto_table[(int) R_390_PLT32DBL];
249
0
    case BFD_RELOC_390_GOTPCDBL:
250
0
      return &elf_howto_table[(int) R_390_GOTPCDBL];
251
0
    case BFD_RELOC_64:
252
0
      return &elf_howto_table[(int) R_390_64];
253
0
    case BFD_RELOC_64_PCREL:
254
0
      return &elf_howto_table[(int) R_390_PC64];
255
0
    case BFD_RELOC_390_GOT64:
256
0
      return &elf_howto_table[(int) R_390_GOT64];
257
0
    case BFD_RELOC_390_PLT64:
258
0
      return &elf_howto_table[(int) R_390_PLT64];
259
0
    case BFD_RELOC_390_GOTENT:
260
0
      return &elf_howto_table[(int) R_390_GOTENT];
261
0
    case BFD_RELOC_16_GOTOFF:
262
0
      return &elf_howto_table[(int) R_390_GOTOFF16];
263
0
    case BFD_RELOC_390_GOTOFF64:
264
0
      return &elf_howto_table[(int) R_390_GOTOFF64];
265
0
    case BFD_RELOC_390_GOTPLT12:
266
0
      return &elf_howto_table[(int) R_390_GOTPLT12];
267
0
    case BFD_RELOC_390_GOTPLT16:
268
0
      return &elf_howto_table[(int) R_390_GOTPLT16];
269
0
    case BFD_RELOC_390_GOTPLT32:
270
0
      return &elf_howto_table[(int) R_390_GOTPLT32];
271
0
    case BFD_RELOC_390_GOTPLT64:
272
0
      return &elf_howto_table[(int) R_390_GOTPLT64];
273
0
    case BFD_RELOC_390_GOTPLTENT:
274
0
      return &elf_howto_table[(int) R_390_GOTPLTENT];
275
0
    case BFD_RELOC_390_PLTOFF16:
276
0
      return &elf_howto_table[(int) R_390_PLTOFF16];
277
0
    case BFD_RELOC_390_PLTOFF32:
278
0
      return &elf_howto_table[(int) R_390_PLTOFF32];
279
0
    case BFD_RELOC_390_PLTOFF64:
280
0
      return &elf_howto_table[(int) R_390_PLTOFF64];
281
0
    case BFD_RELOC_390_TLS_LOAD:
282
0
      return &elf_howto_table[(int) R_390_TLS_LOAD];
283
0
    case BFD_RELOC_390_TLS_GDCALL:
284
0
      return &elf_howto_table[(int) R_390_TLS_GDCALL];
285
0
    case BFD_RELOC_390_TLS_LDCALL:
286
0
      return &elf_howto_table[(int) R_390_TLS_LDCALL];
287
0
    case BFD_RELOC_390_TLS_GD64:
288
0
      return &elf_howto_table[(int) R_390_TLS_GD64];
289
0
    case BFD_RELOC_390_TLS_GOTIE12:
290
0
      return &elf_howto_table[(int) R_390_TLS_GOTIE12];
291
0
    case BFD_RELOC_390_TLS_GOTIE64:
292
0
      return &elf_howto_table[(int) R_390_TLS_GOTIE64];
293
0
    case BFD_RELOC_390_TLS_LDM64:
294
0
      return &elf_howto_table[(int) R_390_TLS_LDM64];
295
0
    case BFD_RELOC_390_TLS_IE64:
296
0
      return &elf_howto_table[(int) R_390_TLS_IE64];
297
0
    case BFD_RELOC_390_TLS_IEENT:
298
0
      return &elf_howto_table[(int) R_390_TLS_IEENT];
299
0
    case BFD_RELOC_390_TLS_LE64:
300
0
      return &elf_howto_table[(int) R_390_TLS_LE64];
301
0
    case BFD_RELOC_390_TLS_LDO64:
302
0
      return &elf_howto_table[(int) R_390_TLS_LDO64];
303
0
    case BFD_RELOC_390_TLS_DTPMOD:
304
0
      return &elf_howto_table[(int) R_390_TLS_DTPMOD];
305
0
    case BFD_RELOC_390_TLS_DTPOFF:
306
0
      return &elf_howto_table[(int) R_390_TLS_DTPOFF];
307
0
    case BFD_RELOC_390_TLS_TPOFF:
308
0
      return &elf_howto_table[(int) R_390_TLS_TPOFF];
309
0
    case BFD_RELOC_390_20:
310
0
      return &elf_howto_table[(int) R_390_20];
311
0
    case BFD_RELOC_390_GOT20:
312
0
      return &elf_howto_table[(int) R_390_GOT20];
313
0
    case BFD_RELOC_390_GOTPLT20:
314
0
      return &elf_howto_table[(int) R_390_GOTPLT20];
315
0
    case BFD_RELOC_390_TLS_GOTIE20:
316
0
      return &elf_howto_table[(int) R_390_TLS_GOTIE20];
317
0
    case BFD_RELOC_390_IRELATIVE:
318
0
      return &elf_howto_table[(int) R_390_IRELATIVE];
319
0
    case BFD_RELOC_VTABLE_INHERIT:
320
0
      return &elf64_s390_vtinherit_howto;
321
0
    case BFD_RELOC_VTABLE_ENTRY:
322
0
      return &elf64_s390_vtentry_howto;
323
0
    default:
324
0
      break;
325
0
    }
326
327
  /* xgettext:c-format */
328
0
  _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, (int) code);
329
0
  bfd_set_error (bfd_error_bad_value);
330
0
  return NULL;
331
0
}
332
333
static reloc_howto_type *
334
elf_s390_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
335
          const char *r_name)
336
0
{
337
0
  unsigned int i;
338
339
0
  for (i = 0;
340
0
       i < sizeof (elf_howto_table) / sizeof (elf_howto_table[0]);
341
0
       i++)
342
0
    if (elf_howto_table[i].name != NULL
343
0
  && strcasecmp (elf_howto_table[i].name, r_name) == 0)
344
0
      return &elf_howto_table[i];
345
346
0
  if (strcasecmp (elf64_s390_vtinherit_howto.name, r_name) == 0)
347
0
    return &elf64_s390_vtinherit_howto;
348
0
  if (strcasecmp (elf64_s390_vtentry_howto.name, r_name) == 0)
349
0
    return &elf64_s390_vtentry_howto;
350
351
0
  return NULL;
352
0
}
353
354
/* We need to use ELF64_R_TYPE so we have our own copy of this function,
355
   and elf64-s390.c has its own copy.  */
356
357
static bool
358
elf_s390_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
359
      arelent *cache_ptr,
360
      Elf_Internal_Rela *dst)
361
0
{
362
0
  unsigned int r_type = ELF64_R_TYPE(dst->r_info);
363
364
0
  switch (r_type)
365
0
    {
366
0
    case R_390_GNU_VTINHERIT:
367
0
      cache_ptr->howto = &elf64_s390_vtinherit_howto;
368
0
      break;
369
370
0
    case R_390_GNU_VTENTRY:
371
0
      cache_ptr->howto = &elf64_s390_vtentry_howto;
372
0
      break;
373
374
0
    default:
375
0
      if (r_type >= sizeof (elf_howto_table) / sizeof (elf_howto_table[0]))
376
0
  {
377
    /* xgettext:c-format */
378
0
    _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
379
0
            abfd, r_type);
380
0
    bfd_set_error (bfd_error_bad_value);
381
0
    return false;
382
0
  }
383
0
      cache_ptr->howto = &elf_howto_table[r_type];
384
0
    }
385
0
  return true;
386
0
}
387
388
/* A relocation function which doesn't do anything.  */
389
static bfd_reloc_status_type
390
s390_tls_reloc (bfd *abfd ATTRIBUTE_UNUSED,
391
    arelent *reloc_entry,
392
    asymbol *symbol ATTRIBUTE_UNUSED,
393
    void * data ATTRIBUTE_UNUSED,
394
    asection *input_section,
395
    bfd *output_bfd,
396
    char **error_message ATTRIBUTE_UNUSED)
397
0
{
398
0
  if (output_bfd)
399
0
    reloc_entry->address += input_section->output_offset;
400
0
  return bfd_reloc_ok;
401
0
}
402
403
/* Handle the large displacement relocs.  */
404
static bfd_reloc_status_type
405
s390_elf_ldisp_reloc (bfd *abfd,
406
          arelent *reloc_entry,
407
          asymbol *symbol,
408
          void * data,
409
          asection *input_section,
410
          bfd *output_bfd,
411
          char **error_message ATTRIBUTE_UNUSED)
412
0
{
413
0
  reloc_howto_type *howto = reloc_entry->howto;
414
0
  bfd_vma relocation;
415
0
  bfd_vma insn;
416
417
0
  if (output_bfd != (bfd *) NULL
418
0
      && (symbol->flags & BSF_SECTION_SYM) == 0
419
0
      && (! howto->partial_inplace
420
0
    || reloc_entry->addend == 0))
421
0
    {
422
0
      reloc_entry->address += input_section->output_offset;
423
0
      return bfd_reloc_ok;
424
0
    }
425
0
  if (output_bfd != NULL)
426
0
    return bfd_reloc_continue;
427
428
0
  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
429
0
    return bfd_reloc_outofrange;
430
431
0
  relocation = (symbol->value
432
0
    + symbol->section->output_section->vma
433
0
    + symbol->section->output_offset);
434
0
  relocation += reloc_entry->addend;
435
0
  if (howto->pc_relative)
436
0
    {
437
0
      relocation -= (input_section->output_section->vma
438
0
         + input_section->output_offset);
439
0
      relocation -= reloc_entry->address;
440
0
    }
441
442
0
  insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
443
0
  insn |= (relocation & 0xfff) << 16 | (relocation & 0xff000) >> 4;
444
0
  bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
445
446
0
  if ((bfd_signed_vma) relocation < - 0x80000
447
0
      || (bfd_signed_vma) relocation > 0x7ffff)
448
0
    return bfd_reloc_overflow;
449
0
  else
450
0
    return bfd_reloc_ok;
451
0
}
452
453
static bool
454
elf_s390_is_local_label_name (bfd *abfd, const char *name)
455
0
{
456
0
  if (name[0] == '.' && (name[1] == 'X' || name[1] == 'L'))
457
0
    return true;
458
459
0
  return _bfd_elf_is_local_label_name (abfd, name);
460
0
}
461
462
/* Functions for the 390 ELF linker.  */
463
464
/* The name of the dynamic interpreter.  This is put in the .interp
465
   section.  */
466
467
0
#define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
468
469
/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid
470
   copying dynamic variables from a shared lib into an app's dynbss
471
   section, and instead use a dynamic relocation to point into the
472
   shared lib.  */
473
0
#define ELIMINATE_COPY_RELOCS 1
474
475
/* The size in bytes of the first entry in the procedure linkage table.  */
476
0
#define PLT_FIRST_ENTRY_SIZE 32
477
/* The size in bytes of an entry in the procedure linkage table.  */
478
0
#define PLT_ENTRY_SIZE 32
479
480
0
#define GOT_ENTRY_SIZE 8
481
482
0
#define RELA_ENTRY_SIZE sizeof (Elf64_External_Rela)
483
484
/* The first three entries in a global offset table are reserved,
485
   and the initial contents are unimportant (we zero them out).
486
   Subsequent entries look like this.  See the SVR4 ABI 386
487
   supplement to see how this works.  */
488
489
/* For the s390, simple addr offset can only be 0 - 4096.
490
   To use the full 16777216 TB address space, several instructions
491
   are needed to load an address in a register and execute
492
   a branch( or just saving the address)
493
494
   Furthermore, only r 0 and 1 are free to use!!!  */
495
496
/* The first 3 words in the GOT are then reserved.
497
   Word 0 is the address of the dynamic table.
498
   Word 1 is a pointer to a structure describing the object
499
   Word 2 is used to point to the loader entry address.
500
501
   The code for PLT entries looks like this:
502
503
   The GOT holds the address in the PLT to be executed.
504
   The loader then gets:
505
   48(15) =  Pointer to the structure describing the object.
506
   56(15) =  Offset in symbol table
507
   The loader  must  then find the module where the function is
508
   and insert the address in the GOT.
509
510
   PLT1: LARL 1,<fn>@GOTENT # 6 bytes  Load address of GOT entry in r1
511
   LG   1,0(1)    # 6 bytes  Load address from GOT in r1
512
   BCR  15,1    # 2 bytes  Jump to address
513
   RET1: BASR 1,0   # 2 bytes  Return from GOT 1st time
514
   LGF  1,12(1)   # 6 bytes  Load rela.plt offset into r1
515
   BRCL 15,-x   # 6 bytes  Jump to first PLT entry
516
   .long ?    # 4 bytes  offset into .rela.plt
517
518
   Total = 32 bytes per PLT entry
519
   Fixup at offset 2: relative address to GOT entry
520
   Fixup at offset 22: relative branch to PLT0
521
   Fixup at offset 28: 32 bit offset into .rela.plt
522
523
   A 32 bit offset into the symbol table is enough. It allows for
524
   .rela.plt sections up to a size of 2 gigabyte.  A single dynamic
525
   object (the main program, any shared library) is limited to 4GB in
526
   size.  Having a .rela.plt of 2GB would already make the .plt
527
   section bigger than 8GB.  */
528
529
static const bfd_byte elf_s390x_plt_entry[PLT_ENTRY_SIZE] =
530
  {
531
    0xc0, 0x10, 0x00, 0x00, 0x00, 0x00,     /* larl    %r1,.     */
532
    0xe3, 0x10, 0x10, 0x00, 0x00, 0x04,     /* lg      %r1,0(%r1)  */
533
    0x07, 0xf1,           /* br      %r1     */
534
    0x0d, 0x10,           /* basr    %r1,%r0     */
535
    0xe3, 0x10, 0x10, 0x0c, 0x00, 0x14,     /* lgf     %r1,12(%r1) */
536
    0xc0, 0xf4, 0x00, 0x00, 0x00, 0x00,     /* jg      first plt   */
537
    0x00, 0x00, 0x00, 0x00        /* .long   0x00000000  */
538
  };
539
540
/* The first PLT entry pushes the offset into the symbol table
541
   from R1 onto the stack at 56(15) and the loader object info
542
   at 48(15), loads the loader address in R1 and jumps to it.  */
543
544
/* The first entry in the PLT:
545
546
  PLT0:
547
     STG  1,56(15)  # r1 contains the offset into the symbol table
548
     LARL 1,_GLOBAL_OFFSET_TABLE # load address of global offset table
549
     MVC  48(8,15),8(1) # move loader ino (object struct address) to stack
550
     LG   1,16(1)   # get entry address of loader
551
     BCR  15,1      # jump to loader
552
553
     Fixup at offset 8: relative address to start of GOT.  */
554
555
static const bfd_byte elf_s390x_first_plt_entry[PLT_FIRST_ENTRY_SIZE] =
556
  {
557
    0xe3, 0x10, 0xf0, 0x38, 0x00, 0x24,     /* stg     %r1,56(%r15)  */
558
    0xc0, 0x10, 0x00, 0x00, 0x00, 0x00,     /* larl    %r1,.     */
559
    0xd2, 0x07, 0xf0, 0x30, 0x10, 0x08,     /* mvc     48(8,%r15),8(%r1) */
560
    0xe3, 0x10, 0x10, 0x10, 0x00, 0x04,     /* lg      %r1,16(%r1)   */
561
    0x07, 0xf1,           /* br      %r1     */
562
    0x07, 0x00,           /* nopr    %r0     */
563
    0x07, 0x00,           /* nopr    %r0     */
564
    0x07, 0x00            /* nopr    %r0     */
565
  };
566
567
568
/* s390 ELF linker hash entry.  */
569
570
struct elf_s390_link_hash_entry
571
{
572
  struct elf_link_hash_entry elf;
573
574
  /* Number of GOTPLT references for a function.  */
575
  bfd_signed_vma gotplt_refcount;
576
577
0
#define GOT_UNKNOWN 0
578
0
#define GOT_NORMAL  1
579
0
#define GOT_TLS_GD  2
580
0
#define GOT_TLS_IE  3
581
0
#define GOT_TLS_IE_NLT  3
582
  unsigned char tls_type;
583
584
  /* For pointer equality reasons we might need to change the symbol
585
     type from STT_GNU_IFUNC to STT_FUNC together with its value and
586
     section entry.  So after alloc_dynrelocs only these values should
587
     be used.  In order to check whether a symbol is IFUNC use
588
     s390_is_ifunc_symbol_p.  */
589
  bfd_vma ifunc_resolver_address;
590
  asection *ifunc_resolver_section;
591
};
592
593
#define elf_s390_hash_entry(ent) \
594
0
  ((struct elf_s390_link_hash_entry *)(ent))
595
596
/* This structure represents an entry in the local PLT list needed for
597
   local IFUNC symbols.  */
598
struct plt_entry
599
{
600
  /* The section of the local symbol.
601
     Set in relocate_section and used in finish_dynamic_sections.  */
602
  asection *sec;
603
604
  union
605
    {
606
      bfd_signed_vma refcount;
607
      bfd_vma offset;
608
    } plt;
609
};
610
611
/* NOTE: Keep this structure in sync with
612
   the one declared in elf32-s390.c.  */
613
struct elf_s390_obj_tdata
614
{
615
  struct elf_obj_tdata root;
616
617
  /* A local PLT is needed for ifunc symbols.  */
618
  struct plt_entry *local_plt;
619
620
  /* TLS type for each local got entry.  */
621
  char *local_got_tls_type;
622
};
623
624
#define elf_s390_tdata(abfd) \
625
0
  ((struct elf_s390_obj_tdata *) (abfd)->tdata.any)
626
627
#define elf_s390_local_plt(abfd) \
628
0
  (elf_s390_tdata (abfd)->local_plt)
629
630
#define elf_s390_local_got_tls_type(abfd) \
631
0
  (elf_s390_tdata (abfd)->local_got_tls_type)
632
633
#define is_s390_elf(bfd)        \
634
0
  (bfd_get_flavour (bfd) == bfd_target_elf_flavour  \
635
0
   && elf_tdata (bfd) != NULL        \
636
0
   && elf_object_id (bfd) == S390_ELF_DATA)
637
638
static bool
639
elf_s390_mkobject (bfd *abfd)
640
6
{
641
6
  return bfd_elf_allocate_object (abfd, sizeof (struct elf_s390_obj_tdata),
642
6
          S390_ELF_DATA);
643
6
}
644
645
static bool
646
elf_s390_object_p (bfd *abfd)
647
2
{
648
  /* Set the right machine number for an s390 elf32 file.  */
649
2
  return bfd_default_set_arch_mach (abfd, bfd_arch_s390, bfd_mach_s390_64);
650
2
}
651
652
/* s390 ELF linker hash table.  */
653
654
struct elf_s390_link_hash_table
655
{
656
  struct elf_link_hash_table elf;
657
658
  /* Short-cuts to get to dynamic linker sections.  */
659
  asection *irelifunc;
660
661
  union {
662
    bfd_signed_vma refcount;
663
    bfd_vma offset;
664
  } tls_ldm_got;
665
666
  /* Options passed from the linker.  */
667
  struct s390_elf_params *params;
668
};
669
670
/* Get the s390 ELF linker hash table from a link_info structure.  */
671
672
#define elf_s390_hash_table(p)            \
673
0
  ((is_elf_hash_table ((p)->hash)          \
674
0
    && elf_hash_table_id (elf_hash_table (p)) == S390_ELF_DATA)   \
675
0
   ? (struct elf_s390_link_hash_table *) (p)->hash : NULL)
676
677
#define ELF64 1
678
#include "elf-s390-common.c"
679
680
/* Create an entry in an s390 ELF linker hash table.  */
681
682
static struct bfd_hash_entry *
683
link_hash_newfunc (struct bfd_hash_entry *entry,
684
       struct bfd_hash_table *table,
685
       const char *string)
686
0
{
687
  /* Allocate the structure if it has not already been allocated by a
688
     subclass.  */
689
0
  if (entry == NULL)
690
0
    {
691
0
      entry = bfd_hash_allocate (table,
692
0
         sizeof (struct elf_s390_link_hash_entry));
693
0
      if (entry == NULL)
694
0
  return entry;
695
0
    }
696
697
  /* Call the allocation method of the superclass.  */
698
0
  entry = _bfd_elf_link_hash_newfunc (entry, table, string);
699
0
  if (entry != NULL)
700
0
    {
701
0
      struct elf_s390_link_hash_entry *eh;
702
703
0
      eh = (struct elf_s390_link_hash_entry *) entry;
704
0
      eh->gotplt_refcount = 0;
705
0
      eh->tls_type = GOT_UNKNOWN;
706
0
      eh->ifunc_resolver_address = 0;
707
0
      eh->ifunc_resolver_section = NULL;
708
0
    }
709
710
0
  return entry;
711
0
}
712
713
/* Create an s390 ELF linker hash table.  */
714
715
static struct bfd_link_hash_table *
716
elf_s390_link_hash_table_create (bfd *abfd)
717
0
{
718
0
  struct elf_s390_link_hash_table *ret;
719
0
  size_t amt = sizeof (struct elf_s390_link_hash_table);
720
721
0
  ret = (struct elf_s390_link_hash_table *) bfd_zmalloc (amt);
722
0
  if (ret == NULL)
723
0
    return NULL;
724
725
0
  if (!_bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc,
726
0
              sizeof (struct elf_s390_link_hash_entry),
727
0
              S390_ELF_DATA))
728
0
    {
729
0
      free (ret);
730
0
      return NULL;
731
0
    }
732
733
0
  return &ret->elf.root;
734
0
}
735
736
/* Copy the extra info we tack onto an elf_link_hash_entry.  */
737
738
static void
739
elf_s390_copy_indirect_symbol (struct bfd_link_info *info,
740
             struct elf_link_hash_entry *dir,
741
             struct elf_link_hash_entry *ind)
742
0
{
743
0
  struct elf_s390_link_hash_entry *edir, *eind;
744
745
0
  edir = (struct elf_s390_link_hash_entry *) dir;
746
0
  eind = (struct elf_s390_link_hash_entry *) ind;
747
748
0
  if (ind->root.type == bfd_link_hash_indirect
749
0
      && dir->got.refcount <= 0)
750
0
    {
751
0
      edir->tls_type = eind->tls_type;
752
0
      eind->tls_type = GOT_UNKNOWN;
753
0
    }
754
755
0
  if (ELIMINATE_COPY_RELOCS
756
0
      && ind->root.type != bfd_link_hash_indirect
757
0
      && dir->dynamic_adjusted)
758
0
    {
759
      /* If called to transfer flags for a weakdef during processing
760
   of elf_adjust_dynamic_symbol, don't copy non_got_ref.
761
   We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
762
0
      if (dir->versioned != versioned_hidden)
763
0
  dir->ref_dynamic |= ind->ref_dynamic;
764
0
      dir->ref_regular |= ind->ref_regular;
765
0
      dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
766
0
      dir->needs_plt |= ind->needs_plt;
767
0
    }
768
0
  else
769
0
    _bfd_elf_link_hash_copy_indirect (info, dir, ind);
770
0
}
771
772
static int
773
elf_s390_tls_transition (struct bfd_link_info *info,
774
       int r_type,
775
       int is_local)
776
0
{
777
0
  if (bfd_link_dll (info))
778
0
    return r_type;
779
780
0
  switch (r_type)
781
0
    {
782
0
    case R_390_TLS_GD64:
783
0
    case R_390_TLS_IE64:
784
0
      if (is_local)
785
0
  return R_390_TLS_LE64;
786
0
      return R_390_TLS_IE64;
787
0
    case R_390_TLS_GOTIE64:
788
0
      if (is_local)
789
0
  return R_390_TLS_LE64;
790
0
      return R_390_TLS_GOTIE64;
791
0
    case R_390_TLS_LDM64:
792
0
      return R_390_TLS_LE64;
793
0
    }
794
795
0
  return r_type;
796
0
}
797
798
/* Look through the relocs for a section during the first phase, and
799
   allocate space in the global offset table or procedure linkage
800
   table.  */
801
802
static bool
803
elf_s390_check_relocs (bfd *abfd,
804
           struct bfd_link_info *info,
805
           asection *sec,
806
           const Elf_Internal_Rela *relocs)
807
0
{
808
0
  struct elf_s390_link_hash_table *htab;
809
0
  Elf_Internal_Shdr *symtab_hdr;
810
0
  struct elf_link_hash_entry **sym_hashes;
811
0
  const Elf_Internal_Rela *rel;
812
0
  const Elf_Internal_Rela *rel_end;
813
0
  asection *sreloc;
814
0
  bfd_signed_vma *local_got_refcounts;
815
0
  int tls_type, old_tls_type;
816
817
0
  if (bfd_link_relocatable (info))
818
0
    return true;
819
820
0
  BFD_ASSERT (is_s390_elf (abfd));
821
822
0
  htab = elf_s390_hash_table (info);
823
0
  if (htab == NULL)
824
0
    return false;
825
826
0
  symtab_hdr = &elf_symtab_hdr (abfd);
827
0
  sym_hashes = elf_sym_hashes (abfd);
828
0
  local_got_refcounts = elf_local_got_refcounts (abfd);
829
830
0
  sreloc = NULL;
831
832
0
  rel_end = relocs + sec->reloc_count;
833
0
  for (rel = relocs; rel < rel_end; rel++)
834
0
    {
835
0
      unsigned int r_type;
836
0
      unsigned int r_symndx;
837
0
      struct elf_link_hash_entry *h;
838
0
      Elf_Internal_Sym *isym;
839
840
0
      r_symndx = ELF64_R_SYM (rel->r_info);
841
842
0
      if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr))
843
0
  {
844
    /* xgettext:c-format */
845
0
    _bfd_error_handler (_("%pB: bad symbol index: %d"),
846
0
            abfd, r_symndx);
847
0
    return false;
848
0
  }
849
850
0
      if (r_symndx < symtab_hdr->sh_info)
851
0
  {
852
    /* A local symbol.  */
853
0
    isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
854
0
          abfd, r_symndx);
855
0
    if (isym == NULL)
856
0
      return false;
857
858
0
    if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
859
0
      {
860
0
        struct plt_entry *plt;
861
862
0
        if (htab->elf.dynobj == NULL)
863
0
    htab->elf.dynobj = abfd;
864
865
0
        if (!s390_elf_create_ifunc_sections (htab->elf.dynobj, info))
866
0
    return false;
867
868
0
        if (local_got_refcounts == NULL)
869
0
    {
870
0
      if (!elf_s390_allocate_local_syminfo (abfd, symtab_hdr))
871
0
        return false;
872
0
      local_got_refcounts = elf_local_got_refcounts (abfd);
873
0
    }
874
0
        plt = elf_s390_local_plt (abfd);
875
0
        plt[r_symndx].plt.refcount++;
876
0
      }
877
0
    h = NULL;
878
0
  }
879
0
      else
880
0
  {
881
0
    h = sym_hashes[r_symndx - symtab_hdr->sh_info];
882
0
    while (h->root.type == bfd_link_hash_indirect
883
0
     || h->root.type == bfd_link_hash_warning)
884
0
      h = (struct elf_link_hash_entry *) h->root.u.i.link;
885
0
  }
886
887
      /* Create got section and local_got_refcounts array if they
888
   are needed.  */
889
0
      r_type = elf_s390_tls_transition (info,
890
0
          ELF64_R_TYPE (rel->r_info),
891
0
          h == NULL);
892
0
      switch (r_type)
893
0
  {
894
0
  case R_390_GOT12:
895
0
  case R_390_GOT16:
896
0
  case R_390_GOT20:
897
0
  case R_390_GOT32:
898
0
  case R_390_GOT64:
899
0
  case R_390_GOTENT:
900
0
  case R_390_GOTPLT12:
901
0
  case R_390_GOTPLT16:
902
0
  case R_390_GOTPLT20:
903
0
  case R_390_GOTPLT32:
904
0
  case R_390_GOTPLT64:
905
0
  case R_390_GOTPLTENT:
906
0
  case R_390_TLS_GD64:
907
0
  case R_390_TLS_GOTIE12:
908
0
  case R_390_TLS_GOTIE20:
909
0
  case R_390_TLS_GOTIE64:
910
0
  case R_390_TLS_IEENT:
911
0
  case R_390_TLS_IE64:
912
0
  case R_390_TLS_LDM64:
913
0
    if (h == NULL
914
0
        && local_got_refcounts == NULL)
915
0
      {
916
0
        if (!elf_s390_allocate_local_syminfo (abfd, symtab_hdr))
917
0
    return false;
918
0
        local_got_refcounts = elf_local_got_refcounts (abfd);
919
0
      }
920
921
    /* Fall through.  */
922
0
  case R_390_GOTOFF16:
923
0
  case R_390_GOTOFF32:
924
0
  case R_390_GOTOFF64:
925
0
  case R_390_GOTPC:
926
0
  case R_390_GOTPCDBL:
927
0
    if (htab->elf.sgot == NULL)
928
0
      {
929
0
        if (htab->elf.dynobj == NULL)
930
0
    htab->elf.dynobj = abfd;
931
0
        if (!_bfd_elf_create_got_section (htab->elf.dynobj, info))
932
0
    return false;
933
0
      }
934
0
  }
935
936
0
      if (h != NULL)
937
0
  {
938
0
    if (htab->elf.dynobj == NULL)
939
0
      htab->elf.dynobj = abfd;
940
0
    if (!s390_elf_create_ifunc_sections (htab->elf.dynobj, info))
941
0
      return false;
942
943
    /* Make sure an IFUNC symbol defined in a non-shared object
944
       always gets a PLT slot.  */
945
0
    if (s390_is_ifunc_symbol_p (h) && h->def_regular)
946
0
      {
947
        /* The symbol is called by the dynamic loader in order
948
     to resolve the relocation.  So it is in fact also
949
     referenced.  */
950
0
        h->ref_regular = 1;
951
0
        h->needs_plt = 1;
952
0
      }
953
0
  }
954
955
0
      switch (r_type)
956
0
  {
957
0
  case R_390_GOTPC:
958
0
  case R_390_GOTPCDBL:
959
    /* These relocs do not need a GOT slot.  They just load the
960
       GOT pointer itself or address something else relative to
961
       the GOT.  Since the GOT pointer has been set up above we
962
       are done.  */
963
0
    break;
964
0
  case R_390_GOTOFF16:
965
0
  case R_390_GOTOFF32:
966
0
  case R_390_GOTOFF64:
967
0
    if (h == NULL || !s390_is_ifunc_symbol_p (h) || !h->def_regular)
968
0
      break;
969
    /* Fall through.  */
970
971
0
  case R_390_PLT12DBL:
972
0
  case R_390_PLT16DBL:
973
0
  case R_390_PLT24DBL:
974
0
  case R_390_PLT32:
975
0
  case R_390_PLT32DBL:
976
0
  case R_390_PLT64:
977
0
  case R_390_PLTOFF16:
978
0
  case R_390_PLTOFF32:
979
0
  case R_390_PLTOFF64:
980
    /* This symbol requires a procedure linkage table entry.  We
981
       actually build the entry in adjust_dynamic_symbol,
982
       because this might be a case of linking PIC code which is
983
       never referenced by a dynamic object, in which case we
984
       don't need to generate a procedure linkage table entry
985
       after all.  */
986
987
    /* If this is a local symbol, we resolve it directly without
988
       creating a procedure linkage table entry.  */
989
0
    if (h != NULL)
990
0
      {
991
0
        h->needs_plt = 1;
992
0
        h->plt.refcount += 1;
993
0
      }
994
0
    break;
995
996
0
  case R_390_GOTPLT12:
997
0
  case R_390_GOTPLT16:
998
0
  case R_390_GOTPLT20:
999
0
  case R_390_GOTPLT32:
1000
0
  case R_390_GOTPLT64:
1001
0
  case R_390_GOTPLTENT:
1002
    /* This symbol requires either a procedure linkage table entry
1003
       or an entry in the local got. We actually build the entry
1004
       in adjust_dynamic_symbol because whether this is really a
1005
       global reference can change and with it the fact if we have
1006
       to create a plt entry or a local got entry. To be able to
1007
       make a once global symbol a local one we have to keep track
1008
       of the number of gotplt references that exist for this
1009
       symbol.  */
1010
0
    if (h != NULL)
1011
0
      {
1012
0
        ((struct elf_s390_link_hash_entry *) h)->gotplt_refcount++;
1013
0
        h->needs_plt = 1;
1014
0
        h->plt.refcount += 1;
1015
0
      }
1016
0
    else
1017
0
      local_got_refcounts[r_symndx] += 1;
1018
0
    break;
1019
1020
0
  case R_390_TLS_LDM64:
1021
0
    htab->tls_ldm_got.refcount += 1;
1022
0
    break;
1023
1024
0
  case R_390_TLS_IE64:
1025
0
  case R_390_TLS_GOTIE12:
1026
0
  case R_390_TLS_GOTIE20:
1027
0
  case R_390_TLS_GOTIE64:
1028
0
  case R_390_TLS_IEENT:
1029
0
    if (bfd_link_dll (info))
1030
0
      info->flags |= DF_STATIC_TLS;
1031
    /* Fall through */
1032
1033
0
  case R_390_GOT12:
1034
0
  case R_390_GOT16:
1035
0
  case R_390_GOT20:
1036
0
  case R_390_GOT32:
1037
0
  case R_390_GOT64:
1038
0
  case R_390_GOTENT:
1039
0
  case R_390_TLS_GD64:
1040
    /* This symbol requires a global offset table entry.  */
1041
0
    switch (r_type)
1042
0
      {
1043
0
      default:
1044
0
      case R_390_GOT12:
1045
0
      case R_390_GOT16:
1046
0
      case R_390_GOT20:
1047
0
      case R_390_GOT32:
1048
0
      case R_390_GOTENT:
1049
0
        tls_type = GOT_NORMAL;
1050
0
        break;
1051
0
      case R_390_TLS_GD64:
1052
0
        tls_type = GOT_TLS_GD;
1053
0
        break;
1054
0
      case R_390_TLS_IE64:
1055
0
      case R_390_TLS_GOTIE64:
1056
0
        tls_type = GOT_TLS_IE;
1057
0
        break;
1058
0
      case R_390_TLS_GOTIE12:
1059
0
      case R_390_TLS_GOTIE20:
1060
0
      case R_390_TLS_IEENT:
1061
0
        tls_type = GOT_TLS_IE_NLT;
1062
0
        break;
1063
0
      }
1064
1065
0
    if (h != NULL)
1066
0
      {
1067
0
        h->got.refcount += 1;
1068
0
        old_tls_type = elf_s390_hash_entry(h)->tls_type;
1069
0
      }
1070
0
    else
1071
0
      {
1072
0
        local_got_refcounts[r_symndx] += 1;
1073
0
        old_tls_type = elf_s390_local_got_tls_type (abfd) [r_symndx];
1074
0
      }
1075
    /* If a TLS symbol is accessed using IE at least once,
1076
       there is no point to use dynamic model for it.  */
1077
0
    if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN)
1078
0
      {
1079
0
        if (old_tls_type == GOT_NORMAL || tls_type == GOT_NORMAL)
1080
0
    {
1081
0
      _bfd_error_handler
1082
        /* xgettext:c-format */
1083
0
        (_("%pB: `%s' accessed both as normal and thread local symbol"),
1084
0
         abfd, h->root.root.string);
1085
0
      return false;
1086
0
    }
1087
0
        if (old_tls_type > tls_type)
1088
0
    tls_type = old_tls_type;
1089
0
      }
1090
1091
0
    if (old_tls_type != tls_type)
1092
0
      {
1093
0
        if (h != NULL)
1094
0
    elf_s390_hash_entry (h)->tls_type = tls_type;
1095
0
        else
1096
0
    elf_s390_local_got_tls_type (abfd) [r_symndx] = tls_type;
1097
0
      }
1098
1099
0
    if (r_type != R_390_TLS_IE64)
1100
0
      break;
1101
    /* Fall through */
1102
1103
0
  case R_390_TLS_LE64:
1104
    /* For static linking and executables this reloc will be
1105
       calculated at linktime otherwise a TLS_TPOFF runtime
1106
       reloc will be generated.  */
1107
0
    if (r_type == R_390_TLS_LE64 && bfd_link_pie (info))
1108
0
      break;
1109
1110
0
    if (!bfd_link_dll (info))
1111
0
      break;
1112
0
    info->flags |= DF_STATIC_TLS;
1113
    /* Fall through */
1114
1115
0
  case R_390_8:
1116
0
  case R_390_16:
1117
0
  case R_390_32:
1118
0
  case R_390_64:
1119
0
  case R_390_PC12DBL:
1120
0
  case R_390_PC16:
1121
0
  case R_390_PC16DBL:
1122
0
  case R_390_PC24DBL:
1123
0
  case R_390_PC32:
1124
0
  case R_390_PC32DBL:
1125
0
  case R_390_PC64:
1126
0
    if (h != NULL && bfd_link_executable (info))
1127
0
      {
1128
        /* If this reloc is in a read-only section, we might
1129
     need a copy reloc.  We can't check reliably at this
1130
     stage whether the section is read-only, as input
1131
     sections have not yet been mapped to output sections.
1132
     Tentatively set the flag for now, and correct in
1133
     adjust_dynamic_symbol.  */
1134
0
        h->non_got_ref = 1;
1135
1136
0
        if (!bfd_link_pic (info))
1137
0
    {
1138
      /* We may need a .plt entry if the function this reloc
1139
         refers to is in a shared lib.  */
1140
0
      h->plt.refcount += 1;
1141
0
    }
1142
0
      }
1143
1144
    /* If we are creating a shared library, and this is a reloc
1145
       against a global symbol, or a non PC relative reloc
1146
       against a local symbol, then we need to copy the reloc
1147
       into the shared library.  However, if we are linking with
1148
       -Bsymbolic, we do not need to copy a reloc against a
1149
       global symbol which is defined in an object we are
1150
       including in the link (i.e., DEF_REGULAR is set).  At
1151
       this point we have not seen all the input files, so it is
1152
       possible that DEF_REGULAR is not set now but will be set
1153
       later (it is never cleared).  In case of a weak definition,
1154
       DEF_REGULAR may be cleared later by a strong definition in
1155
       a shared library. We account for that possibility below by
1156
       storing information in the relocs_copied field of the hash
1157
       table entry.  A similar situation occurs when creating
1158
       shared libraries and symbol visibility changes render the
1159
       symbol local.
1160
1161
       If on the other hand, we are creating an executable, we
1162
       may need to keep relocations for symbols satisfied by a
1163
       dynamic library if we manage to avoid copy relocs for the
1164
       symbol.  */
1165
0
    if ((bfd_link_pic (info)
1166
0
         && (sec->flags & SEC_ALLOC) != 0
1167
0
         && ((ELF64_R_TYPE (rel->r_info) != R_390_PC16
1168
0
        && ELF64_R_TYPE (rel->r_info) != R_390_PC12DBL
1169
0
        && ELF64_R_TYPE (rel->r_info) != R_390_PC16DBL
1170
0
        && ELF64_R_TYPE (rel->r_info) != R_390_PC24DBL
1171
0
        && ELF64_R_TYPE (rel->r_info) != R_390_PC32
1172
0
        && ELF64_R_TYPE (rel->r_info) != R_390_PC32DBL
1173
0
        && ELF64_R_TYPE (rel->r_info) != R_390_PC64)
1174
0
       || (h != NULL
1175
0
           && (! SYMBOLIC_BIND (info, h)
1176
0
         || h->root.type == bfd_link_hash_defweak
1177
0
         || !h->def_regular))))
1178
0
        || (ELIMINATE_COPY_RELOCS
1179
0
      && !bfd_link_pic (info)
1180
0
      && (sec->flags & SEC_ALLOC) != 0
1181
0
      && h != NULL
1182
0
      && (h->root.type == bfd_link_hash_defweak
1183
0
          || !h->def_regular)))
1184
0
      {
1185
0
        struct elf_dyn_relocs *p;
1186
0
        struct elf_dyn_relocs **head;
1187
1188
        /* We must copy these reloc types into the output file.
1189
     Create a reloc section in dynobj and make room for
1190
     this reloc.  */
1191
0
        if (sreloc == NULL)
1192
0
    {
1193
0
      if (htab->elf.dynobj == NULL)
1194
0
        htab->elf.dynobj = abfd;
1195
1196
0
      sreloc = _bfd_elf_make_dynamic_reloc_section
1197
0
        (sec, htab->elf.dynobj, 3, abfd, /*rela?*/ true);
1198
1199
0
      if (sreloc == NULL)
1200
0
        return false;
1201
0
    }
1202
1203
        /* If this is a global symbol, we count the number of
1204
     relocations we need for this symbol.  */
1205
0
        if (h != NULL)
1206
0
    {
1207
0
      head = &h->dyn_relocs;
1208
0
    }
1209
0
        else
1210
0
    {
1211
      /* Track dynamic relocs needed for local syms too.
1212
         We really need local syms available to do this
1213
         easily.  Oh well.  */
1214
0
      asection *s;
1215
0
      void *vpp;
1216
1217
0
      isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
1218
0
            abfd, r_symndx);
1219
0
      if (isym == NULL)
1220
0
        return false;
1221
1222
0
      s = bfd_section_from_elf_index (abfd, isym->st_shndx);
1223
0
      if (s == NULL)
1224
0
        s = sec;
1225
1226
0
      vpp = &elf_section_data (s)->local_dynrel;
1227
0
      head = (struct elf_dyn_relocs **) vpp;
1228
0
    }
1229
1230
0
        p = *head;
1231
0
        if (p == NULL || p->sec != sec)
1232
0
    {
1233
0
      size_t amt = sizeof *p;
1234
0
      p = ((struct elf_dyn_relocs *)
1235
0
           bfd_alloc (htab->elf.dynobj, amt));
1236
0
      if (p == NULL)
1237
0
        return false;
1238
0
      p->next = *head;
1239
0
      *head = p;
1240
0
      p->sec = sec;
1241
0
      p->count = 0;
1242
0
      p->pc_count = 0;
1243
0
    }
1244
1245
0
        p->count += 1;
1246
0
        if (ELF64_R_TYPE (rel->r_info) == R_390_PC16
1247
0
      || ELF64_R_TYPE (rel->r_info) == R_390_PC12DBL
1248
0
      || ELF64_R_TYPE (rel->r_info) == R_390_PC16DBL
1249
0
      || ELF64_R_TYPE (rel->r_info) == R_390_PC16DBL
1250
0
      || ELF64_R_TYPE (rel->r_info) == R_390_PC32
1251
0
      || ELF64_R_TYPE (rel->r_info) == R_390_PC32DBL
1252
0
      || ELF64_R_TYPE (rel->r_info) == R_390_PC64)
1253
0
    p->pc_count += 1;
1254
0
      }
1255
0
    break;
1256
1257
    /* This relocation describes the C++ object vtable hierarchy.
1258
       Reconstruct it for later use during GC.  */
1259
0
  case R_390_GNU_VTINHERIT:
1260
0
    if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
1261
0
      return false;
1262
0
    break;
1263
1264
    /* This relocation describes which C++ vtable entries are actually
1265
       used.  Record for later use during GC.  */
1266
0
  case R_390_GNU_VTENTRY:
1267
0
    if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
1268
0
      return false;
1269
0
    break;
1270
1271
0
  default:
1272
0
    break;
1273
0
  }
1274
0
    }
1275
1276
0
  return true;
1277
0
}
1278
1279
/* Return the section that should be marked against GC for a given
1280
   relocation.  */
1281
1282
static asection *
1283
elf_s390_gc_mark_hook (asection *sec,
1284
           struct bfd_link_info *info,
1285
           Elf_Internal_Rela *rel,
1286
           struct elf_link_hash_entry *h,
1287
           Elf_Internal_Sym *sym)
1288
0
{
1289
0
  if (h != NULL)
1290
0
    switch (ELF64_R_TYPE (rel->r_info))
1291
0
      {
1292
0
      case R_390_GNU_VTINHERIT:
1293
0
      case R_390_GNU_VTENTRY:
1294
0
  return NULL;
1295
0
      }
1296
1297
0
  return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
1298
0
}
1299
1300
/* Make sure we emit a GOT entry if the symbol was supposed to have a PLT
1301
   entry but we found we will not create any.  Called when we find we will
1302
   not have any PLT for this symbol, by for example
1303
   elf_s390_adjust_dynamic_symbol when we're doing a proper dynamic link,
1304
   or elf_s390_size_dynamic_sections if no dynamic sections will be
1305
   created (we're only linking static objects).  */
1306
1307
static void
1308
elf_s390_adjust_gotplt (struct elf_s390_link_hash_entry *h)
1309
0
{
1310
0
  if (h->elf.root.type == bfd_link_hash_warning)
1311
0
    h = (struct elf_s390_link_hash_entry *) h->elf.root.u.i.link;
1312
1313
0
  if (h->gotplt_refcount <= 0)
1314
0
    return;
1315
1316
  /* We simply add the number of gotplt references to the number
1317
   * of got references for this symbol.  */
1318
0
  h->elf.got.refcount += h->gotplt_refcount;
1319
0
  h->gotplt_refcount = -1;
1320
0
}
1321
1322
/* Adjust a symbol defined by a dynamic object and referenced by a
1323
   regular object.  The current definition is in some section of the
1324
   dynamic object, but we're not including those sections.  We have to
1325
   change the definition to something the rest of the link can
1326
   understand.  */
1327
1328
static bool
1329
elf_s390_adjust_dynamic_symbol (struct bfd_link_info *info,
1330
        struct elf_link_hash_entry *h)
1331
0
{
1332
0
  struct elf_s390_link_hash_table *htab;
1333
0
  asection *s, *srel;
1334
1335
  /* STT_GNU_IFUNC symbol must go through PLT. */
1336
0
  if (s390_is_ifunc_symbol_p (h))
1337
0
    {
1338
      /* All local STT_GNU_IFUNC references must be treated as local
1339
   calls via local PLT.  */
1340
0
      if (h->ref_regular && SYMBOL_CALLS_LOCAL (info, h))
1341
0
  {
1342
0
    bfd_size_type pc_count = 0, count = 0;
1343
0
    struct elf_dyn_relocs **pp;
1344
0
    struct elf_dyn_relocs *p;
1345
1346
0
    for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
1347
0
      {
1348
0
        pc_count += p->pc_count;
1349
0
        p->count -= p->pc_count;
1350
0
        p->pc_count = 0;
1351
0
        count += p->count;
1352
0
        if (p->count == 0)
1353
0
    *pp = p->next;
1354
0
        else
1355
0
    pp = &p->next;
1356
0
      }
1357
1358
0
    if (pc_count || count)
1359
0
      {
1360
0
        h->needs_plt = 1;
1361
0
        h->non_got_ref = 1;
1362
0
        if (h->plt.refcount <= 0)
1363
0
    h->plt.refcount = 1;
1364
0
        else
1365
0
    h->plt.refcount += 1;
1366
0
      }
1367
0
  }
1368
1369
0
      if (h->plt.refcount <= 0)
1370
0
  {
1371
0
    h->plt.offset = (bfd_vma) -1;
1372
0
    h->needs_plt = 0;
1373
0
  }
1374
0
      return true;
1375
0
    }
1376
1377
  /* If this is a function, put it in the procedure linkage table.  We
1378
     will fill in the contents of the procedure linkage table later
1379
     (although we could actually do it here).  */
1380
0
  if (h->type == STT_FUNC
1381
0
      || h->needs_plt)
1382
0
    {
1383
0
      if (h->plt.refcount <= 0
1384
0
    || SYMBOL_CALLS_LOCAL (info, h)
1385
0
    || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
1386
0
  {
1387
    /* This case can occur if we saw a PLT32 reloc in an input
1388
       file, but the symbol was never referred to by a dynamic
1389
       object, or if all references were garbage collected.  In
1390
       such a case, we don't actually need to build a procedure
1391
       linkage table, and we can just do a PC32 reloc instead.  */
1392
0
    h->plt.offset = (bfd_vma) -1;
1393
0
    h->needs_plt = 0;
1394
0
    elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
1395
0
  }
1396
1397
0
      return true;
1398
0
    }
1399
0
  else
1400
    /* It's possible that we incorrectly decided a .plt reloc was
1401
       needed for an R_390_PC32 reloc to a non-function sym in
1402
       check_relocs.  We can't decide accurately between function and
1403
       non-function syms in check-relocs;  Objects loaded later in
1404
       the link may change h->type.  So fix it now.  */
1405
0
    h->plt.offset = (bfd_vma) -1;
1406
1407
  /* If this is a weak symbol, and there is a real definition, the
1408
     processor independent code will have arranged for us to see the
1409
     real definition first, and we can just use the same value.  */
1410
0
  if (h->is_weakalias)
1411
0
    {
1412
0
      struct elf_link_hash_entry *def = weakdef (h);
1413
0
      BFD_ASSERT (def->root.type == bfd_link_hash_defined);
1414
0
      h->root.u.def.section = def->root.u.def.section;
1415
0
      h->root.u.def.value = def->root.u.def.value;
1416
0
      if (ELIMINATE_COPY_RELOCS || info->nocopyreloc)
1417
0
  h->non_got_ref = def->non_got_ref;
1418
0
      return true;
1419
0
    }
1420
1421
  /* This is a reference to a symbol defined by a dynamic object which
1422
     is not a function.  */
1423
1424
  /* If we are creating a shared library, we must presume that the
1425
     only references to the symbol are via the global offset table.
1426
     For such cases we need not do anything here; the relocations will
1427
     be handled correctly by relocate_section.  */
1428
0
  if (bfd_link_pic (info))
1429
0
    return true;
1430
1431
  /* If there are no references to this symbol that do not use the
1432
     GOT, we don't need to generate a copy reloc.  */
1433
0
  if (!h->non_got_ref)
1434
0
    return true;
1435
1436
  /* If -z nocopyreloc was given, we won't generate them either.  */
1437
0
  if (info->nocopyreloc)
1438
0
    {
1439
0
      h->non_got_ref = 0;
1440
0
      return true;
1441
0
    }
1442
1443
  /* If we don't find any dynamic relocs in read-only sections, then
1444
     we'll be keeping the dynamic relocs and avoiding the copy reloc.  */
1445
0
  if (ELIMINATE_COPY_RELOCS && !_bfd_elf_readonly_dynrelocs (h))
1446
0
    {
1447
0
      h->non_got_ref = 0;
1448
0
      return true;
1449
0
    }
1450
1451
  /* We must allocate the symbol in our .dynbss section, which will
1452
     become part of the .bss section of the executable.  There will be
1453
     an entry for this symbol in the .dynsym section.  The dynamic
1454
     object will contain position independent code, so all references
1455
     from the dynamic object to this symbol will go through the global
1456
     offset table.  The dynamic linker will use the .dynsym entry to
1457
     determine the address it must put in the global offset table, so
1458
     both the dynamic object and the regular object will refer to the
1459
     same memory location for the variable.  */
1460
1461
0
  htab = elf_s390_hash_table (info);
1462
0
  if (htab == NULL)
1463
0
    return false;
1464
1465
  /* We must generate a R_390_COPY reloc to tell the dynamic linker to
1466
     copy the initial value out of the dynamic object and into the
1467
     runtime process image.  */
1468
0
  if ((h->root.u.def.section->flags & SEC_READONLY) != 0)
1469
0
    {
1470
0
      s = htab->elf.sdynrelro;
1471
0
      srel = htab->elf.sreldynrelro;
1472
0
    }
1473
0
  else
1474
0
    {
1475
0
      s = htab->elf.sdynbss;
1476
0
      srel = htab->elf.srelbss;
1477
0
    }
1478
0
  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
1479
0
    {
1480
0
      srel->size += sizeof (Elf64_External_Rela);
1481
0
      h->needs_copy = 1;
1482
0
    }
1483
1484
0
  return _bfd_elf_adjust_dynamic_copy (info, h, s);
1485
0
}
1486
1487
/* Allocate space in .plt, .got and associated reloc sections for
1488
   dynamic relocs.  */
1489
1490
static bool
1491
allocate_dynrelocs (struct elf_link_hash_entry *h,
1492
        void * inf)
1493
0
{
1494
0
  struct bfd_link_info *info;
1495
0
  struct elf_s390_link_hash_table *htab;
1496
0
  struct elf_dyn_relocs *p;
1497
1498
0
  if (h->root.type == bfd_link_hash_indirect)
1499
0
    return true;
1500
1501
0
  info = (struct bfd_link_info *) inf;
1502
0
  htab = elf_s390_hash_table (info);
1503
0
  if (htab == NULL)
1504
0
    return false;
1505
1506
  /* Since STT_GNU_IFUNC symbol must go through PLT, we handle it
1507
     here if it is defined and referenced in a non-shared object.  */
1508
0
  if (s390_is_ifunc_symbol_p (h) && h->def_regular)
1509
0
    return s390_elf_allocate_ifunc_dyn_relocs (info, h);
1510
0
  else if (htab->elf.dynamic_sections_created
1511
0
     && h->plt.refcount > 0)
1512
0
    {
1513
      /* Make sure this symbol is output as a dynamic symbol.
1514
   Undefined weak syms won't yet be marked as dynamic.  */
1515
0
      if (h->dynindx == -1
1516
0
    && !h->forced_local)
1517
0
  {
1518
0
    if (! bfd_elf_link_record_dynamic_symbol (info, h))
1519
0
      return false;
1520
0
  }
1521
1522
0
      if (bfd_link_pic (info)
1523
0
    || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
1524
0
  {
1525
0
    asection *s = htab->elf.splt;
1526
1527
    /* If this is the first .plt entry, make room for the special
1528
       first entry.  */
1529
0
    if (s->size == 0)
1530
0
      s->size += PLT_FIRST_ENTRY_SIZE;
1531
1532
0
    h->plt.offset = s->size;
1533
1534
    /* If this symbol is not defined in a regular file, and we are
1535
       not generating a shared library, then set the symbol to this
1536
       location in the .plt.  This is required to make function
1537
       pointers compare as equal between the normal executable and
1538
       the shared library.  */
1539
0
    if (! bfd_link_pic (info)
1540
0
        && !h->def_regular)
1541
0
      {
1542
0
        h->root.u.def.section = s;
1543
0
        h->root.u.def.value = h->plt.offset;
1544
0
      }
1545
1546
    /* Make room for this entry.  */
1547
0
    s->size += PLT_ENTRY_SIZE;
1548
1549
    /* We also need to make an entry in the .got.plt section.  */
1550
0
    htab->elf.sgotplt->size += GOT_ENTRY_SIZE;
1551
1552
    /* We also need to make an entry in the .rela.plt section.  */
1553
0
    htab->elf.srelplt->size += sizeof (Elf64_External_Rela);
1554
0
  }
1555
0
      else
1556
0
  {
1557
0
    h->plt.offset = (bfd_vma) -1;
1558
0
    h->needs_plt = 0;
1559
0
    elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
1560
0
  }
1561
0
    }
1562
0
  else
1563
0
    {
1564
0
      h->plt.offset = (bfd_vma) -1;
1565
0
      h->needs_plt = 0;
1566
0
      elf_s390_adjust_gotplt((struct elf_s390_link_hash_entry *) h);
1567
0
    }
1568
1569
  /* If R_390_TLS_{IE64,GOTIE64,GOTIE12,IEENT} symbol is now local to
1570
     the binary, we can optimize a bit. IE64 and GOTIE64 get converted
1571
     to R_390_TLS_LE64 requiring no TLS entry. For GOTIE12 and IEENT
1572
     we can save the dynamic TLS relocation.  */
1573
0
  if (h->got.refcount > 0
1574
0
      && !bfd_link_dll (info)
1575
0
      && h->dynindx == -1
1576
0
      && elf_s390_hash_entry(h)->tls_type >= GOT_TLS_IE)
1577
0
    {
1578
0
      if (elf_s390_hash_entry(h)->tls_type == GOT_TLS_IE_NLT)
1579
  /* For the GOTIE access without a literal pool entry the offset has
1580
     to be stored somewhere. The immediate value in the instruction
1581
     is not bit enough so the value is stored in the got.  */
1582
0
  {
1583
0
    h->got.offset = htab->elf.sgot->size;
1584
0
    htab->elf.sgot->size += GOT_ENTRY_SIZE;
1585
0
  }
1586
0
      else
1587
0
  h->got.offset = (bfd_vma) -1;
1588
0
    }
1589
0
  else if (h->got.refcount > 0)
1590
0
    {
1591
0
      asection *s;
1592
0
      bool dyn;
1593
0
      int tls_type = elf_s390_hash_entry(h)->tls_type;
1594
1595
      /* Make sure this symbol is output as a dynamic symbol.
1596
   Undefined weak syms won't yet be marked as dynamic.  */
1597
0
      if (h->dynindx == -1
1598
0
    && !h->forced_local)
1599
0
  {
1600
0
    if (! bfd_elf_link_record_dynamic_symbol (info, h))
1601
0
      return false;
1602
0
  }
1603
1604
0
      s = htab->elf.sgot;
1605
0
      h->got.offset = s->size;
1606
0
      s->size += GOT_ENTRY_SIZE;
1607
      /* R_390_TLS_GD64 needs 2 consecutive GOT slots.  */
1608
0
      if (tls_type == GOT_TLS_GD)
1609
0
  s->size += GOT_ENTRY_SIZE;
1610
0
      dyn = htab->elf.dynamic_sections_created;
1611
      /* R_390_TLS_IE64 needs one dynamic relocation,
1612
   R_390_TLS_GD64 needs one if local symbol and two if global.  */
1613
0
      if ((tls_type == GOT_TLS_GD && h->dynindx == -1)
1614
0
    || tls_type >= GOT_TLS_IE)
1615
0
  htab->elf.srelgot->size += sizeof (Elf64_External_Rela);
1616
0
      else if (tls_type == GOT_TLS_GD)
1617
0
  htab->elf.srelgot->size += 2 * sizeof (Elf64_External_Rela);
1618
0
      else if (!UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)
1619
0
         && (bfd_link_pic (info)
1620
0
       || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
1621
0
  htab->elf.srelgot->size += sizeof (Elf64_External_Rela);
1622
0
    }
1623
0
  else
1624
0
    h->got.offset = (bfd_vma) -1;
1625
1626
0
  if (h->dyn_relocs == NULL)
1627
0
    return true;
1628
1629
  /* In the shared -Bsymbolic case, discard space allocated for
1630
     dynamic pc-relative relocs against symbols which turn out to be
1631
     defined in regular objects.  For the normal shared case, discard
1632
     space for pc-relative relocs that have become local due to symbol
1633
     visibility changes.  */
1634
1635
0
  if (bfd_link_pic (info))
1636
0
    {
1637
0
      if (SYMBOL_CALLS_LOCAL (info, h))
1638
0
  {
1639
0
    struct elf_dyn_relocs **pp;
1640
1641
0
    for (pp = &h->dyn_relocs; (p = *pp) != NULL; )
1642
0
      {
1643
0
        p->count -= p->pc_count;
1644
0
        p->pc_count = 0;
1645
0
        if (p->count == 0)
1646
0
    *pp = p->next;
1647
0
        else
1648
0
    pp = &p->next;
1649
0
      }
1650
0
  }
1651
1652
      /* Also discard relocs on undefined weak syms with non-default
1653
   visibility.  */
1654
0
      if (h->dyn_relocs != NULL
1655
0
    && h->root.type == bfd_link_hash_undefweak)
1656
0
  {
1657
0
    if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
1658
0
        || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
1659
0
      h->dyn_relocs = NULL;
1660
1661
    /* Make sure undefined weak symbols are output as a dynamic
1662
       symbol in PIEs.  */
1663
0
    else if (h->dynindx == -1
1664
0
       && !h->forced_local)
1665
0
      {
1666
0
        if (! bfd_elf_link_record_dynamic_symbol (info, h))
1667
0
    return false;
1668
0
      }
1669
0
  }
1670
0
    }
1671
0
  else if (ELIMINATE_COPY_RELOCS)
1672
0
    {
1673
      /* For the non-shared case, discard space for relocs against
1674
   symbols which turn out to need copy relocs or are not
1675
   dynamic.  */
1676
1677
0
      if (!h->non_got_ref
1678
0
    && ((h->def_dynamic
1679
0
         && !h->def_regular)
1680
0
        || (htab->elf.dynamic_sections_created
1681
0
      && (h->root.type == bfd_link_hash_undefweak
1682
0
          || h->root.type == bfd_link_hash_undefined))))
1683
0
  {
1684
    /* Make sure this symbol is output as a dynamic symbol.
1685
       Undefined weak syms won't yet be marked as dynamic.  */
1686
0
    if (h->dynindx == -1
1687
0
        && !h->forced_local)
1688
0
      {
1689
0
        if (! bfd_elf_link_record_dynamic_symbol (info, h))
1690
0
    return false;
1691
0
      }
1692
1693
    /* If that succeeded, we know we'll be keeping all the
1694
       relocs.  */
1695
0
    if (h->dynindx != -1)
1696
0
      goto keep;
1697
0
  }
1698
1699
0
      h->dyn_relocs = NULL;
1700
1701
0
    keep: ;
1702
0
    }
1703
1704
  /* Finally, allocate space.  */
1705
0
  for (p = h->dyn_relocs; p != NULL; p = p->next)
1706
0
    {
1707
0
      asection *sreloc = elf_section_data (p->sec)->sreloc;
1708
0
      sreloc->size += p->count * sizeof (Elf64_External_Rela);
1709
0
    }
1710
1711
0
  return true;
1712
0
}
1713
1714
/* Set the sizes of the dynamic sections.  */
1715
1716
static bool
1717
elf_s390_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
1718
        struct bfd_link_info *info)
1719
0
{
1720
0
  struct elf_s390_link_hash_table *htab;
1721
0
  bfd *dynobj;
1722
0
  asection *s;
1723
0
  bool relocs;
1724
0
  bfd *ibfd;
1725
1726
0
  htab = elf_s390_hash_table (info);
1727
0
  if (htab == NULL)
1728
0
    return false;
1729
1730
0
  dynobj = htab->elf.dynobj;
1731
0
  if (dynobj == NULL)
1732
0
    abort ();
1733
1734
0
  if (htab->elf.dynamic_sections_created)
1735
0
    {
1736
      /* Set the contents of the .interp section to the interpreter.  */
1737
0
      if (bfd_link_executable (info) && !info->nointerp)
1738
0
  {
1739
0
    s = bfd_get_linker_section (dynobj, ".interp");
1740
0
    if (s == NULL)
1741
0
      abort ();
1742
0
    s->size = sizeof ELF_DYNAMIC_INTERPRETER;
1743
0
    s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
1744
0
  }
1745
0
    }
1746
1747
0
  if (htab->elf.sgot && s390_gotplt_after_got_p (info))
1748
0
    {
1749
      /* _bfd_elf_create_got_section adds the got header size always
1750
   to .got.plt but we need it in .got if this section comes
1751
   first.  */
1752
0
      htab->elf.sgot->size += 3 * GOT_ENTRY_SIZE;
1753
0
      htab->elf.sgotplt->size -= 3 * GOT_ENTRY_SIZE;
1754
1755
      /* Make the _GLOBAL_OFFSET_TABLE_ symbol point to the .got
1756
   instead of .got.plt.  */
1757
0
      htab->elf.hgot->root.u.def.section = htab->elf.sgot;
1758
0
      htab->elf.hgot->root.u.def.value = 0;
1759
0
    }
1760
1761
  /* Set up .got offsets for local syms, and space for local dynamic
1762
     relocs.  */
1763
0
  for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
1764
0
    {
1765
0
      bfd_signed_vma *local_got;
1766
0
      bfd_signed_vma *end_local_got;
1767
0
      char *local_tls_type;
1768
0
      bfd_size_type locsymcount;
1769
0
      Elf_Internal_Shdr *symtab_hdr;
1770
0
      asection *srela;
1771
0
      struct plt_entry *local_plt;
1772
0
      unsigned int i;
1773
1774
0
      if (! is_s390_elf (ibfd))
1775
0
  continue;
1776
1777
0
      for (s = ibfd->sections; s != NULL; s = s->next)
1778
0
  {
1779
0
    struct elf_dyn_relocs *p;
1780
1781
0
    for (p = elf_section_data (s)->local_dynrel; p != NULL; p = p->next)
1782
0
      {
1783
0
        if (!bfd_is_abs_section (p->sec)
1784
0
      && bfd_is_abs_section (p->sec->output_section))
1785
0
    {
1786
      /* Input section has been discarded, either because
1787
         it is a copy of a linkonce section or due to
1788
         linker script /DISCARD/, so we'll be discarding
1789
         the relocs too.  */
1790
0
    }
1791
0
        else if (p->count != 0)
1792
0
    {
1793
0
      srela = elf_section_data (p->sec)->sreloc;
1794
0
      srela->size += p->count * sizeof (Elf64_External_Rela);
1795
0
      if ((p->sec->output_section->flags & SEC_READONLY) != 0)
1796
0
        info->flags |= DF_TEXTREL;
1797
0
    }
1798
0
      }
1799
0
  }
1800
1801
0
      local_got = elf_local_got_refcounts (ibfd);
1802
0
      if (!local_got)
1803
0
  continue;
1804
1805
0
      symtab_hdr = &elf_symtab_hdr (ibfd);
1806
0
      locsymcount = symtab_hdr->sh_info;
1807
0
      end_local_got = local_got + locsymcount;
1808
0
      local_tls_type = elf_s390_local_got_tls_type (ibfd);
1809
0
      s = htab->elf.sgot;
1810
0
      srela = htab->elf.srelgot;
1811
0
      for (; local_got < end_local_got; ++local_got, ++local_tls_type)
1812
0
  {
1813
0
    if (*local_got > 0)
1814
0
      {
1815
0
        *local_got = s->size;
1816
0
        s->size += GOT_ENTRY_SIZE;
1817
0
        if (*local_tls_type == GOT_TLS_GD)
1818
0
    s->size += GOT_ENTRY_SIZE;
1819
0
        if (bfd_link_pic (info))
1820
0
    srela->size += sizeof (Elf64_External_Rela);
1821
0
      }
1822
0
    else
1823
0
      *local_got = (bfd_vma) -1;
1824
0
  }
1825
1826
0
      local_plt = elf_s390_local_plt (ibfd);
1827
0
      for (i = 0; i < symtab_hdr->sh_info; i++)
1828
0
  {
1829
0
    if (local_plt[i].plt.refcount > 0)
1830
0
      {
1831
0
        local_plt[i].plt.offset = htab->elf.iplt->size;
1832
0
        htab->elf.iplt->size += PLT_ENTRY_SIZE;
1833
0
        htab->elf.igotplt->size += GOT_ENTRY_SIZE;
1834
0
        htab->elf.irelplt->size += sizeof (Elf64_External_Rela);
1835
0
      }
1836
0
    else
1837
0
      local_plt[i].plt.offset = (bfd_vma) -1;
1838
0
  }
1839
0
    }
1840
1841
0
  if (htab->tls_ldm_got.refcount > 0)
1842
0
    {
1843
      /* Allocate 2 got entries and 1 dynamic reloc for R_390_TLS_LDM64
1844
   relocs.  */
1845
0
      htab->tls_ldm_got.offset = htab->elf.sgot->size;
1846
0
      htab->elf.sgot->size += 2 * GOT_ENTRY_SIZE;
1847
0
      htab->elf.srelgot->size += sizeof (Elf64_External_Rela);
1848
0
    }
1849
0
  else
1850
0
    htab->tls_ldm_got.offset = -1;
1851
1852
  /* Allocate global sym .plt and .got entries, and space for global
1853
     sym dynamic relocs.  */
1854
0
  elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, info);
1855
1856
  /* We now have determined the sizes of the various dynamic sections.
1857
     Allocate memory for them.  */
1858
0
  relocs = false;
1859
0
  for (s = dynobj->sections; s != NULL; s = s->next)
1860
0
    {
1861
0
      if ((s->flags & SEC_LINKER_CREATED) == 0)
1862
0
  continue;
1863
1864
0
      if (s == htab->elf.splt
1865
0
    || s == htab->elf.sgot
1866
0
    || s == htab->elf.sgotplt
1867
0
    || s == htab->elf.sdynbss
1868
0
    || s == htab->elf.sdynrelro
1869
0
    || s == htab->elf.iplt
1870
0
    || s == htab->elf.igotplt
1871
0
    || s == htab->irelifunc)
1872
0
  {
1873
    /* Strip this section if we don't need it; see the
1874
       comment below.  */
1875
0
  }
1876
0
      else if (startswith (bfd_section_name (s), ".rela"))
1877
0
  {
1878
0
    if (s->size != 0 && s != htab->elf.srelplt)
1879
0
      {
1880
0
        relocs = true;
1881
0
        if (s == htab->elf.irelplt)
1882
0
    {
1883
      /* In static-pie case, there are IRELATIVE-relocs in
1884
         .rela.iplt (htab->irelplt), which will later be grouped
1885
         to .rela.plt.  On s390, the IRELATIVE relocations are
1886
         always located in .rela.iplt - even for non-static case.
1887
         Ensure that DT_JMPREL, DT_PLTRELA, DT_PLTRELASZ is added
1888
         to the dynamic section even if htab->srelplt->size == 0.
1889
         See _bfd_elf_add_dynamic_tags in bfd/elflink.c.  */
1890
0
      htab->elf.dt_jmprel_required = true;
1891
0
    }
1892
0
      }
1893
1894
    /* We use the reloc_count field as a counter if we need
1895
       to copy relocs into the output file.  */
1896
0
    s->reloc_count = 0;
1897
0
  }
1898
0
      else
1899
0
  {
1900
    /* It's not one of our sections, so don't allocate space.  */
1901
0
    continue;
1902
0
  }
1903
1904
0
      if (s->size == 0)
1905
0
  {
1906
    /* If we don't need this section, strip it from the
1907
       output file.  This is to handle .rela.bss and
1908
       .rela.plt.  We must create it in
1909
       create_dynamic_sections, because it must be created
1910
       before the linker maps input sections to output
1911
       sections.  The linker does that before
1912
       adjust_dynamic_symbol is called, and it is that
1913
       function which decides whether anything needs to go
1914
       into these sections.  */
1915
1916
0
    s->flags |= SEC_EXCLUDE;
1917
0
    continue;
1918
0
  }
1919
1920
0
      if ((s->flags & SEC_HAS_CONTENTS) == 0)
1921
0
  continue;
1922
1923
      /* Allocate memory for the section contents.  We use bfd_zalloc
1924
   here in case unused entries are not reclaimed before the
1925
   section's contents are written out.  This should not happen,
1926
   but this way if it does, we get a R_390_NONE reloc instead
1927
   of garbage.  */
1928
0
      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
1929
0
      if (s->contents == NULL)
1930
0
  return false;
1931
0
    }
1932
1933
0
  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
1934
0
}
1935
1936
/* Return the base VMA address which should be subtracted from real addresses
1937
   when resolving @dtpoff relocation.
1938
   This is PT_TLS segment p_vaddr.  */
1939
1940
static bfd_vma
1941
dtpoff_base (struct bfd_link_info *info)
1942
0
{
1943
  /* If tls_sec is NULL, we should have signalled an error already.  */
1944
0
  if (elf_hash_table (info)->tls_sec == NULL)
1945
0
    return 0;
1946
0
  return elf_hash_table (info)->tls_sec->vma;
1947
0
}
1948
1949
/* Return the relocation value for @tpoff relocation
1950
   if STT_TLS virtual address is ADDRESS.  */
1951
1952
static bfd_vma
1953
tpoff (struct bfd_link_info *info, bfd_vma address)
1954
0
{
1955
0
  struct elf_link_hash_table *htab = elf_hash_table (info);
1956
1957
  /* If tls_sec is NULL, we should have signalled an error already.  */
1958
0
  if (htab->tls_sec == NULL)
1959
0
    return 0;
1960
0
  return htab->tls_size + htab->tls_sec->vma - address;
1961
0
}
1962
1963
/* Complain if TLS instruction relocation is against an invalid
1964
   instruction.  */
1965
1966
static void
1967
invalid_tls_insn (bfd *input_bfd,
1968
      asection *input_section,
1969
      Elf_Internal_Rela *rel)
1970
0
{
1971
0
  reloc_howto_type *howto;
1972
1973
0
  howto = elf_howto_table + ELF64_R_TYPE (rel->r_info);
1974
0
  _bfd_error_handler
1975
    /* xgettext:c-format */
1976
0
    (_("%pB(%pA+%#" PRIx64 "): invalid instruction for TLS relocation %s"),
1977
0
     input_bfd,
1978
0
     input_section,
1979
0
     (uint64_t) rel->r_offset,
1980
0
     howto->name);
1981
0
  bfd_set_error (bfd_error_bad_value);
1982
0
}
1983
1984
/* Relocate a 390 ELF section.  */
1985
1986
static int
1987
elf_s390_relocate_section (bfd *output_bfd,
1988
         struct bfd_link_info *info,
1989
         bfd *input_bfd,
1990
         asection *input_section,
1991
         bfd_byte *contents,
1992
         Elf_Internal_Rela *relocs,
1993
         Elf_Internal_Sym *local_syms,
1994
         asection **local_sections)
1995
0
{
1996
0
  struct elf_s390_link_hash_table *htab;
1997
0
  Elf_Internal_Shdr *symtab_hdr;
1998
0
  struct elf_link_hash_entry **sym_hashes;
1999
0
  bfd_vma *local_got_offsets;
2000
0
  Elf_Internal_Rela *rel;
2001
0
  Elf_Internal_Rela *relend;
2002
2003
0
  if (!is_s390_elf (input_bfd))
2004
0
    {
2005
0
      bfd_set_error (bfd_error_wrong_format);
2006
0
      return false;
2007
0
    }
2008
2009
0
  htab = elf_s390_hash_table (info);
2010
0
  if (htab == NULL)
2011
0
    return false;
2012
2013
0
  symtab_hdr = &elf_symtab_hdr (input_bfd);
2014
0
  sym_hashes = elf_sym_hashes (input_bfd);
2015
0
  local_got_offsets = elf_local_got_offsets (input_bfd);
2016
2017
0
  rel = relocs;
2018
0
  relend = relocs + input_section->reloc_count;
2019
0
  for (; rel < relend; rel++)
2020
0
    {
2021
0
      unsigned int r_type;
2022
0
      reloc_howto_type *howto;
2023
0
      unsigned long r_symndx;
2024
0
      struct elf_link_hash_entry *h;
2025
0
      Elf_Internal_Sym *sym;
2026
0
      asection *sec;
2027
0
      bfd_vma off;
2028
0
      bfd_vma relocation;
2029
0
      bool unresolved_reloc;
2030
0
      bfd_reloc_status_type r;
2031
0
      int tls_type;
2032
0
      bool resolved_to_zero;
2033
2034
0
      r_type = ELF64_R_TYPE (rel->r_info);
2035
0
      if (r_type == (int) R_390_GNU_VTINHERIT
2036
0
    || r_type == (int) R_390_GNU_VTENTRY)
2037
0
  continue;
2038
0
      if (r_type >= (int) R_390_max)
2039
0
  {
2040
0
    bfd_set_error (bfd_error_bad_value);
2041
0
    return false;
2042
0
  }
2043
2044
0
      howto = elf_howto_table + r_type;
2045
0
      r_symndx = ELF64_R_SYM (rel->r_info);
2046
2047
0
      h = NULL;
2048
0
      sym = NULL;
2049
0
      sec = NULL;
2050
0
      unresolved_reloc = false;
2051
0
      if (r_symndx < symtab_hdr->sh_info)
2052
0
  {
2053
0
    sym = local_syms + r_symndx;
2054
0
    sec = local_sections[r_symndx];
2055
2056
0
    if (ELF_ST_TYPE (sym->st_info) == STT_GNU_IFUNC)
2057
0
      {
2058
0
        struct plt_entry *local_plt = elf_s390_local_plt (input_bfd);
2059
0
        if (local_plt == NULL)
2060
0
    return false;
2061
2062
        /* Address of the PLT slot.  */
2063
0
        relocation = (htab->elf.iplt->output_section->vma
2064
0
          + htab->elf.iplt->output_offset
2065
0
          + local_plt[r_symndx].plt.offset);
2066
2067
0
        switch (r_type)
2068
0
    {
2069
0
    case R_390_PLTOFF16:
2070
0
    case R_390_PLTOFF32:
2071
0
    case R_390_PLTOFF64:
2072
0
      relocation -= s390_got_pointer (info);
2073
0
      break;
2074
0
    case R_390_GOTPLT12:
2075
0
    case R_390_GOTPLT16:
2076
0
    case R_390_GOTPLT20:
2077
0
    case R_390_GOTPLT32:
2078
0
    case R_390_GOTPLT64:
2079
0
    case R_390_GOTPLTENT:
2080
0
    case R_390_GOT12:
2081
0
    case R_390_GOT16:
2082
0
    case R_390_GOT20:
2083
0
    case R_390_GOT32:
2084
0
    case R_390_GOT64:
2085
0
    case R_390_GOTENT:
2086
0
      {
2087
        /* Write the PLT slot address into the GOT slot.  */
2088
0
        bfd_put_64 (output_bfd, relocation,
2089
0
        htab->elf.sgot->contents +
2090
0
        local_got_offsets[r_symndx]);
2091
0
        relocation = (local_got_offsets[r_symndx] +
2092
0
          s390_got_offset (info));
2093
2094
0
        if (r_type == R_390_GOTENT || r_type == R_390_GOTPLTENT)
2095
0
          relocation += s390_got_pointer (info);
2096
0
        break;
2097
0
      }
2098
0
    default:
2099
0
      break;
2100
0
    }
2101
        /* The output section is needed later in
2102
     finish_dynamic_section when creating the dynamic
2103
     relocation.  */
2104
0
        local_plt[r_symndx].sec = sec;
2105
0
        goto do_relocation;
2106
0
      }
2107
0
    else
2108
0
      relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
2109
0
  }
2110
0
      else
2111
0
  {
2112
0
    bool warned ATTRIBUTE_UNUSED;
2113
0
    bool ignored ATTRIBUTE_UNUSED;
2114
2115
0
    RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
2116
0
           r_symndx, symtab_hdr, sym_hashes,
2117
0
           h, sec, relocation,
2118
0
           unresolved_reloc, warned, ignored);
2119
0
  }
2120
2121
0
      if (sec != NULL && discarded_section (sec))
2122
0
  RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
2123
0
           rel, 1, relend, howto, 0, contents);
2124
2125
0
      if (bfd_link_relocatable (info))
2126
0
  continue;
2127
2128
0
      resolved_to_zero = (h != NULL
2129
0
        && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
2130
2131
0
      switch (r_type)
2132
0
  {
2133
0
  case R_390_GOTPLT12:
2134
0
  case R_390_GOTPLT16:
2135
0
  case R_390_GOTPLT20:
2136
0
  case R_390_GOTPLT32:
2137
0
  case R_390_GOTPLT64:
2138
0
  case R_390_GOTPLTENT:
2139
    /* There are three cases for a GOTPLT relocation. 1) The
2140
       relocation is against the jump slot entry of a plt that
2141
       will get emitted to the output file. 2) The relocation
2142
       is against the jump slot of a plt entry that has been
2143
       removed. elf_s390_adjust_gotplt has created a GOT entry
2144
       as replacement. 3) The relocation is against a local symbol.
2145
       Cases 2) and 3) are the same as the GOT relocation code
2146
       so we just have to test for case 1 and fall through for
2147
       the other two.  */
2148
0
    if (h != NULL && h->plt.offset != (bfd_vma) -1)
2149
0
      {
2150
0
        bfd_vma plt_index;
2151
2152
0
        if (s390_is_ifunc_symbol_p (h))
2153
0
    {
2154
      /* Entry indices of .iplt and .igot.plt match
2155
         1:1. No magic PLT first entry here.  */
2156
0
      plt_index = h->plt.offset / PLT_ENTRY_SIZE;
2157
0
      relocation = (plt_index * GOT_ENTRY_SIZE
2158
0
        + s390_gotplt_offset (info)
2159
0
        + htab->elf.igotplt->output_offset);
2160
0
    }
2161
0
        else
2162
0
    {
2163
0
      plt_index = ((h->plt.offset - PLT_FIRST_ENTRY_SIZE)
2164
0
             / PLT_ENTRY_SIZE);
2165
2166
0
      relocation = (plt_index * GOT_ENTRY_SIZE
2167
0
        + s390_gotplt_offset (info));
2168
0
    }
2169
0
        if (r_type == R_390_GOTPLTENT)
2170
0
    relocation += s390_got_pointer (info);
2171
0
        unresolved_reloc = false;
2172
0
        break;
2173
0
      }
2174
    /* Fall through.  */
2175
2176
0
  case R_390_GOT12:
2177
0
  case R_390_GOT16:
2178
0
  case R_390_GOT20:
2179
0
  case R_390_GOT32:
2180
0
  case R_390_GOT64:
2181
0
  case R_390_GOTENT:
2182
    /* Relocation is to the entry for this symbol in the global
2183
       offset table.  */
2184
0
    if (htab->elf.sgot == NULL)
2185
0
      abort ();
2186
2187
0
    if (h != NULL)
2188
0
      {
2189
0
        bool dyn;
2190
2191
0
        off = h->got.offset;
2192
0
        dyn = htab->elf.dynamic_sections_created;
2193
2194
0
        if (s390_is_ifunc_symbol_p (h))
2195
0
    {
2196
0
      BFD_ASSERT (h->plt.offset != (bfd_vma) -1);
2197
0
      if (off == (bfd_vma)-1)
2198
0
        {
2199
          /* No explicit GOT usage so redirect to the
2200
       got.iplt slot.  */
2201
0
          relocation = (s390_gotplt_offset (info)
2202
0
            + htab->elf.igotplt->output_offset
2203
0
            + (h->plt.offset / PLT_ENTRY_SIZE
2204
0
               * GOT_ENTRY_SIZE));
2205
2206
          /* For @GOTENT the relocation is against the offset between
2207
       the instruction and the symbols entry in the GOT and not
2208
       between the start of the GOT and the symbols entry. We
2209
       add the vma of the GOT to get the correct value.  */
2210
0
          if (r_type == R_390_GOTENT || r_type == R_390_GOTPLTENT)
2211
0
      relocation += s390_got_pointer (info);
2212
2213
0
          break;
2214
0
        }
2215
0
      else
2216
0
        {
2217
          /* Explicit GOT slots must contain the address
2218
       of the PLT slot. This will be handled in
2219
       finish_dynamic_symbol.  */
2220
0
        }
2221
0
    }
2222
0
        else if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
2223
0
                bfd_link_pic (info),
2224
0
                h)
2225
0
           || (bfd_link_pic (info)
2226
0
         && SYMBOL_REFERENCES_LOCAL (info, h))
2227
0
           || resolved_to_zero)
2228
0
    {
2229
0
      Elf_Internal_Sym *isym;
2230
0
      asection *sym_sec;
2231
2232
      /* This is actually a static link, or it is a
2233
         -Bsymbolic link and the symbol is defined
2234
         locally, or the symbol was forced to be local
2235
         because of a version file.  We must initialize
2236
         this entry in the global offset table.  Since the
2237
         offset must always be a multiple of 2, we use the
2238
         least significant bit to record whether we have
2239
         initialized it already.
2240
2241
         When doing a dynamic link, we create a .rel.got
2242
         relocation entry to initialize the value.  This
2243
         is done in the finish_dynamic_symbol routine.  */
2244
0
      if ((off & 1) != 0)
2245
0
        off &= ~1;
2246
0
      else
2247
0
        {
2248
0
          bfd_put_64 (output_bfd, relocation,
2249
0
          htab->elf.sgot->contents + off);
2250
0
          h->got.offset |= 1;
2251
0
        }
2252
2253
      /* When turning a GOT slot dereference into a direct
2254
         reference using larl we have to make sure that
2255
         the symbol is 1. properly aligned and 2. it is no
2256
         ABS symbol or will become one.  */
2257
0
      if ((h->def_regular
2258
0
           && bfd_link_pic (info)
2259
0
           && SYMBOL_REFERENCES_LOCAL (info, h))
2260
          /* lgrl rx,sym@GOTENT -> larl rx, sym */
2261
0
          && ((r_type == R_390_GOTENT
2262
0
         && (bfd_get_16 (input_bfd,
2263
0
             contents + rel->r_offset - 2)
2264
0
             & 0xff0f) == 0xc408)
2265
        /* lg rx, sym@GOT(r12) -> larl rx, sym */
2266
0
        || (r_type == R_390_GOT20
2267
0
            && (bfd_get_32 (input_bfd,
2268
0
                contents + rel->r_offset - 2)
2269
0
          & 0xff00f000) == 0xe300c000
2270
0
            && bfd_get_8 (input_bfd,
2271
0
              contents + rel->r_offset + 3) == 0x04))
2272
0
          && (isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache,
2273
0
              input_bfd, r_symndx))
2274
0
          && isym->st_shndx != SHN_ABS
2275
0
          && h != htab->elf.hdynamic
2276
0
          && h != htab->elf.hgot
2277
0
          && h != htab->elf.hplt
2278
0
          && !(isym->st_value & 1)
2279
0
          && (sym_sec = bfd_section_from_elf_index (input_bfd,
2280
0
                isym->st_shndx))
2281
0
          && sym_sec->alignment_power)
2282
0
        {
2283
0
          unsigned short new_insn =
2284
0
      (0xc000 | (bfd_get_8 (input_bfd,
2285
0
                contents + rel->r_offset - 1) & 0xf0));
2286
0
          bfd_put_16 (output_bfd, new_insn,
2287
0
          contents + rel->r_offset - 2);
2288
0
          r_type = R_390_PC32DBL;
2289
0
          rel->r_addend = 2;
2290
0
          howto = elf_howto_table + r_type;
2291
0
          relocation = h->root.u.def.value
2292
0
      + h->root.u.def.section->output_section->vma
2293
0
      + h->root.u.def.section->output_offset;
2294
0
          goto do_relocation;
2295
0
        }
2296
0
    }
2297
0
        else
2298
0
    unresolved_reloc = false;
2299
0
      }
2300
0
    else
2301
0
      {
2302
0
        if (local_got_offsets == NULL)
2303
0
    abort ();
2304
2305
0
        off = local_got_offsets[r_symndx];
2306
2307
        /* The offset must always be a multiple of 8.  We use
2308
     the least significant bit to record whether we have
2309
     already generated the necessary reloc.  */
2310
0
        if ((off & 1) != 0)
2311
0
    off &= ~1;
2312
0
        else
2313
0
    {
2314
0
      bfd_put_64 (output_bfd, relocation,
2315
0
            htab->elf.sgot->contents + off);
2316
2317
0
      if (bfd_link_pic (info))
2318
0
        {
2319
0
          asection *s;
2320
0
          Elf_Internal_Rela outrel;
2321
0
          bfd_byte *loc;
2322
2323
0
          s = htab->elf.srelgot;
2324
0
          if (s == NULL)
2325
0
      abort ();
2326
2327
0
          outrel.r_offset = (htab->elf.sgot->output_section->vma
2328
0
           + htab->elf.sgot->output_offset
2329
0
           + off);
2330
0
          outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
2331
0
          outrel.r_addend = relocation;
2332
0
          loc = s->contents;
2333
0
          loc += s->reloc_count++ * sizeof (Elf64_External_Rela);
2334
0
          bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
2335
0
        }
2336
2337
0
      local_got_offsets[r_symndx] |= 1;
2338
0
    }
2339
0
      }
2340
2341
0
    if (off >= (bfd_vma) -2)
2342
0
      abort ();
2343
2344
0
    relocation = s390_got_offset (info) + off;
2345
2346
    /* For @GOTENT the relocation is against the offset between
2347
       the instruction and the symbols entry in the GOT and not
2348
       between the start of the GOT and the symbols entry. We
2349
       add the vma of the GOT to get the correct value.  */
2350
0
    if (   r_type == R_390_GOTENT
2351
0
        || r_type == R_390_GOTPLTENT)
2352
0
      relocation += s390_got_pointer (info);
2353
2354
0
    break;
2355
2356
0
  case R_390_GOTOFF16:
2357
0
  case R_390_GOTOFF32:
2358
0
  case R_390_GOTOFF64:
2359
    /* Relocation is relative to the start of the global offset
2360
       table.  */
2361
2362
0
    if (h != NULL
2363
0
        && s390_is_ifunc_symbol_p (h)
2364
0
        && h->def_regular
2365
0
        && !bfd_link_executable (info))
2366
0
      {
2367
0
        relocation = (htab->elf.iplt->output_section->vma
2368
0
          + htab->elf.iplt->output_offset
2369
0
          + h->plt.offset
2370
0
          - s390_got_pointer (info));
2371
0
        goto do_relocation;
2372
0
      }
2373
2374
0
    relocation -= s390_got_pointer (info);
2375
0
    break;
2376
2377
0
  case R_390_GOTPC:
2378
0
  case R_390_GOTPCDBL:
2379
    /* Use global offset table as symbol value.  */
2380
0
    relocation = s390_got_pointer (info);
2381
0
    unresolved_reloc = false;
2382
0
    break;
2383
2384
0
  case R_390_PLT12DBL:
2385
0
  case R_390_PLT16DBL:
2386
0
  case R_390_PLT24DBL:
2387
0
  case R_390_PLT32:
2388
0
  case R_390_PLT32DBL:
2389
0
  case R_390_PLT64:
2390
    /* Relocation is to the entry for this symbol in the
2391
       procedure linkage table.  */
2392
2393
    /* Resolve a PLT32 reloc against a local symbol directly,
2394
       without using the procedure linkage table.  */
2395
0
    if (h == NULL)
2396
0
      break;
2397
2398
0
    if (h->plt.offset == (bfd_vma) -1
2399
0
        || (htab->elf.splt == NULL && !s390_is_ifunc_symbol_p (h)))
2400
0
      {
2401
        /* We didn't make a PLT entry for this symbol.  This
2402
     happens when statically linking PIC code, or when
2403
     using -Bsymbolic.  */
2404
0
        break;
2405
0
      }
2406
0
    if (s390_is_ifunc_symbol_p (h))
2407
0
      relocation = (htab->elf.iplt->output_section->vma
2408
0
        + htab->elf.iplt->output_offset
2409
0
        + h->plt.offset);
2410
0
    else
2411
0
      relocation = (htab->elf.splt->output_section->vma
2412
0
        + htab->elf.splt->output_offset
2413
0
        + h->plt.offset);
2414
0
    unresolved_reloc = false;
2415
0
    break;
2416
2417
0
  case R_390_PLTOFF16:
2418
0
  case R_390_PLTOFF32:
2419
0
  case R_390_PLTOFF64:
2420
    /* Relocation is to the entry for this symbol in the
2421
       procedure linkage table relative to the start of the GOT.  */
2422
2423
    /* For local symbols or if we didn't make a PLT entry for
2424
       this symbol resolve the symbol directly.  */
2425
0
    if (h == NULL
2426
0
        || h->plt.offset == (bfd_vma) -1
2427
0
        || (htab->elf.splt == NULL && !s390_is_ifunc_symbol_p (h)))
2428
0
      {
2429
0
        relocation -= s390_got_pointer (info);
2430
0
        break;
2431
0
      }
2432
2433
0
    if (s390_is_ifunc_symbol_p (h))
2434
0
      relocation = (htab->elf.iplt->output_section->vma
2435
0
        + htab->elf.iplt->output_offset
2436
0
        + h->plt.offset
2437
0
        - s390_got_pointer (info));
2438
0
    else
2439
0
      relocation = (htab->elf.splt->output_section->vma
2440
0
        + htab->elf.splt->output_offset
2441
0
        + h->plt.offset
2442
0
        - s390_got_pointer (info));
2443
0
    unresolved_reloc = false;
2444
0
    break;
2445
2446
0
  case R_390_PC16:
2447
0
  case R_390_PC12DBL:
2448
0
  case R_390_PC16DBL:
2449
0
  case R_390_PC24DBL:
2450
0
  case R_390_PC32:
2451
0
  case R_390_PC32DBL:
2452
0
  case R_390_PC64:
2453
0
    if (h != NULL
2454
0
        && bfd_link_pie (info)
2455
0
        && !h->def_regular)
2456
0
      {
2457
0
        _bfd_error_handler (_("%pB: `%s' non-PLT reloc for symbol defined "
2458
0
            "in shared library and accessed "
2459
0
            "from executable "
2460
0
            "(rebuild file with -fPIC ?)"),
2461
0
          input_bfd, h->root.root.string);
2462
0
        bfd_set_error (bfd_error_bad_value);
2463
0
        return false;
2464
0
      }
2465
    /* The target of these relocs are instruction operands
2466
       residing in read-only sections.  We cannot emit a runtime
2467
       reloc for it.  */
2468
0
    if (h != NULL
2469
0
        && s390_is_ifunc_symbol_p (h)
2470
0
        && h->def_regular
2471
0
        && bfd_link_pic (info))
2472
0
      {
2473
0
        relocation = (htab->elf.iplt->output_section->vma
2474
0
          + htab->elf.iplt->output_offset
2475
0
          + h->plt.offset);
2476
0
        goto do_relocation;
2477
0
      }
2478
    /* Fall through.  */
2479
2480
0
  case R_390_8:
2481
0
  case R_390_16:
2482
0
  case R_390_32:
2483
0
  case R_390_64:
2484
2485
0
    if ((input_section->flags & SEC_ALLOC) == 0)
2486
0
      break;
2487
2488
0
    if (h != NULL
2489
0
        && s390_is_ifunc_symbol_p (h)
2490
0
        && h->def_regular)
2491
0
      {
2492
0
        if (!bfd_link_pic (info))
2493
0
    {
2494
      /* For a non-shared object the symbol will not
2495
         change.  Hence we can write the address of the
2496
         target IPLT slot now.  */
2497
0
      relocation = (htab->elf.iplt->output_section->vma
2498
0
        + htab->elf.iplt->output_offset
2499
0
        + h ->plt.offset);
2500
0
      goto do_relocation;
2501
0
    }
2502
0
        else
2503
0
    {
2504
      /* For shared objects a runtime relocation is needed.  */
2505
2506
0
      Elf_Internal_Rela outrel;
2507
0
      asection *sreloc;
2508
2509
      /* Need a dynamic relocation to get the real function
2510
         address.  */
2511
0
      outrel.r_offset = _bfd_elf_section_offset (output_bfd,
2512
0
                   info,
2513
0
                   input_section,
2514
0
                   rel->r_offset);
2515
0
      if (outrel.r_offset == (bfd_vma) -1
2516
0
          || outrel.r_offset == (bfd_vma) -2)
2517
0
        abort ();
2518
2519
0
      outrel.r_offset += (input_section->output_section->vma
2520
0
              + input_section->output_offset);
2521
2522
0
      if (h->dynindx == -1
2523
0
          || h->forced_local
2524
0
          || bfd_link_executable (info))
2525
0
        {
2526
          /* This symbol is resolved locally.  */
2527
0
          outrel.r_info = ELF64_R_INFO (0, R_390_IRELATIVE);
2528
0
          outrel.r_addend = (h->root.u.def.value
2529
0
           + h->root.u.def.section->output_section->vma
2530
0
           + h->root.u.def.section->output_offset);
2531
0
        }
2532
0
      else
2533
0
        {
2534
0
          outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
2535
0
          outrel.r_addend = 0;
2536
0
        }
2537
2538
0
      sreloc = htab->elf.irelifunc;
2539
0
      elf_append_rela (output_bfd, sreloc, &outrel);
2540
2541
      /* If this reloc is against an external symbol, we
2542
         do not want to fiddle with the addend.  Otherwise,
2543
         we need to include the symbol value so that it
2544
         becomes an addend for the dynamic reloc.  For an
2545
         internal symbol, we have updated addend.  */
2546
0
      continue;
2547
0
    }
2548
0
      }
2549
2550
0
    if ((bfd_link_pic (info)
2551
0
         && (h == NULL
2552
0
       || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
2553
0
           && !resolved_to_zero)
2554
0
       || h->root.type != bfd_link_hash_undefweak)
2555
0
         && ((r_type != R_390_PC16
2556
0
        && r_type != R_390_PC12DBL
2557
0
        && r_type != R_390_PC16DBL
2558
0
        && r_type != R_390_PC24DBL
2559
0
        && r_type != R_390_PC32
2560
0
        && r_type != R_390_PC32DBL
2561
0
        && r_type != R_390_PC64)
2562
0
       || !SYMBOL_CALLS_LOCAL (info, h)))
2563
0
        || (ELIMINATE_COPY_RELOCS
2564
0
      && !bfd_link_pic (info)
2565
0
      && h != NULL
2566
0
      && h->dynindx != -1
2567
0
      && !h->non_got_ref
2568
0
      && ((h->def_dynamic
2569
0
           && !h->def_regular)
2570
0
          || h->root.type == bfd_link_hash_undefweak
2571
0
          || h->root.type == bfd_link_hash_undefined)))
2572
0
      {
2573
0
        Elf_Internal_Rela outrel;
2574
0
        bool skip, relocate;
2575
0
        asection *sreloc;
2576
0
        bfd_byte *loc;
2577
2578
        /* When generating a shared object, these relocations
2579
     are copied into the output file to be resolved at run
2580
     time.  */
2581
0
        skip = false;
2582
0
        relocate = false;
2583
2584
0
        outrel.r_offset =
2585
0
    _bfd_elf_section_offset (output_bfd, info, input_section,
2586
0
           rel->r_offset);
2587
0
        if (outrel.r_offset == (bfd_vma) -1)
2588
0
    skip = true;
2589
0
        else if (outrel.r_offset == (bfd_vma) -2)
2590
0
    skip = true, relocate = true;
2591
2592
0
        outrel.r_offset += (input_section->output_section->vma
2593
0
          + input_section->output_offset);
2594
2595
0
        if (skip)
2596
0
    memset (&outrel, 0, sizeof outrel);
2597
0
        else if (h != NULL
2598
0
           && h->dynindx != -1
2599
0
           && (r_type == R_390_PC16
2600
0
         || r_type == R_390_PC12DBL
2601
0
         || r_type == R_390_PC16DBL
2602
0
         || r_type == R_390_PC24DBL
2603
0
         || r_type == R_390_PC32
2604
0
         || r_type == R_390_PC32DBL
2605
0
         || r_type == R_390_PC64
2606
0
         || !bfd_link_pic (info)
2607
0
         || !SYMBOLIC_BIND (info, h)
2608
0
         || !h->def_regular))
2609
0
    {
2610
0
      outrel.r_info = ELF64_R_INFO (h->dynindx, r_type);
2611
0
      outrel.r_addend = rel->r_addend;
2612
0
    }
2613
0
        else
2614
0
    {
2615
      /* This symbol is local, or marked to become local.  */
2616
0
      outrel.r_addend = relocation + rel->r_addend;
2617
0
      if (r_type == R_390_64)
2618
0
        {
2619
0
          relocate = true;
2620
0
          outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
2621
0
        }
2622
0
      else
2623
0
        {
2624
0
          long sindx;
2625
2626
0
          if (bfd_is_abs_section (sec))
2627
0
      sindx = 0;
2628
0
          else if (sec == NULL || sec->owner == NULL)
2629
0
      {
2630
0
        bfd_set_error(bfd_error_bad_value);
2631
0
        return false;
2632
0
      }
2633
0
          else
2634
0
      {
2635
0
        asection *osec;
2636
2637
0
        osec = sec->output_section;
2638
0
        sindx = elf_section_data (osec)->dynindx;
2639
2640
0
        if (sindx == 0)
2641
0
          {
2642
0
            osec = htab->elf.text_index_section;
2643
0
            sindx = elf_section_data (osec)->dynindx;
2644
0
          }
2645
0
        BFD_ASSERT (sindx != 0);
2646
2647
        /* We are turning this relocation into one
2648
           against a section symbol, so subtract out
2649
           the output section's address but not the
2650
           offset of the input section in the output
2651
           section.  */
2652
0
        outrel.r_addend -= osec->vma;
2653
0
      }
2654
0
          outrel.r_info = ELF64_R_INFO (sindx, r_type);
2655
0
        }
2656
0
    }
2657
2658
0
        sreloc = elf_section_data (input_section)->sreloc;
2659
0
        if (sreloc == NULL)
2660
0
    abort ();
2661
2662
0
        loc = sreloc->contents;
2663
0
        loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
2664
0
        bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
2665
2666
        /* If this reloc is against an external symbol, we do
2667
     not want to fiddle with the addend.  Otherwise, we
2668
     need to include the symbol value so that it becomes
2669
     an addend for the dynamic reloc.  */
2670
0
        if (! relocate)
2671
0
    continue;
2672
0
      }
2673
2674
0
    break;
2675
2676
    /* Relocations for tls literal pool entries.  */
2677
0
  case R_390_TLS_IE64:
2678
0
    if (bfd_link_dll (info))
2679
0
      {
2680
0
        Elf_Internal_Rela outrel;
2681
0
        asection *sreloc;
2682
0
        bfd_byte *loc;
2683
2684
0
        outrel.r_offset = rel->r_offset
2685
0
        + input_section->output_section->vma
2686
0
        + input_section->output_offset;
2687
0
        outrel.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
2688
0
        sreloc = elf_section_data (input_section)->sreloc;
2689
0
        if (sreloc == NULL)
2690
0
    abort ();
2691
0
        loc = sreloc->contents;
2692
0
        loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
2693
0
        bfd_elf64_swap_reloc_out (output_bfd, &outrel, loc);
2694
0
      }
2695
    /* Fall through.  */
2696
2697
0
  case R_390_TLS_GD64:
2698
0
  case R_390_TLS_GOTIE64:
2699
0
    r_type = elf_s390_tls_transition (info, r_type, h == NULL);
2700
0
    tls_type = GOT_UNKNOWN;
2701
0
    if (h == NULL && local_got_offsets)
2702
0
      tls_type = elf_s390_local_got_tls_type (input_bfd) [r_symndx];
2703
0
    else if (h != NULL)
2704
0
      {
2705
0
        tls_type = elf_s390_hash_entry(h)->tls_type;
2706
0
        if (!bfd_link_dll (info) && h->dynindx == -1 && tls_type >= GOT_TLS_IE)
2707
0
    r_type = R_390_TLS_LE64;
2708
0
      }
2709
0
    if (r_type == R_390_TLS_GD64 && tls_type >= GOT_TLS_IE)
2710
0
      r_type = R_390_TLS_IE64;
2711
2712
0
    if (r_type == R_390_TLS_LE64)
2713
0
      {
2714
        /* This relocation gets optimized away by the local exec
2715
     access optimization.  */
2716
0
        BFD_ASSERT (! unresolved_reloc);
2717
0
        bfd_put_64 (output_bfd, -tpoff (info, relocation) + rel->r_addend,
2718
0
        contents + rel->r_offset);
2719
0
        continue;
2720
0
      }
2721
2722
0
    if (htab->elf.sgot == NULL)
2723
0
      abort ();
2724
2725
0
    if (h != NULL)
2726
0
      off = h->got.offset;
2727
0
    else
2728
0
      {
2729
0
        if (local_got_offsets == NULL)
2730
0
    abort ();
2731
2732
0
        off = local_got_offsets[r_symndx];
2733
0
      }
2734
2735
0
  emit_tls_relocs:
2736
2737
0
    if ((off & 1) != 0)
2738
0
      off &= ~1;
2739
0
    else
2740
0
      {
2741
0
        Elf_Internal_Rela outrel;
2742
0
        bfd_byte *loc;
2743
0
        int dr_type, indx;
2744
2745
0
        if (htab->elf.srelgot == NULL)
2746
0
    abort ();
2747
2748
0
        outrel.r_offset = (htab->elf.sgot->output_section->vma
2749
0
         + htab->elf.sgot->output_offset + off);
2750
2751
0
        indx = h && h->dynindx != -1 ? h->dynindx : 0;
2752
0
        if (r_type == R_390_TLS_GD64)
2753
0
    dr_type = R_390_TLS_DTPMOD;
2754
0
        else
2755
0
    dr_type = R_390_TLS_TPOFF;
2756
0
        if (dr_type == R_390_TLS_TPOFF && indx == 0)
2757
0
    outrel.r_addend = relocation - dtpoff_base (info);
2758
0
        else
2759
0
    outrel.r_addend = 0;
2760
0
        outrel.r_info = ELF64_R_INFO (indx, dr_type);
2761
0
        loc = htab->elf.srelgot->contents;
2762
0
        loc += htab->elf.srelgot->reloc_count++
2763
0
    * sizeof (Elf64_External_Rela);
2764
0
        bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
2765
2766
0
        if (r_type == R_390_TLS_GD64)
2767
0
    {
2768
0
      if (indx == 0)
2769
0
        {
2770
0
          BFD_ASSERT (! unresolved_reloc);
2771
0
          bfd_put_64 (output_bfd,
2772
0
          relocation - dtpoff_base (info),
2773
0
          htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
2774
0
        }
2775
0
      else
2776
0
        {
2777
0
          outrel.r_info = ELF64_R_INFO (indx, R_390_TLS_DTPOFF);
2778
0
          outrel.r_offset += GOT_ENTRY_SIZE;
2779
0
          outrel.r_addend = 0;
2780
0
          htab->elf.srelgot->reloc_count++;
2781
0
          loc += sizeof (Elf64_External_Rela);
2782
0
          bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
2783
0
        }
2784
0
    }
2785
2786
0
        if (h != NULL)
2787
0
    h->got.offset |= 1;
2788
0
        else
2789
0
    local_got_offsets[r_symndx] |= 1;
2790
0
      }
2791
2792
0
    if (off >= (bfd_vma) -2)
2793
0
      abort ();
2794
0
    if (r_type == ELF64_R_TYPE (rel->r_info))
2795
0
      {
2796
0
        relocation = htab->elf.sgot->output_offset + off;
2797
0
        if (r_type == R_390_TLS_IE64 || r_type == R_390_TLS_IEENT)
2798
0
    relocation += htab->elf.sgot->output_section->vma;
2799
0
        unresolved_reloc = false;
2800
0
      }
2801
0
    else
2802
0
      {
2803
0
        bfd_put_64 (output_bfd, htab->elf.sgot->output_offset + off,
2804
0
        contents + rel->r_offset);
2805
0
        continue;
2806
0
      }
2807
0
    break;
2808
2809
0
  case R_390_TLS_GOTIE12:
2810
0
  case R_390_TLS_GOTIE20:
2811
0
  case R_390_TLS_IEENT:
2812
0
    if (h == NULL)
2813
0
      {
2814
0
        if (local_got_offsets == NULL)
2815
0
    abort();
2816
0
        off = local_got_offsets[r_symndx];
2817
0
        if (bfd_link_dll (info))
2818
0
    goto emit_tls_relocs;
2819
0
      }
2820
0
    else
2821
0
      {
2822
0
        off = h->got.offset;
2823
0
        tls_type = elf_s390_hash_entry(h)->tls_type;
2824
0
        if (bfd_link_dll (info) || h->dynindx != -1 || tls_type < GOT_TLS_IE)
2825
0
    goto emit_tls_relocs;
2826
0
      }
2827
2828
0
    if (htab->elf.sgot == NULL)
2829
0
      abort ();
2830
2831
0
    BFD_ASSERT (! unresolved_reloc);
2832
0
    bfd_put_64 (output_bfd, -tpoff (info, relocation),
2833
0
          htab->elf.sgot->contents + off);
2834
0
    relocation = htab->elf.sgot->output_offset + off;
2835
0
    if (r_type == R_390_TLS_IEENT)
2836
0
      relocation += htab->elf.sgot->output_section->vma;
2837
0
    unresolved_reloc = false;
2838
0
    break;
2839
2840
0
  case R_390_TLS_LDM64:
2841
0
    if (! bfd_link_dll (info))
2842
      /* The literal pool entry this relocation refers to gets ignored
2843
         by the optimized code of the local exec model. Do nothing
2844
         and the value will turn out zero.  */
2845
0
      continue;
2846
2847
0
    if (htab->elf.sgot == NULL)
2848
0
      abort ();
2849
2850
0
    off = htab->tls_ldm_got.offset;
2851
0
    if (off & 1)
2852
0
      off &= ~1;
2853
0
    else
2854
0
      {
2855
0
        Elf_Internal_Rela outrel;
2856
0
        bfd_byte *loc;
2857
2858
0
        if (htab->elf.srelgot == NULL)
2859
0
    abort ();
2860
2861
0
        outrel.r_offset = (htab->elf.sgot->output_section->vma
2862
0
         + htab->elf.sgot->output_offset + off);
2863
2864
0
        bfd_put_64 (output_bfd, 0,
2865
0
        htab->elf.sgot->contents + off + GOT_ENTRY_SIZE);
2866
0
        outrel.r_info = ELF64_R_INFO (0, R_390_TLS_DTPMOD);
2867
0
        outrel.r_addend = 0;
2868
0
        loc = htab->elf.srelgot->contents;
2869
0
        loc += htab->elf.srelgot->reloc_count++
2870
0
    * sizeof (Elf64_External_Rela);
2871
0
        bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
2872
0
        htab->tls_ldm_got.offset |= 1;
2873
0
      }
2874
0
    relocation = htab->elf.sgot->output_offset + off;
2875
0
    unresolved_reloc = false;
2876
0
    break;
2877
2878
0
  case R_390_TLS_LE64:
2879
0
    if (bfd_link_dll (info))
2880
0
      {
2881
        /* Linking a shared library with non-fpic code requires
2882
     a R_390_TLS_TPOFF relocation.  */
2883
0
        Elf_Internal_Rela outrel;
2884
0
        asection *sreloc;
2885
0
        bfd_byte *loc;
2886
0
        int indx;
2887
2888
0
        outrel.r_offset = rel->r_offset
2889
0
        + input_section->output_section->vma
2890
0
        + input_section->output_offset;
2891
0
        if (h != NULL && h->dynindx != -1)
2892
0
    indx = h->dynindx;
2893
0
        else
2894
0
    indx = 0;
2895
0
        outrel.r_info = ELF64_R_INFO (indx, R_390_TLS_TPOFF);
2896
0
        if (indx == 0)
2897
0
    outrel.r_addend = relocation - dtpoff_base (info);
2898
0
        else
2899
0
    outrel.r_addend = 0;
2900
0
        sreloc = elf_section_data (input_section)->sreloc;
2901
0
        if (sreloc == NULL)
2902
0
    abort ();
2903
0
        loc = sreloc->contents;
2904
0
        loc += sreloc->reloc_count++ * sizeof (Elf64_External_Rela);
2905
0
        bfd_elf64_swap_reloca_out (output_bfd, &outrel, loc);
2906
0
      }
2907
0
    else
2908
0
      {
2909
0
        BFD_ASSERT (! unresolved_reloc);
2910
0
        bfd_put_64 (output_bfd, -tpoff (info, relocation) + rel->r_addend,
2911
0
        contents + rel->r_offset);
2912
0
      }
2913
0
    continue;
2914
2915
0
  case R_390_TLS_LDO64:
2916
0
    if (bfd_link_dll (info) || (input_section->flags & SEC_DEBUGGING))
2917
0
      relocation -= dtpoff_base (info);
2918
0
    else
2919
      /* When converting LDO to LE, we must negate.  */
2920
0
      relocation = -tpoff (info, relocation);
2921
0
    break;
2922
2923
    /* Relocations for tls instructions.  */
2924
0
  case R_390_TLS_LOAD:
2925
0
  case R_390_TLS_GDCALL:
2926
0
  case R_390_TLS_LDCALL:
2927
0
    tls_type = GOT_UNKNOWN;
2928
0
    if (h == NULL && local_got_offsets)
2929
0
      tls_type = elf_s390_local_got_tls_type (input_bfd) [r_symndx];
2930
0
    else if (h != NULL)
2931
0
      tls_type = elf_s390_hash_entry(h)->tls_type;
2932
2933
0
    if (tls_type == GOT_TLS_GD)
2934
0
      continue;
2935
2936
0
    if (r_type == R_390_TLS_LOAD)
2937
0
      {
2938
0
        if (!bfd_link_dll (info) && (h == NULL || h->dynindx == -1))
2939
0
    {
2940
      /* IE->LE transition. Four valid cases:
2941
         lg %rx,(0,%ry)    -> sllg %rx,%ry,0
2942
         lg %rx,(%ry,0)    -> sllg %rx,%ry,0
2943
         lg %rx,(%ry,%r12) -> sllg %rx,%ry,0
2944
         lg %rx,(%r12,%ry) -> sllg %rx,%ry,0  */
2945
0
      unsigned int insn0, insn1, ry;
2946
2947
0
      insn0 = bfd_get_32 (input_bfd, contents + rel->r_offset);
2948
0
      insn1 = bfd_get_16 (input_bfd, contents + rel->r_offset + 4);
2949
0
      if (insn1 != 0x0004)
2950
0
        {
2951
0
          invalid_tls_insn (input_bfd, input_section, rel);
2952
0
          return false;
2953
0
        }
2954
0
      if ((insn0 & 0xff00f000) == 0xe3000000)
2955
        /* lg %rx,0(%ry,0) -> sllg %rx,%ry,0  */
2956
0
        ry = (insn0 & 0x000f0000);
2957
0
      else if ((insn0 & 0xff0f0000) == 0xe3000000)
2958
        /* lg %rx,0(0,%ry) -> sllg %rx,%ry,0  */
2959
0
        ry = (insn0 & 0x0000f000) << 4;
2960
0
      else if ((insn0 & 0xff00f000) == 0xe300c000)
2961
        /* lg %rx,0(%ry,%r12) -> sllg %rx,%ry,0  */
2962
0
        ry = (insn0 & 0x000f0000);
2963
0
      else if ((insn0 & 0xff0f0000) == 0xe30c0000)
2964
        /* lg %rx,0(%r12,%ry) -> sllg %rx,%ry,0  */
2965
0
        ry = (insn0 & 0x0000f000) << 4;
2966
0
      else
2967
0
        {
2968
0
          invalid_tls_insn (input_bfd, input_section, rel);
2969
0
          return false;
2970
0
        }
2971
0
      insn0 = 0xeb000000 | (insn0 & 0x00f00000) | ry;
2972
0
      insn1 = 0x000d;
2973
0
      bfd_put_32 (output_bfd, insn0, contents + rel->r_offset);
2974
0
      bfd_put_16 (output_bfd, insn1, contents + rel->r_offset + 4);
2975
0
    }
2976
0
      }
2977
0
    else if (r_type == R_390_TLS_GDCALL)
2978
0
      {
2979
0
        unsigned int insn0, insn1;
2980
2981
0
        insn0 = bfd_get_32 (input_bfd, contents + rel->r_offset);
2982
0
        insn1 = bfd_get_16 (input_bfd, contents + rel->r_offset + 4);
2983
0
        if ((insn0 & 0xffff0000) != 0xc0e50000)
2984
0
    {
2985
0
      invalid_tls_insn (input_bfd, input_section, rel);
2986
0
      return false;
2987
0
    }
2988
0
        if (!bfd_link_dll (info) && (h == NULL || h->dynindx == -1))
2989
0
    {
2990
      /* GD->LE transition.
2991
         brasl %r14,__tls_get_addr@plt -> brcl 0,. */
2992
0
      insn0 = 0xc0040000;
2993
0
      insn1 = 0x0000;
2994
0
    }
2995
0
        else
2996
0
    {
2997
      /* GD->IE transition.
2998
         brasl %r14,__tls_get_addr@plt -> lg %r2,0(%r2,%r12)  */
2999
0
      insn0 = 0xe322c000;
3000
0
      insn1 = 0x0004;
3001
0
    }
3002
0
        bfd_put_32 (output_bfd, insn0, contents + rel->r_offset);
3003
0
        bfd_put_16 (output_bfd, insn1, contents + rel->r_offset + 4);
3004
0
      }
3005
0
    else if (r_type == R_390_TLS_LDCALL)
3006
0
      {
3007
0
        if (!bfd_link_dll (info))
3008
0
    {
3009
0
      unsigned int insn0, insn1;
3010
3011
0
      insn0 = bfd_get_32 (input_bfd, contents + rel->r_offset);
3012
0
      insn1 = bfd_get_16 (input_bfd, contents + rel->r_offset + 4);
3013
0
      if ((insn0 & 0xffff0000) != 0xc0e50000)
3014
0
        {
3015
0
          invalid_tls_insn (input_bfd, input_section, rel);
3016
0
          return false;
3017
0
        }
3018
      /* LD->LE transition.
3019
         brasl %r14,__tls_get_addr@plt -> brcl 0,. */
3020
0
      insn0 = 0xc0040000;
3021
0
      insn1 = 0x0000;
3022
0
      bfd_put_32 (output_bfd, insn0, contents + rel->r_offset);
3023
0
      bfd_put_16 (output_bfd, insn1, contents + rel->r_offset + 4);
3024
0
    }
3025
0
      }
3026
0
    continue;
3027
3028
0
  default:
3029
0
    break;
3030
0
  }
3031
3032
      /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3033
   because such sections are not SEC_ALLOC and thus ld.so will
3034
   not process them.  */
3035
0
      if (unresolved_reloc
3036
0
    && !((input_section->flags & SEC_DEBUGGING) != 0
3037
0
         && h->def_dynamic)
3038
0
    && _bfd_elf_section_offset (output_bfd, info, input_section,
3039
0
              rel->r_offset) != (bfd_vma) -1)
3040
0
  _bfd_error_handler
3041
    /* xgettext:c-format */
3042
0
    (_("%pB(%pA+%#" PRIx64 "): "
3043
0
       "unresolvable %s relocation against symbol `%s'"),
3044
0
     input_bfd,
3045
0
     input_section,
3046
0
     (uint64_t) rel->r_offset,
3047
0
     howto->name,
3048
0
     h->root.root.string);
3049
3050
0
    do_relocation:
3051
3052
      /* When applying a 24 bit reloc we need to start one byte
3053
   earlier.  Otherwise the 32 bit get/put bfd operations might
3054
   access a byte after the actual section.  */
3055
0
      if (r_type == R_390_PC24DBL
3056
0
    || r_type == R_390_PLT24DBL)
3057
0
  rel->r_offset--;
3058
3059
      /* Issue an error if the right shift implied by the relocation
3060
   would drop bits from the symbol value.  */
3061
0
      if (howto->rightshift
3062
0
    && (relocation & (((bfd_vma)1 << howto->rightshift) - 1)))
3063
0
  {
3064
0
    _bfd_error_handler
3065
      /* xgettext:c-format */
3066
0
      (_("%pB(%pA+%#" PRIx64 "): "
3067
0
         "misaligned symbol `%s' (%#" PRIx64 ") for relocation %s"),
3068
0
       input_bfd,
3069
0
       input_section,
3070
0
       (uint64_t) rel->r_offset,
3071
0
       h->root.root.string,
3072
0
       (uint64_t)relocation,
3073
0
       howto->name);
3074
0
    return false;
3075
0
  }
3076
3077
0
      if (r_type == R_390_20
3078
0
    || r_type == R_390_GOT20
3079
0
    || r_type == R_390_GOTPLT20
3080
0
    || r_type == R_390_TLS_GOTIE20)
3081
0
  {
3082
0
    relocation += rel->r_addend;
3083
0
    relocation = (relocation&0xfff) << 8 | (relocation&0xff000) >> 12;
3084
0
    r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3085
0
          contents, rel->r_offset,
3086
0
          relocation, 0);
3087
0
  }
3088
0
      else
3089
0
  r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3090
0
              contents, rel->r_offset,
3091
0
              relocation, rel->r_addend);
3092
3093
0
      if (r != bfd_reloc_ok)
3094
0
  {
3095
0
    const char *name;
3096
3097
0
    if (h != NULL)
3098
0
      name = h->root.root.string;
3099
0
    else
3100
0
      {
3101
0
        name = bfd_elf_string_from_elf_section (input_bfd,
3102
0
                  symtab_hdr->sh_link,
3103
0
                  sym->st_name);
3104
0
        if (name == NULL)
3105
0
    return false;
3106
0
        if (*name == '\0')
3107
0
    name = bfd_section_name (sec);
3108
0
      }
3109
3110
0
    if (r == bfd_reloc_overflow)
3111
0
      (*info->callbacks->reloc_overflow)
3112
0
        (info, (h ? &h->root : NULL), name, howto->name,
3113
0
         (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
3114
0
    else
3115
0
      {
3116
0
        _bfd_error_handler
3117
    /* xgettext:c-format */
3118
0
    (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"),
3119
0
     input_bfd, input_section,
3120
0
     (uint64_t) rel->r_offset, name, (int) r);
3121
0
        return false;
3122
0
      }
3123
0
  }
3124
0
    }
3125
3126
0
  return true;
3127
0
}
3128
3129
/* Generate the PLT slots together with the dynamic relocations needed
3130
   for IFUNC symbols.  */
3131
3132
static void
3133
elf_s390_finish_ifunc_symbol (bfd *output_bfd,
3134
            struct bfd_link_info *info,
3135
            struct elf_link_hash_entry *h,
3136
            struct elf_s390_link_hash_table *htab,
3137
            bfd_vma plt_offset,
3138
            bfd_vma resolver_address)
3139
0
{
3140
0
  bfd_vma plt_index;
3141
0
  bfd_vma got_offset;
3142
0
  Elf_Internal_Rela rela;
3143
0
  bfd_byte *loc;
3144
0
  asection *plt, *gotplt, *relplt;
3145
3146
0
  if (htab->elf.iplt == NULL
3147
0
      || htab->elf.igotplt == NULL
3148
0
      || htab->elf.irelplt == NULL)
3149
0
    abort ();
3150
3151
  /* Index of the PLT slot within iplt section.  */
3152
0
  plt_index = plt_offset / PLT_ENTRY_SIZE;
3153
0
  plt = htab->elf.iplt;
3154
  /* Offset into the igot.plt section.  */
3155
0
  got_offset = plt_index * GOT_ENTRY_SIZE;
3156
0
  gotplt = htab->elf.igotplt;
3157
0
  relplt = htab->elf.irelplt;
3158
3159
  /* Fill in the blueprint of a PLT.  */
3160
0
  memcpy (plt->contents + plt_offset, elf_s390x_plt_entry,
3161
0
    PLT_ENTRY_SIZE);
3162
3163
  /* Fixup the relative address to the GOT entry */
3164
0
  bfd_put_32 (output_bfd,
3165
0
        (gotplt->output_section->vma +
3166
0
         gotplt->output_offset + got_offset
3167
0
         - (plt->output_section->vma +
3168
0
      plt->output_offset +
3169
0
      plt_offset))/2,
3170
0
        plt->contents + plt_offset + 2);
3171
  /* Fixup the relative branch to PLT 0 */
3172
0
  bfd_put_32 (output_bfd, - (plt->output_offset +
3173
0
           (PLT_ENTRY_SIZE * plt_index) + 22)/2,
3174
0
        plt->contents + plt_offset + 24);
3175
  /* Fixup offset into .rela.plt section.  */
3176
0
  bfd_put_32 (output_bfd, relplt->output_offset +
3177
0
        plt_index * sizeof (Elf64_External_Rela),
3178
0
        plt->contents + plt_offset + 28);
3179
3180
  /* Fill in the entry in the global offset table.
3181
     Points to instruction after GOT offset.  */
3182
0
  bfd_put_64 (output_bfd,
3183
0
        (plt->output_section->vma
3184
0
         + plt->output_offset
3185
0
         + plt_offset
3186
0
         + 14),
3187
0
        gotplt->contents + got_offset);
3188
3189
  /* Fill in the entry in the .rela.plt section.  */
3190
0
  rela.r_offset = (gotplt->output_section->vma
3191
0
       + gotplt->output_offset
3192
0
       + got_offset);
3193
3194
0
  if (!h
3195
0
      || h->dynindx == -1
3196
0
      || ((bfd_link_executable (info)
3197
0
     || ELF_ST_VISIBILITY (h->other) != STV_DEFAULT)
3198
0
    && h->def_regular))
3199
0
    {
3200
      /* The symbol can be locally resolved.  */
3201
0
      rela.r_info = ELF64_R_INFO (0, R_390_IRELATIVE);
3202
0
      rela.r_addend = resolver_address;
3203
0
    }
3204
0
  else
3205
0
    {
3206
0
      rela.r_info = ELF64_R_INFO (h->dynindx, R_390_JMP_SLOT);
3207
0
      rela.r_addend = 0;
3208
0
    }
3209
3210
0
  loc = relplt->contents + plt_index * sizeof (Elf64_External_Rela);
3211
0
  bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3212
0
}
3213
3214
3215
/* Finish up dynamic symbol handling.  We set the contents of various
3216
   dynamic sections here.  */
3217
3218
static bool
3219
elf_s390_finish_dynamic_symbol (bfd *output_bfd,
3220
        struct bfd_link_info *info,
3221
        struct elf_link_hash_entry *h,
3222
        Elf_Internal_Sym *sym)
3223
0
{
3224
0
  struct elf_s390_link_hash_table *htab;
3225
0
  struct elf_s390_link_hash_entry *eh = (struct elf_s390_link_hash_entry*)h;
3226
3227
0
  htab = elf_s390_hash_table (info);
3228
0
  if (htab == NULL)
3229
0
    return false;
3230
3231
0
  if (h->plt.offset != (bfd_vma) -1)
3232
0
    {
3233
0
      bfd_vma plt_index;
3234
0
      bfd_vma gotplt_offset;
3235
0
      Elf_Internal_Rela rela;
3236
0
      bfd_byte *loc;
3237
3238
      /* This symbol has an entry in the procedure linkage table.  Set
3239
   it up.  */
3240
0
      if (s390_is_ifunc_symbol_p (h) && h->def_regular)
3241
0
  {
3242
0
    elf_s390_finish_ifunc_symbol (output_bfd, info, h,
3243
0
      htab, h->plt.offset,
3244
0
      eh->ifunc_resolver_address +
3245
0
      eh->ifunc_resolver_section->output_offset +
3246
0
      eh->ifunc_resolver_section->output_section->vma);
3247
3248
    /* Do not return yet.  Handling of explicit GOT slots of
3249
       IFUNC symbols is below.  */
3250
0
  }
3251
0
      else
3252
0
  {
3253
0
    if (h->dynindx == -1
3254
0
        || htab->elf.splt == NULL
3255
0
        || htab->elf.sgotplt == NULL
3256
0
        || htab->elf.srelplt == NULL)
3257
0
      abort ();
3258
3259
    /* Calc. index no.
3260
       Current offset - size first entry / entry size.  */
3261
0
    plt_index = (h->plt.offset - PLT_FIRST_ENTRY_SIZE) / PLT_ENTRY_SIZE;
3262
3263
    /* The slots in the .got.plt correspond to the PLT slots in
3264
       the same order.  */
3265
0
    gotplt_offset = plt_index * GOT_ENTRY_SIZE;
3266
3267
    /* If .got.plt comes first it needs to contain the 3 header
3268
       entries.  */
3269
0
    if (!s390_gotplt_after_got_p (info))
3270
0
      gotplt_offset += 3 * GOT_ENTRY_SIZE;
3271
3272
    /* Fill in the blueprint of a PLT.  */
3273
0
    memcpy (htab->elf.splt->contents + h->plt.offset, elf_s390x_plt_entry,
3274
0
      PLT_ENTRY_SIZE);
3275
3276
    /* The first instruction in the PLT entry is a LARL loading
3277
       the address of the GOT slot.  We write the 4 byte
3278
       immediate operand of the LARL instruction here.  */
3279
0
    bfd_put_32 (output_bfd,
3280
0
          (htab->elf.sgotplt->output_section->vma +
3281
0
           htab->elf.sgotplt->output_offset + gotplt_offset
3282
0
           - (htab->elf.splt->output_section->vma +
3283
0
        htab->elf.splt->output_offset +
3284
0
        h->plt.offset))/2,
3285
0
          htab->elf.splt->contents + h->plt.offset + 2);
3286
    /* Fixup the relative branch to PLT 0 */
3287
0
    bfd_put_32 (output_bfd, - (PLT_FIRST_ENTRY_SIZE +
3288
0
             (PLT_ENTRY_SIZE * plt_index) + 22)/2,
3289
0
          htab->elf.splt->contents + h->plt.offset + 24);
3290
    /* Fixup offset into .rela.plt section.  */
3291
0
    bfd_put_32 (output_bfd, plt_index * sizeof (Elf64_External_Rela),
3292
0
          htab->elf.splt->contents + h->plt.offset + 28);
3293
3294
    /* Fill in the entry in the global offset table.
3295
       Points to instruction after GOT offset.  */
3296
0
    bfd_put_64 (output_bfd,
3297
0
          (htab->elf.splt->output_section->vma
3298
0
           + htab->elf.splt->output_offset
3299
0
           + h->plt.offset
3300
0
           + 14),
3301
0
          htab->elf.sgotplt->contents + gotplt_offset);
3302
3303
    /* Fill in the entry in the .rela.plt section.  */
3304
0
    rela.r_offset = (htab->elf.sgotplt->output_section->vma
3305
0
         + htab->elf.sgotplt->output_offset
3306
0
         + gotplt_offset);
3307
0
    rela.r_info = ELF64_R_INFO (h->dynindx, R_390_JMP_SLOT);
3308
0
    rela.r_addend = 0;
3309
0
    loc = htab->elf.srelplt->contents + plt_index *
3310
0
      sizeof (Elf64_External_Rela);
3311
0
    bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3312
3313
0
    if (!h->def_regular)
3314
0
      {
3315
        /* Mark the symbol as undefined, rather than as defined in
3316
     the .plt section.  Leave the value alone.  This is a clue
3317
     for the dynamic linker, to make function pointer
3318
     comparisons work between an application and shared
3319
     library.  */
3320
0
        sym->st_shndx = SHN_UNDEF;
3321
0
      }
3322
0
  }
3323
0
    }
3324
3325
0
  if (h->got.offset != (bfd_vma) -1
3326
0
      && elf_s390_hash_entry(h)->tls_type != GOT_TLS_GD
3327
0
      && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE
3328
0
      && elf_s390_hash_entry(h)->tls_type != GOT_TLS_IE_NLT)
3329
0
    {
3330
0
      Elf_Internal_Rela rela;
3331
0
      bfd_byte *loc;
3332
3333
      /* This symbol has an entry in the global offset table.  Set it
3334
   up.  */
3335
0
      if (htab->elf.sgot == NULL || htab->elf.srelgot == NULL)
3336
0
  abort ();
3337
3338
0
      rela.r_offset = (htab->elf.sgot->output_section->vma
3339
0
           + htab->elf.sgot->output_offset
3340
0
           + (h->got.offset &~ (bfd_vma) 1));
3341
3342
0
      if (h->def_regular && s390_is_ifunc_symbol_p (h))
3343
0
  {
3344
0
    if (bfd_link_pic (info))
3345
0
      {
3346
        /* An explicit GOT slot usage needs GLOB_DAT.  If the
3347
     symbol references local the implicit got.iplt slot
3348
     will be used and the IRELATIVE reloc has been created
3349
     above.  */
3350
0
        goto do_glob_dat;
3351
0
      }
3352
0
    else
3353
0
      {
3354
        /* For non-shared objects explicit GOT slots must be
3355
     filled with the PLT slot address for pointer
3356
     equality reasons.  */
3357
0
        bfd_put_64 (output_bfd, (htab->elf.iplt->output_section->vma
3358
0
               + htab->elf.iplt->output_offset
3359
0
               + h->plt.offset),
3360
0
        htab->elf.sgot->contents + h->got.offset);
3361
0
        return true;
3362
0
      }
3363
0
  }
3364
0
      else if (bfd_link_pic (info)
3365
0
         && SYMBOL_REFERENCES_LOCAL (info, h))
3366
0
  {
3367
0
    if (UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
3368
0
      return true;
3369
3370
    /* If this is a static link, or it is a -Bsymbolic link and
3371
       the symbol is defined locally or was forced to be local
3372
       because of a version file, we just want to emit a
3373
       RELATIVE reloc.  The entry in the global offset table
3374
       will already have been initialized in the
3375
       relocate_section function.  */
3376
0
    if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
3377
0
      return false;
3378
0
    BFD_ASSERT((h->got.offset & 1) != 0);
3379
0
    rela.r_info = ELF64_R_INFO (0, R_390_RELATIVE);
3380
0
    rela.r_addend = (h->root.u.def.value
3381
0
         + h->root.u.def.section->output_section->vma
3382
0
         + h->root.u.def.section->output_offset);
3383
0
  }
3384
0
      else
3385
0
  {
3386
0
    BFD_ASSERT((h->got.offset & 1) == 0);
3387
0
  do_glob_dat:
3388
0
    bfd_put_64 (output_bfd, (bfd_vma) 0, htab->elf.sgot->contents + h->got.offset);
3389
0
    rela.r_info = ELF64_R_INFO (h->dynindx, R_390_GLOB_DAT);
3390
0
    rela.r_addend = 0;
3391
0
  }
3392
3393
0
      loc = htab->elf.srelgot->contents;
3394
0
      loc += htab->elf.srelgot->reloc_count++ * sizeof (Elf64_External_Rela);
3395
0
      bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3396
0
    }
3397
3398
0
  if (h->needs_copy)
3399
0
    {
3400
0
      Elf_Internal_Rela rela;
3401
0
      asection *s;
3402
0
      bfd_byte *loc;
3403
3404
      /* This symbols needs a copy reloc.  Set it up.  */
3405
3406
0
      if (h->dynindx == -1
3407
0
    || (h->root.type != bfd_link_hash_defined
3408
0
        && h->root.type != bfd_link_hash_defweak)
3409
0
    || htab->elf.srelbss == NULL)
3410
0
  abort ();
3411
3412
0
      rela.r_offset = (h->root.u.def.value
3413
0
           + h->root.u.def.section->output_section->vma
3414
0
           + h->root.u.def.section->output_offset);
3415
0
      rela.r_info = ELF64_R_INFO (h->dynindx, R_390_COPY);
3416
0
      rela.r_addend = 0;
3417
0
      if (h->root.u.def.section == htab->elf.sdynrelro)
3418
0
  s = htab->elf.sreldynrelro;
3419
0
      else
3420
0
  s = htab->elf.srelbss;
3421
0
      loc = s->contents + s->reloc_count++ * sizeof (Elf64_External_Rela);
3422
0
      bfd_elf64_swap_reloca_out (output_bfd, &rela, loc);
3423
0
    }
3424
3425
  /* Mark some specially defined symbols as absolute.  */
3426
0
  if (h == htab->elf.hdynamic
3427
0
      || h == htab->elf.hgot
3428
0
      || h == htab->elf.hplt)
3429
0
    sym->st_shndx = SHN_ABS;
3430
3431
0
  return true;
3432
0
}
3433
3434
/* Used to decide how to sort relocs in an optimal manner for the
3435
   dynamic linker, before writing them out.  */
3436
3437
static enum elf_reloc_type_class
3438
elf_s390_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
3439
         const asection *rel_sec ATTRIBUTE_UNUSED,
3440
         const Elf_Internal_Rela *rela)
3441
0
{
3442
0
  bfd *abfd = info->output_bfd;
3443
0
  const struct elf_backend_data *bed = get_elf_backend_data (abfd);
3444
0
  struct elf_s390_link_hash_table *htab = elf_s390_hash_table (info);
3445
0
  unsigned long r_symndx = ELF64_R_SYM (rela->r_info);
3446
0
  Elf_Internal_Sym sym;
3447
3448
0
  if (htab->elf.dynsym == NULL
3449
0
      || !bed->s->swap_symbol_in (abfd,
3450
0
          (htab->elf.dynsym->contents
3451
0
           + r_symndx * bed->s->sizeof_sym),
3452
0
          0, &sym))
3453
0
    abort ();
3454
3455
  /* Check relocation against STT_GNU_IFUNC symbol.  */
3456
0
  if (ELF_ST_TYPE (sym.st_info) == STT_GNU_IFUNC)
3457
0
    return reloc_class_ifunc;
3458
3459
0
  switch ((int) ELF64_R_TYPE (rela->r_info))
3460
0
    {
3461
0
    case R_390_RELATIVE:
3462
0
      return reloc_class_relative;
3463
0
    case R_390_JMP_SLOT:
3464
0
      return reloc_class_plt;
3465
0
    case R_390_COPY:
3466
0
      return reloc_class_copy;
3467
0
    default:
3468
0
      return reloc_class_normal;
3469
0
    }
3470
0
}
3471
3472
/* Finish up the dynamic sections.  */
3473
3474
static bool
3475
elf_s390_finish_dynamic_sections (bfd *output_bfd,
3476
          struct bfd_link_info *info)
3477
0
{
3478
0
  struct elf_s390_link_hash_table *htab;
3479
0
  bfd *dynobj;
3480
0
  asection *sdyn;
3481
0
  bfd *ibfd;
3482
0
  unsigned int i;
3483
3484
0
  htab = elf_s390_hash_table (info);
3485
0
  if (htab == NULL)
3486
0
    return false;
3487
3488
0
  dynobj = htab->elf.dynobj;
3489
0
  sdyn = bfd_get_linker_section (dynobj, ".dynamic");
3490
3491
0
  if (htab->elf.dynamic_sections_created)
3492
0
    {
3493
0
      Elf64_External_Dyn *dyncon, *dynconend;
3494
3495
0
      if (sdyn == NULL || htab->elf.sgot == NULL)
3496
0
  abort ();
3497
3498
0
      dyncon = (Elf64_External_Dyn *) sdyn->contents;
3499
0
      dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->size);
3500
0
      for (; dyncon < dynconend; dyncon++)
3501
0
  {
3502
0
    Elf_Internal_Dyn dyn;
3503
0
    asection *s;
3504
3505
0
    bfd_elf64_swap_dyn_in (dynobj, dyncon, &dyn);
3506
3507
0
    switch (dyn.d_tag)
3508
0
      {
3509
0
      default:
3510
0
        continue;
3511
3512
0
      case DT_PLTGOT:
3513
        /* DT_PLTGOT matches _GLOBAL_OFFSET_TABLE_ */
3514
0
        dyn.d_un.d_ptr = s390_got_pointer (info);
3515
0
        break;
3516
3517
0
      case DT_JMPREL:
3518
0
        s = htab->elf.srelplt;
3519
0
        dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
3520
0
        break;
3521
3522
0
      case DT_PLTRELSZ:
3523
0
        dyn.d_un.d_val = htab->elf.srelplt->size;
3524
0
        if (htab->elf.irelplt)
3525
0
    dyn.d_un.d_val += htab->elf.irelplt->size;
3526
0
        break;
3527
3528
0
      case DT_RELASZ:
3529
        /* The procedure linkage table relocs (DT_JMPREL) should
3530
     not be included in the overall relocs (DT_RELA).
3531
     Therefore, we override the DT_RELASZ entry here to
3532
     make it not include the JMPREL relocs.  Since the
3533
     linker script arranges for .rela.plt to follow all
3534
     other relocation sections, we don't have to worry
3535
     about changing the DT_RELA entry.  */
3536
0
        dyn.d_un.d_val -= htab->elf.srelplt->size;
3537
0
        if (htab->elf.irelplt)
3538
0
    dyn.d_un.d_val -= htab->elf.irelplt->size;
3539
0
        break;
3540
0
      }
3541
3542
0
    bfd_elf64_swap_dyn_out (output_bfd, &dyn, dyncon);
3543
0
  }
3544
3545
      /* Fill in the special first entry in the procedure linkage table.  */
3546
0
      if (htab->elf.splt && htab->elf.splt->size > 0)
3547
0
  {
3548
    /* fill in blueprint for plt 0 entry */
3549
0
    memcpy (htab->elf.splt->contents, elf_s390x_first_plt_entry,
3550
0
      PLT_FIRST_ENTRY_SIZE);
3551
    /* The second instruction in the first PLT entry is a LARL
3552
       loading the GOT pointer.  Fill in the LARL immediate
3553
       address.  */
3554
0
    bfd_put_32 (output_bfd,
3555
0
          (s390_got_pointer (info)
3556
0
           - htab->elf.splt->output_section->vma
3557
0
           - htab->elf.splt->output_offset - 6)/2,
3558
0
          htab->elf.splt->contents + 8);
3559
0
  }
3560
0
      if (elf_section_data (htab->elf.splt->output_section) != NULL)
3561
0
  elf_section_data (htab->elf.splt->output_section)->this_hdr.sh_entsize
3562
0
    = PLT_ENTRY_SIZE;
3563
0
    }
3564
3565
0
  if (htab->elf.hgot && htab->elf.hgot->root.u.def.section)
3566
0
    {
3567
      /* Fill in the first three entries in the global offset table.  */
3568
0
      if (htab->elf.hgot->root.u.def.section->size > 0)
3569
0
  {
3570
0
    bfd_put_64 (output_bfd,
3571
0
          (sdyn == NULL ? (bfd_vma) 0
3572
0
           : sdyn->output_section->vma + sdyn->output_offset),
3573
0
          htab->elf.hgot->root.u.def.section->contents);
3574
    /* One entry for shared object struct ptr.  */
3575
0
    bfd_put_64 (output_bfd, (bfd_vma) 0,
3576
0
          htab->elf.hgot->root.u.def.section->contents + 8);
3577
    /* One entry for _dl_runtime_resolve.  */
3578
0
    bfd_put_64 (output_bfd, (bfd_vma) 0,
3579
0
          htab->elf.hgot->root.u.def.section->contents + 16);
3580
0
  }
3581
0
      if (htab->elf.sgot != NULL && htab->elf.sgot->size > 0)
3582
0
  elf_section_data (htab->elf.sgot->output_section)
3583
0
    ->this_hdr.sh_entsize = 8;
3584
0
    }
3585
3586
  /* Finish dynamic symbol for local IFUNC symbols.  */
3587
0
  for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
3588
0
    {
3589
0
      struct plt_entry *local_plt;
3590
0
      Elf_Internal_Sym *isym;
3591
0
      Elf_Internal_Shdr *symtab_hdr;
3592
3593
0
      symtab_hdr = &elf_symtab_hdr (ibfd);
3594
3595
0
      if (!is_s390_elf (ibfd))
3596
0
  continue;
3597
3598
0
      local_plt = elf_s390_local_plt (ibfd);
3599
0
      if (local_plt != NULL)
3600
0
  for (i = 0; i < symtab_hdr->sh_info; i++)
3601
0
    {
3602
0
      if (local_plt[i].plt.offset != (bfd_vma) -1)
3603
0
        {
3604
0
    asection *sec = local_plt[i].sec;
3605
0
    isym = bfd_sym_from_r_symndx (&htab->elf.sym_cache, ibfd, i);
3606
0
    if (isym == NULL)
3607
0
      return false;
3608
3609
0
    if (ELF_ST_TYPE (isym->st_info) == STT_GNU_IFUNC)
3610
0
      elf_s390_finish_ifunc_symbol (output_bfd, info, NULL, htab,
3611
0
            local_plt[i].plt.offset,
3612
0
            isym->st_value
3613
0
            + sec->output_section->vma
3614
0
            + sec->output_offset);
3615
3616
0
        }
3617
0
    }
3618
0
    }
3619
3620
0
  return true;
3621
0
}
3622

3623
/* Support for core dump NOTE sections.  */
3624
3625
static bool
3626
elf_s390_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
3627
0
{
3628
0
  int offset;
3629
0
  size_t size;
3630
3631
0
  switch (note->descsz)
3632
0
    {
3633
0
    default:
3634
0
      return false;
3635
3636
0
    case 336:     /* sizeof(struct elf_prstatus) on s390x */
3637
      /* pr_cursig */
3638
0
      elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
3639
3640
      /* pr_pid */
3641
0
      elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 32);
3642
3643
      /* pr_reg */
3644
0
      offset = 112;
3645
0
      size = 216;
3646
0
      break;
3647
0
    }
3648
3649
  /* Make a ".reg/999" section.  */
3650
0
  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
3651
0
            size, note->descpos + offset);
3652
0
}
3653
3654
static bool
3655
elf_s390_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
3656
0
{
3657
0
  switch (note->descsz)
3658
0
    {
3659
0
    default:
3660
0
      return false;
3661
3662
0
    case 136:     /* sizeof(struct elf_prpsinfo) on s390x */
3663
0
      elf_tdata (abfd)->core->pid
3664
0
  = bfd_get_32 (abfd, note->descdata + 24);
3665
0
      elf_tdata (abfd)->core->program
3666
0
  = _bfd_elfcore_strndup (abfd, note->descdata + 40, 16);
3667
0
      elf_tdata (abfd)->core->command
3668
0
  = _bfd_elfcore_strndup (abfd, note->descdata + 56, 80);
3669
0
    }
3670
3671
  /* Note that for some reason, a spurious space is tacked
3672
     onto the end of the args in some (at least one anyway)
3673
     implementations, so strip it off if it exists.  */
3674
3675
0
  {
3676
0
    char *command = elf_tdata (abfd)->core->command;
3677
0
    int n = strlen (command);
3678
3679
0
    if (0 < n && command[n - 1] == ' ')
3680
0
      command[n - 1] = '\0';
3681
0
  }
3682
3683
0
  return true;
3684
0
}
3685
3686
static char *
3687
elf_s390_write_core_note (bfd *abfd, char *buf, int *bufsiz,
3688
        int note_type, ...)
3689
0
{
3690
0
  va_list ap;
3691
3692
0
  switch (note_type)
3693
0
    {
3694
0
    default:
3695
0
      return NULL;
3696
3697
0
    case NT_PRPSINFO:
3698
0
      {
3699
0
  char data[136] ATTRIBUTE_NONSTRING = { 0 };
3700
0
  const char *fname, *psargs;
3701
3702
0
  va_start (ap, note_type);
3703
0
  fname = va_arg (ap, const char *);
3704
0
  psargs = va_arg (ap, const char *);
3705
0
  va_end (ap);
3706
3707
0
  strncpy (data + 40, fname, 16);
3708
#if GCC_VERSION == 8000 || GCC_VERSION == 8001
3709
  DIAGNOSTIC_PUSH;
3710
  /* GCC 8.0 and 8.1 warn about 80 equals destination size with
3711
     -Wstringop-truncation:
3712
     https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85643
3713
   */
3714
  DIAGNOSTIC_IGNORE_STRINGOP_TRUNCATION;
3715
#endif
3716
0
  strncpy (data + 56, psargs, 80);
3717
#if GCC_VERSION == 8000 || GCC_VERSION == 8001
3718
  DIAGNOSTIC_POP;
3719
#endif
3720
0
  return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
3721
0
           &data, sizeof (data));
3722
0
      }
3723
3724
0
    case NT_PRSTATUS:
3725
0
      {
3726
0
  char data[336] = { 0 };
3727
0
  long pid;
3728
0
  int cursig;
3729
0
  const void *gregs;
3730
3731
0
  va_start (ap, note_type);
3732
0
  pid = va_arg (ap, long);
3733
0
  cursig = va_arg (ap, int);
3734
0
  gregs = va_arg (ap, const void *);
3735
0
  va_end (ap);
3736
3737
0
  bfd_put_16 (abfd, cursig, data + 12);
3738
0
  bfd_put_32 (abfd, pid, data + 32);
3739
0
  memcpy (data + 112, gregs, 216);
3740
0
  return elfcore_write_note (abfd, buf, bufsiz, "CORE", note_type,
3741
0
           &data, sizeof (data));
3742
0
      }
3743
0
    }
3744
  /* NOTREACHED */
3745
0
}
3746

3747
/* Return address for Ith PLT stub in section PLT, for relocation REL
3748
   or (bfd_vma) -1 if it should not be included.  */
3749
3750
static bfd_vma
3751
elf_s390_plt_sym_val (bfd_vma i, const asection *plt,
3752
          const arelent *rel ATTRIBUTE_UNUSED)
3753
0
{
3754
0
  return plt->vma + PLT_FIRST_ENTRY_SIZE + i * PLT_ENTRY_SIZE;
3755
0
}
3756
3757
/* Merge backend specific data from an object file to the output
3758
   object file when linking.  */
3759
3760
static bool
3761
elf64_s390_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
3762
0
{
3763
0
  if (!is_s390_elf (ibfd) || !is_s390_elf (info->output_bfd))
3764
0
    return true;
3765
3766
0
  return elf_s390_merge_obj_attributes (ibfd, info);
3767
0
}
3768
3769
/* We may add a PT_S390_PGSTE program header.  */
3770
3771
static int
3772
elf_s390_additional_program_headers (bfd *abfd ATTRIBUTE_UNUSED,
3773
             struct bfd_link_info *info)
3774
0
{
3775
0
  struct elf_s390_link_hash_table *htab;
3776
3777
0
  if (info)
3778
0
    {
3779
0
      htab = elf_s390_hash_table (info);
3780
0
      if (htab)
3781
0
  return htab->params->pgste;
3782
0
    }
3783
0
  return 0;
3784
0
}
3785
3786
3787
/* Add the PT_S390_PGSTE program header.  */
3788
3789
static bool
3790
elf_s390_modify_segment_map (bfd *abfd, struct bfd_link_info *info)
3791
1
{
3792
1
  struct elf_s390_link_hash_table *htab;
3793
1
  struct elf_segment_map *m, *pm = NULL;
3794
3795
1
  if (!abfd || !info)
3796
1
    return true;
3797
3798
0
  htab = elf_s390_hash_table (info);
3799
0
  if (!htab || !htab->params->pgste)
3800
0
    return true;
3801
3802
  /* If there is already a PT_S390_PGSTE header, avoid adding
3803
     another.  */
3804
0
  m = elf_seg_map (abfd);
3805
0
  while (m && m->p_type != PT_S390_PGSTE)
3806
0
    {
3807
0
      pm = m;
3808
0
      m = m->next;
3809
0
    }
3810
3811
0
  if (m)
3812
0
    return true;
3813
3814
0
  m = (struct elf_segment_map *)
3815
0
    bfd_zalloc (abfd, sizeof (struct elf_segment_map));
3816
0
  if (m == NULL)
3817
0
    return false;
3818
0
  m->p_type = PT_S390_PGSTE;
3819
0
  m->count = 0;
3820
0
  m->next = NULL;
3821
0
  if (pm)
3822
0
    pm->next = m;
3823
3824
0
  return true;
3825
0
}
3826
3827
bool
3828
bfd_elf_s390_set_options (struct bfd_link_info *info,
3829
        struct s390_elf_params *params)
3830
0
{
3831
0
  struct elf_s390_link_hash_table *htab;
3832
3833
0
  if (info)
3834
0
    {
3835
0
      htab = elf_s390_hash_table (info);
3836
0
      if (htab)
3837
0
  htab->params = params;
3838
0
    }
3839
3840
0
  return true;
3841
0
}
3842
3843
3844
/* Why was the hash table entry size definition changed from
3845
   ARCH_SIZE/8 to 4? This breaks the 64 bit dynamic linker and
3846
   this is the only reason for the s390_elf64_size_info structure.  */
3847
3848
const struct elf_size_info s390_elf64_size_info =
3849
{
3850
  sizeof (Elf64_External_Ehdr),
3851
  sizeof (Elf64_External_Phdr),
3852
  sizeof (Elf64_External_Shdr),
3853
  sizeof (Elf64_External_Rel),
3854
  sizeof (Elf64_External_Rela),
3855
  sizeof (Elf64_External_Sym),
3856
  sizeof (Elf64_External_Dyn),
3857
  sizeof (Elf_External_Note),
3858
  8,    /* hash-table entry size.  */
3859
  1,    /* internal relocations per external relocations.  */
3860
  64,   /* arch_size.  */
3861
  3,    /* log_file_align.  */
3862
  ELFCLASS64, EV_CURRENT,
3863
  bfd_elf64_write_out_phdrs,
3864
  bfd_elf64_write_shdrs_and_ehdr,
3865
  bfd_elf64_checksum_contents,
3866
  bfd_elf64_write_relocs,
3867
  bfd_elf64_swap_symbol_in,
3868
  bfd_elf64_swap_symbol_out,
3869
  bfd_elf64_slurp_reloc_table,
3870
  bfd_elf64_slurp_symbol_table,
3871
  bfd_elf64_swap_dyn_in,
3872
  bfd_elf64_swap_dyn_out,
3873
  bfd_elf64_swap_reloc_in,
3874
  bfd_elf64_swap_reloc_out,
3875
  bfd_elf64_swap_reloca_in,
3876
  bfd_elf64_swap_reloca_out
3877
};
3878
3879
#define TARGET_BIG_SYM  s390_elf64_vec
3880
#define TARGET_BIG_NAME "elf64-s390"
3881
#define ELF_ARCH  bfd_arch_s390
3882
#define ELF_TARGET_ID S390_ELF_DATA
3883
#define ELF_MACHINE_CODE EM_S390
3884
#define ELF_MACHINE_ALT1 EM_S390_OLD
3885
#define ELF_MAXPAGESIZE 0x1000
3886
3887
#define elf_backend_size_info   s390_elf64_size_info
3888
3889
#define elf_backend_can_gc_sections 1
3890
#define elf_backend_can_refcount  1
3891
#define elf_backend_want_got_plt  1
3892
#define elf_backend_plt_readonly  1
3893
#define elf_backend_want_plt_sym  0
3894
#define elf_backend_got_header_size 24
3895
#define elf_backend_want_dynrelro 1
3896
#define elf_backend_rela_normal   1
3897
3898
#define elf_info_to_howto   elf_s390_info_to_howto
3899
3900
#define bfd_elf64_bfd_is_local_label_name     elf_s390_is_local_label_name
3901
#define bfd_elf64_bfd_link_hash_table_create  elf_s390_link_hash_table_create
3902
#define bfd_elf64_bfd_reloc_type_lookup       elf_s390_reloc_type_lookup
3903
#define bfd_elf64_bfd_reloc_name_lookup       elf_s390_reloc_name_lookup
3904
#define bfd_elf64_bfd_merge_private_bfd_data  elf64_s390_merge_private_bfd_data
3905
3906
#define elf_backend_adjust_dynamic_symbol     elf_s390_adjust_dynamic_symbol
3907
#define elf_backend_check_relocs        elf_s390_check_relocs
3908
#define elf_backend_copy_indirect_symbol      elf_s390_copy_indirect_symbol
3909
#define elf_backend_create_dynamic_sections   _bfd_elf_create_dynamic_sections
3910
#define elf_backend_finish_dynamic_sections   elf_s390_finish_dynamic_sections
3911
#define elf_backend_finish_dynamic_symbol     elf_s390_finish_dynamic_symbol
3912
#define elf_backend_gc_mark_hook        elf_s390_gc_mark_hook
3913
#define elf_backend_reloc_type_class        elf_s390_reloc_type_class
3914
#define elf_backend_relocate_section        elf_s390_relocate_section
3915
#define elf_backend_size_dynamic_sections     elf_s390_size_dynamic_sections
3916
#define elf_backend_init_index_section        _bfd_elf_init_1_index_section
3917
#define elf_backend_grok_prstatus       elf_s390_grok_prstatus
3918
#define elf_backend_grok_psinfo         elf_s390_grok_psinfo
3919
#define elf_backend_write_core_note       elf_s390_write_core_note
3920
#define elf_backend_plt_sym_val         elf_s390_plt_sym_val
3921
#define elf_backend_sort_relocs_p       elf_s390_elf_sort_relocs_p
3922
#define elf_backend_additional_program_headers elf_s390_additional_program_headers
3923
#define elf_backend_modify_segment_map        elf_s390_modify_segment_map
3924
3925
#define bfd_elf64_mkobject    elf_s390_mkobject
3926
#define elf_backend_object_p    elf_s390_object_p
3927
3928
#include "elf64-target.h"