Coverage Report

Created: 2025-06-24 06:45

/src/binutils-gdb/bfd/elf32-score.c
Line
Count
Source (jump to first uncovered line)
1
/* 32-bit ELF support for S+core.
2
   Copyright (C) 2006-2025 Free Software Foundation, Inc.
3
   Contributed by
4
   Brain.lin (brain.lin@sunplusct.com)
5
   Mei Ligang (ligang@sunnorth.com.cn)
6
   Pei-Lin Tsai (pltsai@sunplus.com)
7
8
   This file is part of BFD, the Binary File Descriptor library.
9
10
   This program is free software; you can redistribute it and/or modify
11
   it under the terms of the GNU General Public License as published by
12
   the Free Software Foundation; either version 3 of the License, or
13
   (at your option) any later version.
14
15
   This program is distributed in the hope that it will be useful,
16
   but WITHOUT ANY WARRANTY; without even the implied warranty of
17
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
   GNU General Public License for more details.
19
20
   You should have received a copy of the GNU General Public License
21
   along with this program; if not, write to the Free Software
22
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
23
   MA 02110-1301, USA.  */
24
25
#include "sysdep.h"
26
#include "bfd.h"
27
#include "libbfd.h"
28
#include "libiberty.h"
29
#include "elf-bfd.h"
30
#include "elf/score.h"
31
#include "elf/common.h"
32
#include "elf/internal.h"
33
#include "hashtab.h"
34
#include "elf32-score.h"
35
36
37
int score3 = 0;
38
int score7 = 1;
39
40
/* The SCORE ELF linker needs additional information for each symbol in
41
   the global hash table.  */
42
struct score_elf_link_hash_entry
43
{
44
  struct elf_link_hash_entry root;
45
46
  /* Number of R_SCORE_ABS32, R_SCORE_REL32 relocs against this symbol.  */
47
  unsigned int possibly_dynamic_relocs;
48
49
  /* If the R_SCORE_ABS32, R_SCORE_REL32 reloc is against a readonly section.  */
50
  bool readonly_reloc;
51
52
  /* We must not create a stub for a symbol that has relocations related to
53
     taking the function's address, i.e. any but R_SCORE_CALL15 ones.  */
54
  bool no_fn_stub;
55
56
  /* Are we forced local?  This will only be set if we have converted
57
     the initial global GOT entry to a local GOT entry.  */
58
  bool forced_local;
59
};
60
61
/* Traverse a score ELF linker hash table.  */
62
#define score_elf_link_hash_traverse(table, func, info) \
63
0
  (elf_link_hash_traverse         \
64
0
   ((table),              \
65
0
    (bool (*) (struct elf_link_hash_entry *, void *)) (func), \
66
0
    (info)))
67
68
/* This structure is used to hold .got entries while estimating got sizes.  */
69
struct score_got_entry
70
{
71
  /* The input bfd in which the symbol is defined.  */
72
  bfd *abfd;
73
  /* The index of the symbol, as stored in the relocation r_info, if
74
     we have a local symbol; -1 otherwise.  */
75
  long symndx;
76
  union
77
  {
78
    /* If abfd == NULL, an address that must be stored in the got.  */
79
    bfd_vma address;
80
    /* If abfd != NULL && symndx != -1, the addend of the relocation
81
       that should be added to the symbol value.  */
82
    bfd_vma addend;
83
    /* If abfd != NULL && symndx == -1, the hash table entry
84
       corresponding to a global symbol in the got (or, local, if
85
       h->forced_local).  */
86
    struct score_elf_link_hash_entry *h;
87
  } d;
88
89
  /* The offset from the beginning of the .got section to the entry
90
     corresponding to this symbol+addend.  If it's a global symbol
91
     whose offset is yet to be decided, it's going to be -1.  */
92
  long gotidx;
93
};
94
95
/* This structure is passed to score_elf_sort_hash_table_f when sorting
96
   the dynamic symbols.  */
97
98
struct score_elf_hash_sort_data
99
{
100
  /* The symbol in the global GOT with the lowest dynamic symbol table index.  */
101
  struct elf_link_hash_entry *low;
102
  /* The least dynamic symbol table index corresponding to a symbol with a GOT entry.  */
103
  long min_got_dynindx;
104
  /* The greatest dynamic symbol table index corresponding to a symbol
105
     with a GOT entry that is not referenced (e.g., a dynamic symbol
106
     with dynamic relocations pointing to it from non-primary GOTs).  */
107
  long max_unref_got_dynindx;
108
  /* The greatest dynamic symbol table index not corresponding to a
109
     symbol without a GOT entry.  */
110
  long max_non_got_dynindx;
111
};
112
113
struct score_got_info
114
{
115
  /* The global symbol in the GOT with the lowest index in the dynamic
116
     symbol table.  */
117
  struct elf_link_hash_entry *global_gotsym;
118
  /* The number of global .got entries.  */
119
  unsigned int global_gotno;
120
  /* The number of local .got entries.  */
121
  unsigned int local_gotno;
122
  /* The number of local .got entries we have used.  */
123
  unsigned int assigned_gotno;
124
  /* A hash table holding members of the got.  */
125
  struct htab *got_entries;
126
  /* In multi-got links, a pointer to the next got (err, rather, most
127
     of the time, it points to the previous got).  */
128
  struct score_got_info *next;
129
};
130
131
/* A structure used to count GOT entries, for GOT entry or ELF symbol table traversal.  */
132
struct _score_elf_section_data
133
{
134
  struct bfd_elf_section_data elf;
135
  union
136
  {
137
    struct score_got_info *got_info;
138
    bfd_byte *tdata;
139
  }
140
  u;
141
};
142
143
#define score_elf_section_data(sec) \
144
0
  ((struct _score_elf_section_data *) elf_section_data (sec))
145
146
/* The size of a symbol-table entry.  */
147
#define SCORE_ELF_SYM_SIZE(abfd)  \
148
0
  (get_elf_backend_data (abfd)->s->sizeof_sym)
149
150
/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
151
   from smaller values.  Start with zero, widen, *then* decrement.  */
152
0
#define MINUS_ONE (((bfd_vma)0) - 1)
153
0
#define MINUS_TWO (((bfd_vma)0) - 2)
154
155
0
#define PDR_SIZE 32
156
157
158
/* The number of local .got entries we reserve.  */
159
0
#define SCORE_RESERVED_GOTNO (2)
160
0
#define ELF_DYNAMIC_INTERPRETER     "/usr/lib/ld.so.1"
161
162
/* The offset of $gp from the beginning of the .got section.  */
163
0
#define ELF_SCORE_GP_OFFSET(abfd) (0x3ff0)
164
/* The maximum size of the GOT for it to be addressable using 15-bit offsets from $gp.  */
165
0
#define SCORE_ELF_GOT_MAX_SIZE(abfd) (ELF_SCORE_GP_OFFSET(abfd) + 0x3fff)
166
167
0
#define SCORE_ELF_STUB_SECTION_NAME  (".SCORE.stub")
168
0
#define SCORE_FUNCTION_STUB_SIZE (16)
169
170
0
#define STUB_LW      0xc3bcc010     /* lw r29, [r28, -0x3ff0]  */
171
0
#define STUB_MOVE    0x8363bc56     /* mv r27, r3  */
172
0
#define STUB_LI16    0x87548000     /* ori r26, .dynsym_index  */
173
0
#define STUB_BRL     0x801dbc09     /* brl r29  */
174
175
#define SCORE_ELF_GOT_SIZE(abfd)   \
176
0
  (get_elf_backend_data (abfd)->s->arch_size / 8)
177
178
#define SCORE_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
179
0
  (_bfd_elf_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
180
181
/* The size of an external dynamic table entry.  */
182
#define SCORE_ELF_DYN_SIZE(abfd) \
183
0
  (get_elf_backend_data (abfd)->s->sizeof_dyn)
184
185
/* The size of an external REL relocation.  */
186
#define SCORE_ELF_REL_SIZE(abfd) \
187
0
  (get_elf_backend_data (abfd)->s->sizeof_rel)
188
189
/* The default alignment for sections, as a power of two.  */
190
#define SCORE_ELF_LOG_FILE_ALIGN(abfd)\
191
0
  (get_elf_backend_data (abfd)->s->log_file_align)
192
193
static bfd_byte *hi16_rel_addr;
194
195
/* This will be used when we sort the dynamic relocation records.  */
196
static bfd *reldyn_sorting_bfd;
197
198
/* SCORE ELF uses two common sections.  One is the usual one, and the
199
   other is for small objects.  All the small objects are kept
200
   together, and then referenced via the gp pointer, which yields
201
   faster assembler code.  This is what we use for the small common
202
   section.  This approach is copied from ecoff.c.  */
203
static asection score_elf_scom_section;
204
static const asymbol score_elf_scom_symbol =
205
  GLOBAL_SYM_INIT (".scommon", &score_elf_scom_section);
206
static asection score_elf_scom_section =
207
  BFD_FAKE_SECTION (score_elf_scom_section, &score_elf_scom_symbol,
208
        ".scommon", 0, SEC_IS_COMMON | SEC_SMALL_DATA);
209
210
static bfd_vma
211
score_bfd_get_16 (bfd *abfd, const void *data)
212
0
{
213
0
  return bfd_get_16 (abfd, data);
214
0
}
215
216
static bfd_vma
217
score3_bfd_getl32 (const void *p)
218
0
{
219
0
  const bfd_byte *addr = p;
220
0
  unsigned long v;
221
222
0
  v = (unsigned long) addr[2];
223
0
  v |= (unsigned long) addr[3] << 8;
224
0
  v |= (unsigned long) addr[0] << 16;
225
0
  v |= (unsigned long) addr[1] << 24;
226
0
  return v;
227
0
}
228
229
static bfd_vma
230
score3_bfd_getl48 (const void *p)
231
0
{
232
0
  const bfd_byte *addr = p;
233
0
  uint64_t v;
234
235
0
  v = (uint64_t) addr[4];
236
0
  v |= (uint64_t) addr[5] << 8;
237
0
  v |= (uint64_t) addr[2] << 16;
238
0
  v |= (uint64_t) addr[3] << 24;
239
0
  v |= (uint64_t) addr[0] << 32;
240
0
  v |= (uint64_t) addr[1] << 40;
241
0
  return v;
242
0
}
243
244
static bfd_vma
245
score_bfd_get_32 (bfd *abfd, const void *data)
246
0
{
247
0
  if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
248
0
    return score3_bfd_getl32 (data);
249
0
  else
250
0
    return bfd_get_32 (abfd, data);
251
0
}
252
253
static bfd_vma
254
score_bfd_get_48 (bfd *abfd, const void *p)
255
0
{
256
0
  if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
257
0
    return score3_bfd_getl48 (p);
258
0
  else
259
0
    return bfd_get_bits (p, 48, 1);
260
0
}
261
262
static void
263
score_bfd_put_16 (bfd *abfd, bfd_vma addr, void *data)
264
0
{
265
0
  return bfd_put_16 (abfd, addr, data);
266
0
}
267
268
static void
269
score3_bfd_putl32 (bfd_vma data, void *p)
270
0
{
271
0
  bfd_byte *addr = p;
272
0
  addr[0] = (data >> 16) & 0xff;
273
0
  addr[1] = (data >> 24) & 0xff;
274
0
  addr[2] = data & 0xff;
275
0
  addr[3] = (data >>  8) & 0xff;
276
0
}
277
278
static void
279
score3_bfd_putl48 (bfd_vma data, void *p)
280
0
{
281
0
  bfd_byte *addr = p;
282
0
  addr[0] = (data >> 32) & 0xff;
283
0
  addr[1] = (data >> 40) & 0xff;
284
0
  addr[2] = (data >> 16) & 0xff;
285
0
  addr[3] = (data >> 24) & 0xff;
286
0
  addr[4] = data & 0xff;
287
0
  addr[5] = (data >>  8) & 0xff;
288
0
}
289
290
static void
291
score_bfd_put_32 (bfd *abfd, bfd_vma addr, void *data)
292
0
{
293
0
  if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
294
0
    return score3_bfd_putl32 (addr, data);
295
0
  else
296
0
    return bfd_put_32 (abfd, addr, data);
297
0
}
298
299
static void
300
score_bfd_put_48 (bfd *abfd, bfd_vma val, void *p)
301
0
{
302
0
  if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
303
0
    return score3_bfd_putl48 (val, p);
304
0
  else
305
0
    return bfd_put_bits (val, p, 48, 1);
306
0
}
307
308
static bfd_reloc_status_type
309
score_elf_hi16_reloc (bfd *abfd ATTRIBUTE_UNUSED,
310
          arelent *reloc_entry,
311
          asymbol *symbol ATTRIBUTE_UNUSED,
312
          void * data,
313
          asection *input_section ATTRIBUTE_UNUSED,
314
          bfd *output_bfd ATTRIBUTE_UNUSED,
315
          char **error_message ATTRIBUTE_UNUSED)
316
0
{
317
0
  hi16_rel_addr = (bfd_byte *) data + reloc_entry->address;
318
0
  return bfd_reloc_ok;
319
0
}
320
321
static bfd_reloc_status_type
322
score_elf_lo16_reloc (bfd *abfd,
323
          arelent *reloc_entry,
324
          asymbol *symbol ATTRIBUTE_UNUSED,
325
          void * data,
326
          asection *input_section,
327
          bfd *output_bfd ATTRIBUTE_UNUSED,
328
          char **error_message ATTRIBUTE_UNUSED)
329
0
{
330
0
  bfd_vma addend = 0, offset = 0;
331
0
  unsigned long val;
332
0
  unsigned long hi16_offset, hi16_value, uvalue;
333
334
0
  hi16_value = score_bfd_get_32 (abfd, hi16_rel_addr);
335
0
  hi16_offset = ((((hi16_value >> 16) & 0x3) << 15) | (hi16_value & 0x7fff)) >> 1;
336
0
  addend = score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
337
0
  offset = ((((addend >> 16) & 0x3) << 15) | (addend & 0x7fff)) >> 1;
338
0
  val = reloc_entry->addend;
339
0
  if (reloc_entry->address > input_section->size)
340
0
    return bfd_reloc_outofrange;
341
0
  uvalue = ((hi16_offset << 16) | (offset & 0xffff)) + val;
342
0
  hi16_offset = (uvalue >> 16) << 1;
343
0
  hi16_value = (hi16_value & ~0x37fff) | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
344
0
  score_bfd_put_32 (abfd, hi16_value, hi16_rel_addr);
345
0
  offset = (uvalue & 0xffff) << 1;
346
0
  addend = (addend & ~0x37fff) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
347
0
  score_bfd_put_32 (abfd, addend, (bfd_byte *) data + reloc_entry->address);
348
0
  return bfd_reloc_ok;
349
0
}
350
351
/* Set the GP value for OUTPUT_BFD.  Returns FALSE if this is a
352
   dangerous relocation.  */
353
354
static bool
355
score_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp)
356
0
{
357
0
  unsigned int count;
358
0
  asymbol **sym;
359
0
  unsigned int i;
360
361
  /* If we've already figured out what GP will be, just return it.  */
362
0
  *pgp = _bfd_get_gp_value (output_bfd);
363
0
  if (*pgp)
364
0
    return true;
365
366
0
  count = bfd_get_symcount (output_bfd);
367
0
  sym = bfd_get_outsymbols (output_bfd);
368
369
  /* The linker script will have created a symbol named `_gp' with the
370
     appropriate value.  */
371
0
  if (sym == NULL)
372
0
    i = count;
373
0
  else
374
0
    {
375
0
      for (i = 0; i < count; i++, sym++)
376
0
  {
377
0
    const char *name;
378
379
0
    name = bfd_asymbol_name (*sym);
380
0
    if (*name == '_' && strcmp (name, "_gp") == 0)
381
0
      {
382
0
        *pgp = bfd_asymbol_value (*sym);
383
0
        _bfd_set_gp_value (output_bfd, *pgp);
384
0
        break;
385
0
      }
386
0
  }
387
0
    }
388
389
0
  if (i >= count)
390
0
    {
391
      /* Only get the error once.  */
392
0
      *pgp = 4;
393
0
      _bfd_set_gp_value (output_bfd, *pgp);
394
0
      return false;
395
0
    }
396
397
0
  return true;
398
0
}
399
400
/* We have to figure out the gp value, so that we can adjust the
401
   symbol value correctly.  We look up the symbol _gp in the output
402
   BFD.  If we can't find it, we're stuck.  We cache it in the ELF
403
   target data.  We don't need to adjust the symbol value for an
404
   external symbol if we are producing relocatable output.  */
405
static bfd_reloc_status_type
406
score_elf_final_gp (bfd *output_bfd,
407
        asymbol *symbol,
408
        bool relocatable,
409
         char **error_message,
410
        bfd_vma *pgp)
411
0
{
412
0
  if (bfd_is_und_section (symbol->section)
413
0
      && ! relocatable)
414
0
    {
415
0
      *pgp = 0;
416
0
      return bfd_reloc_undefined;
417
0
    }
418
419
0
  *pgp = _bfd_get_gp_value (output_bfd);
420
0
  if (*pgp == 0
421
0
      && (! relocatable
422
0
    || (symbol->flags & BSF_SECTION_SYM) != 0))
423
0
    {
424
0
      if (relocatable)
425
0
  {
426
    /* Make up a value.  */
427
0
    *pgp = symbol->section->output_section->vma + 0x4000;
428
0
    _bfd_set_gp_value (output_bfd, *pgp);
429
0
  }
430
0
      else if (!score_elf_assign_gp (output_bfd, pgp))
431
0
  {
432
0
      *error_message =
433
0
        (char *) _("GP relative relocation when _gp not defined");
434
0
      return bfd_reloc_dangerous;
435
0
  }
436
0
    }
437
438
0
  return bfd_reloc_ok;
439
0
}
440
441
static bfd_reloc_status_type
442
score_elf_gprel15_with_gp (bfd *abfd,
443
         arelent *reloc_entry,
444
         asection *input_section,
445
         bool relocateable,
446
         void * data,
447
         bfd_vma gp ATTRIBUTE_UNUSED)
448
0
{
449
0
  unsigned long insn;
450
451
0
  if (reloc_entry->address > input_section->size)
452
0
    return bfd_reloc_outofrange;
453
454
0
  insn = score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
455
0
  if (((reloc_entry->addend & 0xffffc000) != 0)
456
0
      && ((reloc_entry->addend & 0xffffc000) != 0xffffc000))
457
0
    return bfd_reloc_overflow;
458
459
0
  insn = (insn & ~0x7fff) | (reloc_entry->addend & 0x7fff);
460
0
  score_bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
461
0
  if (relocateable)
462
0
    reloc_entry->address += input_section->output_offset;
463
464
0
  return bfd_reloc_ok;
465
0
}
466
467
static bfd_reloc_status_type
468
gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent *reloc_entry,
469
     asection *input_section, bool relocatable,
470
     void *data, bfd_vma gp)
471
0
{
472
0
  bfd_vma relocation;
473
0
  bfd_vma val;
474
475
0
  if (bfd_is_com_section (symbol->section))
476
0
    relocation = 0;
477
0
  else
478
0
    relocation = symbol->value;
479
480
0
  relocation += symbol->section->output_section->vma;
481
0
  relocation += symbol->section->output_offset;
482
483
0
  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
484
0
    return bfd_reloc_outofrange;
485
486
  /* Set val to the offset into the section or symbol.  */
487
0
  val = reloc_entry->addend;
488
489
0
  if (reloc_entry->howto->partial_inplace)
490
0
    val += score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
491
492
  /* Adjust val for the final section location and GP value.  If we
493
     are producing relocatable output, we don't want to do this for
494
     an external symbol.  */
495
0
  if (! relocatable
496
0
      || (symbol->flags & BSF_SECTION_SYM) != 0)
497
0
    val += relocation - gp;
498
499
0
  if (reloc_entry->howto->partial_inplace)
500
0
    score_bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
501
0
  else
502
0
    reloc_entry->addend = val;
503
504
0
  if (relocatable)
505
0
    reloc_entry->address += input_section->output_offset;
506
507
0
  return bfd_reloc_ok;
508
0
}
509
510
static bfd_reloc_status_type
511
score_elf_gprel15_reloc (bfd *abfd,
512
       arelent *reloc_entry,
513
       asymbol *symbol,
514
       void * data,
515
       asection *input_section,
516
       bfd *output_bfd,
517
       char **error_message)
518
0
{
519
0
  bool relocateable;
520
0
  bfd_reloc_status_type ret;
521
0
  bfd_vma gp;
522
523
0
  if (output_bfd != NULL
524
0
      && (symbol->flags & BSF_SECTION_SYM) == 0 && reloc_entry->addend == 0)
525
0
    {
526
0
      reloc_entry->address += input_section->output_offset;
527
0
      return bfd_reloc_ok;
528
0
    }
529
0
  if (output_bfd != NULL)
530
0
    relocateable = true;
531
0
  else
532
0
    {
533
0
      relocateable = false;
534
0
      output_bfd = symbol->section->output_section->owner;
535
0
    }
536
537
0
  ret = score_elf_final_gp (output_bfd, symbol, relocateable, error_message, &gp);
538
0
  if (ret != bfd_reloc_ok)
539
0
    return ret;
540
541
0
  return score_elf_gprel15_with_gp (abfd, reloc_entry,
542
0
            input_section, relocateable, data, gp);
543
0
}
544
545
/* Do a R_SCORE_GPREL32 relocation.  This is a 32 bit value which must
546
   become the offset from the gp register.  */
547
548
static bfd_reloc_status_type
549
score_elf_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
550
      void *data, asection *input_section, bfd *output_bfd,
551
      char **error_message)
552
0
{
553
0
  bool relocatable;
554
0
  bfd_reloc_status_type ret;
555
0
  bfd_vma gp;
556
557
  /* R_SCORE_GPREL32 relocations are defined for local symbols only.  */
558
0
  if (output_bfd != NULL
559
0
      && (symbol->flags & BSF_SECTION_SYM) == 0
560
0
      && (symbol->flags & BSF_LOCAL) != 0)
561
0
    {
562
0
      *error_message = (char *)
563
0
  _("32bits gp relative relocation occurs for an external symbol");
564
0
      return bfd_reloc_outofrange;
565
0
    }
566
567
0
  if (output_bfd != NULL)
568
0
    relocatable = true;
569
0
  else
570
0
    {
571
0
      relocatable = false;
572
0
      output_bfd = symbol->section->output_section->owner;
573
0
    }
574
575
0
  ret = score_elf_final_gp (output_bfd, symbol, relocatable, error_message, &gp);
576
0
  if (ret != bfd_reloc_ok)
577
0
    return ret;
578
579
0
  gp = 0;
580
0
  return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
581
0
        relocatable, data, gp);
582
0
}
583
584
/* A howto special_function for R_SCORE_GOT15 relocations.  This is just
585
   like any other 16-bit relocation when applied to global symbols, but is
586
   treated in the same as R_SCORE_HI16 when applied to local symbols.  */
587
static bfd_reloc_status_type
588
score_elf_got15_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
589
           void *data, asection *input_section,
590
           bfd *output_bfd, char **error_message)
591
0
{
592
0
  if ((symbol->flags & (BSF_GLOBAL | BSF_WEAK)) != 0
593
0
      || bfd_is_und_section (bfd_asymbol_section (symbol))
594
0
      || bfd_is_com_section (bfd_asymbol_section (symbol)))
595
    /* The relocation is against a global symbol.  */
596
0
    return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
597
0
          input_section, output_bfd,
598
0
          error_message);
599
600
0
  return score_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
601
0
             input_section, output_bfd, error_message);
602
0
}
603
604
static bfd_reloc_status_type
605
score_elf_got_lo16_reloc (bfd *abfd,
606
        arelent *reloc_entry,
607
        asymbol *symbol ATTRIBUTE_UNUSED,
608
        void * data,
609
        asection *input_section,
610
        bfd *output_bfd ATTRIBUTE_UNUSED,
611
        char **error_message ATTRIBUTE_UNUSED)
612
0
{
613
0
  bfd_vma addend = 0, offset = 0;
614
0
  signed long val;
615
0
  signed long hi16_offset, hi16_value, uvalue;
616
617
0
  hi16_value = score_bfd_get_32 (abfd, hi16_rel_addr);
618
0
  hi16_offset = ((((hi16_value >> 16) & 0x3) << 15) | (hi16_value & 0x7fff)) >> 1;
619
0
  addend = score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
620
0
  offset = ((((addend >> 16) & 0x3) << 15) | (addend & 0x7fff)) >> 1;
621
0
  val = reloc_entry->addend;
622
0
  if (reloc_entry->address > input_section->size)
623
0
    return bfd_reloc_outofrange;
624
0
  uvalue = ((hi16_offset << 16) | (offset & 0xffff)) + val;
625
0
  if ((uvalue > -0x8000) && (uvalue < 0x7fff))
626
0
    hi16_offset = 0;
627
0
  else
628
0
    hi16_offset = (uvalue >> 16) & 0x7fff;
629
0
  hi16_value = (hi16_value & ~0x37fff) | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
630
0
  score_bfd_put_32 (abfd, hi16_value, hi16_rel_addr);
631
0
  offset = (uvalue & 0xffff) << 1;
632
0
  addend = (addend & ~0x37fff) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
633
0
  score_bfd_put_32 (abfd, addend, (bfd_byte *) data + reloc_entry->address);
634
0
  return bfd_reloc_ok;
635
0
}
636
637
static reloc_howto_type elf32_score_howto_table[] =
638
{
639
  /* No relocation.  */
640
  HOWTO (R_SCORE_NONE,    /* type */
641
   0,     /* rightshift */
642
   0,     /* size */
643
   0,     /* bitsize */
644
   false,     /* pc_relative */
645
   0,     /* bitpos */
646
   complain_overflow_dont,/* complain_on_overflow */
647
   bfd_elf_generic_reloc, /* special_function */
648
   "R_SCORE_NONE",  /* name */
649
   false,     /* partial_inplace */
650
   0,     /* src_mask */
651
   0,     /* dst_mask */
652
   false),    /* pcrel_offset */
653
654
  /* R_SCORE_HI16 */
655
  HOWTO (R_SCORE_HI16,    /* type */
656
   0,     /* rightshift */
657
   4,     /* size */
658
   16,      /* bitsize */
659
   false,     /* pc_relative */
660
   1,     /* bitpos */
661
   complain_overflow_dont,/* complain_on_overflow */
662
   score_elf_hi16_reloc,  /* special_function */
663
   "R_SCORE_HI16",  /* name */
664
   true,      /* partial_inplace */
665
   0x37fff,   /* src_mask */
666
   0x37fff,   /* dst_mask */
667
   false),    /* pcrel_offset */
668
669
  /* R_SCORE_LO16 */
670
  HOWTO (R_SCORE_LO16,    /* type */
671
   0,     /* rightshift */
672
   4,     /* size */
673
   16,      /* bitsize */
674
   false,     /* pc_relative */
675
   1,     /* bitpos */
676
   complain_overflow_dont,/* complain_on_overflow */
677
   score_elf_lo16_reloc,  /* special_function */
678
   "R_SCORE_LO16",  /* name */
679
   true,      /* partial_inplace */
680
   0x37fff,   /* src_mask */
681
   0x37fff,   /* dst_mask */
682
   false),    /* pcrel_offset */
683
684
  /*  R_SCORE_BCMP */
685
  HOWTO (R_SCORE_BCMP,    /* type */
686
   1,     /* rightshift */
687
   4,     /* size */
688
   16,      /* bitsize */
689
   true,      /* pc_relative */
690
   1,     /* bitpos */
691
   complain_overflow_dont,/* complain_on_overflow */
692
   bfd_elf_generic_reloc, /* special_function */
693
   "R_SCORE_BCMP",  /* name */
694
   false,     /* partial_inplace */
695
   0x03e00381,    /* src_mask */
696
   0x03e00381,    /* dst_mask */
697
   false),    /* pcrel_offset */
698
699
  /*R_SCORE_24 */
700
  HOWTO (R_SCORE_24,    /* type */
701
   1,     /* rightshift */
702
   4,     /* size */
703
   24,      /* bitsize */
704
   false,     /* pc_relative */
705
   1,     /* bitpos */
706
   complain_overflow_dont,/* complain_on_overflow */
707
   bfd_elf_generic_reloc, /* special_function */
708
   "R_SCORE_24",    /* name */
709
   false,     /* partial_inplace */
710
   0x3ff7fff,   /* src_mask */
711
   0x3ff7fff,   /* dst_mask */
712
   false),    /* pcrel_offset */
713
714
  /*R_SCORE_PC19 */
715
  HOWTO (R_SCORE_PC19,    /* type */
716
   1,     /* rightshift */
717
   4,     /* size */
718
   19,      /* bitsize */
719
   true,      /* pc_relative */
720
   1,     /* bitpos */
721
   complain_overflow_dont,/* complain_on_overflow */
722
   bfd_elf_generic_reloc, /* special_function */
723
   "R_SCORE_PC19",  /* name */
724
   false,     /* partial_inplace */
725
   0x3ff03fe,   /* src_mask */
726
   0x3ff03fe,   /* dst_mask */
727
   false),    /* pcrel_offset */
728
729
  /*R_SCORE16_11 */
730
  HOWTO (R_SCORE16_11,    /* type */
731
   1,     /* rightshift */
732
   2,     /* size */
733
   11,      /* bitsize */
734
   false,     /* pc_relative */
735
   1,     /* bitpos */
736
   complain_overflow_dont,/* complain_on_overflow */
737
   bfd_elf_generic_reloc, /* special_function */
738
   "R_SCORE16_11",  /* name */
739
   false,     /* partial_inplace */
740
   0x000000ffe,   /* src_mask */
741
   0x000000ffe,   /* dst_mask */
742
   false),    /* pcrel_offset */
743
744
  /* R_SCORE16_PC8 */
745
  HOWTO (R_SCORE16_PC8,   /* type */
746
   1,     /* rightshift */
747
   2,     /* size */
748
   9,     /* bitsize */
749
   true,      /* pc_relative */
750
   0,     /* bitpos */
751
   complain_overflow_dont,/* complain_on_overflow */
752
   bfd_elf_generic_reloc, /* special_function */
753
   "R_SCORE16_PC8", /* name */
754
   false,     /* partial_inplace */
755
   0x000001ff,    /* src_mask */
756
   0x000001ff,    /* dst_mask */
757
   false),    /* pcrel_offset */
758
759
  /* 32 bit absolute */
760
  HOWTO (R_SCORE_ABS32,   /* type  8 */
761
   0,     /* rightshift */
762
   4,     /* size */
763
   32,      /* bitsize */
764
   false,     /* pc_relative */
765
   0,     /* bitpos */
766
   complain_overflow_bitfield,  /* complain_on_overflow */
767
   bfd_elf_generic_reloc, /* special_function */
768
   "R_SCORE_ABS32", /* name */
769
   false,     /* partial_inplace */
770
   0xffffffff,    /* src_mask */
771
   0xffffffff,    /* dst_mask */
772
   false),    /* pcrel_offset */
773
774
  /* 16 bit absolute */
775
  HOWTO (R_SCORE_ABS16,   /* type 11 */
776
   0,     /* rightshift */
777
   2,     /* size */
778
   16,      /* bitsize */
779
   false,     /* pc_relative */
780
   0,     /* bitpos */
781
   complain_overflow_bitfield,  /* complain_on_overflow */
782
   bfd_elf_generic_reloc, /* special_function */
783
   "R_SCORE_ABS16", /* name */
784
   false,     /* partial_inplace */
785
   0x0000ffff,    /* src_mask */
786
   0x0000ffff,    /* dst_mask */
787
   false),    /* pcrel_offset */
788
789
  /* R_SCORE_DUMMY2 */
790
  HOWTO (R_SCORE_DUMMY2,  /* type */
791
   0,     /* rightshift */
792
   4,     /* size */
793
   16,      /* bitsize */
794
   false,     /* pc_relative */
795
   0,     /* bitpos */
796
   complain_overflow_dont,/* complain_on_overflow */
797
   bfd_elf_generic_reloc, /* special_function */
798
   "R_SCORE_DUMMY2",  /* name */
799
   true,      /* partial_inplace */
800
   0x00007fff,    /* src_mask */
801
   0x00007fff,    /* dst_mask */
802
   false),    /* pcrel_offset */
803
804
  /* R_SCORE_GP15 */
805
  HOWTO (R_SCORE_GP15,    /* type */
806
   0,     /* rightshift */
807
   4,     /* size */
808
   16,      /* bitsize */
809
   false,     /* pc_relative */
810
   0,     /* bitpos */
811
   complain_overflow_dont,/* complain_on_overflow */
812
   score_elf_gprel15_reloc,/* special_function */
813
   "R_SCORE_GP15",  /* name */
814
   true,      /* partial_inplace */
815
   0x00007fff,    /* src_mask */
816
   0x00007fff,    /* dst_mask */
817
   false),    /* pcrel_offset */
818
819
  /* GNU extension to record C++ vtable hierarchy.  */
820
  HOWTO (R_SCORE_GNU_VTINHERIT, /* type */
821
   0,     /* rightshift */
822
   4,     /* size */
823
   0,     /* bitsize */
824
   false,     /* pc_relative */
825
   0,     /* bitpos */
826
   complain_overflow_dont,/* complain_on_overflow */
827
   NULL,      /* special_function */
828
   "R_SCORE_GNU_VTINHERIT", /* name */
829
   false,     /* partial_inplace */
830
   0,     /* src_mask */
831
   0,     /* dst_mask */
832
   false),    /* pcrel_offset */
833
834
  /* GNU extension to record C++ vtable member usage */
835
  HOWTO (R_SCORE_GNU_VTENTRY, /* type */
836
   0,     /* rightshift */
837
   4,     /* size */
838
   0,     /* bitsize */
839
   false,     /* pc_relative */
840
   0,     /* bitpos */
841
   complain_overflow_dont,/* complain_on_overflow */
842
   _bfd_elf_rel_vtable_reloc_fn,  /* special_function */
843
   "R_SCORE_GNU_VTENTRY", /* name */
844
   false,     /* partial_inplace */
845
   0,     /* src_mask */
846
   0,     /* dst_mask */
847
   false),    /* pcrel_offset */
848
849
  /* Reference to global offset table.  */
850
  HOWTO (R_SCORE_GOT15,   /* type */
851
   0,     /* rightshift */
852
   4,     /* size */
853
   16,      /* bitsize */
854
   false,     /* pc_relative */
855
   0,     /* bitpos */
856
   complain_overflow_signed,  /* complain_on_overflow */
857
   score_elf_got15_reloc, /* special_function */
858
   "R_SCORE_GOT15", /* name */
859
   true,      /* partial_inplace */
860
   0x00007fff,    /* src_mask */
861
   0x00007fff,    /* dst_mask */
862
   false),    /* pcrel_offset */
863
864
  /* Low 16 bits of displacement in global offset table.  */
865
  HOWTO (R_SCORE_GOT_LO16,  /* type */
866
   0,     /* rightshift */
867
   4,     /* size */
868
   16,      /* bitsize */
869
   false,     /* pc_relative */
870
   1,     /* bitpos */
871
   complain_overflow_dont,/* complain_on_overflow */
872
   score_elf_got_lo16_reloc, /* special_function */
873
   "R_SCORE_GOT_LO16",  /* name */
874
   true,      /* partial_inplace */
875
   0x37ffe,   /* src_mask */
876
   0x37ffe,   /* dst_mask */
877
   false),    /* pcrel_offset */
878
879
  /* 15 bit call through global offset table.  */
880
  HOWTO (R_SCORE_CALL15,  /* type */
881
   0,     /* rightshift */
882
   4,     /* size */
883
   16,      /* bitsize */
884
   false,     /* pc_relative */
885
   0,     /* bitpos */
886
   complain_overflow_signed, /* complain_on_overflow */
887
   bfd_elf_generic_reloc, /* special_function */
888
   "R_SCORE_CALL15",  /* name */
889
   true,      /* partial_inplace */
890
   0x0000ffff,    /* src_mask */
891
   0x0000ffff,    /* dst_mask */
892
   false),    /* pcrel_offset */
893
894
  /* 32 bit GP relative reference.  */
895
  HOWTO (R_SCORE_GPREL32, /* type */
896
   0,     /* rightshift */
897
   4,     /* size */
898
   32,      /* bitsize */
899
   false,     /* pc_relative */
900
   0,     /* bitpos */
901
   complain_overflow_dont,/* complain_on_overflow */
902
   score_elf_gprel32_reloc, /* special_function */
903
   "R_SCORE_GPREL32", /* name */
904
   true,      /* partial_inplace */
905
   0xffffffff,    /* src_mask */
906
   0xffffffff,    /* dst_mask */
907
   false),    /* pcrel_offset */
908
909
  /* 32 bit symbol relative relocation.  */
910
  HOWTO (R_SCORE_REL32,   /* type */
911
   0,     /* rightshift */
912
   4,     /* size */
913
   32,      /* bitsize */
914
   false,     /* pc_relative */
915
   0,     /* bitpos */
916
   complain_overflow_dont,/* complain_on_overflow */
917
   bfd_elf_generic_reloc, /* special_function */
918
   "R_SCORE_REL32", /* name */
919
   true,      /* partial_inplace */
920
   0xffffffff,    /* src_mask */
921
   0xffffffff,    /* dst_mask */
922
   false),    /* pcrel_offset */
923
924
  /* R_SCORE_DUMMY_HI16 */
925
  HOWTO (R_SCORE_DUMMY_HI16,  /* type */
926
   0,     /* rightshift */
927
   4,     /* size */
928
   16,      /* bitsize */
929
   false,     /* pc_relative */
930
   1,     /* bitpos */
931
   complain_overflow_dont,/* complain_on_overflow */
932
   score_elf_hi16_reloc,  /* special_function */
933
   "R_SCORE_DUMMY_HI16",  /* name */
934
   true,      /* partial_inplace */
935
   0x37fff,   /* src_mask */
936
   0x37fff,   /* dst_mask */
937
   false),    /* pcrel_offset */
938
939
  /* R_SCORE_IMM30 */
940
  HOWTO (R_SCORE_IMM30,   /* type */
941
   2,     /* rightshift */
942
   4,     /* size */
943
   30,      /* bitsize */
944
   false,     /* pc_relative */
945
   7,     /* bitpos */
946
   complain_overflow_dont,/* complain_on_overflow */
947
   bfd_elf_generic_reloc, /* special_function */
948
   "R_SCORE_IMM30", /* name */
949
   false,     /* partial_inplace */
950
   0x7f7fff7f80LL,  /* src_mask */
951
   0x7f7fff7f80LL,  /* dst_mask */
952
   false),    /* pcrel_offset */
953
954
  /* R_SCORE_IMM32 */
955
  HOWTO (R_SCORE_IMM32,   /* type */
956
   0,     /* rightshift */
957
   4,     /* size */
958
   32,      /* bitsize */
959
   false,     /* pc_relative */
960
   5,     /* bitpos */
961
   complain_overflow_dont,/* complain_on_overflow */
962
   bfd_elf_generic_reloc, /* special_function */
963
   "R_SCORE_IMM32", /* name */
964
   false,     /* partial_inplace */
965
   0x7f7fff7fe0LL,  /* src_mask */
966
   0x7f7fff7fe0LL,  /* dst_mask */
967
   false),    /* pcrel_offset */
968
};
969
970
struct score_reloc_map
971
{
972
  bfd_reloc_code_real_type bfd_reloc_val;
973
  unsigned char elf_reloc_val;
974
};
975
976
static const struct score_reloc_map elf32_score_reloc_map[] =
977
{
978
  {BFD_RELOC_NONE,     R_SCORE_NONE},
979
  {BFD_RELOC_HI16_S,     R_SCORE_HI16},
980
  {BFD_RELOC_LO16,     R_SCORE_LO16},
981
  {BFD_RELOC_SCORE_BCMP,   R_SCORE_BCMP},
982
  {BFD_RELOC_SCORE_JMP,    R_SCORE_24},
983
  {BFD_RELOC_SCORE_BRANCH,   R_SCORE_PC19},
984
  {BFD_RELOC_SCORE16_JMP,  R_SCORE16_11},
985
  {BFD_RELOC_SCORE16_BRANCH,   R_SCORE16_PC8},
986
  {BFD_RELOC_32,     R_SCORE_ABS32},
987
  {BFD_RELOC_16,     R_SCORE_ABS16},
988
  {BFD_RELOC_SCORE_DUMMY2,   R_SCORE_DUMMY2},
989
  {BFD_RELOC_SCORE_GPREL15,  R_SCORE_GP15},
990
  {BFD_RELOC_VTABLE_INHERIT,   R_SCORE_GNU_VTINHERIT},
991
  {BFD_RELOC_VTABLE_ENTRY,   R_SCORE_GNU_VTENTRY},
992
  {BFD_RELOC_SCORE_GOT15,  R_SCORE_GOT15},
993
  {BFD_RELOC_SCORE_GOT_LO16,   R_SCORE_GOT_LO16},
994
  {BFD_RELOC_SCORE_CALL15,   R_SCORE_CALL15},
995
  {BFD_RELOC_GPREL32,    R_SCORE_GPREL32},
996
  {BFD_RELOC_32_PCREL,     R_SCORE_REL32},
997
  {BFD_RELOC_SCORE_DUMMY_HI16,   R_SCORE_DUMMY_HI16},
998
  {BFD_RELOC_SCORE_IMM30,  R_SCORE_IMM30},
999
  {BFD_RELOC_SCORE_IMM32,  R_SCORE_IMM32},
1000
};
1001
1002
/* got_entries only match if they're identical, except for gotidx, so
1003
   use all fields to compute the hash, and compare the appropriate
1004
   union members.  */
1005
static hashval_t
1006
score_elf_got_entry_hash (const void *entry_)
1007
0
{
1008
0
  const struct score_got_entry *entry = (struct score_got_entry *)entry_;
1009
1010
0
  return entry->symndx
1011
0
    + (!entry->abfd ? entry->d.address : entry->abfd->id);
1012
0
}
1013
1014
static int
1015
score_elf_got_entry_eq (const void *entry1, const void *entry2)
1016
0
{
1017
0
  const struct score_got_entry *e1 = (struct score_got_entry *)entry1;
1018
0
  const struct score_got_entry *e2 = (struct score_got_entry *)entry2;
1019
1020
0
  return e1->abfd == e2->abfd && e1->symndx == e2->symndx
1021
0
    && (! e1->abfd ? e1->d.address == e2->d.address
1022
0
  : e1->symndx >= 0 ? e1->d.addend == e2->d.addend
1023
0
  : e1->d.h == e2->d.h);
1024
0
}
1025
1026
/* If H needs a GOT entry, assign it the highest available dynamic
1027
   index.  Otherwise, assign it the lowest available dynamic
1028
   index.  */
1029
static bool
1030
score_elf_sort_hash_table_f (struct score_elf_link_hash_entry *h, void *data)
1031
0
{
1032
0
  struct score_elf_hash_sort_data *hsd = data;
1033
1034
  /* Symbols without dynamic symbol table entries aren't interesting at all.  */
1035
0
  if (h->root.dynindx == -1)
1036
0
    return true;
1037
1038
  /* Global symbols that need GOT entries that are not explicitly
1039
     referenced are marked with got offset 2.  Those that are
1040
     referenced get a 1, and those that don't need GOT entries get
1041
     -1.  */
1042
0
  if (h->root.got.offset == 2)
1043
0
    {
1044
0
      if (hsd->max_unref_got_dynindx == hsd->min_got_dynindx)
1045
0
  hsd->low = (struct elf_link_hash_entry *) h;
1046
0
      h->root.dynindx = hsd->max_unref_got_dynindx++;
1047
0
    }
1048
0
  else if (h->root.got.offset != 1)
1049
0
    h->root.dynindx = hsd->max_non_got_dynindx++;
1050
0
  else
1051
0
    {
1052
0
      h->root.dynindx = --hsd->min_got_dynindx;
1053
0
      hsd->low = (struct elf_link_hash_entry *) h;
1054
0
    }
1055
1056
0
  return true;
1057
0
}
1058
1059
static asection *
1060
score_elf_got_section (bfd *abfd, bool maybe_excluded)
1061
0
{
1062
0
  asection *sgot = bfd_get_linker_section (abfd, ".got");
1063
1064
0
  if (sgot == NULL || (! maybe_excluded && (sgot->flags & SEC_EXCLUDE) != 0))
1065
0
    return NULL;
1066
0
  return sgot;
1067
0
}
1068
1069
/* Returns the GOT information associated with the link indicated by
1070
   INFO.  If SGOTP is non-NULL, it is filled in with the GOT section.  */
1071
static struct score_got_info *
1072
score_elf_got_info (bfd *abfd, asection **sgotp)
1073
0
{
1074
0
  asection *sgot;
1075
0
  struct score_got_info *g;
1076
1077
0
  sgot = score_elf_got_section (abfd, true);
1078
0
  BFD_ASSERT (sgot != NULL);
1079
0
  BFD_ASSERT (elf_section_data (sgot) != NULL);
1080
0
  g = score_elf_section_data (sgot)->u.got_info;
1081
0
  BFD_ASSERT (g != NULL);
1082
1083
0
  if (sgotp)
1084
0
    *sgotp = sgot;
1085
0
  return g;
1086
0
}
1087
1088
/* Sort the dynamic symbol table so that symbols that need GOT entries
1089
   appear towards the end.  This reduces the amount of GOT space
1090
   required.  MAX_LOCAL is used to set the number of local symbols
1091
   known to be in the dynamic symbol table.  During
1092
   s3_bfd_score_elf_late_size_sections, this value is 1.  Afterward, the
1093
   section symbols are added and the count is higher.  */
1094
static bool
1095
score_elf_sort_hash_table (struct bfd_link_info *info,
1096
         unsigned long max_local)
1097
0
{
1098
0
  struct score_elf_hash_sort_data hsd;
1099
0
  struct score_got_info *g;
1100
0
  bfd *dynobj;
1101
1102
0
  dynobj = elf_hash_table (info)->dynobj;
1103
1104
0
  g = score_elf_got_info (dynobj, NULL);
1105
1106
0
  hsd.low = NULL;
1107
0
  hsd.max_unref_got_dynindx =
1108
0
    hsd.min_got_dynindx = elf_hash_table (info)->dynsymcount
1109
    /* In the multi-got case, assigned_gotno of the master got_info
1110
       indicate the number of entries that aren't referenced in the
1111
       primary GOT, but that must have entries because there are
1112
       dynamic relocations that reference it.  Since they aren't
1113
       referenced, we move them to the end of the GOT, so that they
1114
       don't prevent other entries that are referenced from getting
1115
       too large offsets.  */
1116
0
    - (g->next ? g->assigned_gotno : 0);
1117
0
  hsd.max_non_got_dynindx = max_local;
1118
0
  score_elf_link_hash_traverse (elf_hash_table (info),
1119
0
        score_elf_sort_hash_table_f,
1120
0
        &hsd);
1121
1122
  /* There should have been enough room in the symbol table to
1123
     accommodate both the GOT and non-GOT symbols.  */
1124
0
  BFD_ASSERT (hsd.max_non_got_dynindx <= hsd.min_got_dynindx);
1125
0
  BFD_ASSERT ((unsigned long)hsd.max_unref_got_dynindx
1126
0
        <= elf_hash_table (info)->dynsymcount);
1127
1128
  /* Now we know which dynamic symbol has the lowest dynamic symbol
1129
     table index in the GOT.  */
1130
0
  g->global_gotsym = hsd.low;
1131
1132
0
  return true;
1133
0
}
1134
1135
/* Create an entry in an score ELF linker hash table.  */
1136
1137
static struct bfd_hash_entry *
1138
score_elf_link_hash_newfunc (struct bfd_hash_entry *entry,
1139
           struct bfd_hash_table *table,
1140
           const char *string)
1141
0
{
1142
0
  struct score_elf_link_hash_entry *ret = (struct score_elf_link_hash_entry *) entry;
1143
1144
  /* Allocate the structure if it has not already been allocated by a subclass.  */
1145
0
  if (ret == NULL)
1146
0
    ret = bfd_hash_allocate (table, sizeof (struct score_elf_link_hash_entry));
1147
0
  if (ret == NULL)
1148
0
    return (struct bfd_hash_entry *) ret;
1149
1150
  /* Call the allocation method of the superclass.  */
1151
0
  ret = ((struct score_elf_link_hash_entry *)
1152
0
   _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, table, string));
1153
1154
0
  if (ret != NULL)
1155
0
    {
1156
0
      ret->possibly_dynamic_relocs = 0;
1157
0
      ret->readonly_reloc = false;
1158
0
      ret->no_fn_stub = false;
1159
0
      ret->forced_local = false;
1160
0
    }
1161
1162
0
  return (struct bfd_hash_entry *) ret;
1163
0
}
1164
1165
/* Returns the first relocation of type r_type found, beginning with
1166
   RELOCATION.  RELEND is one-past-the-end of the relocation table.  */
1167
static const Elf_Internal_Rela *
1168
score_elf_next_relocation (bfd *abfd ATTRIBUTE_UNUSED, unsigned int r_type,
1169
          const Elf_Internal_Rela *relocation,
1170
         const Elf_Internal_Rela *relend)
1171
0
{
1172
0
  while (relocation < relend)
1173
0
    {
1174
0
      if (ELF32_R_TYPE (relocation->r_info) == r_type)
1175
0
  return relocation;
1176
1177
0
      ++relocation;
1178
0
    }
1179
1180
  /* We didn't find it.  */
1181
0
  bfd_set_error (bfd_error_bad_value);
1182
0
  return NULL;
1183
0
}
1184
1185
/* This function is called via qsort() to sort the dynamic relocation
1186
   entries by increasing r_symndx value.  */
1187
static int
1188
score_elf_sort_dynamic_relocs (const void *arg1, const void *arg2)
1189
0
{
1190
0
  Elf_Internal_Rela int_reloc1;
1191
0
  Elf_Internal_Rela int_reloc2;
1192
1193
0
  bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, arg1, &int_reloc1);
1194
0
  bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, arg2, &int_reloc2);
1195
1196
0
  return (ELF32_R_SYM (int_reloc1.r_info) - ELF32_R_SYM (int_reloc2.r_info));
1197
0
}
1198
1199
/* Return whether a relocation is against a local symbol.  */
1200
static bool
1201
score_elf_local_relocation_p (bfd *input_bfd,
1202
            const Elf_Internal_Rela *relocation,
1203
            asection **local_sections,
1204
            bool check_forced)
1205
0
{
1206
0
  unsigned long r_symndx;
1207
0
  Elf_Internal_Shdr *symtab_hdr;
1208
0
  struct score_elf_link_hash_entry *h;
1209
0
  size_t extsymoff;
1210
1211
0
  r_symndx = ELF32_R_SYM (relocation->r_info);
1212
0
  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
1213
0
  extsymoff = (elf_bad_symtab (input_bfd)) ? 0 : symtab_hdr->sh_info;
1214
1215
0
  if (r_symndx < extsymoff)
1216
0
    return true;
1217
0
  if (elf_bad_symtab (input_bfd) && local_sections[r_symndx] != NULL)
1218
0
    return true;
1219
1220
0
  if (check_forced)
1221
0
    {
1222
      /* Look up the hash table to check whether the symbol was forced local.  */
1223
0
      h = (struct score_elf_link_hash_entry *)
1224
0
  elf_sym_hashes (input_bfd) [r_symndx - extsymoff];
1225
      /* Find the real hash-table entry for this symbol.  */
1226
0
      while (h->root.root.type == bfd_link_hash_indirect
1227
0
       || h->root.root.type == bfd_link_hash_warning)
1228
0
  h = (struct score_elf_link_hash_entry *) h->root.root.u.i.link;
1229
0
      if (h->root.forced_local)
1230
0
  return true;
1231
0
    }
1232
1233
0
  return false;
1234
0
}
1235
1236
/* Returns the dynamic relocation section for DYNOBJ.  */
1237
static asection *
1238
score_elf_rel_dyn_section (bfd *dynobj, bool create_p)
1239
0
{
1240
0
  static const char dname[] = ".rel.dyn";
1241
0
  asection *sreloc;
1242
1243
0
  sreloc = bfd_get_linker_section (dynobj, dname);
1244
0
  if (sreloc == NULL && create_p)
1245
0
    {
1246
0
      sreloc = bfd_make_section_anyway_with_flags (dynobj, dname,
1247
0
               (SEC_ALLOC
1248
0
                | SEC_LOAD
1249
0
                | SEC_HAS_CONTENTS
1250
0
                | SEC_IN_MEMORY
1251
0
                | SEC_LINKER_CREATED
1252
0
                | SEC_READONLY));
1253
0
      if (sreloc == NULL
1254
0
    || !bfd_set_section_alignment (sreloc,
1255
0
           SCORE_ELF_LOG_FILE_ALIGN (dynobj)))
1256
0
  return NULL;
1257
0
    }
1258
0
  return sreloc;
1259
0
}
1260
1261
static void
1262
score_elf_allocate_dynamic_relocations (bfd *abfd, unsigned int n)
1263
0
{
1264
0
  asection *s;
1265
1266
0
  s = score_elf_rel_dyn_section (abfd, false);
1267
0
  BFD_ASSERT (s != NULL);
1268
1269
0
  if (s->size == 0)
1270
0
    {
1271
      /* Make room for a null element.  */
1272
0
      s->size += SCORE_ELF_REL_SIZE (abfd);
1273
0
      ++s->reloc_count;
1274
0
    }
1275
0
  s->size += n * SCORE_ELF_REL_SIZE (abfd);
1276
0
}
1277
1278
/* Create a rel.dyn relocation for the dynamic linker to resolve.  REL
1279
   is the original relocation, which is now being transformed into a
1280
   dynamic relocation.  The ADDENDP is adjusted if necessary; the
1281
   caller should store the result in place of the original addend.  */
1282
static bool
1283
score_elf_create_dynamic_relocation (bfd *output_bfd,
1284
             struct bfd_link_info *info,
1285
             const Elf_Internal_Rela *rel,
1286
             struct score_elf_link_hash_entry *h,
1287
             bfd_vma symbol,
1288
             bfd_vma *addendp, asection *input_section)
1289
0
{
1290
0
  Elf_Internal_Rela outrel;
1291
0
  asection *sreloc;
1292
0
  bfd *dynobj;
1293
0
  int r_type;
1294
0
  long indx;
1295
0
  bool defined_p;
1296
1297
0
  r_type = ELF32_R_TYPE (rel->r_info);
1298
0
  dynobj = elf_hash_table (info)->dynobj;
1299
0
  sreloc = score_elf_rel_dyn_section (dynobj, false);
1300
0
  BFD_ASSERT (sreloc != NULL);
1301
0
  BFD_ASSERT (sreloc->contents != NULL);
1302
0
  BFD_ASSERT (sreloc->reloc_count * SCORE_ELF_REL_SIZE (output_bfd) < sreloc->size);
1303
1304
0
  outrel.r_offset =
1305
0
    _bfd_elf_section_offset (output_bfd, info, input_section, rel->r_offset);
1306
1307
0
  if (outrel.r_offset == MINUS_ONE)
1308
    /* The relocation field has been deleted.  */
1309
0
    return true;
1310
1311
0
  if (outrel.r_offset == MINUS_TWO)
1312
0
    {
1313
      /* The relocation field has been converted into a relative value of
1314
   some sort.  Functions like _bfd_elf_write_section_eh_frame expect
1315
   the field to be fully relocated, so add in the symbol's value.  */
1316
0
      *addendp += symbol;
1317
0
      return true;
1318
0
    }
1319
1320
  /* We must now calculate the dynamic symbol table index to use
1321
     in the relocation.  */
1322
0
  if (h != NULL
1323
0
      && (! info->symbolic || !h->root.def_regular)
1324
      /* h->root.dynindx may be -1 if this symbol was marked to
1325
   become local.  */
1326
0
      && h->root.dynindx != -1)
1327
0
    {
1328
0
      indx = h->root.dynindx;
1329
  /* ??? glibc's ld.so just adds the final GOT entry to the
1330
     relocation field.  It therefore treats relocs against
1331
     defined symbols in the same way as relocs against
1332
     undefined symbols.  */
1333
0
      defined_p = false;
1334
0
    }
1335
0
  else
1336
0
    {
1337
0
      indx = 0;
1338
0
      defined_p = true;
1339
0
    }
1340
1341
  /* If the relocation was previously an absolute relocation and
1342
     this symbol will not be referred to by the relocation, we must
1343
     adjust it by the value we give it in the dynamic symbol table.
1344
     Otherwise leave the job up to the dynamic linker.  */
1345
0
  if (defined_p && r_type != R_SCORE_REL32)
1346
0
    *addendp += symbol;
1347
1348
  /* The relocation is always an REL32 relocation because we don't
1349
     know where the shared library will wind up at load-time.  */
1350
0
  outrel.r_info = ELF32_R_INFO ((unsigned long) indx, R_SCORE_REL32);
1351
1352
  /* For strict adherence to the ABI specification, we should
1353
     generate a R_SCORE_64 relocation record by itself before the
1354
     _REL32/_64 record as well, such that the addend is read in as
1355
     a 64-bit value (REL32 is a 32-bit relocation, after all).
1356
     However, since none of the existing ELF64 SCORE dynamic
1357
     loaders seems to care, we don't waste space with these
1358
     artificial relocations.  If this turns out to not be true,
1359
     score_elf_allocate_dynamic_relocations() should be tweaked so
1360
     as to make room for a pair of dynamic relocations per
1361
     invocation if ABI_64_P, and here we should generate an
1362
     additional relocation record with R_SCORE_64 by itself for a
1363
     NULL symbol before this relocation record.  */
1364
1365
  /* Adjust the output offset of the relocation to reference the
1366
     correct location in the output file.  */
1367
0
  outrel.r_offset += (input_section->output_section->vma
1368
0
          + input_section->output_offset);
1369
1370
  /* Put the relocation back out.  We have to use the special
1371
     relocation outputter in the 64-bit case since the 64-bit
1372
     relocation format is non-standard.  */
1373
0
  bfd_elf32_swap_reloc_out
1374
0
    (output_bfd, &outrel,
1375
0
     sreloc->contents + sreloc->reloc_count * sizeof (Elf32_External_Rel));
1376
1377
  /* We've now added another relocation.  */
1378
0
  ++sreloc->reloc_count;
1379
1380
  /* Make sure the output section is writable.  The dynamic linker
1381
     will be writing to it.  */
1382
0
  elf_section_data (input_section->output_section)->this_hdr.sh_flags |= SHF_WRITE;
1383
1384
0
  return true;
1385
0
}
1386
1387
static bool
1388
score_elf_create_got_section (bfd *abfd,
1389
            struct bfd_link_info *info,
1390
            bool maybe_exclude)
1391
0
{
1392
0
  flagword flags;
1393
0
  asection *s;
1394
0
  struct elf_link_hash_entry *h;
1395
0
  struct bfd_link_hash_entry *bh;
1396
0
  struct score_got_info *g;
1397
0
  size_t amt;
1398
1399
  /* This function may be called more than once.  */
1400
0
  s = score_elf_got_section (abfd, true);
1401
0
  if (s)
1402
0
    {
1403
0
      if (! maybe_exclude)
1404
0
  s->flags &= ~SEC_EXCLUDE;
1405
0
      return true;
1406
0
    }
1407
1408
0
  flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED);
1409
1410
0
  if (maybe_exclude)
1411
0
    flags |= SEC_EXCLUDE;
1412
1413
  /* We have to use an alignment of 2**4 here because this is hardcoded
1414
     in the function stub generation and in the linker script.  */
1415
0
  s = bfd_make_section_anyway_with_flags (abfd, ".got", flags);
1416
0
  elf_hash_table (info)->sgot = s;
1417
0
  if (s == NULL
1418
0
      || !bfd_set_section_alignment (s, 4))
1419
0
    return false;
1420
1421
  /* Define the symbol _GLOBAL_OFFSET_TABLE_.  We don't do this in the
1422
     linker script because we don't want to define the symbol if we
1423
     are not creating a global offset table.  */
1424
0
  bh = NULL;
1425
0
  if (! (_bfd_generic_link_add_one_symbol
1426
0
   (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s,
1427
0
    0, NULL, false, get_elf_backend_data (abfd)->collect, &bh)))
1428
0
    return false;
1429
1430
0
  h = (struct elf_link_hash_entry *) bh;
1431
0
  h->non_elf = 0;
1432
0
  h->def_regular = 1;
1433
0
  h->type = STT_OBJECT;
1434
0
  elf_hash_table (info)->hgot = h;
1435
1436
0
  if (bfd_link_pic (info) && ! bfd_elf_link_record_dynamic_symbol (info, h))
1437
0
    return false;
1438
1439
0
  amt = sizeof (struct score_got_info);
1440
0
  g = bfd_alloc (abfd, amt);
1441
0
  if (g == NULL)
1442
0
    return false;
1443
1444
0
  g->global_gotsym = NULL;
1445
0
  g->global_gotno = 0;
1446
1447
0
  g->local_gotno = SCORE_RESERVED_GOTNO;
1448
0
  g->assigned_gotno = SCORE_RESERVED_GOTNO;
1449
0
  g->next = NULL;
1450
1451
0
  g->got_entries = htab_try_create (1, score_elf_got_entry_hash,
1452
0
            score_elf_got_entry_eq, NULL);
1453
0
  if (g->got_entries == NULL)
1454
0
    return false;
1455
0
  score_elf_section_data (s)->u.got_info = g;
1456
0
  score_elf_section_data (s)->elf.this_hdr.sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_SCORE_GPREL;
1457
1458
0
  return true;
1459
0
}
1460
1461
/* Calculate the %high function.  */
1462
static bfd_vma
1463
score_elf_high (bfd_vma value)
1464
0
{
1465
0
  return ((value + (bfd_vma) 0x8000) >> 16) & 0xffff;
1466
0
}
1467
1468
/* Create a local GOT entry for VALUE.  Return the index of the entry,
1469
   or -1 if it could not be created.  */
1470
static struct score_got_entry *
1471
score_elf_create_local_got_entry (bfd *abfd,
1472
          bfd *ibfd ATTRIBUTE_UNUSED,
1473
          struct score_got_info *gg,
1474
          asection *sgot, bfd_vma value,
1475
          unsigned long r_symndx ATTRIBUTE_UNUSED,
1476
          struct score_elf_link_hash_entry *h ATTRIBUTE_UNUSED,
1477
          int r_type ATTRIBUTE_UNUSED)
1478
0
{
1479
0
  struct score_got_entry entry, **loc;
1480
0
  struct score_got_info *g;
1481
1482
0
  entry.abfd = NULL;
1483
0
  entry.symndx = -1;
1484
0
  entry.d.address = value;
1485
1486
0
  g = gg;
1487
0
  loc = (struct score_got_entry **) htab_find_slot (g->got_entries, &entry, INSERT);
1488
0
  if (*loc)
1489
0
    return *loc;
1490
1491
0
  entry.gotidx = SCORE_ELF_GOT_SIZE (abfd) * g->assigned_gotno++;
1492
1493
0
  *loc = bfd_alloc (abfd, sizeof entry);
1494
1495
0
  if (! *loc)
1496
0
    return NULL;
1497
1498
0
  memcpy (*loc, &entry, sizeof entry);
1499
1500
0
  if (g->assigned_gotno >= g->local_gotno)
1501
0
    {
1502
0
      (*loc)->gotidx = -1;
1503
      /* We didn't allocate enough space in the GOT.  */
1504
0
      _bfd_error_handler
1505
0
  (_("not enough GOT space for local GOT entries"));
1506
0
      bfd_set_error (bfd_error_bad_value);
1507
0
      return NULL;
1508
0
    }
1509
1510
0
  score_bfd_put_32 (abfd, value, (sgot->contents + entry.gotidx));
1511
1512
0
  return *loc;
1513
0
}
1514
1515
/* Find a GOT entry whose higher-order 16 bits are the same as those
1516
   for value.  Return the index into the GOT for this entry.  */
1517
static bfd_vma
1518
score_elf_got16_entry (bfd *abfd, bfd *ibfd, struct bfd_link_info *info,
1519
           bfd_vma value, bool external)
1520
0
{
1521
0
  asection *sgot;
1522
0
  struct score_got_info *g;
1523
0
  struct score_got_entry *entry;
1524
1525
0
  if (!external)
1526
0
    {
1527
      /* Although the ABI says that it is "the high-order 16 bits" that we
1528
   want, it is really the %high value.  The complete value is
1529
   calculated with a `addiu' of a LO16 relocation, just as with a
1530
   HI16/LO16 pair.  */
1531
0
      value = score_elf_high (value) << 16;
1532
0
    }
1533
1534
0
  g = score_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
1535
1536
0
  entry = score_elf_create_local_got_entry (abfd, ibfd, g, sgot, value, 0, NULL,
1537
0
              R_SCORE_GOT15);
1538
0
  if (entry)
1539
0
    return entry->gotidx;
1540
0
  else
1541
0
    return MINUS_ONE;
1542
0
}
1543
1544
static void
1545
s3_bfd_score_elf_hide_symbol (struct bfd_link_info *info,
1546
            struct elf_link_hash_entry *entry,
1547
            bool force_local)
1548
0
{
1549
0
  bfd *dynobj;
1550
0
  asection *got;
1551
0
  struct score_got_info *g;
1552
0
  struct score_elf_link_hash_entry *h;
1553
1554
0
  h = (struct score_elf_link_hash_entry *) entry;
1555
0
  if (h->forced_local)
1556
0
    return;
1557
0
  h->forced_local = true;
1558
1559
0
  dynobj = elf_hash_table (info)->dynobj;
1560
0
  if (dynobj != NULL && force_local)
1561
0
    {
1562
0
      got = score_elf_got_section (dynobj, false);
1563
0
      if (got == NULL)
1564
0
  return;
1565
0
      g = score_elf_section_data (got)->u.got_info;
1566
1567
0
      if (g->next)
1568
0
  {
1569
0
    struct score_got_entry e;
1570
0
    struct score_got_info *gg = g;
1571
1572
    /* Since we're turning what used to be a global symbol into a
1573
       local one, bump up the number of local entries of each GOT
1574
       that had an entry for it.  This will automatically decrease
1575
       the number of global entries, since global_gotno is actually
1576
       the upper limit of global entries.  */
1577
0
    e.abfd = dynobj;
1578
0
    e.symndx = -1;
1579
0
    e.d.h = h;
1580
1581
0
    for (g = g->next; g != gg; g = g->next)
1582
0
      if (htab_find (g->got_entries, &e))
1583
0
        {
1584
0
    BFD_ASSERT (g->global_gotno > 0);
1585
0
    g->local_gotno++;
1586
0
    g->global_gotno--;
1587
0
        }
1588
1589
    /* If this was a global symbol forced into the primary GOT, we
1590
       no longer need an entry for it.  We can't release the entry
1591
       at this point, but we must at least stop counting it as one
1592
       of the symbols that required a forced got entry.  */
1593
0
    if (h->root.got.offset == 2)
1594
0
      {
1595
0
        BFD_ASSERT (gg->assigned_gotno > 0);
1596
0
        gg->assigned_gotno--;
1597
0
      }
1598
0
  }
1599
0
      else if (g->global_gotno == 0 && g->global_gotsym == NULL)
1600
  /* If we haven't got through GOT allocation yet, just bump up the
1601
        number of local entries, as this symbol won't be counted as
1602
        global.  */
1603
0
  g->local_gotno++;
1604
0
      else if (h->root.got.offset == 1)
1605
0
  {
1606
    /* If we're past non-multi-GOT allocation and this symbol had
1607
      been marked for a global got entry, give it a local entry
1608
      instead.  */
1609
0
    BFD_ASSERT (g->global_gotno > 0);
1610
0
    g->local_gotno++;
1611
0
    g->global_gotno--;
1612
0
  }
1613
0
    }
1614
1615
0
  _bfd_elf_link_hash_hide_symbol (info, &h->root, force_local);
1616
0
}
1617
1618
/* If H is a symbol that needs a global GOT entry, but has a dynamic
1619
   symbol table index lower than any we've seen to date, record it for
1620
   posterity.  */
1621
static bool
1622
score_elf_record_global_got_symbol (struct elf_link_hash_entry *h,
1623
            bfd *abfd,
1624
            struct bfd_link_info *info,
1625
            struct score_got_info *g)
1626
0
{
1627
0
  struct score_got_entry entry, **loc;
1628
1629
  /* A global symbol in the GOT must also be in the dynamic symbol table.  */
1630
0
  if (h->dynindx == -1)
1631
0
    {
1632
0
      switch (ELF_ST_VISIBILITY (h->other))
1633
0
  {
1634
0
  case STV_INTERNAL:
1635
0
  case STV_HIDDEN:
1636
0
    s3_bfd_score_elf_hide_symbol (info, h, true);
1637
0
    break;
1638
0
  }
1639
0
      if (!bfd_elf_link_record_dynamic_symbol (info, h))
1640
0
  return false;
1641
0
    }
1642
1643
0
  entry.abfd = abfd;
1644
0
  entry.symndx = -1;
1645
0
  entry.d.h = (struct score_elf_link_hash_entry *)h;
1646
1647
0
  loc = (struct score_got_entry **)htab_find_slot (g->got_entries, &entry, INSERT);
1648
1649
  /* If we've already marked this entry as needing GOT space, we don't
1650
     need to do it again.  */
1651
0
  if (*loc)
1652
0
    return true;
1653
1654
0
  *loc = bfd_alloc (abfd, sizeof entry);
1655
0
  if (! *loc)
1656
0
    return false;
1657
1658
0
  entry.gotidx = -1;
1659
1660
0
  memcpy (*loc, &entry, sizeof (entry));
1661
1662
0
  if (h->got.offset != MINUS_ONE)
1663
0
    return true;
1664
1665
  /* By setting this to a value other than -1, we are indicating that
1666
     there needs to be a GOT entry for H.  Avoid using zero, as the
1667
     generic ELF copy_indirect_symbol tests for <= 0.  */
1668
0
  h->got.offset = 1;
1669
1670
0
  return true;
1671
0
}
1672
1673
/* Reserve space in G for a GOT entry containing the value of symbol
1674
   SYMNDX in input bfd ABDF, plus ADDEND.  */
1675
static bool
1676
score_elf_record_local_got_symbol (bfd *abfd,
1677
           long symndx,
1678
           bfd_vma addend,
1679
           struct score_got_info *g)
1680
0
{
1681
0
  struct score_got_entry entry, **loc;
1682
1683
0
  entry.abfd = abfd;
1684
0
  entry.symndx = symndx;
1685
0
  entry.d.addend = addend;
1686
0
  loc = (struct score_got_entry **)htab_find_slot (g->got_entries, &entry, INSERT);
1687
1688
0
  if (*loc)
1689
0
    return true;
1690
1691
0
  entry.gotidx = g->local_gotno++;
1692
1693
0
  *loc = bfd_alloc (abfd, sizeof(entry));
1694
0
  if (! *loc)
1695
0
    return false;
1696
1697
0
  memcpy (*loc, &entry, sizeof (entry));
1698
1699
0
  return true;
1700
0
}
1701
1702
/* Returns the GOT offset at which the indicated address can be found.
1703
   If there is not yet a GOT entry for this value, create one.
1704
   Returns -1 if no satisfactory GOT offset can be found.  */
1705
static bfd_vma
1706
score_elf_local_got_index (bfd *abfd, bfd *ibfd, struct bfd_link_info *info,
1707
         bfd_vma value, unsigned long r_symndx,
1708
         struct score_elf_link_hash_entry *h, int r_type)
1709
0
{
1710
0
  asection *sgot;
1711
0
  struct score_got_info *g;
1712
0
  struct score_got_entry *entry;
1713
1714
0
  g = score_elf_got_info (elf_hash_table (info)->dynobj, &sgot);
1715
1716
0
  entry = score_elf_create_local_got_entry (abfd, ibfd, g, sgot, value,
1717
0
               r_symndx, h, r_type);
1718
0
  if (!entry)
1719
0
    return MINUS_ONE;
1720
1721
0
  else
1722
0
    return entry->gotidx;
1723
0
}
1724
1725
/* Returns the GOT index for the global symbol indicated by H.  */
1726
1727
static bfd_vma
1728
score_elf_global_got_index (bfd *abfd, struct elf_link_hash_entry *h)
1729
0
{
1730
0
  bfd_vma got_index;
1731
0
  asection *sgot;
1732
0
  struct score_got_info *g;
1733
0
  long global_got_dynindx = 0;
1734
1735
0
  g = score_elf_got_info (abfd, &sgot);
1736
0
  if (g->global_gotsym != NULL)
1737
0
    global_got_dynindx = g->global_gotsym->dynindx;
1738
1739
  /* Once we determine the global GOT entry with the lowest dynamic
1740
     symbol table index, we must put all dynamic symbols with greater
1741
     indices into the GOT.  That makes it easy to calculate the GOT
1742
     offset.  */
1743
0
  BFD_ASSERT (h->dynindx >= global_got_dynindx);
1744
0
  got_index = ((h->dynindx - global_got_dynindx + g->local_gotno) * SCORE_ELF_GOT_SIZE (abfd));
1745
0
  BFD_ASSERT (got_index < sgot->size);
1746
1747
0
  return got_index;
1748
0
}
1749
1750
/* Returns the offset for the entry at the INDEXth position in the GOT.  */
1751
1752
static bfd_vma
1753
score_elf_got_offset_from_index (bfd *dynobj,
1754
         bfd *output_bfd,
1755
         bfd *input_bfd ATTRIBUTE_UNUSED,
1756
         bfd_vma got_index)
1757
0
{
1758
0
  asection *sgot;
1759
0
  bfd_vma gp;
1760
1761
0
  score_elf_got_info (dynobj, &sgot);
1762
0
  gp = _bfd_get_gp_value (output_bfd);
1763
1764
0
  return sgot->output_section->vma + sgot->output_offset + got_index - gp;
1765
0
}
1766
1767
/* Follow indirect and warning hash entries so that each got entry
1768
   points to the final symbol definition.  P must point to a pointer
1769
   to the hash table we're traversing.  Since this traversal may
1770
   modify the hash table, we set this pointer to NULL to indicate
1771
   we've made a potentially-destructive change to the hash table, so
1772
   the traversal must be restarted.  */
1773
static int
1774
score_elf_resolve_final_got_entry (void **entryp, void *p)
1775
0
{
1776
0
  struct score_got_entry *entry = (struct score_got_entry *)*entryp;
1777
0
  htab_t got_entries = *(htab_t *)p;
1778
1779
0
  if (entry->abfd != NULL && entry->symndx == -1)
1780
0
    {
1781
0
      struct score_elf_link_hash_entry *h = entry->d.h;
1782
1783
0
      while (h->root.root.type == bfd_link_hash_indirect
1784
0
       || h->root.root.type == bfd_link_hash_warning)
1785
0
  h = (struct score_elf_link_hash_entry *) h->root.root.u.i.link;
1786
1787
0
      if (entry->d.h == h)
1788
0
  return 1;
1789
1790
0
      entry->d.h = h;
1791
1792
      /* If we can't find this entry with the new bfd hash, re-insert
1793
   it, and get the traversal restarted.  */
1794
0
      if (! htab_find (got_entries, entry))
1795
0
  {
1796
0
    htab_clear_slot (got_entries, entryp);
1797
0
    entryp = htab_find_slot (got_entries, entry, INSERT);
1798
0
    if (! *entryp)
1799
0
      *entryp = entry;
1800
    /* Abort the traversal, since the whole table may have
1801
       moved, and leave it up to the parent to restart the
1802
       process.  */
1803
0
    *(htab_t *)p = NULL;
1804
0
    return 0;
1805
0
  }
1806
      /* We might want to decrement the global_gotno count, but it's
1807
   either too early or too late for that at this point.  */
1808
0
    }
1809
1810
0
  return 1;
1811
0
}
1812
1813
/* Turn indirect got entries in a got_entries table into their final locations.  */
1814
static void
1815
score_elf_resolve_final_got_entries (struct score_got_info *g)
1816
0
{
1817
0
  htab_t got_entries;
1818
1819
0
  do
1820
0
    {
1821
0
      got_entries = g->got_entries;
1822
1823
0
      htab_traverse (got_entries,
1824
0
         score_elf_resolve_final_got_entry,
1825
0
         &got_entries);
1826
0
    }
1827
0
  while (got_entries == NULL);
1828
0
}
1829
1830
/* Add INCREMENT to the reloc (of type HOWTO) at ADDRESS. for -r  */
1831
static void
1832
score_elf_add_to_rel (bfd *abfd,
1833
          bfd_byte *address,
1834
          reloc_howto_type *howto,
1835
          bfd_signed_vma increment)
1836
0
{
1837
0
  bfd_signed_vma addend;
1838
0
  bfd_vma contents;
1839
0
  unsigned long offset;
1840
0
  unsigned long r_type = howto->type;
1841
0
  unsigned long hi16_addend, hi16_offset, hi16_value, uvalue;
1842
1843
0
  contents = score_bfd_get_32 (abfd, address);
1844
  /* Get the (signed) value from the instruction.  */
1845
0
  addend = contents & howto->src_mask;
1846
0
  if (addend & ((howto->src_mask + 1) >> 1))
1847
0
    {
1848
0
      bfd_signed_vma mask;
1849
1850
0
      mask = -1;
1851
0
      mask &= ~howto->src_mask;
1852
0
      addend |= mask;
1853
0
    }
1854
  /* Add in the increment, (which is a byte value).  */
1855
0
  switch (r_type)
1856
0
    {
1857
0
    case R_SCORE_PC19:
1858
0
      offset =
1859
0
  (((contents & howto->src_mask) & 0x3ff0000) >> 6) | ((contents & howto->src_mask) & 0x3ff);
1860
0
      offset += increment;
1861
0
      contents =
1862
0
  (contents & ~howto->
1863
0
   src_mask) | (((offset << 6) & howto->src_mask) & 0x3ff0000) | (offset & 0x3ff);
1864
0
      score_bfd_put_32 (abfd, contents, address);
1865
0
      break;
1866
0
    case R_SCORE_HI16:
1867
0
      break;
1868
0
    case R_SCORE_LO16:
1869
0
      hi16_addend = score_bfd_get_32 (abfd, address - 4);
1870
0
      hi16_offset = ((((hi16_addend >> 16) & 0x3) << 15) | (hi16_addend & 0x7fff)) >> 1;
1871
0
      offset = ((((contents >> 16) & 0x3) << 15) | (contents & 0x7fff)) >> 1;
1872
0
      offset = (hi16_offset << 16) | (offset & 0xffff);
1873
0
      uvalue = increment + offset;
1874
0
      hi16_offset = (uvalue >> 16) << 1;
1875
0
      hi16_value = (hi16_addend & (~(howto->dst_mask)))
1876
0
  | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
1877
0
      score_bfd_put_32 (abfd, hi16_value, address - 4);
1878
0
      offset = (uvalue & 0xffff) << 1;
1879
0
      contents = (contents & (~(howto->dst_mask))) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
1880
0
      score_bfd_put_32 (abfd, contents, address);
1881
0
      break;
1882
0
    case R_SCORE_24:
1883
0
      offset =
1884
0
  (((contents & howto->src_mask) >> 1) & 0x1ff8000) | ((contents & howto->src_mask) & 0x7fff);
1885
0
      offset += increment;
1886
0
      contents =
1887
0
  (contents & ~howto->
1888
0
   src_mask) | (((offset << 1) & howto->src_mask) & 0x3ff0000) | (offset & 0x7fff);
1889
0
      score_bfd_put_32 (abfd, contents, address);
1890
0
      break;
1891
1892
0
    case R_SCORE16_11:
1893
1894
0
      contents = score_bfd_get_16 (abfd, address);
1895
0
      offset = contents & howto->src_mask;
1896
0
      offset += increment;
1897
0
      contents = (contents & ~howto->src_mask) | (offset & howto->src_mask);
1898
0
      score_bfd_put_16 (abfd, contents, address);
1899
1900
0
      break;
1901
0
    case R_SCORE16_PC8:
1902
1903
0
      contents = score_bfd_get_16 (abfd, address);
1904
0
      offset = (contents & howto->src_mask) + ((increment >> 1) & 0x1ff);
1905
0
      contents = (contents & (~howto->src_mask)) | (offset & howto->src_mask);
1906
0
      score_bfd_put_16 (abfd, contents, address);
1907
1908
0
      break;
1909
1910
0
    case R_SCORE_BCMP:
1911
0
      contents = score_bfd_get_32 (abfd, address);
1912
0
      offset = (contents & howto->src_mask);
1913
0
      offset <<= howto->rightshift;
1914
0
      offset += increment;
1915
0
      offset >>= howto->rightshift;
1916
0
      contents = (contents & (~howto->src_mask)) | (offset & howto->src_mask);
1917
0
      score_bfd_put_32 (abfd, contents, address);
1918
0
      break;
1919
1920
0
    case R_SCORE_IMM30:
1921
0
      contents = score_bfd_get_48 (abfd, address);
1922
0
      offset = (contents & howto->src_mask);
1923
0
      offset <<= howto->rightshift;
1924
0
      offset += increment;
1925
0
      offset >>= howto->rightshift;
1926
0
      contents = (contents & (~howto->src_mask)) | (offset & howto->src_mask);
1927
0
      score_bfd_put_48 (abfd, contents, address);
1928
0
      break;
1929
1930
0
    case R_SCORE_IMM32:
1931
0
      contents = score_bfd_get_48 (abfd, address);
1932
0
      offset = (contents & howto->src_mask);
1933
0
      offset += increment;
1934
0
      contents = (contents & (~howto->src_mask)) | (offset & howto->src_mask);
1935
0
      score_bfd_put_48 (abfd, contents, address);
1936
0
      break;
1937
1938
0
    default:
1939
0
      addend += increment;
1940
0
      contents = (contents & ~howto->dst_mask) | (addend & howto->dst_mask);
1941
0
      score_bfd_put_32 (abfd, contents, address);
1942
0
      break;
1943
0
    }
1944
0
}
1945
1946
/* Perform a relocation as part of a final link.  */
1947
static bfd_reloc_status_type
1948
score_elf_final_link_relocate (reloc_howto_type *howto,
1949
             bfd *input_bfd,
1950
             bfd *output_bfd,
1951
             asection *input_section,
1952
             bfd_byte *contents,
1953
             Elf_Internal_Rela *rel,
1954
             Elf_Internal_Rela *relocs,
1955
             bfd_vma symbol,
1956
             struct bfd_link_info *info,
1957
             const char *sym_name ATTRIBUTE_UNUSED,
1958
             int sym_flags ATTRIBUTE_UNUSED,
1959
             struct score_elf_link_hash_entry *h,
1960
             asection **local_sections,
1961
             bool gp_disp_p)
1962
0
{
1963
0
  unsigned long r_type;
1964
0
  unsigned long r_symndx;
1965
0
  bfd_byte *hit_data = contents + rel->r_offset;
1966
0
  bfd_vma addend;
1967
  /* The final GP value to be used for the relocatable, executable, or
1968
     shared object file being produced.  */
1969
0
  bfd_vma gp = MINUS_ONE;
1970
  /* The place (section offset or address) of the storage unit being relocated.  */
1971
0
  bfd_vma rel_addr;
1972
  /* The offset into the global offset table at which the address of the relocation entry
1973
     symbol, adjusted by the addend, resides during execution.  */
1974
0
  bfd_vma g = MINUS_ONE;
1975
  /* TRUE if the symbol referred to by this relocation is a local symbol.  */
1976
0
  bool local_p;
1977
  /* The eventual value we will relocate.  */
1978
0
  bfd_vma value = symbol;
1979
0
  unsigned long hi16_addend, hi16_offset, hi16_value, uvalue, offset, abs_value = 0;
1980
1981
1982
0
  if (elf_gp (output_bfd) == 0)
1983
0
    {
1984
0
      struct bfd_link_hash_entry *bh;
1985
0
      asection *o;
1986
1987
0
      bh = bfd_link_hash_lookup (info->hash, "_gp", 0, 0, 1);
1988
0
      if (bh != NULL && bh->type == bfd_link_hash_defined)
1989
0
  elf_gp (output_bfd) = (bh->u.def.value
1990
0
             + bh->u.def.section->output_section->vma
1991
0
             + bh->u.def.section->output_offset);
1992
0
      else if (bfd_link_relocatable (info))
1993
0
  {
1994
0
    bfd_vma lo = -1;
1995
1996
    /* Find the GP-relative section with the lowest offset.  */
1997
0
    for (o = output_bfd->sections; o != NULL; o = o->next)
1998
0
      if (o->vma < lo)
1999
0
        lo = o->vma;
2000
    /* And calculate GP relative to that.  */
2001
0
    elf_gp (output_bfd) = lo + ELF_SCORE_GP_OFFSET (input_bfd);
2002
0
  }
2003
0
      else
2004
0
  {
2005
    /* If the relocate_section function needs to do a reloc
2006
       involving the GP value, it should make a reloc_dangerous
2007
       callback to warn that GP is not defined.  */
2008
0
  }
2009
0
    }
2010
2011
  /* Parse the relocation.  */
2012
0
  r_symndx = ELF32_R_SYM (rel->r_info);
2013
0
  r_type = ELF32_R_TYPE (rel->r_info);
2014
0
  rel_addr = (input_section->output_section->vma + input_section->output_offset + rel->r_offset);
2015
0
  local_p = score_elf_local_relocation_p (input_bfd, rel, local_sections, true);
2016
2017
0
  if (r_type == R_SCORE_GOT15)
2018
0
    {
2019
0
      const Elf_Internal_Rela *relend;
2020
0
      const Elf_Internal_Rela *lo16_rel;
2021
0
      bfd_vma lo_value = 0;
2022
2023
0
      relend = relocs + input_section->reloc_count;
2024
0
      lo16_rel = score_elf_next_relocation (input_bfd, R_SCORE_GOT_LO16, rel, relend);
2025
0
      if ((local_p) && (lo16_rel != NULL))
2026
0
  {
2027
0
    bfd_vma tmp = 0;
2028
0
    tmp = score_bfd_get_32 (input_bfd, contents + lo16_rel->r_offset);
2029
0
    lo_value = (((tmp >> 16) & 0x3) << 14) | ((tmp & 0x7fff) >> 1);
2030
0
  }
2031
0
      addend = lo_value;
2032
0
    }
2033
  /* For score3 R_SCORE_ABS32.  */
2034
0
  else if (r_type == R_SCORE_ABS32 || r_type == R_SCORE_REL32)
2035
0
    {
2036
0
      addend = (bfd_get_32 (input_bfd, hit_data) >> howto->bitpos) & howto->src_mask;
2037
0
    }
2038
0
  else
2039
0
    {
2040
0
      addend = (score_bfd_get_32 (input_bfd, hit_data) >> howto->bitpos) & howto->src_mask;
2041
0
    }
2042
2043
  /* If we haven't already determined the GOT offset, or the GP value,
2044
     and we're going to need it, get it now.  */
2045
0
  switch (r_type)
2046
0
    {
2047
0
    case R_SCORE_CALL15:
2048
0
    case R_SCORE_GOT15:
2049
0
      if (!local_p)
2050
0
  {
2051
0
    g = score_elf_global_got_index (elf_hash_table (info)->dynobj,
2052
0
            (struct elf_link_hash_entry *) h);
2053
0
    if ((! elf_hash_table (info)->dynamic_sections_created
2054
0
         || (bfd_link_pic (info)
2055
0
       && (info->symbolic || h->root.dynindx == -1)
2056
0
       && h->root.def_regular)))
2057
0
      {
2058
        /* This is a static link or a -Bsymbolic link.  The
2059
     symbol is defined locally, or was forced to be local.
2060
     We must initialize this entry in the GOT.  */
2061
0
        bfd *tmpbfd = elf_hash_table (info)->dynobj;
2062
0
        asection *sgot = score_elf_got_section (tmpbfd, false);
2063
0
        score_bfd_put_32 (tmpbfd, value, sgot->contents + g);
2064
0
      }
2065
0
  }
2066
0
      else if (r_type == R_SCORE_GOT15 || r_type == R_SCORE_CALL15)
2067
0
  {
2068
    /* There's no need to create a local GOT entry here; the
2069
       calculation for a local GOT15 entry does not involve G.  */
2070
0
    ;
2071
0
  }
2072
0
      else
2073
0
  {
2074
0
    g = score_elf_local_got_index (output_bfd, input_bfd, info,
2075
0
           symbol + addend, r_symndx, h, r_type);
2076
0
      if (g == MINUS_ONE)
2077
0
      return bfd_reloc_outofrange;
2078
0
  }
2079
2080
      /* Convert GOT indices to actual offsets.  */
2081
0
      g = score_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
2082
0
             output_bfd, input_bfd, g);
2083
0
      break;
2084
2085
0
    case R_SCORE_HI16:
2086
0
    case R_SCORE_LO16:
2087
0
    case R_SCORE_GPREL32:
2088
0
      gp = _bfd_get_gp_value (output_bfd);
2089
0
      break;
2090
2091
0
    case R_SCORE_GP15:
2092
0
      gp = _bfd_get_gp_value (output_bfd);
2093
2094
0
    default:
2095
0
      break;
2096
0
    }
2097
2098
0
  switch (r_type)
2099
0
    {
2100
0
    case R_SCORE_NONE:
2101
0
      return bfd_reloc_ok;
2102
2103
0
    case R_SCORE_ABS32:
2104
0
    case R_SCORE_REL32:
2105
0
      if ((bfd_link_pic (info)
2106
0
     || (elf_hash_table (info)->dynamic_sections_created
2107
0
         && h != NULL
2108
0
         && h->root.def_dynamic
2109
0
         && !h->root.def_regular))
2110
0
     && r_symndx != STN_UNDEF
2111
0
     && (input_section->flags & SEC_ALLOC) != 0)
2112
0
  {
2113
    /* If we're creating a shared library, or this relocation is against a symbol
2114
       in a shared library, then we can't know where the symbol will end up.
2115
       So, we create a relocation record in the output, and leave the job up
2116
       to the dynamic linker.  */
2117
0
    value = addend;
2118
0
    if (!score_elf_create_dynamic_relocation (output_bfd, info, rel, h,
2119
0
                symbol, &value,
2120
0
                input_section))
2121
0
      return bfd_reloc_undefined;
2122
0
  }
2123
0
      else if (r_symndx == STN_UNDEF)
2124
  /* r_symndx will be STN_UNDEF (zero) only for relocs against symbols
2125
     from removed linkonce sections, or sections discarded by
2126
     a linker script.  */
2127
0
  value = 0;
2128
0
      else
2129
0
  {
2130
0
    if (r_type != R_SCORE_REL32)
2131
0
      value = symbol + addend;
2132
0
    else
2133
0
      value = addend;
2134
0
  }
2135
0
      value &= howto->dst_mask;
2136
0
      bfd_put_32 (input_bfd, value, hit_data);
2137
0
      return bfd_reloc_ok;
2138
2139
0
    case R_SCORE_ABS16:
2140
0
      value += addend;
2141
0
      if ((long)value > 0x7fff || (long)value < -0x8000)
2142
0
  return bfd_reloc_overflow;
2143
0
      score_bfd_put_16 (input_bfd, value, hit_data);
2144
0
      return bfd_reloc_ok;
2145
2146
0
    case R_SCORE_24:
2147
0
      addend = score_bfd_get_32 (input_bfd, hit_data);
2148
0
      offset = (((addend & howto->src_mask) >> 1) & 0x1ff8000) | ((addend & howto->src_mask) & 0x7fff);
2149
0
      if ((offset & 0x1000000) != 0)
2150
0
  offset |= 0xfe000000;
2151
0
      value += offset;
2152
0
      abs_value = value - rel_addr;
2153
0
      if ((abs_value & 0xfe000000) != 0)
2154
0
  return bfd_reloc_overflow;
2155
0
      addend = (addend & ~howto->src_mask)
2156
0
    | (((value << 1) & howto->src_mask) & 0x3ff0000) | (value & 0x7fff);
2157
0
      score_bfd_put_32 (input_bfd, addend, hit_data);
2158
0
      return bfd_reloc_ok;
2159
2160
    /* signed imm32.  */
2161
0
    case R_SCORE_IMM30:
2162
0
      {
2163
0
  int not_word_align_p = 0;
2164
0
  bfd_vma imm_offset = 0;
2165
0
  addend = score_bfd_get_48 (input_bfd, hit_data);
2166
0
  imm_offset = ((addend >> 7) & 0xff)
2167
0
         | (((addend >> 16) & 0x7fff) << 8)
2168
0
         | (((addend >> 32) & 0x7f) << 23);
2169
0
  imm_offset <<= howto->rightshift;
2170
0
  value += imm_offset;
2171
0
  value &= 0xffffffff;
2172
2173
  /* Check lw48/sw48 rd, value/label word align.  */
2174
0
  if ((value & 0x3) != 0)
2175
0
    not_word_align_p = 1;
2176
2177
0
  value >>= howto->rightshift;
2178
0
  addend = (addend & ~howto->src_mask)
2179
0
     | (((value & 0xff) >> 0) << 7)
2180
0
     | (((value & 0x7fff00) >> 8) << 16)
2181
0
     | (((value & 0x3f800000) >> 23) << 32);
2182
0
  score_bfd_put_48 (input_bfd, addend, hit_data);
2183
0
  if (not_word_align_p)
2184
0
    return bfd_reloc_other;
2185
0
  else
2186
0
    return bfd_reloc_ok;
2187
0
      }
2188
2189
0
    case R_SCORE_IMM32:
2190
0
      {
2191
0
  bfd_vma imm_offset = 0;
2192
0
  addend = score_bfd_get_48 (input_bfd, hit_data);
2193
0
  imm_offset = ((addend >> 5) & 0x3ff)
2194
0
         | (((addend >> 16) & 0x7fff) << 10)
2195
0
         | (((addend >> 32) & 0x7f) << 25);
2196
0
  value += imm_offset;
2197
0
  value &= 0xffffffff;
2198
0
  addend = (addend & ~howto->src_mask)
2199
0
     | ((value & 0x3ff) << 5)
2200
0
     | (((value >> 10) & 0x7fff) << 16)
2201
0
     | (((value >> 25) & 0x7f) << 32);
2202
0
  score_bfd_put_48 (input_bfd, addend, hit_data);
2203
0
  return bfd_reloc_ok;
2204
0
      }
2205
2206
0
    case R_SCORE_PC19:
2207
0
      addend = score_bfd_get_32 (input_bfd, hit_data);
2208
0
      offset = (((addend & howto->src_mask) & 0x3ff0000) >> 6) | ((addend & howto->src_mask) & 0x3ff);
2209
0
      if ((offset & 0x80000) != 0)
2210
0
  offset |= 0xfff00000;
2211
0
      abs_value = value = value - rel_addr + offset;
2212
      /* exceed 20 bit : overflow.  */
2213
0
      if ((abs_value & 0x80000000) == 0x80000000)
2214
0
  abs_value = 0xffffffff - value + 1;
2215
0
      if ((abs_value & 0xfff80000) != 0)
2216
0
  return bfd_reloc_overflow;
2217
0
      addend = (addend & ~howto->src_mask)
2218
0
    | (((value << 6) & howto->src_mask) & 0x3ff0000) | (value & 0x3ff);
2219
0
      score_bfd_put_32 (input_bfd, addend, hit_data);
2220
0
      return bfd_reloc_ok;
2221
2222
0
    case R_SCORE16_11:
2223
0
      addend = score_bfd_get_16 (input_bfd, hit_data);
2224
0
      offset = addend & howto->src_mask;
2225
0
      if ((offset & 0x800) != 0) /* Offset is negative.  */
2226
0
  offset |= 0xfffff000;
2227
0
      value += offset;
2228
0
      abs_value = value - rel_addr;
2229
0
      if ((abs_value & 0xfffff000) != 0)
2230
0
  return bfd_reloc_overflow;
2231
0
      addend = (addend & ~howto->src_mask) | (value & howto->src_mask);
2232
0
      score_bfd_put_16 (input_bfd, addend, hit_data);
2233
0
      return bfd_reloc_ok;
2234
2235
0
    case R_SCORE16_PC8:
2236
0
      addend = score_bfd_get_16 (input_bfd, hit_data);
2237
0
      offset = (addend & howto->src_mask) << 1;
2238
0
      if ((offset & 0x200) != 0) /* Offset is negative.  */
2239
0
  offset |= 0xfffffe00;
2240
0
      abs_value = value = value - rel_addr + offset;
2241
      /* Sign bit + exceed 9 bit.  */
2242
0
      if (((value & 0xfffffe00) != 0) && ((value & 0xfffffe00) != 0xfffffe00))
2243
0
  return bfd_reloc_overflow;
2244
0
      value >>= 1;
2245
0
      addend = (addend & ~howto->src_mask) | (value & howto->src_mask);
2246
0
      score_bfd_put_16 (input_bfd, addend, hit_data);
2247
0
      return bfd_reloc_ok;
2248
2249
0
    case R_SCORE_BCMP:
2250
0
      addend = score_bfd_get_32 (input_bfd, hit_data);
2251
0
      offset = (addend & howto->src_mask) << howto->rightshift;
2252
0
      if ((offset & 0x200) != 0) /* Offset is negative.  */
2253
0
  offset |= 0xfffffe00;
2254
0
      value = value - rel_addr + offset;
2255
      /* Sign bit + exceed 9 bit.  */
2256
0
      if (((value & 0xfffffe00) != 0) && ((value & 0xfffffe00) != 0xfffffe00))
2257
0
  return bfd_reloc_overflow;
2258
0
      value >>= howto->rightshift;
2259
0
      addend = (addend & ~howto->src_mask)
2260
0
         | (value & 0x1)
2261
0
         | (((value >> 1) & 0x7) << 7)
2262
0
         | (((value >> 4) & 0x1f) << 21);
2263
0
      score_bfd_put_32 (input_bfd, addend, hit_data);
2264
0
      return bfd_reloc_ok;
2265
2266
0
    case R_SCORE_HI16:
2267
0
      return bfd_reloc_ok;
2268
2269
0
    case R_SCORE_LO16:
2270
0
      hi16_addend = score_bfd_get_32 (input_bfd, hit_data - 4);
2271
0
      hi16_offset = ((((hi16_addend >> 16) & 0x3) << 15) | (hi16_addend & 0x7fff)) >> 1;
2272
0
      addend = score_bfd_get_32 (input_bfd, hit_data);
2273
0
      offset = ((((addend >> 16) & 0x3) << 15) | (addend & 0x7fff)) >> 1;
2274
0
      offset = (hi16_offset << 16) | (offset & 0xffff);
2275
2276
0
      if (!gp_disp_p)
2277
0
  uvalue = value + offset;
2278
0
      else
2279
0
  uvalue = offset + gp - rel_addr + 4;
2280
2281
0
      hi16_offset = (uvalue >> 16) << 1;
2282
0
      hi16_value = (hi16_addend & (~(howto->dst_mask)))
2283
0
      | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
2284
0
      score_bfd_put_32 (input_bfd, hi16_value, hit_data - 4);
2285
0
      offset = (uvalue & 0xffff) << 1;
2286
0
      value = (addend & (~(howto->dst_mask))) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
2287
0
      score_bfd_put_32 (input_bfd, value, hit_data);
2288
0
      return bfd_reloc_ok;
2289
2290
0
    case R_SCORE_GP15:
2291
0
      addend = score_bfd_get_32 (input_bfd, hit_data);
2292
0
      offset = addend & 0x7fff;
2293
0
      if ((offset & 0x4000) == 0x4000)
2294
0
  offset |= 0xffffc000;
2295
0
      value = value + offset - gp;
2296
0
      if (((value & 0xffffc000) != 0) && ((value & 0xffffc000) != 0xffffc000))
2297
0
  return bfd_reloc_overflow;
2298
0
      value = (addend & ~howto->src_mask) | (value & howto->src_mask);
2299
0
      score_bfd_put_32 (input_bfd, value, hit_data);
2300
0
      return bfd_reloc_ok;
2301
2302
0
    case R_SCORE_GOT15:
2303
0
    case R_SCORE_CALL15:
2304
0
      if (local_p)
2305
0
  {
2306
0
    bool forced;
2307
2308
    /* The special case is when the symbol is forced to be local.  We need the
2309
       full address in the GOT since no R_SCORE_GOT_LO16 relocation follows.  */
2310
0
    forced = ! score_elf_local_relocation_p (input_bfd, rel,
2311
0
               local_sections, false);
2312
0
    value = score_elf_got16_entry (output_bfd, input_bfd, info,
2313
0
           symbol + addend, forced);
2314
0
    if (value == MINUS_ONE)
2315
0
      return bfd_reloc_outofrange;
2316
0
    value = score_elf_got_offset_from_index (elf_hash_table (info)->dynobj,
2317
0
               output_bfd, input_bfd, value);
2318
0
  }
2319
0
      else
2320
0
  {
2321
0
    value = g;
2322
0
  }
2323
2324
0
      if ((long) value > 0x3fff || (long) value < -0x4000)
2325
0
  return bfd_reloc_overflow;
2326
2327
0
      addend = score_bfd_get_32 (input_bfd, hit_data);
2328
0
      value = (addend & ~howto->dst_mask) | (value & howto->dst_mask);
2329
0
      score_bfd_put_32 (input_bfd, value, hit_data);
2330
0
      return bfd_reloc_ok;
2331
2332
0
    case R_SCORE_GPREL32:
2333
0
      value = (addend + symbol - gp);
2334
0
      value &= howto->dst_mask;
2335
0
      score_bfd_put_32 (input_bfd, value, hit_data);
2336
0
      return bfd_reloc_ok;
2337
2338
0
    case R_SCORE_GOT_LO16:
2339
0
      addend = score_bfd_get_32 (input_bfd, hit_data);
2340
0
      value = (((addend >> 16) & 0x3) << 14) | ((addend & 0x7fff) >> 1);
2341
0
      value += symbol;
2342
0
      value = (addend & (~(howto->dst_mask))) | ((value & 0x3fff) << 1)
2343
0
         | (((value >> 14) & 0x3) << 16);
2344
2345
0
      score_bfd_put_32 (input_bfd, value, hit_data);
2346
0
      return bfd_reloc_ok;
2347
2348
0
    case R_SCORE_DUMMY_HI16:
2349
0
      return bfd_reloc_ok;
2350
2351
0
    case R_SCORE_GNU_VTINHERIT:
2352
0
    case R_SCORE_GNU_VTENTRY:
2353
      /* We don't do anything with these at present.  */
2354
0
      return bfd_reloc_continue;
2355
2356
0
    default:
2357
0
      return bfd_reloc_notsupported;
2358
0
    }
2359
0
}
2360
2361
/* Score backend functions.  */
2362
static bool
2363
s3_bfd_score_info_to_howto (bfd *abfd,
2364
          arelent *bfd_reloc,
2365
          Elf_Internal_Rela *elf_reloc)
2366
0
{
2367
0
  unsigned int r_type;
2368
2369
0
  r_type = ELF32_R_TYPE (elf_reloc->r_info);
2370
0
  if (r_type >= ARRAY_SIZE (elf32_score_howto_table))
2371
0
    {
2372
      /* xgettext:c-format */
2373
0
      _bfd_error_handler (_("%pB: unsupported relocation type %#x"),
2374
0
        abfd, r_type);
2375
0
      bfd_set_error (bfd_error_bad_value);
2376
0
      return false;
2377
0
    }
2378
2379
0
  bfd_reloc->howto = &elf32_score_howto_table[r_type];
2380
0
  return true;
2381
0
}
2382
2383
/* Relocate an score ELF section.  */
2384
static int
2385
s3_bfd_score_elf_relocate_section (bfd *output_bfd,
2386
           struct bfd_link_info *info,
2387
           bfd *input_bfd,
2388
           asection *input_section,
2389
           bfd_byte *contents,
2390
           Elf_Internal_Rela *relocs,
2391
           Elf_Internal_Sym *local_syms,
2392
           asection **local_sections)
2393
0
{
2394
0
  Elf_Internal_Shdr *symtab_hdr;
2395
0
  Elf_Internal_Rela *rel;
2396
0
  Elf_Internal_Rela *relend;
2397
0
  const char *name;
2398
0
  unsigned long offset;
2399
0
  unsigned long hi16_addend, hi16_offset, hi16_value, uvalue;
2400
0
  size_t extsymoff;
2401
0
  bool gp_disp_p = false;
2402
2403
  /* Sort dynsym.  */
2404
0
  if (elf_hash_table (info)->dynamic_sections_created)
2405
0
    {
2406
0
      bfd_size_type dynsecsymcount = 0;
2407
0
      if (bfd_link_pic (info))
2408
0
  {
2409
0
    asection * p;
2410
0
    const struct elf_backend_data *bed = get_elf_backend_data (output_bfd);
2411
2412
0
    for (p = output_bfd->sections; p ; p = p->next)
2413
0
      if ((p->flags & SEC_EXCLUDE) == 0
2414
0
    && (p->flags & SEC_ALLOC) != 0
2415
0
    && !(*bed->elf_backend_omit_section_dynsym) (output_bfd, info, p))
2416
0
        ++ dynsecsymcount;
2417
0
  }
2418
2419
0
      if (!score_elf_sort_hash_table (info, dynsecsymcount + 1))
2420
0
  return false;
2421
0
    }
2422
2423
0
  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
2424
0
  extsymoff = (elf_bad_symtab (input_bfd)) ? 0 : symtab_hdr->sh_info;
2425
0
  rel = relocs;
2426
0
  relend = relocs + input_section->reloc_count;
2427
0
  for (; rel < relend; rel++)
2428
0
    {
2429
0
      int r_type;
2430
0
      reloc_howto_type *howto;
2431
0
      unsigned long r_symndx;
2432
0
      Elf_Internal_Sym *sym;
2433
0
      asection *sec;
2434
0
      struct score_elf_link_hash_entry *h;
2435
0
      bfd_vma relocation = 0;
2436
0
      bfd_reloc_status_type r;
2437
0
      arelent bfd_reloc;
2438
2439
0
      r_symndx = ELF32_R_SYM (rel->r_info);
2440
0
      r_type = ELF32_R_TYPE (rel->r_info);
2441
2442
0
      if (! s3_bfd_score_info_to_howto (input_bfd, &bfd_reloc, (Elf_Internal_Rela *) rel))
2443
0
  continue;
2444
0
      howto = bfd_reloc.howto;
2445
2446
0
      h = NULL;
2447
0
      sym = NULL;
2448
0
      sec = NULL;
2449
2450
0
      if (r_symndx < extsymoff)
2451
0
  {
2452
0
    sym = local_syms + r_symndx;
2453
0
    sec = local_sections[r_symndx];
2454
0
    relocation = (sec->output_section->vma
2455
0
      + sec->output_offset
2456
0
      + sym->st_value);
2457
0
    name = bfd_elf_sym_name (input_bfd, symtab_hdr, sym, sec);
2458
2459
0
    if (!bfd_link_relocatable (info)
2460
0
        && (sec->flags & SEC_MERGE)
2461
0
        && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2462
0
      {
2463
0
        asection *msec;
2464
0
        bfd_vma addend, value;
2465
2466
0
        switch (r_type)
2467
0
    {
2468
0
    case R_SCORE_HI16:
2469
0
      break;
2470
0
    case R_SCORE_LO16:
2471
0
      hi16_addend = score_bfd_get_32 (input_bfd, contents + rel->r_offset - 4);
2472
0
      hi16_offset = ((((hi16_addend >> 16) & 0x3) << 15) | (hi16_addend & 0x7fff)) >> 1;
2473
0
      value = score_bfd_get_32 (input_bfd, contents + rel->r_offset);
2474
0
      offset = ((((value >> 16) & 0x3) << 15) | (value & 0x7fff)) >> 1;
2475
0
      addend = (hi16_offset << 16) | (offset & 0xffff);
2476
0
      msec = sec;
2477
0
      addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend);
2478
0
      addend -= relocation;
2479
0
      addend += msec->output_section->vma + msec->output_offset;
2480
0
      uvalue = addend;
2481
0
      hi16_offset = (uvalue >> 16) << 1;
2482
0
      hi16_value = (hi16_addend & (~(howto->dst_mask)))
2483
0
        | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
2484
0
      score_bfd_put_32 (input_bfd, hi16_value, contents + rel->r_offset - 4);
2485
0
      offset = (uvalue & 0xffff) << 1;
2486
0
      value = (value & (~(howto->dst_mask)))
2487
0
        | (offset & 0x7fff) | ((offset << 1) & 0x30000);
2488
0
      score_bfd_put_32 (input_bfd, value, contents + rel->r_offset);
2489
0
      break;
2490
2491
0
    case R_SCORE_IMM32:
2492
0
      {
2493
0
        value = score_bfd_get_48 (input_bfd, contents + rel->r_offset);
2494
0
        addend = ((value >> 5) & 0x3ff)
2495
0
            | (((value >> 16) & 0x7fff) << 10)
2496
0
            | (((value >> 32) & 0x7f) << 25);
2497
0
        msec = sec;
2498
0
        addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend);
2499
0
        addend -= relocation;
2500
0
        addend += msec->output_section->vma + msec->output_offset;
2501
0
        addend &= 0xffffffff;
2502
0
        value = (value & ~howto->src_mask)
2503
0
           | ((addend & 0x3ff) << 5)
2504
0
           | (((addend >> 10) & 0x7fff) << 16)
2505
0
           | (((addend >> 25) & 0x7f) << 32);
2506
0
        score_bfd_put_48 (input_bfd, value, contents + rel->r_offset);
2507
0
        break;
2508
0
      }
2509
2510
0
    case R_SCORE_IMM30:
2511
0
      {
2512
0
        int not_word_align_p = 0;
2513
0
        value = score_bfd_get_48 (input_bfd, contents + rel->r_offset);
2514
0
        addend = ((value >> 7) & 0xff)
2515
0
            | (((value >> 16) & 0x7fff) << 8)
2516
0
            | (((value >> 32) & 0x7f) << 23);
2517
0
        addend <<= howto->rightshift;
2518
0
        msec = sec;
2519
0
        addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend);
2520
0
        addend -= relocation;
2521
0
        addend += msec->output_section->vma + msec->output_offset;
2522
0
        addend &= 0xffffffff;
2523
2524
        /* Check lw48/sw48 rd, value/label word align.  */
2525
0
        if ((addend & 0x3) != 0)
2526
0
          not_word_align_p = 1;
2527
2528
0
        addend >>= howto->rightshift;
2529
0
        value = (value & ~howto->src_mask)
2530
0
           | (((addend & 0xff) >> 0) << 7)
2531
0
           | (((addend & 0x7fff00) >> 8) << 16)
2532
0
           | (((addend & 0x3f800000) >> 23) << 32);
2533
0
        score_bfd_put_48 (input_bfd, value, contents + rel->r_offset);
2534
2535
0
        if (not_word_align_p)
2536
0
          return bfd_reloc_other;
2537
0
        else
2538
0
          break;
2539
0
      }
2540
2541
0
    case R_SCORE_GOT_LO16:
2542
0
      value = score_bfd_get_32 (input_bfd, contents + rel->r_offset);
2543
0
      addend = (((value >> 16) & 0x3) << 14) | ((value & 0x7fff) >> 1);
2544
0
      msec = sec;
2545
0
      addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) - relocation;
2546
0
      addend += msec->output_section->vma + msec->output_offset;
2547
0
      value = (value & (~(howto->dst_mask))) | ((addend & 0x3fff) << 1)
2548
0
         | (((addend >> 14) & 0x3) << 16);
2549
2550
0
      score_bfd_put_32 (input_bfd, value, contents + rel->r_offset);
2551
0
      break;
2552
2553
0
    case R_SCORE_ABS32:
2554
0
    case R_SCORE_REL32:
2555
0
      value = bfd_get_32 (input_bfd, contents + rel->r_offset);
2556
      /* Get the (signed) value from the instruction.  */
2557
0
      addend = value & howto->src_mask;
2558
0
      if (addend & ((howto->src_mask + 1) >> 1))
2559
0
        {
2560
0
          bfd_signed_vma mask;
2561
2562
0
          mask = -1;
2563
0
          mask &= ~howto->src_mask;
2564
0
          addend |= mask;
2565
0
        }
2566
0
      msec = sec;
2567
0
      addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) - relocation;
2568
0
      addend += msec->output_section->vma + msec->output_offset;
2569
0
      value = (value & ~howto->dst_mask) | (addend & howto->dst_mask);
2570
0
      bfd_put_32 (input_bfd, value, contents + rel->r_offset);
2571
0
      break;
2572
2573
0
    default:
2574
0
      value = score_bfd_get_32 (input_bfd, contents + rel->r_offset);
2575
      /* Get the (signed) value from the instruction.  */
2576
0
      addend = value & howto->src_mask;
2577
0
      if (addend & ((howto->src_mask + 1) >> 1))
2578
0
        {
2579
0
          bfd_signed_vma mask;
2580
2581
0
          mask = -1;
2582
0
          mask &= ~howto->src_mask;
2583
0
          addend |= mask;
2584
0
        }
2585
0
      msec = sec;
2586
0
      addend = _bfd_elf_rel_local_sym (output_bfd, sym, &msec, addend) - relocation;
2587
0
      addend += msec->output_section->vma + msec->output_offset;
2588
0
      value = (value & ~howto->dst_mask) | (addend & howto->dst_mask);
2589
0
      score_bfd_put_32 (input_bfd, value, contents + rel->r_offset);
2590
0
      break;
2591
0
    }
2592
0
      }
2593
0
  }
2594
0
      else
2595
0
  {
2596
    /* For global symbols we look up the symbol in the hash-table.  */
2597
0
    h = ((struct score_elf_link_hash_entry *)
2598
0
         elf_sym_hashes (input_bfd) [r_symndx - extsymoff]);
2599
2600
0
    if (info->wrap_hash != NULL
2601
0
        && (input_section->flags & SEC_DEBUGGING) != 0)
2602
0
      h = ((struct score_elf_link_hash_entry *)
2603
0
     unwrap_hash_lookup (info, input_bfd, &h->root.root));
2604
2605
    /* Find the real hash-table entry for this symbol.  */
2606
0
    while (h->root.root.type == bfd_link_hash_indirect
2607
0
     || h->root.root.type == bfd_link_hash_warning)
2608
0
      h = (struct score_elf_link_hash_entry *) h->root.root.u.i.link;
2609
2610
    /* Record the name of this symbol, for our caller.  */
2611
0
    name = h->root.root.root.string;
2612
2613
    /* See if this is the special GP_DISP_LABEL symbol.  Note that such a
2614
       symbol must always be a global symbol.  */
2615
0
    if (strcmp (name, GP_DISP_LABEL) == 0)
2616
0
      {
2617
        /* Relocations against GP_DISP_LABEL are permitted only with
2618
     R_SCORE_HI16 and R_SCORE_LO16 relocations.  */
2619
0
        if (r_type != R_SCORE_HI16 && r_type != R_SCORE_LO16)
2620
0
    return bfd_reloc_notsupported;
2621
2622
0
        gp_disp_p = true;
2623
0
      }
2624
2625
    /* If this symbol is defined, calculate its address.  Note that
2626
        GP_DISP_LABEL is a magic symbol, always implicitly defined by the
2627
        linker, so it's inappropriate to check to see whether or not
2628
        its defined.  */
2629
0
    else if ((h->root.root.type == bfd_link_hash_defined
2630
0
        || h->root.root.type == bfd_link_hash_defweak)
2631
0
       && h->root.root.u.def.section)
2632
0
      {
2633
0
        sec = h->root.root.u.def.section;
2634
0
        if (sec->output_section)
2635
0
    relocation = (h->root.root.u.def.value
2636
0
            + sec->output_section->vma
2637
0
            + sec->output_offset);
2638
0
        else
2639
0
    {
2640
0
      relocation = h->root.root.u.def.value;
2641
0
    }
2642
0
      }
2643
0
    else if (h->root.root.type == bfd_link_hash_undefweak)
2644
      /* We allow relocations against undefined weak symbols, giving
2645
         it the value zero, so that you can undefined weak functions
2646
         and check to see if they exist by looking at their addresses.  */
2647
0
      relocation = 0;
2648
0
    else if (info->unresolved_syms_in_objects == RM_IGNORE
2649
0
       && ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT)
2650
0
      relocation = 0;
2651
0
    else if (strcmp (name, "_DYNAMIC_LINK") == 0)
2652
0
      {
2653
        /* If this is a dynamic link, we should have created a _DYNAMIC_LINK symbol
2654
     in s3_bfd_score_elf_create_dynamic_sections.  Otherwise, we should define
2655
     the symbol with a value of 0.  */
2656
0
        BFD_ASSERT (! bfd_link_pic (info));
2657
0
        BFD_ASSERT (bfd_get_section_by_name (output_bfd, ".dynamic") == NULL);
2658
0
        relocation = 0;
2659
0
      }
2660
0
    else if (!bfd_link_relocatable (info))
2661
0
      {
2662
0
              info->callbacks->undefined_symbol
2663
0
    (info, h->root.root.root.string, input_bfd, input_section,
2664
0
     rel->r_offset,
2665
0
     (info->unresolved_syms_in_objects == RM_DIAGNOSE
2666
0
      && !info->warn_unresolved_syms)
2667
0
     || ELF_ST_VISIBILITY (h->root.other));
2668
0
              relocation = 0;
2669
0
            }
2670
0
  }
2671
2672
0
      if (sec != NULL && discarded_section (sec))
2673
0
  RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
2674
0
           rel, 1, relend, howto, 0, contents);
2675
2676
0
      if (bfd_link_relocatable (info))
2677
0
  {
2678
    /* This is a relocatable link.  We don't have to change
2679
       anything, unless the reloc is against a section symbol,
2680
       in which case we have to adjust according to where the
2681
       section symbol winds up in the output section.  */
2682
0
    if (r_symndx < symtab_hdr->sh_info)
2683
0
      {
2684
0
        sym = local_syms + r_symndx;
2685
0
        if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
2686
0
    {
2687
0
      sec = local_sections[r_symndx];
2688
0
      score_elf_add_to_rel (input_bfd, contents + rel->r_offset,
2689
0
            howto, (bfd_signed_vma) (sec->output_offset + sym->st_value));
2690
0
    }
2691
0
      }
2692
0
    continue;
2693
0
  }
2694
2695
      /* This is a final link.  */
2696
0
      r = score_elf_final_link_relocate (howto, input_bfd, output_bfd,
2697
0
           input_section, contents, rel, relocs,
2698
0
           relocation, info, name,
2699
0
           (h ? ELF_ST_TYPE ((unsigned int)h->root.root.type) :
2700
0
           ELF_ST_TYPE ((unsigned int)sym->st_info)), h, local_sections,
2701
0
           gp_disp_p);
2702
2703
0
      if (r != bfd_reloc_ok)
2704
0
  {
2705
0
    const char *msg = (const char *)0;
2706
2707
0
    switch (r)
2708
0
      {
2709
0
      case bfd_reloc_overflow:
2710
        /* If the overflowing reloc was to an undefined symbol,
2711
     we have already printed one error message and there
2712
     is no point complaining again.  */
2713
0
        if (!h || h->root.root.type != bfd_link_hash_undefined)
2714
0
    (*info->callbacks->reloc_overflow)
2715
0
      (info, NULL, name, howto->name, (bfd_vma) 0,
2716
0
       input_bfd, input_section, rel->r_offset);
2717
0
        break;
2718
0
      case bfd_reloc_undefined:
2719
0
        (*info->callbacks->undefined_symbol)
2720
0
    (info, name, input_bfd, input_section, rel->r_offset, true);
2721
0
        break;
2722
2723
0
      case bfd_reloc_outofrange:
2724
0
        msg = _("internal error: out of range error");
2725
0
        goto common_error;
2726
2727
0
      case bfd_reloc_notsupported:
2728
0
        msg = _("internal error: unsupported relocation error");
2729
0
        goto common_error;
2730
2731
0
      case bfd_reloc_dangerous:
2732
0
        msg = _("internal error: dangerous error");
2733
0
        goto common_error;
2734
2735
      /* Use bfd_reloc_other to check lw48, sw48 word align.  */
2736
0
      case bfd_reloc_other:
2737
0
        msg = _("address not word aligned");
2738
0
        goto common_error;
2739
2740
0
      default:
2741
0
        msg = _("internal error: unknown error");
2742
        /* Fall through.  */
2743
2744
0
      common_error:
2745
0
        (*info->callbacks->warning) (info, msg, name, input_bfd,
2746
0
             input_section, rel->r_offset);
2747
0
        break;
2748
0
      }
2749
0
  }
2750
0
    }
2751
2752
0
  return true;
2753
0
}
2754
2755
/* Look through the relocs for a section during the first phase, and
2756
   allocate space in the global offset table.  */
2757
static bool
2758
s3_bfd_score_elf_check_relocs (bfd *abfd,
2759
             struct bfd_link_info *info,
2760
             asection *sec,
2761
             const Elf_Internal_Rela *relocs)
2762
0
{
2763
0
  bfd *dynobj;
2764
0
  Elf_Internal_Shdr *symtab_hdr;
2765
0
  struct elf_link_hash_entry **sym_hashes;
2766
0
  struct score_got_info *g;
2767
0
  size_t extsymoff;
2768
0
  const Elf_Internal_Rela *rel;
2769
0
  const Elf_Internal_Rela *rel_end;
2770
0
  asection *sgot;
2771
0
  asection *sreloc;
2772
2773
0
  if (bfd_link_relocatable (info))
2774
0
    return true;
2775
2776
0
  dynobj = elf_hash_table (info)->dynobj;
2777
0
  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
2778
0
  sym_hashes = elf_sym_hashes (abfd);
2779
0
  extsymoff = (elf_bad_symtab (abfd)) ? 0 : symtab_hdr->sh_info;
2780
2781
0
  if (dynobj == NULL)
2782
0
    {
2783
0
      sgot = NULL;
2784
0
      g = NULL;
2785
0
    }
2786
0
  else
2787
0
    {
2788
0
      sgot = score_elf_got_section (dynobj, false);
2789
0
      if (sgot == NULL)
2790
0
  g = NULL;
2791
0
      else
2792
0
  {
2793
0
    BFD_ASSERT (score_elf_section_data (sgot) != NULL);
2794
0
    g = score_elf_section_data (sgot)->u.got_info;
2795
0
    BFD_ASSERT (g != NULL);
2796
0
  }
2797
0
    }
2798
2799
0
  sreloc = NULL;
2800
0
  rel_end = relocs + sec->reloc_count;
2801
0
  for (rel = relocs; rel < rel_end; ++rel)
2802
0
    {
2803
0
      unsigned long r_symndx;
2804
0
      unsigned int r_type;
2805
0
      struct elf_link_hash_entry *h;
2806
2807
0
      r_symndx = ELF32_R_SYM (rel->r_info);
2808
0
      r_type = ELF32_R_TYPE (rel->r_info);
2809
2810
0
      if (r_symndx < extsymoff)
2811
0
  {
2812
0
    h = NULL;
2813
0
  }
2814
0
      else if (r_symndx >= extsymoff + NUM_SHDR_ENTRIES (symtab_hdr))
2815
0
  {
2816
0
    _bfd_error_handler
2817
      /* xgettext:c-format */
2818
0
      (_("%pB: malformed reloc detected for section %pA"), abfd, sec);
2819
0
    bfd_set_error (bfd_error_bad_value);
2820
0
    return false;
2821
0
  }
2822
0
      else
2823
0
  {
2824
0
    h = sym_hashes[r_symndx - extsymoff];
2825
2826
    /* This may be an indirect symbol created because of a version.  */
2827
0
    if (h != NULL)
2828
0
      {
2829
0
        while (h->root.type == bfd_link_hash_indirect)
2830
0
    h = (struct elf_link_hash_entry *)h->root.u.i.link;
2831
0
      }
2832
0
  }
2833
2834
      /* Some relocs require a global offset table.  */
2835
0
      if (dynobj == NULL || sgot == NULL)
2836
0
  {
2837
0
    switch (r_type)
2838
0
      {
2839
0
      case R_SCORE_GOT15:
2840
0
      case R_SCORE_CALL15:
2841
0
        if (dynobj == NULL)
2842
0
    elf_hash_table (info)->dynobj = dynobj = abfd;
2843
0
        if (!score_elf_create_got_section (dynobj, info, false))
2844
0
    return false;
2845
0
        g = score_elf_got_info (dynobj, &sgot);
2846
0
        break;
2847
0
      case R_SCORE_ABS32:
2848
0
      case R_SCORE_REL32:
2849
0
        if (dynobj == NULL
2850
0
      && (bfd_link_pic (info) || h != NULL)
2851
0
      && (sec->flags & SEC_ALLOC) != 0)
2852
0
    elf_hash_table (info)->dynobj = dynobj = abfd;
2853
0
        break;
2854
0
      default:
2855
0
        break;
2856
0
      }
2857
0
  }
2858
2859
0
      if (!h && (r_type == R_SCORE_GOT_LO16))
2860
0
  {
2861
0
    if (! score_elf_record_local_got_symbol (abfd, r_symndx, rel->r_addend, g))
2862
0
      return false;
2863
0
  }
2864
2865
0
      switch (r_type)
2866
0
  {
2867
0
  case R_SCORE_CALL15:
2868
0
    if (h == NULL)
2869
0
      {
2870
0
        _bfd_error_handler
2871
    /* xgettext:c-format */
2872
0
    (_("%pB: CALL15 reloc at %#" PRIx64 " not against global symbol"),
2873
0
     abfd, (uint64_t) rel->r_offset);
2874
0
        bfd_set_error (bfd_error_bad_value);
2875
0
        return false;
2876
0
      }
2877
0
    else
2878
0
      {
2879
        /* This symbol requires a global offset table entry.  */
2880
0
        if (! score_elf_record_global_got_symbol (h, abfd, info, g))
2881
0
    return false;
2882
2883
        /* We need a stub, not a plt entry for the undefined function.  But we record
2884
     it as if it needs plt.  See _bfd_elf_adjust_dynamic_symbol.  */
2885
0
        h->needs_plt = 1;
2886
0
        h->type = STT_FUNC;
2887
0
      }
2888
0
    break;
2889
0
  case R_SCORE_GOT15:
2890
0
    if (h && ! score_elf_record_global_got_symbol (h, abfd, info, g))
2891
0
      return false;
2892
0
    break;
2893
0
  case R_SCORE_ABS32:
2894
0
  case R_SCORE_REL32:
2895
0
    if ((bfd_link_pic (info) || h != NULL)
2896
0
        && (sec->flags & SEC_ALLOC) != 0)
2897
0
      {
2898
0
        if (sreloc == NULL)
2899
0
    {
2900
0
      sreloc = score_elf_rel_dyn_section (dynobj, true);
2901
0
      if (sreloc == NULL)
2902
0
        return false;
2903
0
    }
2904
0
#define SCORE_READONLY_SECTION (SEC_ALLOC | SEC_LOAD | SEC_READONLY)
2905
0
        if (bfd_link_pic (info))
2906
0
    {
2907
      /* When creating a shared object, we must copy these reloc types into
2908
         the output file as R_SCORE_REL32 relocs.  We make room for this reloc
2909
         in the .rel.dyn reloc section.  */
2910
0
      score_elf_allocate_dynamic_relocations (dynobj, 1);
2911
0
      if ((sec->flags & SCORE_READONLY_SECTION)
2912
0
          == SCORE_READONLY_SECTION)
2913
        /* We tell the dynamic linker that there are
2914
           relocations against the text segment.  */
2915
0
        info->flags |= DF_TEXTREL;
2916
0
    }
2917
0
        else
2918
0
    {
2919
0
      struct score_elf_link_hash_entry *hscore;
2920
2921
      /* We only need to copy this reloc if the symbol is
2922
         defined in a dynamic object.  */
2923
0
      hscore = (struct score_elf_link_hash_entry *)h;
2924
0
      ++hscore->possibly_dynamic_relocs;
2925
0
      if ((sec->flags & SCORE_READONLY_SECTION)
2926
0
          == SCORE_READONLY_SECTION)
2927
        /* We need it to tell the dynamic linker if there
2928
           are relocations against the text segment.  */
2929
0
        hscore->readonly_reloc = true;
2930
0
    }
2931
2932
        /* Even though we don't directly need a GOT entry for this symbol,
2933
     a symbol must have a dynamic symbol table index greater that
2934
     DT_SCORE_GOTSYM if there are dynamic relocations against it.  */
2935
0
        if (h != NULL)
2936
0
    {
2937
0
      if (dynobj == NULL)
2938
0
        elf_hash_table (info)->dynobj = dynobj = abfd;
2939
0
      if (! score_elf_create_got_section (dynobj, info, true))
2940
0
        return false;
2941
0
      g = score_elf_got_info (dynobj, &sgot);
2942
0
      if (! score_elf_record_global_got_symbol (h, abfd, info, g))
2943
0
        return false;
2944
0
    }
2945
0
      }
2946
0
    break;
2947
2948
    /* This relocation describes the C++ object vtable hierarchy.
2949
       Reconstruct it for later use during GC.  */
2950
0
  case R_SCORE_GNU_VTINHERIT:
2951
0
    if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2952
0
      return false;
2953
0
    break;
2954
2955
    /* This relocation describes which C++ vtable entries are actually
2956
       used.  Record for later use during GC.  */
2957
0
  case R_SCORE_GNU_VTENTRY:
2958
0
    if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset))
2959
0
      return false;
2960
0
    break;
2961
0
  default:
2962
0
    break;
2963
0
  }
2964
2965
      /* We must not create a stub for a symbol that has relocations
2966
   related to taking the function's address.  */
2967
0
      switch (r_type)
2968
0
  {
2969
0
  default:
2970
0
    if (h != NULL)
2971
0
      {
2972
0
        struct score_elf_link_hash_entry *sh;
2973
2974
0
        sh = (struct score_elf_link_hash_entry *) h;
2975
0
        sh->no_fn_stub = true;
2976
0
      }
2977
0
    break;
2978
0
  case R_SCORE_CALL15:
2979
0
    break;
2980
0
  }
2981
0
    }
2982
2983
0
  return true;
2984
0
}
2985
2986
static bool
2987
s3_bfd_score_elf_add_symbol_hook (bfd *abfd,
2988
          struct bfd_link_info *info ATTRIBUTE_UNUSED,
2989
          Elf_Internal_Sym *sym,
2990
          const char **namep ATTRIBUTE_UNUSED,
2991
          flagword *flagsp ATTRIBUTE_UNUSED,
2992
          asection **secp,
2993
          bfd_vma *valp)
2994
0
{
2995
0
  switch (sym->st_shndx)
2996
0
    {
2997
0
    case SHN_COMMON:
2998
0
      if (sym->st_size > elf_gp_size (abfd))
2999
0
  break;
3000
      /* Fall through.  */
3001
0
    case SHN_SCORE_SCOMMON:
3002
0
      *secp = bfd_make_section_old_way (abfd, ".scommon");
3003
0
      (*secp)->flags |= SEC_IS_COMMON | SEC_SMALL_DATA;
3004
0
      *valp = sym->st_size;
3005
0
      break;
3006
0
    }
3007
3008
0
  return true;
3009
0
}
3010
3011
static void
3012
s3_bfd_score_elf_symbol_processing (bfd *abfd, asymbol *asym)
3013
0
{
3014
0
  elf_symbol_type *elfsym;
3015
3016
0
  elfsym = (elf_symbol_type *) asym;
3017
0
  switch (elfsym->internal_elf_sym.st_shndx)
3018
0
    {
3019
0
    case SHN_COMMON:
3020
0
      if (asym->value > elf_gp_size (abfd))
3021
0
  break;
3022
      /* Fall through.  */
3023
0
    case SHN_SCORE_SCOMMON:
3024
0
      asym->section = &score_elf_scom_section;
3025
0
      asym->value = elfsym->internal_elf_sym.st_size;
3026
0
      break;
3027
0
    }
3028
0
}
3029
3030
static int
3031
s3_bfd_score_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
3032
            const char *name ATTRIBUTE_UNUSED,
3033
            Elf_Internal_Sym *sym,
3034
            asection *input_sec,
3035
            struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
3036
0
{
3037
  /* If we see a common symbol, which implies a relocatable link, then
3038
     if a symbol was small common in an input file, mark it as small
3039
     common in the output file.  */
3040
0
  if (sym->st_shndx == SHN_COMMON && strcmp (input_sec->name, ".scommon") == 0)
3041
0
    sym->st_shndx = SHN_SCORE_SCOMMON;
3042
3043
0
  return 1;
3044
0
}
3045
3046
static bool
3047
s3_bfd_score_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
3048
             asection *sec,
3049
             int *retval)
3050
0
{
3051
0
  if (strcmp (bfd_section_name (sec), ".scommon") == 0)
3052
0
    {
3053
0
      *retval = SHN_SCORE_SCOMMON;
3054
0
      return true;
3055
0
    }
3056
3057
0
  return false;
3058
0
}
3059
3060
/* Adjust a symbol defined by a dynamic object and referenced by a
3061
   regular object.  The current definition is in some section of the
3062
   dynamic object, but we're not including those sections.  We have to
3063
   change the definition to something the rest of the link can understand.  */
3064
static bool
3065
s3_bfd_score_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
3066
          struct elf_link_hash_entry *h)
3067
0
{
3068
0
  bfd *dynobj;
3069
0
  struct score_elf_link_hash_entry *hscore;
3070
0
  asection *s;
3071
3072
0
  dynobj = elf_hash_table (info)->dynobj;
3073
3074
  /* Make sure we know what is going on here.  */
3075
0
  BFD_ASSERT (dynobj != NULL
3076
0
        && (h->needs_plt
3077
0
      || h->is_weakalias
3078
0
      || (h->def_dynamic && h->ref_regular && !h->def_regular)));
3079
3080
  /* If this symbol is defined in a dynamic object, we need to copy
3081
     any R_SCORE_ABS32 or R_SCORE_REL32 relocs against it into the output
3082
     file.  */
3083
0
  hscore = (struct score_elf_link_hash_entry *)h;
3084
0
  if (!bfd_link_relocatable (info)
3085
0
      && hscore->possibly_dynamic_relocs != 0
3086
0
      && (h->root.type == bfd_link_hash_defweak || !h->def_regular))
3087
0
    {
3088
0
      score_elf_allocate_dynamic_relocations (dynobj, hscore->possibly_dynamic_relocs);
3089
0
      if (hscore->readonly_reloc)
3090
  /* We tell the dynamic linker that there are relocations
3091
     against the text segment.  */
3092
0
  info->flags |= DF_TEXTREL;
3093
0
    }
3094
3095
  /* For a function, create a stub, if allowed.  */
3096
0
  if (!hscore->no_fn_stub && h->needs_plt)
3097
0
    {
3098
0
      if (!elf_hash_table (info)->dynamic_sections_created)
3099
0
  return true;
3100
3101
      /* If this symbol is not defined in a regular file, then set
3102
   the symbol to the stub location.  This is required to make
3103
   function pointers compare as equal between the normal
3104
   executable and the shared library.  */
3105
0
      if (!h->def_regular)
3106
0
  {
3107
    /* We need .stub section.  */
3108
0
    s = bfd_get_linker_section (dynobj, SCORE_ELF_STUB_SECTION_NAME);
3109
0
    BFD_ASSERT (s != NULL);
3110
3111
0
    h->root.u.def.section = s;
3112
0
    h->root.u.def.value = s->size;
3113
3114
    /* XXX Write this stub address somewhere.  */
3115
0
    h->plt.offset = s->size;
3116
3117
    /* Make room for this stub code.  */
3118
0
    s->size += SCORE_FUNCTION_STUB_SIZE;
3119
3120
    /* The last half word of the stub will be filled with the index
3121
       of this symbol in .dynsym section.  */
3122
0
    return true;
3123
0
  }
3124
0
    }
3125
0
  else if ((h->type == STT_FUNC) && !h->needs_plt)
3126
0
    {
3127
      /* This will set the entry for this symbol in the GOT to 0, and
3128
   the dynamic linker will take care of this.  */
3129
0
      h->root.u.def.value = 0;
3130
0
      return true;
3131
0
    }
3132
3133
  /* If this is a weak symbol, and there is a real definition, the
3134
     processor independent code will have arranged for us to see the
3135
     real definition first, and we can just use the same value.  */
3136
0
  if (h->is_weakalias)
3137
0
    {
3138
0
      struct elf_link_hash_entry *def = weakdef (h);
3139
0
      BFD_ASSERT (def->root.type == bfd_link_hash_defined);
3140
0
      h->root.u.def.section = def->root.u.def.section;
3141
0
      h->root.u.def.value = def->root.u.def.value;
3142
0
      return true;
3143
0
    }
3144
3145
  /* This is a reference to a symbol defined by a dynamic object which
3146
     is not a function.  */
3147
0
  return true;
3148
0
}
3149
3150
/* This function is called after all the input files have been read,
3151
   and the input sections have been assigned to output sections.  */
3152
static bool
3153
s3_bfd_score_elf_early_size_sections (bfd *output_bfd,
3154
              struct bfd_link_info *info)
3155
0
{
3156
0
  bfd *dynobj;
3157
0
  asection *s;
3158
0
  struct score_got_info *g;
3159
0
  int i;
3160
0
  bfd_size_type loadable_size = 0;
3161
0
  bfd_size_type local_gotno;
3162
0
  bfd *sub;
3163
3164
0
  dynobj = elf_hash_table (info)->dynobj;
3165
0
  if (dynobj == NULL)
3166
    /* Relocatable links don't have it.  */
3167
0
    return true;
3168
3169
0
  g = score_elf_got_info (dynobj, &s);
3170
0
  if (s == NULL)
3171
0
    return true;
3172
3173
  /* Calculate the total loadable size of the output.  That will give us the
3174
     maximum number of GOT_PAGE entries required.  */
3175
0
  for (sub = info->input_bfds; sub; sub = sub->link.next)
3176
0
    {
3177
0
      asection *subsection;
3178
3179
0
      for (subsection = sub->sections;
3180
0
     subsection;
3181
0
     subsection = subsection->next)
3182
0
  {
3183
0
    if ((subsection->flags & SEC_ALLOC) == 0)
3184
0
      continue;
3185
0
    loadable_size += ((subsection->size + 0xf)
3186
0
          &~ (bfd_size_type) 0xf);
3187
0
  }
3188
0
    }
3189
3190
  /* There has to be a global GOT entry for every symbol with
3191
     a dynamic symbol table index of DT_SCORE_GOTSYM or
3192
     higher.  Therefore, it make sense to put those symbols
3193
     that need GOT entries at the end of the symbol table.  We
3194
     do that here.  */
3195
0
  if (! score_elf_sort_hash_table (info, 1))
3196
0
    return false;
3197
3198
0
  if (g->global_gotsym != NULL)
3199
0
    i = elf_hash_table (info)->dynsymcount - g->global_gotsym->dynindx;
3200
0
  else
3201
    /* If there are no global symbols, or none requiring
3202
       relocations, then GLOBAL_GOTSYM will be NULL.  */
3203
0
    i = 0;
3204
3205
  /* In the worst case, we'll get one stub per dynamic symbol.  */
3206
0
  loadable_size += SCORE_FUNCTION_STUB_SIZE * i;
3207
3208
  /* Assume there are two loadable segments consisting of
3209
     contiguous sections.  Is 5 enough?  */
3210
0
  local_gotno = (loadable_size >> 16) + 5;
3211
3212
0
  g->local_gotno += local_gotno;
3213
0
  s->size += g->local_gotno * SCORE_ELF_GOT_SIZE (output_bfd);
3214
3215
0
  g->global_gotno = i;
3216
0
  s->size += i * SCORE_ELF_GOT_SIZE (output_bfd);
3217
3218
0
  score_elf_resolve_final_got_entries (g);
3219
3220
0
  if (s->size > SCORE_ELF_GOT_MAX_SIZE (output_bfd))
3221
0
    {
3222
      /* Fixme. Error message or Warning message should be issued here.  */
3223
0
    }
3224
3225
0
  return true;
3226
0
}
3227
3228
/* Set the sizes of the dynamic sections.  */
3229
static bool
3230
s3_bfd_score_elf_late_size_sections (bfd *output_bfd, struct bfd_link_info *info)
3231
0
{
3232
0
  bfd *dynobj;
3233
0
  asection *s;
3234
0
  bool reltext;
3235
3236
0
  dynobj = elf_hash_table (info)->dynobj;
3237
0
  if (dynobj == NULL)
3238
0
    return true;
3239
3240
0
  if (elf_hash_table (info)->dynamic_sections_created)
3241
0
    {
3242
      /* Set the contents of the .interp section to the interpreter.  */
3243
0
      if (bfd_link_executable (info) && !info->nointerp)
3244
0
  {
3245
0
    s = bfd_get_linker_section (dynobj, ".interp");
3246
0
    BFD_ASSERT (s != NULL);
3247
0
    s->size = strlen (ELF_DYNAMIC_INTERPRETER) + 1;
3248
0
    s->contents = (bfd_byte *) ELF_DYNAMIC_INTERPRETER;
3249
0
    s->alloced = 1;
3250
0
  }
3251
0
    }
3252
3253
  /* The check_relocs and adjust_dynamic_symbol entry points have
3254
     determined the sizes of the various dynamic sections.  Allocate
3255
     memory for them.  */
3256
0
  reltext = false;
3257
0
  for (s = dynobj->sections; s != NULL; s = s->next)
3258
0
    {
3259
0
      const char *name;
3260
3261
0
      if ((s->flags & SEC_LINKER_CREATED) == 0)
3262
0
  continue;
3263
3264
      /* It's OK to base decisions on the section name, because none
3265
   of the dynobj section names depend upon the input files.  */
3266
0
      name = bfd_section_name (s);
3267
3268
0
      if (startswith (name, ".rel"))
3269
0
  {
3270
0
    if (s->size == 0)
3271
0
      {
3272
        /* We only strip the section if the output section name
3273
     has the same name.  Otherwise, there might be several
3274
     input sections for this output section.  FIXME: This
3275
     code is probably not needed these days anyhow, since
3276
     the linker now does not create empty output sections.  */
3277
0
        if (s->output_section != NULL
3278
0
      && strcmp (name,
3279
0
           bfd_section_name (s->output_section)) == 0)
3280
0
    s->flags |= SEC_EXCLUDE;
3281
0
      }
3282
0
    else
3283
0
      {
3284
0
        const char *outname;
3285
0
        asection *target;
3286
3287
        /* If this relocation section applies to a read only
3288
     section, then we probably need a DT_TEXTREL entry.
3289
     If the relocation section is .rel.dyn, we always
3290
     assert a DT_TEXTREL entry rather than testing whether
3291
     there exists a relocation to a read only section or
3292
     not.  */
3293
0
        outname = bfd_section_name (s->output_section);
3294
0
        target = bfd_get_section_by_name (output_bfd, outname + 4);
3295
0
        if ((target != NULL
3296
0
       && (target->flags & SEC_READONLY) != 0
3297
0
       && (target->flags & SEC_ALLOC) != 0) || strcmp (outname, ".rel.dyn") == 0)
3298
0
    reltext = true;
3299
3300
        /* We use the reloc_count field as a counter if we need
3301
     to copy relocs into the output file.  */
3302
0
        if (strcmp (name, ".rel.dyn") != 0)
3303
0
    s->reloc_count = 0;
3304
0
      }
3305
0
  }
3306
0
      else if (startswith (name, ".got"))
3307
0
  {
3308
    /* s3_bfd_score_elf_early_size_sections() has already done
3309
       most of the work, but some symbols may have been mapped
3310
       to versions that we must now resolve in the got_entries
3311
       hash tables.  */
3312
0
  }
3313
0
      else if (strcmp (name, SCORE_ELF_STUB_SECTION_NAME) == 0)
3314
0
  {
3315
    /* IRIX rld assumes that the function stub isn't at the end
3316
       of .text section. So put a dummy. XXX  */
3317
0
    s->size += SCORE_FUNCTION_STUB_SIZE;
3318
0
  }
3319
0
      else if (! startswith (name, ".init"))
3320
0
  {
3321
    /* It's not one of our sections, so don't allocate space.  */
3322
0
    continue;
3323
0
  }
3324
3325
      /* Allocate memory for the section contents.  */
3326
0
      s->contents = bfd_zalloc (dynobj, s->size);
3327
0
      if (s->contents == NULL && s->size != 0)
3328
0
  {
3329
0
    bfd_set_error (bfd_error_no_memory);
3330
0
    return false;
3331
0
  }
3332
0
      s->alloced = 1;
3333
0
    }
3334
3335
0
  if (elf_hash_table (info)->dynamic_sections_created)
3336
0
    {
3337
      /* Add some entries to the .dynamic section.  We fill in the
3338
   values later, in s3_bfd_score_elf_finish_dynamic_sections, but we
3339
   must add the entries now so that we get the correct size for
3340
   the .dynamic section.  The DT_DEBUG entry is filled in by the
3341
   dynamic linker and used by the debugger.  */
3342
3343
0
      if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0))
3344
0
  return false;
3345
3346
0
      if (reltext)
3347
0
  info->flags |= DF_TEXTREL;
3348
3349
0
      if ((info->flags & DF_TEXTREL) != 0)
3350
0
  {
3351
0
    if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_TEXTREL, 0))
3352
0
      return false;
3353
0
  }
3354
3355
0
      if (! SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_PLTGOT, 0))
3356
0
  return false;
3357
3358
0
      if (score_elf_rel_dyn_section (dynobj, false))
3359
0
  {
3360
0
    if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_REL, 0))
3361
0
      return false;
3362
3363
0
    if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELSZ, 0))
3364
0
      return false;
3365
3366
0
    if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELENT, 0))
3367
0
      return false;
3368
0
  }
3369
3370
0
      if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_BASE_ADDRESS, 0))
3371
0
  return false;
3372
3373
0
      if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_LOCAL_GOTNO, 0))
3374
0
  return false;
3375
3376
0
      if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_SYMTABNO, 0))
3377
0
  return false;
3378
3379
0
      if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_UNREFEXTNO, 0))
3380
0
  return false;
3381
3382
0
      if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_GOTSYM, 0))
3383
0
  return false;
3384
3385
0
      if (!SCORE_ELF_ADD_DYNAMIC_ENTRY (info, DT_SCORE_HIPAGENO, 0))
3386
0
  return false;
3387
0
    }
3388
3389
0
  return true;
3390
0
}
3391
3392
static bool
3393
s3_bfd_score_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
3394
0
{
3395
0
  struct elf_link_hash_entry *h;
3396
0
  struct bfd_link_hash_entry *bh;
3397
0
  flagword flags;
3398
0
  asection *s;
3399
3400
0
  flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY
3401
0
     | SEC_LINKER_CREATED | SEC_READONLY);
3402
3403
  /* ABI requests the .dynamic section to be read only.  */
3404
0
  s = bfd_get_linker_section (abfd, ".dynamic");
3405
0
  if (s != NULL)
3406
0
    {
3407
0
      if (!bfd_set_section_flags (s, flags))
3408
0
  return false;
3409
0
    }
3410
3411
  /* We need to create .got section.  */
3412
0
  if (!score_elf_create_got_section (abfd, info, false))
3413
0
    return false;
3414
3415
0
  if (!score_elf_rel_dyn_section (elf_hash_table (info)->dynobj, true))
3416
0
    return false;
3417
3418
  /* Create .stub section.  */
3419
0
  if (bfd_get_linker_section (abfd, SCORE_ELF_STUB_SECTION_NAME) == NULL)
3420
0
    {
3421
0
      s = bfd_make_section_anyway_with_flags (abfd, SCORE_ELF_STUB_SECTION_NAME,
3422
0
                flags | SEC_CODE);
3423
0
      if (s == NULL
3424
0
    || !bfd_set_section_alignment (s, 2))
3425
3426
0
  return false;
3427
0
    }
3428
3429
0
  if (!bfd_link_pic (info))
3430
0
    {
3431
0
      const char *name;
3432
3433
0
      name = "_DYNAMIC_LINK";
3434
0
      bh = NULL;
3435
0
      if (!(_bfd_generic_link_add_one_symbol
3436
0
      (info, abfd, name, BSF_GLOBAL, bfd_abs_section_ptr,
3437
0
       (bfd_vma) 0, NULL, false, get_elf_backend_data (abfd)->collect, &bh)))
3438
0
  return false;
3439
3440
0
      h = (struct elf_link_hash_entry *)bh;
3441
0
      h->non_elf = 0;
3442
0
      h->def_regular = 1;
3443
0
      h->type = STT_SECTION;
3444
3445
0
      if (!bfd_elf_link_record_dynamic_symbol (info, h))
3446
0
  return false;
3447
0
    }
3448
3449
0
  return true;
3450
0
}
3451
3452
3453
/* Finish up dynamic symbol handling.  We set the contents of various
3454
   dynamic sections here.  */
3455
static bool
3456
s3_bfd_score_elf_finish_dynamic_symbol (bfd *output_bfd,
3457
          struct bfd_link_info *info,
3458
          struct elf_link_hash_entry *h,
3459
          Elf_Internal_Sym *sym)
3460
0
{
3461
0
  bfd *dynobj;
3462
0
  asection *sgot;
3463
0
  struct score_got_info *g;
3464
0
  const char *name;
3465
3466
0
  dynobj = elf_hash_table (info)->dynobj;
3467
3468
0
  if (h->plt.offset != MINUS_ONE)
3469
0
    {
3470
0
      asection *s;
3471
0
      bfd_byte stub[SCORE_FUNCTION_STUB_SIZE];
3472
3473
      /* This symbol has a stub.  Set it up.  */
3474
0
      BFD_ASSERT (h->dynindx != -1);
3475
3476
0
      s = bfd_get_linker_section (dynobj, SCORE_ELF_STUB_SECTION_NAME);
3477
0
      BFD_ASSERT (s != NULL);
3478
3479
      /* FIXME: Can h->dynindex be more than 64K?  */
3480
0
      if (h->dynindx & 0xffff0000)
3481
0
  {
3482
0
    _bfd_error_handler
3483
0
      (_("%pB: cannot handle more than %d dynamic symbols"),
3484
0
       output_bfd, 0xffff);
3485
0
    bfd_set_error (bfd_error_bad_value);
3486
0
    return false;
3487
0
  }
3488
3489
      /* Fill the stub.  */
3490
0
      score_bfd_put_32 (output_bfd, STUB_LW, stub);
3491
0
      score_bfd_put_32 (output_bfd, STUB_MOVE, stub + 4);
3492
0
      score_bfd_put_32 (output_bfd, STUB_LI16 | (h->dynindx << 1), stub + 8);
3493
0
      score_bfd_put_32 (output_bfd, STUB_BRL, stub + 12);
3494
3495
0
      BFD_ASSERT (h->plt.offset <= s->size);
3496
0
      memcpy (s->contents + h->plt.offset, stub, SCORE_FUNCTION_STUB_SIZE);
3497
3498
      /* Mark the symbol as undefined.  plt.offset != -1 occurs
3499
   only for the referenced symbol.  */
3500
0
      sym->st_shndx = SHN_UNDEF;
3501
3502
      /* The run-time linker uses the st_value field of the symbol
3503
    to reset the global offset table entry for this external
3504
    to its stub address when unlinking a shared object.  */
3505
0
      sym->st_value = (s->output_section->vma + s->output_offset + h->plt.offset);
3506
0
    }
3507
3508
0
  BFD_ASSERT (h->dynindx != -1 || h->forced_local);
3509
3510
0
  sgot = score_elf_got_section (dynobj, false);
3511
0
  BFD_ASSERT (sgot != NULL);
3512
0
  BFD_ASSERT (score_elf_section_data (sgot) != NULL);
3513
0
  g = score_elf_section_data (sgot)->u.got_info;
3514
0
  BFD_ASSERT (g != NULL);
3515
3516
  /* Run through the global symbol table, creating GOT entries for all
3517
     the symbols that need them.  */
3518
0
  if (g->global_gotsym != NULL && h->dynindx >= g->global_gotsym->dynindx)
3519
0
    {
3520
0
      bfd_vma offset;
3521
0
      bfd_vma value;
3522
3523
0
      value = sym->st_value;
3524
0
      offset = score_elf_global_got_index (dynobj, h);
3525
0
      score_bfd_put_32 (output_bfd, value, sgot->contents + offset);
3526
0
    }
3527
3528
  /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute.  */
3529
0
  name = h->root.root.string;
3530
0
  if (h == elf_hash_table (info)->hdynamic
3531
0
      || h == elf_hash_table (info)->hgot)
3532
0
    sym->st_shndx = SHN_ABS;
3533
0
  else if (strcmp (name, "_DYNAMIC_LINK") == 0)
3534
0
    {
3535
0
      sym->st_shndx = SHN_ABS;
3536
0
      sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
3537
0
      sym->st_value = 1;
3538
0
    }
3539
0
  else if (strcmp (name, GP_DISP_LABEL) == 0)
3540
0
    {
3541
0
      sym->st_shndx = SHN_ABS;
3542
0
      sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION);
3543
0
      sym->st_value = elf_gp (output_bfd);
3544
0
    }
3545
3546
0
  return true;
3547
0
}
3548
3549
/* Finish up the dynamic sections.  */
3550
static bool
3551
s3_bfd_score_elf_finish_dynamic_sections (bfd *output_bfd,
3552
            struct bfd_link_info *info)
3553
0
{
3554
0
  bfd *dynobj;
3555
0
  asection *sdyn;
3556
0
  asection *sgot;
3557
0
  asection *s;
3558
0
  struct score_got_info *g;
3559
3560
0
  dynobj = elf_hash_table (info)->dynobj;
3561
3562
0
  sdyn = bfd_get_linker_section (dynobj, ".dynamic");
3563
3564
0
  sgot = score_elf_got_section (dynobj, false);
3565
0
  if (sgot == NULL)
3566
0
    g = NULL;
3567
0
  else
3568
0
    {
3569
0
      BFD_ASSERT (score_elf_section_data (sgot) != NULL);
3570
0
      g = score_elf_section_data (sgot)->u.got_info;
3571
0
      BFD_ASSERT (g != NULL);
3572
0
    }
3573
3574
0
  if (elf_hash_table (info)->dynamic_sections_created)
3575
0
    {
3576
0
      bfd_byte *b;
3577
3578
0
      BFD_ASSERT (sdyn != NULL);
3579
0
      BFD_ASSERT (g != NULL);
3580
3581
0
      for (b = sdyn->contents;
3582
0
     b < sdyn->contents + sdyn->size;
3583
0
     b += SCORE_ELF_DYN_SIZE (dynobj))
3584
0
  {
3585
0
    Elf_Internal_Dyn dyn;
3586
0
    const char *name;
3587
0
    size_t elemsize;
3588
0
    bool swap_out_p;
3589
3590
    /* Read in the current dynamic entry.  */
3591
0
    (*get_elf_backend_data (dynobj)->s->swap_dyn_in) (dynobj, b, &dyn);
3592
3593
    /* Assume that we're going to modify it and write it out.  */
3594
0
    swap_out_p = true;
3595
3596
0
    switch (dyn.d_tag)
3597
0
      {
3598
0
      case DT_RELENT:
3599
0
        dyn.d_un.d_val = SCORE_ELF_REL_SIZE (dynobj);
3600
0
        break;
3601
3602
0
      case DT_STRSZ:
3603
        /* Rewrite DT_STRSZ.  */
3604
0
        dyn.d_un.d_val
3605
0
    = _bfd_elf_strtab_size (elf_hash_table (info)->dynstr);
3606
0
        break;
3607
3608
0
      case DT_PLTGOT:
3609
0
        s = elf_hash_table (info)->sgot;
3610
0
        dyn.d_un.d_ptr = s->output_section->vma + s->output_offset;
3611
0
        break;
3612
3613
0
      case DT_SCORE_BASE_ADDRESS:
3614
0
        s = output_bfd->sections;
3615
0
        BFD_ASSERT (s != NULL);
3616
0
        dyn.d_un.d_ptr = s->vma & ~(bfd_vma) 0xffff;
3617
0
        break;
3618
3619
0
      case DT_SCORE_LOCAL_GOTNO:
3620
0
        dyn.d_un.d_val = g->local_gotno;
3621
0
        break;
3622
3623
0
      case DT_SCORE_UNREFEXTNO:
3624
        /* The index into the dynamic symbol table which is the
3625
     entry of the first external symbol that is not
3626
     referenced within the same object.  */
3627
0
        dyn.d_un.d_val = bfd_count_sections (output_bfd) + 1;
3628
0
        break;
3629
3630
0
      case DT_SCORE_GOTSYM:
3631
0
        if (g->global_gotsym)
3632
0
    {
3633
0
      dyn.d_un.d_val = g->global_gotsym->dynindx;
3634
0
      break;
3635
0
    }
3636
        /* In case if we don't have global got symbols we default
3637
      to setting DT_SCORE_GOTSYM to the same value as
3638
      DT_SCORE_SYMTABNO.  */
3639
        /* Fall through.  */
3640
3641
0
      case DT_SCORE_SYMTABNO:
3642
0
        name = ".dynsym";
3643
0
        elemsize = SCORE_ELF_SYM_SIZE (output_bfd);
3644
0
        s = bfd_get_linker_section (dynobj, name);
3645
0
        dyn.d_un.d_val = s->size / elemsize;
3646
0
        break;
3647
3648
0
      case DT_SCORE_HIPAGENO:
3649
0
        dyn.d_un.d_val = g->local_gotno - SCORE_RESERVED_GOTNO;
3650
0
        break;
3651
3652
0
      default:
3653
0
        swap_out_p = false;
3654
0
        break;
3655
0
      }
3656
3657
0
    if (swap_out_p)
3658
0
      (*get_elf_backend_data (dynobj)->s->swap_dyn_out) (dynobj, &dyn, b);
3659
0
  }
3660
0
    }
3661
3662
  /* The first entry of the global offset table will be filled at
3663
     runtime. The second entry will be used by some runtime loaders.
3664
     This isn't the case of IRIX rld.  */
3665
0
  if (sgot != NULL && sgot->size > 0)
3666
0
    {
3667
0
      score_bfd_put_32 (output_bfd, 0, sgot->contents);
3668
0
      score_bfd_put_32 (output_bfd, 0x80000000, sgot->contents + SCORE_ELF_GOT_SIZE (output_bfd));
3669
0
    }
3670
3671
0
  if (sgot != NULL)
3672
0
    elf_section_data (sgot->output_section)->this_hdr.sh_entsize
3673
0
      = SCORE_ELF_GOT_SIZE (output_bfd);
3674
3675
3676
  /* We need to sort the entries of the dynamic relocation section.  */
3677
0
  s = score_elf_rel_dyn_section (dynobj, false);
3678
3679
0
  if (s != NULL && s->size > (bfd_vma)2 * SCORE_ELF_REL_SIZE (output_bfd))
3680
0
    {
3681
0
      reldyn_sorting_bfd = output_bfd;
3682
0
      qsort ((Elf32_External_Rel *) s->contents + 1, s->reloc_count - 1,
3683
0
       sizeof (Elf32_External_Rel), score_elf_sort_dynamic_relocs);
3684
0
    }
3685
3686
0
  return true;
3687
0
}
3688
3689
/* This function set up the ELF section header for a BFD section in preparation for writing
3690
   it out.  This is where the flags and type fields are set for unusual sections.  */
3691
static bool
3692
s3_bfd_score_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
3693
        Elf_Internal_Shdr *hdr,
3694
        asection *sec)
3695
0
{
3696
0
  const char *name;
3697
3698
0
  name = bfd_section_name (sec);
3699
3700
0
  if (strcmp (name, ".got") == 0
3701
0
      || strcmp (name, ".srdata") == 0
3702
0
      || strcmp (name, ".sdata") == 0
3703
0
      || strcmp (name, ".sbss") == 0)
3704
0
    hdr->sh_flags |= SHF_SCORE_GPREL;
3705
3706
0
  return true;
3707
0
}
3708
3709
/* This function do additional processing on the ELF section header before writing
3710
   it out.  This is used to set the flags and type fields for some sections.  */
3711
3712
/* assign_file_positions_except_relocs() check section flag and if it is allocatable,
3713
   warning message will be issued.  backend_fake_section is called before
3714
   assign_file_positions_except_relocs(); backend_section_processing after it.  so, we
3715
   modify section flag there, but not backend_fake_section.  */
3716
static bool
3717
s3_bfd_score_elf_section_processing (bfd *abfd ATTRIBUTE_UNUSED, Elf_Internal_Shdr *hdr)
3718
0
{
3719
0
  if (hdr->bfd_section != NULL)
3720
0
    {
3721
0
      const char *name = bfd_section_name (hdr->bfd_section);
3722
3723
0
      if (strcmp (name, ".sdata") == 0)
3724
0
  {
3725
0
    hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_SCORE_GPREL;
3726
0
    hdr->sh_type = SHT_PROGBITS;
3727
0
  }
3728
0
      else if (strcmp (name, ".sbss") == 0)
3729
0
  {
3730
0
    hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_SCORE_GPREL;
3731
0
    hdr->sh_type = SHT_NOBITS;
3732
0
  }
3733
0
      else if (strcmp (name, ".srdata") == 0)
3734
0
  {
3735
0
    hdr->sh_flags |= SHF_ALLOC | SHF_SCORE_GPREL;
3736
0
    hdr->sh_type = SHT_PROGBITS;
3737
0
  }
3738
0
    }
3739
3740
0
  return true;
3741
0
}
3742
3743
static bool
3744
s3_bfd_score_elf_write_section (bfd *output_bfd, asection *sec, bfd_byte *contents)
3745
0
{
3746
0
  bfd_byte *to, *from, *end;
3747
0
  int i;
3748
3749
0
  if (strcmp (sec->name, ".pdr") != 0)
3750
0
    return false;
3751
3752
0
  if (score_elf_section_data (sec)->u.tdata == NULL)
3753
0
    return false;
3754
3755
0
  to = contents;
3756
0
  end = contents + sec->size;
3757
0
  for (from = contents, i = 0; from < end; from += PDR_SIZE, i++)
3758
0
    {
3759
0
      if ((score_elf_section_data (sec)->u.tdata)[i] == 1)
3760
0
  continue;
3761
3762
0
      if (to != from)
3763
0
  memcpy (to, from, PDR_SIZE);
3764
3765
0
      to += PDR_SIZE;
3766
0
    }
3767
0
  bfd_set_section_contents (output_bfd, sec->output_section, contents,
3768
0
          (file_ptr) sec->output_offset, sec->size);
3769
3770
0
  return true;
3771
0
}
3772
3773
/* Copy data from a SCORE ELF indirect symbol to its direct symbol, hiding the old
3774
   indirect symbol.  Process additional relocation information.  */
3775
static void
3776
s3_bfd_score_elf_copy_indirect_symbol (struct bfd_link_info *info,
3777
               struct elf_link_hash_entry *dir,
3778
               struct elf_link_hash_entry *ind)
3779
0
{
3780
0
  struct score_elf_link_hash_entry *dirscore, *indscore;
3781
3782
0
  _bfd_elf_link_hash_copy_indirect (info, dir, ind);
3783
3784
0
  if (ind->root.type != bfd_link_hash_indirect)
3785
0
    return;
3786
3787
0
  dirscore = (struct score_elf_link_hash_entry *) dir;
3788
0
  indscore = (struct score_elf_link_hash_entry *) ind;
3789
0
  dirscore->possibly_dynamic_relocs += indscore->possibly_dynamic_relocs;
3790
3791
0
  if (indscore->readonly_reloc)
3792
0
    dirscore->readonly_reloc = true;
3793
3794
0
  if (indscore->no_fn_stub)
3795
0
    dirscore->no_fn_stub = true;
3796
0
}
3797
3798
/* Remove information about discarded functions from other sections which mention them.  */
3799
static bool
3800
s3_bfd_score_elf_discard_info (bfd *abfd, struct elf_reloc_cookie *cookie,
3801
             struct bfd_link_info *info)
3802
0
{
3803
0
  asection *o;
3804
0
  bool ret = false;
3805
0
  unsigned char *tdata;
3806
0
  size_t i, skip;
3807
3808
0
  o = bfd_get_section_by_name (abfd, ".pdr");
3809
0
  if ((!o) || (o->size == 0) || (o->size % PDR_SIZE != 0)
3810
0
      || (o->output_section != NULL && bfd_is_abs_section (o->output_section)))
3811
0
    return false;
3812
3813
0
  tdata = bfd_zmalloc (o->size / PDR_SIZE);
3814
0
  if (!tdata)
3815
0
    return false;
3816
3817
0
  cookie->rels = _bfd_elf_link_read_relocs (abfd, o, NULL, NULL, info->keep_memory);
3818
0
  if (!cookie->rels)
3819
0
    {
3820
0
      free (tdata);
3821
0
      return false;
3822
0
    }
3823
3824
0
  cookie->rel = cookie->rels;
3825
0
  cookie->relend = cookie->rels + o->reloc_count;
3826
3827
0
  for (i = 0, skip = 0; i < o->size; i++)
3828
0
    {
3829
0
      if (bfd_elf_reloc_symbol_deleted_p (i * PDR_SIZE, cookie))
3830
0
  {
3831
0
    tdata[i] = 1;
3832
0
    skip++;
3833
0
  }
3834
0
    }
3835
3836
0
  if (skip != 0)
3837
0
    {
3838
0
      score_elf_section_data (o)->u.tdata = tdata;
3839
0
      o->size -= skip * PDR_SIZE;
3840
0
      ret = true;
3841
0
    }
3842
0
  else
3843
0
    free (tdata);
3844
3845
0
  if (!info->keep_memory)
3846
0
    free (cookie->rels);
3847
3848
0
  return ret;
3849
0
}
3850
3851
/* Signal that discard_info() has removed the discarded relocations for this section.  */
3852
static bool
3853
s3_bfd_score_elf_ignore_discarded_relocs (asection *sec)
3854
0
{
3855
0
  if (strcmp (sec->name, ".pdr") == 0)
3856
0
    return true;
3857
0
  return false;
3858
0
}
3859
3860
/* Return the section that should be marked against GC for a given
3861
   relocation.  */
3862
static asection *
3863
s3_bfd_score_elf_gc_mark_hook (asection *sec,
3864
             struct bfd_link_info *info,
3865
             Elf_Internal_Rela *rel,
3866
             struct elf_link_hash_entry *h,
3867
             Elf_Internal_Sym *sym)
3868
0
{
3869
0
  if (h != NULL)
3870
0
    switch (ELF32_R_TYPE (rel->r_info))
3871
0
      {
3872
0
      case R_SCORE_GNU_VTINHERIT:
3873
0
      case R_SCORE_GNU_VTENTRY:
3874
0
  return NULL;
3875
0
      }
3876
3877
0
  return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym);
3878
0
}
3879
3880
/* Support for core dump NOTE sections.  */
3881
3882
static bool
3883
s3_bfd_score_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
3884
0
{
3885
0
  int offset;
3886
0
  unsigned int raw_size;
3887
3888
0
  switch (note->descsz)
3889
0
    {
3890
0
    default:
3891
0
      return false;
3892
3893
0
    case 148:          /* Linux/Score 32-bit.  */
3894
      /* pr_cursig */
3895
0
      elf_tdata (abfd)->core->signal
3896
0
  = score_bfd_get_16 (abfd, note->descdata + 12);
3897
3898
      /* pr_pid */
3899
0
      elf_tdata (abfd)->core->lwpid
3900
0
  = score_bfd_get_32 (abfd, note->descdata + 24);
3901
3902
      /* pr_reg */
3903
0
      offset = 72;
3904
0
      raw_size = 72;
3905
3906
0
      break;
3907
0
    }
3908
3909
  /* Make a ".reg/999" section.  */
3910
0
  return _bfd_elfcore_make_pseudosection (abfd, ".reg", raw_size,
3911
0
            note->descpos + offset);
3912
0
}
3913
3914
static bool
3915
s3_bfd_score_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
3916
0
{
3917
0
  switch (note->descsz)
3918
0
    {
3919
0
    default:
3920
0
      return false;
3921
3922
0
    case 124:          /* Linux/Score elf_prpsinfo.  */
3923
0
      elf_tdata (abfd)->core->program
3924
0
  = _bfd_elfcore_strndup (abfd, note->descdata + 28, 16);
3925
0
      elf_tdata (abfd)->core->command
3926
0
  = _bfd_elfcore_strndup (abfd, note->descdata + 44, 80);
3927
0
    }
3928
3929
  /* Note that for some reason, a spurious space is tacked
3930
     onto the end of the args in some (at least one anyway)
3931
     implementations, so strip it off if it exists.  */
3932
3933
0
  {
3934
0
    char *command = elf_tdata (abfd)->core->command;
3935
0
    int n = strlen (command);
3936
3937
0
    if (0 < n && command[n - 1] == ' ')
3938
0
      command[n - 1] = '\0';
3939
0
  }
3940
3941
0
  return true;
3942
0
}
3943
3944
3945
/* Score BFD functions.  */
3946
static reloc_howto_type *
3947
s3_elf32_score_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code)
3948
0
{
3949
0
  unsigned int i;
3950
3951
0
  for (i = 0; i < ARRAY_SIZE (elf32_score_reloc_map); i++)
3952
0
    if (elf32_score_reloc_map[i].bfd_reloc_val == code)
3953
0
      return &elf32_score_howto_table[elf32_score_reloc_map[i].elf_reloc_val];
3954
3955
0
  return NULL;
3956
0
}
3957
3958
static reloc_howto_type *
3959
elf32_score_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
3960
             const char *r_name)
3961
0
{
3962
0
  unsigned int i;
3963
3964
0
  for (i = 0;
3965
0
       i < (sizeof (elf32_score_howto_table)
3966
0
      / sizeof (elf32_score_howto_table[0]));
3967
0
       i++)
3968
0
    if (elf32_score_howto_table[i].name != NULL
3969
0
  && strcasecmp (elf32_score_howto_table[i].name, r_name) == 0)
3970
0
      return &elf32_score_howto_table[i];
3971
3972
0
  return NULL;
3973
0
}
3974
3975
static bool
3976
s3_elf32_score_print_private_bfd_data (bfd *abfd, void * ptr)
3977
33
{
3978
33
  FILE *file = (FILE *) ptr;
3979
3980
33
  BFD_ASSERT (abfd != NULL && ptr != NULL);
3981
3982
  /* Print normal ELF private data.  */
3983
33
  _bfd_elf_print_private_bfd_data (abfd, ptr);
3984
3985
  /* xgettext:c-format */
3986
33
  fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags);
3987
33
  if (elf_elfheader (abfd)->e_flags & EF_SCORE_PIC)
3988
2
    {
3989
2
      fprintf (file, _(" [pic]"));
3990
2
    }
3991
33
  if (elf_elfheader (abfd)->e_flags & EF_SCORE_FIXDEP)
3992
1
    {
3993
1
      fprintf (file, _(" [fix dep]"));
3994
1
    }
3995
33
  fputc ('\n', file);
3996
3997
33
  return true;
3998
33
}
3999
4000
static bool
4001
s3_elf32_score_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
4002
0
{
4003
0
  bfd *obfd = info->output_bfd;
4004
0
  flagword in_flags;
4005
0
  flagword out_flags;
4006
4007
0
  if (!_bfd_generic_verify_endian_match (ibfd, info))
4008
0
    return false;
4009
4010
  /* FIXME: What should be checked when linking shared libraries?  */
4011
0
  if ((ibfd->flags & DYNAMIC) != 0)
4012
0
    return true;
4013
4014
0
  in_flags  = elf_elfheader (ibfd)->e_flags;
4015
0
  out_flags = elf_elfheader (obfd)->e_flags;
4016
4017
0
  if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour
4018
0
      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)
4019
0
    return true;
4020
4021
0
  in_flags = elf_elfheader (ibfd)->e_flags;
4022
0
  out_flags = elf_elfheader (obfd)->e_flags;
4023
4024
0
  if (! elf_flags_init (obfd))
4025
0
    {
4026
0
      elf_flags_init (obfd) = true;
4027
0
      elf_elfheader (obfd)->e_flags = in_flags;
4028
4029
0
      if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)
4030
0
    && bfd_get_arch_info (obfd)->the_default)
4031
0
  {
4032
0
    return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));
4033
0
  }
4034
4035
0
      return true;
4036
0
    }
4037
4038
0
  if (((in_flags & EF_SCORE_PIC) != 0) != ((out_flags & EF_SCORE_PIC) != 0))
4039
0
    _bfd_error_handler
4040
0
      (_("%pB: warning: linking PIC files with non-PIC files"), ibfd);
4041
4042
  /* FIXME: Maybe dependency fix compatibility should be checked here.  */
4043
4044
0
  return true;
4045
0
}
4046
4047
static bool
4048
s3_elf32_score_new_section_hook (bfd *abfd, asection *sec)
4049
11.2k
{
4050
11.2k
  struct _score_elf_section_data *sdata;
4051
4052
11.2k
  sdata = bfd_zalloc (abfd, sizeof (*sdata));
4053
11.2k
  if (sdata == NULL)
4054
0
    return false;
4055
11.2k
  sec->used_by_bfd = sdata;
4056
4057
11.2k
  return _bfd_elf_new_section_hook (abfd, sec);
4058
11.2k
}
4059
4060
/*****************************************************************************/
4061
4062
/* s3_s7: backend hooks.  */
4063
static bool
4064
_bfd_score_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
4065
        arelent *bfd_reloc,
4066
        Elf_Internal_Rela *elf_reloc)
4067
39
{
4068
39
  if (bfd_get_mach (abfd) == bfd_mach_score3)
4069
0
    return s3_bfd_score_info_to_howto (abfd, bfd_reloc, elf_reloc);
4070
39
  else
4071
39
    return s7_bfd_score_info_to_howto (abfd, bfd_reloc, elf_reloc);
4072
39
}
4073
4074
static int
4075
_bfd_score_elf_relocate_section (bfd *output_bfd,
4076
         struct bfd_link_info *info,
4077
         bfd *input_bfd,
4078
         asection *input_section,
4079
         bfd_byte *contents,
4080
         Elf_Internal_Rela *relocs,
4081
         Elf_Internal_Sym *local_syms,
4082
         asection **local_sections)
4083
0
{
4084
0
  if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4085
0
    return s3_bfd_score_elf_relocate_section (output_bfd,
4086
0
       info, input_bfd, input_section, contents, relocs,
4087
0
       local_syms, local_sections);
4088
0
  else
4089
0
    return s7_bfd_score_elf_relocate_section (output_bfd,
4090
0
       info, input_bfd, input_section, contents, relocs,
4091
0
       local_syms, local_sections);
4092
0
}
4093
4094
static bool
4095
_bfd_score_elf_check_relocs (bfd *abfd,
4096
           struct bfd_link_info *info,
4097
           asection *sec,
4098
           const Elf_Internal_Rela *relocs)
4099
0
{
4100
0
  if (bfd_get_mach (abfd) == bfd_mach_score3)
4101
0
    return s3_bfd_score_elf_check_relocs (abfd, info, sec, relocs);
4102
0
  else
4103
0
    return s7_bfd_score_elf_check_relocs (abfd, info, sec, relocs);
4104
0
}
4105
4106
static bool
4107
_bfd_score_elf_add_symbol_hook (bfd *abfd,
4108
        struct bfd_link_info *info ATTRIBUTE_UNUSED,
4109
        Elf_Internal_Sym *sym,
4110
        const char **namep ATTRIBUTE_UNUSED,
4111
        flagword *flagsp ATTRIBUTE_UNUSED,
4112
        asection **secp,
4113
        bfd_vma *valp)
4114
0
{
4115
0
  if (bfd_get_mach (abfd) == bfd_mach_score3)
4116
0
    return s3_bfd_score_elf_add_symbol_hook (abfd, info, sym, namep, flagsp,
4117
0
               secp, valp);
4118
0
  else
4119
0
    return s7_bfd_score_elf_add_symbol_hook (abfd, info, sym, namep, flagsp,
4120
0
               secp, valp);
4121
0
}
4122
4123
static void
4124
_bfd_score_elf_symbol_processing (bfd *abfd, asymbol *asym)
4125
125
{
4126
125
  if (bfd_get_mach (abfd) == bfd_mach_score3)
4127
0
    return s3_bfd_score_elf_symbol_processing (abfd, asym);
4128
125
  else
4129
125
    return s7_bfd_score_elf_symbol_processing (abfd, asym);
4130
125
}
4131
4132
static int
4133
_bfd_score_elf_link_output_symbol_hook (struct bfd_link_info *info ATTRIBUTE_UNUSED,
4134
     const char *name ATTRIBUTE_UNUSED,
4135
     Elf_Internal_Sym *sym,
4136
     asection *input_sec,
4137
     struct elf_link_hash_entry *h ATTRIBUTE_UNUSED)
4138
0
{
4139
  /* If link a empty .o, then this filed is NULL.  */
4140
0
  if (info->input_bfds == NULL)
4141
0
    {
4142
      /* If we see a common symbol, which implies a relocatable link, then
4143
   if a symbol was small common in an input file, mark it as small
4144
   common in the output file.  */
4145
0
      if (sym->st_shndx == SHN_COMMON && strcmp (input_sec->name, ".scommon") == 0)
4146
0
  sym->st_shndx = SHN_SCORE_SCOMMON;
4147
0
      return 1;
4148
0
    }
4149
4150
0
  if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4151
0
    return s3_bfd_score_elf_link_output_symbol_hook (info, name, sym, input_sec, h);
4152
0
  else
4153
0
    return s7_bfd_score_elf_link_output_symbol_hook (info, name, sym, input_sec, h);
4154
0
}
4155
4156
static bool
4157
_bfd_score_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED,
4158
           asection *sec,
4159
           int *retval)
4160
0
{
4161
0
  if (bfd_get_mach (abfd) == bfd_mach_score3)
4162
0
    return s3_bfd_score_elf_section_from_bfd_section (abfd, sec, retval);
4163
0
  else
4164
0
    return s7_bfd_score_elf_section_from_bfd_section (abfd, sec, retval);
4165
0
}
4166
4167
static bool
4168
_bfd_score_elf_adjust_dynamic_symbol (struct bfd_link_info *info,
4169
              struct elf_link_hash_entry *h)
4170
0
{
4171
0
  if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4172
0
    return s3_bfd_score_elf_adjust_dynamic_symbol (info, h);
4173
0
  else
4174
0
    return s7_bfd_score_elf_adjust_dynamic_symbol (info, h);
4175
0
}
4176
4177
static bool
4178
_bfd_score_elf_early_size_sections (bfd *output_bfd,
4179
            struct bfd_link_info *info)
4180
0
{
4181
0
  if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4182
0
    return s3_bfd_score_elf_early_size_sections (output_bfd, info);
4183
0
  else
4184
0
    return s7_bfd_score_elf_early_size_sections (output_bfd, info);
4185
0
}
4186
4187
static bool
4188
_bfd_score_elf_late_size_sections (bfd *output_bfd, struct bfd_link_info *info)
4189
0
{
4190
0
  if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4191
0
    return s3_bfd_score_elf_late_size_sections (output_bfd, info);
4192
0
  else
4193
0
    return s7_bfd_score_elf_late_size_sections (output_bfd, info);
4194
0
}
4195
4196
static bool
4197
_bfd_score_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info)
4198
0
{
4199
0
  if (bfd_get_mach (abfd) == bfd_mach_score3)
4200
0
    return s3_bfd_score_elf_create_dynamic_sections (abfd, info);
4201
0
  else
4202
0
    return s7_bfd_score_elf_create_dynamic_sections (abfd, info);
4203
0
}
4204
4205
static bool
4206
_bfd_score_elf_finish_dynamic_symbol (bfd *output_bfd,
4207
              struct bfd_link_info *info,
4208
              struct elf_link_hash_entry *h,
4209
              Elf_Internal_Sym *sym)
4210
0
{
4211
0
  if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4212
0
    return s3_bfd_score_elf_finish_dynamic_symbol (output_bfd, info, h, sym);
4213
0
  else
4214
0
    return s7_bfd_score_elf_finish_dynamic_symbol (output_bfd, info, h, sym);
4215
0
}
4216
4217
static bool
4218
_bfd_score_elf_finish_dynamic_sections (bfd *output_bfd,
4219
          struct bfd_link_info *info)
4220
0
{
4221
0
  if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4222
0
    return s3_bfd_score_elf_finish_dynamic_sections (output_bfd, info);
4223
0
  else
4224
0
    return s7_bfd_score_elf_finish_dynamic_sections (output_bfd, info);
4225
0
}
4226
4227
static bool
4228
_bfd_score_elf_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
4229
            Elf_Internal_Shdr *hdr,
4230
            asection *sec)
4231
0
{
4232
0
  if (bfd_get_mach (abfd) == bfd_mach_score3)
4233
0
    return s3_bfd_score_elf_fake_sections (abfd, hdr, sec);
4234
0
  else
4235
0
    return s7_bfd_score_elf_fake_sections (abfd, hdr, sec);
4236
0
}
4237
4238
static bool
4239
_bfd_score_elf_section_processing (bfd *abfd ATTRIBUTE_UNUSED, Elf_Internal_Shdr *hdr)
4240
0
{
4241
0
  if (bfd_get_mach (abfd) == bfd_mach_score3)
4242
0
    return s3_bfd_score_elf_section_processing (abfd, hdr);
4243
0
  else
4244
0
    return s7_bfd_score_elf_section_processing (abfd, hdr);
4245
0
}
4246
4247
static bool
4248
_bfd_score_elf_write_section (bfd *output_bfd,
4249
            struct bfd_link_info *link_info ATTRIBUTE_UNUSED,
4250
            asection *sec, bfd_byte *contents)
4251
0
{
4252
0
  if (bfd_get_mach (output_bfd) == bfd_mach_score3)
4253
0
    return s3_bfd_score_elf_write_section (output_bfd, sec, contents);
4254
0
  else
4255
0
    return s7_bfd_score_elf_write_section (output_bfd, sec, contents);
4256
0
}
4257
4258
static void
4259
_bfd_score_elf_copy_indirect_symbol (struct bfd_link_info *info,
4260
             struct elf_link_hash_entry *dir,
4261
             struct elf_link_hash_entry *ind)
4262
0
{
4263
0
  if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4264
0
    return s3_bfd_score_elf_copy_indirect_symbol (info, dir, ind);
4265
0
  else
4266
0
    return s7_bfd_score_elf_copy_indirect_symbol (info, dir, ind);
4267
0
}
4268
4269
static void
4270
_bfd_score_elf_hide_symbol (struct bfd_link_info *info,
4271
          struct elf_link_hash_entry *entry,
4272
          bool force_local)
4273
0
{
4274
0
  if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4275
0
    return s3_bfd_score_elf_hide_symbol (info, entry, force_local);
4276
0
  else
4277
0
    return s7_bfd_score_elf_hide_symbol (info, entry, force_local);
4278
0
}
4279
4280
static bool
4281
_bfd_score_elf_discard_info (bfd *abfd, struct elf_reloc_cookie *cookie,
4282
       struct bfd_link_info *info)
4283
0
{
4284
0
  if (bfd_get_mach (abfd) == bfd_mach_score3)
4285
0
    return s3_bfd_score_elf_discard_info (abfd, cookie, info);
4286
0
  else
4287
0
    return s7_bfd_score_elf_discard_info (abfd, cookie, info);
4288
0
}
4289
4290
static bool
4291
_bfd_score_elf_ignore_discarded_relocs (asection *sec)
4292
0
{
4293
0
  if (bfd_get_mach (sec->owner) == bfd_mach_score3)
4294
0
    return s3_bfd_score_elf_ignore_discarded_relocs (sec);
4295
0
  else
4296
0
    return s7_bfd_score_elf_ignore_discarded_relocs (sec);
4297
0
}
4298
4299
static asection *
4300
_bfd_score_elf_gc_mark_hook (asection *sec,
4301
           struct bfd_link_info *info,
4302
           Elf_Internal_Rela *rel,
4303
           struct elf_link_hash_entry *h,
4304
           Elf_Internal_Sym *sym)
4305
0
{
4306
0
  if (bfd_get_mach (info->input_bfds) == bfd_mach_score3)
4307
0
    return s3_bfd_score_elf_gc_mark_hook (sec, info, rel, h, sym);
4308
0
  else
4309
0
    return s7_bfd_score_elf_gc_mark_hook (sec, info, rel, h, sym);
4310
0
}
4311
4312
static bool
4313
_bfd_score_elf_grok_prstatus (bfd *abfd, Elf_Internal_Note *note)
4314
12
{
4315
12
  if (bfd_get_mach (abfd) == bfd_mach_score3)
4316
0
    return s3_bfd_score_elf_grok_prstatus (abfd, note);
4317
12
  else
4318
12
    return s7_bfd_score_elf_grok_prstatus (abfd, note);
4319
12
}
4320
4321
static bool
4322
_bfd_score_elf_grok_psinfo (bfd *abfd, Elf_Internal_Note *note)
4323
3
{
4324
3
  if (bfd_get_mach (abfd) == bfd_mach_score3)
4325
0
    return s3_bfd_score_elf_grok_psinfo (abfd, note);
4326
3
  else
4327
3
    return s7_bfd_score_elf_grok_psinfo (abfd, note);
4328
3
}
4329
4330
static reloc_howto_type *
4331
elf32_score_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, bfd_reloc_code_real_type code)
4332
0
{
4333
  /* s3: NOTE!!!
4334
     gas will call elf32_score_reloc_type_lookup, and don't write elf file.
4335
     So just using score3, but we don't know ld will call this or not.
4336
     If so, this way can't work.  */
4337
4338
0
  if (score3)
4339
0
    return s3_elf32_score_reloc_type_lookup (abfd, code);
4340
0
  else
4341
0
    return s7_elf32_score_reloc_type_lookup (abfd, code);
4342
0
}
4343
4344
/* Create a score elf linker hash table.
4345
   This is a copy of _bfd_elf_link_hash_table_create() except with a
4346
   different hash table entry creation function.  */
4347
4348
static struct bfd_link_hash_table *
4349
elf32_score_link_hash_table_create (bfd *abfd)
4350
0
{
4351
0
  struct elf_link_hash_table *ret;
4352
0
  size_t amt = sizeof (struct elf_link_hash_table);
4353
4354
0
  ret = (struct elf_link_hash_table *) bfd_zmalloc (amt);
4355
0
  if (ret == NULL)
4356
0
    return NULL;
4357
4358
0
  if (!_bfd_elf_link_hash_table_init (ret, abfd, score_elf_link_hash_newfunc,
4359
0
              sizeof (struct score_elf_link_hash_entry)))
4360
0
    {
4361
0
      free (ret);
4362
0
      return NULL;
4363
0
    }
4364
4365
0
  return &ret->root;
4366
0
}
4367
4368
static bool
4369
elf32_score_print_private_bfd_data (bfd *abfd, void * ptr)
4370
65
{
4371
65
  if (bfd_get_mach (abfd) == bfd_mach_score3)
4372
33
    return s3_elf32_score_print_private_bfd_data (abfd, ptr);
4373
32
  else
4374
32
    return s7_elf32_score_print_private_bfd_data (abfd, ptr);
4375
65
}
4376
4377
static bool
4378
elf32_score_merge_private_bfd_data (bfd *ibfd, struct bfd_link_info *info)
4379
0
{
4380
0
  if (bfd_get_mach (info->output_bfd) == bfd_mach_score3)
4381
0
    return s3_elf32_score_merge_private_bfd_data (ibfd, info);
4382
0
  else
4383
0
    return s7_elf32_score_merge_private_bfd_data (ibfd, info);
4384
0
}
4385
4386
static bool
4387
elf32_score_new_section_hook (bfd *abfd, asection *sec)
4388
40.1k
{
4389
40.1k
  if (bfd_get_mach (abfd) == bfd_mach_score3)
4390
11.2k
    return s3_elf32_score_new_section_hook (abfd, sec);
4391
28.9k
  else
4392
28.9k
    return s7_elf32_score_new_section_hook (abfd, sec);
4393
40.1k
}
4394
4395
4396
/* s3_s7: don't need to split.  */
4397
4398
/* Set the right machine number.  */
4399
static bool
4400
_bfd_score_elf_score_object_p (bfd * abfd)
4401
6.53k
{
4402
6.53k
  int e_set = bfd_mach_score7;
4403
4404
6.53k
  if (elf_elfheader (abfd)->e_machine == EM_SCORE)
4405
2.02k
    {
4406
2.02k
      int e_mach = elf_elfheader (abfd)->e_flags & EF_SCORE_MACH & EF_OMIT_PIC_FIXDD;
4407
2.02k
      switch (e_mach)
4408
2.02k
  {
4409
  /* Set default target is score7.  */
4410
1.48k
  default:
4411
1.48k
  case E_SCORE_MACH_SCORE7:
4412
1.48k
    e_set = bfd_mach_score7;
4413
1.48k
    break;
4414
4415
536
  case E_SCORE_MACH_SCORE3:
4416
536
    e_set = bfd_mach_score3;
4417
536
    break;
4418
2.02k
  }
4419
2.02k
    }
4420
4421
6.53k
  return bfd_default_set_arch_mach (abfd, bfd_arch_score, e_set);
4422
6.53k
}
4423
4424
bool
4425
_bfd_score_elf_common_definition (Elf_Internal_Sym *sym)
4426
0
{
4427
0
  return (sym->st_shndx == SHN_COMMON || sym->st_shndx == SHN_SCORE_SCOMMON);
4428
0
}
4429
4430
/*****************************************************************************/
4431
4432
4433
#define USE_REL       1
4434
#define TARGET_LITTLE_SYM   score_elf32_le_vec
4435
#define TARGET_LITTLE_NAME    "elf32-littlescore"
4436
#define TARGET_BIG_SYM      score_elf32_be_vec
4437
#define TARGET_BIG_NAME     "elf32-bigscore"
4438
#define ELF_ARCH      bfd_arch_score
4439
#define ELF_MACHINE_CODE    EM_SCORE
4440
#define ELF_MACHINE_ALT1    EM_SCORE_OLD
4441
#define ELF_TARGET_ID     SCORE_ELF_DATA
4442
#define ELF_MAXPAGESIZE     0x8000
4443
4444
#define elf_info_to_howto   NULL
4445
#define elf_info_to_howto_rel   _bfd_score_info_to_howto
4446
#define elf_backend_relocate_section  _bfd_score_elf_relocate_section
4447
#define elf_backend_check_relocs  _bfd_score_elf_check_relocs
4448
#define elf_backend_add_symbol_hook _bfd_score_elf_add_symbol_hook
4449
#define elf_backend_symbol_processing _bfd_score_elf_symbol_processing
4450
#define elf_backend_link_output_symbol_hook \
4451
  _bfd_score_elf_link_output_symbol_hook
4452
#define elf_backend_section_from_bfd_section \
4453
  _bfd_score_elf_section_from_bfd_section
4454
#define elf_backend_adjust_dynamic_symbol \
4455
  _bfd_score_elf_adjust_dynamic_symbol
4456
#define elf_backend_early_size_sections \
4457
  _bfd_score_elf_early_size_sections
4458
#define elf_backend_late_size_sections \
4459
  _bfd_score_elf_late_size_sections
4460
#define elf_backend_omit_section_dynsym   _bfd_elf_omit_section_dynsym_all
4461
#define elf_backend_create_dynamic_sections \
4462
  _bfd_score_elf_create_dynamic_sections
4463
#define elf_backend_finish_dynamic_symbol \
4464
  _bfd_score_elf_finish_dynamic_symbol
4465
#define elf_backend_finish_dynamic_sections \
4466
  _bfd_score_elf_finish_dynamic_sections
4467
#define elf_backend_fake_sections   _bfd_score_elf_fake_sections
4468
#define elf_backend_section_processing    _bfd_score_elf_section_processing
4469
#define elf_backend_write_section   _bfd_score_elf_write_section
4470
#define elf_backend_copy_indirect_symbol  _bfd_score_elf_copy_indirect_symbol
4471
#define elf_backend_hide_symbol     _bfd_score_elf_hide_symbol
4472
#define elf_backend_discard_info    _bfd_score_elf_discard_info
4473
#define elf_backend_ignore_discarded_relocs \
4474
  _bfd_score_elf_ignore_discarded_relocs
4475
#define elf_backend_gc_mark_hook    _bfd_score_elf_gc_mark_hook
4476
#define elf_backend_grok_prstatus   _bfd_score_elf_grok_prstatus
4477
#define elf_backend_grok_psinfo     _bfd_score_elf_grok_psinfo
4478
#define elf_backend_can_gc_sections   1
4479
#define elf_backend_want_plt_sym    0
4480
#define elf_backend_got_header_size   (4 * SCORE_RESERVED_GOTNO)
4481
#define elf_backend_plt_header_size   0
4482
#define elf_backend_collect     true
4483
#define elf_backend_type_change_ok    true
4484
#define elf_backend_object_p          _bfd_score_elf_score_object_p
4485
4486
#define bfd_elf32_bfd_reloc_type_lookup      elf32_score_reloc_type_lookup
4487
#define bfd_elf32_bfd_reloc_name_lookup \
4488
  elf32_score_reloc_name_lookup
4489
#define bfd_elf32_bfd_link_hash_table_create elf32_score_link_hash_table_create
4490
#define bfd_elf32_bfd_print_private_bfd_data elf32_score_print_private_bfd_data
4491
#define bfd_elf32_bfd_merge_private_bfd_data elf32_score_merge_private_bfd_data
4492
#define bfd_elf32_new_section_hook       elf32_score_new_section_hook
4493
4494
#include "elf32-target.h"