1/* MIPS ELF specific backend routines.
2   Copyright (C) 2002-2017 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#include "elf/mips.h"
24
25extern bfd_boolean _bfd_mips_elf_mkobject
26  (bfd *);
27extern bfd_boolean _bfd_mips_elf_new_section_hook
28  (bfd *, asection *);
29extern void _bfd_mips_elf_symbol_processing
30  (bfd *, asymbol *);
31extern unsigned int _bfd_mips_elf_eh_frame_address_size
32  (bfd *, asection *);
33extern bfd_boolean _bfd_mips_elf_name_local_section_symbols
34  (bfd *);
35extern bfd_boolean _bfd_mips_elf_section_processing
36  (bfd *, Elf_Internal_Shdr *);
37extern bfd_boolean _bfd_mips_elf_section_from_shdr
38  (bfd *, Elf_Internal_Shdr *, const char *, int);
39extern bfd_boolean _bfd_mips_elf_fake_sections
40  (bfd *, Elf_Internal_Shdr *, asection *);
41extern bfd_boolean _bfd_mips_elf_section_from_bfd_section
42  (bfd *, asection *, int *);
43extern bfd_boolean _bfd_mips_elf_add_symbol_hook
44  (bfd *, struct bfd_link_info *, Elf_Internal_Sym *,
45   const char **, flagword *, asection **, bfd_vma *);
46extern int _bfd_mips_elf_link_output_symbol_hook
47  (struct bfd_link_info *, const char *, Elf_Internal_Sym *,
48   asection *, struct elf_link_hash_entry *);
49extern bfd_boolean _bfd_mips_elf_create_dynamic_sections
50  (bfd *, struct bfd_link_info *);
51extern bfd_boolean _bfd_mips_elf_check_relocs
52  (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
53extern bfd_boolean _bfd_mips_elf_adjust_dynamic_symbol
54  (struct bfd_link_info *, struct elf_link_hash_entry *);
55extern bfd_boolean _bfd_mips_elf_always_size_sections
56  (bfd *, struct bfd_link_info *);
57extern bfd_boolean _bfd_mips_elf_size_dynamic_sections
58  (bfd *, struct bfd_link_info *);
59extern bfd_boolean _bfd_mips_elf_relocate_section
60  (bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
61   Elf_Internal_Rela *, Elf_Internal_Sym *, asection **);
62extern bfd_boolean _bfd_mips_elf_finish_dynamic_symbol
63  (bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
64   Elf_Internal_Sym *);
65extern bfd_boolean _bfd_mips_vxworks_finish_dynamic_symbol
66  (bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
67   Elf_Internal_Sym *);
68extern bfd_boolean _bfd_mips_elf_finish_dynamic_sections
69  (bfd *, struct bfd_link_info *);
70extern bfd_boolean _bfd_mips_elf_sort_relocs_p
71  (asection *);
72extern void _bfd_mips_elf_final_write_processing
73  (bfd *, bfd_boolean);
74extern int _bfd_mips_elf_additional_program_headers
75  (bfd *, struct bfd_link_info *);
76extern bfd_boolean _bfd_mips_elf_modify_segment_map
77  (bfd *, struct bfd_link_info *);
78extern asection * _bfd_mips_elf_gc_mark_hook
79  (asection *, struct bfd_link_info *, Elf_Internal_Rela *,
80   struct elf_link_hash_entry *, Elf_Internal_Sym *);
81extern bfd_boolean _bfd_mips_elf_gc_sweep_hook
82  (bfd *, struct bfd_link_info *, asection *, const Elf_Internal_Rela *);
83extern void _bfd_mips_elf_copy_indirect_symbol
84  (struct bfd_link_info *, struct elf_link_hash_entry *,
85   struct elf_link_hash_entry *);
86extern bfd_boolean _bfd_mips_elf_ignore_discarded_relocs
87  (asection *);
88extern bfd_boolean _bfd_mips_elf_is_target_special_symbol
89  (bfd *abfd, asymbol *sym);
90extern bfd_boolean _bfd_mips_elf_find_nearest_line
91  (bfd *, asymbol **, asection *, bfd_vma,
92   const char **, const char **, unsigned int *, unsigned int *);
93extern bfd_boolean _bfd_mips_elf_find_inliner_info
94  (bfd *, const char **, const char **, unsigned int *);
95extern bfd_boolean _bfd_mips_elf_set_section_contents
96  (bfd *, asection *, const void *, file_ptr, bfd_size_type);
97extern bfd_byte *_bfd_elf_mips_get_relocated_section_contents
98  (bfd *, struct bfd_link_info *, struct bfd_link_order *,
99   bfd_byte *, bfd_boolean, asymbol **);
100extern bfd_boolean _bfd_mips_elf_relax_section
101  (bfd *abfd, asection *sec, struct bfd_link_info *link_info,
102   bfd_boolean *again);
103extern struct bfd_link_hash_table *_bfd_mips_elf_link_hash_table_create
104  (bfd *);
105extern struct bfd_link_hash_table *_bfd_mips_vxworks_link_hash_table_create
106  (bfd *);
107extern bfd_boolean _bfd_mips_elf_final_link
108  (bfd *, struct bfd_link_info *);
109extern bfd_boolean _bfd_mips_elf_merge_private_bfd_data
110  (bfd *, struct bfd_link_info *);
111extern bfd_boolean _bfd_mips_elf_set_private_flags
112  (bfd *, flagword);
113extern const char * _bfd_mips_fp_abi_string
114  (int);
115extern bfd_boolean _bfd_mips_elf_print_private_bfd_data
116  (bfd *, void *);
117extern bfd_boolean _bfd_mips_elf_discard_info
118  (bfd *, struct elf_reloc_cookie *, struct bfd_link_info *);
119extern bfd_boolean _bfd_mips_elf_write_section
120  (bfd *, struct bfd_link_info *, asection *, bfd_byte *);
121
122extern bfd_boolean _bfd_mips_elf_read_ecoff_info
123  (bfd *, asection *, struct ecoff_debug_info *);
124extern void _bfd_mips_elf_reloc_unshuffle
125  (bfd *, int, bfd_boolean, bfd_byte *);
126extern void _bfd_mips_elf_reloc_shuffle
127  (bfd *, int, bfd_boolean, bfd_byte *);
128extern bfd_reloc_status_type _bfd_mips_elf_gprel16_with_gp
129  (bfd *, asymbol *, arelent *, asection *, bfd_boolean, void *, bfd_vma);
130extern bfd_reloc_status_type _bfd_mips_elf32_gprel16_reloc
131  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
132extern bfd_reloc_status_type _bfd_mips_elf_hi16_reloc
133  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
134extern bfd_reloc_status_type _bfd_mips_elf_got16_reloc
135  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
136extern bfd_reloc_status_type _bfd_mips_elf_lo16_reloc
137  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
138extern bfd_reloc_status_type _bfd_mips_elf_generic_reloc
139  (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
140extern unsigned long _bfd_elf_mips_mach
141  (flagword);
142extern bfd_boolean _bfd_mips_relax_section
143  (bfd *, asection *, struct bfd_link_info *, bfd_boolean *);
144extern bfd_vma _bfd_mips_elf_sign_extend
145  (bfd_vma, int);
146extern void _bfd_mips_elf_merge_symbol_attribute
147  (struct elf_link_hash_entry *, const Elf_Internal_Sym *, bfd_boolean, bfd_boolean);
148extern char *_bfd_mips_elf_get_target_dtag (bfd_vma);
149extern bfd_boolean _bfd_mips_elf_ignore_undef_symbol
150  (struct elf_link_hash_entry *);
151extern void _bfd_mips_elf_use_plts_and_copy_relocs
152  (struct bfd_link_info *);
153extern void _bfd_mips_elf_linker_flags
154  (struct bfd_link_info *, bfd_boolean, bfd_boolean);
155extern bfd_boolean _bfd_mips_elf_init_stubs
156  (struct bfd_link_info *,
157   asection *(*) (const char *, asection *, asection *));
158extern bfd_vma _bfd_mips_elf_plt_sym_val
159  (bfd_vma, const asection *, const arelent *rel);
160extern long _bfd_mips_elf_get_synthetic_symtab
161  (bfd *, long, asymbol **, long, asymbol **, asymbol **);
162extern bfd_boolean _bfd_mips_elf_gc_mark_extra_sections
163  (struct bfd_link_info *, elf_gc_mark_hook_fn);
164extern void _bfd_mips_post_process_headers
165  (bfd *abfd, struct bfd_link_info *link_info);
166
167extern const struct bfd_elf_special_section _bfd_mips_elf_special_sections [];
168
169extern bfd_boolean _bfd_mips_elf_common_definition (Elf_Internal_Sym *);
170
171extern int _bfd_mips_elf_compact_eh_encoding (struct bfd_link_info *);
172extern int _bfd_mips_elf_cant_unwind_opcode (struct bfd_link_info *);
173
174static inline bfd_boolean
175gprel16_reloc_p (unsigned int r_type)
176{
177  return (r_type == R_MIPS_GPREL16
178	  || r_type == R_MIPS16_GPREL
179	  || r_type == R_MICROMIPS_GPREL16
180	  || r_type == R_MICROMIPS_GPREL7_S2);
181}
182
183static inline bfd_boolean
184literal_reloc_p (int r_type)
185{
186  return r_type == R_MIPS_LITERAL || r_type == R_MICROMIPS_LITERAL;
187}
188
189#define elf_backend_common_definition   _bfd_mips_elf_common_definition
190#define elf_backend_name_local_section_symbols \
191  _bfd_mips_elf_name_local_section_symbols
192#define elf_backend_special_sections _bfd_mips_elf_special_sections
193#define elf_backend_eh_frame_address_size _bfd_mips_elf_eh_frame_address_size
194#define elf_backend_merge_symbol_attribute  _bfd_mips_elf_merge_symbol_attribute
195#define elf_backend_ignore_undef_symbol _bfd_mips_elf_ignore_undef_symbol
196#define elf_backend_post_process_headers _bfd_mips_post_process_headers
197#define elf_backend_compact_eh_encoding _bfd_mips_elf_compact_eh_encoding
198#define elf_backend_cant_unwind_opcode _bfd_mips_elf_cant_unwind_opcode
199#define elf_backend_always_renumber_dynsyms TRUE
200