forked from bminor/binutils-gdb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathelf32-score.c
4494 lines (3896 loc) · 133 KB
/
elf32-score.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
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
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
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
/* 32-bit ELF support for S+core.
Copyright (C) 2006-2025 Free Software Foundation, Inc.
Contributed by
Brain.lin ([email protected])
Mei Ligang ([email protected])
Pei-Lin Tsai ([email protected])
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
the Free Software Foundation; either version 3 of the License, or
(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
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
MA 02110-1301, USA. */
#include "sysdep.h"
#include "bfd.h"
#include "libbfd.h"
#include "libiberty.h"
#include "elf-bfd.h"
#include "elf/score.h"
#include "elf/common.h"
#include "elf/internal.h"
#include "hashtab.h"
#include "elf32-score.h"
int score3 = 0;
int score7 = 1;
/* The SCORE ELF linker needs additional information for each symbol in
the global hash table. */
struct score_elf_link_hash_entry
{
struct elf_link_hash_entry root;
/* Number of R_SCORE_ABS32, R_SCORE_REL32 relocs against this symbol. */
unsigned int possibly_dynamic_relocs;
/* If the R_SCORE_ABS32, R_SCORE_REL32 reloc is against a readonly section. */
bool readonly_reloc;
/* We must not create a stub for a symbol that has relocations related to
taking the function's address, i.e. any but R_SCORE_CALL15 ones. */
bool no_fn_stub;
/* Are we forced local? This will only be set if we have converted
the initial global GOT entry to a local GOT entry. */
bool forced_local;
};
/* Traverse a score ELF linker hash table. */
#define score_elf_link_hash_traverse(table, func, info) \
(elf_link_hash_traverse \
((table), \
(bool (*) (struct elf_link_hash_entry *, void *)) (func), \
(info)))
/* This structure is used to hold .got entries while estimating got sizes. */
struct score_got_entry
{
/* The input bfd in which the symbol is defined. */
bfd *abfd;
/* The index of the symbol, as stored in the relocation r_info, if
we have a local symbol; -1 otherwise. */
long symndx;
union
{
/* If abfd == NULL, an address that must be stored in the got. */
bfd_vma address;
/* If abfd != NULL && symndx != -1, the addend of the relocation
that should be added to the symbol value. */
bfd_vma addend;
/* If abfd != NULL && symndx == -1, the hash table entry
corresponding to a global symbol in the got (or, local, if
h->forced_local). */
struct score_elf_link_hash_entry *h;
} d;
/* The offset from the beginning of the .got section to the entry
corresponding to this symbol+addend. If it's a global symbol
whose offset is yet to be decided, it's going to be -1. */
long gotidx;
};
/* This structure is passed to score_elf_sort_hash_table_f when sorting
the dynamic symbols. */
struct score_elf_hash_sort_data
{
/* The symbol in the global GOT with the lowest dynamic symbol table index. */
struct elf_link_hash_entry *low;
/* The least dynamic symbol table index corresponding to a symbol with a GOT entry. */
long min_got_dynindx;
/* The greatest dynamic symbol table index corresponding to a symbol
with a GOT entry that is not referenced (e.g., a dynamic symbol
with dynamic relocations pointing to it from non-primary GOTs). */
long max_unref_got_dynindx;
/* The greatest dynamic symbol table index not corresponding to a
symbol without a GOT entry. */
long max_non_got_dynindx;
};
struct score_got_info
{
/* The global symbol in the GOT with the lowest index in the dynamic
symbol table. */
struct elf_link_hash_entry *global_gotsym;
/* The number of global .got entries. */
unsigned int global_gotno;
/* The number of local .got entries. */
unsigned int local_gotno;
/* The number of local .got entries we have used. */
unsigned int assigned_gotno;
/* A hash table holding members of the got. */
struct htab *got_entries;
/* In multi-got links, a pointer to the next got (err, rather, most
of the time, it points to the previous got). */
struct score_got_info *next;
};
/* A structure used to count GOT entries, for GOT entry or ELF symbol table traversal. */
struct _score_elf_section_data
{
struct bfd_elf_section_data elf;
union
{
struct score_got_info *got_info;
bfd_byte *tdata;
}
u;
};
#define score_elf_section_data(sec) \
((struct _score_elf_section_data *) elf_section_data (sec))
/* The size of a symbol-table entry. */
#define SCORE_ELF_SYM_SIZE(abfd) \
(get_elf_backend_data (abfd)->s->sizeof_sym)
/* In case we're on a 32-bit machine, construct a 64-bit "-1" value
from smaller values. Start with zero, widen, *then* decrement. */
#define MINUS_ONE (((bfd_vma)0) - 1)
#define MINUS_TWO (((bfd_vma)0) - 2)
#define PDR_SIZE 32
/* The number of local .got entries we reserve. */
#define SCORE_RESERVED_GOTNO (2)
#define ELF_DYNAMIC_INTERPRETER "/usr/lib/ld.so.1"
/* The offset of $gp from the beginning of the .got section. */
#define ELF_SCORE_GP_OFFSET(abfd) (0x3ff0)
/* The maximum size of the GOT for it to be addressable using 15-bit offsets from $gp. */
#define SCORE_ELF_GOT_MAX_SIZE(abfd) (ELF_SCORE_GP_OFFSET(abfd) + 0x3fff)
#define SCORE_ELF_STUB_SECTION_NAME (".SCORE.stub")
#define SCORE_FUNCTION_STUB_SIZE (16)
#define STUB_LW 0xc3bcc010 /* lw r29, [r28, -0x3ff0] */
#define STUB_MOVE 0x8363bc56 /* mv r27, r3 */
#define STUB_LI16 0x87548000 /* ori r26, .dynsym_index */
#define STUB_BRL 0x801dbc09 /* brl r29 */
#define SCORE_ELF_GOT_SIZE(abfd) \
(get_elf_backend_data (abfd)->s->arch_size / 8)
#define SCORE_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
(_bfd_elf_add_dynamic_entry (info, (bfd_vma) tag, (bfd_vma) val))
/* The size of an external dynamic table entry. */
#define SCORE_ELF_DYN_SIZE(abfd) \
(get_elf_backend_data (abfd)->s->sizeof_dyn)
/* The size of an external REL relocation. */
#define SCORE_ELF_REL_SIZE(abfd) \
(get_elf_backend_data (abfd)->s->sizeof_rel)
/* The default alignment for sections, as a power of two. */
#define SCORE_ELF_LOG_FILE_ALIGN(abfd)\
(get_elf_backend_data (abfd)->s->log_file_align)
static bfd_byte *hi16_rel_addr;
/* This will be used when we sort the dynamic relocation records. */
static bfd *reldyn_sorting_bfd;
/* SCORE ELF uses two common sections. One is the usual one, and the
other is for small objects. All the small objects are kept
together, and then referenced via the gp pointer, which yields
faster assembler code. This is what we use for the small common
section. This approach is copied from ecoff.c. */
static asection score_elf_scom_section;
static const asymbol score_elf_scom_symbol =
GLOBAL_SYM_INIT (".scommon", &score_elf_scom_section);
static asection score_elf_scom_section =
BFD_FAKE_SECTION (score_elf_scom_section, &score_elf_scom_symbol,
".scommon", 0, SEC_IS_COMMON | SEC_SMALL_DATA);
static bfd_vma
score_bfd_get_16 (bfd *abfd, const void *data)
{
return bfd_get_16 (abfd, data);
}
static bfd_vma
score3_bfd_getl32 (const void *p)
{
const bfd_byte *addr = p;
unsigned long v;
v = (unsigned long) addr[2];
v |= (unsigned long) addr[3] << 8;
v |= (unsigned long) addr[0] << 16;
v |= (unsigned long) addr[1] << 24;
return v;
}
static bfd_vma
score3_bfd_getl48 (const void *p)
{
const bfd_byte *addr = p;
uint64_t v;
v = (uint64_t) addr[4];
v |= (uint64_t) addr[5] << 8;
v |= (uint64_t) addr[2] << 16;
v |= (uint64_t) addr[3] << 24;
v |= (uint64_t) addr[0] << 32;
v |= (uint64_t) addr[1] << 40;
return v;
}
static bfd_vma
score_bfd_get_32 (bfd *abfd, const void *data)
{
if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
return score3_bfd_getl32 (data);
else
return bfd_get_32 (abfd, data);
}
static bfd_vma
score_bfd_get_48 (bfd *abfd, const void *p)
{
if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
return score3_bfd_getl48 (p);
else
return bfd_get_bits (p, 48, 1);
}
static void
score_bfd_put_16 (bfd *abfd, bfd_vma addr, void *data)
{
return bfd_put_16 (abfd, addr, data);
}
static void
score3_bfd_putl32 (bfd_vma data, void *p)
{
bfd_byte *addr = p;
addr[0] = (data >> 16) & 0xff;
addr[1] = (data >> 24) & 0xff;
addr[2] = data & 0xff;
addr[3] = (data >> 8) & 0xff;
}
static void
score3_bfd_putl48 (bfd_vma data, void *p)
{
bfd_byte *addr = p;
addr[0] = (data >> 32) & 0xff;
addr[1] = (data >> 40) & 0xff;
addr[2] = (data >> 16) & 0xff;
addr[3] = (data >> 24) & 0xff;
addr[4] = data & 0xff;
addr[5] = (data >> 8) & 0xff;
}
static void
score_bfd_put_32 (bfd *abfd, bfd_vma addr, void *data)
{
if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
return score3_bfd_putl32 (addr, data);
else
return bfd_put_32 (abfd, addr, data);
}
static void
score_bfd_put_48 (bfd *abfd, bfd_vma val, void *p)
{
if (/* score3 && */ abfd->xvec->byteorder == BFD_ENDIAN_LITTLE)
return score3_bfd_putl48 (val, p);
else
return bfd_put_bits (val, p, 48, 1);
}
static bfd_reloc_status_type
score_elf_hi16_reloc (bfd *abfd ATTRIBUTE_UNUSED,
arelent *reloc_entry,
asymbol *symbol ATTRIBUTE_UNUSED,
void * data,
asection *input_section ATTRIBUTE_UNUSED,
bfd *output_bfd ATTRIBUTE_UNUSED,
char **error_message ATTRIBUTE_UNUSED)
{
hi16_rel_addr = (bfd_byte *) data + reloc_entry->address;
return bfd_reloc_ok;
}
static bfd_reloc_status_type
score_elf_lo16_reloc (bfd *abfd,
arelent *reloc_entry,
asymbol *symbol ATTRIBUTE_UNUSED,
void * data,
asection *input_section,
bfd *output_bfd ATTRIBUTE_UNUSED,
char **error_message ATTRIBUTE_UNUSED)
{
bfd_vma addend = 0, offset = 0;
unsigned long val;
unsigned long hi16_offset, hi16_value, uvalue;
hi16_value = score_bfd_get_32 (abfd, hi16_rel_addr);
hi16_offset = ((((hi16_value >> 16) & 0x3) << 15) | (hi16_value & 0x7fff)) >> 1;
addend = score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
offset = ((((addend >> 16) & 0x3) << 15) | (addend & 0x7fff)) >> 1;
val = reloc_entry->addend;
if (reloc_entry->address > input_section->size)
return bfd_reloc_outofrange;
uvalue = ((hi16_offset << 16) | (offset & 0xffff)) + val;
hi16_offset = (uvalue >> 16) << 1;
hi16_value = (hi16_value & ~0x37fff) | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
score_bfd_put_32 (abfd, hi16_value, hi16_rel_addr);
offset = (uvalue & 0xffff) << 1;
addend = (addend & ~0x37fff) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
score_bfd_put_32 (abfd, addend, (bfd_byte *) data + reloc_entry->address);
return bfd_reloc_ok;
}
/* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
dangerous relocation. */
static bool
score_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp)
{
unsigned int count;
asymbol **sym;
unsigned int i;
/* If we've already figured out what GP will be, just return it. */
*pgp = _bfd_get_gp_value (output_bfd);
if (*pgp)
return true;
count = bfd_get_symcount (output_bfd);
sym = bfd_get_outsymbols (output_bfd);
/* The linker script will have created a symbol named `_gp' with the
appropriate value. */
if (sym == NULL)
i = count;
else
{
for (i = 0; i < count; i++, sym++)
{
const char *name;
name = bfd_asymbol_name (*sym);
if (*name == '_' && strcmp (name, "_gp") == 0)
{
*pgp = bfd_asymbol_value (*sym);
_bfd_set_gp_value (output_bfd, *pgp);
break;
}
}
}
if (i >= count)
{
/* Only get the error once. */
*pgp = 4;
_bfd_set_gp_value (output_bfd, *pgp);
return false;
}
return true;
}
/* We have to figure out the gp value, so that we can adjust the
symbol value correctly. We look up the symbol _gp in the output
BFD. If we can't find it, we're stuck. We cache it in the ELF
target data. We don't need to adjust the symbol value for an
external symbol if we are producing relocatable output. */
static bfd_reloc_status_type
score_elf_final_gp (bfd *output_bfd,
asymbol *symbol,
bool relocatable,
char **error_message,
bfd_vma *pgp)
{
if (bfd_is_und_section (symbol->section)
&& ! relocatable)
{
*pgp = 0;
return bfd_reloc_undefined;
}
*pgp = _bfd_get_gp_value (output_bfd);
if (*pgp == 0
&& (! relocatable
|| (symbol->flags & BSF_SECTION_SYM) != 0))
{
if (relocatable)
{
/* Make up a value. */
*pgp = symbol->section->output_section->vma + 0x4000;
_bfd_set_gp_value (output_bfd, *pgp);
}
else if (!score_elf_assign_gp (output_bfd, pgp))
{
*error_message =
(char *) _("GP relative relocation when _gp not defined");
return bfd_reloc_dangerous;
}
}
return bfd_reloc_ok;
}
static bfd_reloc_status_type
score_elf_gprel15_with_gp (bfd *abfd,
arelent *reloc_entry,
asection *input_section,
bool relocateable,
void * data,
bfd_vma gp ATTRIBUTE_UNUSED)
{
unsigned long insn;
if (reloc_entry->address > input_section->size)
return bfd_reloc_outofrange;
insn = score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
if (((reloc_entry->addend & 0xffffc000) != 0)
&& ((reloc_entry->addend & 0xffffc000) != 0xffffc000))
return bfd_reloc_overflow;
insn = (insn & ~0x7fff) | (reloc_entry->addend & 0x7fff);
score_bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address);
if (relocateable)
reloc_entry->address += input_section->output_offset;
return bfd_reloc_ok;
}
static bfd_reloc_status_type
gprel32_with_gp (bfd *abfd, asymbol *symbol, arelent *reloc_entry,
asection *input_section, bool relocatable,
void *data, bfd_vma gp)
{
bfd_vma relocation;
bfd_vma val;
if (bfd_is_com_section (symbol->section))
relocation = 0;
else
relocation = symbol->value;
relocation += symbol->section->output_section->vma;
relocation += symbol->section->output_offset;
if (reloc_entry->address > bfd_get_section_limit (abfd, input_section))
return bfd_reloc_outofrange;
/* Set val to the offset into the section or symbol. */
val = reloc_entry->addend;
if (reloc_entry->howto->partial_inplace)
val += score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
/* Adjust val for the final section location and GP value. If we
are producing relocatable output, we don't want to do this for
an external symbol. */
if (! relocatable
|| (symbol->flags & BSF_SECTION_SYM) != 0)
val += relocation - gp;
if (reloc_entry->howto->partial_inplace)
score_bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);
else
reloc_entry->addend = val;
if (relocatable)
reloc_entry->address += input_section->output_offset;
return bfd_reloc_ok;
}
static bfd_reloc_status_type
score_elf_gprel15_reloc (bfd *abfd,
arelent *reloc_entry,
asymbol *symbol,
void * data,
asection *input_section,
bfd *output_bfd,
char **error_message)
{
bool relocateable;
bfd_reloc_status_type ret;
bfd_vma gp;
if (output_bfd != NULL
&& (symbol->flags & BSF_SECTION_SYM) == 0 && reloc_entry->addend == 0)
{
reloc_entry->address += input_section->output_offset;
return bfd_reloc_ok;
}
if (output_bfd != NULL)
relocateable = true;
else
{
relocateable = false;
output_bfd = symbol->section->output_section->owner;
}
ret = score_elf_final_gp (output_bfd, symbol, relocateable, error_message, &gp);
if (ret != bfd_reloc_ok)
return ret;
return score_elf_gprel15_with_gp (abfd, reloc_entry,
input_section, relocateable, data, gp);
}
/* Do a R_SCORE_GPREL32 relocation. This is a 32 bit value which must
become the offset from the gp register. */
static bfd_reloc_status_type
score_elf_gprel32_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
void *data, asection *input_section, bfd *output_bfd,
char **error_message)
{
bool relocatable;
bfd_reloc_status_type ret;
bfd_vma gp;
/* R_SCORE_GPREL32 relocations are defined for local symbols only. */
if (output_bfd != NULL
&& (symbol->flags & BSF_SECTION_SYM) == 0
&& (symbol->flags & BSF_LOCAL) != 0)
{
*error_message = (char *)
_("32bits gp relative relocation occurs for an external symbol");
return bfd_reloc_outofrange;
}
if (output_bfd != NULL)
relocatable = true;
else
{
relocatable = false;
output_bfd = symbol->section->output_section->owner;
}
ret = score_elf_final_gp (output_bfd, symbol, relocatable, error_message, &gp);
if (ret != bfd_reloc_ok)
return ret;
gp = 0;
return gprel32_with_gp (abfd, symbol, reloc_entry, input_section,
relocatable, data, gp);
}
/* A howto special_function for R_SCORE_GOT15 relocations. This is just
like any other 16-bit relocation when applied to global symbols, but is
treated in the same as R_SCORE_HI16 when applied to local symbols. */
static bfd_reloc_status_type
score_elf_got15_reloc (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
void *data, asection *input_section,
bfd *output_bfd, char **error_message)
{
if ((symbol->flags & (BSF_GLOBAL | BSF_WEAK)) != 0
|| bfd_is_und_section (bfd_asymbol_section (symbol))
|| bfd_is_com_section (bfd_asymbol_section (symbol)))
/* The relocation is against a global symbol. */
return bfd_elf_generic_reloc (abfd, reloc_entry, symbol, data,
input_section, output_bfd,
error_message);
return score_elf_hi16_reloc (abfd, reloc_entry, symbol, data,
input_section, output_bfd, error_message);
}
static bfd_reloc_status_type
score_elf_got_lo16_reloc (bfd *abfd,
arelent *reloc_entry,
asymbol *symbol ATTRIBUTE_UNUSED,
void * data,
asection *input_section,
bfd *output_bfd ATTRIBUTE_UNUSED,
char **error_message ATTRIBUTE_UNUSED)
{
bfd_vma addend = 0, offset = 0;
signed long val;
signed long hi16_offset, hi16_value, uvalue;
hi16_value = score_bfd_get_32 (abfd, hi16_rel_addr);
hi16_offset = ((((hi16_value >> 16) & 0x3) << 15) | (hi16_value & 0x7fff)) >> 1;
addend = score_bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address);
offset = ((((addend >> 16) & 0x3) << 15) | (addend & 0x7fff)) >> 1;
val = reloc_entry->addend;
if (reloc_entry->address > input_section->size)
return bfd_reloc_outofrange;
uvalue = ((hi16_offset << 16) | (offset & 0xffff)) + val;
if ((uvalue > -0x8000) && (uvalue < 0x7fff))
hi16_offset = 0;
else
hi16_offset = (uvalue >> 16) & 0x7fff;
hi16_value = (hi16_value & ~0x37fff) | (hi16_offset & 0x7fff) | ((hi16_offset << 1) & 0x30000);
score_bfd_put_32 (abfd, hi16_value, hi16_rel_addr);
offset = (uvalue & 0xffff) << 1;
addend = (addend & ~0x37fff) | (offset & 0x7fff) | ((offset << 1) & 0x30000);
score_bfd_put_32 (abfd, addend, (bfd_byte *) data + reloc_entry->address);
return bfd_reloc_ok;
}
static reloc_howto_type elf32_score_howto_table[] =
{
/* No relocation. */
HOWTO (R_SCORE_NONE, /* type */
0, /* rightshift */
0, /* size */
0, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_SCORE_NONE", /* name */
false, /* partial_inplace */
0, /* src_mask */
0, /* dst_mask */
false), /* pcrel_offset */
/* R_SCORE_HI16 */
HOWTO (R_SCORE_HI16, /* type */
0, /* rightshift */
4, /* size */
16, /* bitsize */
false, /* pc_relative */
1, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
score_elf_hi16_reloc, /* special_function */
"R_SCORE_HI16", /* name */
true, /* partial_inplace */
0x37fff, /* src_mask */
0x37fff, /* dst_mask */
false), /* pcrel_offset */
/* R_SCORE_LO16 */
HOWTO (R_SCORE_LO16, /* type */
0, /* rightshift */
4, /* size */
16, /* bitsize */
false, /* pc_relative */
1, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
score_elf_lo16_reloc, /* special_function */
"R_SCORE_LO16", /* name */
true, /* partial_inplace */
0x37fff, /* src_mask */
0x37fff, /* dst_mask */
false), /* pcrel_offset */
/* R_SCORE_BCMP */
HOWTO (R_SCORE_BCMP, /* type */
1, /* rightshift */
4, /* size */
16, /* bitsize */
true, /* pc_relative */
1, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_SCORE_BCMP", /* name */
false, /* partial_inplace */
0x03e00381, /* src_mask */
0x03e00381, /* dst_mask */
false), /* pcrel_offset */
/*R_SCORE_24 */
HOWTO (R_SCORE_24, /* type */
1, /* rightshift */
4, /* size */
24, /* bitsize */
false, /* pc_relative */
1, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_SCORE_24", /* name */
false, /* partial_inplace */
0x3ff7fff, /* src_mask */
0x3ff7fff, /* dst_mask */
false), /* pcrel_offset */
/*R_SCORE_PC19 */
HOWTO (R_SCORE_PC19, /* type */
1, /* rightshift */
4, /* size */
19, /* bitsize */
true, /* pc_relative */
1, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_SCORE_PC19", /* name */
false, /* partial_inplace */
0x3ff03fe, /* src_mask */
0x3ff03fe, /* dst_mask */
false), /* pcrel_offset */
/*R_SCORE16_11 */
HOWTO (R_SCORE16_11, /* type */
1, /* rightshift */
2, /* size */
11, /* bitsize */
false, /* pc_relative */
1, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_SCORE16_11", /* name */
false, /* partial_inplace */
0x000000ffe, /* src_mask */
0x000000ffe, /* dst_mask */
false), /* pcrel_offset */
/* R_SCORE16_PC8 */
HOWTO (R_SCORE16_PC8, /* type */
1, /* rightshift */
2, /* size */
9, /* bitsize */
true, /* pc_relative */
0, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_SCORE16_PC8", /* name */
false, /* partial_inplace */
0x000001ff, /* src_mask */
0x000001ff, /* dst_mask */
false), /* pcrel_offset */
/* 32 bit absolute */
HOWTO (R_SCORE_ABS32, /* type 8 */
0, /* rightshift */
4, /* size */
32, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_SCORE_ABS32", /* name */
false, /* partial_inplace */
0xffffffff, /* src_mask */
0xffffffff, /* dst_mask */
false), /* pcrel_offset */
/* 16 bit absolute */
HOWTO (R_SCORE_ABS16, /* type 11 */
0, /* rightshift */
2, /* size */
16, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_bitfield, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_SCORE_ABS16", /* name */
false, /* partial_inplace */
0x0000ffff, /* src_mask */
0x0000ffff, /* dst_mask */
false), /* pcrel_offset */
/* R_SCORE_DUMMY2 */
HOWTO (R_SCORE_DUMMY2, /* type */
0, /* rightshift */
4, /* size */
16, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_SCORE_DUMMY2", /* name */
true, /* partial_inplace */
0x00007fff, /* src_mask */
0x00007fff, /* dst_mask */
false), /* pcrel_offset */
/* R_SCORE_GP15 */
HOWTO (R_SCORE_GP15, /* type */
0, /* rightshift */
4, /* size */
16, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
score_elf_gprel15_reloc,/* special_function */
"R_SCORE_GP15", /* name */
true, /* partial_inplace */
0x00007fff, /* src_mask */
0x00007fff, /* dst_mask */
false), /* pcrel_offset */
/* GNU extension to record C++ vtable hierarchy. */
HOWTO (R_SCORE_GNU_VTINHERIT, /* type */
0, /* rightshift */
4, /* size */
0, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
NULL, /* special_function */
"R_SCORE_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_SCORE_GNU_VTENTRY, /* type */
0, /* rightshift */
4, /* size */
0, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
_bfd_elf_rel_vtable_reloc_fn, /* special_function */
"R_SCORE_GNU_VTENTRY", /* name */
false, /* partial_inplace */
0, /* src_mask */
0, /* dst_mask */
false), /* pcrel_offset */
/* Reference to global offset table. */
HOWTO (R_SCORE_GOT15, /* type */
0, /* rightshift */
4, /* size */
16, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_signed, /* complain_on_overflow */
score_elf_got15_reloc, /* special_function */
"R_SCORE_GOT15", /* name */
true, /* partial_inplace */
0x00007fff, /* src_mask */
0x00007fff, /* dst_mask */
false), /* pcrel_offset */
/* Low 16 bits of displacement in global offset table. */
HOWTO (R_SCORE_GOT_LO16, /* type */
0, /* rightshift */
4, /* size */
16, /* bitsize */
false, /* pc_relative */
1, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
score_elf_got_lo16_reloc, /* special_function */
"R_SCORE_GOT_LO16", /* name */
true, /* partial_inplace */
0x37ffe, /* src_mask */
0x37ffe, /* dst_mask */
false), /* pcrel_offset */
/* 15 bit call through global offset table. */
HOWTO (R_SCORE_CALL15, /* type */
0, /* rightshift */
4, /* size */
16, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_signed, /* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_SCORE_CALL15", /* name */
true, /* partial_inplace */
0x0000ffff, /* src_mask */
0x0000ffff, /* dst_mask */
false), /* pcrel_offset */
/* 32 bit GP relative reference. */
HOWTO (R_SCORE_GPREL32, /* type */
0, /* rightshift */
4, /* size */
32, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
score_elf_gprel32_reloc, /* special_function */
"R_SCORE_GPREL32", /* name */
true, /* partial_inplace */
0xffffffff, /* src_mask */
0xffffffff, /* dst_mask */
false), /* pcrel_offset */
/* 32 bit symbol relative relocation. */
HOWTO (R_SCORE_REL32, /* type */
0, /* rightshift */
4, /* size */
32, /* bitsize */
false, /* pc_relative */
0, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_SCORE_REL32", /* name */
true, /* partial_inplace */
0xffffffff, /* src_mask */
0xffffffff, /* dst_mask */
false), /* pcrel_offset */
/* R_SCORE_DUMMY_HI16 */
HOWTO (R_SCORE_DUMMY_HI16, /* type */
0, /* rightshift */
4, /* size */
16, /* bitsize */
false, /* pc_relative */
1, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
score_elf_hi16_reloc, /* special_function */
"R_SCORE_DUMMY_HI16", /* name */
true, /* partial_inplace */
0x37fff, /* src_mask */
0x37fff, /* dst_mask */
false), /* pcrel_offset */
/* R_SCORE_IMM30 */
HOWTO (R_SCORE_IMM30, /* type */
2, /* rightshift */
4, /* size */
30, /* bitsize */
false, /* pc_relative */
7, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_SCORE_IMM30", /* name */
false, /* partial_inplace */
0x7f7fff7f80LL, /* src_mask */
0x7f7fff7f80LL, /* dst_mask */
false), /* pcrel_offset */
/* R_SCORE_IMM32 */
HOWTO (R_SCORE_IMM32, /* type */
0, /* rightshift */
4, /* size */
32, /* bitsize */
false, /* pc_relative */
5, /* bitpos */
complain_overflow_dont,/* complain_on_overflow */
bfd_elf_generic_reloc, /* special_function */
"R_SCORE_IMM32", /* name */
false, /* partial_inplace */
0x7f7fff7fe0LL, /* src_mask */
0x7f7fff7fe0LL, /* dst_mask */
false), /* pcrel_offset */
};
struct score_reloc_map
{
bfd_reloc_code_real_type bfd_reloc_val;
unsigned char elf_reloc_val;
};
static const struct score_reloc_map elf32_score_reloc_map[] =
{
{BFD_RELOC_NONE, R_SCORE_NONE},
{BFD_RELOC_HI16_S, R_SCORE_HI16},
{BFD_RELOC_LO16, R_SCORE_LO16},
{BFD_RELOC_SCORE_BCMP, R_SCORE_BCMP},
{BFD_RELOC_SCORE_JMP, R_SCORE_24},
{BFD_RELOC_SCORE_BRANCH, R_SCORE_PC19},
{BFD_RELOC_SCORE16_JMP, R_SCORE16_11},
{BFD_RELOC_SCORE16_BRANCH, R_SCORE16_PC8},
{BFD_RELOC_32, R_SCORE_ABS32},
{BFD_RELOC_16, R_SCORE_ABS16},
{BFD_RELOC_SCORE_DUMMY2, R_SCORE_DUMMY2},
{BFD_RELOC_SCORE_GPREL15, R_SCORE_GP15},
{BFD_RELOC_VTABLE_INHERIT, R_SCORE_GNU_VTINHERIT},
{BFD_RELOC_VTABLE_ENTRY, R_SCORE_GNU_VTENTRY},
{BFD_RELOC_SCORE_GOT15, R_SCORE_GOT15},
{BFD_RELOC_SCORE_GOT_LO16, R_SCORE_GOT_LO16},
{BFD_RELOC_SCORE_CALL15, R_SCORE_CALL15},
{BFD_RELOC_GPREL32, R_SCORE_GPREL32},
{BFD_RELOC_32_PCREL, R_SCORE_REL32},
{BFD_RELOC_SCORE_DUMMY_HI16, R_SCORE_DUMMY_HI16},
{BFD_RELOC_SCORE_IMM30, R_SCORE_IMM30},
{BFD_RELOC_SCORE_IMM32, R_SCORE_IMM32},
};