elf32-bfin.c 174 KB
Newer Older
1
/* ADI Blackfin BFD support for 32-bit ELF.
Alan Modra's avatar
Alan Modra committed
2
   Copyright (C) 2005-2016 Free Software Foundation, Inc.
3
4
5
6
7

   This file is part of BFD, the Binary File Descriptor library.

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
8
   the Free Software Foundation; either version 3 of the License, or
9
10
11
12
13
14
15
16
17
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
18
19
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
   MA 02110-1301, USA.  */
20
21

#include "sysdep.h"
Alan Modra's avatar
   
Alan Modra committed
22
#include "bfd.h"
23
24
25
#include "libbfd.h"
#include "elf-bfd.h"
#include "elf/bfin.h"
Tom Tromey's avatar
bfd    
Tom Tromey committed
26
#include "dwarf2.h"
27
#include "hashtab.h"
28
29
30
31
32
33
34
35

/* FUNCTION : bfin_pltpc_reloc
   ABSTRACT : TODO : figure out how to handle pltpc relocs.  */
static bfd_reloc_status_type
bfin_pltpc_reloc (
     bfd *abfd ATTRIBUTE_UNUSED,
     arelent *reloc_entry ATTRIBUTE_UNUSED,
     asymbol *symbol ATTRIBUTE_UNUSED,
36
     void * data ATTRIBUTE_UNUSED,
37
38
     asection *input_section ATTRIBUTE_UNUSED,
     bfd *output_bfd ATTRIBUTE_UNUSED,
39
     char **error_message ATTRIBUTE_UNUSED)
40
41
{
  bfd_reloc_status_type flag = bfd_reloc_ok;
42
  return flag;
43
44
45
46
47
48
49
}


static bfd_reloc_status_type
bfin_pcrel24_reloc (bfd *abfd,
                    arelent *reloc_entry,
                    asymbol *symbol,
50
                    void * data,
51
52
53
54
55
56
57
58
59
60
61
62
63
64
                    asection *input_section,
                    bfd *output_bfd,
                    char **error_message ATTRIBUTE_UNUSED)
{
  bfd_vma relocation;
  bfd_size_type addr = reloc_entry->address;
  bfd_vma output_base = 0;
  reloc_howto_type *howto = reloc_entry->howto;
  asection *output_section;
  bfd_boolean relocatable = (output_bfd != NULL);

  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
    return bfd_reloc_outofrange;

65
66
67
68
69
70
71
  if (bfd_is_und_section (symbol->section)
      && (symbol->flags & BSF_WEAK) == 0
      && !relocatable)
    return bfd_reloc_undefined;

  if (bfd_is_com_section (symbol->section))
    relocation = 0;
72
  else
73
    relocation = symbol->value;
74

75
76
77
78
79
80
81
82
83
  output_section = symbol->section->output_section;

  if (relocatable)
    output_base = 0;
  else
    output_base = output_section->vma;

  if (!relocatable || !strcmp (symbol->name, symbol->section->name))
    relocation += output_base + symbol->section->output_offset;
84

85
86
  if (!relocatable && !strcmp (symbol->name, symbol->section->name))
    relocation += reloc_entry->addend;
87
88
89
90
91
92
93

  relocation -= input_section->output_section->vma + input_section->output_offset;
  relocation -= reloc_entry->address;

  if (howto->complain_on_overflow != complain_overflow_dont)
    {
      bfd_reloc_status_type status;
94
95
96
97
98
      status = bfd_check_overflow (howto->complain_on_overflow,
				   howto->bitsize,
				   howto->rightshift,
				   bfd_arch_bits_per_address(abfd),
				   relocation);
99
100
101
      if (status != bfd_reloc_ok)
	return status;
    }
102

103
104
105
  /* if rightshift is 1 and the number odd, return error.  */
  if (howto->rightshift && (relocation & 0x01))
    {
106
      (*_bfd_error_handler) (_("relocation should be even number"));
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
      return bfd_reloc_overflow;
    }

  relocation >>= (bfd_vma) howto->rightshift;
  /* Shift everything up to where it's going to be used.  */

  relocation <<= (bfd_vma) howto->bitpos;

  if (relocatable)
    {
      reloc_entry->address += input_section->output_offset;
      reloc_entry->addend += symbol->section->output_offset;
    }

  {
    short x;

    /* We are getting reloc_entry->address 2 byte off from
125
126
127
128
129
       the start of instruction. Assuming absolute postion
       of the reloc data. But, following code had been written assuming
       reloc address is starting at begining of instruction.
       To compensate that I have increased the value of
       relocation by 1 (effectively 2) and used the addr -2 instead of addr.  */
130
131
132
133
134
135
136
137
138
139
140
141
142
143

    relocation += 1;
    x = bfd_get_16 (abfd, (bfd_byte *) data + addr - 2);
    x = (x & 0xff00) | ((relocation >> 16) & 0xff);
    bfd_put_16 (abfd, x, (unsigned char *) data + addr - 2);

    x = bfd_get_16 (abfd, (bfd_byte *) data + addr);
    x = relocation & 0xFFFF;
    bfd_put_16 (abfd, x, (unsigned char *) data + addr );
  }
  return bfd_reloc_ok;
}

static bfd_reloc_status_type
144
145
146
bfin_imm16_reloc (bfd *abfd,
     		  arelent *reloc_entry,
     		  asymbol *symbol,
147
     		  void * data,
148
149
150
     		  asection *input_section,
     		  bfd *output_bfd,
     		  char **error_message ATTRIBUTE_UNUSED)
151
{
152
153
  bfd_vma relocation, x;
  bfd_size_type reloc_addr = reloc_entry->address;
154
  bfd_vma output_base = 0;
155
  reloc_howto_type *howto = reloc_entry->howto;
156
157
158
  asection *output_section;
  bfd_boolean relocatable = (output_bfd != NULL);

159
160
161
162
  /* Is the address of the relocation really within the section?  */
  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
    return bfd_reloc_outofrange;

163
164
165
166
167
168
  if (bfd_is_und_section (symbol->section)
      && (symbol->flags & BSF_WEAK) == 0
      && !relocatable)
    return bfd_reloc_undefined;

  output_section = symbol->section->output_section;
169
  relocation = symbol->value;
170
171
172
173
174
175
176

  /* Convert input-section-relative symbol value to absolute.  */
  if (relocatable)
    output_base = 0;
  else
    output_base = output_section->vma;

177
  if (!relocatable || !strcmp (symbol->name, symbol->section->name))
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
    relocation += output_base + symbol->section->output_offset;

  /* Add in supplied addend.  */
  relocation += reloc_entry->addend;

  if (relocatable)
    {
      reloc_entry->address += input_section->output_offset;
      reloc_entry->addend += symbol->section->output_offset;
    }
  else
    {
      reloc_entry->addend = 0;
    }

  if (howto->complain_on_overflow != complain_overflow_dont)
    {
      bfd_reloc_status_type flag;
      flag = bfd_check_overflow (howto->complain_on_overflow,
197
198
199
200
				 howto->bitsize,
				 howto->rightshift,
				 bfd_arch_bits_per_address(abfd),
				 relocation);
201
      if (flag != bfd_reloc_ok)
202
	return flag;
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
    }

  /* Here the variable relocation holds the final address of the
     symbol we are relocating against, plus any addend.  */

  relocation >>= (bfd_vma) howto->rightshift;
  x = relocation;
  bfd_put_16 (abfd, x, (unsigned char *) data + reloc_addr);
  return bfd_reloc_ok;
}


static bfd_reloc_status_type
bfin_byte4_reloc (bfd *abfd,
                  arelent *reloc_entry,
                  asymbol *symbol,
219
                  void * data,
220
221
                  asection *input_section,
                  bfd *output_bfd,
222
                  char **error_message ATTRIBUTE_UNUSED)
223
224
225
226
227
228
229
230
231
232
233
{
  bfd_vma relocation, x;
  bfd_size_type addr = reloc_entry->address;
  bfd_vma output_base = 0;
  asection *output_section;
  bfd_boolean relocatable = (output_bfd != NULL);

  /* Is the address of the relocation really within the section?  */
  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
    return bfd_reloc_outofrange;

234
235
236
237
  if (bfd_is_und_section (symbol->section)
      && (symbol->flags & BSF_WEAK) == 0
      && !relocatable)
    return bfd_reloc_undefined;
238

239
240
241
242
243
  output_section = symbol->section->output_section;
  relocation = symbol->value;
  /* Convert input-section-relative symbol value to absolute.  */
  if (relocatable)
    output_base = 0;
244
  else
245
246
247
248
249
250
    output_base = output_section->vma;

  if ((symbol->name
       && symbol->section->name
       && !strcmp (symbol->name, symbol->section->name))
      || !relocatable)
251
    {
252
      relocation += output_base + symbol->section->output_offset;
253
254
    }

255
256
  relocation += reloc_entry->addend;

257
  if (relocatable)
258
    {
259
260
261
262
263
264
265
266
267
268
269
270
271
272
      /* This output will be relocatable ... like ld -r. */
      reloc_entry->address += input_section->output_offset;
      reloc_entry->addend += symbol->section->output_offset;
    }
  else
    {
      reloc_entry->addend = 0;
    }

  /* Here the variable relocation holds the final address of the
     symbol we are relocating against, plus any addend.  */
  x = relocation & 0xFFFF0000;
  x >>=16;
  bfd_put_16 (abfd, x, (unsigned char *) data + addr + 2);
273

274
275
276
277
278
279
280
281
282
283
284
  x = relocation & 0x0000FFFF;
  bfd_put_16 (abfd, x, (unsigned char *) data + addr);
  return bfd_reloc_ok;
}

/* bfin_bfd_reloc handles the blackfin arithmetic relocations.
   Use this instead of bfd_perform_relocation.  */
static bfd_reloc_status_type
bfin_bfd_reloc (bfd *abfd,
		arelent *reloc_entry,
     		asymbol *symbol,
285
     		void * data,
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
     		asection *input_section,
     		bfd *output_bfd,
     		char **error_message ATTRIBUTE_UNUSED)
{
  bfd_vma relocation;
  bfd_size_type addr = reloc_entry->address;
  bfd_vma output_base = 0;
  reloc_howto_type *howto = reloc_entry->howto;
  asection *output_section;
  bfd_boolean relocatable = (output_bfd != NULL);

  /* Is the address of the relocation really within the section?  */
  if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
    return bfd_reloc_outofrange;

301
302
303
304
305
306
307
308
  if (bfd_is_und_section (symbol->section)
      && (symbol->flags & BSF_WEAK) == 0
      && !relocatable)
    return bfd_reloc_undefined;

  /* Get symbol value.  (Common symbols are special.)  */
  if (bfd_is_com_section (symbol->section))
    relocation = 0;
309
  else
310
311
312
313
314
315
316
317
318
319
320
321
322
323
    relocation = symbol->value;

  output_section = symbol->section->output_section;

  /* Convert input-section-relative symbol value to absolute.  */
  if (relocatable)
    output_base = 0;
  else
    output_base = output_section->vma;

  if (!relocatable || !strcmp (symbol->name, symbol->section->name))
    relocation += output_base + symbol->section->output_offset;

  if (!relocatable && !strcmp (symbol->name, symbol->section->name))
324
    {
325
326
      /* Add in supplied addend.  */
      relocation += reloc_entry->addend;
327
    }
328

329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
  /* Here the variable relocation holds the final address of the
     symbol we are relocating against, plus any addend.  */

  if (howto->pc_relative == TRUE)
    {
      relocation -= input_section->output_section->vma + input_section->output_offset;

      if (howto->pcrel_offset == TRUE)
        relocation -= reloc_entry->address;
    }

  if (relocatable)
    {
      reloc_entry->address += input_section->output_offset;
      reloc_entry->addend += symbol->section->output_offset;
    }

  if (howto->complain_on_overflow != complain_overflow_dont)
    {
      bfd_reloc_status_type status;

350
      status = bfd_check_overflow (howto->complain_on_overflow,
351
                                  howto->bitsize,
352
                                  howto->rightshift,
353
354
355
356
357
                                  bfd_arch_bits_per_address(abfd),
                                  relocation);
      if (status != bfd_reloc_ok)
	return status;
    }
358

359
360
361
  /* If rightshift is 1 and the number odd, return error.  */
  if (howto->rightshift && (relocation & 0x01))
    {
362
      (*_bfd_error_handler) (_("relocation should be even number"));
363
364
365
366
367
368
369
370
371
      return bfd_reloc_overflow;
    }

  relocation >>= (bfd_vma) howto->rightshift;

  /* Shift everything up to where it's going to be used.  */

  relocation <<= (bfd_vma) howto->bitpos;

372
#define DOIT(x)								\
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
  x = ( (x & ~howto->dst_mask) | (relocation & howto->dst_mask))

  /* handle 8 and 16 bit relocations here. */
  switch (howto->size)
    {
    case 0:
      {
        char x = bfd_get_8 (abfd, (char *) data + addr);
        DOIT (x);
        bfd_put_8 (abfd, x, (unsigned char *) data + addr);
      }
      break;

    case 1:
      {
        unsigned short x = bfd_get_16 (abfd, (bfd_byte *) data + addr);
        DOIT (x);
        bfd_put_16 (abfd, (bfd_vma) x, (unsigned char *) data + addr);
      }
      break;

    default:
      return bfd_reloc_other;
    }

398
  return bfd_reloc_ok;
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
}

/* HOWTO Table for blackfin.
   Blackfin relocations are fairly complicated.
   Some of the salient features are
   a. Even numbered offsets. A number of (not all) relocations are
      even numbered. This means that the rightmost bit is not stored.
      Needs to right shift by 1 and check to see if value is not odd
   b. A relocation can be an expression. An expression takes on
      a variety of relocations arranged in a stack.
   As a result, we cannot use the standard generic function as special
   function. We will have our own, which is very similar to the standard
   generic function except that it understands how to get the value from
   the relocation stack. .  */

#define BFIN_RELOC_MIN 0
415
#define BFIN_RELOC_MAX 0x21
416
417
418
419
420
421
422
423
#define BFIN_GNUEXT_RELOC_MIN 0x40
#define BFIN_GNUEXT_RELOC_MAX 0x43
#define BFIN_ARELOC_MIN 0xE0
#define BFIN_ARELOC_MAX 0xF3

static reloc_howto_type bfin_howto_table [] =
{
  /* This reloc does nothing. .  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
424
  HOWTO (R_BFIN_UNUSED0,	/* type.  */
425
	 0,			/* rightshift.  */
426
427
	 3,			/* size (0 = byte, 1 = short, 2 = long).  */
	 0,			/* bitsize.  */
428
429
	 FALSE,			/* pc_relative.  */
	 0,			/* bitpos.  */
430
	 complain_overflow_dont, /* complain_on_overflow.  */
431
	 bfd_elf_generic_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
432
	 "R_BFIN_UNUSED0",	/* name.  */
433
434
435
436
437
	 FALSE,			/* partial_inplace.  */
	 0,			/* src_mask.  */
	 0,			/* dst_mask.  */
	 FALSE),		/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
438
  HOWTO (R_BFIN_PCREL5M2,	/* type.  */
439
440
441
442
443
444
445
	 1,			/* rightshift.  */
	 1,			/* size (0 = byte, 1 = short, 2 = long)..  */
	 4,			/* bitsize.  */
	 TRUE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_unsigned, /* complain_on_overflow.  */
	 bfin_bfd_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
446
	 "R_BFIN_PCREL5M2",	/* name.  */
447
	 FALSE,			/* partial_inplace.  */
448
	 0,			/* src_mask.  */
449
450
451
	 0x0000000F,		/* dst_mask.  */
	 FALSE),		/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
452
  HOWTO (R_BFIN_UNUSED1,	/* type.  */
453
	 0,			/* rightshift.  */
454
455
	 3,			/* size (0 = byte, 1 = short, 2 = long).  */
	 0,			/* bitsize.  */
456
457
	 FALSE,			/* pc_relative.  */
	 0,			/* bitpos.  */
458
	 complain_overflow_dont, /* complain_on_overflow.  */
459
	 bfd_elf_generic_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
460
	 "R_BFIN_UNUSED1",	/* name.  */
461
462
463
464
465
	 FALSE,			/* partial_inplace.  */
	 0,			/* src_mask.  */
	 0,			/* dst_mask.  */
	 FALSE),		/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
466
  HOWTO (R_BFIN_PCREL10,	/* type.  */
467
468
469
470
471
472
473
	 1,			/* rightshift.  */
	 1,			/* size (0 = byte, 1 = short, 2 = long).  */
	 10,			/* bitsize.  */
	 TRUE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_signed, /* complain_on_overflow.  */
	 bfin_bfd_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
474
	 "R_BFIN_PCREL10",	/* name.  */
475
	 FALSE,			/* partial_inplace.  */
476
	 0,			/* src_mask.  */
477
478
	 0x000003FF,		/* dst_mask.  */
	 TRUE),			/* pcrel_offset.  */
479

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
480
  HOWTO (R_BFIN_PCREL12_JUMP,	/* type.  */
481
482
483
484
485
486
487
488
489
490
491
	 1,			/* rightshift.  */
				/* the offset is actually 13 bit
				   aligned on a word boundary so
				   only 12 bits have to be used.
				   Right shift the rightmost bit..  */
	 1,			/* size (0 = byte, 1 = short, 2 = long).  */
	 12,			/* bitsize.  */
	 TRUE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_signed, /* complain_on_overflow.  */
	 bfin_bfd_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
492
	 "R_BFIN_PCREL12_JUMP",	/* name.  */
493
	 FALSE,			/* partial_inplace.  */
494
	 0,			/* src_mask.  */
495
496
497
	 0x0FFF,		/* dst_mask.  */
	 TRUE),			/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
498
  HOWTO (R_BFIN_RIMM16,		/* type.  */
499
500
501
502
503
504
505
	 0,			/* rightshift.  */
	 1,			/* size (0 = byte, 1 = short, 2 = long).  */
	 16,			/* bitsize.  */
	 FALSE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_signed, /* complain_on_overflow.  */
	 bfin_imm16_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
506
	 "R_BFIN_RIMM16",	/* name.  */
507
	 FALSE,			/* partial_inplace.  */
508
	 0,			/* src_mask.  */
509
510
511
	 0x0000FFFF,		/* dst_mask.  */
	 TRUE),			/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
512
  HOWTO (R_BFIN_LUIMM16,	/* type.  */
513
514
515
516
517
518
519
	 0,			/* rightshift.  */
	 1,			/* size (0 = byte, 1 = short, 2 = long).  */
	 16,			/* bitsize.  */
	 FALSE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_dont, /* complain_on_overflow.  */
	 bfin_imm16_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
520
	 "R_BFIN_LUIMM16",	/* name.  */
521
	 FALSE,			/* partial_inplace.  */
522
	 0,			/* src_mask.  */
523
524
	 0x0000FFFF,		/* dst_mask.  */
	 TRUE),			/* pcrel_offset.  */
525

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
526
  HOWTO (R_BFIN_HUIMM16,	/* type.  */
527
528
529
530
531
532
533
	 16,			/* rightshift.  */
	 1,			/* size (0 = byte, 1 = short, 2 = long).  */
	 16,			/* bitsize.  */
	 FALSE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_unsigned, /* complain_on_overflow.  */
	 bfin_imm16_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
534
	 "R_BFIN_HUIMM16",	/* name.  */
535
	 FALSE,			/* partial_inplace.  */
536
	 0,			/* src_mask.  */
537
538
539
	 0x0000FFFF,		/* dst_mask.  */
	 TRUE),			/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
540
  HOWTO (R_BFIN_PCREL12_JUMP_S,	/* type.  */
541
542
543
544
545
546
547
	 1,			/* rightshift.  */
	 1,			/* size (0 = byte, 1 = short, 2 = long).  */
	 12,			/* bitsize.  */
	 TRUE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_signed, /* complain_on_overflow.  */
	 bfin_bfd_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
548
	 "R_BFIN_PCREL12_JUMP_S", /* name.  */
549
	 FALSE,			/* partial_inplace.  */
550
	 0,			/* src_mask.  */
551
552
553
	 0x00000FFF,		/* dst_mask.  */
	 TRUE),			/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
554
  HOWTO (R_BFIN_PCREL24_JUMP_X,	/* type.  */
555
556
557
558
559
560
561
         1,			/* rightshift.  */
         2,			/* size (0 = byte, 1 = short, 2 = long).  */
         24,			/* bitsize.  */
         TRUE,			/* pc_relative.  */
         0,			/* bitpos.  */
         complain_overflow_signed, /* complain_on_overflow.  */
         bfin_pcrel24_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
562
	"R_BFIN_PCREL24_JUMP_X", /* name.  */
563
	 FALSE,			/* partial_inplace.  */
564
	 0,			/* src_mask.  */
565
566
567
	 0x00FFFFFF,		/* dst_mask.  */
	 TRUE),			/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
568
  HOWTO (R_BFIN_PCREL24,	/* type.  */
569
570
571
572
573
574
575
	 1,			/* rightshift.  */
	 2,			/* size (0 = byte, 1 = short, 2 = long).  */
	 24,			/* bitsize.  */
	 TRUE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_signed, /* complain_on_overflow.  */
	 bfin_pcrel24_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
576
	 "R_BFIN_PCREL24",	/* name.  */
577
	 FALSE,			/* partial_inplace.  */
578
	 0,			/* src_mask.  */
579
580
581
	 0x00FFFFFF,		/* dst_mask.  */
	 TRUE),			/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
582
  HOWTO (R_BFIN_UNUSEDB,	/* type.  */
583
	 0,			/* rightshift.  */
584
585
	 3,			/* size (0 = byte, 1 = short, 2 = long).  */
	 0,			/* bitsize.  */
586
587
588
589
	 FALSE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_dont, /* complain_on_overflow.  */
	 bfd_elf_generic_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
590
	 "R_BFIN_UNUSEDB",	/* name.  */
591
592
593
594
595
	 FALSE,			/* partial_inplace.  */
	 0,			/* src_mask.  */
	 0,			/* dst_mask.  */
	 FALSE),		/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
596
  HOWTO (R_BFIN_UNUSEDC,	/* type.  */
597
	 0,			/* rightshift.  */
598
599
	 3,			/* size (0 = byte, 1 = short, 2 = long).  */
	 0,			/* bitsize.  */
600
601
602
603
	 FALSE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_dont, /* complain_on_overflow.  */
	 bfd_elf_generic_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
604
	 "R_BFIN_UNUSEDC",	/* name.  */
605
606
607
608
609
	 FALSE,			/* partial_inplace.  */
	 0,			/* src_mask.  */
	 0,			/* dst_mask.  */
	 FALSE),		/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
610
  HOWTO (R_BFIN_PCREL24_JUMP_L,	/* type.  */
611
612
613
614
615
616
617
	 1,			/* rightshift.  */
	 2,			/* size (0 = byte, 1 = short, 2 = long).  */
	 24,			/* bitsize.  */
	 TRUE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_signed, /* complain_on_overflow.  */
	 bfin_pcrel24_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
618
	 "R_BFIN_PCREL24_JUMP_L", /* name.  */
619
	 FALSE,			/* partial_inplace.  */
620
	 0,			/* src_mask.  */
621
622
623
	 0x00FFFFFF,		/* dst_mask.  */
	 TRUE),			/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
624
  HOWTO (R_BFIN_PCREL24_CALL_X,	/* type.  */
625
626
627
628
629
630
631
	 1,			/* rightshift.  */
	 2,			/* size (0 = byte, 1 = short, 2 = long).  */
	 24,			/* bitsize.  */
	 TRUE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_signed, /* complain_on_overflow.  */
	 bfin_pcrel24_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
632
	 "R_BFIN_PCREL24_CALL_X", /* name.  */
633
	 FALSE,			/* partial_inplace.  */
634
	 0,			/* src_mask.  */
635
636
637
	 0x00FFFFFF,		/* dst_mask.  */
	 TRUE),			/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
638
  HOWTO (R_BFIN_VAR_EQ_SYMB,	/* type.  */
639
640
641
642
643
644
645
	 0,			/* rightshift.  */
	 2,			/* size (0 = byte, 1 = short, 2 = long).  */
	 32,			/* bitsize.  */
	 FALSE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_bitfield, /* complain_on_overflow.  */
	 bfin_bfd_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
646
	 "R_BFIN_VAR_EQ_SYMB",	/* name.  */
647
648
649
650
651
	 FALSE,			/* partial_inplace.  */
	 0,			/* src_mask.  */
	 0,			/* dst_mask.  */
	 FALSE),		/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
652
  HOWTO (R_BFIN_BYTE_DATA,	/* type.  */
653
654
655
656
657
658
659
	 0,			/* rightshift.  */
	 0,			/* size (0 = byte, 1 = short, 2 = long).  */
	 8,			/* bitsize.  */
	 FALSE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_unsigned, /* complain_on_overflow.  */
	 bfin_bfd_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
660
	 "R_BFIN_BYTE_DATA",	/* name.  */
661
	 FALSE,			/* partial_inplace.  */
662
	 0,			/* src_mask.  */
663
664
665
	 0xFF,			/* dst_mask.  */
	 TRUE),			/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
666
  HOWTO (R_BFIN_BYTE2_DATA,	/* type.  */
667
668
669
670
671
672
673
	 0,			/* rightshift.  */
	 1,			/* size (0 = byte, 1 = short, 2 = long).  */
	 16,			/* bitsize.  */
	 FALSE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_signed, /* complain_on_overflow.  */
	 bfin_bfd_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
674
	 "R_BFIN_BYTE2_DATA",	/* name.  */
675
	 FALSE,			/* partial_inplace.  */
676
	 0,			/* src_mask.  */
677
678
679
	 0xFFFF,		/* dst_mask.  */
	 TRUE),			/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
680
  HOWTO (R_BFIN_BYTE4_DATA,	/* type.  */
681
682
683
684
685
686
687
	 0,			/* rightshift.  */
	 2,			/* size (0 = byte, 1 = short, 2 = long).  */
	 32,			/* bitsize.  */
	 FALSE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_unsigned, /* complain_on_overflow.  */
	 bfin_byte4_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
688
	 "R_BFIN_BYTE4_DATA",	/* name.  */
689
	 FALSE,			/* partial_inplace.  */
690
	 0,			/* src_mask.  */
691
692
693
	 0xFFFFFFFF,		/* dst_mask.  */
	 TRUE),			/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
694
  HOWTO (R_BFIN_PCREL11,	/* type.  */
695
696
697
698
699
700
701
	 1,			/* rightshift.  */
	 1,			/* size (0 = byte, 1 = short, 2 = long).  */
	 10,			/* bitsize.  */
	 TRUE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_unsigned, /* complain_on_overflow.  */
	 bfin_bfd_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
702
	 "R_BFIN_PCREL11",	/* name.  */
703
	 FALSE,			/* partial_inplace.  */
704
	 0,			/* src_mask.  */
705
706
	 0x000003FF,		/* dst_mask.  */
	 FALSE),		/* pcrel_offset.  */
707
708
709
710
711
712
713
714
715
716
717
718


  /* A 18-bit signed operand with the GOT offset for the address of
     the symbol.  */
  HOWTO (R_BFIN_GOT17M4,        /* type */
	 2,			/* rightshift */
	 1,			/* size (0 = byte, 1 = short, 2 = long) */
	 16,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_signed, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
719
	 "R_BFIN_GOT17M4",	/* name */
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
	 FALSE,			/* partial_inplace */
	 0xffff,	        /* src_mask */
	 0xffff,	        /* dst_mask */
	 FALSE),	        /* pcrel_offset */

  /* The upper 16 bits of the GOT offset for the address of the
     symbol.  */
  HOWTO (R_BFIN_GOTHI,	        /* type */
	 0,			/* rightshift */
	 1,			/* size (0 = byte, 1 = short, 2 = long) */
	 16,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_dont, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
	 "R_BFIN_GOTHI",		/* name */
	 FALSE,			/* partial_inplace */
	 0xffff,		        /* src_mask */
	 0xffff,		/* dst_mask */
	 FALSE),	        /* pcrel_offset */

  /* The lower 16 bits of the GOT offset for the address of the
     symbol.  */
  HOWTO (R_BFIN_GOTLO,	        /* type */
	 0,			/* rightshift */
	 1,			/* size (0 = byte, 1 = short, 2 = long) */
	 16,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_dont, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
	 "R_BFIN_GOTLO",		/* name */
	 FALSE,			/* partial_inplace */
	 0xffff,		/* src_mask */
	 0xffff,		/* dst_mask */
	 FALSE),	        /* pcrel_offset */

  /* The 32-bit address of the canonical descriptor of a function.  */
  HOWTO (R_BFIN_FUNCDESC,	/* type */
	 0,			/* rightshift */
	 2,			/* size (0 = byte, 1 = short, 2 = long) */
	 32,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_bitfield, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
	 "R_BFIN_FUNCDESC",	/* name */
	 FALSE,			/* partial_inplace */
	 0xffffffff,		/* src_mask */
	 0xffffffff,		/* dst_mask */
	 FALSE),		/* pcrel_offset */

  /* A 12-bit signed operand with the GOT offset for the address of
     canonical descriptor of a function.  */
  HOWTO (R_BFIN_FUNCDESC_GOT17M4,	/* type */
	 2,			/* rightshift */
	 1,			/* size (0 = byte, 1 = short, 2 = long) */
	 16,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_signed, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
	 "R_BFIN_FUNCDESC_GOT17M4", /* name */
	 FALSE,			/* partial_inplace */
	 0xffff,	        /* src_mask */
	 0xffff,	        /* dst_mask */
	 FALSE),	        /* pcrel_offset */

  /* The upper 16 bits of the GOT offset for the address of the
     canonical descriptor of a function.  */
  HOWTO (R_BFIN_FUNCDESC_GOTHI,	/* type */
	 0,			/* rightshift */
	 1,			/* size (0 = byte, 1 = short, 2 = long) */
	 16,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_dont, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
	 "R_BFIN_FUNCDESC_GOTHI", /* name */
	 FALSE,			/* partial_inplace */
	 0xffff,		/* src_mask */
	 0xffff,		/* dst_mask */
	 FALSE),	        /* pcrel_offset */

  /* The lower 16 bits of the GOT offset for the address of the
     canonical descriptor of a function.  */
  HOWTO (R_BFIN_FUNCDESC_GOTLO,	/* type */
	 0,			/* rightshift */
	 1,			/* size (0 = byte, 1 = short, 2 = long) */
	 16,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_dont, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
	 "R_BFIN_FUNCDESC_GOTLO", /* name */
	 FALSE,			/* partial_inplace */
	 0xffff,		/* src_mask */
	 0xffff,		/* dst_mask */
	 FALSE),	        /* pcrel_offset */

  /* The 32-bit address of the canonical descriptor of a function.  */
  HOWTO (R_BFIN_FUNCDESC_VALUE,	/* type */
	 0,			/* rightshift */
	 2,			/* size (0 = byte, 1 = short, 2 = long) */
	 64,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_bitfield, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
	 "R_BFIN_FUNCDESC_VALUE", /* name */
	 FALSE,			/* partial_inplace */
	 0xffffffff,		/* src_mask */
	 0xffffffff,		/* dst_mask */
	 FALSE),		/* pcrel_offset */

  /* A 12-bit signed operand with the GOT offset for the address of
     canonical descriptor of a function.  */
  HOWTO (R_BFIN_FUNCDESC_GOTOFF17M4, /* type */
	 2,			/* rightshift */
	 1,			/* size (0 = byte, 1 = short, 2 = long) */
	 16,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_signed, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
	 "R_BFIN_FUNCDESC_GOTOFF17M4", /* name */
	 FALSE,			/* partial_inplace */
	 0xffff,	        /* src_mask */
	 0xffff,	        /* dst_mask */
	 FALSE),	        /* pcrel_offset */

  /* The upper 16 bits of the GOT offset for the address of the
     canonical descriptor of a function.  */
  HOWTO (R_BFIN_FUNCDESC_GOTOFFHI, /* type */
	 0,			/* rightshift */
	 1,			/* size (0 = byte, 1 = short, 2 = long) */
	 16,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_dont, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
	 "R_BFIN_FUNCDESC_GOTOFFHI", /* name */
	 FALSE,			/* partial_inplace */
	 0xffff,		/* src_mask */
	 0xffff,		/* dst_mask */
	 FALSE),	        /* pcrel_offset */

  /* The lower 16 bits of the GOT offset for the address of the
     canonical descriptor of a function.  */
  HOWTO (R_BFIN_FUNCDESC_GOTOFFLO, /* type */
	 0,			/* rightshift */
	 1,			/* size (0 = byte, 1 = short, 2 = long) */
	 16,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_dont, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
	 "R_BFIN_FUNCDESC_GOTOFFLO", /* name */
	 FALSE,			/* partial_inplace */
	 0xffff,		/* src_mask */
	 0xffff,		/* dst_mask */
	 FALSE),	        /* pcrel_offset */

  /* A 12-bit signed operand with the GOT offset for the address of
     the symbol.  */
  HOWTO (R_BFIN_GOTOFF17M4,     /* type */
	 2,			/* rightshift */
	 1,			/* size (0 = byte, 1 = short, 2 = long) */
	 16,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_signed, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
	 "R_BFIN_GOTOFF17M4",	/* name */
	 FALSE,			/* partial_inplace */
	 0xffff,	        /* src_mask */
	 0xffff,	        /* dst_mask */
	 FALSE),	        /* pcrel_offset */

  /* The upper 16 bits of the GOT offset for the address of the
     symbol.  */
  HOWTO (R_BFIN_GOTOFFHI,        /* type */
	 0,			/* rightshift */
	 1,			/* size (0 = byte, 1 = short, 2 = long) */
	 16,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_dont, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
	 "R_BFIN_GOTOFFHI",	/* name */
	 FALSE,			/* partial_inplace */
	 0xffff,		/* src_mask */
	 0xffff,		/* dst_mask */
	 FALSE),	        /* pcrel_offset */

  /* The lower 16 bits of the GOT offset for the address of the
     symbol.  */
  HOWTO (R_BFIN_GOTOFFLO,	/* type */
	 0,			/* rightshift */
	 1,			/* size (0 = byte, 1 = short, 2 = long) */
	 16,			/* bitsize */
	 FALSE,			/* pc_relative */
	 0,			/* bitpos */
	 complain_overflow_dont, /* complain_on_overflow */
	 bfd_elf_generic_reloc,	/* special_function */
	 "R_BFIN_GOTOFFLO",	/* name */
	 FALSE,			/* partial_inplace */
	 0xffff,		/* src_mask */
	 0xffff,		/* dst_mask */
	 FALSE),	        /* pcrel_offset */
930
931
932
933
};

static reloc_howto_type bfin_gnuext_howto_table [] =
{
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
934
  HOWTO (R_BFIN_PLTPC,		/* type.  */
935
936
937
938
939
940
941
	 0,			/* rightshift.  */
	 1,			/* size (0 = byte, 1 = short, 2 = long).  */
	 16,			/* bitsize.  */
	 FALSE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_bitfield, /* complain_on_overflow.  */
	 bfin_pltpc_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
942
	 "R_BFIN_PLTPC",	/* name.  */
943
944
945
946
947
	 FALSE,			/* partial_inplace.  */
	 0xffff,		/* src_mask.  */
	 0xffff,		/* dst_mask.  */
	 FALSE),		/* pcrel_offset.  */

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
948
  HOWTO (R_BFIN_GOT,		/* type.  */
949
950
951
952
953
954
955
	 0,			/* rightshift.  */
	 1,			/* size (0 = byte, 1 = short, 2 = long).  */
	 16,			/* bitsize.  */
	 FALSE,			/* pc_relative.  */
	 0,			/* bitpos.  */
	 complain_overflow_bitfield, /* complain_on_overflow.  */
	 bfd_elf_generic_reloc,	/* special_function.  */
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
956
	 "R_BFIN_GOT",		/* name.  */
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
	 FALSE,			/* partial_inplace.  */
	 0x7fff,		/* src_mask.  */
	 0x7fff,		/* dst_mask.  */
	 FALSE),		/* pcrel_offset.  */

/* GNU extension to record C++ vtable hierarchy.  */
  HOWTO (R_BFIN_GNU_VTINHERIT, /* type.  */
         0,                     /* rightshift.  */
         2,                     /* size (0 = byte, 1 = short, 2 = long).  */
         0,                     /* bitsize.  */
         FALSE,                 /* pc_relative.  */
         0,                     /* bitpos.  */
         complain_overflow_dont, /* complain_on_overflow.  */
         NULL,                  /* special_function.  */
         "R_BFIN_GNU_VTINHERIT", /* name.  */
         FALSE,                 /* partial_inplace.  */
         0,                     /* src_mask.  */
         0,                     /* dst_mask.  */
         FALSE),                /* pcrel_offset.  */

/* GNU extension to record C++ vtable member usage.  */
  HOWTO (R_BFIN_GNU_VTENTRY,	/* type.  */
         0,                     /* rightshift.  */
         2,                     /* size (0 = byte, 1 = short, 2 = long).  */
         0,                     /* bitsize.  */
         FALSE,                 /* pc_relative.  */
         0,			/* bitpos.  */
         complain_overflow_dont, /* complain_on_overflow.  */
         _bfd_elf_rel_vtable_reloc_fn, /* special_function.  */
         "R_BFIN_GNU_VTENTRY",	/* name.  */
         FALSE,                 /* partial_inplace.  */
         0,                     /* src_mask.  */
         0,                     /* dst_mask.  */
         FALSE)                 /* pcrel_offset.  */
};

struct bfin_reloc_map
{
  bfd_reloc_code_real_type 	bfd_reloc_val;
  unsigned int			bfin_reloc_val;
};

static const struct bfin_reloc_map bfin_reloc_map [] =
{
Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
  { BFD_RELOC_NONE,			R_BFIN_UNUSED0 },
  { BFD_RELOC_BFIN_5_PCREL,		R_BFIN_PCREL5M2 },
  { BFD_RELOC_NONE,			R_BFIN_UNUSED1 },
  { BFD_RELOC_BFIN_10_PCREL,		R_BFIN_PCREL10 },
  { BFD_RELOC_BFIN_12_PCREL_JUMP,	R_BFIN_PCREL12_JUMP },
  { BFD_RELOC_BFIN_16_IMM,		R_BFIN_RIMM16 },
  { BFD_RELOC_BFIN_16_LOW,		R_BFIN_LUIMM16 },
  { BFD_RELOC_BFIN_16_HIGH,		R_BFIN_HUIMM16 },
  { BFD_RELOC_BFIN_12_PCREL_JUMP_S,	R_BFIN_PCREL12_JUMP_S },
  { BFD_RELOC_24_PCREL,			R_BFIN_PCREL24 },
  { BFD_RELOC_24_PCREL,			R_BFIN_PCREL24 },
  { BFD_RELOC_BFIN_24_PCREL_JUMP_L,	R_BFIN_PCREL24_JUMP_L },
  { BFD_RELOC_NONE,			R_BFIN_UNUSEDB },
  { BFD_RELOC_NONE,			R_BFIN_UNUSEDC },
  { BFD_RELOC_BFIN_24_PCREL_CALL_X,	R_BFIN_PCREL24_CALL_X },
  { BFD_RELOC_8,			R_BFIN_BYTE_DATA },
  { BFD_RELOC_16,			R_BFIN_BYTE2_DATA },
  { BFD_RELOC_32,			R_BFIN_BYTE4_DATA },
  { BFD_RELOC_BFIN_11_PCREL,		R_BFIN_PCREL11 },
  { BFD_RELOC_BFIN_GOT,			R_BFIN_GOT },
  { BFD_RELOC_BFIN_PLTPC,		R_BFIN_PLTPC },
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037

  { BFD_RELOC_BFIN_GOT17M4,      R_BFIN_GOT17M4 },
  { BFD_RELOC_BFIN_GOTHI,      R_BFIN_GOTHI },
  { BFD_RELOC_BFIN_GOTLO,      R_BFIN_GOTLO },
  { BFD_RELOC_BFIN_FUNCDESC,   R_BFIN_FUNCDESC },
  { BFD_RELOC_BFIN_FUNCDESC_GOT17M4, R_BFIN_FUNCDESC_GOT17M4 },
  { BFD_RELOC_BFIN_FUNCDESC_GOTHI, R_BFIN_FUNCDESC_GOTHI },
  { BFD_RELOC_BFIN_FUNCDESC_GOTLO, R_BFIN_FUNCDESC_GOTLO },
  { BFD_RELOC_BFIN_FUNCDESC_VALUE, R_BFIN_FUNCDESC_VALUE },
  { BFD_RELOC_BFIN_FUNCDESC_GOTOFF17M4, R_BFIN_FUNCDESC_GOTOFF17M4 },
  { BFD_RELOC_BFIN_FUNCDESC_GOTOFFHI, R_BFIN_FUNCDESC_GOTOFFHI },
  { BFD_RELOC_BFIN_FUNCDESC_GOTOFFLO, R_BFIN_FUNCDESC_GOTOFFLO },
  { BFD_RELOC_BFIN_GOTOFF17M4,   R_BFIN_GOTOFF17M4 },
  { BFD_RELOC_BFIN_GOTOFFHI,   R_BFIN_GOTOFFHI },
  { BFD_RELOC_BFIN_GOTOFFLO,   R_BFIN_GOTOFFLO },

1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
  { BFD_RELOC_VTABLE_INHERIT,		R_BFIN_GNU_VTINHERIT },
  { BFD_RELOC_VTABLE_ENTRY,		R_BFIN_GNU_VTENTRY },
};


static void
bfin_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED,
                    arelent *cache_ptr,
                    Elf_Internal_Rela *dst)
{
  unsigned int r_type;

  r_type = ELF32_R_TYPE (dst->r_info);

  if (r_type <= BFIN_RELOC_MAX)
    cache_ptr->howto = &bfin_howto_table [r_type];

  else if (r_type >= BFIN_GNUEXT_RELOC_MIN && r_type <= BFIN_GNUEXT_RELOC_MAX)
    cache_ptr->howto = &bfin_gnuext_howto_table [r_type - BFIN_GNUEXT_RELOC_MIN];

  else
    cache_ptr->howto = (reloc_howto_type *) NULL;
}
1061

1062
1063
1064
1065
1066
1067
/* Given a BFD reloc type, return the howto.  */
static reloc_howto_type *
bfin_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
			    bfd_reloc_code_real_type code)
{
  unsigned int i;
Alan Modra's avatar
Alan Modra committed
1068
  unsigned int r_type = (unsigned int) -1;
1069

Alan Modra's avatar
Alan Modra committed
1070
  for (i = sizeof (bfin_reloc_map) / sizeof (bfin_reloc_map[0]); i--;)
1071
1072
1073
    if (bfin_reloc_map[i].bfd_reloc_val == code)
      r_type = bfin_reloc_map[i].bfin_reloc_val;

Alan Modra's avatar
Alan Modra committed
1074
  if (r_type <= BFIN_RELOC_MAX)
1075
1076
1077
1078
1079
1080
    return &bfin_howto_table [r_type];

  else if (r_type >= BFIN_GNUEXT_RELOC_MIN && r_type <= BFIN_GNUEXT_RELOC_MAX)
   return &bfin_gnuext_howto_table [r_type - BFIN_GNUEXT_RELOC_MIN];

  return (reloc_howto_type *) NULL;
1081
}
1082

1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
static reloc_howto_type *
bfin_bfd_reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED,
			    const char *r_name)
{
  unsigned int i;

  for (i = 0;
       i < (sizeof (bfin_howto_table)
	    / sizeof (bfin_howto_table[0]));
       i++)
    if (bfin_howto_table[i].name != NULL
	&& strcasecmp (bfin_howto_table[i].name, r_name) == 0)
      return &bfin_howto_table[i];

  for (i = 0;
       i < (sizeof (bfin_gnuext_howto_table)
	    / sizeof (bfin_gnuext_howto_table[0]));
       i++)
    if (bfin_gnuext_howto_table[i].name != NULL
	&& strcasecmp (bfin_gnuext_howto_table[i].name, r_name) == 0)
      return &bfin_gnuext_howto_table[i];

  return NULL;
1106
}
1107

1108
1109
1110
/* Given a bfin relocation type, return the howto.  */
static reloc_howto_type *
bfin_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
1111
			unsigned int r_type)
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
{
  if (r_type <= BFIN_RELOC_MAX)
    return &bfin_howto_table [r_type];

  else if (r_type >= BFIN_GNUEXT_RELOC_MIN && r_type <= BFIN_GNUEXT_RELOC_MAX)
   return &bfin_gnuext_howto_table [r_type - BFIN_GNUEXT_RELOC_MIN];

  return (reloc_howto_type *) NULL;
}

1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
/* Set by ld emulation if --code-in-l1.  */
bfd_boolean elf32_bfin_code_in_l1 = 0;

/* Set by ld emulation if --data-in-l1.  */
bfd_boolean elf32_bfin_data_in_l1 = 0;

static void
elf32_bfin_final_write_processing (bfd *abfd,
				   bfd_boolean linker ATTRIBUTE_UNUSED)
{
  if (elf32_bfin_code_in_l1)
    elf_elfheader (abfd)->e_flags |= EF_BFIN_CODE_IN_L1;
  if (elf32_bfin_data_in_l1)
    elf_elfheader (abfd)->e_flags |= EF_BFIN_DATA_IN_L1;
}

1138
1139
1140
/* Return TRUE if the name is a local label.
   bfin local labels begin with L$.  */
static bfd_boolean
1141
bfin_is_local_label_name (bfd *abfd, const char *label)
1142
1143
1144
1145
1146
1147
{
  if (label[0] == 'L' && label[1] == '$' )
    return TRUE;

  return _bfd_elf_is_local_label_name (abfd, label);
}
1148
1149
1150
1151

/* Look through the relocs for a section during the first phase, and
   allocate space in the global offset table or procedure linkage
   table.  */
1152

1153
1154
1155
1156
1157
static bfd_boolean
bfin_check_relocs (bfd * abfd,
		   struct bfd_link_info *info,
		   asection *sec,
                   const Elf_Internal_Rela *relocs)
1158
{
1159
1160
1161
1162
1163
1164
  bfd *dynobj;
  Elf_Internal_Shdr *symtab_hdr;
  struct elf_link_hash_entry **sym_hashes;
  bfd_signed_vma *local_got_refcounts;
  const Elf_Internal_Rela *rel;
  const Elf_Internal_Rela *rel_end;
1165
  asection *sgot;
1166
  asection *srelgot;
1167

H.J. Lu's avatar
H.J. Lu committed
1168
  if (bfd_link_relocatable (info))
1169
    return TRUE;
1170

1171
1172
1173
1174
  dynobj = elf_hash_table (info)->dynobj;
  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  sym_hashes = elf_sym_hashes (abfd);
  local_got_refcounts = elf_local_got_refcounts (abfd);
1175

1176
1177
  sgot = NULL;
  srelgot = NULL;
1178

1179
1180
  rel_end = relocs + sec->reloc_count;
  for (rel = relocs; rel < rel_end; rel++)
1181
    {
1182
1183
      unsigned long r_symndx;
      struct elf_link_hash_entry *h;
1184

1185
1186
1187
1188
      r_symndx = ELF32_R_SYM (rel->r_info);
      if (r_symndx < symtab_hdr->sh_info)
	h = NULL;
      else
Alan Modra's avatar
Alan Modra committed
1189
1190
1191
1192
1193
1194
1195
	{
	  h = sym_hashes[r_symndx - symtab_hdr->sh_info];

	  /* PR15323, ref flags aren't set for references in the same
	     object.  */
	  h->root.non_ir_ref = 1;
	}
1196

1197
1198
1199
1200
1201
1202
1203
1204
      switch (ELF32_R_TYPE (rel->r_info))
	{
       /* This relocation describes the C++ object vtable hierarchy.
           Reconstruct it for later use during GC.  */
        case R_BFIN_GNU_VTINHERIT:
          if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
            return FALSE;
          break;
1205

1206
1207
1208
1209
1210
1211
1212
1213
        /* This relocation describes which C++ vtable entries
           are actually used.  Record for later use during GC.  */
        case R_BFIN_GNU_VTENTRY:
          BFD_ASSERT (h != NULL);
          if (h != NULL
              && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
            return FALSE;
          break;
1214

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
1215
	case R_BFIN_GOT:
1216
1217
1218
1219
	  if (h != NULL
	      && strcmp (h->root.root.string, "__GLOBAL_OFFSET_TABLE_") == 0)
	    break;
	  /* Fall through.  */
1220

1221
1222
1223
1224
1225
1226
1227
	  if (dynobj == NULL)
	    {
	      /* Create the .got section.  */
	      elf_hash_table (info)->dynobj = dynobj = abfd;
	      if (!_bfd_elf_create_got_section (dynobj, info))
		return FALSE;
	    }
1228

1229
1230
	  if (sgot == NULL)
	    {
1231
	      sgot = bfd_get_linker_section (dynobj, ".got");
1232
1233
	      BFD_ASSERT (sgot != NULL);
	    }
1234

H.J. Lu's avatar
H.J. Lu committed
1235
	  if (srelgot == NULL && (h != NULL || bfd_link_pic (info)))
1236
	    {
1237
	      srelgot = bfd_get_linker_section (dynobj, ".rela.got");
1238
1239
1240
1241
1242
	      if (srelgot == NULL)
		{
		  flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
				    | SEC_IN_MEMORY | SEC_LINKER_CREATED
				    | SEC_READONLY);
1243
1244
1245
		  srelgot = bfd_make_section_anyway_with_flags (dynobj,
								".rela.got",
								flags);
1246
1247
1248
1249
1250
		  if (srelgot == NULL
		      || !bfd_set_section_alignment (dynobj, srelgot, 2))
		    return FALSE;
		}
	    }
1251

1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
	  if (h != NULL)
	    {
	      if (h->got.refcount == 0)
		{
		  /* Make sure this symbol is output as a dynamic symbol.  */
		  if (h->dynindx == -1 && !h->forced_local)
		    {
		      if (!bfd_elf_link_record_dynamic_symbol (info, h))
			return FALSE;
		    }
1262

1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
		  /* Allocate space in the .got section.  */
		  sgot->size += 4;
		  /* Allocate relocation space.  */
		  srelgot->size += sizeof (Elf32_External_Rela);
		}
	      h->got.refcount++;
	    }
	  else
	    {
	      /* This is a global offset table entry for a local symbol.  */
	      if (local_got_refcounts == NULL)
		{
		  bfd_size_type size;
1276

1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
		  size = symtab_hdr->sh_info;
		  size *= sizeof (bfd_signed_vma);
		  local_got_refcounts = ((bfd_signed_vma *)
					 bfd_zalloc (abfd, size));
		  if (local_got_refcounts == NULL)
		    return FALSE;
		  elf_local_got_refcounts (abfd) = local_got_refcounts;
		}
	      if (local_got_refcounts[r_symndx] == 0)
		{
		  sgot->size += 4;
H.J. Lu's avatar
H.J. Lu committed
1288
		  if (bfd_link_pic (info))
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
		    {
		      /* If we are generating a shared object, we need to
		         output a R_68K_RELATIVE reloc so that the dynamic
		         linker can adjust this GOT entry.  */
		      srelgot->size += sizeof (Elf32_External_Rela);
		    }
		}
	      local_got_refcounts[r_symndx]++;
	    }
	  break;
1299

1300
1301
1302
1303
1304
1305
	default:
	  break;
	}
    }

  return TRUE;
1306
1307
}

1308
static enum elf_reloc_type_class
1309
1310
1311
elf32_bfin_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED,
			     const asection *rel_sec ATTRIBUTE_UNUSED,
			     const Elf_Internal_Rela * rela)
1312
{
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
  switch ((int) ELF32_R_TYPE (rela->r_info))
    {
    default:
      return reloc_class_normal;
    }
}

static bfd_reloc_status_type
bfin_final_link_relocate (Elf_Internal_Rela *rel, reloc_howto_type *howto,
			  bfd *input_bfd, asection *input_section,
			  bfd_byte *contents, bfd_vma address,
			  bfd_vma value, bfd_vma addend)
{
  int r_type = ELF32_R_TYPE (rel->r_info);
1327

Bernd Schmidt's avatar
bfd/    
Bernd Schmidt committed
1328
  if (r_type == R_BFIN_PCREL24 || r_type == R_BFIN_PCREL24_JUMP_L)
1329
1330
1331
    {
      bfd_reloc_status_type r = bfd_reloc_ok;
      bfd_vma x;
1332

1333
1334
      if (address > bfd_get_section_limit (input_bfd, input_section))
	return bfd_reloc_outofrange;
1335

1336
      value += addend;
1337

1338
1339
1340
      /* Perform usual pc-relative correction.  */
      value -= input_section->output_section->vma + input_section->output_offset;
      value -= address;
1341

1342
1343
1344
1345
1346
1347
      /* We are getting reloc_entry->address 2 byte off from
	 the start of instruction. Assuming absolute postion
	 of the reloc data. But, following code had been written assuming
	 reloc address is starting at begining of instruction.
	 To compensate that I have increased the value of
	 relocation by 1 (effectively 2) and used the addr -2 instead of addr.  */
1348

1349
1350
      value += 2;
      address -= 2;
1351

1352
1353
1354
      if ((value & 0xFF000000) != 0
	  && (value & 0xFF000000) != 0xFF000000)
	r = bfd_reloc_overflow;
1355

1356
      value >>= 1;
1357

1358
1359
1360
      x = bfd_get_16 (input_bfd, contents + address);
      x = (x & 0xff00) | ((value >> 16) & 0xff);
      bfd_put_16 (input_bfd, x, contents + address);
1361

1362
1363
1364
1365
1366
      x = bfd_get_16 (input_bfd, contents + address + 2);
      x = value & 0xFFFF;
      bfd_put_16 (input_bfd, x, contents + address + 2);
      return r;
    }
1367

1368
1369
  return _bfd_final_link_relocate (howto, input_bfd, input_section, contents,
				   rel->r_offset, value, addend);
1370
1371
1372

}

1373
1374
1375
1376
1377
1378
1379
1380
1381
static bfd_boolean
bfin_relocate_section (bfd * output_bfd,
		       struct bfd_link_info *info,
		       bfd * input_bfd,
		       asection * input_section,
		       bfd_byte * contents,
		       Elf_Internal_Rela * relocs,
		       Elf_Internal_Sym * local_syms,
		       asection ** local_sections)
1382
{
1383
1384
1385
1386
1387
1388
1389
1390
  bfd *dynobj;
  Elf_Internal_Shdr *symtab_hdr;
  struct elf_link_hash_entry **sym_hashes;
  bfd_vma *local_got_offsets;
  asection *sgot;
  Elf_Internal_Rela *rel;
  Elf_Internal_Rela *relend;
  int i = 0;
1391

1392
1393
1394
1395
  dynobj = elf_hash_table (info)->dynobj;
  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
  sym_hashes = elf_sym_hashes (input_bfd);
  local_got_offsets = elf_local_got_offsets (input_bfd);
1396

1397
  sgot = NULL;
1398

1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
  rel = relocs;
  relend = relocs + input_section->reloc_count;
  for (; rel < relend; rel++, i++)
    {
      int r_type;
      reloc_howto_type *howto;
      unsigned long r_symndx;
      struct elf_link_hash_entry *h;
      Elf_Internal_Sym *sym;
      asection *sec;
      bfd_vma relocation = 0;
      bfd_boolean unresolved_reloc;
      bfd_reloc_status_type r;
      bfd_vma address;
1413

1414
1415
1416
1417
1418
1419
      r_type = ELF32_R_TYPE (rel->r_info);
      if (r_type < 0 || r_type >= 243)
	{
	  bfd_set_error (bfd_error_bad_value);
	  return FALSE;
	}
1420

1421
1422
1423
      if (r_type == R_BFIN_GNU_VTENTRY
          || r_type == R_BFIN_GNU_VTINHERIT)
	continue;
1424

1425
1426
1427
1428
1429
1430
1431
      howto = bfin_reloc_type_lookup (input_bfd, r_type);
      if (howto == NULL)
	{
	  bfd_set_error (bfd_error_bad_value);
	  return FALSE;
	}
      r_symndx = ELF32_R_SYM (rel->r_info);
1432

1433
1434
1435
1436
      h = NULL;
      sym = NULL;
      sec = NULL;
      unresolved_reloc = FALSE;
1437

1438
1439
1440
1441
1442
1443
1444
1445
      if (r_symndx < symtab_hdr->sh_info)
	{
	  sym = local_syms + r_symndx;
	  sec = local_sections[r_symndx];
	  relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
	}
      else
	{
1446
	  bfd_boolean warned, ignored;
1447

1448
1449
1450
	  RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
				   r_symndx, symtab_hdr, sym_hashes,
				   h, sec, relocation,
1451
				   unresolved_reloc, warned, ignored);
1452
	}
1453

Alan Modra's avatar
Alan Modra committed
1454
      if (sec != NULL && discarded_section (sec))
Daniel Jacobowitz's avatar
bfd/    
Daniel Jacobowitz committed
1455
	RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section,
1456
					 rel, 1, relend, howto, 0, contents);
1457

H.J. Lu's avatar
H.J. Lu committed
1458
      if (bfd_link_relocatable (info))
1459
	continue;
1460

1461
      address = rel->r_offset;