Coverage Report

Created: 2024-05-21 06:29

/src/binutils-gdb/bfd/elf32-m68k.c
Line
Count
Source (jump to first uncovered line)
1
/* Motorola 68k series support for 32-bit ELF
2
   Copyright (C) 1993-2024 Free Software Foundation, Inc.
3
4
   This file is part of BFD, the Binary File Descriptor library.
5
6
   This program is free software; you can redistribute it and/or modify
7
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 3 of the License, or
9
   (at your option) any later version.
10
11
   This program is distributed in the hope that it will be useful,
12
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
   GNU General Public License for more details.
15
16
   You should have received a copy of the GNU General Public License
17
   along with this program; if not, write to the Free Software
18
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19
   MA 02110-1301, USA.  */
20
21
#include "sysdep.h"
22
#include "bfd.h"
23
#include "bfdlink.h"
24
#include "libbfd.h"
25
#include "elf-bfd.h"
26
#include "elf/m68k.h"
27
#include "opcode/m68k.h"
28
#include "cpu-m68k.h"
29
#include "elf32-m68k.h"
30
31
static bool
32
elf_m68k_discard_copies (struct elf_link_hash_entry *, void *);
33
34
static reloc_howto_type howto_table[] =
35
{
36
  HOWTO(R_68K_NONE,   0, 0, 0, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE",    false, 0, 0x00000000,false),
37
  HOWTO(R_68K_32,   0, 4,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32",    false, 0, 0xffffffff,false),
38
  HOWTO(R_68K_16,   0, 2,16, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16",    false, 0, 0x0000ffff,false),
39
  HOWTO(R_68K_8,    0, 1, 8, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8",   false, 0, 0x000000ff,false),
40
  HOWTO(R_68K_PC32,   0, 4,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32",    false, 0, 0xffffffff,true),
41
  HOWTO(R_68K_PC16,   0, 2,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16",    false, 0, 0x0000ffff,true),
42
  HOWTO(R_68K_PC8,    0, 1, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8",   false, 0, 0x000000ff,true),
43
  HOWTO(R_68K_GOT32,    0, 4,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32",   false, 0, 0xffffffff,true),
44
  HOWTO(R_68K_GOT16,    0, 2,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16",   false, 0, 0x0000ffff,true),
45
  HOWTO(R_68K_GOT8,   0, 1, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8",    false, 0, 0x000000ff,true),
46
  HOWTO(R_68K_GOT32O,   0, 4,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O",    false, 0, 0xffffffff,false),
47
  HOWTO(R_68K_GOT16O,   0, 2,16, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O",    false, 0, 0x0000ffff,false),
48
  HOWTO(R_68K_GOT8O,    0, 1, 8, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O",   false, 0, 0x000000ff,false),
49
  HOWTO(R_68K_PLT32,    0, 4,32, true, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32",   false, 0, 0xffffffff,true),
50
  HOWTO(R_68K_PLT16,    0, 2,16, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16",   false, 0, 0x0000ffff,true),
51
  HOWTO(R_68K_PLT8,   0, 1, 8, true, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8",    false, 0, 0x000000ff,true),
52
  HOWTO(R_68K_PLT32O,   0, 4,32, false,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O",    false, 0, 0xffffffff,false),
53
  HOWTO(R_68K_PLT16O,   0, 2,16, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O",    false, 0, 0x0000ffff,false),
54
  HOWTO(R_68K_PLT8O,    0, 1, 8, false,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O",   false, 0, 0x000000ff,false),
55
  HOWTO(R_68K_COPY,   0, 0, 0, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY",    false, 0, 0xffffffff,false),
56
  HOWTO(R_68K_GLOB_DAT,   0, 4,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_GLOB_DAT",  false, 0, 0xffffffff,false),
57
  HOWTO(R_68K_JMP_SLOT,   0, 4,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_JMP_SLOT",  false, 0, 0xffffffff,false),
58
  HOWTO(R_68K_RELATIVE,   0, 4,32, false,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE",  false, 0, 0xffffffff,false),
59
  /* GNU extension to record C++ vtable hierarchy.  */
60
  HOWTO (R_68K_GNU_VTINHERIT, /* type */
61
   0,     /* rightshift */
62
   4,     /* size */
63
   0,     /* bitsize */
64
   false,     /* pc_relative */
65
   0,     /* bitpos */
66
   complain_overflow_dont, /* complain_on_overflow */
67
   NULL,      /* special_function */
68
   "R_68K_GNU_VTINHERIT", /* name */
69
   false,     /* partial_inplace */
70
   0,     /* src_mask */
71
   0,     /* dst_mask */
72
   false),
73
  /* GNU extension to record C++ vtable member usage.  */
74
  HOWTO (R_68K_GNU_VTENTRY, /* type */
75
   0,     /* rightshift */
76
   4,     /* size */
77
   0,     /* bitsize */
78
   false,     /* pc_relative */
79
   0,     /* bitpos */
80
   complain_overflow_dont, /* complain_on_overflow */
81
   _bfd_elf_rel_vtable_reloc_fn, /* special_function */
82
   "R_68K_GNU_VTENTRY", /* name */
83
   false,     /* partial_inplace */
84
   0,     /* src_mask */
85
   0,     /* dst_mask */
86
   false),
87
88
  /* TLS general dynamic variable reference.  */
89
  HOWTO (R_68K_TLS_GD32,  /* type */
90
   0,     /* rightshift */
91
   4,     /* size */
92
   32,      /* bitsize */
93
   false,     /* pc_relative */
94
   0,     /* bitpos */
95
   complain_overflow_bitfield, /* complain_on_overflow */
96
   bfd_elf_generic_reloc, /* special_function */
97
   "R_68K_TLS_GD32",  /* name */
98
   false,     /* partial_inplace */
99
   0,     /* src_mask */
100
   0xffffffff,    /* dst_mask */
101
   false),    /* pcrel_offset */
102
103
  HOWTO (R_68K_TLS_GD16,  /* type */
104
   0,     /* rightshift */
105
   2,     /* size */
106
   16,      /* bitsize */
107
   false,     /* pc_relative */
108
   0,     /* bitpos */
109
   complain_overflow_signed, /* complain_on_overflow */
110
   bfd_elf_generic_reloc, /* special_function */
111
   "R_68K_TLS_GD16",  /* name */
112
   false,     /* partial_inplace */
113
   0,     /* src_mask */
114
   0x0000ffff,    /* dst_mask */
115
   false),    /* pcrel_offset */
116
117
  HOWTO (R_68K_TLS_GD8,   /* type */
118
   0,     /* rightshift */
119
   1,     /* size */
120
   8,     /* bitsize */
121
   false,     /* pc_relative */
122
   0,     /* bitpos */
123
   complain_overflow_signed, /* complain_on_overflow */
124
   bfd_elf_generic_reloc, /* special_function */
125
   "R_68K_TLS_GD8", /* name */
126
   false,     /* partial_inplace */
127
   0,     /* src_mask */
128
   0x000000ff,    /* dst_mask */
129
   false),    /* pcrel_offset */
130
131
  /* TLS local dynamic variable reference.  */
132
  HOWTO (R_68K_TLS_LDM32, /* type */
133
   0,     /* rightshift */
134
   4,     /* size */
135
   32,      /* bitsize */
136
   false,     /* pc_relative */
137
   0,     /* bitpos */
138
   complain_overflow_bitfield, /* complain_on_overflow */
139
   bfd_elf_generic_reloc, /* special_function */
140
   "R_68K_TLS_LDM32", /* name */
141
   false,     /* partial_inplace */
142
   0,     /* src_mask */
143
   0xffffffff,    /* dst_mask */
144
   false),    /* pcrel_offset */
145
146
  HOWTO (R_68K_TLS_LDM16, /* type */
147
   0,     /* rightshift */
148
   2,     /* size */
149
   16,      /* bitsize */
150
   false,     /* pc_relative */
151
   0,     /* bitpos */
152
   complain_overflow_signed, /* complain_on_overflow */
153
   bfd_elf_generic_reloc, /* special_function */
154
   "R_68K_TLS_LDM16", /* name */
155
   false,     /* partial_inplace */
156
   0,     /* src_mask */
157
   0x0000ffff,    /* dst_mask */
158
   false),    /* pcrel_offset */
159
160
  HOWTO (R_68K_TLS_LDM8,    /* type */
161
   0,     /* rightshift */
162
   1,     /* size */
163
   8,     /* bitsize */
164
   false,     /* pc_relative */
165
   0,     /* bitpos */
166
   complain_overflow_signed, /* complain_on_overflow */
167
   bfd_elf_generic_reloc, /* special_function */
168
   "R_68K_TLS_LDM8",  /* name */
169
   false,     /* partial_inplace */
170
   0,     /* src_mask */
171
   0x000000ff,    /* dst_mask */
172
   false),    /* pcrel_offset */
173
174
  HOWTO (R_68K_TLS_LDO32, /* type */
175
   0,     /* rightshift */
176
   4,     /* size */
177
   32,      /* bitsize */
178
   false,     /* pc_relative */
179
   0,     /* bitpos */
180
   complain_overflow_bitfield, /* complain_on_overflow */
181
   bfd_elf_generic_reloc, /* special_function */
182
   "R_68K_TLS_LDO32", /* name */
183
   false,     /* partial_inplace */
184
   0,     /* src_mask */
185
   0xffffffff,    /* dst_mask */
186
   false),    /* pcrel_offset */
187
188
  HOWTO (R_68K_TLS_LDO16, /* type */
189
   0,     /* rightshift */
190
   2,     /* size */
191
   16,      /* bitsize */
192
   false,     /* pc_relative */
193
   0,     /* bitpos */
194
   complain_overflow_signed, /* complain_on_overflow */
195
   bfd_elf_generic_reloc, /* special_function */
196
   "R_68K_TLS_LDO16", /* name */
197
   false,     /* partial_inplace */
198
   0,     /* src_mask */
199
   0x0000ffff,    /* dst_mask */
200
   false),    /* pcrel_offset */
201
202
  HOWTO (R_68K_TLS_LDO8,    /* type */
203
   0,     /* rightshift */
204
   1,     /* size */
205
   8,     /* bitsize */
206
   false,     /* pc_relative */
207
   0,     /* bitpos */
208
   complain_overflow_signed, /* complain_on_overflow */
209
   bfd_elf_generic_reloc, /* special_function */
210
   "R_68K_TLS_LDO8",  /* name */
211
   false,     /* partial_inplace */
212
   0,     /* src_mask */
213
   0x000000ff,    /* dst_mask */
214
   false),    /* pcrel_offset */
215
216
  /* TLS initial execution variable reference.  */
217
  HOWTO (R_68K_TLS_IE32,  /* type */
218
   0,     /* rightshift */
219
   4,     /* size */
220
   32,      /* bitsize */
221
   false,     /* pc_relative */
222
   0,     /* bitpos */
223
   complain_overflow_bitfield, /* complain_on_overflow */
224
   bfd_elf_generic_reloc, /* special_function */
225
   "R_68K_TLS_IE32",  /* name */
226
   false,     /* partial_inplace */
227
   0,     /* src_mask */
228
   0xffffffff,    /* dst_mask */
229
   false),    /* pcrel_offset */
230
231
  HOWTO (R_68K_TLS_IE16,  /* type */
232
   0,     /* rightshift */
233
   2,     /* size */
234
   16,      /* bitsize */
235
   false,     /* pc_relative */
236
   0,     /* bitpos */
237
   complain_overflow_signed, /* complain_on_overflow */
238
   bfd_elf_generic_reloc, /* special_function */
239
   "R_68K_TLS_IE16",  /* name */
240
   false,     /* partial_inplace */
241
   0,     /* src_mask */
242
   0x0000ffff,    /* dst_mask */
243
   false),    /* pcrel_offset */
244
245
  HOWTO (R_68K_TLS_IE8,   /* type */
246
   0,     /* rightshift */
247
   1,     /* size */
248
   8,     /* bitsize */
249
   false,     /* pc_relative */
250
   0,     /* bitpos */
251
   complain_overflow_signed, /* complain_on_overflow */
252
   bfd_elf_generic_reloc, /* special_function */
253
   "R_68K_TLS_IE8", /* name */
254
   false,     /* partial_inplace */
255
   0,     /* src_mask */
256
   0x000000ff,    /* dst_mask */
257
   false),    /* pcrel_offset */
258
259
  /* TLS local execution variable reference.  */
260
  HOWTO (R_68K_TLS_LE32,  /* type */
261
   0,     /* rightshift */
262
   4,     /* size */
263
   32,      /* bitsize */
264
   false,     /* pc_relative */
265
   0,     /* bitpos */
266
   complain_overflow_bitfield, /* complain_on_overflow */
267
   bfd_elf_generic_reloc, /* special_function */
268
   "R_68K_TLS_LE32",  /* name */
269
   false,     /* partial_inplace */
270
   0,     /* src_mask */
271
   0xffffffff,    /* dst_mask */
272
   false),    /* pcrel_offset */
273
274
  HOWTO (R_68K_TLS_LE16,  /* type */
275
   0,     /* rightshift */
276
   2,     /* size */
277
   16,      /* bitsize */
278
   false,     /* pc_relative */
279
   0,     /* bitpos */
280
   complain_overflow_signed, /* complain_on_overflow */
281
   bfd_elf_generic_reloc, /* special_function */
282
   "R_68K_TLS_LE16",  /* name */
283
   false,     /* partial_inplace */
284
   0,     /* src_mask */
285
   0x0000ffff,    /* dst_mask */
286
   false),    /* pcrel_offset */
287
288
  HOWTO (R_68K_TLS_LE8,   /* type */
289
   0,     /* rightshift */
290
   1,     /* size */
291
   8,     /* bitsize */
292
   false,     /* pc_relative */
293
   0,     /* bitpos */
294
   complain_overflow_signed, /* complain_on_overflow */
295
   bfd_elf_generic_reloc, /* special_function */
296
   "R_68K_TLS_LE8", /* name */
297
   false,     /* partial_inplace */
298
   0,     /* src_mask */
299
   0x000000ff,    /* dst_mask */
300
   false),    /* pcrel_offset */
301
302
  /* TLS GD/LD dynamic relocations.  */
303
  HOWTO (R_68K_TLS_DTPMOD32,  /* type */
304
   0,     /* rightshift */
305
   4,     /* size */
306
   32,      /* bitsize */
307
   false,     /* pc_relative */
308
   0,     /* bitpos */
309
   complain_overflow_dont, /* complain_on_overflow */
310
   bfd_elf_generic_reloc, /* special_function */
311
   "R_68K_TLS_DTPMOD32",  /* name */
312
   false,     /* partial_inplace */
313
   0,     /* src_mask */
314
   0xffffffff,    /* dst_mask */
315
   false),    /* pcrel_offset */
316
317
  HOWTO (R_68K_TLS_DTPREL32,  /* type */
318
   0,     /* rightshift */
319
   4,     /* size */
320
   32,      /* bitsize */
321
   false,     /* pc_relative */
322
   0,     /* bitpos */
323
   complain_overflow_dont, /* complain_on_overflow */
324
   bfd_elf_generic_reloc, /* special_function */
325
   "R_68K_TLS_DTPREL32",  /* name */
326
   false,     /* partial_inplace */
327
   0,     /* src_mask */
328
   0xffffffff,    /* dst_mask */
329
   false),    /* pcrel_offset */
330
331
  HOWTO (R_68K_TLS_TPREL32, /* type */
332
   0,     /* rightshift */
333
   4,     /* size */
334
   32,      /* bitsize */
335
   false,     /* pc_relative */
336
   0,     /* bitpos */
337
   complain_overflow_dont, /* complain_on_overflow */
338
   bfd_elf_generic_reloc, /* special_function */
339
   "R_68K_TLS_TPREL32", /* name */
340
   false,     /* partial_inplace */
341
   0,     /* src_mask */
342
   0xffffffff,    /* dst_mask */
343
   false),    /* pcrel_offset */
344
};
345
346
static bool
347
rtype_to_howto (bfd *abfd, arelent *cache_ptr, Elf_Internal_Rela *dst)
348
0
{
349
0
  unsigned int indx = ELF32_R_TYPE (dst->r_info);
350
351
0
  if (indx >= (unsigned int) R_68K_max)
352
0
    {
353
      /* xgettext:c-format */
354
0
      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
355
0
        abfd, indx);
356
0
      bfd_set_error (bfd_error_bad_value);
357
0
      return false;
358
0
    }
359
0
  cache_ptr->howto = &howto_table[indx];
360
0
  return true;
361
0
}
362
363
#define elf_info_to_howto rtype_to_howto
364
365
static const struct
366
{
367
  bfd_reloc_code_real_type bfd_val;
368
  int elf_val;
369
}
370
  reloc_map[] =
371
{
372
  { BFD_RELOC_NONE, R_68K_NONE },
373
  { BFD_RELOC_32, R_68K_32 },
374
  { BFD_RELOC_16, R_68K_16 },
375
  { BFD_RELOC_8, R_68K_8 },
376
  { BFD_RELOC_32_PCREL, R_68K_PC32 },
377
  { BFD_RELOC_16_PCREL, R_68K_PC16 },
378
  { BFD_RELOC_8_PCREL, R_68K_PC8 },
379
  { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 },
380
  { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 },
381
  { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 },
382
  { BFD_RELOC_32_GOTOFF, R_68K_GOT32O },
383
  { BFD_RELOC_16_GOTOFF, R_68K_GOT16O },
384
  { BFD_RELOC_8_GOTOFF, R_68K_GOT8O },
385
  { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 },
386
  { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 },
387
  { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 },
388
  { BFD_RELOC_32_PLTOFF, R_68K_PLT32O },
389
  { BFD_RELOC_16_PLTOFF, R_68K_PLT16O },
390
  { BFD_RELOC_8_PLTOFF, R_68K_PLT8O },
391
  { BFD_RELOC_NONE, R_68K_COPY },
392
  { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT },
393
  { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT },
394
  { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE },
395
  { BFD_RELOC_CTOR, R_68K_32 },
396
  { BFD_RELOC_VTABLE_INHERIT, R_68K_GNU_VTINHERIT },
397
  { BFD_RELOC_VTABLE_ENTRY, R_68K_GNU_VTENTRY },
398
  { BFD_RELOC_68K_TLS_GD32, R_68K_TLS_GD32 },
399
  { BFD_RELOC_68K_TLS_GD16, R_68K_TLS_GD16 },
400
  { BFD_RELOC_68K_TLS_GD8, R_68K_TLS_GD8 },
401
  { BFD_RELOC_68K_TLS_LDM32, R_68K_TLS_LDM32 },
402
  { BFD_RELOC_68K_TLS_LDM16, R_68K_TLS_LDM16 },
403
  { BFD_RELOC_68K_TLS_LDM8, R_68K_TLS_LDM8 },
404
  { BFD_RELOC_68K_TLS_LDO32, R_68K_TLS_LDO32 },
405
  { BFD_RELOC_68K_TLS_LDO16, R_68K_TLS_LDO16 },
406
  { BFD_RELOC_68K_TLS_LDO8, R_68K_TLS_LDO8 },
407
  { BFD_RELOC_68K_TLS_IE32, R_68K_TLS_IE32 },
408
  { BFD_RELOC_68K_TLS_IE16, R_68K_TLS_IE16 },
409
  { BFD_RELOC_68K_TLS_IE8, R_68K_TLS_IE8 },
410
  { BFD_RELOC_68K_TLS_LE32, R_68K_TLS_LE32 },
411
  { BFD_RELOC_68K_TLS_LE16, R_68K_TLS_LE16 },
412
  { BFD_RELOC_68K_TLS_LE8, R_68K_TLS_LE8 },
413
};
414
415
static reloc_howto_type *
416
reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED,
417
       bfd_reloc_code_real_type code)
418
0
{
419
0
  unsigned int i;
420
0
  for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++)
421
0
    {
422
0
      if (reloc_map[i].bfd_val == code)
423
0
  return &howto_table[reloc_map[i].elf_val];
424
0
    }
425
0
  return 0;
426
0
}
427
428
static reloc_howto_type *
429
reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name)
430
0
{
431
0
  unsigned int i;
432
433
0
  for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++)
434
0
    if (howto_table[i].name != NULL
435
0
  && strcasecmp (howto_table[i].name, r_name) == 0)
436
0
      return &howto_table[i];
437
438
0
  return NULL;
439
0
}
440
441
#define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
442
#define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup
443
#define ELF_ARCH bfd_arch_m68k
444
#define ELF_TARGET_ID M68K_ELF_DATA
445

446
/* Functions for the m68k ELF linker.  */
447
448
/* The name of the dynamic interpreter.  This is put in the .interp
449
   section.  */
450
451
0
#define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
452
453
/* Describes one of the various PLT styles.  */
454
455
struct elf_m68k_plt_info
456
{
457
  /* The size of each PLT entry.  */
458
  bfd_vma size;
459
460
  /* The template for the first PLT entry.  */
461
  const bfd_byte *plt0_entry;
462
463
  /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations.
464
     The comments by each member indicate the value that the relocation
465
     is against.  */
466
  struct {
467
    unsigned int got4; /* .got + 4 */
468
    unsigned int got8; /* .got + 8 */
469
  } plt0_relocs;
470
471
  /* The template for a symbol's PLT entry.  */
472
  const bfd_byte *symbol_entry;
473
474
  /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations.
475
     The comments by each member indicate the value that the relocation
476
     is against.  */
477
  struct {
478
    unsigned int got; /* the symbol's .got.plt entry */
479
    unsigned int plt; /* .plt */
480
  } symbol_relocs;
481
482
  /* The offset of the resolver stub from the start of SYMBOL_ENTRY.
483
     The stub starts with "move.l #relocoffset,%d0".  */
484
  bfd_vma symbol_resolve_entry;
485
};
486
487
/* The size in bytes of an entry in the procedure linkage table.  */
488
489
#define PLT_ENTRY_SIZE 20
490
491
/* The first entry in a procedure linkage table looks like this.  See
492
   the SVR4 ABI m68k supplement to see how this works.  */
493
494
static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] =
495
{
496
  0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
497
  0, 0, 0, 2,     /* + (.got + 4) - . */
498
  0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
499
  0, 0, 0, 2,     /* + (.got + 8) - . */
500
  0, 0, 0, 0      /* pad out to 20 bytes.  */
501
};
502
503
/* Subsequent entries in a procedure linkage table look like this.  */
504
505
static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] =
506
{
507
  0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
508
  0, 0, 0, 2,     /* + (.got.plt entry) - . */
509
  0x2f, 0x3c,     /* move.l #offset,-(%sp) */
510
  0, 0, 0, 0,     /* + reloc index */
511
  0x60, 0xff,     /* bra.l .plt */
512
  0, 0, 0, 0      /* + .plt - . */
513
};
514
515
static const struct elf_m68k_plt_info elf_m68k_plt_info =
516
{
517
  PLT_ENTRY_SIZE,
518
  elf_m68k_plt0_entry, { 4, 12 },
519
  elf_m68k_plt_entry, { 4, 16 }, 8
520
};
521
522
#define ISAB_PLT_ENTRY_SIZE 24
523
524
static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] =
525
{
526
  0x20, 0x3c,     /* move.l #offset,%d0 */
527
  0, 0, 0, 0,     /* + (.got + 4) - . */
528
  0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */
529
  0x20, 0x3c,     /* move.l #offset,%d0 */
530
  0, 0, 0, 0,     /* + (.got + 8) - . */
531
  0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
532
  0x4e, 0xd0,     /* jmp (%a0) */
533
  0x4e, 0x71      /* nop */
534
};
535
536
/* Subsequent entries in a procedure linkage table look like this.  */
537
538
static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] =
539
{
540
  0x20, 0x3c,     /* move.l #offset,%d0 */
541
  0, 0, 0, 0,     /* + (.got.plt entry) - . */
542
  0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
543
  0x4e, 0xd0,     /* jmp (%a0) */
544
  0x2f, 0x3c,     /* move.l #offset,-(%sp) */
545
  0, 0, 0, 0,     /* + reloc index */
546
  0x60, 0xff,     /* bra.l .plt */
547
  0, 0, 0, 0      /* + .plt - . */
548
};
549
550
static const struct elf_m68k_plt_info elf_isab_plt_info =
551
{
552
  ISAB_PLT_ENTRY_SIZE,
553
  elf_isab_plt0_entry, { 2, 12 },
554
  elf_isab_plt_entry, { 2, 20 }, 12
555
};
556
557
#define ISAC_PLT_ENTRY_SIZE 24
558
559
static const bfd_byte elf_isac_plt0_entry[ISAC_PLT_ENTRY_SIZE] =
560
{
561
  0x20, 0x3c,     /* move.l #offset,%d0 */
562
  0, 0, 0, 0,     /* replaced with .got + 4 - . */
563
  0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */
564
  0x20, 0x3c,     /* move.l #offset,%d0 */
565
  0, 0, 0, 0,     /* replaced with .got + 8 - . */
566
  0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
567
  0x4e, 0xd0,     /* jmp (%a0) */
568
  0x4e, 0x71      /* nop */
569
};
570
571
/* Subsequent entries in a procedure linkage table look like this.  */
572
573
static const bfd_byte elf_isac_plt_entry[ISAC_PLT_ENTRY_SIZE] =
574
{
575
  0x20, 0x3c,     /* move.l #offset,%d0 */
576
  0, 0, 0, 0,     /* replaced with (.got entry) - . */
577
  0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */
578
  0x4e, 0xd0,     /* jmp (%a0) */
579
  0x2f, 0x3c,     /* move.l #offset,-(%sp) */
580
  0, 0, 0, 0,     /* replaced with offset into relocation table */
581
  0x61, 0xff,     /* bsr.l .plt */
582
  0, 0, 0, 0      /* replaced with .plt - . */
583
};
584
585
static const struct elf_m68k_plt_info elf_isac_plt_info =
586
{
587
  ISAC_PLT_ENTRY_SIZE,
588
  elf_isac_plt0_entry, { 2, 12},
589
  elf_isac_plt_entry, { 2, 20 }, 12
590
};
591
592
#define CPU32_PLT_ENTRY_SIZE 24
593
/* Procedure linkage table entries for the cpu32 */
594
static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] =
595
{
596
  0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
597
  0, 0, 0, 2,     /* + (.got + 4) - . */
598
  0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */
599
  0, 0, 0, 2,     /* + (.got + 8) - . */
600
  0x4e, 0xd1,     /* jmp %a1@ */
601
  0, 0, 0, 0,     /* pad out to 24 bytes.  */
602
  0, 0
603
};
604
605
static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] =
606
{
607
  0x22, 0x7b, 0x01, 0x70,  /* moveal %pc@(0xc), %a1 */
608
  0, 0, 0, 2,      /* + (.got.plt entry) - . */
609
  0x4e, 0xd1,      /* jmp %a1@ */
610
  0x2f, 0x3c,      /* move.l #offset,-(%sp) */
611
  0, 0, 0, 0,      /* + reloc index */
612
  0x60, 0xff,      /* bra.l .plt */
613
  0, 0, 0, 0,      /* + .plt - . */
614
  0, 0
615
};
616
617
static const struct elf_m68k_plt_info elf_cpu32_plt_info =
618
{
619
  CPU32_PLT_ENTRY_SIZE,
620
  elf_cpu32_plt0_entry, { 4, 12 },
621
  elf_cpu32_plt_entry, { 4, 18 }, 10
622
};
623
624
/* The m68k linker needs to keep track of the number of relocs that it
625
   decides to copy in check_relocs for each symbol.  This is so that it
626
   can discard PC relative relocs if it doesn't need them when linking
627
   with -Bsymbolic.  We store the information in a field extending the
628
   regular ELF linker hash table.  */
629
630
/* This structure keeps track of the number of PC relative relocs we have
631
   copied for a given symbol.  */
632
633
struct elf_m68k_pcrel_relocs_copied
634
{
635
  /* Next section.  */
636
  struct elf_m68k_pcrel_relocs_copied *next;
637
  /* A section in dynobj.  */
638
  asection *section;
639
  /* Number of relocs copied in this section.  */
640
  bfd_size_type count;
641
};
642
643
/* Forward declaration.  */
644
struct elf_m68k_got_entry;
645
646
/* m68k ELF linker hash entry.  */
647
648
struct elf_m68k_link_hash_entry
649
{
650
  struct elf_link_hash_entry root;
651
652
  /* Number of PC relative relocs copied for this symbol.  */
653
  struct elf_m68k_pcrel_relocs_copied *pcrel_relocs_copied;
654
655
  /* Key to got_entries.  */
656
  unsigned long got_entry_key;
657
658
  /* List of GOT entries for this symbol.  This list is build during
659
     offset finalization and is used within elf_m68k_finish_dynamic_symbol
660
     to traverse all GOT entries for a particular symbol.
661
662
     ??? We could've used root.got.glist field instead, but having
663
     a separate field is cleaner.  */
664
  struct elf_m68k_got_entry *glist;
665
};
666
667
0
#define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent))
668
669
/* Key part of GOT entry in hashtable.  */
670
struct elf_m68k_got_entry_key
671
{
672
  /* BFD in which this symbol was defined.  NULL for global symbols.  */
673
  const bfd *bfd;
674
675
  /* Symbol index.  Either local symbol index or h->got_entry_key.  */
676
  unsigned long symndx;
677
678
  /* Type is one of R_68K_GOT{8, 16, 32}O, R_68K_TLS_GD{8, 16, 32},
679
     R_68K_TLS_LDM{8, 16, 32} or R_68K_TLS_IE{8, 16, 32}.
680
681
     From perspective of hashtable key, only elf_m68k_got_reloc_type (type)
682
     matters.  That is, we distinguish between, say, R_68K_GOT16O
683
     and R_68K_GOT32O when allocating offsets, but they are considered to be
684
     the same when searching got->entries.  */
685
  enum elf_m68k_reloc_type type;
686
};
687
688
/* Size of the GOT offset suitable for relocation.  */
689
enum elf_m68k_got_offset_size { R_8, R_16, R_32, R_LAST };
690
691
/* Entry of the GOT.  */
692
struct elf_m68k_got_entry
693
{
694
  /* GOT entries are put into a got->entries hashtable.  This is the key.  */
695
  struct elf_m68k_got_entry_key key_;
696
697
  /* GOT entry data.  We need s1 before offset finalization and s2 after.  */
698
  union
699
  {
700
    struct
701
    {
702
      /* Number of times this entry is referenced.  */
703
      bfd_vma refcount;
704
    } s1;
705
706
    struct
707
    {
708
      /* Offset from the start of .got section.  To calculate offset relative
709
   to GOT pointer one should subtract got->offset from this value.  */
710
      bfd_vma offset;
711
712
      /* Pointer to the next GOT entry for this global symbol.
713
   Symbols have at most one entry in one GOT, but might
714
   have entries in more than one GOT.
715
   Root of this list is h->glist.
716
   NULL for local symbols.  */
717
      struct elf_m68k_got_entry *next;
718
    } s2;
719
  } u;
720
};
721
722
/* Return representative type for relocation R_TYPE.
723
   This is used to avoid enumerating many relocations in comparisons,
724
   switches etc.  */
725
726
static enum elf_m68k_reloc_type
727
elf_m68k_reloc_got_type (enum elf_m68k_reloc_type r_type)
728
0
{
729
0
  switch (r_type)
730
0
    {
731
      /* In most cases R_68K_GOTx relocations require the very same
732
   handling as R_68K_GOT32O relocation.  In cases when we need
733
   to distinguish between the two, we use explicitly compare against
734
   r_type.  */
735
0
    case R_68K_GOT32:
736
0
    case R_68K_GOT16:
737
0
    case R_68K_GOT8:
738
0
    case R_68K_GOT32O:
739
0
    case R_68K_GOT16O:
740
0
    case R_68K_GOT8O:
741
0
      return R_68K_GOT32O;
742
743
0
    case R_68K_TLS_GD32:
744
0
    case R_68K_TLS_GD16:
745
0
    case R_68K_TLS_GD8:
746
0
      return R_68K_TLS_GD32;
747
748
0
    case R_68K_TLS_LDM32:
749
0
    case R_68K_TLS_LDM16:
750
0
    case R_68K_TLS_LDM8:
751
0
      return R_68K_TLS_LDM32;
752
753
0
    case R_68K_TLS_IE32:
754
0
    case R_68K_TLS_IE16:
755
0
    case R_68K_TLS_IE8:
756
0
      return R_68K_TLS_IE32;
757
758
0
    default:
759
0
      BFD_ASSERT (false);
760
0
      return 0;
761
0
    }
762
0
}
763
764
/* Return size of the GOT entry offset for relocation R_TYPE.  */
765
766
static enum elf_m68k_got_offset_size
767
elf_m68k_reloc_got_offset_size (enum elf_m68k_reloc_type r_type)
768
0
{
769
0
  switch (r_type)
770
0
    {
771
0
    case R_68K_GOT32: case R_68K_GOT16: case R_68K_GOT8:
772
0
    case R_68K_GOT32O: case R_68K_TLS_GD32: case R_68K_TLS_LDM32:
773
0
    case R_68K_TLS_IE32:
774
0
      return R_32;
775
776
0
    case R_68K_GOT16O: case R_68K_TLS_GD16: case R_68K_TLS_LDM16:
777
0
    case R_68K_TLS_IE16:
778
0
      return R_16;
779
780
0
    case R_68K_GOT8O: case R_68K_TLS_GD8: case R_68K_TLS_LDM8:
781
0
    case R_68K_TLS_IE8:
782
0
      return R_8;
783
784
0
    default:
785
0
      BFD_ASSERT (false);
786
0
      return 0;
787
0
    }
788
0
}
789
790
/* Return number of GOT entries we need to allocate in GOT for
791
   relocation R_TYPE.  */
792
793
static bfd_vma
794
elf_m68k_reloc_got_n_slots (enum elf_m68k_reloc_type r_type)
795
0
{
796
0
  switch (elf_m68k_reloc_got_type (r_type))
797
0
    {
798
0
    case R_68K_GOT32O:
799
0
    case R_68K_TLS_IE32:
800
0
      return 1;
801
802
0
    case R_68K_TLS_GD32:
803
0
    case R_68K_TLS_LDM32:
804
0
      return 2;
805
806
0
    default:
807
0
      BFD_ASSERT (false);
808
0
      return 0;
809
0
    }
810
0
}
811
812
/* Return TRUE if relocation R_TYPE is a TLS one.  */
813
814
static bool
815
elf_m68k_reloc_tls_p (enum elf_m68k_reloc_type r_type)
816
0
{
817
0
  switch (r_type)
818
0
    {
819
0
    case R_68K_TLS_GD32: case R_68K_TLS_GD16: case R_68K_TLS_GD8:
820
0
    case R_68K_TLS_LDM32: case R_68K_TLS_LDM16: case R_68K_TLS_LDM8:
821
0
    case R_68K_TLS_LDO32: case R_68K_TLS_LDO16: case R_68K_TLS_LDO8:
822
0
    case R_68K_TLS_IE32: case R_68K_TLS_IE16: case R_68K_TLS_IE8:
823
0
    case R_68K_TLS_LE32: case R_68K_TLS_LE16: case R_68K_TLS_LE8:
824
0
    case R_68K_TLS_DTPMOD32: case R_68K_TLS_DTPREL32: case R_68K_TLS_TPREL32:
825
0
      return true;
826
827
0
    default:
828
0
      return false;
829
0
    }
830
0
}
831
832
/* Data structure representing a single GOT.  */
833
struct elf_m68k_got
834
{
835
  /* Hashtable of 'struct elf_m68k_got_entry's.
836
     Starting size of this table is the maximum number of
837
     R_68K_GOT8O entries.  */
838
  htab_t entries;
839
840
  /* Number of R_x slots in this GOT.  Some (e.g., TLS) entries require
841
     several GOT slots.
842
843
     n_slots[R_8] is the count of R_8 slots in this GOT.
844
     n_slots[R_16] is the cumulative count of R_8 and R_16 slots
845
     in this GOT.
846
     n_slots[R_32] is the cumulative count of R_8, R_16 and R_32 slots
847
     in this GOT.  This is the total number of slots.  */
848
  bfd_vma n_slots[R_LAST];
849
850
  /* Number of local (entry->key_.h == NULL) slots in this GOT.
851
     This is only used to properly calculate size of .rela.got section;
852
     see elf_m68k_partition_multi_got.  */
853
  bfd_vma local_n_slots;
854
855
  /* Offset of this GOT relative to beginning of .got section.  */
856
  bfd_vma offset;
857
};
858
859
/* BFD and its GOT.  This is an entry in multi_got->bfd2got hashtable.  */
860
struct elf_m68k_bfd2got_entry
861
{
862
  /* BFD.  */
863
  const bfd *bfd;
864
865
  /* Assigned GOT.  Before partitioning multi-GOT each BFD has its own
866
     GOT structure.  After partitioning several BFD's might [and often do]
867
     share a single GOT.  */
868
  struct elf_m68k_got *got;
869
};
870
871
/* The main data structure holding all the pieces.  */
872
struct elf_m68k_multi_got
873
{
874
  /* Hashtable mapping each BFD to its GOT.  If a BFD doesn't have an entry
875
     here, then it doesn't need a GOT (this includes the case of a BFD
876
     having an empty GOT).
877
878
     ??? This hashtable can be replaced by an array indexed by bfd->id.  */
879
  htab_t bfd2got;
880
881
  /* Next symndx to assign a global symbol.
882
     h->got_entry_key is initialized from this counter.  */
883
  unsigned long global_symndx;
884
};
885
886
/* m68k ELF linker hash table.  */
887
888
struct elf_m68k_link_hash_table
889
{
890
  struct elf_link_hash_table root;
891
892
  /* The PLT format used by this link, or NULL if the format has not
893
     yet been chosen.  */
894
  const struct elf_m68k_plt_info *plt_info;
895
896
  /* True, if GP is loaded within each function which uses it.
897
     Set to TRUE when GOT negative offsets or multi-GOT is enabled.  */
898
  bool local_gp_p;
899
900
  /* Switch controlling use of negative offsets to double the size of GOTs.  */
901
  bool use_neg_got_offsets_p;
902
903
  /* Switch controlling generation of multiple GOTs.  */
904
  bool allow_multigot_p;
905
906
  /* Multi-GOT data structure.  */
907
  struct elf_m68k_multi_got multi_got_;
908
};
909
910
/* Get the m68k ELF linker hash table from a link_info structure.  */
911
912
#define elf_m68k_hash_table(p) \
913
0
  ((is_elf_hash_table ((p)->hash)          \
914
0
    && elf_hash_table_id (elf_hash_table (p)) == M68K_ELF_DATA)   \
915
0
   ? (struct elf_m68k_link_hash_table *) (p)->hash : NULL)
916
917
/* Shortcut to multi-GOT data.  */
918
0
#define elf_m68k_multi_got(INFO) (&elf_m68k_hash_table (INFO)->multi_got_)
919
920
/* Create an entry in an m68k ELF linker hash table.  */
921
922
static struct bfd_hash_entry *
923
elf_m68k_link_hash_newfunc (struct bfd_hash_entry *entry,
924
          struct bfd_hash_table *table,
925
          const char *string)
926
0
{
927
0
  struct bfd_hash_entry *ret = entry;
928
929
  /* Allocate the structure if it has not already been allocated by a
930
     subclass.  */
931
0
  if (ret == NULL)
932
0
    ret = bfd_hash_allocate (table,
933
0
           sizeof (struct elf_m68k_link_hash_entry));
934
0
  if (ret == NULL)
935
0
    return ret;
936
937
  /* Call the allocation method of the superclass.  */
938
0
  ret = _bfd_elf_link_hash_newfunc (ret, table, string);
939
0
  if (ret != NULL)
940
0
    {
941
0
      elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL;
942
0
      elf_m68k_hash_entry (ret)->got_entry_key = 0;
943
0
      elf_m68k_hash_entry (ret)->glist = NULL;
944
0
    }
945
946
0
  return ret;
947
0
}
948
949
/* Destroy an m68k ELF linker hash table.  */
950
951
static void
952
elf_m68k_link_hash_table_free (bfd *obfd)
953
0
{
954
0
  struct elf_m68k_link_hash_table *htab;
955
956
0
  htab = (struct elf_m68k_link_hash_table *) obfd->link.hash;
957
958
0
  if (htab->multi_got_.bfd2got != NULL)
959
0
    {
960
0
      htab_delete (htab->multi_got_.bfd2got);
961
0
      htab->multi_got_.bfd2got = NULL;
962
0
    }
963
0
  _bfd_elf_link_hash_table_free (obfd);
964
0
}
965
966
/* Create an m68k ELF linker hash table.  */
967
968
static struct bfd_link_hash_table *
969
elf_m68k_link_hash_table_create (bfd *abfd)
970
0
{
971
0
  struct elf_m68k_link_hash_table *ret;
972
0
  size_t amt = sizeof (struct elf_m68k_link_hash_table);
973
974
0
  ret = (struct elf_m68k_link_hash_table *) bfd_zmalloc (amt);
975
0
  if (ret == (struct elf_m68k_link_hash_table *) NULL)
976
0
    return NULL;
977
978
0
  if (!_bfd_elf_link_hash_table_init (&ret->root, abfd,
979
0
              elf_m68k_link_hash_newfunc,
980
0
              sizeof (struct elf_m68k_link_hash_entry),
981
0
              M68K_ELF_DATA))
982
0
    {
983
0
      free (ret);
984
0
      return NULL;
985
0
    }
986
0
  ret->root.root.hash_table_free = elf_m68k_link_hash_table_free;
987
988
0
  ret->multi_got_.global_symndx = 1;
989
990
0
  return &ret->root.root;
991
0
}
992
993
/* Set the right machine number.  */
994
995
static bool
996
elf32_m68k_object_p (bfd *abfd)
997
11.6k
{
998
11.6k
  unsigned int mach = 0;
999
11.6k
  unsigned features = 0;
1000
11.6k
  flagword eflags = elf_elfheader (abfd)->e_flags;
1001
1002
11.6k
  if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1003
1.90k
    features |= m68000;
1004
9.71k
  else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1005
1.43k
    features |= cpu32;
1006
8.28k
  else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1007
485
    features |= fido_a;
1008
7.79k
  else
1009
7.79k
    {
1010
7.79k
      switch (eflags & EF_M68K_CF_ISA_MASK)
1011
7.79k
  {
1012
481
  case EF_M68K_CF_ISA_A_NODIV:
1013
481
    features |= mcfisa_a;
1014
481
    break;
1015
6
  case EF_M68K_CF_ISA_A:
1016
6
    features |= mcfisa_a|mcfhwdiv;
1017
6
    break;
1018
207
  case EF_M68K_CF_ISA_A_PLUS:
1019
207
    features |= mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp;
1020
207
    break;
1021
666
  case EF_M68K_CF_ISA_B_NOUSP:
1022
666
    features |= mcfisa_a|mcfisa_b|mcfhwdiv;
1023
666
    break;
1024
6
  case EF_M68K_CF_ISA_B:
1025
6
    features |= mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp;
1026
6
    break;
1027
2.14k
  case EF_M68K_CF_ISA_C:
1028
2.14k
    features |= mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp;
1029
2.14k
    break;
1030
672
  case EF_M68K_CF_ISA_C_NODIV:
1031
672
    features |= mcfisa_a|mcfisa_c|mcfusp;
1032
672
    break;
1033
7.79k
  }
1034
7.79k
      switch (eflags & EF_M68K_CF_MAC_MASK)
1035
7.79k
  {
1036
1.22k
  case EF_M68K_CF_MAC:
1037
1.22k
    features |= mcfmac;
1038
1.22k
    break;
1039
1.43k
  case EF_M68K_CF_EMAC:
1040
1.43k
    features |= mcfemac;
1041
1.43k
    break;
1042
7.79k
  }
1043
7.79k
      if (eflags & EF_M68K_CF_FLOAT)
1044
2.86k
  features |= cfloat;
1045
7.79k
    }
1046
1047
11.6k
  mach = bfd_m68k_features_to_mach (features);
1048
11.6k
  bfd_default_set_arch_mach (abfd, bfd_arch_m68k, mach);
1049
1050
11.6k
  return true;
1051
11.6k
}
1052
1053
/* Somewhat reverse of elf32_m68k_object_p, this sets the e_flag
1054
   field based on the machine number.  */
1055
1056
static bool
1057
elf_m68k_final_write_processing (bfd *abfd)
1058
0
{
1059
0
  int mach = bfd_get_mach (abfd);
1060
0
  unsigned long e_flags = elf_elfheader (abfd)->e_flags;
1061
1062
0
  if (!e_flags)
1063
0
    {
1064
0
      unsigned int arch_mask;
1065
1066
0
      arch_mask = bfd_m68k_mach_to_features (mach);
1067
1068
0
      if (arch_mask & m68000)
1069
0
  e_flags = EF_M68K_M68000;
1070
0
      else if (arch_mask & cpu32)
1071
0
  e_flags = EF_M68K_CPU32;
1072
0
      else if (arch_mask & fido_a)
1073
0
  e_flags = EF_M68K_FIDO;
1074
0
      else
1075
0
  {
1076
0
    switch (arch_mask
1077
0
      & (mcfisa_a | mcfisa_aa | mcfisa_b | mcfisa_c | mcfhwdiv | mcfusp))
1078
0
      {
1079
0
      case mcfisa_a:
1080
0
        e_flags |= EF_M68K_CF_ISA_A_NODIV;
1081
0
        break;
1082
0
      case mcfisa_a | mcfhwdiv:
1083
0
        e_flags |= EF_M68K_CF_ISA_A;
1084
0
        break;
1085
0
      case mcfisa_a | mcfisa_aa | mcfhwdiv | mcfusp:
1086
0
        e_flags |= EF_M68K_CF_ISA_A_PLUS;
1087
0
        break;
1088
0
      case mcfisa_a | mcfisa_b | mcfhwdiv:
1089
0
        e_flags |= EF_M68K_CF_ISA_B_NOUSP;
1090
0
        break;
1091
0
      case mcfisa_a | mcfisa_b | mcfhwdiv | mcfusp:
1092
0
        e_flags |= EF_M68K_CF_ISA_B;
1093
0
        break;
1094
0
      case mcfisa_a | mcfisa_c | mcfhwdiv | mcfusp:
1095
0
        e_flags |= EF_M68K_CF_ISA_C;
1096
0
        break;
1097
0
      case mcfisa_a | mcfisa_c | mcfusp:
1098
0
        e_flags |= EF_M68K_CF_ISA_C_NODIV;
1099
0
        break;
1100
0
      }
1101
0
    if (arch_mask & mcfmac)
1102
0
      e_flags |= EF_M68K_CF_MAC;
1103
0
    else if (arch_mask & mcfemac)
1104
0
      e_flags |= EF_M68K_CF_EMAC;
1105
0
    if (arch_mask & cfloat)
1106
0
      e_flags |= EF_M68K_CF_FLOAT | EF_M68K_CFV4E;
1107
0
  }
1108
0
      elf_elfheader (abfd)->e_flags = e_flags;
1109
0
    }
1110
0
  return _bfd_elf_final_write_processing (abfd);
1111
0
}
1112
1113
/* Keep m68k-specific flags in the ELF header.  */
1114
1115
static bool
1116
elf32_m68k_set_private_flags (bfd *abfd, flagword flags)
1117
0
{
1118
0
  elf_elfheader (abfd)->e_flags = flags;
1119
0
  elf_flags_init (abfd) = true;
1120
0
  return true;
1121
0
}
1122
1123
/* Merge object attributes from IBFD into OBFD.  Warn if
1124
   there are conflicting attributes. */
1125
static bool
1126
m68k_elf_merge_obj_attributes (bfd *ibfd, struct bfd_link_info *info)
1127
0
{
1128
0
  bfd *obfd = info->output_bfd;
1129
0
  obj_attribute *in_attr, *in_attrs;
1130
0
  obj_attribute *out_attr, *out_attrs;
1131
0
  bool ret = true;
1132
1133
0
  in_attrs = elf_known_obj_attributes (ibfd)[OBJ_ATTR_GNU];
1134
0
  out_attrs = elf_known_obj_attributes (obfd)[OBJ_ATTR_GNU];
1135
1136
0
  in_attr = &in_attrs[Tag_GNU_M68K_ABI_FP];
1137
0
  out_attr = &out_attrs[Tag_GNU_M68K_ABI_FP];
1138
1139
0
  if (in_attr->i != out_attr->i)
1140
0
    {
1141
0
      int in_fp = in_attr->i & 3;
1142
0
      int out_fp = out_attr->i & 3;
1143
0
      static bfd *last_fp;
1144
1145
0
      if (in_fp == 0)
1146
0
  ;
1147
0
      else if (out_fp == 0)
1148
0
  {
1149
0
    out_attr->type = ATTR_TYPE_FLAG_INT_VAL;
1150
0
    out_attr->i ^= in_fp;
1151
0
    last_fp = ibfd;
1152
0
  }
1153
0
      else if (out_fp == 1 && in_fp == 2)
1154
0
  {
1155
0
    _bfd_error_handler
1156
      /* xgettext:c-format */
1157
0
      (_("%pB uses hard float, %pB uses soft float"),
1158
0
       last_fp, ibfd);
1159
0
    ret = false;
1160
0
  }
1161
0
      else if (out_fp == 2 && in_fp == 1)
1162
0
  {
1163
0
    _bfd_error_handler
1164
      /* xgettext:c-format */
1165
0
      (_("%pB uses hard float, %pB uses soft float"),
1166
0
       ibfd, last_fp);
1167
0
    ret = false;
1168
0
  }
1169
0
    }
1170
1171
0
  if (!ret)
1172
0
    {
1173
0
      out_attr->type = ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_ERROR;
1174
0
      bfd_set_error (bfd_error_bad_value);
1175
0
      return false;
1176
0
    }
1177
1178
  /* Merge Tag_compatibility attributes and any common GNU ones.  */
1179
0
  return _bfd_elf_merge_object_attributes (ibfd, info);
1180
0
}
1181
1182
/* Merge backend specific data from an object file to the output
1183
   object file when linking.  */
1184
static bool
1185
elf32_m68k_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
1186
0
{
1187
0
  bfd *obfd = info->output_bfd;
1188
0
  flagword out_flags;
1189
0
  flagword in_flags;
1190
0
  flagword out_isa;
1191
0
  flagword in_isa;
1192
0
  const bfd_arch_info_type *arch_info;
1193
1194
0
  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
1195
0
      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
1196
    /* PR 24523: For non-ELF files do not try to merge any private
1197
       data, but also do not prevent the link from succeeding.  */
1198
0
    return true;
1199
1200
  /* Get the merged machine.  This checks for incompatibility between
1201
     Coldfire & non-Coldfire flags, incompability between different
1202
     Coldfire ISAs, and incompability between different MAC types.  */
1203
0
  arch_info = bfd_arch_get_compatible (ibfd, obfd, false);
1204
0
  if (!arch_info)
1205
0
    return false;
1206
1207
0
  bfd_set_arch_mach (obfd, bfd_arch_m68k, arch_info->mach);
1208
1209
0
  if (!m68k_elf_merge_obj_attributes (ibfd, info))
1210
0
    return false;
1211
1212
0
  in_flags = elf_elfheader (ibfd)->e_flags;
1213
0
  if (!elf_flags_init (obfd))
1214
0
    {
1215
0
      elf_flags_init (obfd) = true;
1216
0
      out_flags = in_flags;
1217
0
    }
1218
0
  else
1219
0
    {
1220
0
      out_flags = elf_elfheader (obfd)->e_flags;
1221
0
      unsigned int variant_mask;
1222
1223
0
      if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1224
0
  variant_mask = 0;
1225
0
      else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1226
0
  variant_mask = 0;
1227
0
      else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1228
0
  variant_mask = 0;
1229
0
      else
1230
0
  variant_mask = EF_M68K_CF_ISA_MASK;
1231
1232
0
      in_isa = (in_flags & variant_mask);
1233
0
      out_isa = (out_flags & variant_mask);
1234
0
      if (in_isa > out_isa)
1235
0
  out_flags ^= in_isa ^ out_isa;
1236
0
      if (((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32
1237
0
     && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1238
0
    || ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO
1239
0
        && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32))
1240
0
  out_flags = EF_M68K_FIDO;
1241
0
      else
1242
0
      out_flags |= in_flags ^ in_isa;
1243
0
    }
1244
0
  elf_elfheader (obfd)->e_flags = out_flags;
1245
1246
0
  return true;
1247
0
}
1248
1249
/* Display the flags field.  */
1250
1251
static bool
1252
elf32_m68k_print_private_bfd_data (bfd *abfd, void * ptr)
1253
27
{
1254
27
  FILE *file = (FILE *) ptr;
1255
27
  flagword eflags = elf_elfheader (abfd)->e_flags;
1256
1257
27
  BFD_ASSERT (abfd != NULL && ptr != NULL);
1258
1259
  /* Print normal ELF private data.  */
1260
27
  _bfd_elf_print_private_bfd_data (abfd, ptr);
1261
1262
  /* Ignore init flag - it may not be set, despite the flags field containing valid data.  */
1263
1264
  /* xgettext:c-format */
1265
27
  fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
1266
1267
27
  if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000)
1268
2
    fprintf (file, " [m68000]");
1269
25
  else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)
1270
2
    fprintf (file, " [cpu32]");
1271
23
  else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO)
1272
2
    fprintf (file, " [fido]");
1273
21
  else
1274
21
    {
1275
21
      if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CFV4E)
1276
1
  fprintf (file, " [cfv4e]");
1277
1278
21
      if (eflags & EF_M68K_CF_ISA_MASK)
1279
12
  {
1280
12
    char const *isa = _("unknown");
1281
12
    char const *mac = _("unknown");
1282
12
    char const *additional = "";
1283
1284
12
    switch (eflags & EF_M68K_CF_ISA_MASK)
1285
12
      {
1286
2
      case EF_M68K_CF_ISA_A_NODIV:
1287
2
        isa = "A";
1288
2
        additional = " [nodiv]";
1289
2
        break;
1290
0
      case EF_M68K_CF_ISA_A:
1291
0
        isa = "A";
1292
0
        break;
1293
0
      case EF_M68K_CF_ISA_A_PLUS:
1294
0
        isa = "A+";
1295
0
        break;
1296
0
      case EF_M68K_CF_ISA_B_NOUSP:
1297
0
        isa = "B";
1298
0
        additional = " [nousp]";
1299
0
        break;
1300
1
      case EF_M68K_CF_ISA_B:
1301
1
        isa = "B";
1302
1
        break;
1303
2
      case EF_M68K_CF_ISA_C:
1304
2
        isa = "C";
1305
2
        break;
1306
0
      case EF_M68K_CF_ISA_C_NODIV:
1307
0
        isa = "C";
1308
0
        additional = " [nodiv]";
1309
0
        break;
1310
12
      }
1311
12
    fprintf (file, " [isa %s]%s", isa, additional);
1312
1313
12
    if (eflags & EF_M68K_CF_FLOAT)
1314
9
      fprintf (file, " [float]");
1315
1316
12
    switch (eflags & EF_M68K_CF_MAC_MASK)
1317
12
      {
1318
1
      case 0:
1319
1
        mac = NULL;
1320
1
        break;
1321
1
      case EF_M68K_CF_MAC:
1322
1
        mac = "mac";
1323
1
        break;
1324
2
      case EF_M68K_CF_EMAC:
1325
2
        mac = "emac";
1326
2
        break;
1327
8
      case EF_M68K_CF_EMAC_B:
1328
8
        mac = "emac_b";
1329
8
        break;
1330
12
      }
1331
12
    if (mac)
1332
11
      fprintf (file, " [%s]", mac);
1333
12
  }
1334
21
    }
1335
1336
27
  fputc ('\n', file);
1337
1338
27
  return true;
1339
27
}
1340
1341
/* Multi-GOT support implementation design:
1342
1343
   Multi-GOT starts in check_relocs hook.  There we scan all
1344
   relocations of a BFD and build a local GOT (struct elf_m68k_got)
1345
   for it.  If a single BFD appears to require too many GOT slots with
1346
   R_68K_GOT8O or R_68K_GOT16O relocations, we fail with notification
1347
   to user.
1348
   After check_relocs has been invoked for each input BFD, we have
1349
   constructed a GOT for each input BFD.
1350
1351
   To minimize total number of GOTs required for a particular output BFD
1352
   (as some environments support only 1 GOT per output object) we try
1353
   to merge some of the GOTs to share an offset space.  Ideally [and in most
1354
   cases] we end up with a single GOT.  In cases when there are too many
1355
   restricted relocations (e.g., R_68K_GOT16O relocations) we end up with
1356
   several GOTs, assuming the environment can handle them.
1357
1358
   Partitioning is done in elf_m68k_partition_multi_got.  We start with
1359
   an empty GOT and traverse bfd2got hashtable putting got_entries from
1360
   local GOTs to the new 'big' one.  We do that by constructing an
1361
   intermediate GOT holding all the entries the local GOT has and the big
1362
   GOT lacks.  Then we check if there is room in the big GOT to accomodate
1363
   all the entries from diff.  On success we add those entries to the big
1364
   GOT; on failure we start the new 'big' GOT and retry the adding of
1365
   entries from the local GOT.  Note that this retry will always succeed as
1366
   each local GOT doesn't overflow the limits.  After partitioning we
1367
   end up with each bfd assigned one of the big GOTs.  GOT entries in the
1368
   big GOTs are initialized with GOT offsets.  Note that big GOTs are
1369
   positioned consequently in program space and represent a single huge GOT
1370
   to the outside world.
1371
1372
   After that we get to elf_m68k_relocate_section.  There we
1373
   adjust relocations of GOT pointer (_GLOBAL_OFFSET_TABLE_) and symbol
1374
   relocations to refer to appropriate [assigned to current input_bfd]
1375
   big GOT.
1376
1377
   Notes:
1378
1379
   GOT entry type: We have several types of GOT entries.
1380
   * R_8 type is used in entries for symbols that have at least one
1381
   R_68K_GOT8O or R_68K_TLS_*8 relocation.  We can have at most 0x40
1382
   such entries in one GOT.
1383
   * R_16 type is used in entries for symbols that have at least one
1384
   R_68K_GOT16O or R_68K_TLS_*16 relocation and no R_8 relocations.
1385
   We can have at most 0x4000 such entries in one GOT.
1386
   * R_32 type is used in all other cases.  We can have as many
1387
   such entries in one GOT as we'd like.
1388
   When counting relocations we have to include the count of the smaller
1389
   ranged relocations in the counts of the larger ranged ones in order
1390
   to correctly detect overflow.
1391
1392
   Sorting the GOT: In each GOT starting offsets are assigned to
1393
   R_8 entries, which are followed by R_16 entries, and
1394
   R_32 entries go at the end.  See finalize_got_offsets for details.
1395
1396
   Negative GOT offsets: To double usable offset range of GOTs we use
1397
   negative offsets.  As we assign entries with GOT offsets relative to
1398
   start of .got section, the offset values are positive.  They become
1399
   negative only in relocate_section where got->offset value is
1400
   subtracted from them.
1401
1402
   3 special GOT entries: There are 3 special GOT entries used internally
1403
   by loader.  These entries happen to be placed to .got.plt section,
1404
   so we don't do anything about them in multi-GOT support.
1405
1406
   Memory management: All data except for hashtables
1407
   multi_got->bfd2got and got->entries are allocated on
1408
   elf_hash_table (info)->dynobj bfd (for this reason we pass 'info'
1409
   to most functions), so we don't need to care to free them.  At the
1410
   moment of allocation hashtables are being linked into main data
1411
   structure (multi_got), all pieces of which are reachable from
1412
   elf_m68k_multi_got (info).  We deallocate them in
1413
   elf_m68k_link_hash_table_free.  */
1414
1415
/* Initialize GOT.  */
1416
1417
static void
1418
elf_m68k_init_got (struct elf_m68k_got *got)
1419
0
{
1420
0
  got->entries = NULL;
1421
0
  got->n_slots[R_8] = 0;
1422
0
  got->n_slots[R_16] = 0;
1423
0
  got->n_slots[R_32] = 0;
1424
0
  got->local_n_slots = 0;
1425
0
  got->offset = (bfd_vma) -1;
1426
0
}
1427
1428
/* Destruct GOT.  */
1429
1430
static void
1431
elf_m68k_clear_got (struct elf_m68k_got *got)
1432
0
{
1433
0
  if (got->entries != NULL)
1434
0
    {
1435
0
      htab_delete (got->entries);
1436
0
      got->entries = NULL;
1437
0
    }
1438
0
}
1439
1440
/* Create and empty GOT structure.  INFO is the context where memory
1441
   should be allocated.  */
1442
1443
static struct elf_m68k_got *
1444
elf_m68k_create_empty_got (struct bfd_link_info *info)
1445
0
{
1446
0
  struct elf_m68k_got *got;
1447
1448
0
  got = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*got));
1449
0
  if (got == NULL)
1450
0
    return NULL;
1451
1452
0
  elf_m68k_init_got (got);
1453
1454
0
  return got;
1455
0
}
1456
1457
/* Initialize KEY.  */
1458
1459
static void
1460
elf_m68k_init_got_entry_key (struct elf_m68k_got_entry_key *key,
1461
           struct elf_link_hash_entry *h,
1462
           const bfd *abfd, unsigned long symndx,
1463
           enum elf_m68k_reloc_type reloc_type)
1464
0
{
1465
0
  if (elf_m68k_reloc_got_type (reloc_type) == R_68K_TLS_LDM32)
1466
    /* All TLS_LDM relocations share a single GOT entry.  */
1467
0
    {
1468
0
      key->bfd = NULL;
1469
0
      key->symndx = 0;
1470
0
    }
1471
0
  else if (h != NULL)
1472
    /* Global symbols are identified with their got_entry_key.  */
1473
0
    {
1474
0
      key->bfd = NULL;
1475
0
      key->symndx = elf_m68k_hash_entry (h)->got_entry_key;
1476
0
      BFD_ASSERT (key->symndx != 0);
1477
0
    }
1478
0
  else
1479
    /* Local symbols are identified by BFD they appear in and symndx.  */
1480
0
    {
1481
0
      key->bfd = abfd;
1482
0
      key->symndx = symndx;
1483
0
    }
1484
1485
0
  key->type = reloc_type;
1486
0
}
1487
1488
/* Calculate hash of got_entry.
1489
   ??? Is it good?  */
1490
1491
static hashval_t
1492
elf_m68k_got_entry_hash (const void *_entry)
1493
0
{
1494
0
  const struct elf_m68k_got_entry_key *key;
1495
1496
0
  key = &((const struct elf_m68k_got_entry *) _entry)->key_;
1497
1498
0
  return (key->symndx
1499
0
    + (key->bfd != NULL ? (int) key->bfd->id : -1)
1500
0
    + elf_m68k_reloc_got_type (key->type));
1501
0
}
1502
1503
/* Check if two got entries are equal.  */
1504
1505
static int
1506
elf_m68k_got_entry_eq (const void *_entry1, const void *_entry2)
1507
0
{
1508
0
  const struct elf_m68k_got_entry_key *key1;
1509
0
  const struct elf_m68k_got_entry_key *key2;
1510
1511
0
  key1 = &((const struct elf_m68k_got_entry *) _entry1)->key_;
1512
0
  key2 = &((const struct elf_m68k_got_entry *) _entry2)->key_;
1513
1514
0
  return (key1->bfd == key2->bfd
1515
0
    && key1->symndx == key2->symndx
1516
0
    && (elf_m68k_reloc_got_type (key1->type)
1517
0
        == elf_m68k_reloc_got_type (key2->type)));
1518
0
}
1519
1520
/* When using negative offsets, we allocate one extra R_8, one extra R_16
1521
   and one extra R_32 slots to simplify handling of 2-slot entries during
1522
   offset allocation -- hence -1 for R_8 slots and -2 for R_16 slots.  */
1523
1524
/* Maximal number of R_8 slots in a single GOT.  */
1525
#define ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT(INFO)   \
1526
0
  (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p    \
1527
0
   ? (0x40 - 1)              \
1528
0
   : 0x20)
1529
1530
/* Maximal number of R_8 and R_16 slots in a single GOT.  */
1531
#define ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT(INFO)    \
1532
0
  (elf_m68k_hash_table (INFO)->use_neg_got_offsets_p    \
1533
0
   ? (0x4000 - 2)            \
1534
0
   : 0x2000)
1535
1536
/* SEARCH - simply search the hashtable, don't insert new entries or fail when
1537
   the entry cannot be found.
1538
   FIND_OR_CREATE - search for an existing entry, but create new if there's
1539
   no such.
1540
   MUST_FIND - search for an existing entry and assert that it exist.
1541
   MUST_CREATE - assert that there's no such entry and create new one.  */
1542
enum elf_m68k_get_entry_howto
1543
  {
1544
    SEARCH,
1545
    FIND_OR_CREATE,
1546
    MUST_FIND,
1547
    MUST_CREATE
1548
  };
1549
1550
/* Get or create (depending on HOWTO) entry with KEY in GOT.
1551
   INFO is context in which memory should be allocated (can be NULL if
1552
   HOWTO is SEARCH or MUST_FIND).  */
1553
1554
static struct elf_m68k_got_entry *
1555
elf_m68k_get_got_entry (struct elf_m68k_got *got,
1556
      const struct elf_m68k_got_entry_key *key,
1557
      enum elf_m68k_get_entry_howto howto,
1558
      struct bfd_link_info *info)
1559
0
{
1560
0
  struct elf_m68k_got_entry entry_;
1561
0
  struct elf_m68k_got_entry *entry;
1562
0
  void **ptr;
1563
1564
0
  BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
1565
1566
0
  if (got->entries == NULL)
1567
    /* This is the first entry in ABFD.  Initialize hashtable.  */
1568
0
    {
1569
0
      if (howto == SEARCH)
1570
0
  return NULL;
1571
1572
0
      got->entries = htab_try_create (ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT
1573
0
              (info),
1574
0
              elf_m68k_got_entry_hash,
1575
0
              elf_m68k_got_entry_eq, NULL);
1576
0
      if (got->entries == NULL)
1577
0
  {
1578
0
    bfd_set_error (bfd_error_no_memory);
1579
0
    return NULL;
1580
0
  }
1581
0
    }
1582
1583
0
  entry_.key_ = *key;
1584
0
  ptr = htab_find_slot (got->entries, &entry_,
1585
0
      (howto == SEARCH || howto == MUST_FIND ? NO_INSERT
1586
0
       : INSERT));
1587
0
  if (ptr == NULL)
1588
0
    {
1589
0
      if (howto == SEARCH)
1590
  /* Entry not found.  */
1591
0
  return NULL;
1592
1593
0
      if (howto == MUST_FIND)
1594
0
  abort ();
1595
1596
      /* We're out of memory.  */
1597
0
      bfd_set_error (bfd_error_no_memory);
1598
0
      return NULL;
1599
0
    }
1600
1601
0
  if (*ptr == NULL)
1602
    /* We didn't find the entry and we're asked to create a new one.  */
1603
0
    {
1604
0
      if (howto == MUST_FIND)
1605
0
  abort ();
1606
1607
0
      BFD_ASSERT (howto != SEARCH);
1608
1609
0
      entry = bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry));
1610
0
      if (entry == NULL)
1611
0
  return NULL;
1612
1613
      /* Initialize new entry.  */
1614
0
      entry->key_ = *key;
1615
1616
0
      entry->u.s1.refcount = 0;
1617
1618
      /* Mark the entry as not initialized.  */
1619
0
      entry->key_.type = R_68K_max;
1620
1621
0
      *ptr = entry;
1622
0
    }
1623
0
  else
1624
    /* We found the entry.  */
1625
0
    {
1626
0
      BFD_ASSERT (howto != MUST_CREATE);
1627
1628
0
      entry = *ptr;
1629
0
    }
1630
1631
0
  return entry;
1632
0
}
1633
1634
/* Update GOT counters when merging entry of WAS type with entry of NEW type.
1635
   Return the value to which ENTRY's type should be set.  */
1636
1637
static enum elf_m68k_reloc_type
1638
elf_m68k_update_got_entry_type (struct elf_m68k_got *got,
1639
        enum elf_m68k_reloc_type was,
1640
        enum elf_m68k_reloc_type new_reloc)
1641
0
{
1642
0
  enum elf_m68k_got_offset_size was_size;
1643
0
  enum elf_m68k_got_offset_size new_size;
1644
0
  bfd_vma n_slots;
1645
1646
0
  if (was == R_68K_max)
1647
    /* The type of the entry is not initialized yet.  */
1648
0
    {
1649
      /* Update all got->n_slots counters, including n_slots[R_32].  */
1650
0
      was_size = R_LAST;
1651
1652
0
      was = new_reloc;
1653
0
    }
1654
0
  else
1655
0
    {
1656
      /* !!! We, probably, should emit an error rather then fail on assert
1657
   in such a case.  */
1658
0
      BFD_ASSERT (elf_m68k_reloc_got_type (was)
1659
0
      == elf_m68k_reloc_got_type (new_reloc));
1660
1661
0
      was_size = elf_m68k_reloc_got_offset_size (was);
1662
0
    }
1663
1664
0
  new_size = elf_m68k_reloc_got_offset_size (new_reloc);
1665
0
  n_slots = elf_m68k_reloc_got_n_slots (new_reloc);
1666
1667
0
  while (was_size > new_size)
1668
0
    {
1669
0
      --was_size;
1670
0
      got->n_slots[was_size] += n_slots;
1671
0
    }
1672
1673
0
  if (new_reloc > was)
1674
    /* Relocations are ordered from bigger got offset size to lesser,
1675
       so choose the relocation type with lesser offset size.  */
1676
0
    was = new_reloc;
1677
1678
0
  return was;
1679
0
}
1680
1681
/* Add new or update existing entry to GOT.
1682
   H, ABFD, TYPE and SYMNDX is data for the entry.
1683
   INFO is a context where memory should be allocated.  */
1684
1685
static struct elf_m68k_got_entry *
1686
elf_m68k_add_entry_to_got (struct elf_m68k_got *got,
1687
         struct elf_link_hash_entry *h,
1688
         const bfd *abfd,
1689
         enum elf_m68k_reloc_type reloc_type,
1690
         unsigned long symndx,
1691
         struct bfd_link_info *info)
1692
0
{
1693
0
  struct elf_m68k_got_entry_key key_;
1694
0
  struct elf_m68k_got_entry *entry;
1695
1696
0
  if (h != NULL && elf_m68k_hash_entry (h)->got_entry_key == 0)
1697
0
    elf_m68k_hash_entry (h)->got_entry_key
1698
0
      = elf_m68k_multi_got (info)->global_symndx++;
1699
1700
0
  elf_m68k_init_got_entry_key (&key_, h, abfd, symndx, reloc_type);
1701
1702
0
  entry = elf_m68k_get_got_entry (got, &key_, FIND_OR_CREATE, info);
1703
0
  if (entry == NULL)
1704
0
    return NULL;
1705
1706
  /* Determine entry's type and update got->n_slots counters.  */
1707
0
  entry->key_.type = elf_m68k_update_got_entry_type (got,
1708
0
                 entry->key_.type,
1709
0
                 reloc_type);
1710
1711
  /* Update refcount.  */
1712
0
  ++entry->u.s1.refcount;
1713
1714
0
  if (entry->u.s1.refcount == 1)
1715
    /* We see this entry for the first time.  */
1716
0
    {
1717
0
      if (entry->key_.bfd != NULL)
1718
0
  got->local_n_slots += elf_m68k_reloc_got_n_slots (entry->key_.type);
1719
0
    }
1720
1721
0
  BFD_ASSERT (got->n_slots[R_32] >= got->local_n_slots);
1722
1723
0
  if ((got->n_slots[R_8]
1724
0
       > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1725
0
      || (got->n_slots[R_16]
1726
0
    > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))
1727
    /* This BFD has too many relocation.  */
1728
0
    {
1729
0
      if (got->n_slots[R_8] > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1730
  /* xgettext:c-format */
1731
0
  _bfd_error_handler (_("%pB: GOT overflow: "
1732
0
            "number of relocations with 8-bit "
1733
0
            "offset > %d"),
1734
0
          abfd,
1735
0
          ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info));
1736
0
      else
1737
  /* xgettext:c-format */
1738
0
  _bfd_error_handler (_("%pB: GOT overflow: "
1739
0
            "number of relocations with 8- or 16-bit "
1740
0
            "offset > %d"),
1741
0
          abfd,
1742
0
          ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info));
1743
1744
0
      return NULL;
1745
0
    }
1746
1747
0
  return entry;
1748
0
}
1749
1750
/* Compute the hash value of the bfd in a bfd2got hash entry.  */
1751
1752
static hashval_t
1753
elf_m68k_bfd2got_entry_hash (const void *entry)
1754
0
{
1755
0
  const struct elf_m68k_bfd2got_entry *e;
1756
1757
0
  e = (const struct elf_m68k_bfd2got_entry *) entry;
1758
1759
0
  return e->bfd->id;
1760
0
}
1761
1762
/* Check whether two hash entries have the same bfd.  */
1763
1764
static int
1765
elf_m68k_bfd2got_entry_eq (const void *entry1, const void *entry2)
1766
0
{
1767
0
  const struct elf_m68k_bfd2got_entry *e1;
1768
0
  const struct elf_m68k_bfd2got_entry *e2;
1769
1770
0
  e1 = (const struct elf_m68k_bfd2got_entry *) entry1;
1771
0
  e2 = (const struct elf_m68k_bfd2got_entry *) entry2;
1772
1773
0
  return e1->bfd == e2->bfd;
1774
0
}
1775
1776
/* Destruct a bfd2got entry.  */
1777
1778
static void
1779
elf_m68k_bfd2got_entry_del (void *_entry)
1780
0
{
1781
0
  struct elf_m68k_bfd2got_entry *entry;
1782
1783
0
  entry = (struct elf_m68k_bfd2got_entry *) _entry;
1784
1785
0
  BFD_ASSERT (entry->got != NULL);
1786
0
  elf_m68k_clear_got (entry->got);
1787
0
}
1788
1789
/* Find existing or create new (depending on HOWTO) bfd2got entry in
1790
   MULTI_GOT.  ABFD is the bfd we need a GOT for.  INFO is a context where
1791
   memory should be allocated.  */
1792
1793
static struct elf_m68k_bfd2got_entry *
1794
elf_m68k_get_bfd2got_entry (struct elf_m68k_multi_got *multi_got,
1795
          const bfd *abfd,
1796
          enum elf_m68k_get_entry_howto howto,
1797
          struct bfd_link_info *info)
1798
0
{
1799
0
  struct elf_m68k_bfd2got_entry entry_;
1800
0
  void **ptr;
1801
0
  struct elf_m68k_bfd2got_entry *entry;
1802
1803
0
  BFD_ASSERT ((info == NULL) == (howto == SEARCH || howto == MUST_FIND));
1804
1805
0
  if (multi_got->bfd2got == NULL)
1806
    /* This is the first GOT.  Initialize bfd2got.  */
1807
0
    {
1808
0
      if (howto == SEARCH)
1809
0
  return NULL;
1810
1811
0
      multi_got->bfd2got = htab_try_create (1, elf_m68k_bfd2got_entry_hash,
1812
0
              elf_m68k_bfd2got_entry_eq,
1813
0
              elf_m68k_bfd2got_entry_del);
1814
0
      if (multi_got->bfd2got == NULL)
1815
0
  {
1816
0
    bfd_set_error (bfd_error_no_memory);
1817
0
    return NULL;
1818
0
  }
1819
0
    }
1820
1821
0
  entry_.bfd = abfd;
1822
0
  ptr = htab_find_slot (multi_got->bfd2got, &entry_,
1823
0
      (howto == SEARCH || howto == MUST_FIND ? NO_INSERT
1824
0
       : INSERT));
1825
0
  if (ptr == NULL)
1826
0
    {
1827
0
      if (howto == SEARCH)
1828
  /* Entry not found.  */
1829
0
  return NULL;
1830
1831
0
      if (howto == MUST_FIND)
1832
0
  abort ();
1833
1834
      /* We're out of memory.  */
1835
0
      bfd_set_error (bfd_error_no_memory);
1836
0
      return NULL;
1837
0
    }
1838
1839
0
  if (*ptr == NULL)
1840
    /* Entry was not found.  Create new one.  */
1841
0
    {
1842
0
      if (howto == MUST_FIND)
1843
0
  abort ();
1844
1845
0
      BFD_ASSERT (howto != SEARCH);
1846
1847
0
      entry = ((struct elf_m68k_bfd2got_entry *)
1848
0
         bfd_alloc (elf_hash_table (info)->dynobj, sizeof (*entry)));
1849
0
      if (entry == NULL)
1850
0
  return NULL;
1851
1852
0
      entry->bfd = abfd;
1853
1854
0
      entry->got = elf_m68k_create_empty_got (info);
1855
0
      if (entry->got == NULL)
1856
0
  return NULL;
1857
1858
0
      *ptr = entry;
1859
0
    }
1860
0
  else
1861
0
    {
1862
0
      BFD_ASSERT (howto != MUST_CREATE);
1863
1864
      /* Return existing entry.  */
1865
0
      entry = *ptr;
1866
0
    }
1867
1868
0
  return entry;
1869
0
}
1870
1871
struct elf_m68k_can_merge_gots_arg
1872
{
1873
  /* A current_got that we constructing a DIFF against.  */
1874
  struct elf_m68k_got *big;
1875
1876
  /* GOT holding entries not present or that should be changed in
1877
     BIG.  */
1878
  struct elf_m68k_got *diff;
1879
1880
  /* Context where to allocate memory.  */
1881
  struct bfd_link_info *info;
1882
1883
  /* Error flag.  */
1884
  bool error_p;
1885
};
1886
1887
/* Process a single entry from the small GOT to see if it should be added
1888
   or updated in the big GOT.  */
1889
1890
static int
1891
elf_m68k_can_merge_gots_1 (void **_entry_ptr, void *_arg)
1892
0
{
1893
0
  const struct elf_m68k_got_entry *entry1;
1894
0
  struct elf_m68k_can_merge_gots_arg *arg;
1895
0
  const struct elf_m68k_got_entry *entry2;
1896
0
  enum elf_m68k_reloc_type type;
1897
1898
0
  entry1 = (const struct elf_m68k_got_entry *) *_entry_ptr;
1899
0
  arg = (struct elf_m68k_can_merge_gots_arg *) _arg;
1900
1901
0
  entry2 = elf_m68k_get_got_entry (arg->big, &entry1->key_, SEARCH, NULL);
1902
1903
0
  if (entry2 != NULL)
1904
    /* We found an existing entry.  Check if we should update it.  */
1905
0
    {
1906
0
      type = elf_m68k_update_got_entry_type (arg->diff,
1907
0
               entry2->key_.type,
1908
0
               entry1->key_.type);
1909
1910
0
      if (type == entry2->key_.type)
1911
  /* ENTRY1 doesn't update data in ENTRY2.  Skip it.
1912
     To skip creation of difference entry we use the type,
1913
     which we won't see in GOT entries for sure.  */
1914
0
  type = R_68K_max;
1915
0
    }
1916
0
  else
1917
    /* We didn't find the entry.  Add entry1 to DIFF.  */
1918
0
    {
1919
0
      BFD_ASSERT (entry1->key_.type != R_68K_max);
1920
1921
0
      type = elf_m68k_update_got_entry_type (arg->diff,
1922
0
               R_68K_max, entry1->key_.type);
1923
1924
0
      if (entry1->key_.bfd != NULL)
1925
0
  arg->diff->local_n_slots += elf_m68k_reloc_got_n_slots (type);
1926
0
    }
1927
1928
0
  if (type != R_68K_max)
1929
    /* Create an entry in DIFF.  */
1930
0
    {
1931
0
      struct elf_m68k_got_entry *entry;
1932
1933
0
      entry = elf_m68k_get_got_entry (arg->diff, &entry1->key_, MUST_CREATE,
1934
0
              arg->info);
1935
0
      if (entry == NULL)
1936
0
  {
1937
0
    arg->error_p = true;
1938
0
    return 0;
1939
0
  }
1940
1941
0
      entry->key_.type = type;
1942
0
    }
1943
1944
0
  return 1;
1945
0
}
1946
1947
/* Return TRUE if SMALL GOT can be added to BIG GOT without overflowing it.
1948
   Construct DIFF GOT holding the entries which should be added or updated
1949
   in BIG GOT to accumulate information from SMALL.
1950
   INFO is the context where memory should be allocated.  */
1951
1952
static bool
1953
elf_m68k_can_merge_gots (struct elf_m68k_got *big,
1954
       const struct elf_m68k_got *small,
1955
       struct bfd_link_info *info,
1956
       struct elf_m68k_got *diff)
1957
0
{
1958
0
  struct elf_m68k_can_merge_gots_arg arg_;
1959
1960
0
  BFD_ASSERT (small->offset == (bfd_vma) -1);
1961
1962
0
  arg_.big = big;
1963
0
  arg_.diff = diff;
1964
0
  arg_.info = info;
1965
0
  arg_.error_p = false;
1966
0
  htab_traverse_noresize (small->entries, elf_m68k_can_merge_gots_1, &arg_);
1967
0
  if (arg_.error_p)
1968
0
    {
1969
0
      diff->offset = 0;
1970
0
      return false;
1971
0
    }
1972
1973
  /* Check for overflow.  */
1974
0
  if ((big->n_slots[R_8] + arg_.diff->n_slots[R_8]
1975
0
       > ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
1976
0
      || (big->n_slots[R_16] + arg_.diff->n_slots[R_16]
1977
0
    > ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info)))
1978
0
    return false;
1979
1980
0
  return true;
1981
0
}
1982
1983
struct elf_m68k_merge_gots_arg
1984
{
1985
  /* The BIG got.  */
1986
  struct elf_m68k_got *big;
1987
1988
  /* Context where memory should be allocated.  */
1989
  struct bfd_link_info *info;
1990
1991
  /* Error flag.  */
1992
  bool error_p;
1993
};
1994
1995
/* Process a single entry from DIFF got.  Add or update corresponding
1996
   entry in the BIG got.  */
1997
1998
static int
1999
elf_m68k_merge_gots_1 (void **entry_ptr, void *_arg)
2000
0
{
2001
0
  const struct elf_m68k_got_entry *from;
2002
0
  struct elf_m68k_merge_gots_arg *arg;
2003
0
  struct elf_m68k_got_entry *to;
2004
2005
0
  from = (const struct elf_m68k_got_entry *) *entry_ptr;
2006
0
  arg = (struct elf_m68k_merge_gots_arg *) _arg;
2007
2008
0
  to = elf_m68k_get_got_entry (arg->big, &from->key_, FIND_OR_CREATE,
2009
0
             arg->info);
2010
0
  if (to == NULL)
2011
0
    {
2012
0
      arg->error_p = true;
2013
0
      return 0;
2014
0
    }
2015
2016
0
  BFD_ASSERT (to->u.s1.refcount == 0);
2017
  /* All we need to merge is TYPE.  */
2018
0
  to->key_.type = from->key_.type;
2019
2020
0
  return 1;
2021
0
}
2022
2023
/* Merge data from DIFF to BIG.  INFO is context where memory should be
2024
   allocated.  */
2025
2026
static bool
2027
elf_m68k_merge_gots (struct elf_m68k_got *big,
2028
         struct elf_m68k_got *diff,
2029
         struct bfd_link_info *info)
2030
0
{
2031
0
  if (diff->entries != NULL)
2032
    /* DIFF is not empty.  Merge it into BIG GOT.  */
2033
0
    {
2034
0
      struct elf_m68k_merge_gots_arg arg_;
2035
2036
      /* Merge entries.  */
2037
0
      arg_.big = big;
2038
0
      arg_.info = info;
2039
0
      arg_.error_p = false;
2040
0
      htab_traverse_noresize (diff->entries, elf_m68k_merge_gots_1, &arg_);
2041
0
      if (arg_.error_p)
2042
0
  return false;
2043
2044
      /* Merge counters.  */
2045
0
      big->n_slots[R_8] += diff->n_slots[R_8];
2046
0
      big->n_slots[R_16] += diff->n_slots[R_16];
2047
0
      big->n_slots[R_32] += diff->n_slots[R_32];
2048
0
      big->local_n_slots += diff->local_n_slots;
2049
0
    }
2050
0
  else
2051
    /* DIFF is empty.  */
2052
0
    {
2053
0
      BFD_ASSERT (diff->n_slots[R_8] == 0);
2054
0
      BFD_ASSERT (diff->n_slots[R_16] == 0);
2055
0
      BFD_ASSERT (diff->n_slots[R_32] == 0);
2056
0
      BFD_ASSERT (diff->local_n_slots == 0);
2057
0
    }
2058
2059
0
  BFD_ASSERT (!elf_m68k_hash_table (info)->allow_multigot_p
2060
0
        || ((big->n_slots[R_8]
2061
0
       <= ELF_M68K_R_8_MAX_N_SLOTS_IN_GOT (info))
2062
0
      && (big->n_slots[R_16]
2063
0
          <= ELF_M68K_R_8_16_MAX_N_SLOTS_IN_GOT (info))));
2064
2065
0
  return true;
2066
0
}
2067
2068
struct elf_m68k_finalize_got_offsets_arg
2069
{
2070
  /* Ranges of the offsets for GOT entries.
2071
     R_x entries receive offsets between offset1[R_x] and offset2[R_x].
2072
     R_x is R_8, R_16 and R_32.  */
2073
  bfd_vma *offset1;
2074
  bfd_vma *offset2;
2075
2076
  /* Mapping from global symndx to global symbols.
2077
     This is used to build lists of got entries for global symbols.  */
2078
  struct elf_m68k_link_hash_entry **symndx2h;
2079
2080
  bfd_vma n_ldm_entries;
2081
};
2082
2083
/* Assign ENTRY an offset.  Build list of GOT entries for global symbols
2084
   along the way.  */
2085
2086
static int
2087
elf_m68k_finalize_got_offsets_1 (void **entry_ptr, void *_arg)
2088
0
{
2089
0
  struct elf_m68k_got_entry *entry;
2090
0
  struct elf_m68k_finalize_got_offsets_arg *arg;
2091
2092
0
  enum elf_m68k_got_offset_size got_offset_size;
2093
0
  bfd_vma entry_size;
2094
2095
0
  entry = (struct elf_m68k_got_entry *) *entry_ptr;
2096
0
  arg = (struct elf_m68k_finalize_got_offsets_arg *) _arg;
2097
2098
  /* This should be a fresh entry created in elf_m68k_can_merge_gots.  */
2099
0
  BFD_ASSERT (entry->u.s1.refcount == 0);
2100
2101
  /* Get GOT offset size for the entry .  */
2102
0
  got_offset_size = elf_m68k_reloc_got_offset_size (entry->key_.type);
2103
2104
  /* Calculate entry size in bytes.  */
2105
0
  entry_size = 4 * elf_m68k_reloc_got_n_slots (entry->key_.type);
2106
2107
  /* Check if we should switch to negative range of the offsets. */
2108
0
  if (arg->offset1[got_offset_size] + entry_size
2109
0
      > arg->offset2[got_offset_size])
2110
0
    {
2111
      /* Verify that this is the only switch to negative range for
2112
   got_offset_size.  If this assertion fails, then we've miscalculated
2113
   range for got_offset_size entries in
2114
   elf_m68k_finalize_got_offsets.  */
2115
0
      BFD_ASSERT (arg->offset2[got_offset_size]
2116
0
      != arg->offset2[-(int) got_offset_size - 1]);
2117
2118
      /* Switch.  */
2119
0
      arg->offset1[got_offset_size] = arg->offset1[-(int) got_offset_size - 1];
2120
0
      arg->offset2[got_offset_size] = arg->offset2[-(int) got_offset_size - 1];
2121
2122
      /* Verify that now we have enough room for the entry.  */
2123
0
      BFD_ASSERT (arg->offset1[got_offset_size] + entry_size
2124
0
      <= arg->offset2[got_offset_size]);
2125
0
    }
2126
2127
  /* Assign offset to entry.  */
2128
0
  entry->u.s2.offset = arg->offset1[got_offset_size];
2129
0
  arg->offset1[got_offset_size] += entry_size;
2130
2131
0
  if (entry->key_.bfd == NULL)
2132
    /* Hook up this entry into the list of got_entries of H.  */
2133
0
    {
2134
0
      struct elf_m68k_link_hash_entry *h;
2135
2136
0
      h = arg->symndx2h[entry->key_.symndx];
2137
0
      if (h != NULL)
2138
0
  {
2139
0
    entry->u.s2.next = h->glist;
2140
0
    h->glist = entry;
2141
0
  }
2142
0
      else
2143
  /* This should be the entry for TLS_LDM relocation then.  */
2144
0
  {
2145
0
    BFD_ASSERT ((elf_m68k_reloc_got_type (entry->key_.type)
2146
0
           == R_68K_TLS_LDM32)
2147
0
          && entry->key_.symndx == 0);
2148
2149
0
    ++arg->n_ldm_entries;
2150
0
  }
2151
0
    }
2152
0
  else
2153
    /* This entry is for local symbol.  */
2154
0
    entry->u.s2.next = NULL;
2155
2156
0
  return 1;
2157
0
}
2158
2159
/* Assign offsets within GOT.  USE_NEG_GOT_OFFSETS_P indicates if we
2160
   should use negative offsets.
2161
   Build list of GOT entries for global symbols along the way.
2162
   SYMNDX2H is mapping from global symbol indices to actual
2163
   global symbols.
2164
   Return offset at which next GOT should start.  */
2165
2166
static void
2167
elf_m68k_finalize_got_offsets (struct elf_m68k_got *got,
2168
             bool use_neg_got_offsets_p,
2169
             struct elf_m68k_link_hash_entry **symndx2h,
2170
             bfd_vma *final_offset, bfd_vma *n_ldm_entries)
2171
0
{
2172
0
  struct elf_m68k_finalize_got_offsets_arg arg_;
2173
0
  bfd_vma offset1_[2 * R_LAST];
2174
0
  bfd_vma offset2_[2 * R_LAST];
2175
0
  int i;
2176
0
  bfd_vma start_offset;
2177
2178
0
  BFD_ASSERT (got->offset != (bfd_vma) -1);
2179
2180
  /* We set entry offsets relative to the .got section (and not the
2181
     start of a particular GOT), so that we can use them in
2182
     finish_dynamic_symbol without needing to know the GOT which they come
2183
     from.  */
2184
2185
  /* Put offset1 in the middle of offset1_, same for offset2.  */
2186
0
  arg_.offset1 = offset1_ + R_LAST;
2187
0
  arg_.offset2 = offset2_ + R_LAST;
2188
2189
0
  start_offset = got->offset;
2190
2191
0
  if (use_neg_got_offsets_p)
2192
    /* Setup both negative and positive ranges for R_8, R_16 and R_32.  */
2193
0
    i = -(int) R_32 - 1;
2194
0
  else
2195
    /* Setup positives ranges for R_8, R_16 and R_32.  */
2196
0
    i = (int) R_8;
2197
2198
0
  for (; i <= (int) R_32; ++i)
2199
0
    {
2200
0
      int j;
2201
0
      size_t n;
2202
2203
      /* Set beginning of the range of offsets I.  */
2204
0
      arg_.offset1[i] = start_offset;
2205
2206
      /* Calculate number of slots that require I offsets.  */
2207
0
      j = (i >= 0) ? i : -i - 1;
2208
0
      n = (j >= 1) ? got->n_slots[j - 1] : 0;
2209
0
      n = got->n_slots[j] - n;
2210
2211
0
      if (use_neg_got_offsets_p && n != 0)
2212
0
  {
2213
0
    if (i < 0)
2214
      /* We first fill the positive side of the range, so we might
2215
         end up with one empty slot at that side when we can't fit
2216
         whole 2-slot entry.  Account for that at negative side of
2217
         the interval with one additional entry.  */
2218
0
      n = n / 2 + 1;
2219
0
    else
2220
      /* When the number of slots is odd, make positive side of the
2221
         range one entry bigger.  */
2222
0
      n = (n + 1) / 2;
2223
0
  }
2224
2225
      /* N is the number of slots that require I offsets.
2226
   Calculate length of the range for I offsets.  */
2227
0
      n = 4 * n;
2228
2229
      /* Set end of the range.  */
2230
0
      arg_.offset2[i] = start_offset + n;
2231
2232
0
      start_offset = arg_.offset2[i];
2233
0
    }
2234
2235
0
  if (!use_neg_got_offsets_p)
2236
    /* Make sure that if we try to switch to negative offsets in
2237
       elf_m68k_finalize_got_offsets_1, the assert therein will catch
2238
       the bug.  */
2239
0
    for (i = R_8; i <= R_32; ++i)
2240
0
      arg_.offset2[-i - 1] = arg_.offset2[i];
2241
2242
  /* Setup got->offset.  offset1[R_8] is either in the middle or at the
2243
     beginning of GOT depending on use_neg_got_offsets_p.  */
2244
0
  got->offset = arg_.offset1[R_8];
2245
2246
0
  arg_.symndx2h = symndx2h;
2247
0
  arg_.n_ldm_entries = 0;
2248
2249
  /* Assign offsets.  */
2250
0
  htab_traverse (got->entries, elf_m68k_finalize_got_offsets_1, &arg_);
2251
2252
  /* Check offset ranges we have actually assigned.  */
2253
0
  for (i = (int) R_8; i <= (int) R_32; ++i)
2254
0
    BFD_ASSERT (arg_.offset2[i] - arg_.offset1[i] <= 4);
2255
2256
0
  *final_offset = start_offset;
2257
0
  *n_ldm_entries = arg_.n_ldm_entries;
2258
0
}
2259
2260
struct elf_m68k_partition_multi_got_arg
2261
{
2262
  /* The GOT we are adding entries to.  Aka big got.  */
2263
  struct elf_m68k_got *current_got;
2264
2265
  /* Offset to assign the next CURRENT_GOT.  */
2266
  bfd_vma offset;
2267
2268
  /* Context where memory should be allocated.  */
2269
  struct bfd_link_info *info;
2270
2271
  /* Total number of slots in the .got section.
2272
     This is used to calculate size of the .got and .rela.got sections.  */
2273
  bfd_vma n_slots;
2274
2275
  /* Difference in numbers of allocated slots in the .got section
2276
     and necessary relocations in the .rela.got section.
2277
     This is used to calculate size of the .rela.got section.  */
2278
  bfd_vma slots_relas_diff;
2279
2280
  /* Error flag.  */
2281
  bool error_p;
2282
2283
  /* Mapping from global symndx to global symbols.
2284
     This is used to build lists of got entries for global symbols.  */
2285
  struct elf_m68k_link_hash_entry **symndx2h;
2286
};
2287
2288
static void
2289
elf_m68k_partition_multi_got_2 (struct elf_m68k_partition_multi_got_arg *arg)
2290
0
{
2291
0
  bfd_vma n_ldm_entries;
2292
2293
0
  elf_m68k_finalize_got_offsets (arg->current_got,
2294
0
         (elf_m68k_hash_table (arg->info)
2295
0
          ->use_neg_got_offsets_p),
2296
0
         arg->symndx2h,
2297
0
         &arg->offset, &n_ldm_entries);
2298
2299
0
  arg->n_slots += arg->current_got->n_slots[R_32];
2300
2301
0
  if (!bfd_link_pic (arg->info))
2302
    /* If we are generating a shared object, we need to
2303
       output a R_68K_RELATIVE reloc so that the dynamic
2304
       linker can adjust this GOT entry.  Overwise we
2305
       don't need space in .rela.got for local symbols.  */
2306
0
    arg->slots_relas_diff += arg->current_got->local_n_slots;
2307
2308
  /* @LDM relocations require a 2-slot GOT entry, but only
2309
     one relocation.  Account for that.  */
2310
0
  arg->slots_relas_diff += n_ldm_entries;
2311
2312
0
  BFD_ASSERT (arg->slots_relas_diff <= arg->n_slots);
2313
0
}
2314
2315
2316
/* Process a single BFD2GOT entry and either merge GOT to CURRENT_GOT
2317
   or start a new CURRENT_GOT.  */
2318
2319
static int
2320
elf_m68k_partition_multi_got_1 (void **_entry, void *_arg)
2321
0
{
2322
0
  struct elf_m68k_bfd2got_entry *entry;
2323
0
  struct elf_m68k_partition_multi_got_arg *arg;
2324
0
  struct elf_m68k_got *got;
2325
0
  struct elf_m68k_got diff_;
2326
0
  struct elf_m68k_got *diff;
2327
2328
0
  entry = (struct elf_m68k_bfd2got_entry *) *_entry;
2329
0
  arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
2330
2331
0
  got = entry->got;
2332
0
  BFD_ASSERT (got != NULL);
2333
0
  BFD_ASSERT (got->offset == (bfd_vma) -1);
2334
2335
0
  diff = NULL;
2336
2337
0
  if (arg->current_got != NULL)
2338
    /* Construct diff.  */
2339
0
    {
2340
0
      diff = &diff_;
2341
0
      elf_m68k_init_got (diff);
2342
2343
0
      if (!elf_m68k_can_merge_gots (arg->current_got, got, arg->info, diff))
2344
0
  {
2345
0
    if (diff->offset == 0)
2346
      /* Offset set to 0 in the diff_ indicates an error.  */
2347
0
      {
2348
0
        arg->error_p = true;
2349
0
        goto final_return;
2350
0
      }
2351
2352
0
    if (elf_m68k_hash_table (arg->info)->allow_multigot_p)
2353
0
      {
2354
0
        elf_m68k_clear_got (diff);
2355
        /* Schedule to finish up current_got and start new one.  */
2356
0
        diff = NULL;
2357
0
      }
2358
    /* else
2359
       Merge GOTs no matter what.  If big GOT overflows,
2360
       we'll fail in relocate_section due to truncated relocations.
2361
2362
       ??? May be fail earlier?  E.g., in can_merge_gots.  */
2363
0
  }
2364
0
    }
2365
0
  else
2366
    /* Diff of got against empty current_got is got itself.  */
2367
0
    {
2368
      /* Create empty current_got to put subsequent GOTs to.  */
2369
0
      arg->current_got = elf_m68k_create_empty_got (arg->info);
2370
0
      if (arg->current_got == NULL)
2371
0
  {
2372
0
    arg->error_p = true;
2373
0
    goto final_return;
2374
0
  }
2375
2376
0
      arg->current_got->offset = arg->offset;
2377
2378
0
      diff = got;
2379
0
    }
2380
2381
0
  if (diff != NULL)
2382
0
    {
2383
0
      if (!elf_m68k_merge_gots (arg->current_got, diff, arg->info))
2384
0
  {
2385
0
    arg->error_p = true;
2386
0
    goto final_return;
2387
0
  }
2388
2389
      /* Now we can free GOT.  */
2390
0
      elf_m68k_clear_got (got);
2391
2392
0
      entry->got = arg->current_got;
2393
0
    }
2394
0
  else
2395
0
    {
2396
      /* Finish up current_got.  */
2397
0
      elf_m68k_partition_multi_got_2 (arg);
2398
2399
      /* Schedule to start a new current_got.  */
2400
0
      arg->current_got = NULL;
2401
2402
      /* Retry.  */
2403
0
      if (!elf_m68k_partition_multi_got_1 (_entry, _arg))
2404
0
  {
2405
0
    BFD_ASSERT (arg->error_p);
2406
0
    goto final_return;
2407
0
  }
2408
0
    }
2409
2410
0
 final_return:
2411
0
  if (diff != NULL)
2412
0
    elf_m68k_clear_got (diff);
2413
2414
0
  return !arg->error_p;
2415
0
}
2416
2417
/* Helper function to build symndx2h mapping.  */
2418
2419
static bool
2420
elf_m68k_init_symndx2h_1 (struct elf_link_hash_entry *_h,
2421
        void *_arg)
2422
0
{
2423
0
  struct elf_m68k_link_hash_entry *h;
2424
2425
0
  h = elf_m68k_hash_entry (_h);
2426
2427
0
  if (h->got_entry_key != 0)
2428
    /* H has at least one entry in the GOT.  */
2429
0
    {
2430
0
      struct elf_m68k_partition_multi_got_arg *arg;
2431
2432
0
      arg = (struct elf_m68k_partition_multi_got_arg *) _arg;
2433
2434
0
      BFD_ASSERT (arg->symndx2h[h->got_entry_key] == NULL);
2435
0
      arg->symndx2h[h->got_entry_key] = h;
2436
0
    }
2437
2438
0
  return true;
2439
0
}
2440
2441
/* Merge GOTs of some BFDs, assign offsets to GOT entries and build
2442
   lists of GOT entries for global symbols.
2443
   Calculate sizes of .got and .rela.got sections.  */
2444
2445
static bool
2446
elf_m68k_partition_multi_got (struct bfd_link_info *info)
2447
0
{
2448
0
  struct elf_m68k_multi_got *multi_got;
2449
0
  struct elf_m68k_partition_multi_got_arg arg_;
2450
2451
0
  multi_got = elf_m68k_multi_got (info);
2452
2453
0
  arg_.current_got = NULL;
2454
0
  arg_.offset = 0;
2455
0
  arg_.info = info;
2456
0
  arg_.n_slots = 0;
2457
0
  arg_.slots_relas_diff = 0;
2458
0
  arg_.error_p = false;
2459
2460
0
  if (multi_got->bfd2got != NULL)
2461
0
    {
2462
      /* Initialize symndx2h mapping.  */
2463
0
      {
2464
0
  arg_.symndx2h = bfd_zmalloc (multi_got->global_symndx
2465
0
             * sizeof (*arg_.symndx2h));
2466
0
  if (arg_.symndx2h == NULL)
2467
0
    return false;
2468
2469
0
  elf_link_hash_traverse (elf_hash_table (info),
2470
0
        elf_m68k_init_symndx2h_1, &arg_);
2471
0
      }
2472
2473
      /* Partition.  */
2474
0
      htab_traverse (multi_got->bfd2got, elf_m68k_partition_multi_got_1,
2475
0
         &arg_);
2476
0
      if (arg_.error_p)
2477
0
  {
2478
0
    free (arg_.symndx2h);
2479
0
    arg_.symndx2h = NULL;
2480
2481
0
    return false;
2482
0
  }
2483
2484
      /* Finish up last current_got.  */
2485
0
      elf_m68k_partition_multi_got_2 (&arg_);
2486
2487
0
      free (arg_.symndx2h);
2488
0
    }
2489
2490
0
  if (elf_hash_table (info)->dynobj != NULL)
2491
    /* Set sizes of .got and .rela.got sections.  */
2492
0
    {
2493
0
      asection *s;
2494
2495
0
      s = elf_hash_table (info)->sgot;
2496
0
      if (s != NULL)
2497
0
  s->size = arg_.offset;
2498
0
      else
2499
0
  BFD_ASSERT (arg_.offset == 0);
2500
2501
0
      BFD_ASSERT (arg_.slots_relas_diff <= arg_.n_slots);
2502
0
      arg_.n_slots -= arg_.slots_relas_diff;
2503
2504
0
      s = elf_hash_table (info)->srelgot;
2505
0
      if (s != NULL)
2506
0
  s->size = arg_.n_slots * sizeof (Elf32_External_Rela);
2507
0
      else
2508
0
  BFD_ASSERT (arg_.n_slots == 0);
2509
0
    }
2510
0
  else
2511
0
    BFD_ASSERT (multi_got->bfd2got == NULL);
2512
2513
0
  return true;
2514
0
}
2515
2516
/* Copy any information related to dynamic linking from a pre-existing
2517
   symbol to a newly created symbol.  Also called to copy flags and
2518
   other back-end info to a weakdef, in which case the symbol is not
2519
   newly created and plt/got refcounts and dynamic indices should not
2520
   be copied.  */
2521
2522
static void
2523
elf_m68k_copy_indirect_symbol (struct bfd_link_info *info,
2524
             struct elf_link_hash_entry *_dir,
2525
             struct elf_link_hash_entry *_ind)
2526
0
{
2527
0
  struct elf_m68k_link_hash_entry *dir;
2528
0
  struct elf_m68k_link_hash_entry *ind;
2529
2530
0
  _bfd_elf_link_hash_copy_indirect (info, _dir, _ind);
2531
2532
0
  if (_ind->root.type != bfd_link_hash_indirect)
2533
0
    return;
2534
2535
0
  dir = elf_m68k_hash_entry (_dir);
2536
0
  ind = elf_m68k_hash_entry (_ind);
2537
2538
  /* Any absolute non-dynamic relocations against an indirect or weak
2539
     definition will be against the target symbol.  */
2540
0
  _dir->non_got_ref |= _ind->non_got_ref;
2541
2542
  /* We might have a direct symbol already having entries in the GOTs.
2543
     Update its key only in case indirect symbol has GOT entries and
2544
     assert that both indirect and direct symbols don't have GOT entries
2545
     at the same time.  */
2546
0
  if (ind->got_entry_key != 0)
2547
0
    {
2548
0
      BFD_ASSERT (dir->got_entry_key == 0);
2549
      /* Assert that GOTs aren't partioned yet.  */
2550
0
      BFD_ASSERT (ind->glist == NULL);
2551
2552
0
      dir->got_entry_key = ind->got_entry_key;
2553
0
      ind->got_entry_key = 0;
2554
0
    }
2555
0
}
2556
2557
/* Look through the relocs for a section during the first phase, and
2558
   allocate space in the global offset table or procedure linkage
2559
   table.  */
2560
2561
static bool
2562
elf_m68k_check_relocs (bfd *abfd,
2563
           struct bfd_link_info *info,
2564
           asection *sec,
2565
           const Elf_Internal_Rela *relocs)
2566
0
{
2567
0
  bfd *dynobj;
2568
0
  Elf_Internal_Shdr *symtab_hdr;
2569
0
  struct elf_link_hash_entry **sym_hashes;
2570
0
  const Elf_Internal_Rela *rel;
2571
0
  const Elf_Internal_Rela *rel_end;
2572
0
  asection *sreloc;
2573
0
  struct elf_m68k_got *got;
2574
2575
0
  if (bfd_link_relocatable (info))
2576
0
    return true;
2577
2578
0
  dynobj = elf_hash_table (info)->dynobj;
2579
0
  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2580
0
  sym_hashes = elf_sym_hashes (abfd);
2581
2582
0
  sreloc = NULL;
2583
2584
0
  got = NULL;
2585
2586
0
  rel_end = relocs + sec->reloc_count;
2587
0
  for (rel = relocs; rel < rel_end; rel++)
2588
0
    {
2589
0
      unsigned long r_symndx;
2590
0
      struct elf_link_hash_entry *h;
2591
2592
0
      r_symndx = ELF32_R_SYM (rel->r_info);
2593
2594
0
      if (r_symndx < symtab_hdr->sh_info)
2595
0
  h = NULL;
2596
0
      else
2597
0
  {
2598
0
    h = sym_hashes[r_symndx - symtab_hdr->sh_info];
2599
0
    while (h->root.type == bfd_link_hash_indirect
2600
0
     || h->root.type == bfd_link_hash_warning)
2601
0
      h = (struct elf_link_hash_entry *) h->root.u.i.link;
2602
0
  }
2603
2604
0
      switch (ELF32_R_TYPE (rel->r_info))
2605
0
  {
2606
0
  case R_68K_GOT8:
2607
0
  case R_68K_GOT16:
2608
0
  case R_68K_GOT32:
2609
0
    if (h != NULL
2610
0
        && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
2611
0
      break;
2612
    /* Fall through.  */
2613
2614
    /* Relative GOT relocations.  */
2615
0
  case R_68K_GOT8O:
2616
0
  case R_68K_GOT16O:
2617
0
  case R_68K_GOT32O:
2618
    /* Fall through.  */
2619
2620
    /* TLS relocations.  */
2621
0
  case R_68K_TLS_GD8:
2622
0
  case R_68K_TLS_GD16:
2623
0
  case R_68K_TLS_GD32:
2624
0
  case R_68K_TLS_LDM8:
2625
0
  case R_68K_TLS_LDM16:
2626
0
  case R_68K_TLS_LDM32:
2627
0
  case R_68K_TLS_IE8:
2628
0
  case R_68K_TLS_IE16:
2629
0
  case R_68K_TLS_IE32:
2630
2631
0
  case R_68K_TLS_TPREL32:
2632
0
  case R_68K_TLS_DTPREL32:
2633
2634
0
    if (ELF32_R_TYPE (rel->r_info) == R_68K_TLS_TPREL32
2635
0
        && bfd_link_pic (info))
2636
      /* Do the special chorus for libraries with static TLS.  */
2637
0
      info->flags |= DF_STATIC_TLS;
2638
2639
    /* This symbol requires a global offset table entry.  */
2640
2641
0
    if (dynobj == NULL)
2642
0
      {
2643
        /* Create the .got section.  */
2644
0
        elf_hash_table (info)->dynobj = dynobj = abfd;
2645
0
        if (!_bfd_elf_create_got_section (dynobj, info))
2646
0
    return false;
2647
0
      }
2648
2649
0
    if (got == NULL)
2650
0
      {
2651
0
        struct elf_m68k_bfd2got_entry *bfd2got_entry;
2652
2653
0
        bfd2got_entry
2654
0
    = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
2655
0
                abfd, FIND_OR_CREATE, info);
2656
0
        if (bfd2got_entry == NULL)
2657
0
    return false;
2658
2659
0
        got = bfd2got_entry->got;
2660
0
        BFD_ASSERT (got != NULL);
2661
0
      }
2662
2663
0
    {
2664
0
      struct elf_m68k_got_entry *got_entry;
2665
2666
      /* Add entry to got.  */
2667
0
      got_entry = elf_m68k_add_entry_to_got (got, h, abfd,
2668
0
               ELF32_R_TYPE (rel->r_info),
2669
0
               r_symndx, info);
2670
0
      if (got_entry == NULL)
2671
0
        return false;
2672
2673
0
      if (got_entry->u.s1.refcount == 1)
2674
0
        {
2675
    /* Make sure this symbol is output as a dynamic symbol.  */
2676
0
    if (h != NULL
2677
0
        && h->dynindx == -1
2678
0
        && !h->forced_local)
2679
0
      {
2680
0
        if (!bfd_elf_link_record_dynamic_symbol (info, h))
2681
0
          return false;
2682
0
      }
2683
0
        }
2684
0
    }
2685
2686
0
    break;
2687
2688
0
  case R_68K_PLT8:
2689
0
  case R_68K_PLT16:
2690
0
  case R_68K_PLT32:
2691
    /* This symbol requires a procedure linkage table entry.  We
2692
       actually build the entry in adjust_dynamic_symbol,
2693
       because this might be a case of linking PIC code which is
2694
       never referenced by a dynamic object, in which case we
2695
       don't need to generate a procedure linkage table entry
2696
       after all.  */
2697
2698
    /* If this is a local symbol, we resolve it directly without
2699
       creating a procedure linkage table entry.  */
2700
0
    if (h == NULL)
2701
0
      continue;
2702
2703
0
    h->needs_plt = 1;
2704
0
    h->plt.refcount++;
2705
0
    break;
2706
2707
0
  case R_68K_PLT8O:
2708
0
  case R_68K_PLT16O:
2709
0
  case R_68K_PLT32O:
2710
    /* This symbol requires a procedure linkage table entry.  */
2711
2712
0
    if (h == NULL)
2713
0
      {
2714
        /* It does not make sense to have this relocation for a
2715
     local symbol.  FIXME: does it?  How to handle it if
2716
     it does make sense?  */
2717
0
        bfd_set_error (bfd_error_bad_value);
2718
0
        return false;
2719
0
      }
2720
2721
    /* Make sure this symbol is output as a dynamic symbol.  */
2722
0
    if (h->dynindx == -1
2723
0
        && !h->forced_local)
2724
0
      {
2725
0
        if (!bfd_elf_link_record_dynamic_symbol (info, h))
2726
0
    return false;
2727
0
      }
2728
2729
0
    h->needs_plt = 1;
2730
0
    h->plt.refcount++;
2731
0
    break;
2732
2733
0
  case R_68K_PC8:
2734
0
  case R_68K_PC16:
2735
0
  case R_68K_PC32:
2736
    /* If we are creating a shared library and this is not a local
2737
       symbol, we need to copy the reloc into the shared library.
2738
       However when linking with -Bsymbolic and this is a global
2739
       symbol which is defined in an object we are including in the
2740
       link (i.e., DEF_REGULAR is set), then we can resolve the
2741
       reloc directly.  At this point we have not seen all the input
2742
       files, so it is possible that DEF_REGULAR is not set now but
2743
       will be set later (it is never cleared).  We account for that
2744
       possibility below by storing information in the
2745
       pcrel_relocs_copied field of the hash table entry.  */
2746
0
    if (!(bfd_link_pic (info)
2747
0
    && (sec->flags & SEC_ALLOC) != 0
2748
0
    && h != NULL
2749
0
    && (!SYMBOLIC_BIND (info, h)
2750
0
        || h->root.type == bfd_link_hash_defweak
2751
0
        || !h->def_regular)))
2752
0
      {
2753
0
        if (h != NULL)
2754
0
    {
2755
      /* Make sure a plt entry is created for this symbol if
2756
         it turns out to be a function defined by a dynamic
2757
         object.  */
2758
0
      h->plt.refcount++;
2759
0
    }
2760
0
        break;
2761
0
      }
2762
    /* Fall through.  */
2763
0
  case R_68K_8:
2764
0
  case R_68K_16:
2765
0
  case R_68K_32:
2766
    /* We don't need to handle relocs into sections not going into
2767
       the "real" output.  */
2768
0
    if ((sec->flags & SEC_ALLOC) == 0)
2769
0
        break;
2770
2771
0
    if (h != NULL)
2772
0
      {
2773
        /* Make sure a plt entry is created for this symbol if it
2774
     turns out to be a function defined by a dynamic object.  */
2775
0
        h->plt.refcount++;
2776
2777
0
        if (bfd_link_executable (info))
2778
    /* This symbol needs a non-GOT reference.  */
2779
0
    h->non_got_ref = 1;
2780
0
      }
2781
2782
    /* If we are creating a shared library, we need to copy the
2783
       reloc into the shared library.  */
2784
0
    if (bfd_link_pic (info)
2785
0
        && (h == NULL
2786
0
      || !UNDEFWEAK_NO_DYNAMIC_RELOC (info, h)))
2787
0
      {
2788
        /* When creating a shared object, we must copy these
2789
     reloc types into the output file.  We create a reloc
2790
     section in dynobj and make room for this reloc.  */
2791
0
        if (sreloc == NULL)
2792
0
    {
2793
0
      sreloc = _bfd_elf_make_dynamic_reloc_section
2794
0
        (sec, dynobj, 2, abfd, /*rela?*/ true);
2795
2796
0
      if (sreloc == NULL)
2797
0
        return false;
2798
0
    }
2799
2800
0
        if (sec->flags & SEC_READONLY
2801
      /* Don't set DF_TEXTREL yet for PC relative
2802
         relocations, they might be discarded later.  */
2803
0
      && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8
2804
0
           || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
2805
0
           || ELF32_R_TYPE (rel->r_info) == R_68K_PC32))
2806
0
        info->flags |= DF_TEXTREL;
2807
2808
0
        sreloc->size += sizeof (Elf32_External_Rela);
2809
2810
        /* We count the number of PC relative relocations we have
2811
     entered for this symbol, so that we can discard them
2812
     again if, in the -Bsymbolic case, the symbol is later
2813
     defined by a regular object, or, in the normal shared
2814
     case, the symbol is forced to be local.  Note that this
2815
     function is only called if we are using an m68kelf linker
2816
     hash table, which means that h is really a pointer to an
2817
     elf_m68k_link_hash_entry.  */
2818
0
        if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8
2819
0
      || ELF32_R_TYPE (rel->r_info) == R_68K_PC16
2820
0
      || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)
2821
0
    {
2822
0
      struct elf_m68k_pcrel_relocs_copied *p;
2823
0
      struct elf_m68k_pcrel_relocs_copied **head;
2824
2825
0
      if (h != NULL)
2826
0
        {
2827
0
          struct elf_m68k_link_hash_entry *eh
2828
0
      = elf_m68k_hash_entry (h);
2829
0
          head = &eh->pcrel_relocs_copied;
2830
0
        }
2831
0
      else
2832
0
        {
2833
0
          asection *s;
2834
0
          void *vpp;
2835
0
          Elf_Internal_Sym *isym;
2836
2837
0
          isym = bfd_sym_from_r_symndx (&elf_m68k_hash_table (info)->root.sym_cache,
2838
0
                abfd, r_symndx);
2839
0
          if (isym == NULL)
2840
0
      return false;
2841
2842
0
          s = bfd_section_from_elf_index (abfd, isym->st_shndx);
2843
0
          if (s == NULL)
2844
0
      s = sec;
2845
2846
0
          vpp = &elf_section_data (s)->local_dynrel;
2847
0
          head = (struct elf_m68k_pcrel_relocs_copied **) vpp;
2848
0
        }
2849
2850
0
      for (p = *head; p != NULL; p = p->next)
2851
0
        if (p->section == sreloc)
2852
0
          break;
2853
2854
0
      if (p == NULL)
2855
0
        {
2856
0
          p = ((struct elf_m68k_pcrel_relocs_copied *)
2857
0
         bfd_alloc (dynobj, (bfd_size_type) sizeof *p));
2858
0
          if (p == NULL)
2859
0
      return false;
2860
0
          p->next = *head;
2861
0
          *head = p;
2862
0
          p->section = sreloc;
2863
0
          p->count = 0;
2864
0
        }
2865
2866
0
      ++p->count;
2867
0
    }
2868
0
      }
2869
2870
0
    break;
2871
2872
    /* This relocation describes the C++ object vtable hierarchy.
2873
       Reconstruct it for later use during GC.  */
2874
0
  case R_68K_GNU_VTINHERIT:
2875
0
    if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2876
0
      return false;
2877
0
    break;
2878
2879
    /* This relocation describes which C++ vtable entries are actually
2880
       used.  Record for later use during GC.  */
2881
0
  case R_68K_GNU_VTENTRY:
2882
0
    if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2883
0
      return false;
2884
0
    break;
2885
2886
0
  default:
2887
0
    break;
2888
0
  }
2889
0
    }
2890
2891
0
  return true;
2892
0
}
2893
2894
/* Return the section that should be marked against GC for a given
2895
   relocation.  */
2896
2897
static asection *
2898
elf_m68k_gc_mark_hook (asection *sec,
2899
           struct bfd_link_info *info,
2900
           Elf_Internal_Rela *rel,
2901
           struct elf_link_hash_entry *h,
2902
           Elf_Internal_Sym *sym)
2903
0
{
2904
0
  if (h != NULL)
2905
0
    switch (ELF32_R_TYPE (rel->r_info))
2906
0
      {
2907
0
      case R_68K_GNU_VTINHERIT:
2908
0
      case R_68K_GNU_VTENTRY:
2909
0
  return NULL;
2910
0
      }
2911
2912
0
  return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
2913
0
}
2914

2915
/* Return the type of PLT associated with OUTPUT_BFD.  */
2916
2917
static const struct elf_m68k_plt_info *
2918
elf_m68k_get_plt_info (bfd *output_bfd)
2919
0
{
2920
0
  unsigned int features;
2921
2922
0
  features = bfd_m68k_mach_to_features (bfd_get_mach (output_bfd));
2923
0
  if (features & cpu32)
2924
0
    return &elf_cpu32_plt_info;
2925
0
  if (features & mcfisa_b)
2926
0
    return &elf_isab_plt_info;
2927
0
  if (features & mcfisa_c)
2928
0
    return &elf_isac_plt_info;
2929
0
  return &elf_m68k_plt_info;
2930
0
}
2931
2932
/* This function is called after all the input files have been read,
2933
   and the input sections have been assigned to output sections.
2934
   It's a convenient place to determine the PLT style.  */
2935
2936
static bool
2937
elf_m68k_early_size_sections (bfd *output_bfd, struct bfd_link_info *info)
2938
0
{
2939
  /* Bind input BFDs to GOTs and calculate sizes of .got and .rela.got
2940
     sections.  */
2941
0
  if (!elf_m68k_partition_multi_got (info))
2942
0
    return false;
2943
2944
0
  elf_m68k_hash_table (info)->plt_info = elf_m68k_get_plt_info (output_bfd);
2945
0
  return true;
2946
0
}
2947
2948
/* Adjust a symbol defined by a dynamic object and referenced by a
2949
   regular object.  The current definition is in some section of the
2950
   dynamic object, but we're not including those sections.  We have to
2951
   change the definition to something the rest of the link can
2952
   understand.  */
2953
2954
static bool
2955
elf_m68k_adjust_dynamic_symbol (struct bfd_link_info *info,
2956
        struct elf_link_hash_entry *h)
2957
0
{
2958
0
  struct elf_m68k_link_hash_table *htab;
2959
0
  bfd *dynobj;
2960
0
  asection *s;
2961
2962
0
  htab = elf_m68k_hash_table (info);
2963
0
  dynobj = htab->root.dynobj;
2964
2965
  /* Make sure we know what is going on here.  */
2966
0
  BFD_ASSERT (dynobj != NULL
2967
0
        && (h->needs_plt
2968
0
      || h->is_weakalias
2969
0
      || (h->def_dynamic
2970
0
          && h->ref_regular
2971
0
          && !h->def_regular)));
2972
2973
  /* If this is a function, put it in the procedure linkage table.  We
2974
     will fill in the contents of the procedure linkage table later,
2975
     when we know the address of the .got section.  */
2976
0
  if (h->type == STT_FUNC
2977
0
      || h->needs_plt)
2978
0
    {
2979
0
      if ((h->plt.refcount <= 0
2980
0
     || SYMBOL_CALLS_LOCAL (info, h)
2981
0
     || ((ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
2982
0
    || UNDEFWEAK_NO_DYNAMIC_RELOC (info, h))
2983
0
         && h->root.type == bfd_link_hash_undefweak))
2984
    /* We must always create the plt entry if it was referenced
2985
       by a PLTxxO relocation.  In this case we already recorded
2986
       it as a dynamic symbol.  */
2987
0
    && h->dynindx == -1)
2988
0
  {
2989
    /* This case can occur if we saw a PLTxx reloc in an input
2990
       file, but the symbol was never referred to by a dynamic
2991
       object, or if all references were garbage collected.  In
2992
       such a case, we don't actually need to build a procedure
2993
       linkage table, and we can just do a PCxx reloc instead.  */
2994
0
    h->plt.offset = (bfd_vma) -1;
2995
0
    h->needs_plt = 0;
2996
0
    return true;
2997
0
  }
2998
2999
      /* Make sure this symbol is output as a dynamic symbol.  */
3000
0
      if (h->dynindx == -1
3001
0
    && !h->forced_local)
3002
0
  {
3003
0
    if (! bfd_elf_link_record_dynamic_symbol (info, h))
3004
0
      return false;
3005
0
  }
3006
3007
0
      s = htab->root.splt;
3008
0
      BFD_ASSERT (s != NULL);
3009
3010
      /* If this is the first .plt entry, make room for the special
3011
   first entry.  */
3012
0
      if (s->size == 0)
3013
0
  s->size = htab->plt_info->size;
3014
3015
      /* If this symbol is not defined in a regular file, and we are
3016
   not generating a shared library, then set the symbol to this
3017
   location in the .plt.  This is required to make function
3018
   pointers compare as equal between the normal executable and
3019
   the shared library.  */
3020
0
      if (!bfd_link_pic (info)
3021
0
    && !h->def_regular)
3022
0
  {
3023
0
    h->root.u.def.section = s;
3024
0
    h->root.u.def.value = s->size;
3025
0
  }
3026
3027
0
      h->plt.offset = s->size;
3028
3029
      /* Make room for this entry.  */
3030
0
      s->size += htab->plt_info->size;
3031
3032
      /* We also need to make an entry in the .got.plt section, which
3033
   will be placed in the .got section by the linker script.  */
3034
0
      s = htab->root.sgotplt;
3035
0
      BFD_ASSERT (s != NULL);
3036
0
      s->size += 4;
3037
3038
      /* We also need to make an entry in the .rela.plt section.  */
3039
0
      s = htab->root.srelplt;
3040
0
      BFD_ASSERT (s != NULL);
3041
0
      s->size += sizeof (Elf32_External_Rela);
3042
3043
0
      return true;
3044
0
    }
3045
3046
  /* Reinitialize the plt offset now that it is not used as a reference
3047
     count any more.  */
3048
0
  h->plt.offset = (bfd_vma) -1;
3049
3050
  /* If this is a weak symbol, and there is a real definition, the
3051
     processor independent code will have arranged for us to see the
3052
     real definition first, and we can just use the same value.  */
3053
0
  if (h->is_weakalias)
3054
0
    {
3055
0
      struct elf_link_hash_entry *def = weakdef (h);
3056
0
      BFD_ASSERT (def->root.type == bfd_link_hash_defined);
3057
0
      h->root.u.def.section = def->root.u.def.section;
3058
0
      h->root.u.def.value = def->root.u.def.value;
3059
0
      return true;
3060
0
    }
3061
3062
  /* This is a reference to a symbol defined by a dynamic object which
3063
     is not a function.  */
3064
3065
  /* If we are creating a shared library, we must presume that the
3066
     only references to the symbol are via the global offset table.
3067
     For such cases we need not do anything here; the relocations will
3068
     be handled correctly by relocate_section.  */
3069
0
  if (bfd_link_pic (info))
3070
0
    return true;
3071
3072
  /* If there are no references to this symbol that do not use the
3073
     GOT, we don't need to generate a copy reloc.  */
3074
0
  if (!h->non_got_ref)
3075
0
    return true;
3076
3077
  /* We must allocate the symbol in our .dynbss section, which will
3078
     become part of the .bss section of the executable.  There will be
3079
     an entry for this symbol in the .dynsym section.  The dynamic
3080
     object will contain position independent code, so all references
3081
     from the dynamic object to this symbol will go through the global
3082
     offset table.  The dynamic linker will use the .dynsym entry to
3083
     determine the address it must put in the global offset table, so
3084
     both the dynamic object and the regular object will refer to the
3085
     same memory location for the variable.  */
3086
3087
0
  s = bfd_get_linker_section (dynobj, ".dynbss");
3088
0
  BFD_ASSERT (s != NULL);
3089
3090
  /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
3091
     copy the initial value out of the dynamic object and into the
3092
     runtime process image.  We need to remember the offset into the
3093
     .rela.bss section we are going to use.  */
3094
0
  if ((h->root.u.def.section->flags & SEC_ALLOC) != 0 && h->size != 0)
3095
0
    {
3096
0
      asection *srel;
3097
3098
0
      srel = bfd_get_linker_section (dynobj, ".rela.bss");
3099
0
      BFD_ASSERT (srel != NULL);
3100
0
      srel->size += sizeof (Elf32_External_Rela);
3101
0
      h->needs_copy = 1;
3102
0
    }
3103
3104
0
  return _bfd_elf_adjust_dynamic_copy (info, h, s);
3105
0
}
3106
3107
/* Set the sizes of the dynamic sections.  */
3108
3109
static bool
3110
elf_m68k_late_size_sections (bfd *output_bfd ATTRIBUTE_UNUSED,
3111
           struct bfd_link_info *info)
3112
0
{
3113
0
  bfd *dynobj;
3114
0
  asection *s;
3115
0
  bool relocs;
3116
3117
0
  dynobj = elf_hash_table (info)->dynobj;
3118
0
  if (dynobj == NULL)
3119
0
    return true;
3120
3121
0
  if (elf_hash_table (info)->dynamic_sections_created)
3122
0
    {
3123
      /* Set the contents of the .interp section to the interpreter.  */
3124
0
      if (bfd_link_executable (info) && !info->nointerp)
3125
0
  {
3126
0
    s = bfd_get_linker_section (dynobj, ".interp");
3127
0
    BFD_ASSERT (s != NULL);
3128
0
    s->size = sizeof ELF_DYNAMIC_INTERPRETER;
3129
0
    s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
3130
0
  }
3131
0
    }
3132
0
  else
3133
0
    {
3134
      /* We may have created entries in the .rela.got section.
3135
   However, if we are not creating the dynamic sections, we will
3136
   not actually use these entries.  Reset the size of .rela.got,
3137
   which will cause it to get stripped from the output file
3138
   below.  */
3139
0
      s = elf_hash_table (info)->srelgot;
3140
0
      if (s != NULL)
3141
0
  s->size = 0;
3142
0
    }
3143
3144
  /* If this is a -Bsymbolic shared link, then we need to discard all
3145
     PC relative relocs against symbols defined in a regular object.
3146
     For the normal shared case we discard the PC relative relocs
3147
     against symbols that have become local due to visibility changes.
3148
     We allocated space for them in the check_relocs routine, but we
3149
     will not fill them in in the relocate_section routine.  */
3150
0
  if (bfd_link_pic (info))
3151
0
    elf_link_hash_traverse (elf_hash_table (info),
3152
0
          elf_m68k_discard_copies,
3153
0
          info);
3154
3155
  /* The check_relocs and adjust_dynamic_symbol entry points have
3156
     determined the sizes of the various dynamic sections.  Allocate
3157
     memory for them.  */
3158
0
  relocs = false;
3159
0
  for (s = dynobj->sections; s != NULL; s = s->next)
3160
0
    {
3161
0
      const char *name;
3162
3163
0
      if ((s->flags & SEC_LINKER_CREATED) == 0)
3164
0
  continue;
3165
3166
      /* It's OK to base decisions on the section name, because none
3167
   of the dynobj section names depend upon the input files.  */
3168
0
      name = bfd_section_name (s);
3169
3170
0
      if (strcmp (name, ".plt") == 0)
3171
0
  {
3172
    /* Remember whether there is a PLT.  */
3173
0
    ;
3174
0
  }
3175
0
      else if (startswith (name, ".rela"))
3176
0
  {
3177
0
    if (s->size != 0)
3178
0
      {
3179
0
        relocs = true;
3180
3181
        /* We use the reloc_count field as a counter if we need
3182
     to copy relocs into the output file.  */
3183
0
        s->reloc_count = 0;
3184
0
      }
3185
0
  }
3186
0
      else if (! startswith (name, ".got")
3187
0
         && strcmp (name, ".dynbss") != 0)
3188
0
  {
3189
    /* It's not one of our sections, so don't allocate space.  */
3190
0
    continue;
3191
0
  }
3192
3193
0
      if (s->size == 0)
3194
0
  {
3195
    /* If we don't need this section, strip it from the
3196
       output file.  This is mostly to handle .rela.bss and
3197
       .rela.plt.  We must create both sections in
3198
       create_dynamic_sections, because they must be created
3199
       before the linker maps input sections to output
3200
       sections.  The linker does that before
3201
       adjust_dynamic_symbol is called, and it is that
3202
       function which decides whether anything needs to go
3203
       into these sections.  */
3204
0
    s->flags |= SEC_EXCLUDE;
3205
0
    continue;
3206
0
  }
3207
3208
0
      if ((s->flags & SEC_HAS_CONTENTS) == 0)
3209
0
  continue;
3210
3211
      /* Allocate memory for the section contents.  */
3212
      /* FIXME: This should be a call to bfd_alloc not bfd_zalloc.
3213
   Unused entries should be reclaimed before the section's contents
3214
   are written out, but at the moment this does not happen.  Thus in
3215
   order to prevent writing out garbage, we initialise the section's
3216
   contents to zero.  */
3217
0
      s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size);
3218
0
      if (s->contents == NULL)
3219
0
  return false;
3220
0
    }
3221
3222
0
  return _bfd_elf_add_dynamic_tags (output_bfd, info, relocs);
3223
0
}
3224
3225
/* This function is called via elf_link_hash_traverse if we are
3226
   creating a shared object.  In the -Bsymbolic case it discards the
3227
   space allocated to copy PC relative relocs against symbols which
3228
   are defined in regular objects.  For the normal shared case, it
3229
   discards space for pc-relative relocs that have become local due to
3230
   symbol visibility changes.  We allocated space for them in the
3231
   check_relocs routine, but we won't fill them in in the
3232
   relocate_section routine.
3233
3234
   We also check whether any of the remaining relocations apply
3235
   against a readonly section, and set the DF_TEXTREL flag in this
3236
   case.  */
3237
3238
static bool
3239
elf_m68k_discard_copies (struct elf_link_hash_entry *h,
3240
       void * inf)
3241
0
{
3242
0
  struct bfd_link_info *info = (struct bfd_link_info *) inf;
3243
0
  struct elf_m68k_pcrel_relocs_copied *s;
3244
3245
0
  if (!SYMBOL_CALLS_LOCAL (info, h))
3246
0
    {
3247
0
      if ((info->flags & DF_TEXTREL) == 0)
3248
0
  {
3249
    /* Look for relocations against read-only sections.  */
3250
0
    for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
3251
0
         s != NULL;
3252
0
         s = s->next)
3253
0
      if ((s->section->flags & SEC_READONLY) != 0)
3254
0
        {
3255
0
    info->flags |= DF_TEXTREL;
3256
0
    break;
3257
0
        }
3258
0
  }
3259
3260
      /* Make sure undefined weak symbols are output as a dynamic symbol
3261
   in PIEs.  */
3262
0
      if (h->non_got_ref
3263
0
    && h->root.type == bfd_link_hash_undefweak
3264
0
    && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3265
0
    && h->dynindx == -1
3266
0
    && !h->forced_local)
3267
0
  {
3268
0
    if (! bfd_elf_link_record_dynamic_symbol (info, h))
3269
0
      return false;
3270
0
  }
3271
3272
0
      return true;
3273
0
    }
3274
3275
0
  for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied;
3276
0
       s != NULL;
3277
0
       s = s->next)
3278
0
    s->section->size -= s->count * sizeof (Elf32_External_Rela);
3279
3280
0
  return true;
3281
0
}
3282
3283
3284
/* Install relocation RELA.  */
3285
3286
static void
3287
elf_m68k_install_rela (bfd *output_bfd,
3288
           asection *srela,
3289
           Elf_Internal_Rela *rela)
3290
0
{
3291
0
  bfd_byte *loc;
3292
3293
0
  loc = srela->contents;
3294
0
  loc += srela->reloc_count++ * sizeof (Elf32_External_Rela);
3295
0
  bfd_elf32_swap_reloca_out (output_bfd, rela, loc);
3296
0
}
3297
3298
/* Find the base offsets for thread-local storage in this object,
3299
   for GD/LD and IE/LE respectively.  */
3300
3301
0
#define DTP_OFFSET 0x8000
3302
0
#define TP_OFFSET  0x7000
3303
3304
static bfd_vma
3305
dtpoff_base (struct bfd_link_info *info)
3306
0
{
3307
  /* If tls_sec is NULL, we should have signalled an error already.  */
3308
0
  if (elf_hash_table (info)->tls_sec == NULL)
3309
0
    return 0;
3310
0
  return elf_hash_table (info)->tls_sec->vma + DTP_OFFSET;
3311
0
}
3312
3313
static bfd_vma
3314
tpoff_base (struct bfd_link_info *info)
3315
0
{
3316
  /* If tls_sec is NULL, we should have signalled an error already.  */
3317
0
  if (elf_hash_table (info)->tls_sec == NULL)
3318
0
    return 0;
3319
0
  return elf_hash_table (info)->tls_sec->vma + TP_OFFSET;
3320
0
}
3321
3322
/* Output necessary relocation to handle a symbol during static link.
3323
   This function is called from elf_m68k_relocate_section.  */
3324
3325
static void
3326
elf_m68k_init_got_entry_static (struct bfd_link_info *info,
3327
        bfd *output_bfd,
3328
        enum elf_m68k_reloc_type r_type,
3329
        asection *sgot,
3330
        bfd_vma got_entry_offset,
3331
        bfd_vma relocation)
3332
0
{
3333
0
  switch (elf_m68k_reloc_got_type (r_type))
3334
0
    {
3335
0
    case R_68K_GOT32O:
3336
0
      bfd_put_32 (output_bfd, relocation, sgot->contents + got_entry_offset);
3337
0
      break;
3338
3339
0
    case R_68K_TLS_GD32:
3340
      /* We know the offset within the module,
3341
   put it into the second GOT slot.  */
3342
0
      bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
3343
0
      sgot->contents + got_entry_offset + 4);
3344
      /* FALLTHRU */
3345
3346
0
    case R_68K_TLS_LDM32:
3347
      /* Mark it as belonging to module 1, the executable.  */
3348
0
      bfd_put_32 (output_bfd, 1, sgot->contents + got_entry_offset);
3349
0
      break;
3350
3351
0
    case R_68K_TLS_IE32:
3352
0
      bfd_put_32 (output_bfd, relocation - tpoff_base (info),
3353
0
      sgot->contents + got_entry_offset);
3354
0
      break;
3355
3356
0
    default:
3357
0
      BFD_ASSERT (false);
3358
0
    }
3359
0
}
3360
3361
/* Output necessary relocation to handle a local symbol
3362
   during dynamic link.
3363
   This function is called either from elf_m68k_relocate_section
3364
   or from elf_m68k_finish_dynamic_symbol.  */
3365
3366
static void
3367
elf_m68k_init_got_entry_local_shared (struct bfd_link_info *info,
3368
              bfd *output_bfd,
3369
              enum elf_m68k_reloc_type r_type,
3370
              asection *sgot,
3371
              bfd_vma got_entry_offset,
3372
              bfd_vma relocation,
3373
              asection *srela)
3374
0
{
3375
0
  Elf_Internal_Rela outrel;
3376
3377
0
  switch (elf_m68k_reloc_got_type (r_type))
3378
0
    {
3379
0
    case R_68K_GOT32O:
3380
      /* Emit RELATIVE relocation to initialize GOT slot
3381
   at run-time.  */
3382
0
      outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
3383
0
      outrel.r_addend = relocation;
3384
0
      break;
3385
3386
0
    case R_68K_TLS_GD32:
3387
      /* We know the offset within the module,
3388
   put it into the second GOT slot.  */
3389
0
      bfd_put_32 (output_bfd, relocation - dtpoff_base (info),
3390
0
      sgot->contents + got_entry_offset + 4);
3391
      /* FALLTHRU */
3392
3393
0
    case R_68K_TLS_LDM32:
3394
      /* We don't know the module number,
3395
   create a relocation for it.  */
3396
0
      outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_DTPMOD32);
3397
0
      outrel.r_addend = 0;
3398
0
      break;
3399
3400
0
    case R_68K_TLS_IE32:
3401
      /* Emit TPREL relocation to initialize GOT slot
3402
   at run-time.  */
3403
0
      outrel.r_info = ELF32_R_INFO (0, R_68K_TLS_TPREL32);
3404
0
      outrel.r_addend = relocation - elf_hash_table (info)->tls_sec->vma;
3405
0
      break;
3406
3407
0
    default:
3408
0
      BFD_ASSERT (false);
3409
0
    }
3410
3411
  /* Offset of the GOT entry.  */
3412
0
  outrel.r_offset = (sgot->output_section->vma
3413
0
         + sgot->output_offset
3414
0
         + got_entry_offset);
3415
3416
  /* Install one of the above relocations.  */
3417
0
  elf_m68k_install_rela (output_bfd, srela, &outrel);
3418
3419
0
  bfd_put_32 (output_bfd, outrel.r_addend, sgot->contents + got_entry_offset);
3420
0
}
3421
3422
/* Relocate an M68K ELF section.  */
3423
3424
static int
3425
elf_m68k_relocate_section (bfd *output_bfd,
3426
         struct bfd_link_info *info,
3427
         bfd *input_bfd,
3428
         asection *input_section,
3429
         bfd_byte *contents,
3430
         Elf_Internal_Rela *relocs,
3431
         Elf_Internal_Sym *local_syms,
3432
         asection **local_sections)
3433
0
{
3434
0
  Elf_Internal_Shdr *symtab_hdr;
3435
0
  struct elf_link_hash_entry **sym_hashes;
3436
0
  asection *sgot;
3437
0
  asection *splt;
3438
0
  asection *sreloc;
3439
0
  asection *srela;
3440
0
  struct elf_m68k_got *got;
3441
0
  Elf_Internal_Rela *rel;
3442
0
  Elf_Internal_Rela *relend;
3443
3444
0
  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
3445
0
  sym_hashes = elf_sym_hashes (input_bfd);
3446
3447
0
  sgot = NULL;
3448
0
  splt = NULL;
3449
0
  sreloc = NULL;
3450
0
  srela = NULL;
3451
3452
0
  got = NULL;
3453
3454
0
  rel = relocs;
3455
0
  relend = relocs + input_section->reloc_count;
3456
0
  for (; rel < relend; rel++)
3457
0
    {
3458
0
      int r_type;
3459
0
      reloc_howto_type *howto;
3460
0
      unsigned long r_symndx;
3461
0
      struct elf_link_hash_entry *h;
3462
0
      Elf_Internal_Sym *sym;
3463
0
      asection *sec;
3464
0
      bfd_vma relocation;
3465
0
      bool unresolved_reloc;
3466
0
      bfd_reloc_status_type r;
3467
0
      bool resolved_to_zero;
3468
3469
0
      r_type = ELF32_R_TYPE (rel->r_info);
3470
0
      if (r_type < 0 || r_type >= (int) R_68K_max)
3471
0
  {
3472
0
    bfd_set_error (bfd_error_bad_value);
3473
0
    return false;
3474
0
  }
3475
0
      howto = howto_table + r_type;
3476
3477
0
      r_symndx = ELF32_R_SYM (rel->r_info);
3478
3479
0
      h = NULL;
3480
0
      sym = NULL;
3481
0
      sec = NULL;
3482
0
      unresolved_reloc = false;
3483
3484
0
      if (r_symndx < symtab_hdr->sh_info)
3485
0
  {
3486
0
    sym = local_syms + r_symndx;
3487
0
    sec = local_sections[r_symndx];
3488
0
    relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
3489
0
  }
3490
0
      else
3491
0
  {
3492
0
    bool warned, ignored;
3493
3494
0
    RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
3495
0
           r_symndx, symtab_hdr, sym_hashes,
3496
0
           h, sec, relocation,
3497
0
           unresolved_reloc, warned, ignored);
3498
0
  }
3499
3500
0
      if (sec != NULL && discarded_section (sec))
3501
0
  RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
3502
0
           rel, 1, relend, howto, 0, contents);
3503
3504
0
      if (bfd_link_relocatable (info))
3505
0
  continue;
3506
3507
0
      resolved_to_zero = (h != NULL
3508
0
        && UNDEFWEAK_NO_DYNAMIC_RELOC (info, h));
3509
3510
0
      switch (r_type)
3511
0
  {
3512
0
  case R_68K_GOT8:
3513
0
  case R_68K_GOT16:
3514
0
  case R_68K_GOT32:
3515
    /* Relocation is to the address of the entry for this symbol
3516
       in the global offset table.  */
3517
0
    if (h != NULL
3518
0
        && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
3519
0
      {
3520
0
        if (elf_m68k_hash_table (info)->local_gp_p)
3521
0
    {
3522
0
      bfd_vma sgot_output_offset;
3523
0
      bfd_vma got_offset;
3524
3525
0
      sgot = elf_hash_table (info)->sgot;
3526
3527
0
      if (sgot != NULL)
3528
0
        sgot_output_offset = sgot->output_offset;
3529
0
      else
3530
        /* In this case we have a reference to
3531
           _GLOBAL_OFFSET_TABLE_, but the GOT itself is
3532
           empty.
3533
           ??? Issue a warning?  */
3534
0
        sgot_output_offset = 0;
3535
3536
0
      if (got == NULL)
3537
0
        {
3538
0
          struct elf_m68k_bfd2got_entry *bfd2got_entry;
3539
3540
0
          bfd2got_entry
3541
0
      = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
3542
0
                  input_bfd, SEARCH, NULL);
3543
3544
0
          if (bfd2got_entry != NULL)
3545
0
      {
3546
0
        got = bfd2got_entry->got;
3547
0
        BFD_ASSERT (got != NULL);
3548
3549
0
        got_offset = got->offset;
3550
0
      }
3551
0
          else
3552
      /* In this case we have a reference to
3553
         _GLOBAL_OFFSET_TABLE_, but no other references
3554
         accessing any GOT entries.
3555
         ??? Issue a warning?  */
3556
0
      got_offset = 0;
3557
0
        }
3558
0
      else
3559
0
        got_offset = got->offset;
3560
3561
      /* Adjust GOT pointer to point to the GOT
3562
         assigned to input_bfd.  */
3563
0
      rel->r_addend += sgot_output_offset + got_offset;
3564
0
    }
3565
0
        else
3566
0
    BFD_ASSERT (got == NULL || got->offset == 0);
3567
3568
0
        break;
3569
0
      }
3570
    /* Fall through.  */
3571
0
  case R_68K_GOT8O:
3572
0
  case R_68K_GOT16O:
3573
0
  case R_68K_GOT32O:
3574
3575
0
  case R_68K_TLS_LDM32:
3576
0
  case R_68K_TLS_LDM16:
3577
0
  case R_68K_TLS_LDM8:
3578
3579
0
  case R_68K_TLS_GD8:
3580
0
  case R_68K_TLS_GD16:
3581
0
  case R_68K_TLS_GD32:
3582
3583
0
  case R_68K_TLS_IE8:
3584
0
  case R_68K_TLS_IE16:
3585
0
  case R_68K_TLS_IE32:
3586
3587
    /* Relocation is the offset of the entry for this symbol in
3588
       the global offset table.  */
3589
3590
0
    {
3591
0
      struct elf_m68k_got_entry_key key_;
3592
0
      bfd_vma *off_ptr;
3593
0
      bfd_vma off;
3594
3595
0
      sgot = elf_hash_table (info)->sgot;
3596
0
      BFD_ASSERT (sgot != NULL);
3597
3598
0
      if (got == NULL)
3599
0
        got = elf_m68k_get_bfd2got_entry (elf_m68k_multi_got (info),
3600
0
            input_bfd, MUST_FIND,
3601
0
            NULL)->got;
3602
3603
      /* Get GOT offset for this symbol.  */
3604
0
      elf_m68k_init_got_entry_key (&key_, h, input_bfd, r_symndx,
3605
0
           r_type);
3606
0
      off_ptr = &elf_m68k_get_got_entry (got, &key_, MUST_FIND,
3607
0
                 NULL)->u.s2.offset;
3608
0
      off = *off_ptr;
3609
3610
      /* The offset must always be a multiple of 4.  We use
3611
         the least significant bit to record whether we have
3612
         already generated the necessary reloc.  */
3613
0
      if ((off & 1) != 0)
3614
0
        off &= ~1;
3615
0
      else
3616
0
        {
3617
0
    if (h != NULL
3618
        /* @TLSLDM relocations are bounded to the module, in
3619
           which the symbol is defined -- not to the symbol
3620
           itself.  */
3621
0
        && elf_m68k_reloc_got_type (r_type) != R_68K_TLS_LDM32)
3622
0
      {
3623
0
        bool dyn;
3624
3625
0
        dyn = elf_hash_table (info)->dynamic_sections_created;
3626
0
        if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn,
3627
0
                bfd_link_pic (info),
3628
0
                h)
3629
0
      || (bfd_link_pic (info)
3630
0
          && SYMBOL_REFERENCES_LOCAL (info, h))
3631
0
      || ((ELF_ST_VISIBILITY (h->other)
3632
0
           || resolved_to_zero)
3633
0
          && h->root.type == bfd_link_hash_undefweak))
3634
0
          {
3635
      /* This is actually a static link, or it is a
3636
         -Bsymbolic link and the symbol is defined
3637
         locally, or the symbol was forced to be local
3638
         because of a version file.  We must initialize
3639
         this entry in the global offset table.  Since
3640
         the offset must always be a multiple of 4, we
3641
         use the least significant bit to record whether
3642
         we have initialized it already.
3643
3644
         When doing a dynamic link, we create a .rela.got
3645
         relocation entry to initialize the value.  This
3646
         is done in the finish_dynamic_symbol routine.  */
3647
3648
0
      elf_m68k_init_got_entry_static (info,
3649
0
              output_bfd,
3650
0
              r_type,
3651
0
              sgot,
3652
0
              off,
3653
0
              relocation);
3654
3655
0
      *off_ptr |= 1;
3656
0
          }
3657
0
        else
3658
0
          unresolved_reloc = false;
3659
0
      }
3660
0
    else if (bfd_link_pic (info)) /* && h == NULL */
3661
      /* Process local symbol during dynamic link.  */
3662
0
      {
3663
0
        srela = elf_hash_table (info)->srelgot;
3664
0
        BFD_ASSERT (srela != NULL);
3665
3666
0
        elf_m68k_init_got_entry_local_shared (info,
3667
0
                output_bfd,
3668
0
                r_type,
3669
0
                sgot,
3670
0
                off,
3671
0
                relocation,
3672
0
                srela);
3673
3674
0
        *off_ptr |= 1;
3675
0
      }
3676
0
    else /* h == NULL && !bfd_link_pic (info) */
3677
0
      {
3678
0
        elf_m68k_init_got_entry_static (info,
3679
0
                output_bfd,
3680
0
                r_type,
3681
0
                sgot,
3682
0
                off,
3683
0
                relocation);
3684
3685
0
        *off_ptr |= 1;
3686
0
      }
3687
0
        }
3688
3689
      /* We don't use elf_m68k_reloc_got_type in the condition below
3690
         because this is the only place where difference between
3691
         R_68K_GOTx and R_68K_GOTxO relocations matters.  */
3692
0
      if (r_type == R_68K_GOT32O
3693
0
    || r_type == R_68K_GOT16O
3694
0
    || r_type == R_68K_GOT8O
3695
0
    || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_GD32
3696
0
    || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_LDM32
3697
0
    || elf_m68k_reloc_got_type (r_type) == R_68K_TLS_IE32)
3698
0
        {
3699
    /* GOT pointer is adjusted to point to the start/middle
3700
       of local GOT.  Adjust the offset accordingly.  */
3701
0
    BFD_ASSERT (elf_m68k_hash_table (info)->use_neg_got_offsets_p
3702
0
          || off >= got->offset);
3703
3704
0
    if (elf_m68k_hash_table (info)->local_gp_p)
3705
0
      relocation = off - got->offset;
3706
0
    else
3707
0
      {
3708
0
        BFD_ASSERT (got->offset == 0);
3709
0
        relocation = sgot->output_offset + off;
3710
0
      }
3711
3712
    /* This relocation does not use the addend.  */
3713
0
    rel->r_addend = 0;
3714
0
        }
3715
0
      else
3716
0
        relocation = (sgot->output_section->vma + sgot->output_offset
3717
0
          + off);
3718
0
    }
3719
0
    break;
3720
3721
0
  case R_68K_TLS_LDO32:
3722
0
  case R_68K_TLS_LDO16:
3723
0
  case R_68K_TLS_LDO8:
3724
0
    relocation -= dtpoff_base (info);
3725
0
    break;
3726
3727
0
  case R_68K_TLS_LE32:
3728
0
  case R_68K_TLS_LE16:
3729
0
  case R_68K_TLS_LE8:
3730
0
    if (bfd_link_dll (info))
3731
0
      {
3732
0
        _bfd_error_handler
3733
    /* xgettext:c-format */
3734
0
    (_("%pB(%pA+%#" PRIx64 "): "
3735
0
       "%s relocation not permitted in shared object"),
3736
0
     input_bfd, input_section, (uint64_t) rel->r_offset,
3737
0
     howto->name);
3738
3739
0
        return false;
3740
0
      }
3741
0
    else
3742
0
      relocation -= tpoff_base (info);
3743
3744
0
    break;
3745
3746
0
  case R_68K_PLT8:
3747
0
  case R_68K_PLT16:
3748
0
  case R_68K_PLT32:
3749
    /* Relocation is to the entry for this symbol in the
3750
       procedure linkage table.  */
3751
3752
    /* Resolve a PLTxx reloc against a local symbol directly,
3753
       without using the procedure linkage table.  */
3754
0
    if (h == NULL)
3755
0
      break;
3756
3757
0
    if (h->plt.offset == (bfd_vma) -1
3758
0
        || !elf_hash_table (info)->dynamic_sections_created)
3759
0
      {
3760
        /* We didn't make a PLT entry for this symbol.  This
3761
     happens when statically linking PIC code, or when
3762
     using -Bsymbolic.  */
3763
0
        break;
3764
0
      }
3765
3766
0
    splt = elf_hash_table (info)->splt;
3767
0
    BFD_ASSERT (splt != NULL);
3768
3769
0
    relocation = (splt->output_section->vma
3770
0
      + splt->output_offset
3771
0
      + h->plt.offset);
3772
0
    unresolved_reloc = false;
3773
0
    break;
3774
3775
0
  case R_68K_PLT8O:
3776
0
  case R_68K_PLT16O:
3777
0
  case R_68K_PLT32O:
3778
    /* Relocation is the offset of the entry for this symbol in
3779
       the procedure linkage table.  */
3780
0
    BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1);
3781
3782
0
    splt = elf_hash_table (info)->splt;
3783
0
    BFD_ASSERT (splt != NULL);
3784
3785
0
    relocation = h->plt.offset;
3786
0
    unresolved_reloc = false;
3787
3788
    /* This relocation does not use the addend.  */
3789
0
    rel->r_addend = 0;
3790
3791
0
    break;
3792
3793
0
  case R_68K_8:
3794
0
  case R_68K_16:
3795
0
  case R_68K_32:
3796
0
  case R_68K_PC8:
3797
0
  case R_68K_PC16:
3798
0
  case R_68K_PC32:
3799
0
    if (bfd_link_pic (info)
3800
0
        && r_symndx != STN_UNDEF
3801
0
        && (input_section->flags & SEC_ALLOC) != 0
3802
0
        && (h == NULL
3803
0
      || (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
3804
0
          && !resolved_to_zero)
3805
0
      || h->root.type != bfd_link_hash_undefweak)
3806
0
        && ((r_type != R_68K_PC8
3807
0
       && r_type != R_68K_PC16
3808
0
       && r_type != R_68K_PC32)
3809
0
      || !SYMBOL_CALLS_LOCAL (info, h)))
3810
0
      {
3811
0
        Elf_Internal_Rela outrel;
3812
0
        bfd_byte *loc;
3813
0
        bool skip, relocate;
3814
3815
        /* When generating a shared object, these relocations
3816
     are copied into the output file to be resolved at run
3817
     time.  */
3818
3819
0
        skip = false;
3820
0
        relocate = false;
3821
3822
0
        outrel.r_offset =
3823
0
    _bfd_elf_section_offset (output_bfd, info, input_section,
3824
0
           rel->r_offset);
3825
0
        if (outrel.r_offset == (bfd_vma) -1)
3826
0
    skip = true;
3827
0
        else if (outrel.r_offset == (bfd_vma) -2)
3828
0
    skip = true, relocate = true;
3829
0
        outrel.r_offset += (input_section->output_section->vma
3830
0
          + input_section->output_offset);
3831
3832
0
        if (skip)
3833
0
    memset (&outrel, 0, sizeof outrel);
3834
0
        else if (h != NULL
3835
0
           && h->dynindx != -1
3836
0
           && (r_type == R_68K_PC8
3837
0
         || r_type == R_68K_PC16
3838
0
         || r_type == R_68K_PC32
3839
0
         || !bfd_link_pic (info)
3840
0
         || !SYMBOLIC_BIND (info, h)
3841
0
         || !h->def_regular))
3842
0
    {
3843
0
      outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
3844
0
      outrel.r_addend = rel->r_addend;
3845
0
    }
3846
0
        else
3847
0
    {
3848
      /* This symbol is local, or marked to become local.  */
3849
0
      outrel.r_addend = relocation + rel->r_addend;
3850
3851
0
      if (r_type == R_68K_32)
3852
0
        {
3853
0
          relocate = true;
3854
0
          outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE);
3855
0
        }
3856
0
      else
3857
0
        {
3858
0
          long indx;
3859
3860
0
          if (bfd_is_abs_section (sec))
3861
0
      indx = 0;
3862
0
          else if (sec == NULL || sec->owner == NULL)
3863
0
      {
3864
0
        bfd_set_error (bfd_error_bad_value);
3865
0
        return false;
3866
0
      }
3867
0
          else
3868
0
      {
3869
0
        asection *osec;
3870
3871
        /* We are turning this relocation into one
3872
           against a section symbol.  It would be
3873
           proper to subtract the symbol's value,
3874
           osec->vma, from the emitted reloc addend,
3875
           but ld.so expects buggy relocs.  */
3876
0
        osec = sec->output_section;
3877
0
        indx = elf_section_data (osec)->dynindx;
3878
0
        if (indx == 0)
3879
0
          {
3880
0
            struct elf_link_hash_table *htab;
3881
0
            htab = elf_hash_table (info);
3882
0
            osec = htab->text_index_section;
3883
0
            indx = elf_section_data (osec)->dynindx;
3884
0
          }
3885
0
        BFD_ASSERT (indx != 0);
3886
0
      }
3887
3888
0
          outrel.r_info = ELF32_R_INFO (indx, r_type);
3889
0
        }
3890
0
    }
3891
3892
0
        sreloc = elf_section_data (input_section)->sreloc;
3893
0
        if (sreloc == NULL)
3894
0
    abort ();
3895
3896
0
        loc = sreloc->contents;
3897
0
        loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela);
3898
0
        bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc);
3899
3900
        /* This reloc will be computed at runtime, so there's no
3901
     need to do anything now, except for R_68K_32
3902
     relocations that have been turned into
3903
     R_68K_RELATIVE.  */
3904
0
        if (!relocate)
3905
0
    continue;
3906
0
      }
3907
3908
0
    break;
3909
3910
0
  case R_68K_GNU_VTINHERIT:
3911
0
  case R_68K_GNU_VTENTRY:
3912
    /* These are no-ops in the end.  */
3913
0
    continue;
3914
3915
0
  default:
3916
0
    break;
3917
0
  }
3918
3919
      /* Dynamic relocs are not propagated for SEC_DEBUGGING sections
3920
   because such sections are not SEC_ALLOC and thus ld.so will
3921
   not process them.  */
3922
0
      if (unresolved_reloc
3923
0
    && !((input_section->flags & SEC_DEBUGGING) != 0
3924
0
         && h->def_dynamic)
3925
0
    && _bfd_elf_section_offset (output_bfd, info, input_section,
3926
0
              rel->r_offset) != (bfd_vma) -1)
3927
0
  {
3928
0
    _bfd_error_handler
3929
      /* xgettext:c-format */
3930
0
      (_("%pB(%pA+%#" PRIx64 "): "
3931
0
         "unresolvable %s relocation against symbol `%s'"),
3932
0
       input_bfd,
3933
0
       input_section,
3934
0
       (uint64_t) rel->r_offset,
3935
0
       howto->name,
3936
0
       h->root.root.string);
3937
0
    return false;
3938
0
  }
3939
3940
0
      if (r_symndx != STN_UNDEF
3941
0
    && r_type != R_68K_NONE
3942
0
    && (h == NULL
3943
0
        || h->root.type == bfd_link_hash_defined
3944
0
        || h->root.type == bfd_link_hash_defweak))
3945
0
  {
3946
0
    char sym_type;
3947
3948
0
    sym_type = (sym != NULL) ? ELF32_ST_TYPE (sym->st_info) : h->type;
3949
3950
0
    if (elf_m68k_reloc_tls_p (r_type) != (sym_type == STT_TLS))
3951
0
      {
3952
0
        const char *name;
3953
3954
0
        if (h != NULL)
3955
0
    name = h->root.root.string;
3956
0
        else
3957
0
    {
3958
0
      name = (bfd_elf_string_from_elf_section
3959
0
        (input_bfd, symtab_hdr->sh_link, sym->st_name));
3960
0
      if (name == NULL || *name == '\0')
3961
0
        name = bfd_section_name (sec);
3962
0
    }
3963
3964
0
        _bfd_error_handler
3965
0
    ((sym_type == STT_TLS
3966
      /* xgettext:c-format */
3967
0
      ? _("%pB(%pA+%#" PRIx64 "): %s used with TLS symbol %s")
3968
      /* xgettext:c-format */
3969
0
      : _("%pB(%pA+%#" PRIx64 "): %s used with non-TLS symbol %s")),
3970
0
     input_bfd,
3971
0
     input_section,
3972
0
     (uint64_t) rel->r_offset,
3973
0
     howto->name,
3974
0
     name);
3975
0
      }
3976
0
  }
3977
3978
0
      r = _bfd_final_link_relocate (howto, input_bfd, input_section,
3979
0
            contents, rel->r_offset,
3980
0
            relocation, rel->r_addend);
3981
3982
0
      if (r != bfd_reloc_ok)
3983
0
  {
3984
0
    const char *name;
3985
3986
0
    if (h != NULL)
3987
0
      name = h->root.root.string;
3988
0
    else
3989
0
      {
3990
0
        name = bfd_elf_string_from_elf_section (input_bfd,
3991
0
                  symtab_hdr->sh_link,
3992
0
                  sym->st_name);
3993
0
        if (name == NULL)
3994
0
    return false;
3995
0
        if (*name == '\0')
3996
0
    name = bfd_section_name (sec);
3997
0
      }
3998
3999
0
    if (r == bfd_reloc_overflow)
4000
0
      (*info->callbacks->reloc_overflow)
4001
0
        (info, (h ? &h->root : NULL), name, howto->name,
4002
0
         (bfd_vma) 0, input_bfd, input_section, rel->r_offset);
4003
0
    else
4004
0
      {
4005
0
        _bfd_error_handler
4006
    /* xgettext:c-format */
4007
0
    (_("%pB(%pA+%#" PRIx64 "): reloc against `%s': error %d"),
4008
0
     input_bfd, input_section,
4009
0
     (uint64_t) rel->r_offset, name, (int) r);
4010
0
        return false;
4011
0
      }
4012
0
  }
4013
0
    }
4014
4015
0
  return true;
4016
0
}
4017
4018
/* Install an M_68K_PC32 relocation against VALUE at offset OFFSET
4019
   into section SEC.  */
4020
4021
static void
4022
elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value)
4023
0
{
4024
  /* Make VALUE PC-relative.  */
4025
0
  value -= sec->output_section->vma + offset;
4026
4027
  /* Apply any in-place addend.  */
4028
0
  value += bfd_get_32 (sec->owner, sec->contents + offset);
4029
4030
0
  bfd_put_32 (sec->owner, value, sec->contents + offset);
4031
0
}
4032
4033
/* Finish up dynamic symbol handling.  We set the contents of various
4034
   dynamic sections here.  */
4035
4036
static bool
4037
elf_m68k_finish_dynamic_symbol (bfd *output_bfd,
4038
        struct bfd_link_info *info,
4039
        struct elf_link_hash_entry *h,
4040
        Elf_Internal_Sym *sym)
4041
0
{
4042
0
  bfd *dynobj;
4043
4044
0
  dynobj = elf_hash_table (info)->dynobj;
4045
4046
0
  if (h->plt.offset != (bfd_vma) -1)
4047
0
    {
4048
0
      const struct elf_m68k_plt_info *plt_info;
4049
0
      asection *splt;
4050
0
      asection *sgot;
4051
0
      asection *srela;
4052
0
      bfd_vma plt_index;
4053
0
      bfd_vma got_offset;
4054
0
      Elf_Internal_Rela rela;
4055
0
      bfd_byte *loc;
4056
4057
      /* This symbol has an entry in the procedure linkage table.  Set
4058
   it up.  */
4059
4060
0
      BFD_ASSERT (h->dynindx != -1);
4061
4062
0
      plt_info = elf_m68k_hash_table (info)->plt_info;
4063
0
      splt = elf_hash_table (info)->splt;
4064
0
      sgot = elf_hash_table (info)->sgotplt;
4065
0
      srela = elf_hash_table (info)->srelplt;
4066
0
      BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL);
4067
4068
      /* Get the index in the procedure linkage table which
4069
   corresponds to this symbol.  This is the index of this symbol
4070
   in all the symbols for which we are making plt entries.  The
4071
   first entry in the procedure linkage table is reserved.  */
4072
0
      plt_index = (h->plt.offset / plt_info->size) - 1;
4073
4074
      /* Get the offset into the .got table of the entry that
4075
   corresponds to this function.  Each .got entry is 4 bytes.
4076
   The first three are reserved.  */
4077
0
      got_offset = (plt_index + 3) * 4;
4078
4079
0
      memcpy (splt->contents + h->plt.offset,
4080
0
        plt_info->symbol_entry,
4081
0
        plt_info->size);
4082
4083
0
      elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.got,
4084
0
           (sgot->output_section->vma
4085
0
            + sgot->output_offset
4086
0
            + got_offset));
4087
4088
0
      bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela),
4089
0
      splt->contents
4090
0
      + h->plt.offset
4091
0
      + plt_info->symbol_resolve_entry + 2);
4092
4093
0
      elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.plt,
4094
0
           splt->output_section->vma);
4095
4096
      /* Fill in the entry in the global offset table.  */
4097
0
      bfd_put_32 (output_bfd,
4098
0
      (splt->output_section->vma
4099
0
       + splt->output_offset
4100
0
       + h->plt.offset
4101
0
       + plt_info->symbol_resolve_entry),
4102
0
      sgot->contents + got_offset);
4103
4104
      /* Fill in the entry in the .rela.plt section.  */
4105
0
      rela.r_offset = (sgot->output_section->vma
4106
0
           + sgot->output_offset
4107
0
           + got_offset);
4108
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT);
4109
0
      rela.r_addend = 0;
4110
0
      loc = srela->contents + plt_index * sizeof (Elf32_External_Rela);
4111
0
      bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4112
4113
0
      if (!h->def_regular)
4114
0
  {
4115
    /* Mark the symbol as undefined, rather than as defined in
4116
       the .plt section.  Leave the value alone.  */
4117
0
    sym->st_shndx = SHN_UNDEF;
4118
0
  }
4119
0
    }
4120
4121
0
  if (elf_m68k_hash_entry (h)->glist != NULL)
4122
0
    {
4123
0
      asection *sgot;
4124
0
      asection *srela;
4125
0
      struct elf_m68k_got_entry *got_entry;
4126
4127
      /* This symbol has an entry in the global offset table.  Set it
4128
   up.  */
4129
4130
0
      sgot = elf_hash_table (info)->sgot;
4131
0
      srela = elf_hash_table (info)->srelgot;
4132
0
      BFD_ASSERT (sgot != NULL && srela != NULL);
4133
4134
0
      got_entry = elf_m68k_hash_entry (h)->glist;
4135
4136
0
      while (got_entry != NULL)
4137
0
  {
4138
0
    enum elf_m68k_reloc_type r_type;
4139
0
    bfd_vma got_entry_offset;
4140
4141
0
    r_type = got_entry->key_.type;
4142
0
    got_entry_offset = got_entry->u.s2.offset &~ (bfd_vma) 1;
4143
4144
    /* If this is a -Bsymbolic link, and the symbol is defined
4145
       locally, we just want to emit a RELATIVE reloc.  Likewise if
4146
       the symbol was forced to be local because of a version file.
4147
       The entry in the global offset table already have been
4148
       initialized in the relocate_section function.  */
4149
0
    if (bfd_link_pic (info)
4150
0
        && SYMBOL_REFERENCES_LOCAL (info, h))
4151
0
      {
4152
0
        bfd_vma relocation;
4153
4154
0
        relocation = bfd_get_signed_32 (output_bfd,
4155
0
                (sgot->contents
4156
0
                 + got_entry_offset));
4157
4158
        /* Undo TP bias.  */
4159
0
        switch (elf_m68k_reloc_got_type (r_type))
4160
0
    {
4161
0
    case R_68K_GOT32O:
4162
0
    case R_68K_TLS_LDM32:
4163
0
      break;
4164
4165
0
    case R_68K_TLS_GD32:
4166
      /* The value for this relocation is actually put in
4167
         the second GOT slot.  */
4168
0
      relocation = bfd_get_signed_32 (output_bfd,
4169
0
              (sgot->contents
4170
0
               + got_entry_offset + 4));
4171
0
      relocation += dtpoff_base (info);
4172
0
      break;
4173
4174
0
    case R_68K_TLS_IE32:
4175
0
      relocation += tpoff_base (info);
4176
0
      break;
4177
4178
0
    default:
4179
0
      BFD_ASSERT (false);
4180
0
    }
4181
4182
0
        elf_m68k_init_got_entry_local_shared (info,
4183
0
                output_bfd,
4184
0
                r_type,
4185
0
                sgot,
4186
0
                got_entry_offset,
4187
0
                relocation,
4188
0
                srela);
4189
0
      }
4190
0
    else
4191
0
      {
4192
0
        Elf_Internal_Rela rela;
4193
4194
        /* Put zeros to GOT slots that will be initialized
4195
     at run-time.  */
4196
0
        {
4197
0
    bfd_vma n_slots;
4198
4199
0
    n_slots = elf_m68k_reloc_got_n_slots (got_entry->key_.type);
4200
0
    while (n_slots--)
4201
0
      bfd_put_32 (output_bfd, (bfd_vma) 0,
4202
0
            (sgot->contents + got_entry_offset
4203
0
             + 4 * n_slots));
4204
0
        }
4205
4206
0
        rela.r_addend = 0;
4207
0
        rela.r_offset = (sgot->output_section->vma
4208
0
             + sgot->output_offset
4209
0
             + got_entry_offset);
4210
4211
0
        switch (elf_m68k_reloc_got_type (r_type))
4212
0
    {
4213
0
    case R_68K_GOT32O:
4214
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT);
4215
0
      elf_m68k_install_rela (output_bfd, srela, &rela);
4216
0
      break;
4217
4218
0
    case R_68K_TLS_GD32:
4219
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPMOD32);
4220
0
      elf_m68k_install_rela (output_bfd, srela, &rela);
4221
4222
0
      rela.r_offset += 4;
4223
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_DTPREL32);
4224
0
      elf_m68k_install_rela (output_bfd, srela, &rela);
4225
0
      break;
4226
4227
0
    case R_68K_TLS_IE32:
4228
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_TLS_TPREL32);
4229
0
      elf_m68k_install_rela (output_bfd, srela, &rela);
4230
0
      break;
4231
4232
0
    default:
4233
0
      BFD_ASSERT (false);
4234
0
      break;
4235
0
    }
4236
0
      }
4237
4238
0
    got_entry = got_entry->u.s2.next;
4239
0
  }
4240
0
    }
4241
4242
0
  if (h->needs_copy)
4243
0
    {
4244
0
      asection *s;
4245
0
      Elf_Internal_Rela rela;
4246
0
      bfd_byte *loc;
4247
4248
      /* This symbol needs a copy reloc.  Set it up.  */
4249
4250
0
      BFD_ASSERT (h->dynindx != -1
4251
0
      && (h->root.type == bfd_link_hash_defined
4252
0
          || h->root.type == bfd_link_hash_defweak));
4253
4254
0
      s = bfd_get_linker_section (dynobj, ".rela.bss");
4255
0
      BFD_ASSERT (s != NULL);
4256
4257
0
      rela.r_offset = (h->root.u.def.value
4258
0
           + h->root.u.def.section->output_section->vma
4259
0
           + h->root.u.def.section->output_offset);
4260
0
      rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY);
4261
0
      rela.r_addend = 0;
4262
0
      loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela);
4263
0
      bfd_elf32_swap_reloca_out (output_bfd, &rela, loc);
4264
0
    }
4265
4266
0
  return true;
4267
0
}
4268
4269
/* Finish up the dynamic sections.  */
4270
4271
static bool
4272
elf_m68k_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info)
4273
0
{
4274
0
  bfd *dynobj;
4275
0
  asection *sgot;
4276
0
  asection *sdyn;
4277
4278
0
  dynobj = elf_hash_table (info)->dynobj;
4279
4280
0
  sgot = elf_hash_table (info)->sgotplt;
4281
0
  BFD_ASSERT (sgot != NULL);
4282
0
  sdyn = bfd_get_linker_section (dynobj, ".dynamic");
4283
4284
0
  if (elf_hash_table (info)->dynamic_sections_created)
4285
0
    {
4286
0
      asection *splt;
4287
0
      Elf32_External_Dyn *dyncon, *dynconend;
4288
4289
0
      splt = elf_hash_table (info)->splt;
4290
0
      BFD_ASSERT (splt != NULL && sdyn != NULL);
4291
4292
0
      dyncon = (Elf32_External_Dyn *) sdyn->contents;
4293
0
      dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size);
4294
0
      for (; dyncon < dynconend; dyncon++)
4295
0
  {
4296
0
    Elf_Internal_Dyn dyn;
4297
0
    asection *s;
4298
4299
0
    bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn);
4300
4301
0
    switch (dyn.d_tag)
4302
0
      {
4303
0
      default:
4304
0
        break;
4305
4306
0
      case DT_PLTGOT:
4307
0
        s = elf_hash_table (info)->sgotplt;
4308
0
        goto get_vma;
4309
0
      case DT_JMPREL:
4310
0
        s = elf_hash_table (info)->srelplt;
4311
0
      get_vma:
4312
0
        dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
4313
0
        bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4314
0
        break;
4315
4316
0
      case DT_PLTRELSZ:
4317
0
        s = elf_hash_table (info)->srelplt;
4318
0
        dyn.d_un.d_val = s->size;
4319
0
        bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
4320
0
        break;
4321
0
      }
4322
0
  }
4323
4324
      /* Fill in the first entry in the procedure linkage table.  */
4325
0
      if (splt->size > 0)
4326
0
  {
4327
0
    const struct elf_m68k_plt_info *plt_info;
4328
4329
0
    plt_info = elf_m68k_hash_table (info)->plt_info;
4330
0
    memcpy (splt->contents, plt_info->plt0_entry, plt_info->size);
4331
4332
0
    elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got4,
4333
0
         (sgot->output_section->vma
4334
0
          + sgot->output_offset
4335
0
          + 4));
4336
4337
0
    elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got8,
4338
0
         (sgot->output_section->vma
4339
0
          + sgot->output_offset
4340
0
          + 8));
4341
4342
0
    elf_section_data (splt->output_section)->this_hdr.sh_entsize
4343
0
      = plt_info->size;
4344
0
  }
4345
0
    }
4346
4347
  /* Fill in the first three entries in the global offset table.  */
4348
0
  if (sgot->size > 0)
4349
0
    {
4350
0
      if (sdyn == NULL)
4351
0
  bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);
4352
0
      else
4353
0
  bfd_put_32 (output_bfd,
4354
0
        sdyn->output_section->vma + sdyn->output_offset,
4355
0
        sgot->contents);
4356
0
      bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
4357
0
      bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
4358
0
    }
4359
4360
0
  elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
4361
4362
0
  return true;
4363
0
}
4364
4365
/* Given a .data section and a .emreloc in-memory section, store
4366
   relocation information into the .emreloc section which can be
4367
   used at runtime to relocate the section.  This is called by the
4368
   linker when the --embedded-relocs switch is used.  This is called
4369
   after the add_symbols entry point has been called for all the
4370
   objects, and before the final_link entry point is called.  */
4371
4372
bool
4373
bfd_m68k_elf32_create_embedded_relocs (bfd *abfd, struct bfd_link_info *info,
4374
               asection *datasec, asection *relsec,
4375
               char **errmsg)
4376
0
{
4377
0
  Elf_Internal_Shdr *symtab_hdr;
4378
0
  Elf_Internal_Sym *isymbuf = NULL;
4379
0
  Elf_Internal_Rela *internal_relocs = NULL;
4380
0
  Elf_Internal_Rela *irel, *irelend;
4381
0
  bfd_byte *p;
4382
0
  bfd_size_type amt;
4383
4384
0
  BFD_ASSERT (! bfd_link_relocatable (info));
4385
4386
0
  *errmsg = NULL;
4387
4388
0
  if (datasec->reloc_count == 0)
4389
0
    return true;
4390
4391
0
  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
4392
4393
  /* Get a copy of the native relocations.  */
4394
0
  internal_relocs = (_bfd_elf_link_read_relocs
4395
0
         (abfd, datasec, NULL, (Elf_Internal_Rela *) NULL,
4396
0
          info->keep_memory));
4397
0
  if (internal_relocs == NULL)
4398
0
    goto error_return;
4399
4400
0
  amt = (bfd_size_type) datasec->reloc_count * 12;
4401
0
  relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt);
4402
0
  if (relsec->contents == NULL)
4403
0
    goto error_return;
4404
4405
0
  p = relsec->contents;
4406
4407
0
  irelend = internal_relocs + datasec->reloc_count;
4408
0
  for (irel = internal_relocs; irel < irelend; irel++, p += 12)
4409
0
    {
4410
0
      asection *targetsec;
4411
4412
      /* We are going to write a four byte longword into the runtime
4413
       reloc section.  The longword will be the address in the data
4414
       section which must be relocated.  It is followed by the name
4415
       of the target section NUL-padded or truncated to 8
4416
       characters.  */
4417
4418
      /* We can only relocate absolute longword relocs at run time.  */
4419
0
      if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32)
4420
0
  {
4421
0
    *errmsg = _("unsupported relocation type");
4422
0
    bfd_set_error (bfd_error_bad_value);
4423
0
    goto error_return;
4424
0
  }
4425
4426
      /* Get the target section referred to by the reloc.  */
4427
0
      if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
4428
0
  {
4429
    /* A local symbol.  */
4430
0
    Elf_Internal_Sym *isym;
4431
4432
    /* Read this BFD's local symbols if we haven't done so already.  */
4433
0
    if (isymbuf == NULL)
4434
0
      {
4435
0
        isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
4436
0
        if (isymbuf == NULL)
4437
0
    isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
4438
0
            symtab_hdr->sh_info, 0,
4439
0
            NULL, NULL, NULL);
4440
0
        if (isymbuf == NULL)
4441
0
    goto error_return;
4442
0
      }
4443
4444
0
    isym = isymbuf + ELF32_R_SYM (irel->r_info);
4445
0
    targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx);
4446
0
  }
4447
0
      else
4448
0
  {
4449
0
    unsigned long indx;
4450
0
    struct elf_link_hash_entry *h;
4451
4452
    /* An external symbol.  */
4453
0
    indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
4454
0
    h = elf_sym_hashes (abfd)[indx];
4455
0
    BFD_ASSERT (h != NULL);
4456
0
    if (h->root.type == bfd_link_hash_defined
4457
0
        || h->root.type == bfd_link_hash_defweak)
4458
0
      targetsec = h->root.u.def.section;
4459
0
    else
4460
0
      targetsec = NULL;
4461
0
  }
4462
4463
0
      bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p);
4464
0
      memset (p + 4, 0, 8);
4465
0
      if (targetsec != NULL)
4466
0
  strncpy ((char *) p + 4, targetsec->output_section->name, 8);
4467
0
    }
4468
4469
0
  if (symtab_hdr->contents != (unsigned char *) isymbuf)
4470
0
    free (isymbuf);
4471
0
  if (elf_section_data (datasec)->relocs != internal_relocs)
4472
0
    free (internal_relocs);
4473
0
  return true;
4474
4475
0
 error_return:
4476
0
  if (symtab_hdr->contents != (unsigned char *) isymbuf)
4477
0
    free (isymbuf);
4478
0
  if (elf_section_data (datasec)->relocs != internal_relocs)
4479
0
    free (internal_relocs);
4480
0
  return false;
4481
0
}
4482
4483
/* Set target options.  */
4484
4485
void
4486
bfd_elf_m68k_set_target_options (struct bfd_link_info *info, int got_handling)
4487
0
{
4488
0
  struct elf_m68k_link_hash_table *htab;
4489
0
  bool use_neg_got_offsets_p;
4490
0
  bool allow_multigot_p;
4491
0
  bool local_gp_p;
4492
4493
0
  switch (got_handling)
4494
0
    {
4495
0
    case 0:
4496
      /* --got=single.  */
4497
0
      local_gp_p = false;
4498
0
      use_neg_got_offsets_p = false;
4499
0
      allow_multigot_p = false;
4500
0
      break;
4501
4502
0
    case 1:
4503
      /* --got=negative.  */
4504
0
      local_gp_p = true;
4505
0
      use_neg_got_offsets_p = true;
4506
0
      allow_multigot_p = false;
4507
0
      break;
4508
4509
0
    case 2:
4510
      /* --got=multigot.  */
4511
0
      local_gp_p = true;
4512
0
      use_neg_got_offsets_p = true;
4513
0
      allow_multigot_p = true;
4514
0
      break;
4515
4516
0
    default:
4517
0
      BFD_ASSERT (false);
4518
0
      return;
4519
0
    }
4520
4521
0
  htab = elf_m68k_hash_table (info);
4522
0
  if (htab != NULL)
4523
0
    {
4524
0
      htab->local_gp_p = local_gp_p;
4525
0
      htab->use_neg_got_offsets_p = use_neg_got_offsets_p;
4526
0
      htab->allow_multigot_p = allow_multigot_p;
4527
0
    }
4528
0
}
4529
4530
static enum elf_reloc_type_class
4531
elf32_m68k_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
4532
           const asection *rel_sec ATTRIBUTE_UNUSED,
4533
           const Elf_Internal_Rela *rela)
4534
0
{
4535
0
  switch ((int) ELF32_R_TYPE (rela->r_info))
4536
0
    {
4537
0
    case R_68K_RELATIVE:
4538
0
      return reloc_class_relative;
4539
0
    case R_68K_JMP_SLOT:
4540
0
      return reloc_class_plt;
4541
0
    case R_68K_COPY:
4542
0
      return reloc_class_copy;
4543
0
    default:
4544
0
      return reloc_class_normal;
4545
0
    }
4546
0
}
4547
4548
/* Return address for Ith PLT stub in section PLT, for relocation REL
4549
   or (bfd_vma) -1 if it should not be included.  */
4550
4551
static bfd_vma
4552
elf_m68k_plt_sym_val (bfd_vma i, const asection *plt,
4553
          const arelent *rel ATTRIBUTE_UNUSED)
4554
0
{
4555
0
  return plt->vma + (i + 1) * elf_m68k_get_plt_info (plt->owner)->size;
4556
0
}
4557
4558
/* Support for core dump NOTE sections.  */
4559
4560
static bool
4561
elf_m68k_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
4562
0
{
4563
0
  int offset;
4564
0
  size_t size;
4565
4566
0
  switch (note->descsz)
4567
0
    {
4568
0
    default:
4569
0
      return false;
4570
4571
0
    case 154:   /* Linux/m68k */
4572
      /* pr_cursig */
4573
0
      elf_tdata (abfd)->core->signal = bfd_get_16 (abfd, note->descdata + 12);
4574
4575
      /* pr_pid */
4576
0
      elf_tdata (abfd)->core->lwpid = bfd_get_32 (abfd, note->descdata + 22);
4577
4578
      /* pr_reg */
4579
0
      offset = 70;
4580
0
      size = 80;
4581
4582
0
      break;
4583
0
    }
4584
4585
  /* Make a ".reg/999" section.  */
4586
0
  return _bfd_elfcore_make_pseudosection (abfd, ".reg",
4587
0
            size, note->descpos + offset);
4588
0
}
4589
4590
static bool
4591
elf_m68k_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
4592
0
{
4593
0
  switch (note->descsz)
4594
0
    {
4595
0
    default:
4596
0
      return false;
4597
4598
0
    case 124:   /* Linux/m68k elf_prpsinfo.  */
4599
0
      elf_tdata (abfd)->core->pid
4600
0
  = bfd_get_32 (abfd, note->descdata + 12);
4601
0
      elf_tdata (abfd)->core->program
4602
0
  = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
4603
0
      elf_tdata (abfd)->core->command
4604
0
  = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
4605
0
    }
4606
4607
  /* Note that for some reason, a spurious space is tacked
4608
     onto the end of the args in some (at least one anyway)
4609
     implementations, so strip it off if it exists.  */
4610
0
  {
4611
0
    char *command = elf_tdata (abfd)->core->command;
4612
0
    int n = strlen (command);
4613
4614
0
    if (n > 0 && command[n - 1] == ' ')
4615
0
      command[n - 1] = '\0';
4616
0
  }
4617
4618
0
  return true;
4619
0
}
4620
4621
#define TARGET_BIG_SYM      m68k_elf32_vec
4622
#define TARGET_BIG_NAME     "elf32-m68k"
4623
#define ELF_MACHINE_CODE    EM_68K
4624
#define ELF_MAXPAGESIZE     0x2000
4625
#define elf_backend_create_dynamic_sections \
4626
          _bfd_elf_create_dynamic_sections
4627
#define bfd_elf32_bfd_link_hash_table_create \
4628
          elf_m68k_link_hash_table_create
4629
#define bfd_elf32_bfd_final_link  bfd_elf_final_link
4630
4631
#define elf_backend_check_relocs  elf_m68k_check_relocs
4632
#define elf_backend_early_size_sections \
4633
          elf_m68k_early_size_sections
4634
#define elf_backend_adjust_dynamic_symbol \
4635
          elf_m68k_adjust_dynamic_symbol
4636
#define elf_backend_late_size_sections  elf_m68k_late_size_sections
4637
#define elf_backend_final_write_processing  elf_m68k_final_write_processing
4638
#define elf_backend_init_index_section  _bfd_elf_init_1_index_section
4639
#define elf_backend_relocate_section  elf_m68k_relocate_section
4640
#define elf_backend_finish_dynamic_symbol \
4641
          elf_m68k_finish_dynamic_symbol
4642
#define elf_backend_finish_dynamic_sections \
4643
          elf_m68k_finish_dynamic_sections
4644
#define elf_backend_gc_mark_hook  elf_m68k_gc_mark_hook
4645
#define elf_backend_copy_indirect_symbol elf_m68k_copy_indirect_symbol
4646
#define bfd_elf32_bfd_merge_private_bfd_data \
4647
          elf32_m68k_merge_private_bfd_data
4648
#define bfd_elf32_bfd_set_private_flags \
4649
          elf32_m68k_set_private_flags
4650
#define bfd_elf32_bfd_print_private_bfd_data \
4651
          elf32_m68k_print_private_bfd_data
4652
#define elf_backend_reloc_type_class  elf32_m68k_reloc_type_class
4653
#define elf_backend_plt_sym_val   elf_m68k_plt_sym_val
4654
#define elf_backend_object_p    elf32_m68k_object_p
4655
#define elf_backend_grok_prstatus elf_m68k_grok_prstatus
4656
#define elf_backend_grok_psinfo   elf_m68k_grok_psinfo
4657
4658
#define elf_backend_can_gc_sections 1
4659
#define elf_backend_can_refcount 1
4660
#define elf_backend_want_got_plt 1
4661
#define elf_backend_plt_readonly 1
4662
#define elf_backend_want_plt_sym 0
4663
#define elf_backend_got_header_size 12
4664
#define elf_backend_rela_normal   1
4665
#define elf_backend_dtrel_excludes_plt  1
4666
4667
#define elf_backend_linux_prpsinfo32_ugid16 true
4668
4669
#include "elf32-target.h"