1
1
/* CRIS-specific support for 32-bit ELF.
2
Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
2
Copyright 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
3
3
Contributed by Axis Communications AB.
4
4
Written by Hans-Peter Nilsson, based on elf32-fr30.c
5
5
PIC and shlib bits based primarily on elf32-m68k.c and elf32-i386.c.
848
848
sym = local_syms + r_symndx;
849
849
sec = local_sections [r_symndx];
850
relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel);
850
relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel);
852
852
symname = (bfd_elf_string_from_elf_section
853
853
(input_bfd, symtab_hdr->sh_link, sym->st_name));
859
859
bfd_boolean warned;
860
860
bfd_boolean unresolved_reloc;
862
RELOC_FOR_GLOBAL_SYMBOL (h, sym_hashes, r_symndx, symtab_hdr, relocation, sec, unresolved_reloc, info, warned);
862
RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel,
863
r_symndx, symtab_hdr, sym_hashes,
865
unresolved_reloc, warned);
864
867
if (unresolved_reloc
865
868
/* Perhaps we should detect the cases that
957
960
statically linking PIC code, or when using -Bsymbolic. Check
958
961
that we instead have a GOT entry as done for us by
959
962
elf_cris_adjust_dynamic_symbol, and drop through into the
960
ordinary GOT cases. */
961
if (h != NULL && h->got.offset == (bfd_vma) -1)
963
ordinary GOT cases. This must not happen for the
964
executable, because any reference it does to a function
965
that is satisfied by a DSO must generate a PLT. We assume
966
these call-specific relocs don't address non-functions. */
968
&& (h->got.offset == (bfd_vma) -1
970
&& !((h->elf_link_hash_flags
971
& ELF_LINK_HASH_DEF_REGULAR) != 0
972
|| ((h->elf_link_hash_flags
973
& ELF_LINK_HASH_DEF_DYNAMIC) == 0
974
&& h->root.type == bfd_link_hash_undefweak)))))
963
976
(*_bfd_error_handler)
964
(_("%s: No PLT nor GOT for relocation %s against symbol `%s' from %s section"),
977
((h->got.offset == (bfd_vma) -1)
978
? _("%s: No PLT nor GOT for relocation %s against\
979
symbol `%s' from %s section")
980
: _("%s: No PLT for relocation %s against\
981
symbol `%s' from %s section"),
965
982
bfd_archive_filename (input_bfd),
966
983
cris_elf_howto_table[r_type].name,
967
984
symname[0] != '\0' ? symname : _("[whose name is lost]"),
994
1011
if (!elf_hash_table (info)->dynamic_sections_created
995
1012
|| (! info->shared
996
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
1013
&& ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)
1014
|| h->type == STT_FUNC
1015
|| (h->elf_link_hash_flags
1016
& ELF_LINK_HASH_NEEDS_PLT)))
997
1017
|| (info->shared
998
1018
&& (info->symbolic || h->dynindx == -1)
999
1019
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
1001
1021
/* This wasn't checked above for ! info->shared, but
1002
must hold there if we get here; the symbol must be
1003
defined in the regular program, or be undefweak. */
1022
must hold there if we get here; the symbol must
1023
be defined in the regular program or be undefweak
1024
or be a function or otherwise need a PLT. */
1004
1025
BFD_ASSERT (!elf_hash_table (info)->dynamic_sections_created
1005
1026
|| info->shared
1006
1027
|| (h->elf_link_hash_flags
1007
1028
& ELF_LINK_HASH_DEF_REGULAR) != 0
1029
|| h->type == STT_FUNC
1030
|| (h->elf_link_hash_flags
1031
& ELF_LINK_HASH_NEEDS_PLT)
1008
1032
|| h->root.type == bfd_link_hash_undefweak);
1010
1034
/* This is actually a static link, or it is a
1296
sec = local_sections[r_symndx];
1299
BFD_ASSERT (h->root.type == bfd_link_hash_defined
1301
== bfd_link_hash_defweak));
1302
sec = h->root.u.def.section;
1304
if (sec != NULL && bfd_is_abs_section (sec))
1319
if (bfd_is_abs_section (sec))
1306
1321
else if (sec == NULL || sec->owner == NULL)
1427
1442
to this function. Note that we embed knowledge that "incoming"
1428
1443
.got goes after .got.plt in the output without padding (pointer
1429
1444
aligned). However, that knowledge is present in several other
1430
places too, here and in elflink.h at least. */
1431
1446
bfd_vma got_offset
1433
1448
? gotplt_offset
1520
/* We don't emit .got relocs for symbols that aren't in the
1521
dynamic-symbols table for an ordinary program and are either defined
1522
by the program or are undefined weak symbols. */
1535
/* For an ordinary program, we emit .got relocs only for symbols that
1536
are in the dynamic-symbols table and are either defined by the
1537
program or are undefined weak symbols, or are function symbols
1538
where we do not output a PLT: the PLT reloc was output above and all
1539
references to the function symbol are redirected to the PLT. */
1523
1540
if (h->got.offset != (bfd_vma) -1
1524
1541
&& (info->shared
1525
1542
|| (h->dynindx != -1
1543
&& h->plt.offset == (bfd_vma) -1
1526
1544
&& (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
1527
1545
&& h->root.type != bfd_link_hash_undefweak)))
1779
1797
struct elf_link_hash_entry **sym_hashes;
1780
1798
bfd_signed_vma *local_got_refcounts;
1781
1799
const Elf_Internal_Rela *rel, *relend;
1782
unsigned long r_symndx;
1783
struct elf_link_hash_entry *h;
1785
1801
asection *sgot;
1786
1802
asection *srelgot;
1788
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1789
sym_hashes = elf_sym_hashes (abfd);
1790
local_got_refcounts = elf_local_got_refcounts (abfd);
1792
1804
dynobj = elf_hash_table (info)->dynobj;
1793
1805
if (dynobj == NULL)
1808
symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
1809
sym_hashes = elf_sym_hashes (abfd);
1810
local_got_refcounts = elf_local_got_refcounts (abfd);
1796
1812
sgot = bfd_get_section_by_name (dynobj, ".got");
1797
1813
srelgot = bfd_get_section_by_name (dynobj, ".rela.got");
1799
1815
relend = relocs + sec->reloc_count;
1800
1816
for (rel = relocs; rel < relend; rel++)
1818
unsigned long r_symndx;
1819
struct elf_link_hash_entry *h;
1802
1821
switch (ELF32_R_TYPE (rel->r_info))
1804
1823
case R_CRIS_16_GOT:
1843
1862
r_symndx = ELF32_R_SYM (rel->r_info);
1844
1863
if (r_symndx < symtab_hdr->sh_info)
1845
1864
goto local_got_reloc;
1847
1866
case R_CRIS_32_PLT_GOTREL:
1848
1867
/* FIXME: We don't garbage-collect away the .got section. */
1849
1868
if (local_got_refcounts != NULL)
1850
1869
local_got_refcounts[-1]--;
1851
1870
/* Fall through. */
1853
1871
case R_CRIS_8_PCREL:
1854
1872
case R_CRIS_16_PCREL:
1855
1873
case R_CRIS_32_PCREL:
1934
1952
want to do this:
1936
1954
- When all PLT references are GOTPLT references, and there are GOT
1937
references. We don't have to generate a PLT at all.
1955
references, and this is not the executable. We don't have to
1956
generate a PLT at all.
1939
- When there are both (ordinary) PLT references and GOT references.
1958
- When there are both (ordinary) PLT references and GOT references,
1959
and this isn't the executable.
1940
1960
We want to make the PLT reference use the ordinary GOT entry rather
1941
than a run-time dynamically resolved GOTPLT entry (since the GOT
1942
entry will have to be resolved at startup anyway).
1961
than R_CRIS_JUMP_SLOT, a run-time dynamically resolved GOTPLT entry,
1962
since the GOT entry will have to be resolved at startup anyway.
1944
1964
Though the latter case is handled when room for the PLT is allocated,
1967
By folding into the GOT, we may need a round-trip to a PLT in the
1968
executable for calls, a loss in performance. Still, losing a
1969
reloc is a win in size and at least in start-up time.
1947
1971
Note that this function is called before symbols are forced local by
1948
1972
version scripts. The differing cases are handled by
1949
1973
elf_cris_hide_symbol. */
2053
/* If there are only GOT references and GOTPLT references to this
2054
PLT entry, get rid of the PLT. */
2055
if (! elf_cris_try_fold_plt_to_got ((struct elf_cris_link_hash_entry *)
2077
/* If we had a R_CRIS_GLOB_DAT that didn't have to point to a PLT;
2078
where a pointer-equivalent symbol was unimportant (i.e. more
2079
like R_CRIS_JUMP_SLOT after symbol evaluation) we could get rid
2080
of the PLT. We can't for the executable, because the GOT
2081
entries will point to the PLT there (and be constant). */
2083
&& !elf_cris_try_fold_plt_to_got ((struct elf_cris_link_hash_entry*)
2059
2087
/* GC or folding may have rendered this entry unused. */
2092
2120
/* If there's already a GOT entry, use that, not a .got.plt. A
2093
2121
GOT field still has a reference count when we get here; it's
2094
not yet changed to an offset. */
2095
if (h->got.refcount > 0)
2122
not yet changed to an offset. We can't do this for an
2123
executable, because then the reloc associated with the PLT
2124
would get a non-PLT reloc pointing to the PLT. FIXME: Move
2125
this to elf_cris_try_fold_plt_to_got. */
2126
if (info->shared && h->got.refcount > 0)
2097
2128
h->got.refcount += h->plt.refcount;
2608
2639
/* This relocation describes the C++ object vtable hierarchy.
2609
2640
Reconstruct it for later use during GC. */
2610
2641
case R_CRIS_GNU_VTINHERIT:
2611
if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2642
if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
2615
2646
/* This relocation describes which C++ vtable entries are actually
2616
2647
used. Record for later use during GC. */
2617
2648
case R_CRIS_GNU_VTENTRY:
2618
if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2649
if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
2778
2809
the .dynamic section. The DT_DEBUG entry is filled in by the
2779
2810
dynamic linker and used by the debugger. */
2780
2811
#define add_dynamic_entry(TAG, VAL) \
2781
bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
2812
_bfd_elf_add_dynamic_entry (info, TAG, VAL)
2783
2814
if (!info->shared)
2866
2897
/* If we're not creating a shared library and have a symbol which is
2867
2898
referred to by .got references, but the symbol is defined locally,
2868
(or rather, not not defined by a DSO) then lose the reloc for the
2869
.got (don't allocate room for it). */
2870
if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0)
2899
(or rather, not defined by a DSO) then lose the reloc for the .got
2900
(don't allocate room for it). Likewise for relocs for something
2901
for which we create a PLT. */
2902
if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
2903
|| h->root.plt.refcount > 0)
2872
2905
if (h->root.got.refcount > 0
2873
2906
/* The size of this section is only valid and in sync with the
2893
2926
introduce new problems. Of course we don't do this if we're
2894
2927
exporting all dynamic symbols. */
2895
2928
if (! info->export_dynamic
2896
&& (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
2929
&& (h->root.elf_link_hash_flags
2930
& (ELF_LINK_HASH_DEF_DYNAMIC|ELF_LINK_HASH_REF_DYNAMIC)) == 0)
2898
2932
h->root.dynindx = -1;
2899
2933
_bfd_elf_strtab_delref (elf_hash_table (info)->dynstr,
3056
3090
#define elf_backend_create_dynamic_sections \
3057
3091
_bfd_elf_create_dynamic_sections
3058
3092
#define bfd_elf32_bfd_final_link \
3059
_bfd_elf32_gc_common_final_link
3093
bfd_elf_gc_common_final_link
3060
3094
#define elf_backend_hide_symbol elf_cris_hide_symbol
3061
3095
#define elf_backend_reloc_type_class elf_cris_reloc_type_class
3064
3098
#define elf_backend_plt_readonly 1
3065
3099
#define elf_backend_want_plt_sym 0
3066
3100
#define elf_backend_got_header_size 12
3067
#define elf_backend_plt_header_size PLT_ENTRY_SIZE
3069
3102
/* Later, we my want to optimize RELA entries into REL entries for dynamic
3070
3103
linking and libraries (if it's a win of any significance). Until then,