1/* SPARC ELF specific backend routines.
2   Copyright 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
3
4   This file is part of BFD, the Binary File Descriptor library.
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 3 of the License, or
9   (at your option) any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software
18   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19   MA 02110-1301, USA.  */
20
21#include "elf/common.h"
22#include "elf/internal.h"
23
24struct _bfd_sparc_elf_section_data
25{
26  struct bfd_elf_section_data elf;
27  unsigned int do_relax, reloc_count;
28};
29
30#define sec_do_relax(sec) \
31  ((struct _bfd_sparc_elf_section_data *) elf_section_data (sec))->do_relax
32#define canon_reloc_count(sec) \
33  ((struct _bfd_sparc_elf_section_data *) elf_section_data (sec))->reloc_count
34
35struct _bfd_sparc_elf_app_reg
36{
37  unsigned char bind;
38  unsigned short shndx;
39  bfd *abfd;
40  char *name;
41};
42
43/* Sparc ELF linker hash table.  */
44
45struct _bfd_sparc_elf_link_hash_table
46{
47  struct elf_link_hash_table elf;
48
49  /* Short-cuts to get to dynamic linker sections.  */
50  asection *sdynbss;
51  asection *srelbss;
52
53  union
54  {
55    bfd_signed_vma refcount;
56    bfd_vma offset;
57  } tls_ldm_got;
58
59  /* Small local sym cache.  */
60  struct sym_cache sym_cache;
61
62  /* Used by local STT_GNU_IFUNC symbols.  */
63  htab_t loc_hash_table;
64  void *loc_hash_memory;
65
66  /* True if the target system is VxWorks.  */
67  int is_vxworks;
68
69  /* The (unloaded but important) .rela.plt.unloaded section, for VxWorks.  */
70  asection *srelplt2;
71
72  void (*put_word) (bfd *, bfd_vma, void *);
73  bfd_vma (*r_info) (Elf_Internal_Rela *, bfd_vma, bfd_vma);
74  bfd_vma (*r_symndx) (bfd_vma);
75  int (*build_plt_entry) (bfd *, asection *, bfd_vma, bfd_vma, bfd_vma *);
76  const char *dynamic_interpreter;
77  int dynamic_interpreter_size;
78  unsigned int word_align_power;
79  unsigned int align_power_max;
80  unsigned int plt_header_size;
81  unsigned int plt_entry_size;
82  int bytes_per_word;
83  int bytes_per_rela;
84  int dtpoff_reloc;
85  int dtpmod_reloc;
86  int tpoff_reloc;
87
88  struct _bfd_sparc_elf_app_reg app_regs [4];
89};
90
91/* Get the SPARC ELF linker hash table from a link_info structure.  */
92
93#define _bfd_sparc_elf_hash_table(p) \
94  (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
95  == SPARC_ELF_DATA ? ((struct _bfd_sparc_elf_link_hash_table *) ((p)->hash)) : NULL)
96
97extern reloc_howto_type *_bfd_sparc_elf_reloc_type_lookup
98  (bfd *, bfd_reloc_code_real_type);
99extern reloc_howto_type *_bfd_sparc_elf_reloc_name_lookup
100  (bfd *, const char *);
101extern void _bfd_sparc_elf_info_to_howto
102  (bfd *, arelent *, Elf_Internal_Rela *);
103extern reloc_howto_type *_bfd_sparc_elf_info_to_howto_ptr
104  (unsigned int);
105extern bfd_boolean _bfd_sparc_elf_mkobject
106  (bfd *);
107extern struct bfd_link_hash_table *_bfd_sparc_elf_link_hash_table_create
108  (bfd *);
109extern void _bfd_sparc_elf_link_hash_table_free
110  (struct bfd_link_hash_table *);
111extern bfd_boolean _bfd_sparc_elf_create_dynamic_sections
112  (bfd *, struct bfd_link_info *);
113extern void _bfd_sparc_elf_copy_indirect_symbol
114  (struct bfd_link_info *,
115   struct elf_link_hash_entry *,
116   struct elf_link_hash_entry *);
117extern bfd_boolean _bfd_sparc_elf_check_relocs
118  (bfd *, struct bfd_link_info *,
119   asection *, const Elf_Internal_Rela *);
120extern asection *_bfd_sparc_elf_gc_mark_hook
121  (asection *, struct bfd_link_info *,
122   Elf_Internal_Rela *, struct elf_link_hash_entry *,
123   Elf_Internal_Sym *);
124extern bfd_boolean _bfd_sparc_elf_gc_sweep_hook
125  (bfd *, struct bfd_link_info *,
126   asection *, const Elf_Internal_Rela *);
127extern bfd_boolean _bfd_sparc_elf_adjust_dynamic_symbol
128  (struct bfd_link_info *, struct elf_link_hash_entry *);
129extern bfd_boolean _bfd_sparc_elf_omit_section_dynsym
130  (bfd *, struct bfd_link_info *, asection *);
131extern bfd_boolean _bfd_sparc_elf_size_dynamic_sections
132  (bfd *, struct bfd_link_info *);
133extern bfd_boolean _bfd_sparc_elf_new_section_hook
134  (bfd *, asection *);
135extern bfd_boolean _bfd_sparc_elf_relax_section
136  (bfd *, struct bfd_section *, struct bfd_link_info *, bfd_boolean *);
137extern bfd_boolean _bfd_sparc_elf_relocate_section
138  (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
139   Elf_Internal_Rela *, Elf_Internal_Sym *, asection **);
140extern bfd_boolean _bfd_sparc_elf_finish_dynamic_symbol
141  (bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
142   Elf_Internal_Sym *sym);
143extern bfd_boolean _bfd_sparc_elf_finish_dynamic_sections
144  (bfd *, struct bfd_link_info *);
145extern bfd_boolean _bfd_sparc_elf_object_p
146  (bfd *);
147extern bfd_vma _bfd_sparc_elf_plt_sym_val
148  (bfd_vma, const asection *, const arelent *);
149