Coverage Report

Created: 2026-03-10 08:46

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