1 /* MIPS-specific support for ELF
2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
6 Most of the information added by Ian Lance Taylor, Cygnus Support,
8 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
9 <mark@codesourcery.com>
10 Traditional MIPS targets support added by Koundinya.K, Dansk Data
11 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
13 This file is part of BFD, the Binary File Descriptor library.
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 3 of the License, or
18 (at your option) any later version.
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
28 MA 02110-1301, USA. */
31 /* This file handles functionality common to the different MIPS ABI's. */
36 #include "libiberty.h"
38 #include "elfxx-mips.h"
40 #include "elf-vxworks.h"
42 /* Get the ECOFF swapping routines. */
44 #include "coff/symconst.h"
45 #include "coff/ecoff.h"
46 #include "coff/mips.h"
50 /* This structure is used to hold information about one GOT entry.
51 There are three types of entry:
53 (1) absolute addresses
55 (2) SYMBOL + OFFSET addresses, where SYMBOL is local to an input bfd
56 (abfd != NULL, symndx >= 0)
57 (3) SYMBOL addresses, where SYMBOL is not local to an input bfd
58 (abfd != NULL, symndx == -1)
60 Type (3) entries are treated differently for different types of GOT.
61 In the "master" GOT -- i.e. the one that describes every GOT
62 reference needed in the link -- the mips_got_entry is keyed on both
63 the symbol and the input bfd that references it. If it turns out
64 that we need multiple GOTs, we can then use this information to
65 create separate GOTs for each input bfd.
67 However, we want each of these separate GOTs to have at most one
68 entry for a given symbol, so their type (3) entries are keyed only
69 on the symbol. The input bfd given by the "abfd" field is somewhat
70 arbitrary in this case.
72 This means that when there are multiple GOTs, each GOT has a unique
73 mips_got_entry for every symbol within it. We can therefore use the
74 mips_got_entry fields (tls_type and gotidx) to track the symbol's
77 However, if it turns out that we need only a single GOT, we continue
78 to use the master GOT to describe it. There may therefore be several
79 mips_got_entries for the same symbol, each with a different input bfd.
80 We want to make sure that each symbol gets a unique GOT entry, so when
81 there's a single GOT, we use the symbol's hash entry, not the
82 mips_got_entry fields, to track a symbol's GOT index. */
85 /* The input bfd in which the symbol is defined. */
87 /* The index of the symbol, as stored in the relocation r_info, if
88 we have a local symbol; -1 otherwise. */
92 /* If abfd == NULL, an address that must be stored in the got. */
94 /* If abfd != NULL && symndx != -1, the addend of the relocation
95 that should be added to the symbol value. */
97 /* If abfd != NULL && symndx == -1, the hash table entry
98 corresponding to symbol in the GOT. The symbol's entry
99 is in the local area if h->global_got_area is GGA_NONE,
100 otherwise it is in the global area. */
101 struct mips_elf_link_hash_entry
*h
;
104 /* The TLS types included in this GOT entry (specifically, GD and
105 IE). The GD and IE flags can be added as we encounter new
106 relocations. LDM can also be set; it will always be alone, not
107 combined with any GD or IE flags. An LDM GOT entry will be
108 a local symbol entry with r_symndx == 0. */
109 unsigned char tls_type
;
111 /* The offset from the beginning of the .got section to the entry
112 corresponding to this symbol+addend. If it's a global symbol
113 whose offset is yet to be decided, it's going to be -1. */
117 /* This structure describes a range of addends: [MIN_ADDEND, MAX_ADDEND].
118 The structures form a non-overlapping list that is sorted by increasing
120 struct mips_got_page_range
122 struct mips_got_page_range
*next
;
123 bfd_signed_vma min_addend
;
124 bfd_signed_vma max_addend
;
127 /* This structure describes the range of addends that are applied to page
128 relocations against a given symbol. */
129 struct mips_got_page_entry
131 /* The input bfd in which the symbol is defined. */
133 /* The index of the symbol, as stored in the relocation r_info. */
135 /* The ranges for this page entry. */
136 struct mips_got_page_range
*ranges
;
137 /* The maximum number of page entries needed for RANGES. */
141 /* This structure is used to hold .got information when linking. */
145 /* The global symbol in the GOT with the lowest index in the dynamic
147 struct elf_link_hash_entry
*global_gotsym
;
148 /* The number of global .got entries. */
149 unsigned int global_gotno
;
150 /* The number of global .got entries that are in the GGA_RELOC_ONLY area. */
151 unsigned int reloc_only_gotno
;
152 /* The number of .got slots used for TLS. */
153 unsigned int tls_gotno
;
154 /* The first unused TLS .got entry. Used only during
155 mips_elf_initialize_tls_index. */
156 unsigned int tls_assigned_gotno
;
157 /* The number of local .got entries, eventually including page entries. */
158 unsigned int local_gotno
;
159 /* The maximum number of page entries needed. */
160 unsigned int page_gotno
;
161 /* The number of local .got entries we have used. */
162 unsigned int assigned_gotno
;
163 /* A hash table holding members of the got. */
164 struct htab
*got_entries
;
165 /* A hash table of mips_got_page_entry structures. */
166 struct htab
*got_page_entries
;
167 /* A hash table mapping input bfds to other mips_got_info. NULL
168 unless multi-got was necessary. */
169 struct htab
*bfd2got
;
170 /* In multi-got links, a pointer to the next got (err, rather, most
171 of the time, it points to the previous got). */
172 struct mips_got_info
*next
;
173 /* This is the GOT index of the TLS LDM entry for the GOT, MINUS_ONE
174 for none, or MINUS_TWO for not yet assigned. This is needed
175 because a single-GOT link may have multiple hash table entries
176 for the LDM. It does not get initialized in multi-GOT mode. */
177 bfd_vma tls_ldm_offset
;
180 /* Map an input bfd to a got in a multi-got link. */
182 struct mips_elf_bfd2got_hash
185 struct mips_got_info
*g
;
188 /* Structure passed when traversing the bfd2got hash table, used to
189 create and merge bfd's gots. */
191 struct mips_elf_got_per_bfd_arg
193 /* A hashtable that maps bfds to gots. */
195 /* The output bfd. */
197 /* The link information. */
198 struct bfd_link_info
*info
;
199 /* A pointer to the primary got, i.e., the one that's going to get
200 the implicit relocations from DT_MIPS_LOCAL_GOTNO and
202 struct mips_got_info
*primary
;
203 /* A non-primary got we're trying to merge with other input bfd's
205 struct mips_got_info
*current
;
206 /* The maximum number of got entries that can be addressed with a
208 unsigned int max_count
;
209 /* The maximum number of page entries needed by each got. */
210 unsigned int max_pages
;
211 /* The total number of global entries which will live in the
212 primary got and be automatically relocated. This includes
213 those not referenced by the primary GOT but included in
215 unsigned int global_count
;
218 /* Another structure used to pass arguments for got entries traversal. */
220 struct mips_elf_set_global_got_offset_arg
222 struct mips_got_info
*g
;
224 unsigned int needed_relocs
;
225 struct bfd_link_info
*info
;
228 /* A structure used to count TLS relocations or GOT entries, for GOT
229 entry or ELF symbol table traversal. */
231 struct mips_elf_count_tls_arg
233 struct bfd_link_info
*info
;
237 struct _mips_elf_section_data
239 struct bfd_elf_section_data elf
;
246 #define mips_elf_section_data(sec) \
247 ((struct _mips_elf_section_data *) elf_section_data (sec))
249 #define is_mips_elf(bfd) \
250 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
251 && elf_tdata (bfd) != NULL \
252 && elf_object_id (bfd) == MIPS_ELF_DATA)
254 /* The ABI says that every symbol used by dynamic relocations must have
255 a global GOT entry. Among other things, this provides the dynamic
256 linker with a free, directly-indexed cache. The GOT can therefore
257 contain symbols that are not referenced by GOT relocations themselves
258 (in other words, it may have symbols that are not referenced by things
259 like R_MIPS_GOT16 and R_MIPS_GOT_PAGE).
261 GOT relocations are less likely to overflow if we put the associated
262 GOT entries towards the beginning. We therefore divide the global
263 GOT entries into two areas: "normal" and "reloc-only". Entries in
264 the first area can be used for both dynamic relocations and GP-relative
265 accesses, while those in the "reloc-only" area are for dynamic
268 These GGA_* ("Global GOT Area") values are organised so that lower
269 values are more general than higher values. Also, non-GGA_NONE
270 values are ordered by the position of the area in the GOT. */
272 #define GGA_RELOC_ONLY 1
275 /* Information about a non-PIC interface to a PIC function. There are
276 two ways of creating these interfaces. The first is to add:
279 addiu $25,$25,%lo(func)
281 immediately before a PIC function "func". The second is to add:
285 addiu $25,$25,%lo(func)
287 to a separate trampoline section.
289 Stubs of the first kind go in a new section immediately before the
290 target function. Stubs of the second kind go in a single section
291 pointed to by the hash table's "strampoline" field. */
292 struct mips_elf_la25_stub
{
293 /* The generated section that contains this stub. */
294 asection
*stub_section
;
296 /* The offset of the stub from the start of STUB_SECTION. */
299 /* One symbol for the original function. Its location is available
300 in H->root.root.u.def. */
301 struct mips_elf_link_hash_entry
*h
;
304 /* Macros for populating a mips_elf_la25_stub. */
306 #define LA25_LUI(VAL) (0x3c190000 | (VAL)) /* lui t9,VAL */
307 #define LA25_J(VAL) (0x08000000 | (((VAL) >> 2) & 0x3ffffff)) /* j VAL */
308 #define LA25_ADDIU(VAL) (0x27390000 | (VAL)) /* addiu t9,t9,VAL */
310 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
311 the dynamic symbols. */
313 struct mips_elf_hash_sort_data
315 /* The symbol in the global GOT with the lowest dynamic symbol table
317 struct elf_link_hash_entry
*low
;
318 /* The least dynamic symbol table index corresponding to a non-TLS
319 symbol with a GOT entry. */
320 long min_got_dynindx
;
321 /* The greatest dynamic symbol table index corresponding to a symbol
322 with a GOT entry that is not referenced (e.g., a dynamic symbol
323 with dynamic relocations pointing to it from non-primary GOTs). */
324 long max_unref_got_dynindx
;
325 /* The greatest dynamic symbol table index not corresponding to a
326 symbol without a GOT entry. */
327 long max_non_got_dynindx
;
330 /* The MIPS ELF linker needs additional information for each symbol in
331 the global hash table. */
333 struct mips_elf_link_hash_entry
335 struct elf_link_hash_entry root
;
337 /* External symbol information. */
340 /* The la25 stub we have created for ths symbol, if any. */
341 struct mips_elf_la25_stub
*la25_stub
;
343 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
345 unsigned int possibly_dynamic_relocs
;
347 /* If there is a stub that 32 bit functions should use to call this
348 16 bit function, this points to the section containing the stub. */
351 /* If there is a stub that 16 bit functions should use to call this
352 32 bit function, this points to the section containing the stub. */
355 /* This is like the call_stub field, but it is used if the function
356 being called returns a floating point value. */
357 asection
*call_fp_stub
;
361 #define GOT_TLS_LDM 2
363 #define GOT_TLS_OFFSET_DONE 0x40
364 #define GOT_TLS_DONE 0x80
365 unsigned char tls_type
;
367 /* This is only used in single-GOT mode; in multi-GOT mode there
368 is one mips_got_entry per GOT entry, so the offset is stored
369 there. In single-GOT mode there may be many mips_got_entry
370 structures all referring to the same GOT slot. It might be
371 possible to use root.got.offset instead, but that field is
372 overloaded already. */
373 bfd_vma tls_got_offset
;
375 /* The highest GGA_* value that satisfies all references to this symbol. */
376 unsigned int global_got_area
: 2;
378 /* True if all GOT relocations against this symbol are for calls. This is
379 a looser condition than no_fn_stub below, because there may be other
380 non-call non-GOT relocations against the symbol. */
381 unsigned int got_only_for_calls
: 1;
383 /* True if one of the relocations described by possibly_dynamic_relocs
384 is against a readonly section. */
385 unsigned int readonly_reloc
: 1;
387 /* True if there is a relocation against this symbol that must be
388 resolved by the static linker (in other words, if the relocation
389 cannot possibly be made dynamic). */
390 unsigned int has_static_relocs
: 1;
392 /* True if we must not create a .MIPS.stubs entry for this symbol.
393 This is set, for example, if there are relocations related to
394 taking the function's address, i.e. any but R_MIPS_CALL*16 ones.
395 See "MIPS ABI Supplement, 3rd Edition", p. 4-20. */
396 unsigned int no_fn_stub
: 1;
398 /* Whether we need the fn_stub; this is true if this symbol appears
399 in any relocs other than a 16 bit call. */
400 unsigned int need_fn_stub
: 1;
402 /* True if this symbol is referenced by branch relocations from
403 any non-PIC input file. This is used to determine whether an
404 la25 stub is required. */
405 unsigned int has_nonpic_branches
: 1;
407 /* Does this symbol need a traditional MIPS lazy-binding stub
408 (as opposed to a PLT entry)? */
409 unsigned int needs_lazy_stub
: 1;
412 /* MIPS ELF linker hash table. */
414 struct mips_elf_link_hash_table
416 struct elf_link_hash_table root
;
418 /* We no longer use this. */
419 /* String section indices for the dynamic section symbols. */
420 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
423 /* The number of .rtproc entries. */
424 bfd_size_type procedure_count
;
426 /* The size of the .compact_rel section (if SGI_COMPAT). */
427 bfd_size_type compact_rel_size
;
429 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
430 entry is set to the address of __rld_obj_head as in IRIX5. */
431 bfd_boolean use_rld_obj_head
;
433 /* This is the value of the __rld_map or __rld_obj_head symbol. */
436 /* This is set if we see any mips16 stub sections. */
437 bfd_boolean mips16_stubs_seen
;
439 /* True if we can generate copy relocs and PLTs. */
440 bfd_boolean use_plts_and_copy_relocs
;
442 /* True if we're generating code for VxWorks. */
443 bfd_boolean is_vxworks
;
445 /* True if we already reported the small-data section overflow. */
446 bfd_boolean small_data_overflow_reported
;
448 /* Shortcuts to some dynamic sections, or NULL if they are not
459 /* The master GOT information. */
460 struct mips_got_info
*got_info
;
462 /* The size of the PLT header in bytes. */
463 bfd_vma plt_header_size
;
465 /* The size of a PLT entry in bytes. */
466 bfd_vma plt_entry_size
;
468 /* The number of functions that need a lazy-binding stub. */
469 bfd_vma lazy_stub_count
;
471 /* The size of a function stub entry in bytes. */
472 bfd_vma function_stub_size
;
474 /* The number of reserved entries at the beginning of the GOT. */
475 unsigned int reserved_gotno
;
477 /* The section used for mips_elf_la25_stub trampolines.
478 See the comment above that structure for details. */
479 asection
*strampoline
;
481 /* A table of mips_elf_la25_stubs, indexed by (input_section, offset)
485 /* A function FN (NAME, IS, OS) that creates a new input section
486 called NAME and links it to output section OS. If IS is nonnull,
487 the new section should go immediately before it, otherwise it
488 should go at the (current) beginning of OS.
490 The function returns the new section on success, otherwise it
492 asection
*(*add_stub_section
) (const char *, asection
*, asection
*);
495 /* Get the MIPS ELF linker hash table from a link_info structure. */
497 #define mips_elf_hash_table(p) \
498 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
499 == MIPS_ELF_DATA ? ((struct mips_elf_link_hash_table *) ((p)->hash)) : NULL)
501 /* A structure used to communicate with htab_traverse callbacks. */
502 struct mips_htab_traverse_info
504 /* The usual link-wide information. */
505 struct bfd_link_info
*info
;
508 /* Starts off FALSE and is set to TRUE if the link should be aborted. */
512 #define TLS_RELOC_P(r_type) \
513 (r_type == R_MIPS_TLS_DTPMOD32 \
514 || r_type == R_MIPS_TLS_DTPMOD64 \
515 || r_type == R_MIPS_TLS_DTPREL32 \
516 || r_type == R_MIPS_TLS_DTPREL64 \
517 || r_type == R_MIPS_TLS_GD \
518 || r_type == R_MIPS_TLS_LDM \
519 || r_type == R_MIPS_TLS_DTPREL_HI16 \
520 || r_type == R_MIPS_TLS_DTPREL_LO16 \
521 || r_type == R_MIPS_TLS_GOTTPREL \
522 || r_type == R_MIPS_TLS_TPREL32 \
523 || r_type == R_MIPS_TLS_TPREL64 \
524 || r_type == R_MIPS_TLS_TPREL_HI16 \
525 || r_type == R_MIPS_TLS_TPREL_LO16)
527 /* Structure used to pass information to mips_elf_output_extsym. */
532 struct bfd_link_info
*info
;
533 struct ecoff_debug_info
*debug
;
534 const struct ecoff_debug_swap
*swap
;
538 /* The names of the runtime procedure table symbols used on IRIX5. */
540 static const char * const mips_elf_dynsym_rtproc_names
[] =
543 "_procedure_string_table",
544 "_procedure_table_size",
548 /* These structures are used to generate the .compact_rel section on
553 unsigned long id1
; /* Always one? */
554 unsigned long num
; /* Number of compact relocation entries. */
555 unsigned long id2
; /* Always two? */
556 unsigned long offset
; /* The file offset of the first relocation. */
557 unsigned long reserved0
; /* Zero? */
558 unsigned long reserved1
; /* Zero? */
567 bfd_byte reserved0
[4];
568 bfd_byte reserved1
[4];
569 } Elf32_External_compact_rel
;
573 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
574 unsigned int rtype
: 4; /* Relocation types. See below. */
575 unsigned int dist2to
: 8;
576 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
577 unsigned long konst
; /* KONST field. See below. */
578 unsigned long vaddr
; /* VADDR to be relocated. */
583 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
584 unsigned int rtype
: 4; /* Relocation types. See below. */
585 unsigned int dist2to
: 8;
586 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
587 unsigned long konst
; /* KONST field. See below. */
595 } Elf32_External_crinfo
;
601 } Elf32_External_crinfo2
;
603 /* These are the constants used to swap the bitfields in a crinfo. */
605 #define CRINFO_CTYPE (0x1)
606 #define CRINFO_CTYPE_SH (31)
607 #define CRINFO_RTYPE (0xf)
608 #define CRINFO_RTYPE_SH (27)
609 #define CRINFO_DIST2TO (0xff)
610 #define CRINFO_DIST2TO_SH (19)
611 #define CRINFO_RELVADDR (0x7ffff)
612 #define CRINFO_RELVADDR_SH (0)
614 /* A compact relocation info has long (3 words) or short (2 words)
615 formats. A short format doesn't have VADDR field and relvaddr
616 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
617 #define CRF_MIPS_LONG 1
618 #define CRF_MIPS_SHORT 0
620 /* There are 4 types of compact relocation at least. The value KONST
621 has different meaning for each type:
624 CT_MIPS_REL32 Address in data
625 CT_MIPS_WORD Address in word (XXX)
626 CT_MIPS_GPHI_LO GP - vaddr
627 CT_MIPS_JMPAD Address to jump
630 #define CRT_MIPS_REL32 0xa
631 #define CRT_MIPS_WORD 0xb
632 #define CRT_MIPS_GPHI_LO 0xc
633 #define CRT_MIPS_JMPAD 0xd
635 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
636 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
637 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
638 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
640 /* The structure of the runtime procedure descriptor created by the
641 loader for use by the static exception system. */
643 typedef struct runtime_pdr
{
644 bfd_vma adr
; /* Memory address of start of procedure. */
645 long regmask
; /* Save register mask. */
646 long regoffset
; /* Save register offset. */
647 long fregmask
; /* Save floating point register mask. */
648 long fregoffset
; /* Save floating point register offset. */
649 long frameoffset
; /* Frame size. */
650 short framereg
; /* Frame pointer register. */
651 short pcreg
; /* Offset or reg of return pc. */
652 long irpss
; /* Index into the runtime string table. */
654 struct exception_info
*exception_info
;/* Pointer to exception array. */
656 #define cbRPDR sizeof (RPDR)
657 #define rpdNil ((pRPDR) 0)
659 static struct mips_got_entry
*mips_elf_create_local_got_entry
660 (bfd
*, struct bfd_link_info
*, bfd
*, bfd_vma
, unsigned long,
661 struct mips_elf_link_hash_entry
*, int);
662 static bfd_boolean mips_elf_sort_hash_table_f
663 (struct mips_elf_link_hash_entry
*, void *);
664 static bfd_vma mips_elf_high
666 static bfd_boolean mips_elf_create_dynamic_relocation
667 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
668 struct mips_elf_link_hash_entry
*, asection
*, bfd_vma
,
669 bfd_vma
*, asection
*);
670 static hashval_t mips_elf_got_entry_hash
672 static bfd_vma mips_elf_adjust_gp
673 (bfd
*, struct mips_got_info
*, bfd
*);
674 static struct mips_got_info
*mips_elf_got_for_ibfd
675 (struct mips_got_info
*, bfd
*);
677 /* This will be used when we sort the dynamic relocation records. */
678 static bfd
*reldyn_sorting_bfd
;
680 /* True if ABFD is for CPUs with load interlocking that include
681 non-MIPS1 CPUs and R3900. */
682 #define LOAD_INTERLOCKS_P(abfd) \
683 ( ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) != E_MIPS_ARCH_1) \
684 || ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_3900))
686 /* True if ABFD is for CPUs that are faster if JAL is converted to BAL.
687 This should be safe for all architectures. We enable this predicate
688 for RM9000 for now. */
689 #define JAL_TO_BAL_P(abfd) \
690 ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_9000)
692 /* True if ABFD is for CPUs that are faster if JALR is converted to BAL.
693 This should be safe for all architectures. We enable this predicate for
695 #define JALR_TO_BAL_P(abfd) 1
697 /* True if ABFD is for CPUs that are faster if JR is converted to B.
698 This should be safe for all architectures. We enable this predicate for
700 #define JR_TO_B_P(abfd) 1
702 /* True if ABFD is a PIC object. */
703 #define PIC_OBJECT_P(abfd) \
704 ((elf_elfheader (abfd)->e_flags & EF_MIPS_PIC) != 0)
706 /* Nonzero if ABFD is using the N32 ABI. */
707 #define ABI_N32_P(abfd) \
708 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
710 /* Nonzero if ABFD is using the N64 ABI. */
711 #define ABI_64_P(abfd) \
712 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
714 /* Nonzero if ABFD is using NewABI conventions. */
715 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
717 /* The IRIX compatibility level we are striving for. */
718 #define IRIX_COMPAT(abfd) \
719 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
721 /* Whether we are trying to be compatible with IRIX at all. */
722 #define SGI_COMPAT(abfd) \
723 (IRIX_COMPAT (abfd) != ict_none)
725 /* The name of the options section. */
726 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
727 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
729 /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
730 Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
731 #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
732 (strcmp (NAME, ".MIPS.options") == 0 || strcmp (NAME, ".options") == 0)
734 /* Whether the section is readonly. */
735 #define MIPS_ELF_READONLY_SECTION(sec) \
736 ((sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) \
737 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
739 /* The name of the stub section. */
740 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
742 /* The size of an external REL relocation. */
743 #define MIPS_ELF_REL_SIZE(abfd) \
744 (get_elf_backend_data (abfd)->s->sizeof_rel)
746 /* The size of an external RELA relocation. */
747 #define MIPS_ELF_RELA_SIZE(abfd) \
748 (get_elf_backend_data (abfd)->s->sizeof_rela)
750 /* The size of an external dynamic table entry. */
751 #define MIPS_ELF_DYN_SIZE(abfd) \
752 (get_elf_backend_data (abfd)->s->sizeof_dyn)
754 /* The size of a GOT entry. */
755 #define MIPS_ELF_GOT_SIZE(abfd) \
756 (get_elf_backend_data (abfd)->s->arch_size / 8)
758 /* The size of a symbol-table entry. */
759 #define MIPS_ELF_SYM_SIZE(abfd) \
760 (get_elf_backend_data (abfd)->s->sizeof_sym)
762 /* The default alignment for sections, as a power of two. */
763 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
764 (get_elf_backend_data (abfd)->s->log_file_align)
766 /* Get word-sized data. */
767 #define MIPS_ELF_GET_WORD(abfd, ptr) \
768 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
770 /* Put out word-sized data. */
771 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
773 ? bfd_put_64 (abfd, val, ptr) \
774 : bfd_put_32 (abfd, val, ptr))
776 /* The opcode for word-sized loads (LW or LD). */
777 #define MIPS_ELF_LOAD_WORD(abfd) \
778 (ABI_64_P (abfd) ? 0xdc000000 : 0x8c000000)
780 /* Add a dynamic symbol table-entry. */
781 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
782 _bfd_elf_add_dynamic_entry (info, tag, val)
784 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
785 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
787 /* The name of the dynamic relocation section. */
788 #define MIPS_ELF_REL_DYN_NAME(INFO) \
789 (mips_elf_hash_table (INFO)->is_vxworks ? ".rela.dyn" : ".rel.dyn")
791 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
792 from smaller values. Start with zero, widen, *then* decrement. */
793 #define MINUS_ONE (((bfd_vma)0) - 1)
794 #define MINUS_TWO (((bfd_vma)0) - 2)
796 /* The value to write into got[1] for SVR4 targets, to identify it is
797 a GNU object. The dynamic linker can then use got[1] to store the
799 #define MIPS_ELF_GNU_GOT1_MASK(abfd) \
800 ((bfd_vma) 1 << (ABI_64_P (abfd) ? 63 : 31))
802 /* The offset of $gp from the beginning of the .got section. */
803 #define ELF_MIPS_GP_OFFSET(INFO) \
804 (mips_elf_hash_table (INFO)->is_vxworks ? 0x0 : 0x7ff0)
806 /* The maximum size of the GOT for it to be addressable using 16-bit
808 #define MIPS_ELF_GOT_MAX_SIZE(INFO) (ELF_MIPS_GP_OFFSET (INFO) + 0x7fff)
810 /* Instructions which appear in a stub. */
811 #define STUB_LW(abfd) \
813 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
814 : 0x8f998010)) /* lw t9,0x8010(gp) */
815 #define STUB_MOVE(abfd) \
817 ? 0x03e0782d /* daddu t7,ra */ \
818 : 0x03e07821)) /* addu t7,ra */
819 #define STUB_LUI(VAL) (0x3c180000 + (VAL)) /* lui t8,VAL */
820 #define STUB_JALR 0x0320f809 /* jalr t9,ra */
821 #define STUB_ORI(VAL) (0x37180000 + (VAL)) /* ori t8,t8,VAL */
822 #define STUB_LI16U(VAL) (0x34180000 + (VAL)) /* ori t8,zero,VAL unsigned */
823 #define STUB_LI16S(abfd, VAL) \
825 ? (0x64180000 + (VAL)) /* daddiu t8,zero,VAL sign extended */ \
826 : (0x24180000 + (VAL)))) /* addiu t8,zero,VAL sign extended */
828 #define MIPS_FUNCTION_STUB_NORMAL_SIZE 16
829 #define MIPS_FUNCTION_STUB_BIG_SIZE 20
831 /* The name of the dynamic interpreter. This is put in the .interp
834 #define ELF_DYNAMIC_INTERPRETER(abfd) \
835 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
836 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
837 : "/usr/lib/libc.so.1")
840 #define MNAME(bfd,pre,pos) \
841 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
842 #define ELF_R_SYM(bfd, i) \
843 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
844 #define ELF_R_TYPE(bfd, i) \
845 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
846 #define ELF_R_INFO(bfd, s, t) \
847 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
849 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
850 #define ELF_R_SYM(bfd, i) \
852 #define ELF_R_TYPE(bfd, i) \
854 #define ELF_R_INFO(bfd, s, t) \
855 (ELF32_R_INFO (s, t))
858 /* The mips16 compiler uses a couple of special sections to handle
859 floating point arguments.
861 Section names that look like .mips16.fn.FNNAME contain stubs that
862 copy floating point arguments from the fp regs to the gp regs and
863 then jump to FNNAME. If any 32 bit function calls FNNAME, the
864 call should be redirected to the stub instead. If no 32 bit
865 function calls FNNAME, the stub should be discarded. We need to
866 consider any reference to the function, not just a call, because
867 if the address of the function is taken we will need the stub,
868 since the address might be passed to a 32 bit function.
870 Section names that look like .mips16.call.FNNAME contain stubs
871 that copy floating point arguments from the gp regs to the fp
872 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
873 then any 16 bit function that calls FNNAME should be redirected
874 to the stub instead. If FNNAME is not a 32 bit function, the
875 stub should be discarded.
877 .mips16.call.fp.FNNAME sections are similar, but contain stubs
878 which call FNNAME and then copy the return value from the fp regs
879 to the gp regs. These stubs store the return value in $18 while
880 calling FNNAME; any function which might call one of these stubs
881 must arrange to save $18 around the call. (This case is not
882 needed for 32 bit functions that call 16 bit functions, because
883 16 bit functions always return floating point values in both
886 Note that in all cases FNNAME might be defined statically.
887 Therefore, FNNAME is not used literally. Instead, the relocation
888 information will indicate which symbol the section is for.
890 We record any stubs that we find in the symbol table. */
892 #define FN_STUB ".mips16.fn."
893 #define CALL_STUB ".mips16.call."
894 #define CALL_FP_STUB ".mips16.call.fp."
896 #define FN_STUB_P(name) CONST_STRNEQ (name, FN_STUB)
897 #define CALL_STUB_P(name) CONST_STRNEQ (name, CALL_STUB)
898 #define CALL_FP_STUB_P(name) CONST_STRNEQ (name, CALL_FP_STUB)
900 /* The format of the first PLT entry in an O32 executable. */
901 static const bfd_vma mips_o32_exec_plt0_entry
[] =
903 0x3c1c0000, /* lui $28, %hi(&GOTPLT[0]) */
904 0x8f990000, /* lw $25, %lo(&GOTPLT[0])($28) */
905 0x279c0000, /* addiu $28, $28, %lo(&GOTPLT[0]) */
906 0x031cc023, /* subu $24, $24, $28 */
907 0x03e07821, /* move $15, $31 */
908 0x0018c082, /* srl $24, $24, 2 */
909 0x0320f809, /* jalr $25 */
910 0x2718fffe /* subu $24, $24, 2 */
913 /* The format of the first PLT entry in an N32 executable. Different
914 because gp ($28) is not available; we use t2 ($14) instead. */
915 static const bfd_vma mips_n32_exec_plt0_entry
[] =
917 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
918 0x8dd90000, /* lw $25, %lo(&GOTPLT[0])($14) */
919 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
920 0x030ec023, /* subu $24, $24, $14 */
921 0x03e07821, /* move $15, $31 */
922 0x0018c082, /* srl $24, $24, 2 */
923 0x0320f809, /* jalr $25 */
924 0x2718fffe /* subu $24, $24, 2 */
927 /* The format of the first PLT entry in an N64 executable. Different
928 from N32 because of the increased size of GOT entries. */
929 static const bfd_vma mips_n64_exec_plt0_entry
[] =
931 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
932 0xddd90000, /* ld $25, %lo(&GOTPLT[0])($14) */
933 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
934 0x030ec023, /* subu $24, $24, $14 */
935 0x03e07821, /* move $15, $31 */
936 0x0018c0c2, /* srl $24, $24, 3 */
937 0x0320f809, /* jalr $25 */
938 0x2718fffe /* subu $24, $24, 2 */
941 /* The format of subsequent PLT entries. */
942 static const bfd_vma mips_exec_plt_entry
[] =
944 0x3c0f0000, /* lui $15, %hi(.got.plt entry) */
945 0x01f90000, /* l[wd] $25, %lo(.got.plt entry)($15) */
946 0x25f80000, /* addiu $24, $15, %lo(.got.plt entry) */
947 0x03200008 /* jr $25 */
950 /* The format of the first PLT entry in a VxWorks executable. */
951 static const bfd_vma mips_vxworks_exec_plt0_entry
[] =
953 0x3c190000, /* lui t9, %hi(_GLOBAL_OFFSET_TABLE_) */
954 0x27390000, /* addiu t9, t9, %lo(_GLOBAL_OFFSET_TABLE_) */
955 0x8f390008, /* lw t9, 8(t9) */
956 0x00000000, /* nop */
957 0x03200008, /* jr t9 */
961 /* The format of subsequent PLT entries. */
962 static const bfd_vma mips_vxworks_exec_plt_entry
[] =
964 0x10000000, /* b .PLT_resolver */
965 0x24180000, /* li t8, <pltindex> */
966 0x3c190000, /* lui t9, %hi(<.got.plt slot>) */
967 0x27390000, /* addiu t9, t9, %lo(<.got.plt slot>) */
968 0x8f390000, /* lw t9, 0(t9) */
969 0x00000000, /* nop */
970 0x03200008, /* jr t9 */
974 /* The format of the first PLT entry in a VxWorks shared object. */
975 static const bfd_vma mips_vxworks_shared_plt0_entry
[] =
977 0x8f990008, /* lw t9, 8(gp) */
978 0x00000000, /* nop */
979 0x03200008, /* jr t9 */
980 0x00000000, /* nop */
981 0x00000000, /* nop */
985 /* The format of subsequent PLT entries. */
986 static const bfd_vma mips_vxworks_shared_plt_entry
[] =
988 0x10000000, /* b .PLT_resolver */
989 0x24180000 /* li t8, <pltindex> */
992 /* Look up an entry in a MIPS ELF linker hash table. */
994 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
995 ((struct mips_elf_link_hash_entry *) \
996 elf_link_hash_lookup (&(table)->root, (string), (create), \
999 /* Traverse a MIPS ELF linker hash table. */
1001 #define mips_elf_link_hash_traverse(table, func, info) \
1002 (elf_link_hash_traverse \
1004 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1007 /* Find the base offsets for thread-local storage in this object,
1008 for GD/LD and IE/LE respectively. */
1010 #define TP_OFFSET 0x7000
1011 #define DTP_OFFSET 0x8000
1014 dtprel_base (struct bfd_link_info
*info
)
1016 /* If tls_sec is NULL, we should have signalled an error already. */
1017 if (elf_hash_table (info
)->tls_sec
== NULL
)
1019 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
1023 tprel_base (struct bfd_link_info
*info
)
1025 /* If tls_sec is NULL, we should have signalled an error already. */
1026 if (elf_hash_table (info
)->tls_sec
== NULL
)
1028 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
1031 /* Create an entry in a MIPS ELF linker hash table. */
1033 static struct bfd_hash_entry
*
1034 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1035 struct bfd_hash_table
*table
, const char *string
)
1037 struct mips_elf_link_hash_entry
*ret
=
1038 (struct mips_elf_link_hash_entry
*) entry
;
1040 /* Allocate the structure if it has not already been allocated by a
1043 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
1045 return (struct bfd_hash_entry
*) ret
;
1047 /* Call the allocation method of the superclass. */
1048 ret
= ((struct mips_elf_link_hash_entry
*)
1049 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1053 /* Set local fields. */
1054 memset (&ret
->esym
, 0, sizeof (EXTR
));
1055 /* We use -2 as a marker to indicate that the information has
1056 not been set. -1 means there is no associated ifd. */
1059 ret
->possibly_dynamic_relocs
= 0;
1060 ret
->fn_stub
= NULL
;
1061 ret
->call_stub
= NULL
;
1062 ret
->call_fp_stub
= NULL
;
1063 ret
->tls_type
= GOT_NORMAL
;
1064 ret
->global_got_area
= GGA_NONE
;
1065 ret
->got_only_for_calls
= TRUE
;
1066 ret
->readonly_reloc
= FALSE
;
1067 ret
->has_static_relocs
= FALSE
;
1068 ret
->no_fn_stub
= FALSE
;
1069 ret
->need_fn_stub
= FALSE
;
1070 ret
->has_nonpic_branches
= FALSE
;
1071 ret
->needs_lazy_stub
= FALSE
;
1074 return (struct bfd_hash_entry
*) ret
;
1078 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
1080 if (!sec
->used_by_bfd
)
1082 struct _mips_elf_section_data
*sdata
;
1083 bfd_size_type amt
= sizeof (*sdata
);
1085 sdata
= bfd_zalloc (abfd
, amt
);
1088 sec
->used_by_bfd
= sdata
;
1091 return _bfd_elf_new_section_hook (abfd
, sec
);
1094 /* Read ECOFF debugging information from a .mdebug section into a
1095 ecoff_debug_info structure. */
1098 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
1099 struct ecoff_debug_info
*debug
)
1102 const struct ecoff_debug_swap
*swap
;
1105 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1106 memset (debug
, 0, sizeof (*debug
));
1108 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
1109 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1112 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
1113 swap
->external_hdr_size
))
1116 symhdr
= &debug
->symbolic_header
;
1117 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1119 /* The symbolic header contains absolute file offsets and sizes to
1121 #define READ(ptr, offset, count, size, type) \
1122 if (symhdr->count == 0) \
1123 debug->ptr = NULL; \
1126 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
1127 debug->ptr = bfd_malloc (amt); \
1128 if (debug->ptr == NULL) \
1129 goto error_return; \
1130 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0 \
1131 || bfd_bread (debug->ptr, amt, abfd) != amt) \
1132 goto error_return; \
1135 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1136 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
1137 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
1138 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
1139 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
1140 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1142 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1143 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
1144 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
1145 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
1146 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
1154 if (ext_hdr
!= NULL
)
1156 if (debug
->line
!= NULL
)
1158 if (debug
->external_dnr
!= NULL
)
1159 free (debug
->external_dnr
);
1160 if (debug
->external_pdr
!= NULL
)
1161 free (debug
->external_pdr
);
1162 if (debug
->external_sym
!= NULL
)
1163 free (debug
->external_sym
);
1164 if (debug
->external_opt
!= NULL
)
1165 free (debug
->external_opt
);
1166 if (debug
->external_aux
!= NULL
)
1167 free (debug
->external_aux
);
1168 if (debug
->ss
!= NULL
)
1170 if (debug
->ssext
!= NULL
)
1171 free (debug
->ssext
);
1172 if (debug
->external_fdr
!= NULL
)
1173 free (debug
->external_fdr
);
1174 if (debug
->external_rfd
!= NULL
)
1175 free (debug
->external_rfd
);
1176 if (debug
->external_ext
!= NULL
)
1177 free (debug
->external_ext
);
1181 /* Swap RPDR (runtime procedure table entry) for output. */
1184 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
1186 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
1187 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
1188 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
1189 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
1190 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
1191 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
1193 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
1194 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
1196 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
1199 /* Create a runtime procedure table from the .mdebug section. */
1202 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
1203 struct bfd_link_info
*info
, asection
*s
,
1204 struct ecoff_debug_info
*debug
)
1206 const struct ecoff_debug_swap
*swap
;
1207 HDRR
*hdr
= &debug
->symbolic_header
;
1209 struct rpdr_ext
*erp
;
1211 struct pdr_ext
*epdr
;
1212 struct sym_ext
*esym
;
1216 bfd_size_type count
;
1217 unsigned long sindex
;
1221 const char *no_name_func
= _("static procedure (no name)");
1229 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1231 sindex
= strlen (no_name_func
) + 1;
1232 count
= hdr
->ipdMax
;
1235 size
= swap
->external_pdr_size
;
1237 epdr
= bfd_malloc (size
* count
);
1241 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
1244 size
= sizeof (RPDR
);
1245 rp
= rpdr
= bfd_malloc (size
* count
);
1249 size
= sizeof (char *);
1250 sv
= bfd_malloc (size
* count
);
1254 count
= hdr
->isymMax
;
1255 size
= swap
->external_sym_size
;
1256 esym
= bfd_malloc (size
* count
);
1260 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
1263 count
= hdr
->issMax
;
1264 ss
= bfd_malloc (count
);
1267 if (! _bfd_ecoff_get_accumulated_ss (handle
, (bfd_byte
*) ss
))
1270 count
= hdr
->ipdMax
;
1271 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
1273 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
1274 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
1275 rp
->adr
= sym
.value
;
1276 rp
->regmask
= pdr
.regmask
;
1277 rp
->regoffset
= pdr
.regoffset
;
1278 rp
->fregmask
= pdr
.fregmask
;
1279 rp
->fregoffset
= pdr
.fregoffset
;
1280 rp
->frameoffset
= pdr
.frameoffset
;
1281 rp
->framereg
= pdr
.framereg
;
1282 rp
->pcreg
= pdr
.pcreg
;
1284 sv
[i
] = ss
+ sym
.iss
;
1285 sindex
+= strlen (sv
[i
]) + 1;
1289 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
1290 size
= BFD_ALIGN (size
, 16);
1291 rtproc
= bfd_alloc (abfd
, size
);
1294 mips_elf_hash_table (info
)->procedure_count
= 0;
1298 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
1301 memset (erp
, 0, sizeof (struct rpdr_ext
));
1303 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
1304 strcpy (str
, no_name_func
);
1305 str
+= strlen (no_name_func
) + 1;
1306 for (i
= 0; i
< count
; i
++)
1308 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
1309 strcpy (str
, sv
[i
]);
1310 str
+= strlen (sv
[i
]) + 1;
1312 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
1314 /* Set the size and contents of .rtproc section. */
1316 s
->contents
= rtproc
;
1318 /* Skip this section later on (I don't think this currently
1319 matters, but someday it might). */
1320 s
->map_head
.link_order
= NULL
;
1349 /* We're going to create a stub for H. Create a symbol for the stub's
1350 value and size, to help make the disassembly easier to read. */
1353 mips_elf_create_stub_symbol (struct bfd_link_info
*info
,
1354 struct mips_elf_link_hash_entry
*h
,
1355 const char *prefix
, asection
*s
, bfd_vma value
,
1358 struct bfd_link_hash_entry
*bh
;
1359 struct elf_link_hash_entry
*elfh
;
1362 /* Create a new symbol. */
1363 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1365 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1366 BSF_LOCAL
, s
, value
, NULL
,
1370 /* Make it a local function. */
1371 elfh
= (struct elf_link_hash_entry
*) bh
;
1372 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
1374 elfh
->forced_local
= 1;
1378 /* We're about to redefine H. Create a symbol to represent H's
1379 current value and size, to help make the disassembly easier
1383 mips_elf_create_shadow_symbol (struct bfd_link_info
*info
,
1384 struct mips_elf_link_hash_entry
*h
,
1387 struct bfd_link_hash_entry
*bh
;
1388 struct elf_link_hash_entry
*elfh
;
1393 /* Read the symbol's value. */
1394 BFD_ASSERT (h
->root
.root
.type
== bfd_link_hash_defined
1395 || h
->root
.root
.type
== bfd_link_hash_defweak
);
1396 s
= h
->root
.root
.u
.def
.section
;
1397 value
= h
->root
.root
.u
.def
.value
;
1399 /* Create a new symbol. */
1400 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1402 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1403 BSF_LOCAL
, s
, value
, NULL
,
1407 /* Make it local and copy the other attributes from H. */
1408 elfh
= (struct elf_link_hash_entry
*) bh
;
1409 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (h
->root
.type
));
1410 elfh
->other
= h
->root
.other
;
1411 elfh
->size
= h
->root
.size
;
1412 elfh
->forced_local
= 1;
1416 /* Return TRUE if relocations in SECTION can refer directly to a MIPS16
1417 function rather than to a hard-float stub. */
1420 section_allows_mips16_refs_p (asection
*section
)
1424 name
= bfd_get_section_name (section
->owner
, section
);
1425 return (FN_STUB_P (name
)
1426 || CALL_STUB_P (name
)
1427 || CALL_FP_STUB_P (name
)
1428 || strcmp (name
, ".pdr") == 0);
1431 /* [RELOCS, RELEND) are the relocations against SEC, which is a MIPS16
1432 stub section of some kind. Return the R_SYMNDX of the target
1433 function, or 0 if we can't decide which function that is. */
1435 static unsigned long
1436 mips16_stub_symndx (asection
*sec ATTRIBUTE_UNUSED
,
1437 const Elf_Internal_Rela
*relocs
,
1438 const Elf_Internal_Rela
*relend
)
1440 const Elf_Internal_Rela
*rel
;
1442 /* Trust the first R_MIPS_NONE relocation, if any. */
1443 for (rel
= relocs
; rel
< relend
; rel
++)
1444 if (ELF_R_TYPE (sec
->owner
, rel
->r_info
) == R_MIPS_NONE
)
1445 return ELF_R_SYM (sec
->owner
, rel
->r_info
);
1447 /* Otherwise trust the first relocation, whatever its kind. This is
1448 the traditional behavior. */
1449 if (relocs
< relend
)
1450 return ELF_R_SYM (sec
->owner
, relocs
->r_info
);
1455 /* Check the mips16 stubs for a particular symbol, and see if we can
1459 mips_elf_check_mips16_stubs (struct bfd_link_info
*info
,
1460 struct mips_elf_link_hash_entry
*h
)
1462 /* Dynamic symbols must use the standard call interface, in case other
1463 objects try to call them. */
1464 if (h
->fn_stub
!= NULL
1465 && h
->root
.dynindx
!= -1)
1467 mips_elf_create_shadow_symbol (info
, h
, ".mips16.");
1468 h
->need_fn_stub
= TRUE
;
1471 if (h
->fn_stub
!= NULL
1472 && ! h
->need_fn_stub
)
1474 /* We don't need the fn_stub; the only references to this symbol
1475 are 16 bit calls. Clobber the size to 0 to prevent it from
1476 being included in the link. */
1477 h
->fn_stub
->size
= 0;
1478 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1479 h
->fn_stub
->reloc_count
= 0;
1480 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1483 if (h
->call_stub
!= NULL
1484 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1486 /* We don't need the call_stub; this is a 16 bit function, so
1487 calls from other 16 bit functions are OK. Clobber the size
1488 to 0 to prevent it from being included in the link. */
1489 h
->call_stub
->size
= 0;
1490 h
->call_stub
->flags
&= ~SEC_RELOC
;
1491 h
->call_stub
->reloc_count
= 0;
1492 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1495 if (h
->call_fp_stub
!= NULL
1496 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1498 /* We don't need the call_stub; this is a 16 bit function, so
1499 calls from other 16 bit functions are OK. Clobber the size
1500 to 0 to prevent it from being included in the link. */
1501 h
->call_fp_stub
->size
= 0;
1502 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1503 h
->call_fp_stub
->reloc_count
= 0;
1504 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1508 /* Hashtable callbacks for mips_elf_la25_stubs. */
1511 mips_elf_la25_stub_hash (const void *entry_
)
1513 const struct mips_elf_la25_stub
*entry
;
1515 entry
= (struct mips_elf_la25_stub
*) entry_
;
1516 return entry
->h
->root
.root
.u
.def
.section
->id
1517 + entry
->h
->root
.root
.u
.def
.value
;
1521 mips_elf_la25_stub_eq (const void *entry1_
, const void *entry2_
)
1523 const struct mips_elf_la25_stub
*entry1
, *entry2
;
1525 entry1
= (struct mips_elf_la25_stub
*) entry1_
;
1526 entry2
= (struct mips_elf_la25_stub
*) entry2_
;
1527 return ((entry1
->h
->root
.root
.u
.def
.section
1528 == entry2
->h
->root
.root
.u
.def
.section
)
1529 && (entry1
->h
->root
.root
.u
.def
.value
1530 == entry2
->h
->root
.root
.u
.def
.value
));
1533 /* Called by the linker to set up the la25 stub-creation code. FN is
1534 the linker's implementation of add_stub_function. Return true on
1538 _bfd_mips_elf_init_stubs (struct bfd_link_info
*info
,
1539 asection
*(*fn
) (const char *, asection
*,
1542 struct mips_elf_link_hash_table
*htab
;
1544 htab
= mips_elf_hash_table (info
);
1548 htab
->add_stub_section
= fn
;
1549 htab
->la25_stubs
= htab_try_create (1, mips_elf_la25_stub_hash
,
1550 mips_elf_la25_stub_eq
, NULL
);
1551 if (htab
->la25_stubs
== NULL
)
1557 /* Return true if H is a locally-defined PIC function, in the sense
1558 that it might need $25 to be valid on entry. Note that MIPS16
1559 functions never need $25 to be valid on entry; they set up $gp
1560 using PC-relative instructions instead. */
1563 mips_elf_local_pic_function_p (struct mips_elf_link_hash_entry
*h
)
1565 return ((h
->root
.root
.type
== bfd_link_hash_defined
1566 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1567 && h
->root
.def_regular
1568 && !bfd_is_abs_section (h
->root
.root
.u
.def
.section
)
1569 && !ELF_ST_IS_MIPS16 (h
->root
.other
)
1570 && (PIC_OBJECT_P (h
->root
.root
.u
.def
.section
->owner
)
1571 || ELF_ST_IS_MIPS_PIC (h
->root
.other
)));
1574 /* STUB describes an la25 stub that we have decided to implement
1575 by inserting an LUI/ADDIU pair before the target function.
1576 Create the section and redirect the function symbol to it. */
1579 mips_elf_add_la25_intro (struct mips_elf_la25_stub
*stub
,
1580 struct bfd_link_info
*info
)
1582 struct mips_elf_link_hash_table
*htab
;
1584 asection
*s
, *input_section
;
1587 htab
= mips_elf_hash_table (info
);
1591 /* Create a unique name for the new section. */
1592 name
= bfd_malloc (11 + sizeof (".text.stub."));
1595 sprintf (name
, ".text.stub.%d", (int) htab_elements (htab
->la25_stubs
));
1597 /* Create the section. */
1598 input_section
= stub
->h
->root
.root
.u
.def
.section
;
1599 s
= htab
->add_stub_section (name
, input_section
,
1600 input_section
->output_section
);
1604 /* Make sure that any padding goes before the stub. */
1605 align
= input_section
->alignment_power
;
1606 if (!bfd_set_section_alignment (s
->owner
, s
, align
))
1609 s
->size
= (1 << align
) - 8;
1611 /* Create a symbol for the stub. */
1612 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 8);
1613 stub
->stub_section
= s
;
1614 stub
->offset
= s
->size
;
1616 /* Allocate room for it. */
1621 /* STUB describes an la25 stub that we have decided to implement
1622 with a separate trampoline. Allocate room for it and redirect
1623 the function symbol to it. */
1626 mips_elf_add_la25_trampoline (struct mips_elf_la25_stub
*stub
,
1627 struct bfd_link_info
*info
)
1629 struct mips_elf_link_hash_table
*htab
;
1632 htab
= mips_elf_hash_table (info
);
1636 /* Create a trampoline section, if we haven't already. */
1637 s
= htab
->strampoline
;
1640 asection
*input_section
= stub
->h
->root
.root
.u
.def
.section
;
1641 s
= htab
->add_stub_section (".text", NULL
,
1642 input_section
->output_section
);
1643 if (s
== NULL
|| !bfd_set_section_alignment (s
->owner
, s
, 4))
1645 htab
->strampoline
= s
;
1648 /* Create a symbol for the stub. */
1649 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 16);
1650 stub
->stub_section
= s
;
1651 stub
->offset
= s
->size
;
1653 /* Allocate room for it. */
1658 /* H describes a symbol that needs an la25 stub. Make sure that an
1659 appropriate stub exists and point H at it. */
1662 mips_elf_add_la25_stub (struct bfd_link_info
*info
,
1663 struct mips_elf_link_hash_entry
*h
)
1665 struct mips_elf_link_hash_table
*htab
;
1666 struct mips_elf_la25_stub search
, *stub
;
1667 bfd_boolean use_trampoline_p
;
1672 /* Prefer to use LUI/ADDIU stubs if the function is at the beginning
1673 of the section and if we would need no more than 2 nops. */
1674 s
= h
->root
.root
.u
.def
.section
;
1675 value
= h
->root
.root
.u
.def
.value
;
1676 use_trampoline_p
= (value
!= 0 || s
->alignment_power
> 4);
1678 /* Describe the stub we want. */
1679 search
.stub_section
= NULL
;
1683 /* See if we've already created an equivalent stub. */
1684 htab
= mips_elf_hash_table (info
);
1688 slot
= htab_find_slot (htab
->la25_stubs
, &search
, INSERT
);
1692 stub
= (struct mips_elf_la25_stub
*) *slot
;
1695 /* We can reuse the existing stub. */
1696 h
->la25_stub
= stub
;
1700 /* Create a permanent copy of ENTRY and add it to the hash table. */
1701 stub
= bfd_malloc (sizeof (search
));
1707 h
->la25_stub
= stub
;
1708 return (use_trampoline_p
1709 ? mips_elf_add_la25_trampoline (stub
, info
)
1710 : mips_elf_add_la25_intro (stub
, info
));
1713 /* A mips_elf_link_hash_traverse callback that is called before sizing
1714 sections. DATA points to a mips_htab_traverse_info structure. */
1717 mips_elf_check_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
1719 struct mips_htab_traverse_info
*hti
;
1721 hti
= (struct mips_htab_traverse_info
*) data
;
1722 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1723 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1725 if (!hti
->info
->relocatable
)
1726 mips_elf_check_mips16_stubs (hti
->info
, h
);
1728 if (mips_elf_local_pic_function_p (h
))
1730 /* PR 12845: If H is in a section that has been garbage
1731 collected it will have its output section set to *ABS*. */
1732 if (bfd_is_abs_section (h
->root
.root
.u
.def
.section
->output_section
))
1735 /* H is a function that might need $25 to be valid on entry.
1736 If we're creating a non-PIC relocatable object, mark H as
1737 being PIC. If we're creating a non-relocatable object with
1738 non-PIC branches and jumps to H, make sure that H has an la25
1740 if (hti
->info
->relocatable
)
1742 if (!PIC_OBJECT_P (hti
->output_bfd
))
1743 h
->root
.other
= ELF_ST_SET_MIPS_PIC (h
->root
.other
);
1745 else if (h
->has_nonpic_branches
&& !mips_elf_add_la25_stub (hti
->info
, h
))
1754 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
1755 Most mips16 instructions are 16 bits, but these instructions
1758 The format of these instructions is:
1760 +--------------+--------------------------------+
1761 | JALX | X| Imm 20:16 | Imm 25:21 |
1762 +--------------+--------------------------------+
1764 +-----------------------------------------------+
1766 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
1767 Note that the immediate value in the first word is swapped.
1769 When producing a relocatable object file, R_MIPS16_26 is
1770 handled mostly like R_MIPS_26. In particular, the addend is
1771 stored as a straight 26-bit value in a 32-bit instruction.
1772 (gas makes life simpler for itself by never adjusting a
1773 R_MIPS16_26 reloc to be against a section, so the addend is
1774 always zero). However, the 32 bit instruction is stored as 2
1775 16-bit values, rather than a single 32-bit value. In a
1776 big-endian file, the result is the same; in a little-endian
1777 file, the two 16-bit halves of the 32 bit value are swapped.
1778 This is so that a disassembler can recognize the jal
1781 When doing a final link, R_MIPS16_26 is treated as a 32 bit
1782 instruction stored as two 16-bit values. The addend A is the
1783 contents of the targ26 field. The calculation is the same as
1784 R_MIPS_26. When storing the calculated value, reorder the
1785 immediate value as shown above, and don't forget to store the
1786 value as two 16-bit values.
1788 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
1792 +--------+----------------------+
1796 +--------+----------------------+
1799 +----------+------+-------------+
1803 +----------+--------------------+
1804 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
1805 ((sub1 << 16) | sub2)).
1807 When producing a relocatable object file, the calculation is
1808 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1809 When producing a fully linked file, the calculation is
1810 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1811 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
1813 The table below lists the other MIPS16 instruction relocations.
1814 Each one is calculated in the same way as the non-MIPS16 relocation
1815 given on the right, but using the extended MIPS16 layout of 16-bit
1818 R_MIPS16_GPREL R_MIPS_GPREL16
1819 R_MIPS16_GOT16 R_MIPS_GOT16
1820 R_MIPS16_CALL16 R_MIPS_CALL16
1821 R_MIPS16_HI16 R_MIPS_HI16
1822 R_MIPS16_LO16 R_MIPS_LO16
1824 A typical instruction will have a format like this:
1826 +--------------+--------------------------------+
1827 | EXTEND | Imm 10:5 | Imm 15:11 |
1828 +--------------+--------------------------------+
1829 | Major | rx | ry | Imm 4:0 |
1830 +--------------+--------------------------------+
1832 EXTEND is the five bit value 11110. Major is the instruction
1835 All we need to do here is shuffle the bits appropriately.
1836 As above, the two 16-bit halves must be swapped on a
1837 little-endian system. */
1839 static inline bfd_boolean
1840 mips16_reloc_p (int r_type
)
1845 case R_MIPS16_GPREL
:
1846 case R_MIPS16_GOT16
:
1847 case R_MIPS16_CALL16
:
1857 static inline bfd_boolean
1858 got16_reloc_p (int r_type
)
1860 return r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS16_GOT16
;
1863 static inline bfd_boolean
1864 call16_reloc_p (int r_type
)
1866 return r_type
== R_MIPS_CALL16
|| r_type
== R_MIPS16_CALL16
;
1869 static inline bfd_boolean
1870 hi16_reloc_p (int r_type
)
1872 return r_type
== R_MIPS_HI16
|| r_type
== R_MIPS16_HI16
;
1875 static inline bfd_boolean
1876 lo16_reloc_p (int r_type
)
1878 return r_type
== R_MIPS_LO16
|| r_type
== R_MIPS16_LO16
;
1881 static inline bfd_boolean
1882 mips16_call_reloc_p (int r_type
)
1884 return r_type
== R_MIPS16_26
|| r_type
== R_MIPS16_CALL16
;
1887 static inline bfd_boolean
1888 jal_reloc_p (int r_type
)
1890 return r_type
== R_MIPS_26
|| r_type
== R_MIPS16_26
;
1894 _bfd_mips16_elf_reloc_unshuffle (bfd
*abfd
, int r_type
,
1895 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1897 bfd_vma extend
, insn
, val
;
1899 if (!mips16_reloc_p (r_type
))
1902 /* Pick up the mips16 extend instruction and the real instruction. */
1903 extend
= bfd_get_16 (abfd
, data
);
1904 insn
= bfd_get_16 (abfd
, data
+ 2);
1905 if (r_type
== R_MIPS16_26
)
1908 val
= ((extend
& 0xfc00) << 16) | ((extend
& 0x3e0) << 11)
1909 | ((extend
& 0x1f) << 21) | insn
;
1911 val
= extend
<< 16 | insn
;
1914 val
= ((extend
& 0xf800) << 16) | ((insn
& 0xffe0) << 11)
1915 | ((extend
& 0x1f) << 11) | (extend
& 0x7e0) | (insn
& 0x1f);
1916 bfd_put_32 (abfd
, val
, data
);
1920 _bfd_mips16_elf_reloc_shuffle (bfd
*abfd
, int r_type
,
1921 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1923 bfd_vma extend
, insn
, val
;
1925 if (!mips16_reloc_p (r_type
))
1928 val
= bfd_get_32 (abfd
, data
);
1929 if (r_type
== R_MIPS16_26
)
1933 insn
= val
& 0xffff;
1934 extend
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
1935 | ((val
>> 21) & 0x1f);
1939 insn
= val
& 0xffff;
1945 insn
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
1946 extend
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
1948 bfd_put_16 (abfd
, insn
, data
+ 2);
1949 bfd_put_16 (abfd
, extend
, data
);
1952 bfd_reloc_status_type
1953 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
1954 arelent
*reloc_entry
, asection
*input_section
,
1955 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
1959 bfd_reloc_status_type status
;
1961 if (bfd_is_com_section (symbol
->section
))
1964 relocation
= symbol
->value
;
1966 relocation
+= symbol
->section
->output_section
->vma
;
1967 relocation
+= symbol
->section
->output_offset
;
1969 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1970 return bfd_reloc_outofrange
;
1972 /* Set val to the offset into the section or symbol. */
1973 val
= reloc_entry
->addend
;
1975 _bfd_mips_elf_sign_extend (val
, 16);
1977 /* Adjust val for the final section location and GP value. If we
1978 are producing relocatable output, we don't want to do this for
1979 an external symbol. */
1981 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1982 val
+= relocation
- gp
;
1984 if (reloc_entry
->howto
->partial_inplace
)
1986 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1988 + reloc_entry
->address
);
1989 if (status
!= bfd_reloc_ok
)
1993 reloc_entry
->addend
= val
;
1996 reloc_entry
->address
+= input_section
->output_offset
;
1998 return bfd_reloc_ok
;
2001 /* Used to store a REL high-part relocation such as R_MIPS_HI16 or
2002 R_MIPS_GOT16. REL is the relocation, INPUT_SECTION is the section
2003 that contains the relocation field and DATA points to the start of
2008 struct mips_hi16
*next
;
2010 asection
*input_section
;
2014 /* FIXME: This should not be a static variable. */
2016 static struct mips_hi16
*mips_hi16_list
;
2018 /* A howto special_function for REL *HI16 relocations. We can only
2019 calculate the correct value once we've seen the partnering
2020 *LO16 relocation, so just save the information for later.
2022 The ABI requires that the *LO16 immediately follow the *HI16.
2023 However, as a GNU extension, we permit an arbitrary number of
2024 *HI16s to be associated with a single *LO16. This significantly
2025 simplies the relocation handling in gcc. */
2027 bfd_reloc_status_type
2028 _bfd_mips_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2029 asymbol
*symbol ATTRIBUTE_UNUSED
, void *data
,
2030 asection
*input_section
, bfd
*output_bfd
,
2031 char **error_message ATTRIBUTE_UNUSED
)
2033 struct mips_hi16
*n
;
2035 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2036 return bfd_reloc_outofrange
;
2038 n
= bfd_malloc (sizeof *n
);
2040 return bfd_reloc_outofrange
;
2042 n
->next
= mips_hi16_list
;
2044 n
->input_section
= input_section
;
2045 n
->rel
= *reloc_entry
;
2048 if (output_bfd
!= NULL
)
2049 reloc_entry
->address
+= input_section
->output_offset
;
2051 return bfd_reloc_ok
;
2054 /* A howto special_function for REL R_MIPS*_GOT16 relocations. This is just
2055 like any other 16-bit relocation when applied to global symbols, but is
2056 treated in the same as R_MIPS_HI16 when applied to local symbols. */
2058 bfd_reloc_status_type
2059 _bfd_mips_elf_got16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2060 void *data
, asection
*input_section
,
2061 bfd
*output_bfd
, char **error_message
)
2063 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
2064 || bfd_is_und_section (bfd_get_section (symbol
))
2065 || bfd_is_com_section (bfd_get_section (symbol
)))
2066 /* The relocation is against a global symbol. */
2067 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2068 input_section
, output_bfd
,
2071 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
2072 input_section
, output_bfd
, error_message
);
2075 /* A howto special_function for REL *LO16 relocations. The *LO16 itself
2076 is a straightforward 16 bit inplace relocation, but we must deal with
2077 any partnering high-part relocations as well. */
2079 bfd_reloc_status_type
2080 _bfd_mips_elf_lo16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2081 void *data
, asection
*input_section
,
2082 bfd
*output_bfd
, char **error_message
)
2085 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2087 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2088 return bfd_reloc_outofrange
;
2090 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2092 vallo
= bfd_get_32 (abfd
, location
);
2093 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2096 while (mips_hi16_list
!= NULL
)
2098 bfd_reloc_status_type ret
;
2099 struct mips_hi16
*hi
;
2101 hi
= mips_hi16_list
;
2103 /* R_MIPS*_GOT16 relocations are something of a special case. We
2104 want to install the addend in the same way as for a R_MIPS*_HI16
2105 relocation (with a rightshift of 16). However, since GOT16
2106 relocations can also be used with global symbols, their howto
2107 has a rightshift of 0. */
2108 if (hi
->rel
.howto
->type
== R_MIPS_GOT16
)
2109 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS_HI16
, FALSE
);
2110 else if (hi
->rel
.howto
->type
== R_MIPS16_GOT16
)
2111 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS16_HI16
, FALSE
);
2113 /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
2114 carry or borrow will induce a change of +1 or -1 in the high part. */
2115 hi
->rel
.addend
+= (vallo
+ 0x8000) & 0xffff;
2117 ret
= _bfd_mips_elf_generic_reloc (abfd
, &hi
->rel
, symbol
, hi
->data
,
2118 hi
->input_section
, output_bfd
,
2120 if (ret
!= bfd_reloc_ok
)
2123 mips_hi16_list
= hi
->next
;
2127 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2128 input_section
, output_bfd
,
2132 /* A generic howto special_function. This calculates and installs the
2133 relocation itself, thus avoiding the oft-discussed problems in
2134 bfd_perform_relocation and bfd_install_relocation. */
2136 bfd_reloc_status_type
2137 _bfd_mips_elf_generic_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2138 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
2139 asection
*input_section
, bfd
*output_bfd
,
2140 char **error_message ATTRIBUTE_UNUSED
)
2143 bfd_reloc_status_type status
;
2144 bfd_boolean relocatable
;
2146 relocatable
= (output_bfd
!= NULL
);
2148 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2149 return bfd_reloc_outofrange
;
2151 /* Build up the field adjustment in VAL. */
2153 if (!relocatable
|| (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2155 /* Either we're calculating the final field value or we have a
2156 relocation against a section symbol. Add in the section's
2157 offset or address. */
2158 val
+= symbol
->section
->output_section
->vma
;
2159 val
+= symbol
->section
->output_offset
;
2164 /* We're calculating the final field value. Add in the symbol's value
2165 and, if pc-relative, subtract the address of the field itself. */
2166 val
+= symbol
->value
;
2167 if (reloc_entry
->howto
->pc_relative
)
2169 val
-= input_section
->output_section
->vma
;
2170 val
-= input_section
->output_offset
;
2171 val
-= reloc_entry
->address
;
2175 /* VAL is now the final adjustment. If we're keeping this relocation
2176 in the output file, and if the relocation uses a separate addend,
2177 we just need to add VAL to that addend. Otherwise we need to add
2178 VAL to the relocation field itself. */
2179 if (relocatable
&& !reloc_entry
->howto
->partial_inplace
)
2180 reloc_entry
->addend
+= val
;
2183 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2185 /* Add in the separate addend, if any. */
2186 val
+= reloc_entry
->addend
;
2188 /* Add VAL to the relocation field. */
2189 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2191 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
2193 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2196 if (status
!= bfd_reloc_ok
)
2201 reloc_entry
->address
+= input_section
->output_offset
;
2203 return bfd_reloc_ok
;
2206 /* Swap an entry in a .gptab section. Note that these routines rely
2207 on the equivalence of the two elements of the union. */
2210 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
2213 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
2214 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
2218 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
2219 Elf32_External_gptab
*ex
)
2221 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
2222 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
2226 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
2227 Elf32_External_compact_rel
*ex
)
2229 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
2230 H_PUT_32 (abfd
, in
->num
, ex
->num
);
2231 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
2232 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
2233 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
2234 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
2238 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
2239 Elf32_External_crinfo
*ex
)
2243 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2244 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2245 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2246 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2247 H_PUT_32 (abfd
, l
, ex
->info
);
2248 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
2249 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
2252 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2253 routines swap this structure in and out. They are used outside of
2254 BFD, so they are globally visible. */
2257 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
2260 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2261 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2262 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2263 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2264 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2265 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
2269 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
2270 Elf32_External_RegInfo
*ex
)
2272 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2273 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2274 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2275 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2276 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2277 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2280 /* In the 64 bit ABI, the .MIPS.options section holds register
2281 information in an Elf64_Reginfo structure. These routines swap
2282 them in and out. They are globally visible because they are used
2283 outside of BFD. These routines are here so that gas can call them
2284 without worrying about whether the 64 bit ABI has been included. */
2287 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
2288 Elf64_Internal_RegInfo
*in
)
2290 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2291 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
2292 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2293 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2294 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2295 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2296 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
2300 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
2301 Elf64_External_RegInfo
*ex
)
2303 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2304 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
2305 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2306 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2307 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2308 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2309 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2312 /* Swap in an options header. */
2315 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
2316 Elf_Internal_Options
*in
)
2318 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
2319 in
->size
= H_GET_8 (abfd
, ex
->size
);
2320 in
->section
= H_GET_16 (abfd
, ex
->section
);
2321 in
->info
= H_GET_32 (abfd
, ex
->info
);
2324 /* Swap out an options header. */
2327 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
2328 Elf_External_Options
*ex
)
2330 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
2331 H_PUT_8 (abfd
, in
->size
, ex
->size
);
2332 H_PUT_16 (abfd
, in
->section
, ex
->section
);
2333 H_PUT_32 (abfd
, in
->info
, ex
->info
);
2336 /* This function is called via qsort() to sort the dynamic relocation
2337 entries by increasing r_symndx value. */
2340 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
2342 Elf_Internal_Rela int_reloc1
;
2343 Elf_Internal_Rela int_reloc2
;
2346 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
2347 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
2349 diff
= ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
2353 if (int_reloc1
.r_offset
< int_reloc2
.r_offset
)
2355 if (int_reloc1
.r_offset
> int_reloc2
.r_offset
)
2360 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
2363 sort_dynamic_relocs_64 (const void *arg1 ATTRIBUTE_UNUSED
,
2364 const void *arg2 ATTRIBUTE_UNUSED
)
2367 Elf_Internal_Rela int_reloc1
[3];
2368 Elf_Internal_Rela int_reloc2
[3];
2370 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2371 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
2372 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2373 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
2375 if (ELF64_R_SYM (int_reloc1
[0].r_info
) < ELF64_R_SYM (int_reloc2
[0].r_info
))
2377 if (ELF64_R_SYM (int_reloc1
[0].r_info
) > ELF64_R_SYM (int_reloc2
[0].r_info
))
2380 if (int_reloc1
[0].r_offset
< int_reloc2
[0].r_offset
)
2382 if (int_reloc1
[0].r_offset
> int_reloc2
[0].r_offset
)
2391 /* This routine is used to write out ECOFF debugging external symbol
2392 information. It is called via mips_elf_link_hash_traverse. The
2393 ECOFF external symbol information must match the ELF external
2394 symbol information. Unfortunately, at this point we don't know
2395 whether a symbol is required by reloc information, so the two
2396 tables may wind up being different. We must sort out the external
2397 symbol information before we can set the final size of the .mdebug
2398 section, and we must set the size of the .mdebug section before we
2399 can relocate any sections, and we can't know which symbols are
2400 required by relocation until we relocate the sections.
2401 Fortunately, it is relatively unlikely that any symbol will be
2402 stripped but required by a reloc. In particular, it can not happen
2403 when generating a final executable. */
2406 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
2408 struct extsym_info
*einfo
= data
;
2410 asection
*sec
, *output_section
;
2412 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2413 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2415 if (h
->root
.indx
== -2)
2417 else if ((h
->root
.def_dynamic
2418 || h
->root
.ref_dynamic
2419 || h
->root
.type
== bfd_link_hash_new
)
2420 && !h
->root
.def_regular
2421 && !h
->root
.ref_regular
)
2423 else if (einfo
->info
->strip
== strip_all
2424 || (einfo
->info
->strip
== strip_some
2425 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2426 h
->root
.root
.root
.string
,
2427 FALSE
, FALSE
) == NULL
))
2435 if (h
->esym
.ifd
== -2)
2438 h
->esym
.cobol_main
= 0;
2439 h
->esym
.weakext
= 0;
2440 h
->esym
.reserved
= 0;
2441 h
->esym
.ifd
= ifdNil
;
2442 h
->esym
.asym
.value
= 0;
2443 h
->esym
.asym
.st
= stGlobal
;
2445 if (h
->root
.root
.type
== bfd_link_hash_undefined
2446 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
2450 /* Use undefined class. Also, set class and type for some
2452 name
= h
->root
.root
.root
.string
;
2453 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2454 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2456 h
->esym
.asym
.sc
= scData
;
2457 h
->esym
.asym
.st
= stLabel
;
2458 h
->esym
.asym
.value
= 0;
2460 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2462 h
->esym
.asym
.sc
= scAbs
;
2463 h
->esym
.asym
.st
= stLabel
;
2464 h
->esym
.asym
.value
=
2465 mips_elf_hash_table (einfo
->info
)->procedure_count
;
2467 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
2469 h
->esym
.asym
.sc
= scAbs
;
2470 h
->esym
.asym
.st
= stLabel
;
2471 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
2474 h
->esym
.asym
.sc
= scUndefined
;
2476 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2477 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2478 h
->esym
.asym
.sc
= scAbs
;
2483 sec
= h
->root
.root
.u
.def
.section
;
2484 output_section
= sec
->output_section
;
2486 /* When making a shared library and symbol h is the one from
2487 the another shared library, OUTPUT_SECTION may be null. */
2488 if (output_section
== NULL
)
2489 h
->esym
.asym
.sc
= scUndefined
;
2492 name
= bfd_section_name (output_section
->owner
, output_section
);
2494 if (strcmp (name
, ".text") == 0)
2495 h
->esym
.asym
.sc
= scText
;
2496 else if (strcmp (name
, ".data") == 0)
2497 h
->esym
.asym
.sc
= scData
;
2498 else if (strcmp (name
, ".sdata") == 0)
2499 h
->esym
.asym
.sc
= scSData
;
2500 else if (strcmp (name
, ".rodata") == 0
2501 || strcmp (name
, ".rdata") == 0)
2502 h
->esym
.asym
.sc
= scRData
;
2503 else if (strcmp (name
, ".bss") == 0)
2504 h
->esym
.asym
.sc
= scBss
;
2505 else if (strcmp (name
, ".sbss") == 0)
2506 h
->esym
.asym
.sc
= scSBss
;
2507 else if (strcmp (name
, ".init") == 0)
2508 h
->esym
.asym
.sc
= scInit
;
2509 else if (strcmp (name
, ".fini") == 0)
2510 h
->esym
.asym
.sc
= scFini
;
2512 h
->esym
.asym
.sc
= scAbs
;
2516 h
->esym
.asym
.reserved
= 0;
2517 h
->esym
.asym
.index
= indexNil
;
2520 if (h
->root
.root
.type
== bfd_link_hash_common
)
2521 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2522 else if (h
->root
.root
.type
== bfd_link_hash_defined
2523 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2525 if (h
->esym
.asym
.sc
== scCommon
)
2526 h
->esym
.asym
.sc
= scBss
;
2527 else if (h
->esym
.asym
.sc
== scSCommon
)
2528 h
->esym
.asym
.sc
= scSBss
;
2530 sec
= h
->root
.root
.u
.def
.section
;
2531 output_section
= sec
->output_section
;
2532 if (output_section
!= NULL
)
2533 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2534 + sec
->output_offset
2535 + output_section
->vma
);
2537 h
->esym
.asym
.value
= 0;
2541 struct mips_elf_link_hash_entry
*hd
= h
;
2543 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
2544 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2546 if (hd
->needs_lazy_stub
)
2548 /* Set type and value for a symbol with a function stub. */
2549 h
->esym
.asym
.st
= stProc
;
2550 sec
= hd
->root
.root
.u
.def
.section
;
2552 h
->esym
.asym
.value
= 0;
2555 output_section
= sec
->output_section
;
2556 if (output_section
!= NULL
)
2557 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
2558 + sec
->output_offset
2559 + output_section
->vma
);
2561 h
->esym
.asym
.value
= 0;
2566 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2567 h
->root
.root
.root
.string
,
2570 einfo
->failed
= TRUE
;
2577 /* A comparison routine used to sort .gptab entries. */
2580 gptab_compare (const void *p1
, const void *p2
)
2582 const Elf32_gptab
*a1
= p1
;
2583 const Elf32_gptab
*a2
= p2
;
2585 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
2588 /* Functions to manage the got entry hash table. */
2590 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
2593 static INLINE hashval_t
2594 mips_elf_hash_bfd_vma (bfd_vma addr
)
2597 return addr
+ (addr
>> 32);
2603 /* got_entries only match if they're identical, except for gotidx, so
2604 use all fields to compute the hash, and compare the appropriate
2608 mips_elf_got_entry_hash (const void *entry_
)
2610 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2612 return entry
->symndx
2613 + ((entry
->tls_type
& GOT_TLS_LDM
) << 17)
2614 + (! entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
2616 + (entry
->symndx
>= 0 ? mips_elf_hash_bfd_vma (entry
->d
.addend
)
2617 : entry
->d
.h
->root
.root
.root
.hash
));
2621 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
2623 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2624 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2626 /* An LDM entry can only match another LDM entry. */
2627 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2630 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
2631 && (! e1
->abfd
? e1
->d
.address
== e2
->d
.address
2632 : e1
->symndx
>= 0 ? e1
->d
.addend
== e2
->d
.addend
2633 : e1
->d
.h
== e2
->d
.h
);
2636 /* multi_got_entries are still a match in the case of global objects,
2637 even if the input bfd in which they're referenced differs, so the
2638 hash computation and compare functions are adjusted
2642 mips_elf_multi_got_entry_hash (const void *entry_
)
2644 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2646 return entry
->symndx
2648 ? mips_elf_hash_bfd_vma (entry
->d
.address
)
2649 : entry
->symndx
>= 0
2650 ? ((entry
->tls_type
& GOT_TLS_LDM
)
2651 ? (GOT_TLS_LDM
<< 17)
2653 + mips_elf_hash_bfd_vma (entry
->d
.addend
)))
2654 : entry
->d
.h
->root
.root
.root
.hash
);
2658 mips_elf_multi_got_entry_eq (const void *entry1
, const void *entry2
)
2660 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2661 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2663 /* Any two LDM entries match. */
2664 if (e1
->tls_type
& e2
->tls_type
& GOT_TLS_LDM
)
2667 /* Nothing else matches an LDM entry. */
2668 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2671 return e1
->symndx
== e2
->symndx
2672 && (e1
->symndx
>= 0 ? e1
->abfd
== e2
->abfd
&& e1
->d
.addend
== e2
->d
.addend
2673 : e1
->abfd
== NULL
|| e2
->abfd
== NULL
2674 ? e1
->abfd
== e2
->abfd
&& e1
->d
.address
== e2
->d
.address
2675 : e1
->d
.h
== e2
->d
.h
);
2679 mips_got_page_entry_hash (const void *entry_
)
2681 const struct mips_got_page_entry
*entry
;
2683 entry
= (const struct mips_got_page_entry
*) entry_
;
2684 return entry
->abfd
->id
+ entry
->symndx
;
2688 mips_got_page_entry_eq (const void *entry1_
, const void *entry2_
)
2690 const struct mips_got_page_entry
*entry1
, *entry2
;
2692 entry1
= (const struct mips_got_page_entry
*) entry1_
;
2693 entry2
= (const struct mips_got_page_entry
*) entry2_
;
2694 return entry1
->abfd
== entry2
->abfd
&& entry1
->symndx
== entry2
->symndx
;
2697 /* Return the dynamic relocation section. If it doesn't exist, try to
2698 create a new it if CREATE_P, otherwise return NULL. Also return NULL
2699 if creation fails. */
2702 mips_elf_rel_dyn_section (struct bfd_link_info
*info
, bfd_boolean create_p
)
2708 dname
= MIPS_ELF_REL_DYN_NAME (info
);
2709 dynobj
= elf_hash_table (info
)->dynobj
;
2710 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
2711 if (sreloc
== NULL
&& create_p
)
2713 sreloc
= bfd_make_section_with_flags (dynobj
, dname
,
2718 | SEC_LINKER_CREATED
2721 || ! bfd_set_section_alignment (dynobj
, sreloc
,
2722 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
2728 /* Count the number of relocations needed for a TLS GOT entry, with
2729 access types from TLS_TYPE, and symbol H (or a local symbol if H
2733 mips_tls_got_relocs (struct bfd_link_info
*info
, unsigned char tls_type
,
2734 struct elf_link_hash_entry
*h
)
2738 bfd_boolean need_relocs
= FALSE
;
2739 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2741 if (h
&& WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2742 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, h
)))
2745 if ((info
->shared
|| indx
!= 0)
2747 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2748 || h
->root
.type
!= bfd_link_hash_undefweak
))
2754 if (tls_type
& GOT_TLS_GD
)
2761 if (tls_type
& GOT_TLS_IE
)
2764 if ((tls_type
& GOT_TLS_LDM
) && info
->shared
)
2770 /* Count the number of TLS relocations required for the GOT entry in
2771 ARG1, if it describes a local symbol. */
2774 mips_elf_count_local_tls_relocs (void **arg1
, void *arg2
)
2776 struct mips_got_entry
*entry
= * (struct mips_got_entry
**) arg1
;
2777 struct mips_elf_count_tls_arg
*arg
= arg2
;
2779 if (entry
->abfd
!= NULL
&& entry
->symndx
!= -1)
2780 arg
->needed
+= mips_tls_got_relocs (arg
->info
, entry
->tls_type
, NULL
);
2785 /* Count the number of TLS GOT entries required for the global (or
2786 forced-local) symbol in ARG1. */
2789 mips_elf_count_global_tls_entries (void *arg1
, void *arg2
)
2791 struct mips_elf_link_hash_entry
*hm
2792 = (struct mips_elf_link_hash_entry
*) arg1
;
2793 struct mips_elf_count_tls_arg
*arg
= arg2
;
2795 if (hm
->tls_type
& GOT_TLS_GD
)
2797 if (hm
->tls_type
& GOT_TLS_IE
)
2803 /* Count the number of TLS relocations required for the global (or
2804 forced-local) symbol in ARG1. */
2807 mips_elf_count_global_tls_relocs (void *arg1
, void *arg2
)
2809 struct mips_elf_link_hash_entry
*hm
2810 = (struct mips_elf_link_hash_entry
*) arg1
;
2811 struct mips_elf_count_tls_arg
*arg
= arg2
;
2813 arg
->needed
+= mips_tls_got_relocs (arg
->info
, hm
->tls_type
, &hm
->root
);
2818 /* Output a simple dynamic relocation into SRELOC. */
2821 mips_elf_output_dynamic_relocation (bfd
*output_bfd
,
2823 unsigned long reloc_index
,
2828 Elf_Internal_Rela rel
[3];
2830 memset (rel
, 0, sizeof (rel
));
2832 rel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, r_type
);
2833 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
2835 if (ABI_64_P (output_bfd
))
2837 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
2838 (output_bfd
, &rel
[0],
2840 + reloc_index
* sizeof (Elf64_Mips_External_Rel
)));
2843 bfd_elf32_swap_reloc_out
2844 (output_bfd
, &rel
[0],
2846 + reloc_index
* sizeof (Elf32_External_Rel
)));
2849 /* Initialize a set of TLS GOT entries for one symbol. */
2852 mips_elf_initialize_tls_slots (bfd
*abfd
, bfd_vma got_offset
,
2853 unsigned char *tls_type_p
,
2854 struct bfd_link_info
*info
,
2855 struct mips_elf_link_hash_entry
*h
,
2858 struct mips_elf_link_hash_table
*htab
;
2860 asection
*sreloc
, *sgot
;
2861 bfd_vma offset
, offset2
;
2862 bfd_boolean need_relocs
= FALSE
;
2864 htab
= mips_elf_hash_table (info
);
2873 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2875 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, &h
->root
)
2876 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
2877 indx
= h
->root
.dynindx
;
2880 if (*tls_type_p
& GOT_TLS_DONE
)
2883 if ((info
->shared
|| indx
!= 0)
2885 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
2886 || h
->root
.type
!= bfd_link_hash_undefweak
))
2889 /* MINUS_ONE means the symbol is not defined in this object. It may not
2890 be defined at all; assume that the value doesn't matter in that
2891 case. Otherwise complain if we would use the value. */
2892 BFD_ASSERT (value
!= MINUS_ONE
|| (indx
!= 0 && need_relocs
)
2893 || h
->root
.root
.type
== bfd_link_hash_undefweak
);
2895 /* Emit necessary relocations. */
2896 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
2898 /* General Dynamic. */
2899 if (*tls_type_p
& GOT_TLS_GD
)
2901 offset
= got_offset
;
2902 offset2
= offset
+ MIPS_ELF_GOT_SIZE (abfd
);
2906 mips_elf_output_dynamic_relocation
2907 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2908 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2909 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2912 mips_elf_output_dynamic_relocation
2913 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2914 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPREL64
: R_MIPS_TLS_DTPREL32
,
2915 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset2
);
2917 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2918 sgot
->contents
+ offset2
);
2922 MIPS_ELF_PUT_WORD (abfd
, 1,
2923 sgot
->contents
+ offset
);
2924 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2925 sgot
->contents
+ offset2
);
2928 got_offset
+= 2 * MIPS_ELF_GOT_SIZE (abfd
);
2931 /* Initial Exec model. */
2932 if (*tls_type_p
& GOT_TLS_IE
)
2934 offset
= got_offset
;
2939 MIPS_ELF_PUT_WORD (abfd
, value
- elf_hash_table (info
)->tls_sec
->vma
,
2940 sgot
->contents
+ offset
);
2942 MIPS_ELF_PUT_WORD (abfd
, 0,
2943 sgot
->contents
+ offset
);
2945 mips_elf_output_dynamic_relocation
2946 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2947 ABI_64_P (abfd
) ? R_MIPS_TLS_TPREL64
: R_MIPS_TLS_TPREL32
,
2948 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2951 MIPS_ELF_PUT_WORD (abfd
, value
- tprel_base (info
),
2952 sgot
->contents
+ offset
);
2955 if (*tls_type_p
& GOT_TLS_LDM
)
2957 /* The initial offset is zero, and the LD offsets will include the
2958 bias by DTP_OFFSET. */
2959 MIPS_ELF_PUT_WORD (abfd
, 0,
2960 sgot
->contents
+ got_offset
2961 + MIPS_ELF_GOT_SIZE (abfd
));
2964 MIPS_ELF_PUT_WORD (abfd
, 1,
2965 sgot
->contents
+ got_offset
);
2967 mips_elf_output_dynamic_relocation
2968 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2969 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2970 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
2973 *tls_type_p
|= GOT_TLS_DONE
;
2976 /* Return the GOT index to use for a relocation of type R_TYPE against
2977 a symbol accessed using TLS_TYPE models. The GOT entries for this
2978 symbol in this GOT start at GOT_INDEX. This function initializes the
2979 GOT entries and corresponding relocations. */
2982 mips_tls_got_index (bfd
*abfd
, bfd_vma got_index
, unsigned char *tls_type
,
2983 int r_type
, struct bfd_link_info
*info
,
2984 struct mips_elf_link_hash_entry
*h
, bfd_vma symbol
)
2986 BFD_ASSERT (r_type
== R_MIPS_TLS_GOTTPREL
|| r_type
== R_MIPS_TLS_GD
2987 || r_type
== R_MIPS_TLS_LDM
);
2989 mips_elf_initialize_tls_slots (abfd
, got_index
, tls_type
, info
, h
, symbol
);
2991 if (r_type
== R_MIPS_TLS_GOTTPREL
)
2993 BFD_ASSERT (*tls_type
& GOT_TLS_IE
);
2994 if (*tls_type
& GOT_TLS_GD
)
2995 return got_index
+ 2 * MIPS_ELF_GOT_SIZE (abfd
);
3000 if (r_type
== R_MIPS_TLS_GD
)
3002 BFD_ASSERT (*tls_type
& GOT_TLS_GD
);
3006 if (r_type
== R_MIPS_TLS_LDM
)
3008 BFD_ASSERT (*tls_type
& GOT_TLS_LDM
);
3015 /* Return the offset from _GLOBAL_OFFSET_TABLE_ of the .got.plt entry
3016 for global symbol H. .got.plt comes before the GOT, so the offset
3017 will be negative. */
3020 mips_elf_gotplt_index (struct bfd_link_info
*info
,
3021 struct elf_link_hash_entry
*h
)
3023 bfd_vma plt_index
, got_address
, got_value
;
3024 struct mips_elf_link_hash_table
*htab
;
3026 htab
= mips_elf_hash_table (info
);
3027 BFD_ASSERT (htab
!= NULL
);
3029 BFD_ASSERT (h
->plt
.offset
!= (bfd_vma
) -1);
3031 /* This function only works for VxWorks, because a non-VxWorks .got.plt
3032 section starts with reserved entries. */
3033 BFD_ASSERT (htab
->is_vxworks
);
3035 /* Calculate the index of the symbol's PLT entry. */
3036 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
3038 /* Calculate the address of the associated .got.plt entry. */
3039 got_address
= (htab
->sgotplt
->output_section
->vma
3040 + htab
->sgotplt
->output_offset
3043 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
3044 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
3045 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
3046 + htab
->root
.hgot
->root
.u
.def
.value
);
3048 return got_address
- got_value
;
3051 /* Return the GOT offset for address VALUE. If there is not yet a GOT
3052 entry for this value, create one. If R_SYMNDX refers to a TLS symbol,
3053 create a TLS GOT entry instead. Return -1 if no satisfactory GOT
3054 offset can be found. */
3057 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3058 bfd_vma value
, unsigned long r_symndx
,
3059 struct mips_elf_link_hash_entry
*h
, int r_type
)
3061 struct mips_elf_link_hash_table
*htab
;
3062 struct mips_got_entry
*entry
;
3064 htab
= mips_elf_hash_table (info
);
3065 BFD_ASSERT (htab
!= NULL
);
3067 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
,
3068 r_symndx
, h
, r_type
);
3072 if (TLS_RELOC_P (r_type
))
3074 if (entry
->symndx
== -1 && htab
->got_info
->next
== NULL
)
3075 /* A type (3) entry in the single-GOT case. We use the symbol's
3076 hash table entry to track the index. */
3077 return mips_tls_got_index (abfd
, h
->tls_got_offset
, &h
->tls_type
,
3078 r_type
, info
, h
, value
);
3080 return mips_tls_got_index (abfd
, entry
->gotidx
, &entry
->tls_type
,
3081 r_type
, info
, h
, value
);
3084 return entry
->gotidx
;
3087 /* Returns the GOT index for the global symbol indicated by H. */
3090 mips_elf_global_got_index (bfd
*abfd
, bfd
*ibfd
, struct elf_link_hash_entry
*h
,
3091 int r_type
, struct bfd_link_info
*info
)
3093 struct mips_elf_link_hash_table
*htab
;
3095 struct mips_got_info
*g
, *gg
;
3096 long global_got_dynindx
= 0;
3098 htab
= mips_elf_hash_table (info
);
3099 BFD_ASSERT (htab
!= NULL
);
3101 gg
= g
= htab
->got_info
;
3102 if (g
->bfd2got
&& ibfd
)
3104 struct mips_got_entry e
, *p
;
3106 BFD_ASSERT (h
->dynindx
>= 0);
3108 g
= mips_elf_got_for_ibfd (g
, ibfd
);
3109 if (g
->next
!= gg
|| TLS_RELOC_P (r_type
))
3113 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
3116 p
= htab_find (g
->got_entries
, &e
);
3118 BFD_ASSERT (p
->gotidx
> 0);
3120 if (TLS_RELOC_P (r_type
))
3122 bfd_vma value
= MINUS_ONE
;
3123 if ((h
->root
.type
== bfd_link_hash_defined
3124 || h
->root
.type
== bfd_link_hash_defweak
)
3125 && h
->root
.u
.def
.section
->output_section
)
3126 value
= (h
->root
.u
.def
.value
3127 + h
->root
.u
.def
.section
->output_offset
3128 + h
->root
.u
.def
.section
->output_section
->vma
);
3130 return mips_tls_got_index (abfd
, p
->gotidx
, &p
->tls_type
, r_type
,
3131 info
, e
.d
.h
, value
);
3138 if (gg
->global_gotsym
!= NULL
)
3139 global_got_dynindx
= gg
->global_gotsym
->dynindx
;
3141 if (TLS_RELOC_P (r_type
))
3143 struct mips_elf_link_hash_entry
*hm
3144 = (struct mips_elf_link_hash_entry
*) h
;
3145 bfd_vma value
= MINUS_ONE
;
3147 if ((h
->root
.type
== bfd_link_hash_defined
3148 || h
->root
.type
== bfd_link_hash_defweak
)
3149 && h
->root
.u
.def
.section
->output_section
)
3150 value
= (h
->root
.u
.def
.value
3151 + h
->root
.u
.def
.section
->output_offset
3152 + h
->root
.u
.def
.section
->output_section
->vma
);
3154 got_index
= mips_tls_got_index (abfd
, hm
->tls_got_offset
, &hm
->tls_type
,
3155 r_type
, info
, hm
, value
);
3159 /* Once we determine the global GOT entry with the lowest dynamic
3160 symbol table index, we must put all dynamic symbols with greater
3161 indices into the GOT. That makes it easy to calculate the GOT
3163 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
3164 got_index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
3165 * MIPS_ELF_GOT_SIZE (abfd
));
3167 BFD_ASSERT (got_index
< htab
->sgot
->size
);
3172 /* Find a GOT page entry that points to within 32KB of VALUE. These
3173 entries are supposed to be placed at small offsets in the GOT, i.e.,
3174 within 32KB of GP. Return the index of the GOT entry, or -1 if no
3175 entry could be created. If OFFSETP is nonnull, use it to return the
3176 offset of the GOT entry from VALUE. */
3179 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3180 bfd_vma value
, bfd_vma
*offsetp
)
3182 bfd_vma page
, got_index
;
3183 struct mips_got_entry
*entry
;
3185 page
= (value
+ 0x8000) & ~(bfd_vma
) 0xffff;
3186 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, page
, 0,
3187 NULL
, R_MIPS_GOT_PAGE
);
3192 got_index
= entry
->gotidx
;
3195 *offsetp
= value
- entry
->d
.address
;
3200 /* Find a local GOT entry for an R_MIPS*_GOT16 relocation against VALUE.
3201 EXTERNAL is true if the relocation was originally against a global
3202 symbol that binds locally. */
3205 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3206 bfd_vma value
, bfd_boolean external
)
3208 struct mips_got_entry
*entry
;
3210 /* GOT16 relocations against local symbols are followed by a LO16
3211 relocation; those against global symbols are not. Thus if the
3212 symbol was originally local, the GOT16 relocation should load the
3213 equivalent of %hi(VALUE), otherwise it should load VALUE itself. */
3215 value
= mips_elf_high (value
) << 16;
3217 /* It doesn't matter whether the original relocation was R_MIPS_GOT16,
3218 R_MIPS16_GOT16, R_MIPS_CALL16, etc. The format of the entry is the
3219 same in all cases. */
3220 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
, 0,
3221 NULL
, R_MIPS_GOT16
);
3223 return entry
->gotidx
;
3228 /* Returns the offset for the entry at the INDEXth position
3232 mips_elf_got_offset_from_index (struct bfd_link_info
*info
, bfd
*output_bfd
,
3233 bfd
*input_bfd
, bfd_vma got_index
)
3235 struct mips_elf_link_hash_table
*htab
;
3239 htab
= mips_elf_hash_table (info
);
3240 BFD_ASSERT (htab
!= NULL
);
3243 gp
= _bfd_get_gp_value (output_bfd
)
3244 + mips_elf_adjust_gp (output_bfd
, htab
->got_info
, input_bfd
);
3246 return sgot
->output_section
->vma
+ sgot
->output_offset
+ got_index
- gp
;
3249 /* Create and return a local GOT entry for VALUE, which was calculated
3250 from a symbol belonging to INPUT_SECTON. Return NULL if it could not
3251 be created. If R_SYMNDX refers to a TLS symbol, create a TLS entry
3254 static struct mips_got_entry
*
3255 mips_elf_create_local_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
3256 bfd
*ibfd
, bfd_vma value
,
3257 unsigned long r_symndx
,
3258 struct mips_elf_link_hash_entry
*h
,
3261 struct mips_got_entry entry
, **loc
;
3262 struct mips_got_info
*g
;
3263 struct mips_elf_link_hash_table
*htab
;
3265 htab
= mips_elf_hash_table (info
);
3266 BFD_ASSERT (htab
!= NULL
);
3270 entry
.d
.address
= value
;
3273 g
= mips_elf_got_for_ibfd (htab
->got_info
, ibfd
);
3276 g
= mips_elf_got_for_ibfd (htab
->got_info
, abfd
);
3277 BFD_ASSERT (g
!= NULL
);
3280 /* This function shouldn't be called for symbols that live in the global
3282 BFD_ASSERT (h
== NULL
|| h
->global_got_area
== GGA_NONE
);
3283 if (TLS_RELOC_P (r_type
))
3285 struct mips_got_entry
*p
;
3288 if (r_type
== R_MIPS_TLS_LDM
)
3290 entry
.tls_type
= GOT_TLS_LDM
;
3296 entry
.symndx
= r_symndx
;
3302 p
= (struct mips_got_entry
*)
3303 htab_find (g
->got_entries
, &entry
);
3309 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
3314 entry
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
3317 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3322 memcpy (*loc
, &entry
, sizeof entry
);
3324 if (g
->assigned_gotno
> g
->local_gotno
)
3326 (*loc
)->gotidx
= -1;
3327 /* We didn't allocate enough space in the GOT. */
3328 (*_bfd_error_handler
)
3329 (_("not enough GOT space for local GOT entries"));
3330 bfd_set_error (bfd_error_bad_value
);
3334 MIPS_ELF_PUT_WORD (abfd
, value
,
3335 (htab
->sgot
->contents
+ entry
.gotidx
));
3337 /* These GOT entries need a dynamic relocation on VxWorks. */
3338 if (htab
->is_vxworks
)
3340 Elf_Internal_Rela outrel
;
3343 bfd_vma got_address
;
3345 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3346 got_address
= (htab
->sgot
->output_section
->vma
3347 + htab
->sgot
->output_offset
3350 rloc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
3351 outrel
.r_offset
= got_address
;
3352 outrel
.r_info
= ELF32_R_INFO (STN_UNDEF
, R_MIPS_32
);
3353 outrel
.r_addend
= value
;
3354 bfd_elf32_swap_reloca_out (abfd
, &outrel
, rloc
);
3360 /* Return the number of dynamic section symbols required by OUTPUT_BFD.
3361 The number might be exact or a worst-case estimate, depending on how
3362 much information is available to elf_backend_omit_section_dynsym at
3363 the current linking stage. */
3365 static bfd_size_type
3366 count_section_dynsyms (bfd
*output_bfd
, struct bfd_link_info
*info
)
3368 bfd_size_type count
;
3371 if (info
->shared
|| elf_hash_table (info
)->is_relocatable_executable
)
3374 const struct elf_backend_data
*bed
;
3376 bed
= get_elf_backend_data (output_bfd
);
3377 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
3378 if ((p
->flags
& SEC_EXCLUDE
) == 0
3379 && (p
->flags
& SEC_ALLOC
) != 0
3380 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
3386 /* Sort the dynamic symbol table so that symbols that need GOT entries
3387 appear towards the end. */
3390 mips_elf_sort_hash_table (bfd
*abfd
, struct bfd_link_info
*info
)
3392 struct mips_elf_link_hash_table
*htab
;
3393 struct mips_elf_hash_sort_data hsd
;
3394 struct mips_got_info
*g
;
3396 if (elf_hash_table (info
)->dynsymcount
== 0)
3399 htab
= mips_elf_hash_table (info
);
3400 BFD_ASSERT (htab
!= NULL
);
3407 hsd
.max_unref_got_dynindx
3408 = hsd
.min_got_dynindx
3409 = (elf_hash_table (info
)->dynsymcount
- g
->reloc_only_gotno
);
3410 hsd
.max_non_got_dynindx
= count_section_dynsyms (abfd
, info
) + 1;
3411 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
3412 elf_hash_table (info
)),
3413 mips_elf_sort_hash_table_f
,
3416 /* There should have been enough room in the symbol table to
3417 accommodate both the GOT and non-GOT symbols. */
3418 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
3419 BFD_ASSERT ((unsigned long) hsd
.max_unref_got_dynindx
3420 == elf_hash_table (info
)->dynsymcount
);
3421 BFD_ASSERT (elf_hash_table (info
)->dynsymcount
- hsd
.min_got_dynindx
3422 == g
->global_gotno
);
3424 /* Now we know which dynamic symbol has the lowest dynamic symbol
3425 table index in the GOT. */
3426 g
->global_gotsym
= hsd
.low
;
3431 /* If H needs a GOT entry, assign it the highest available dynamic
3432 index. Otherwise, assign it the lowest available dynamic
3436 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
3438 struct mips_elf_hash_sort_data
*hsd
= data
;
3440 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3441 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3443 /* Symbols without dynamic symbol table entries aren't interesting
3445 if (h
->root
.dynindx
== -1)
3448 switch (h
->global_got_area
)
3451 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
3455 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
3457 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
3458 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3461 case GGA_RELOC_ONLY
:
3462 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
3464 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
3465 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3466 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
3473 /* If H is a symbol that needs a global GOT entry, but has a dynamic
3474 symbol table index lower than any we've seen to date, record it for
3475 posterity. FOR_CALL is true if the caller is only interested in
3476 using the GOT entry for calls. */
3479 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
3480 bfd
*abfd
, struct bfd_link_info
*info
,
3481 bfd_boolean for_call
,
3482 unsigned char tls_flag
)
3484 struct mips_elf_link_hash_table
*htab
;
3485 struct mips_elf_link_hash_entry
*hmips
;
3486 struct mips_got_entry entry
, **loc
;
3487 struct mips_got_info
*g
;
3489 htab
= mips_elf_hash_table (info
);
3490 BFD_ASSERT (htab
!= NULL
);
3492 hmips
= (struct mips_elf_link_hash_entry
*) h
;
3494 hmips
->got_only_for_calls
= FALSE
;
3496 /* A global symbol in the GOT must also be in the dynamic symbol
3498 if (h
->dynindx
== -1)
3500 switch (ELF_ST_VISIBILITY (h
->other
))
3504 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
3507 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3511 /* Make sure we have a GOT to put this entry into. */
3513 BFD_ASSERT (g
!= NULL
);
3517 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
3520 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
3523 /* If we've already marked this entry as needing GOT space, we don't
3524 need to do it again. */
3527 (*loc
)->tls_type
|= tls_flag
;
3531 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3537 entry
.tls_type
= tls_flag
;
3539 memcpy (*loc
, &entry
, sizeof entry
);
3542 hmips
->global_got_area
= GGA_NORMAL
;
3547 /* Reserve space in G for a GOT entry containing the value of symbol
3548 SYMNDX in input bfd ABDF, plus ADDEND. */
3551 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
3552 struct bfd_link_info
*info
,
3553 unsigned char tls_flag
)
3555 struct mips_elf_link_hash_table
*htab
;
3556 struct mips_got_info
*g
;
3557 struct mips_got_entry entry
, **loc
;
3559 htab
= mips_elf_hash_table (info
);
3560 BFD_ASSERT (htab
!= NULL
);
3563 BFD_ASSERT (g
!= NULL
);
3566 entry
.symndx
= symndx
;
3567 entry
.d
.addend
= addend
;
3568 entry
.tls_type
= tls_flag
;
3569 loc
= (struct mips_got_entry
**)
3570 htab_find_slot (g
->got_entries
, &entry
, INSERT
);
3574 if (tls_flag
== GOT_TLS_GD
&& !((*loc
)->tls_type
& GOT_TLS_GD
))
3577 (*loc
)->tls_type
|= tls_flag
;
3579 else if (tls_flag
== GOT_TLS_IE
&& !((*loc
)->tls_type
& GOT_TLS_IE
))
3582 (*loc
)->tls_type
|= tls_flag
;
3590 entry
.tls_type
= tls_flag
;
3591 if (tls_flag
== GOT_TLS_IE
)
3593 else if (tls_flag
== GOT_TLS_GD
)
3595 else if (g
->tls_ldm_offset
== MINUS_ONE
)
3597 g
->tls_ldm_offset
= MINUS_TWO
;
3603 entry
.gotidx
= g
->local_gotno
++;
3607 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3612 memcpy (*loc
, &entry
, sizeof entry
);
3617 /* Return the maximum number of GOT page entries required for RANGE. */
3620 mips_elf_pages_for_range (const struct mips_got_page_range
*range
)
3622 return (range
->max_addend
- range
->min_addend
+ 0x1ffff) >> 16;
3625 /* Record that ABFD has a page relocation against symbol SYMNDX and
3626 that ADDEND is the addend for that relocation.
3628 This function creates an upper bound on the number of GOT slots
3629 required; no attempt is made to combine references to non-overridable
3630 global symbols across multiple input files. */
3633 mips_elf_record_got_page_entry (struct bfd_link_info
*info
, bfd
*abfd
,
3634 long symndx
, bfd_signed_vma addend
)
3636 struct mips_elf_link_hash_table
*htab
;
3637 struct mips_got_info
*g
;
3638 struct mips_got_page_entry lookup
, *entry
;
3639 struct mips_got_page_range
**range_ptr
, *range
;
3640 bfd_vma old_pages
, new_pages
;
3643 htab
= mips_elf_hash_table (info
);
3644 BFD_ASSERT (htab
!= NULL
);
3647 BFD_ASSERT (g
!= NULL
);
3649 /* Find the mips_got_page_entry hash table entry for this symbol. */
3651 lookup
.symndx
= symndx
;
3652 loc
= htab_find_slot (g
->got_page_entries
, &lookup
, INSERT
);
3656 /* Create a mips_got_page_entry if this is the first time we've
3658 entry
= (struct mips_got_page_entry
*) *loc
;
3661 entry
= bfd_alloc (abfd
, sizeof (*entry
));
3666 entry
->symndx
= symndx
;
3667 entry
->ranges
= NULL
;
3668 entry
->num_pages
= 0;
3672 /* Skip over ranges whose maximum extent cannot share a page entry
3674 range_ptr
= &entry
->ranges
;
3675 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
3676 range_ptr
= &(*range_ptr
)->next
;
3678 /* If we scanned to the end of the list, or found a range whose
3679 minimum extent cannot share a page entry with ADDEND, create
3680 a new singleton range. */
3682 if (!range
|| addend
< range
->min_addend
- 0xffff)
3684 range
= bfd_alloc (abfd
, sizeof (*range
));
3688 range
->next
= *range_ptr
;
3689 range
->min_addend
= addend
;
3690 range
->max_addend
= addend
;
3698 /* Remember how many pages the old range contributed. */
3699 old_pages
= mips_elf_pages_for_range (range
);
3701 /* Update the ranges. */
3702 if (addend
< range
->min_addend
)
3703 range
->min_addend
= addend
;
3704 else if (addend
> range
->max_addend
)
3706 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
3708 old_pages
+= mips_elf_pages_for_range (range
->next
);
3709 range
->max_addend
= range
->next
->max_addend
;
3710 range
->next
= range
->next
->next
;
3713 range
->max_addend
= addend
;
3716 /* Record any change in the total estimate. */
3717 new_pages
= mips_elf_pages_for_range (range
);
3718 if (old_pages
!= new_pages
)
3720 entry
->num_pages
+= new_pages
- old_pages
;
3721 g
->page_gotno
+= new_pages
- old_pages
;
3727 /* Add room for N relocations to the .rel(a).dyn section in ABFD. */
3730 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, struct bfd_link_info
*info
,
3734 struct mips_elf_link_hash_table
*htab
;
3736 htab
= mips_elf_hash_table (info
);
3737 BFD_ASSERT (htab
!= NULL
);
3739 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3740 BFD_ASSERT (s
!= NULL
);
3742 if (htab
->is_vxworks
)
3743 s
->size
+= n
* MIPS_ELF_RELA_SIZE (abfd
);
3748 /* Make room for a null element. */
3749 s
->size
+= MIPS_ELF_REL_SIZE (abfd
);
3752 s
->size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
3756 /* A htab_traverse callback for GOT entries. Set boolean *DATA to true
3757 if the GOT entry is for an indirect or warning symbol. */
3760 mips_elf_check_recreate_got (void **entryp
, void *data
)
3762 struct mips_got_entry
*entry
;
3763 bfd_boolean
*must_recreate
;
3765 entry
= (struct mips_got_entry
*) *entryp
;
3766 must_recreate
= (bfd_boolean
*) data
;
3767 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3769 struct mips_elf_link_hash_entry
*h
;
3772 if (h
->root
.root
.type
== bfd_link_hash_indirect
3773 || h
->root
.root
.type
== bfd_link_hash_warning
)
3775 *must_recreate
= TRUE
;
3782 /* A htab_traverse callback for GOT entries. Add all entries to
3783 hash table *DATA, converting entries for indirect and warning
3784 symbols into entries for the target symbol. Set *DATA to null
3788 mips_elf_recreate_got (void **entryp
, void *data
)
3791 struct mips_got_entry
*entry
;
3794 new_got
= (htab_t
*) data
;
3795 entry
= (struct mips_got_entry
*) *entryp
;
3796 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3798 struct mips_elf_link_hash_entry
*h
;
3801 while (h
->root
.root
.type
== bfd_link_hash_indirect
3802 || h
->root
.root
.type
== bfd_link_hash_warning
)
3804 BFD_ASSERT (h
->global_got_area
== GGA_NONE
);
3805 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3809 slot
= htab_find_slot (*new_got
, entry
, INSERT
);
3822 /* If any entries in G->got_entries are for indirect or warning symbols,
3823 replace them with entries for the target symbol. */
3826 mips_elf_resolve_final_got_entries (struct mips_got_info
*g
)
3828 bfd_boolean must_recreate
;
3831 must_recreate
= FALSE
;
3832 htab_traverse (g
->got_entries
, mips_elf_check_recreate_got
, &must_recreate
);
3835 new_got
= htab_create (htab_size (g
->got_entries
),
3836 mips_elf_got_entry_hash
,
3837 mips_elf_got_entry_eq
, NULL
);
3838 htab_traverse (g
->got_entries
, mips_elf_recreate_got
, &new_got
);
3839 if (new_got
== NULL
)
3842 /* Each entry in g->got_entries has either been copied to new_got
3843 or freed. Now delete the hash table itself. */
3844 htab_delete (g
->got_entries
);
3845 g
->got_entries
= new_got
;
3850 /* A mips_elf_link_hash_traverse callback for which DATA points
3851 to the link_info structure. Count the number of type (3) entries
3852 in the master GOT. */
3855 mips_elf_count_got_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
3857 struct bfd_link_info
*info
;
3858 struct mips_elf_link_hash_table
*htab
;
3859 struct mips_got_info
*g
;
3861 info
= (struct bfd_link_info
*) data
;
3862 htab
= mips_elf_hash_table (info
);
3864 if (h
->global_got_area
!= GGA_NONE
)
3866 /* Make a final decision about whether the symbol belongs in the
3867 local or global GOT. Symbols that bind locally can (and in the
3868 case of forced-local symbols, must) live in the local GOT.
3869 Those that are aren't in the dynamic symbol table must also
3870 live in the local GOT.
3872 Note that the former condition does not always imply the
3873 latter: symbols do not bind locally if they are completely
3874 undefined. We'll report undefined symbols later if appropriate. */
3875 if (h
->root
.dynindx
== -1
3876 || (h
->got_only_for_calls
3877 ? SYMBOL_CALLS_LOCAL (info
, &h
->root
)
3878 : SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
3880 /* The symbol belongs in the local GOT. We no longer need this
3881 entry if it was only used for relocations; those relocations
3882 will be against the null or section symbol instead of H. */
3883 if (h
->global_got_area
!= GGA_RELOC_ONLY
)
3885 h
->global_got_area
= GGA_NONE
;
3887 else if (htab
->is_vxworks
3888 && h
->got_only_for_calls
3889 && h
->root
.plt
.offset
!= MINUS_ONE
)
3890 /* On VxWorks, calls can refer directly to the .got.plt entry;
3891 they don't need entries in the regular GOT. .got.plt entries
3892 will be allocated by _bfd_mips_elf_adjust_dynamic_symbol. */
3893 h
->global_got_area
= GGA_NONE
;
3897 if (h
->global_got_area
== GGA_RELOC_ONLY
)
3898 g
->reloc_only_gotno
++;
3904 /* Compute the hash value of the bfd in a bfd2got hash entry. */
3907 mips_elf_bfd2got_entry_hash (const void *entry_
)
3909 const struct mips_elf_bfd2got_hash
*entry
3910 = (struct mips_elf_bfd2got_hash
*)entry_
;
3912 return entry
->bfd
->id
;
3915 /* Check whether two hash entries have the same bfd. */
3918 mips_elf_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
3920 const struct mips_elf_bfd2got_hash
*e1
3921 = (const struct mips_elf_bfd2got_hash
*)entry1
;
3922 const struct mips_elf_bfd2got_hash
*e2
3923 = (const struct mips_elf_bfd2got_hash
*)entry2
;
3925 return e1
->bfd
== e2
->bfd
;
3928 /* In a multi-got link, determine the GOT to be used for IBFD. G must
3929 be the master GOT data. */
3931 static struct mips_got_info
*
3932 mips_elf_got_for_ibfd (struct mips_got_info
*g
, bfd
*ibfd
)
3934 struct mips_elf_bfd2got_hash e
, *p
;
3940 p
= htab_find (g
->bfd2got
, &e
);
3941 return p
? p
->g
: NULL
;
3944 /* Use BFD2GOT to find ABFD's got entry, creating one if none exists.
3945 Return NULL if an error occured. */
3947 static struct mips_got_info
*
3948 mips_elf_get_got_for_bfd (struct htab
*bfd2got
, bfd
*output_bfd
,
3951 struct mips_elf_bfd2got_hash bfdgot_entry
, *bfdgot
;
3952 struct mips_got_info
*g
;
3955 bfdgot_entry
.bfd
= input_bfd
;
3956 bfdgotp
= htab_find_slot (bfd2got
, &bfdgot_entry
, INSERT
);
3957 bfdgot
= (struct mips_elf_bfd2got_hash
*) *bfdgotp
;
3961 bfdgot
= ((struct mips_elf_bfd2got_hash
*)
3962 bfd_alloc (output_bfd
, sizeof (struct mips_elf_bfd2got_hash
)));
3968 g
= ((struct mips_got_info
*)
3969 bfd_alloc (output_bfd
, sizeof (struct mips_got_info
)));
3973 bfdgot
->bfd
= input_bfd
;
3976 g
->global_gotsym
= NULL
;
3977 g
->global_gotno
= 0;
3978 g
->reloc_only_gotno
= 0;
3981 g
->assigned_gotno
= -1;
3983 g
->tls_assigned_gotno
= 0;
3984 g
->tls_ldm_offset
= MINUS_ONE
;
3985 g
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3986 mips_elf_multi_got_entry_eq
, NULL
);
3987 if (g
->got_entries
== NULL
)
3990 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
3991 mips_got_page_entry_eq
, NULL
);
3992 if (g
->got_page_entries
== NULL
)
4002 /* A htab_traverse callback for the entries in the master got.
4003 Create one separate got for each bfd that has entries in the global
4004 got, such that we can tell how many local and global entries each
4008 mips_elf_make_got_per_bfd (void **entryp
, void *p
)
4010 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
4011 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
4012 struct mips_got_info
*g
;
4014 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
4021 /* Insert the GOT entry in the bfd's got entry hash table. */
4022 entryp
= htab_find_slot (g
->got_entries
, entry
, INSERT
);
4023 if (*entryp
!= NULL
)
4028 if (entry
->tls_type
)
4030 if (entry
->tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
4032 if (entry
->tls_type
& GOT_TLS_IE
)
4035 else if (entry
->symndx
>= 0 || entry
->d
.h
->global_got_area
== GGA_NONE
)
4043 /* A htab_traverse callback for the page entries in the master got.
4044 Associate each page entry with the bfd's got. */
4047 mips_elf_make_got_pages_per_bfd (void **entryp
, void *p
)
4049 struct mips_got_page_entry
*entry
= (struct mips_got_page_entry
*) *entryp
;
4050 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*) p
;
4051 struct mips_got_info
*g
;
4053 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
4060 /* Insert the GOT entry in the bfd's got entry hash table. */
4061 entryp
= htab_find_slot (g
->got_page_entries
, entry
, INSERT
);
4062 if (*entryp
!= NULL
)
4066 g
->page_gotno
+= entry
->num_pages
;
4070 /* Consider merging the got described by BFD2GOT with TO, using the
4071 information given by ARG. Return -1 if this would lead to overflow,
4072 1 if they were merged successfully, and 0 if a merge failed due to
4073 lack of memory. (These values are chosen so that nonnegative return
4074 values can be returned by a htab_traverse callback.) */
4077 mips_elf_merge_got_with (struct mips_elf_bfd2got_hash
*bfd2got
,
4078 struct mips_got_info
*to
,
4079 struct mips_elf_got_per_bfd_arg
*arg
)
4081 struct mips_got_info
*from
= bfd2got
->g
;
4082 unsigned int estimate
;
4084 /* Work out how many page entries we would need for the combined GOT. */
4085 estimate
= arg
->max_pages
;
4086 if (estimate
>= from
->page_gotno
+ to
->page_gotno
)
4087 estimate
= from
->page_gotno
+ to
->page_gotno
;
4089 /* And conservatively estimate how many local and TLS entries
4091 estimate
+= from
->local_gotno
+ to
->local_gotno
;
4092 estimate
+= from
->tls_gotno
+ to
->tls_gotno
;
4094 /* If we're merging with the primary got, we will always have
4095 the full set of global entries. Otherwise estimate those
4096 conservatively as well. */
4097 if (to
== arg
->primary
)
4098 estimate
+= arg
->global_count
;
4100 estimate
+= from
->global_gotno
+ to
->global_gotno
;
4102 /* Bail out if the combined GOT might be too big. */
4103 if (estimate
> arg
->max_count
)
4106 /* Commit to the merge. Record that TO is now the bfd for this got. */
4109 /* Transfer the bfd's got information from FROM to TO. */
4110 htab_traverse (from
->got_entries
, mips_elf_make_got_per_bfd
, arg
);
4111 if (arg
->obfd
== NULL
)
4114 htab_traverse (from
->got_page_entries
, mips_elf_make_got_pages_per_bfd
, arg
);
4115 if (arg
->obfd
== NULL
)
4118 /* We don't have to worry about releasing memory of the actual
4119 got entries, since they're all in the master got_entries hash
4121 htab_delete (from
->got_entries
);
4122 htab_delete (from
->got_page_entries
);
4126 /* Attempt to merge gots of different input bfds. Try to use as much
4127 as possible of the primary got, since it doesn't require explicit
4128 dynamic relocations, but don't use bfds that would reference global
4129 symbols out of the addressable range. Failing the primary got,
4130 attempt to merge with the current got, or finish the current got
4131 and then make make the new got current. */
4134 mips_elf_merge_gots (void **bfd2got_
, void *p
)
4136 struct mips_elf_bfd2got_hash
*bfd2got
4137 = (struct mips_elf_bfd2got_hash
*)*bfd2got_
;
4138 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
4139 struct mips_got_info
*g
;
4140 unsigned int estimate
;
4145 /* Work out the number of page, local and TLS entries. */
4146 estimate
= arg
->max_pages
;
4147 if (estimate
> g
->page_gotno
)
4148 estimate
= g
->page_gotno
;
4149 estimate
+= g
->local_gotno
+ g
->tls_gotno
;
4151 /* We place TLS GOT entries after both locals and globals. The globals
4152 for the primary GOT may overflow the normal GOT size limit, so be
4153 sure not to merge a GOT which requires TLS with the primary GOT in that
4154 case. This doesn't affect non-primary GOTs. */
4155 estimate
+= (g
->tls_gotno
> 0 ? arg
->global_count
: g
->global_gotno
);
4157 if (estimate
<= arg
->max_count
)
4159 /* If we don't have a primary GOT, use it as
4160 a starting point for the primary GOT. */
4163 arg
->primary
= bfd2got
->g
;
4167 /* Try merging with the primary GOT. */
4168 result
= mips_elf_merge_got_with (bfd2got
, arg
->primary
, arg
);
4173 /* If we can merge with the last-created got, do it. */
4176 result
= mips_elf_merge_got_with (bfd2got
, arg
->current
, arg
);
4181 /* Well, we couldn't merge, so create a new GOT. Don't check if it
4182 fits; if it turns out that it doesn't, we'll get relocation
4183 overflows anyway. */
4184 g
->next
= arg
->current
;
4190 /* Set the TLS GOT index for the GOT entry in ENTRYP. ENTRYP's NEXT field
4191 is null iff there is just a single GOT. */
4194 mips_elf_initialize_tls_index (void **entryp
, void *p
)
4196 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
4197 struct mips_got_info
*g
= p
;
4199 unsigned char tls_type
;
4201 /* We're only interested in TLS symbols. */
4202 if (entry
->tls_type
== 0)
4205 next_index
= MIPS_ELF_GOT_SIZE (entry
->abfd
) * (long) g
->tls_assigned_gotno
;
4207 if (entry
->symndx
== -1 && g
->next
== NULL
)
4209 /* A type (3) got entry in the single-GOT case. We use the symbol's
4210 hash table entry to track its index. */
4211 if (entry
->d
.h
->tls_type
& GOT_TLS_OFFSET_DONE
)
4213 entry
->d
.h
->tls_type
|= GOT_TLS_OFFSET_DONE
;
4214 entry
->d
.h
->tls_got_offset
= next_index
;
4215 tls_type
= entry
->d
.h
->tls_type
;
4219 if (entry
->tls_type
& GOT_TLS_LDM
)
4221 /* There are separate mips_got_entry objects for each input bfd
4222 that requires an LDM entry. Make sure that all LDM entries in
4223 a GOT resolve to the same index. */
4224 if (g
->tls_ldm_offset
!= MINUS_TWO
&& g
->tls_ldm_offset
!= MINUS_ONE
)
4226 entry
->gotidx
= g
->tls_ldm_offset
;
4229 g
->tls_ldm_offset
= next_index
;
4231 entry
->gotidx
= next_index
;
4232 tls_type
= entry
->tls_type
;
4235 /* Account for the entries we've just allocated. */
4236 if (tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
4237 g
->tls_assigned_gotno
+= 2;
4238 if (tls_type
& GOT_TLS_IE
)
4239 g
->tls_assigned_gotno
+= 1;
4244 /* If passed a NULL mips_got_info in the argument, set the marker used
4245 to tell whether a global symbol needs a got entry (in the primary
4246 got) to the given VALUE.
4248 If passed a pointer G to a mips_got_info in the argument (it must
4249 not be the primary GOT), compute the offset from the beginning of
4250 the (primary) GOT section to the entry in G corresponding to the
4251 global symbol. G's assigned_gotno must contain the index of the
4252 first available global GOT entry in G. VALUE must contain the size
4253 of a GOT entry in bytes. For each global GOT entry that requires a
4254 dynamic relocation, NEEDED_RELOCS is incremented, and the symbol is
4255 marked as not eligible for lazy resolution through a function
4258 mips_elf_set_global_got_offset (void **entryp
, void *p
)
4260 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
4261 struct mips_elf_set_global_got_offset_arg
*arg
4262 = (struct mips_elf_set_global_got_offset_arg
*)p
;
4263 struct mips_got_info
*g
= arg
->g
;
4265 if (g
&& entry
->tls_type
!= GOT_NORMAL
)
4266 arg
->needed_relocs
+=
4267 mips_tls_got_relocs (arg
->info
, entry
->tls_type
,
4268 entry
->symndx
== -1 ? &entry
->d
.h
->root
: NULL
);
4270 if (entry
->abfd
!= NULL
4271 && entry
->symndx
== -1
4272 && entry
->d
.h
->global_got_area
!= GGA_NONE
)
4276 BFD_ASSERT (g
->global_gotsym
== NULL
);
4278 entry
->gotidx
= arg
->value
* (long) g
->assigned_gotno
++;
4279 if (arg
->info
->shared
4280 || (elf_hash_table (arg
->info
)->dynamic_sections_created
4281 && entry
->d
.h
->root
.def_dynamic
4282 && !entry
->d
.h
->root
.def_regular
))
4283 ++arg
->needed_relocs
;
4286 entry
->d
.h
->global_got_area
= arg
->value
;
4292 /* A htab_traverse callback for GOT entries for which DATA is the
4293 bfd_link_info. Forbid any global symbols from having traditional
4294 lazy-binding stubs. */
4297 mips_elf_forbid_lazy_stubs (void **entryp
, void *data
)
4299 struct bfd_link_info
*info
;
4300 struct mips_elf_link_hash_table
*htab
;
4301 struct mips_got_entry
*entry
;
4303 entry
= (struct mips_got_entry
*) *entryp
;
4304 info
= (struct bfd_link_info
*) data
;
4305 htab
= mips_elf_hash_table (info
);
4306 BFD_ASSERT (htab
!= NULL
);
4308 if (entry
->abfd
!= NULL
4309 && entry
->symndx
== -1
4310 && entry
->d
.h
->needs_lazy_stub
)
4312 entry
->d
.h
->needs_lazy_stub
= FALSE
;
4313 htab
->lazy_stub_count
--;
4319 /* Return the offset of an input bfd IBFD's GOT from the beginning of
4322 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
4324 if (g
->bfd2got
== NULL
)
4327 g
= mips_elf_got_for_ibfd (g
, ibfd
);
4331 BFD_ASSERT (g
->next
);
4335 return (g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
)
4336 * MIPS_ELF_GOT_SIZE (abfd
);
4339 /* Turn a single GOT that is too big for 16-bit addressing into
4340 a sequence of GOTs, each one 16-bit addressable. */
4343 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
4344 asection
*got
, bfd_size_type pages
)
4346 struct mips_elf_link_hash_table
*htab
;
4347 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
4348 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
4349 struct mips_got_info
*g
, *gg
;
4350 unsigned int assign
, needed_relocs
;
4353 dynobj
= elf_hash_table (info
)->dynobj
;
4354 htab
= mips_elf_hash_table (info
);
4355 BFD_ASSERT (htab
!= NULL
);
4358 g
->bfd2got
= htab_try_create (1, mips_elf_bfd2got_entry_hash
,
4359 mips_elf_bfd2got_entry_eq
, NULL
);
4360 if (g
->bfd2got
== NULL
)
4363 got_per_bfd_arg
.bfd2got
= g
->bfd2got
;
4364 got_per_bfd_arg
.obfd
= abfd
;
4365 got_per_bfd_arg
.info
= info
;
4367 /* Count how many GOT entries each input bfd requires, creating a
4368 map from bfd to got info while at that. */
4369 htab_traverse (g
->got_entries
, mips_elf_make_got_per_bfd
, &got_per_bfd_arg
);
4370 if (got_per_bfd_arg
.obfd
== NULL
)
4373 /* Also count how many page entries each input bfd requires. */
4374 htab_traverse (g
->got_page_entries
, mips_elf_make_got_pages_per_bfd
,
4376 if (got_per_bfd_arg
.obfd
== NULL
)
4379 got_per_bfd_arg
.current
= NULL
;
4380 got_per_bfd_arg
.primary
= NULL
;
4381 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (info
)
4382 / MIPS_ELF_GOT_SIZE (abfd
))
4383 - htab
->reserved_gotno
);
4384 got_per_bfd_arg
.max_pages
= pages
;
4385 /* The number of globals that will be included in the primary GOT.
4386 See the calls to mips_elf_set_global_got_offset below for more
4388 got_per_bfd_arg
.global_count
= g
->global_gotno
;
4390 /* Try to merge the GOTs of input bfds together, as long as they
4391 don't seem to exceed the maximum GOT size, choosing one of them
4392 to be the primary GOT. */
4393 htab_traverse (g
->bfd2got
, mips_elf_merge_gots
, &got_per_bfd_arg
);
4394 if (got_per_bfd_arg
.obfd
== NULL
)
4397 /* If we do not find any suitable primary GOT, create an empty one. */
4398 if (got_per_bfd_arg
.primary
== NULL
)
4400 g
->next
= (struct mips_got_info
*)
4401 bfd_alloc (abfd
, sizeof (struct mips_got_info
));
4402 if (g
->next
== NULL
)
4405 g
->next
->global_gotsym
= NULL
;
4406 g
->next
->global_gotno
= 0;
4407 g
->next
->reloc_only_gotno
= 0;
4408 g
->next
->local_gotno
= 0;
4409 g
->next
->page_gotno
= 0;
4410 g
->next
->tls_gotno
= 0;
4411 g
->next
->assigned_gotno
= 0;
4412 g
->next
->tls_assigned_gotno
= 0;
4413 g
->next
->tls_ldm_offset
= MINUS_ONE
;
4414 g
->next
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
4415 mips_elf_multi_got_entry_eq
,
4417 if (g
->next
->got_entries
== NULL
)
4419 g
->next
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4420 mips_got_page_entry_eq
,
4422 if (g
->next
->got_page_entries
== NULL
)
4424 g
->next
->bfd2got
= NULL
;
4427 g
->next
= got_per_bfd_arg
.primary
;
4428 g
->next
->next
= got_per_bfd_arg
.current
;
4430 /* GG is now the master GOT, and G is the primary GOT. */
4434 /* Map the output bfd to the primary got. That's what we're going
4435 to use for bfds that use GOT16 or GOT_PAGE relocations that we
4436 didn't mark in check_relocs, and we want a quick way to find it.
4437 We can't just use gg->next because we're going to reverse the
4440 struct mips_elf_bfd2got_hash
*bfdgot
;
4443 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
4444 (abfd
, sizeof (struct mips_elf_bfd2got_hash
));
4451 bfdgotp
= htab_find_slot (gg
->bfd2got
, bfdgot
, INSERT
);
4453 BFD_ASSERT (*bfdgotp
== NULL
);
4457 /* Every symbol that is referenced in a dynamic relocation must be
4458 present in the primary GOT, so arrange for them to appear after
4459 those that are actually referenced. */
4460 gg
->reloc_only_gotno
= gg
->global_gotno
- g
->global_gotno
;
4461 g
->global_gotno
= gg
->global_gotno
;
4463 set_got_offset_arg
.g
= NULL
;
4464 set_got_offset_arg
.value
= GGA_RELOC_ONLY
;
4465 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_offset
,
4466 &set_got_offset_arg
);
4467 set_got_offset_arg
.value
= GGA_NORMAL
;
4468 htab_traverse (g
->got_entries
, mips_elf_set_global_got_offset
,
4469 &set_got_offset_arg
);
4471 /* Now go through the GOTs assigning them offset ranges.
4472 [assigned_gotno, local_gotno[ will be set to the range of local
4473 entries in each GOT. We can then compute the end of a GOT by
4474 adding local_gotno to global_gotno. We reverse the list and make
4475 it circular since then we'll be able to quickly compute the
4476 beginning of a GOT, by computing the end of its predecessor. To
4477 avoid special cases for the primary GOT, while still preserving
4478 assertions that are valid for both single- and multi-got links,
4479 we arrange for the main got struct to have the right number of
4480 global entries, but set its local_gotno such that the initial
4481 offset of the primary GOT is zero. Remember that the primary GOT
4482 will become the last item in the circular linked list, so it
4483 points back to the master GOT. */
4484 gg
->local_gotno
= -g
->global_gotno
;
4485 gg
->global_gotno
= g
->global_gotno
;
4492 struct mips_got_info
*gn
;
4494 assign
+= htab
->reserved_gotno
;
4495 g
->assigned_gotno
= assign
;
4496 g
->local_gotno
+= assign
;
4497 g
->local_gotno
+= (pages
< g
->page_gotno
? pages
: g
->page_gotno
);
4498 assign
= g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
;
4500 /* Take g out of the direct list, and push it onto the reversed
4501 list that gg points to. g->next is guaranteed to be nonnull after
4502 this operation, as required by mips_elf_initialize_tls_index. */
4507 /* Set up any TLS entries. We always place the TLS entries after
4508 all non-TLS entries. */
4509 g
->tls_assigned_gotno
= g
->local_gotno
+ g
->global_gotno
;
4510 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
4512 /* Move onto the next GOT. It will be a secondary GOT if nonull. */
4515 /* Forbid global symbols in every non-primary GOT from having
4516 lazy-binding stubs. */
4518 htab_traverse (g
->got_entries
, mips_elf_forbid_lazy_stubs
, info
);
4522 got
->size
= (gg
->next
->local_gotno
4523 + gg
->next
->global_gotno
4524 + gg
->next
->tls_gotno
) * MIPS_ELF_GOT_SIZE (abfd
);
4527 set_got_offset_arg
.value
= MIPS_ELF_GOT_SIZE (abfd
);
4528 set_got_offset_arg
.info
= info
;
4529 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
4531 unsigned int save_assign
;
4533 /* Assign offsets to global GOT entries. */
4534 save_assign
= g
->assigned_gotno
;
4535 g
->assigned_gotno
= g
->local_gotno
;
4536 set_got_offset_arg
.g
= g
;
4537 set_got_offset_arg
.needed_relocs
= 0;
4538 htab_traverse (g
->got_entries
,
4539 mips_elf_set_global_got_offset
,
4540 &set_got_offset_arg
);
4541 needed_relocs
+= set_got_offset_arg
.needed_relocs
;
4542 BFD_ASSERT (g
->assigned_gotno
- g
->local_gotno
<= g
->global_gotno
);
4544 g
->assigned_gotno
= save_assign
;
4547 needed_relocs
+= g
->local_gotno
- g
->assigned_gotno
;
4548 BFD_ASSERT (g
->assigned_gotno
== g
->next
->local_gotno
4549 + g
->next
->global_gotno
4550 + g
->next
->tls_gotno
4551 + htab
->reserved_gotno
);
4556 mips_elf_allocate_dynamic_relocations (dynobj
, info
,
4563 /* Returns the first relocation of type r_type found, beginning with
4564 RELOCATION. RELEND is one-past-the-end of the relocation table. */
4566 static const Elf_Internal_Rela
*
4567 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
4568 const Elf_Internal_Rela
*relocation
,
4569 const Elf_Internal_Rela
*relend
)
4571 unsigned long r_symndx
= ELF_R_SYM (abfd
, relocation
->r_info
);
4573 while (relocation
< relend
)
4575 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
4576 && ELF_R_SYM (abfd
, relocation
->r_info
) == r_symndx
)
4582 /* We didn't find it. */
4586 /* Return whether an input relocation is against a local symbol. */
4589 mips_elf_local_relocation_p (bfd
*input_bfd
,
4590 const Elf_Internal_Rela
*relocation
,
4591 asection
**local_sections
)
4593 unsigned long r_symndx
;
4594 Elf_Internal_Shdr
*symtab_hdr
;
4597 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4598 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4599 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
4601 if (r_symndx
< extsymoff
)
4603 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
4609 /* Sign-extend VALUE, which has the indicated number of BITS. */
4612 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
4614 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
4615 /* VALUE is negative. */
4616 value
|= ((bfd_vma
) - 1) << bits
;
4621 /* Return non-zero if the indicated VALUE has overflowed the maximum
4622 range expressible by a signed number with the indicated number of
4626 mips_elf_overflow_p (bfd_vma value
, int bits
)
4628 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
4630 if (svalue
> (1 << (bits
- 1)) - 1)
4631 /* The value is too big. */
4633 else if (svalue
< -(1 << (bits
- 1)))
4634 /* The value is too small. */
4641 /* Calculate the %high function. */
4644 mips_elf_high (bfd_vma value
)
4646 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
4649 /* Calculate the %higher function. */
4652 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
4655 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
4662 /* Calculate the %highest function. */
4665 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
4668 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
4675 /* Create the .compact_rel section. */
4678 mips_elf_create_compact_rel_section
4679 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4682 register asection
*s
;
4684 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4686 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
4689 s
= bfd_make_section_with_flags (abfd
, ".compact_rel", flags
);
4691 || ! bfd_set_section_alignment (abfd
, s
,
4692 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
4695 s
->size
= sizeof (Elf32_External_compact_rel
);
4701 /* Create the .got section to hold the global offset table. */
4704 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4707 register asection
*s
;
4708 struct elf_link_hash_entry
*h
;
4709 struct bfd_link_hash_entry
*bh
;
4710 struct mips_got_info
*g
;
4712 struct mips_elf_link_hash_table
*htab
;
4714 htab
= mips_elf_hash_table (info
);
4715 BFD_ASSERT (htab
!= NULL
);
4717 /* This function may be called more than once. */
4721 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4722 | SEC_LINKER_CREATED
);
4724 /* We have to use an alignment of 2**4 here because this is hardcoded
4725 in the function stub generation and in the linker script. */
4726 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
4728 || ! bfd_set_section_alignment (abfd
, s
, 4))
4732 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4733 linker script because we don't want to define the symbol if we
4734 are not creating a global offset table. */
4736 if (! (_bfd_generic_link_add_one_symbol
4737 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4738 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
4741 h
= (struct elf_link_hash_entry
*) bh
;
4744 h
->type
= STT_OBJECT
;
4745 elf_hash_table (info
)->hgot
= h
;
4748 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4751 amt
= sizeof (struct mips_got_info
);
4752 g
= bfd_alloc (abfd
, amt
);
4755 g
->global_gotsym
= NULL
;
4756 g
->global_gotno
= 0;
4757 g
->reloc_only_gotno
= 0;
4761 g
->assigned_gotno
= 0;
4764 g
->tls_ldm_offset
= MINUS_ONE
;
4765 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
4766 mips_elf_got_entry_eq
, NULL
);
4767 if (g
->got_entries
== NULL
)
4769 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4770 mips_got_page_entry_eq
, NULL
);
4771 if (g
->got_page_entries
== NULL
)
4774 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
4775 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
4777 /* We also need a .got.plt section when generating PLTs. */
4778 s
= bfd_make_section_with_flags (abfd
, ".got.plt",
4779 SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
4780 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4788 /* Return true if H refers to the special VxWorks __GOTT_BASE__ or
4789 __GOTT_INDEX__ symbols. These symbols are only special for
4790 shared objects; they are not used in executables. */
4793 is_gott_symbol (struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
)
4795 return (mips_elf_hash_table (info
)->is_vxworks
4797 && (strcmp (h
->root
.root
.string
, "__GOTT_BASE__") == 0
4798 || strcmp (h
->root
.root
.string
, "__GOTT_INDEX__") == 0));
4801 /* Return TRUE if a relocation of type R_TYPE from INPUT_BFD might
4802 require an la25 stub. See also mips_elf_local_pic_function_p,
4803 which determines whether the destination function ever requires a
4807 mips_elf_relocation_needs_la25_stub (bfd
*input_bfd
, int r_type
)
4809 /* We specifically ignore branches and jumps from EF_PIC objects,
4810 where the onus is on the compiler or programmer to perform any
4811 necessary initialization of $25. Sometimes such initialization
4812 is unnecessary; for example, -mno-shared functions do not use
4813 the incoming value of $25, and may therefore be called directly. */
4814 if (PIC_OBJECT_P (input_bfd
))
4829 /* Calculate the value produced by the RELOCATION (which comes from
4830 the INPUT_BFD). The ADDEND is the addend to use for this
4831 RELOCATION; RELOCATION->R_ADDEND is ignored.
4833 The result of the relocation calculation is stored in VALUEP.
4834 On exit, set *CROSS_MODE_JUMP_P to true if the relocation field
4835 is a MIPS16 jump to non-MIPS16 code, or vice versa.
4837 This function returns bfd_reloc_continue if the caller need take no
4838 further action regarding this relocation, bfd_reloc_notsupported if
4839 something goes dramatically wrong, bfd_reloc_overflow if an
4840 overflow occurs, and bfd_reloc_ok to indicate success. */
4842 static bfd_reloc_status_type
4843 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
4844 asection
*input_section
,
4845 struct bfd_link_info
*info
,
4846 const Elf_Internal_Rela
*relocation
,
4847 bfd_vma addend
, reloc_howto_type
*howto
,
4848 Elf_Internal_Sym
*local_syms
,
4849 asection
**local_sections
, bfd_vma
*valuep
,
4851 bfd_boolean
*cross_mode_jump_p
,
4852 bfd_boolean save_addend
)
4854 /* The eventual value we will return. */
4856 /* The address of the symbol against which the relocation is
4859 /* The final GP value to be used for the relocatable, executable, or
4860 shared object file being produced. */
4862 /* The place (section offset or address) of the storage unit being
4865 /* The value of GP used to create the relocatable object. */
4867 /* The offset into the global offset table at which the address of
4868 the relocation entry symbol, adjusted by the addend, resides
4869 during execution. */
4870 bfd_vma g
= MINUS_ONE
;
4871 /* The section in which the symbol referenced by the relocation is
4873 asection
*sec
= NULL
;
4874 struct mips_elf_link_hash_entry
*h
= NULL
;
4875 /* TRUE if the symbol referred to by this relocation is a local
4877 bfd_boolean local_p
, was_local_p
;
4878 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
4879 bfd_boolean gp_disp_p
= FALSE
;
4880 /* TRUE if the symbol referred to by this relocation is
4881 "__gnu_local_gp". */
4882 bfd_boolean gnu_local_gp_p
= FALSE
;
4883 Elf_Internal_Shdr
*symtab_hdr
;
4885 unsigned long r_symndx
;
4887 /* TRUE if overflow occurred during the calculation of the
4888 relocation value. */
4889 bfd_boolean overflowed_p
;
4890 /* TRUE if this relocation refers to a MIPS16 function. */
4891 bfd_boolean target_is_16_bit_code_p
= FALSE
;
4892 struct mips_elf_link_hash_table
*htab
;
4895 dynobj
= elf_hash_table (info
)->dynobj
;
4896 htab
= mips_elf_hash_table (info
);
4897 BFD_ASSERT (htab
!= NULL
);
4899 /* Parse the relocation. */
4900 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4901 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
4902 p
= (input_section
->output_section
->vma
4903 + input_section
->output_offset
4904 + relocation
->r_offset
);
4906 /* Assume that there will be no overflow. */
4907 overflowed_p
= FALSE
;
4909 /* Figure out whether or not the symbol is local, and get the offset
4910 used in the array of hash table entries. */
4911 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4912 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
4914 was_local_p
= local_p
;
4915 if (! elf_bad_symtab (input_bfd
))
4916 extsymoff
= symtab_hdr
->sh_info
;
4919 /* The symbol table does not follow the rule that local symbols
4920 must come before globals. */
4924 /* Figure out the value of the symbol. */
4927 Elf_Internal_Sym
*sym
;
4929 sym
= local_syms
+ r_symndx
;
4930 sec
= local_sections
[r_symndx
];
4932 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4933 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
4934 || (sec
->flags
& SEC_MERGE
))
4935 symbol
+= sym
->st_value
;
4936 if ((sec
->flags
& SEC_MERGE
)
4937 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4939 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
4941 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
4944 /* MIPS16 text labels should be treated as odd. */
4945 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
4948 /* Record the name of this symbol, for our caller. */
4949 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
4950 symtab_hdr
->sh_link
,
4953 *namep
= bfd_section_name (input_bfd
, sec
);
4955 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (sym
->st_other
);
4959 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
4961 /* For global symbols we look up the symbol in the hash-table. */
4962 h
= ((struct mips_elf_link_hash_entry
*)
4963 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
4964 /* Find the real hash-table entry for this symbol. */
4965 while (h
->root
.root
.type
== bfd_link_hash_indirect
4966 || h
->root
.root
.type
== bfd_link_hash_warning
)
4967 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4969 /* Record the name of this symbol, for our caller. */
4970 *namep
= h
->root
.root
.root
.string
;
4972 /* See if this is the special _gp_disp symbol. Note that such a
4973 symbol must always be a global symbol. */
4974 if (strcmp (*namep
, "_gp_disp") == 0
4975 && ! NEWABI_P (input_bfd
))
4977 /* Relocations against _gp_disp are permitted only with
4978 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
4979 if (!hi16_reloc_p (r_type
) && !lo16_reloc_p (r_type
))
4980 return bfd_reloc_notsupported
;
4984 /* See if this is the special _gp symbol. Note that such a
4985 symbol must always be a global symbol. */
4986 else if (strcmp (*namep
, "__gnu_local_gp") == 0)
4987 gnu_local_gp_p
= TRUE
;
4990 /* If this symbol is defined, calculate its address. Note that
4991 _gp_disp is a magic symbol, always implicitly defined by the
4992 linker, so it's inappropriate to check to see whether or not
4994 else if ((h
->root
.root
.type
== bfd_link_hash_defined
4995 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4996 && h
->root
.root
.u
.def
.section
)
4998 sec
= h
->root
.root
.u
.def
.section
;
4999 if (sec
->output_section
)
5000 symbol
= (h
->root
.root
.u
.def
.value
5001 + sec
->output_section
->vma
5002 + sec
->output_offset
);
5004 symbol
= h
->root
.root
.u
.def
.value
;
5006 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
5007 /* We allow relocations against undefined weak symbols, giving
5008 it the value zero, so that you can undefined weak functions
5009 and check to see if they exist by looking at their
5012 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
5013 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
5015 else if (strcmp (*namep
, SGI_COMPAT (input_bfd
)
5016 ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING") == 0)
5018 /* If this is a dynamic link, we should have created a
5019 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
5020 in in _bfd_mips_elf_create_dynamic_sections.
5021 Otherwise, we should define the symbol with a value of 0.
5022 FIXME: It should probably get into the symbol table
5024 BFD_ASSERT (! info
->shared
);
5025 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
5028 else if (ELF_MIPS_IS_OPTIONAL (h
->root
.other
))
5030 /* This is an optional symbol - an Irix specific extension to the
5031 ELF spec. Ignore it for now.
5032 XXX - FIXME - there is more to the spec for OPTIONAL symbols
5033 than simply ignoring them, but we do not handle this for now.
5034 For information see the "64-bit ELF Object File Specification"
5035 which is available from here:
5036 http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf */
5039 else if ((*info
->callbacks
->undefined_symbol
)
5040 (info
, h
->root
.root
.root
.string
, input_bfd
,
5041 input_section
, relocation
->r_offset
,
5042 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
5043 || ELF_ST_VISIBILITY (h
->root
.other
)))
5045 return bfd_reloc_undefined
;
5049 return bfd_reloc_notsupported
;
5052 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (h
->root
.other
);
5055 /* If this is a reference to a 16-bit function with a stub, we need
5056 to redirect the relocation to the stub unless:
5058 (a) the relocation is for a MIPS16 JAL;
5060 (b) the relocation is for a MIPS16 PIC call, and there are no
5061 non-MIPS16 uses of the GOT slot; or
5063 (c) the section allows direct references to MIPS16 functions. */
5064 if (r_type
!= R_MIPS16_26
5065 && !info
->relocatable
5067 && h
->fn_stub
!= NULL
5068 && (r_type
!= R_MIPS16_CALL16
|| h
->need_fn_stub
))
5070 && elf_tdata (input_bfd
)->local_stubs
!= NULL
5071 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5072 && !section_allows_mips16_refs_p (input_section
))
5074 /* This is a 32- or 64-bit call to a 16-bit function. We should
5075 have already noticed that we were going to need the
5078 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5081 BFD_ASSERT (h
->need_fn_stub
);
5085 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5086 /* The target is 16-bit, but the stub isn't. */
5087 target_is_16_bit_code_p
= FALSE
;
5089 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
5090 need to redirect the call to the stub. Note that we specifically
5091 exclude R_MIPS16_CALL16 from this behavior; indirect calls should
5092 use an indirect stub instead. */
5093 else if (r_type
== R_MIPS16_26
&& !info
->relocatable
5094 && ((h
!= NULL
&& (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
))
5096 && elf_tdata (input_bfd
)->local_call_stubs
!= NULL
5097 && elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
] != NULL
))
5098 && !target_is_16_bit_code_p
)
5101 sec
= elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
];
5104 /* If both call_stub and call_fp_stub are defined, we can figure
5105 out which one to use by checking which one appears in the input
5107 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
5112 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5114 if (CALL_FP_STUB_P (bfd_get_section_name (input_bfd
, o
)))
5116 sec
= h
->call_fp_stub
;
5123 else if (h
->call_stub
!= NULL
)
5126 sec
= h
->call_fp_stub
;
5129 BFD_ASSERT (sec
->size
> 0);
5130 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5132 /* If this is a direct call to a PIC function, redirect to the
5134 else if (h
!= NULL
&& h
->la25_stub
5135 && mips_elf_relocation_needs_la25_stub (input_bfd
, r_type
))
5136 symbol
= (h
->la25_stub
->stub_section
->output_section
->vma
5137 + h
->la25_stub
->stub_section
->output_offset
5138 + h
->la25_stub
->offset
);
5140 /* Calls from 16-bit code to 32-bit code and vice versa require the
5142 *cross_mode_jump_p
= !info
->relocatable
5143 && ((r_type
== R_MIPS16_26
&& !target_is_16_bit_code_p
)
5144 || ((r_type
== R_MIPS_26
|| r_type
== R_MIPS_JALR
)
5145 && target_is_16_bit_code_p
));
5147 local_p
= h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->root
);
5149 gp0
= _bfd_get_gp_value (input_bfd
);
5150 gp
= _bfd_get_gp_value (abfd
);
5152 gp
+= mips_elf_adjust_gp (abfd
, htab
->got_info
, input_bfd
);
5157 /* Global R_MIPS_GOT_PAGE relocations are equivalent to R_MIPS_GOT_DISP.
5158 The addend is applied by the corresponding R_MIPS_GOT_OFST. */
5159 if (r_type
== R_MIPS_GOT_PAGE
&& !local_p
)
5161 r_type
= R_MIPS_GOT_DISP
;
5165 /* If we haven't already determined the GOT offset, and we're going
5166 to need it, get it now. */
5169 case R_MIPS16_CALL16
:
5170 case R_MIPS16_GOT16
:
5173 case R_MIPS_GOT_DISP
:
5174 case R_MIPS_GOT_HI16
:
5175 case R_MIPS_CALL_HI16
:
5176 case R_MIPS_GOT_LO16
:
5177 case R_MIPS_CALL_LO16
:
5179 case R_MIPS_TLS_GOTTPREL
:
5180 case R_MIPS_TLS_LDM
:
5181 /* Find the index into the GOT where this value is located. */
5182 if (r_type
== R_MIPS_TLS_LDM
)
5184 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5185 0, 0, NULL
, r_type
);
5187 return bfd_reloc_outofrange
;
5191 /* On VxWorks, CALL relocations should refer to the .got.plt
5192 entry, which is initialized to point at the PLT stub. */
5193 if (htab
->is_vxworks
5194 && (r_type
== R_MIPS_CALL_HI16
5195 || r_type
== R_MIPS_CALL_LO16
5196 || call16_reloc_p (r_type
)))
5198 BFD_ASSERT (addend
== 0);
5199 BFD_ASSERT (h
->root
.needs_plt
);
5200 g
= mips_elf_gotplt_index (info
, &h
->root
);
5204 BFD_ASSERT (addend
== 0);
5205 g
= mips_elf_global_got_index (dynobj
, input_bfd
,
5206 &h
->root
, r_type
, info
);
5207 if (h
->tls_type
== GOT_NORMAL
5208 && !elf_hash_table (info
)->dynamic_sections_created
)
5209 /* This is a static link. We must initialize the GOT entry. */
5210 MIPS_ELF_PUT_WORD (dynobj
, symbol
, htab
->sgot
->contents
+ g
);
5213 else if (!htab
->is_vxworks
5214 && (call16_reloc_p (r_type
) || got16_reloc_p (r_type
)))
5215 /* The calculation below does not involve "g". */
5219 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5220 symbol
+ addend
, r_symndx
, h
, r_type
);
5222 return bfd_reloc_outofrange
;
5225 /* Convert GOT indices to actual offsets. */
5226 g
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, g
);
5230 /* Relocations against the VxWorks __GOTT_BASE__ and __GOTT_INDEX__
5231 symbols are resolved by the loader. Add them to .rela.dyn. */
5232 if (h
!= NULL
&& is_gott_symbol (info
, &h
->root
))
5234 Elf_Internal_Rela outrel
;
5238 s
= mips_elf_rel_dyn_section (info
, FALSE
);
5239 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5241 outrel
.r_offset
= (input_section
->output_section
->vma
5242 + input_section
->output_offset
5243 + relocation
->r_offset
);
5244 outrel
.r_info
= ELF32_R_INFO (h
->root
.dynindx
, r_type
);
5245 outrel
.r_addend
= addend
;
5246 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
5248 /* If we've written this relocation for a readonly section,
5249 we need to set DF_TEXTREL again, so that we do not delete the
5251 if (MIPS_ELF_READONLY_SECTION (input_section
))
5252 info
->flags
|= DF_TEXTREL
;
5255 return bfd_reloc_ok
;
5258 /* Figure out what kind of relocation is being performed. */
5262 return bfd_reloc_continue
;
5265 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 16);
5266 overflowed_p
= mips_elf_overflow_p (value
, 16);
5273 || (htab
->root
.dynamic_sections_created
5275 && h
->root
.def_dynamic
5276 && !h
->root
.def_regular
5277 && !h
->has_static_relocs
))
5278 && r_symndx
!= STN_UNDEF
5280 || h
->root
.root
.type
!= bfd_link_hash_undefweak
5281 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
5282 && (input_section
->flags
& SEC_ALLOC
) != 0)
5284 /* If we're creating a shared library, then we can't know
5285 where the symbol will end up. So, we create a relocation
5286 record in the output, and leave the job up to the dynamic
5287 linker. We must do the same for executable references to
5288 shared library symbols, unless we've decided to use copy
5289 relocs or PLTs instead. */
5291 if (!mips_elf_create_dynamic_relocation (abfd
,
5299 return bfd_reloc_undefined
;
5303 if (r_type
!= R_MIPS_REL32
)
5304 value
= symbol
+ addend
;
5308 value
&= howto
->dst_mask
;
5312 value
= symbol
+ addend
- p
;
5313 value
&= howto
->dst_mask
;
5317 /* The calculation for R_MIPS16_26 is just the same as for an
5318 R_MIPS_26. It's only the storage of the relocated field into
5319 the output file that's different. That's handled in
5320 mips_elf_perform_relocation. So, we just fall through to the
5321 R_MIPS_26 case here. */
5324 value
= ((addend
| ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
5327 value
= (_bfd_mips_elf_sign_extend (addend
, 28) + symbol
) >> 2;
5328 if (h
->root
.root
.type
!= bfd_link_hash_undefweak
)
5329 overflowed_p
= (value
>> 26) != ((p
+ 4) >> 28);
5331 value
&= howto
->dst_mask
;
5334 case R_MIPS_TLS_DTPREL_HI16
:
5335 value
= (mips_elf_high (addend
+ symbol
- dtprel_base (info
))
5339 case R_MIPS_TLS_DTPREL_LO16
:
5340 case R_MIPS_TLS_DTPREL32
:
5341 case R_MIPS_TLS_DTPREL64
:
5342 value
= (symbol
+ addend
- dtprel_base (info
)) & howto
->dst_mask
;
5345 case R_MIPS_TLS_TPREL_HI16
:
5346 value
= (mips_elf_high (addend
+ symbol
- tprel_base (info
))
5350 case R_MIPS_TLS_TPREL_LO16
:
5351 value
= (symbol
+ addend
- tprel_base (info
)) & howto
->dst_mask
;
5358 value
= mips_elf_high (addend
+ symbol
);
5359 value
&= howto
->dst_mask
;
5363 /* For MIPS16 ABI code we generate this sequence
5364 0: li $v0,%hi(_gp_disp)
5365 4: addiupc $v1,%lo(_gp_disp)
5369 So the offsets of hi and lo relocs are the same, but the
5370 $pc is four higher than $t9 would be, so reduce
5371 both reloc addends by 4. */
5372 if (r_type
== R_MIPS16_HI16
)
5373 value
= mips_elf_high (addend
+ gp
- p
- 4);
5375 value
= mips_elf_high (addend
+ gp
- p
);
5376 overflowed_p
= mips_elf_overflow_p (value
, 16);
5383 value
= (symbol
+ addend
) & howto
->dst_mask
;
5386 /* See the comment for R_MIPS16_HI16 above for the reason
5387 for this conditional. */
5388 if (r_type
== R_MIPS16_LO16
)
5389 value
= addend
+ gp
- p
;
5391 value
= addend
+ gp
- p
+ 4;
5392 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
5393 for overflow. But, on, say, IRIX5, relocations against
5394 _gp_disp are normally generated from the .cpload
5395 pseudo-op. It generates code that normally looks like
5398 lui $gp,%hi(_gp_disp)
5399 addiu $gp,$gp,%lo(_gp_disp)
5402 Here $t9 holds the address of the function being called,
5403 as required by the MIPS ELF ABI. The R_MIPS_LO16
5404 relocation can easily overflow in this situation, but the
5405 R_MIPS_HI16 relocation will handle the overflow.
5406 Therefore, we consider this a bug in the MIPS ABI, and do
5407 not check for overflow here. */
5411 case R_MIPS_LITERAL
:
5412 /* Because we don't merge literal sections, we can handle this
5413 just like R_MIPS_GPREL16. In the long run, we should merge
5414 shared literals, and then we will need to additional work
5419 case R_MIPS16_GPREL
:
5420 /* The R_MIPS16_GPREL performs the same calculation as
5421 R_MIPS_GPREL16, but stores the relocated bits in a different
5422 order. We don't need to do anything special here; the
5423 differences are handled in mips_elf_perform_relocation. */
5424 case R_MIPS_GPREL16
:
5425 /* Only sign-extend the addend if it was extracted from the
5426 instruction. If the addend was separate, leave it alone,
5427 otherwise we may lose significant bits. */
5428 if (howto
->partial_inplace
)
5429 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
5430 value
= symbol
+ addend
- gp
;
5431 /* If the symbol was local, any earlier relocatable links will
5432 have adjusted its addend with the gp offset, so compensate
5433 for that now. Don't do it for symbols forced local in this
5434 link, though, since they won't have had the gp offset applied
5438 overflowed_p
= mips_elf_overflow_p (value
, 16);
5441 case R_MIPS16_GOT16
:
5442 case R_MIPS16_CALL16
:
5445 /* VxWorks does not have separate local and global semantics for
5446 R_MIPS*_GOT16; every relocation evaluates to "G". */
5447 if (!htab
->is_vxworks
&& local_p
)
5449 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
,
5450 symbol
+ addend
, !was_local_p
);
5451 if (value
== MINUS_ONE
)
5452 return bfd_reloc_outofrange
;
5454 = mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
5455 overflowed_p
= mips_elf_overflow_p (value
, 16);
5462 case R_MIPS_TLS_GOTTPREL
:
5463 case R_MIPS_TLS_LDM
:
5464 case R_MIPS_GOT_DISP
:
5466 overflowed_p
= mips_elf_overflow_p (value
, 16);
5469 case R_MIPS_GPREL32
:
5470 value
= (addend
+ symbol
+ gp0
- gp
);
5472 value
&= howto
->dst_mask
;
5476 case R_MIPS_GNU_REL16_S2
:
5477 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 18) - p
;
5478 overflowed_p
= mips_elf_overflow_p (value
, 18);
5479 value
>>= howto
->rightshift
;
5480 value
&= howto
->dst_mask
;
5483 case R_MIPS_GOT_HI16
:
5484 case R_MIPS_CALL_HI16
:
5485 /* We're allowed to handle these two relocations identically.
5486 The dynamic linker is allowed to handle the CALL relocations
5487 differently by creating a lazy evaluation stub. */
5489 value
= mips_elf_high (value
);
5490 value
&= howto
->dst_mask
;
5493 case R_MIPS_GOT_LO16
:
5494 case R_MIPS_CALL_LO16
:
5495 value
= g
& howto
->dst_mask
;
5498 case R_MIPS_GOT_PAGE
:
5499 value
= mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, NULL
);
5500 if (value
== MINUS_ONE
)
5501 return bfd_reloc_outofrange
;
5502 value
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
5503 overflowed_p
= mips_elf_overflow_p (value
, 16);
5506 case R_MIPS_GOT_OFST
:
5508 mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, &value
);
5511 overflowed_p
= mips_elf_overflow_p (value
, 16);
5515 value
= symbol
- addend
;
5516 value
&= howto
->dst_mask
;
5520 value
= mips_elf_higher (addend
+ symbol
);
5521 value
&= howto
->dst_mask
;
5524 case R_MIPS_HIGHEST
:
5525 value
= mips_elf_highest (addend
+ symbol
);
5526 value
&= howto
->dst_mask
;
5529 case R_MIPS_SCN_DISP
:
5530 value
= symbol
+ addend
- sec
->output_offset
;
5531 value
&= howto
->dst_mask
;
5535 /* This relocation is only a hint. In some cases, we optimize
5536 it into a bal instruction. But we don't try to optimize
5537 when the symbol does not resolve locally. */
5538 if (h
!= NULL
&& !SYMBOL_CALLS_LOCAL (info
, &h
->root
))
5539 return bfd_reloc_continue
;
5540 value
= symbol
+ addend
;
5544 case R_MIPS_GNU_VTINHERIT
:
5545 case R_MIPS_GNU_VTENTRY
:
5546 /* We don't do anything with these at present. */
5547 return bfd_reloc_continue
;
5550 /* An unrecognized relocation type. */
5551 return bfd_reloc_notsupported
;
5554 /* Store the VALUE for our caller. */
5556 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
5559 /* Obtain the field relocated by RELOCATION. */
5562 mips_elf_obtain_contents (reloc_howto_type
*howto
,
5563 const Elf_Internal_Rela
*relocation
,
5564 bfd
*input_bfd
, bfd_byte
*contents
)
5567 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5569 /* Obtain the bytes. */
5570 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
5575 /* It has been determined that the result of the RELOCATION is the
5576 VALUE. Use HOWTO to place VALUE into the output file at the
5577 appropriate position. The SECTION is the section to which the
5579 CROSS_MODE_JUMP_P is true if the relocation field
5580 is a MIPS16 jump to non-MIPS16 code, or vice versa.
5582 Returns FALSE if anything goes wrong. */
5585 mips_elf_perform_relocation (struct bfd_link_info
*info
,
5586 reloc_howto_type
*howto
,
5587 const Elf_Internal_Rela
*relocation
,
5588 bfd_vma value
, bfd
*input_bfd
,
5589 asection
*input_section
, bfd_byte
*contents
,
5590 bfd_boolean cross_mode_jump_p
)
5594 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
5596 /* Figure out where the relocation is occurring. */
5597 location
= contents
+ relocation
->r_offset
;
5599 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
5601 /* Obtain the current value. */
5602 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
5604 /* Clear the field we are setting. */
5605 x
&= ~howto
->dst_mask
;
5607 /* Set the field. */
5608 x
|= (value
& howto
->dst_mask
);
5610 /* If required, turn JAL into JALX. */
5611 if (cross_mode_jump_p
&& jal_reloc_p (r_type
))
5614 bfd_vma opcode
= x
>> 26;
5615 bfd_vma jalx_opcode
;
5617 /* Check to see if the opcode is already JAL or JALX. */
5618 if (r_type
== R_MIPS16_26
)
5620 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
5625 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
5629 /* If the opcode is not JAL or JALX, there's a problem. */
5632 (*_bfd_error_handler
)
5633 (_("%B: %A+0x%lx: Direct jumps between ISA modes are not allowed; consider recompiling with interlinking enabled."),
5636 (unsigned long) relocation
->r_offset
);
5637 bfd_set_error (bfd_error_bad_value
);
5641 /* Make this the JALX opcode. */
5642 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
5645 /* Try converting JAL to BAL and J(AL)R to B(AL), if the target is in
5647 if (!info
->relocatable
5648 && !cross_mode_jump_p
5649 && ((JAL_TO_BAL_P (input_bfd
)
5650 && r_type
== R_MIPS_26
5651 && (x
>> 26) == 0x3) /* jal addr */
5652 || (JALR_TO_BAL_P (input_bfd
)
5653 && r_type
== R_MIPS_JALR
5654 && x
== 0x0320f809) /* jalr t9 */
5655 || (JR_TO_B_P (input_bfd
)
5656 && r_type
== R_MIPS_JALR
5657 && x
== 0x03200008))) /* jr t9 */
5663 addr
= (input_section
->output_section
->vma
5664 + input_section
->output_offset
5665 + relocation
->r_offset
5667 if (r_type
== R_MIPS_26
)
5668 dest
= (value
<< 2) | ((addr
>> 28) << 28);
5672 if (off
<= 0x1ffff && off
>= -0x20000)
5674 if (x
== 0x03200008) /* jr t9 */
5675 x
= 0x10000000 | (((bfd_vma
) off
>> 2) & 0xffff); /* b addr */
5677 x
= 0x04110000 | (((bfd_vma
) off
>> 2) & 0xffff); /* bal addr */
5681 /* Put the value into the output. */
5682 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
5684 _bfd_mips16_elf_reloc_shuffle(input_bfd
, r_type
, !info
->relocatable
,
5690 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
5691 is the original relocation, which is now being transformed into a
5692 dynamic relocation. The ADDENDP is adjusted if necessary; the
5693 caller should store the result in place of the original addend. */
5696 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
5697 struct bfd_link_info
*info
,
5698 const Elf_Internal_Rela
*rel
,
5699 struct mips_elf_link_hash_entry
*h
,
5700 asection
*sec
, bfd_vma symbol
,
5701 bfd_vma
*addendp
, asection
*input_section
)
5703 Elf_Internal_Rela outrel
[3];
5708 bfd_boolean defined_p
;
5709 struct mips_elf_link_hash_table
*htab
;
5711 htab
= mips_elf_hash_table (info
);
5712 BFD_ASSERT (htab
!= NULL
);
5714 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
5715 dynobj
= elf_hash_table (info
)->dynobj
;
5716 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
5717 BFD_ASSERT (sreloc
!= NULL
);
5718 BFD_ASSERT (sreloc
->contents
!= NULL
);
5719 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
5722 outrel
[0].r_offset
=
5723 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
5724 if (ABI_64_P (output_bfd
))
5726 outrel
[1].r_offset
=
5727 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
5728 outrel
[2].r_offset
=
5729 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
5732 if (outrel
[0].r_offset
== MINUS_ONE
)
5733 /* The relocation field has been deleted. */
5736 if (outrel
[0].r_offset
== MINUS_TWO
)
5738 /* The relocation field has been converted into a relative value of
5739 some sort. Functions like _bfd_elf_write_section_eh_frame expect
5740 the field to be fully relocated, so add in the symbol's value. */
5745 /* We must now calculate the dynamic symbol table index to use
5746 in the relocation. */
5747 if (h
!= NULL
&& ! SYMBOL_REFERENCES_LOCAL (info
, &h
->root
))
5749 BFD_ASSERT (htab
->is_vxworks
|| h
->global_got_area
!= GGA_NONE
);
5750 indx
= h
->root
.dynindx
;
5751 if (SGI_COMPAT (output_bfd
))
5752 defined_p
= h
->root
.def_regular
;
5754 /* ??? glibc's ld.so just adds the final GOT entry to the
5755 relocation field. It therefore treats relocs against
5756 defined symbols in the same way as relocs against
5757 undefined symbols. */
5762 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5764 else if (sec
== NULL
|| sec
->owner
== NULL
)
5766 bfd_set_error (bfd_error_bad_value
);
5771 indx
= elf_section_data (sec
->output_section
)->dynindx
;
5774 asection
*osec
= htab
->root
.text_index_section
;
5775 indx
= elf_section_data (osec
)->dynindx
;
5781 /* Instead of generating a relocation using the section
5782 symbol, we may as well make it a fully relative
5783 relocation. We want to avoid generating relocations to
5784 local symbols because we used to generate them
5785 incorrectly, without adding the original symbol value,
5786 which is mandated by the ABI for section symbols. In
5787 order to give dynamic loaders and applications time to
5788 phase out the incorrect use, we refrain from emitting
5789 section-relative relocations. It's not like they're
5790 useful, after all. This should be a bit more efficient
5792 /* ??? Although this behavior is compatible with glibc's ld.so,
5793 the ABI says that relocations against STN_UNDEF should have
5794 a symbol value of 0. Irix rld honors this, so relocations
5795 against STN_UNDEF have no effect. */
5796 if (!SGI_COMPAT (output_bfd
))
5801 /* If the relocation was previously an absolute relocation and
5802 this symbol will not be referred to by the relocation, we must
5803 adjust it by the value we give it in the dynamic symbol table.
5804 Otherwise leave the job up to the dynamic linker. */
5805 if (defined_p
&& r_type
!= R_MIPS_REL32
)
5808 if (htab
->is_vxworks
)
5809 /* VxWorks uses non-relative relocations for this. */
5810 outrel
[0].r_info
= ELF32_R_INFO (indx
, R_MIPS_32
);
5812 /* The relocation is always an REL32 relocation because we don't
5813 know where the shared library will wind up at load-time. */
5814 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
5817 /* For strict adherence to the ABI specification, we should
5818 generate a R_MIPS_64 relocation record by itself before the
5819 _REL32/_64 record as well, such that the addend is read in as
5820 a 64-bit value (REL32 is a 32-bit relocation, after all).
5821 However, since none of the existing ELF64 MIPS dynamic
5822 loaders seems to care, we don't waste space with these
5823 artificial relocations. If this turns out to not be true,
5824 mips_elf_allocate_dynamic_relocation() should be tweaked so
5825 as to make room for a pair of dynamic relocations per
5826 invocation if ABI_64_P, and here we should generate an
5827 additional relocation record with R_MIPS_64 by itself for a
5828 NULL symbol before this relocation record. */
5829 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
5830 ABI_64_P (output_bfd
)
5833 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
5835 /* Adjust the output offset of the relocation to reference the
5836 correct location in the output file. */
5837 outrel
[0].r_offset
+= (input_section
->output_section
->vma
5838 + input_section
->output_offset
);
5839 outrel
[1].r_offset
+= (input_section
->output_section
->vma
5840 + input_section
->output_offset
);
5841 outrel
[2].r_offset
+= (input_section
->output_section
->vma
5842 + input_section
->output_offset
);
5844 /* Put the relocation back out. We have to use the special
5845 relocation outputter in the 64-bit case since the 64-bit
5846 relocation format is non-standard. */
5847 if (ABI_64_P (output_bfd
))
5849 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
5850 (output_bfd
, &outrel
[0],
5852 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
5854 else if (htab
->is_vxworks
)
5856 /* VxWorks uses RELA rather than REL dynamic relocations. */
5857 outrel
[0].r_addend
= *addendp
;
5858 bfd_elf32_swap_reloca_out
5859 (output_bfd
, &outrel
[0],
5861 + sreloc
->reloc_count
* sizeof (Elf32_External_Rela
)));
5864 bfd_elf32_swap_reloc_out
5865 (output_bfd
, &outrel
[0],
5866 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
5868 /* We've now added another relocation. */
5869 ++sreloc
->reloc_count
;
5871 /* Make sure the output section is writable. The dynamic linker
5872 will be writing to it. */
5873 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5876 /* On IRIX5, make an entry of compact relocation info. */
5877 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
5879 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5884 Elf32_crinfo cptrel
;
5886 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5887 cptrel
.vaddr
= (rel
->r_offset
5888 + input_section
->output_section
->vma
5889 + input_section
->output_offset
);
5890 if (r_type
== R_MIPS_REL32
)
5891 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5893 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5894 mips_elf_set_cr_dist2to (cptrel
, 0);
5895 cptrel
.konst
= *addendp
;
5897 cr
= (scpt
->contents
5898 + sizeof (Elf32_External_compact_rel
));
5899 mips_elf_set_cr_relvaddr (cptrel
, 0);
5900 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5901 ((Elf32_External_crinfo
*) cr
5902 + scpt
->reloc_count
));
5903 ++scpt
->reloc_count
;
5907 /* If we've written this relocation for a readonly section,
5908 we need to set DF_TEXTREL again, so that we do not delete the
5910 if (MIPS_ELF_READONLY_SECTION (input_section
))
5911 info
->flags
|= DF_TEXTREL
;
5916 /* Return the MACH for a MIPS e_flags value. */
5919 _bfd_elf_mips_mach (flagword flags
)
5921 switch (flags
& EF_MIPS_MACH
)
5923 case E_MIPS_MACH_3900
:
5924 return bfd_mach_mips3900
;
5926 case E_MIPS_MACH_4010
:
5927 return bfd_mach_mips4010
;
5929 case E_MIPS_MACH_4100
:
5930 return bfd_mach_mips4100
;
5932 case E_MIPS_MACH_4111
:
5933 return bfd_mach_mips4111
;
5935 case E_MIPS_MACH_4120
:
5936 return bfd_mach_mips4120
;
5938 case E_MIPS_MACH_4650
:
5939 return bfd_mach_mips4650
;
5941 case E_MIPS_MACH_5400
:
5942 return bfd_mach_mips5400
;
5944 case E_MIPS_MACH_5500
:
5945 return bfd_mach_mips5500
;
5947 case E_MIPS_MACH_9000
:
5948 return bfd_mach_mips9000
;
5950 case E_MIPS_MACH_SB1
:
5951 return bfd_mach_mips_sb1
;
5953 case E_MIPS_MACH_LS2E
:
5954 return bfd_mach_mips_loongson_2e
;
5956 case E_MIPS_MACH_LS2F
:
5957 return bfd_mach_mips_loongson_2f
;
5959 case E_MIPS_MACH_LS3A
:
5960 return bfd_mach_mips_loongson_3a
;
5962 case E_MIPS_MACH_OCTEON
:
5963 return bfd_mach_mips_octeon
;
5965 case E_MIPS_MACH_XLR
:
5966 return bfd_mach_mips_xlr
;
5969 switch (flags
& EF_MIPS_ARCH
)
5973 return bfd_mach_mips3000
;
5976 return bfd_mach_mips6000
;
5979 return bfd_mach_mips4000
;
5982 return bfd_mach_mips8000
;
5985 return bfd_mach_mips5
;
5987 case E_MIPS_ARCH_32
:
5988 return bfd_mach_mipsisa32
;
5990 case E_MIPS_ARCH_64
:
5991 return bfd_mach_mipsisa64
;
5993 case E_MIPS_ARCH_32R2
:
5994 return bfd_mach_mipsisa32r2
;
5996 case E_MIPS_ARCH_64R2
:
5997 return bfd_mach_mipsisa64r2
;
6004 /* Return printable name for ABI. */
6006 static INLINE
char *
6007 elf_mips_abi_name (bfd
*abfd
)
6011 flags
= elf_elfheader (abfd
)->e_flags
;
6012 switch (flags
& EF_MIPS_ABI
)
6015 if (ABI_N32_P (abfd
))
6017 else if (ABI_64_P (abfd
))
6021 case E_MIPS_ABI_O32
:
6023 case E_MIPS_ABI_O64
:
6025 case E_MIPS_ABI_EABI32
:
6027 case E_MIPS_ABI_EABI64
:
6030 return "unknown abi";
6034 /* MIPS ELF uses two common sections. One is the usual one, and the
6035 other is for small objects. All the small objects are kept
6036 together, and then referenced via the gp pointer, which yields
6037 faster assembler code. This is what we use for the small common
6038 section. This approach is copied from ecoff.c. */
6039 static asection mips_elf_scom_section
;
6040 static asymbol mips_elf_scom_symbol
;
6041 static asymbol
*mips_elf_scom_symbol_ptr
;
6043 /* MIPS ELF also uses an acommon section, which represents an
6044 allocated common symbol which may be overridden by a
6045 definition in a shared library. */
6046 static asection mips_elf_acom_section
;
6047 static asymbol mips_elf_acom_symbol
;
6048 static asymbol
*mips_elf_acom_symbol_ptr
;
6050 /* This is used for both the 32-bit and the 64-bit ABI. */
6053 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
6055 elf_symbol_type
*elfsym
;
6057 /* Handle the special MIPS section numbers that a symbol may use. */
6058 elfsym
= (elf_symbol_type
*) asym
;
6059 switch (elfsym
->internal_elf_sym
.st_shndx
)
6061 case SHN_MIPS_ACOMMON
:
6062 /* This section is used in a dynamically linked executable file.
6063 It is an allocated common section. The dynamic linker can
6064 either resolve these symbols to something in a shared
6065 library, or it can just leave them here. For our purposes,
6066 we can consider these symbols to be in a new section. */
6067 if (mips_elf_acom_section
.name
== NULL
)
6069 /* Initialize the acommon section. */
6070 mips_elf_acom_section
.name
= ".acommon";
6071 mips_elf_acom_section
.flags
= SEC_ALLOC
;
6072 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
6073 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
6074 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
6075 mips_elf_acom_symbol
.name
= ".acommon";
6076 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
6077 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
6078 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
6080 asym
->section
= &mips_elf_acom_section
;
6084 /* Common symbols less than the GP size are automatically
6085 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
6086 if (asym
->value
> elf_gp_size (abfd
)
6087 || ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_TLS
6088 || IRIX_COMPAT (abfd
) == ict_irix6
)
6091 case SHN_MIPS_SCOMMON
:
6092 if (mips_elf_scom_section
.name
== NULL
)
6094 /* Initialize the small common section. */
6095 mips_elf_scom_section
.name
= ".scommon";
6096 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
6097 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
6098 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
6099 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
6100 mips_elf_scom_symbol
.name
= ".scommon";
6101 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
6102 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
6103 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
6105 asym
->section
= &mips_elf_scom_section
;
6106 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
6109 case SHN_MIPS_SUNDEFINED
:
6110 asym
->section
= bfd_und_section_ptr
;
6115 asection
*section
= bfd_get_section_by_name (abfd
, ".text");
6117 BFD_ASSERT (SGI_COMPAT (abfd
));
6118 if (section
!= NULL
)
6120 asym
->section
= section
;
6121 /* MIPS_TEXT is a bit special, the address is not an offset
6122 to the base of the .text section. So substract the section
6123 base address to make it an offset. */
6124 asym
->value
-= section
->vma
;
6131 asection
*section
= bfd_get_section_by_name (abfd
, ".data");
6133 BFD_ASSERT (SGI_COMPAT (abfd
));
6134 if (section
!= NULL
)
6136 asym
->section
= section
;
6137 /* MIPS_DATA is a bit special, the address is not an offset
6138 to the base of the .data section. So substract the section
6139 base address to make it an offset. */
6140 asym
->value
-= section
->vma
;
6146 /* If this is an odd-valued function symbol, assume it's a MIPS16 one. */
6147 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_FUNC
6148 && (asym
->value
& 1) != 0)
6151 elfsym
->internal_elf_sym
.st_other
6152 = ELF_ST_SET_MIPS16 (elfsym
->internal_elf_sym
.st_other
);
6156 /* Implement elf_backend_eh_frame_address_size. This differs from
6157 the default in the way it handles EABI64.
6159 EABI64 was originally specified as an LP64 ABI, and that is what
6160 -mabi=eabi normally gives on a 64-bit target. However, gcc has
6161 historically accepted the combination of -mabi=eabi and -mlong32,
6162 and this ILP32 variation has become semi-official over time.
6163 Both forms use elf32 and have pointer-sized FDE addresses.
6165 If an EABI object was generated by GCC 4.0 or above, it will have
6166 an empty .gcc_compiled_longXX section, where XX is the size of longs
6167 in bits. Unfortunately, ILP32 objects generated by earlier compilers
6168 have no special marking to distinguish them from LP64 objects.
6170 We don't want users of the official LP64 ABI to be punished for the
6171 existence of the ILP32 variant, but at the same time, we don't want
6172 to mistakenly interpret pre-4.0 ILP32 objects as being LP64 objects.
6173 We therefore take the following approach:
6175 - If ABFD contains a .gcc_compiled_longXX section, use it to
6176 determine the pointer size.
6178 - Otherwise check the type of the first relocation. Assume that
6179 the LP64 ABI is being used if the relocation is of type R_MIPS_64.
6183 The second check is enough to detect LP64 objects generated by pre-4.0
6184 compilers because, in the kind of output generated by those compilers,
6185 the first relocation will be associated with either a CIE personality
6186 routine or an FDE start address. Furthermore, the compilers never
6187 used a special (non-pointer) encoding for this ABI.
6189 Checking the relocation type should also be safe because there is no
6190 reason to use R_MIPS_64 in an ILP32 object. Pre-4.0 compilers never
6194 _bfd_mips_elf_eh_frame_address_size (bfd
*abfd
, asection
*sec
)
6196 if (elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
6198 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
6200 bfd_boolean long32_p
, long64_p
;
6202 long32_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long32") != 0;
6203 long64_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long64") != 0;
6204 if (long32_p
&& long64_p
)
6211 if (sec
->reloc_count
> 0
6212 && elf_section_data (sec
)->relocs
!= NULL
6213 && (ELF32_R_TYPE (elf_section_data (sec
)->relocs
[0].r_info
)
6222 /* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
6223 relocations against two unnamed section symbols to resolve to the
6224 same address. For example, if we have code like:
6226 lw $4,%got_disp(.data)($gp)
6227 lw $25,%got_disp(.text)($gp)
6230 then the linker will resolve both relocations to .data and the program
6231 will jump there rather than to .text.
6233 We can work around this problem by giving names to local section symbols.
6234 This is also what the MIPSpro tools do. */
6237 _bfd_mips_elf_name_local_section_symbols (bfd
*abfd
)
6239 return SGI_COMPAT (abfd
);
6242 /* Work over a section just before writing it out. This routine is
6243 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
6244 sections that need the SHF_MIPS_GPREL flag by name; there has to be
6248 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
6250 if (hdr
->sh_type
== SHT_MIPS_REGINFO
6251 && hdr
->sh_size
> 0)
6255 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
6256 BFD_ASSERT (hdr
->contents
== NULL
);
6259 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
6262 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
6263 if (bfd_bwrite (buf
, 4, abfd
) != 4)
6267 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
6268 && hdr
->bfd_section
!= NULL
6269 && mips_elf_section_data (hdr
->bfd_section
) != NULL
6270 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
6272 bfd_byte
*contents
, *l
, *lend
;
6274 /* We stored the section contents in the tdata field in the
6275 set_section_contents routine. We save the section contents
6276 so that we don't have to read them again.
6277 At this point we know that elf_gp is set, so we can look
6278 through the section contents to see if there is an
6279 ODK_REGINFO structure. */
6281 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
6283 lend
= contents
+ hdr
->sh_size
;
6284 while (l
+ sizeof (Elf_External_Options
) <= lend
)
6286 Elf_Internal_Options intopt
;
6288 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
6290 if (intopt
.size
< sizeof (Elf_External_Options
))
6292 (*_bfd_error_handler
)
6293 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
6294 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
6297 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
6304 + sizeof (Elf_External_Options
)
6305 + (sizeof (Elf64_External_RegInfo
) - 8)),
6308 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
6309 if (bfd_bwrite (buf
, 8, abfd
) != 8)
6312 else if (intopt
.kind
== ODK_REGINFO
)
6319 + sizeof (Elf_External_Options
)
6320 + (sizeof (Elf32_External_RegInfo
) - 4)),
6323 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
6324 if (bfd_bwrite (buf
, 4, abfd
) != 4)
6331 if (hdr
->bfd_section
!= NULL
)
6333 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
6335 /* .sbss is not handled specially here because the GNU/Linux
6336 prelinker can convert .sbss from NOBITS to PROGBITS and
6337 changing it back to NOBITS breaks the binary. The entry in
6338 _bfd_mips_elf_special_sections will ensure the correct flags
6339 are set on .sbss if BFD creates it without reading it from an
6340 input file, and without special handling here the flags set
6341 on it in an input file will be followed. */
6342 if (strcmp (name
, ".sdata") == 0
6343 || strcmp (name
, ".lit8") == 0
6344 || strcmp (name
, ".lit4") == 0)
6346 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
6347 hdr
->sh_type
= SHT_PROGBITS
;
6349 else if (strcmp (name
, ".srdata") == 0)
6351 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
6352 hdr
->sh_type
= SHT_PROGBITS
;
6354 else if (strcmp (name
, ".compact_rel") == 0)
6357 hdr
->sh_type
= SHT_PROGBITS
;
6359 else if (strcmp (name
, ".rtproc") == 0)
6361 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
6363 unsigned int adjust
;
6365 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
6367 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
6375 /* Handle a MIPS specific section when reading an object file. This
6376 is called when elfcode.h finds a section with an unknown type.
6377 This routine supports both the 32-bit and 64-bit ELF ABI.
6379 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
6383 _bfd_mips_elf_section_from_shdr (bfd
*abfd
,
6384 Elf_Internal_Shdr
*hdr
,
6390 /* There ought to be a place to keep ELF backend specific flags, but
6391 at the moment there isn't one. We just keep track of the
6392 sections by their name, instead. Fortunately, the ABI gives
6393 suggested names for all the MIPS specific sections, so we will
6394 probably get away with this. */
6395 switch (hdr
->sh_type
)
6397 case SHT_MIPS_LIBLIST
:
6398 if (strcmp (name
, ".liblist") != 0)
6402 if (strcmp (name
, ".msym") != 0)
6405 case SHT_MIPS_CONFLICT
:
6406 if (strcmp (name
, ".conflict") != 0)
6409 case SHT_MIPS_GPTAB
:
6410 if (! CONST_STRNEQ (name
, ".gptab."))
6413 case SHT_MIPS_UCODE
:
6414 if (strcmp (name
, ".ucode") != 0)
6417 case SHT_MIPS_DEBUG
:
6418 if (strcmp (name
, ".mdebug") != 0)
6420 flags
= SEC_DEBUGGING
;
6422 case SHT_MIPS_REGINFO
:
6423 if (strcmp (name
, ".reginfo") != 0
6424 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
6426 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
6428 case SHT_MIPS_IFACE
:
6429 if (strcmp (name
, ".MIPS.interfaces") != 0)
6432 case SHT_MIPS_CONTENT
:
6433 if (! CONST_STRNEQ (name
, ".MIPS.content"))
6436 case SHT_MIPS_OPTIONS
:
6437 if (!MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
6440 case SHT_MIPS_DWARF
:
6441 if (! CONST_STRNEQ (name
, ".debug_")
6442 && ! CONST_STRNEQ (name
, ".zdebug_"))
6445 case SHT_MIPS_SYMBOL_LIB
:
6446 if (strcmp (name
, ".MIPS.symlib") != 0)
6449 case SHT_MIPS_EVENTS
:
6450 if (! CONST_STRNEQ (name
, ".MIPS.events")
6451 && ! CONST_STRNEQ (name
, ".MIPS.post_rel"))
6458 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6463 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
6464 (bfd_get_section_flags (abfd
,
6470 /* FIXME: We should record sh_info for a .gptab section. */
6472 /* For a .reginfo section, set the gp value in the tdata information
6473 from the contents of this section. We need the gp value while
6474 processing relocs, so we just get it now. The .reginfo section
6475 is not used in the 64-bit MIPS ELF ABI. */
6476 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
6478 Elf32_External_RegInfo ext
;
6481 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
6482 &ext
, 0, sizeof ext
))
6484 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
6485 elf_gp (abfd
) = s
.ri_gp_value
;
6488 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
6489 set the gp value based on what we find. We may see both
6490 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
6491 they should agree. */
6492 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
6494 bfd_byte
*contents
, *l
, *lend
;
6496 contents
= bfd_malloc (hdr
->sh_size
);
6497 if (contents
== NULL
)
6499 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
6506 lend
= contents
+ hdr
->sh_size
;
6507 while (l
+ sizeof (Elf_External_Options
) <= lend
)
6509 Elf_Internal_Options intopt
;
6511 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
6513 if (intopt
.size
< sizeof (Elf_External_Options
))
6515 (*_bfd_error_handler
)
6516 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
6517 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
6520 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
6522 Elf64_Internal_RegInfo intreg
;
6524 bfd_mips_elf64_swap_reginfo_in
6526 ((Elf64_External_RegInfo
*)
6527 (l
+ sizeof (Elf_External_Options
))),
6529 elf_gp (abfd
) = intreg
.ri_gp_value
;
6531 else if (intopt
.kind
== ODK_REGINFO
)
6533 Elf32_RegInfo intreg
;
6535 bfd_mips_elf32_swap_reginfo_in
6537 ((Elf32_External_RegInfo
*)
6538 (l
+ sizeof (Elf_External_Options
))),
6540 elf_gp (abfd
) = intreg
.ri_gp_value
;
6550 /* Set the correct type for a MIPS ELF section. We do this by the
6551 section name, which is a hack, but ought to work. This routine is
6552 used by both the 32-bit and the 64-bit ABI. */
6555 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
6557 const char *name
= bfd_get_section_name (abfd
, sec
);
6559 if (strcmp (name
, ".liblist") == 0)
6561 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
6562 hdr
->sh_info
= sec
->size
/ sizeof (Elf32_Lib
);
6563 /* The sh_link field is set in final_write_processing. */
6565 else if (strcmp (name
, ".conflict") == 0)
6566 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
6567 else if (CONST_STRNEQ (name
, ".gptab."))
6569 hdr
->sh_type
= SHT_MIPS_GPTAB
;
6570 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
6571 /* The sh_info field is set in final_write_processing. */
6573 else if (strcmp (name
, ".ucode") == 0)
6574 hdr
->sh_type
= SHT_MIPS_UCODE
;
6575 else if (strcmp (name
, ".mdebug") == 0)
6577 hdr
->sh_type
= SHT_MIPS_DEBUG
;
6578 /* In a shared object on IRIX 5.3, the .mdebug section has an
6579 entsize of 0. FIXME: Does this matter? */
6580 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
6581 hdr
->sh_entsize
= 0;
6583 hdr
->sh_entsize
= 1;
6585 else if (strcmp (name
, ".reginfo") == 0)
6587 hdr
->sh_type
= SHT_MIPS_REGINFO
;
6588 /* In a shared object on IRIX 5.3, the .reginfo section has an
6589 entsize of 0x18. FIXME: Does this matter? */
6590 if (SGI_COMPAT (abfd
))
6592 if ((abfd
->flags
& DYNAMIC
) != 0)
6593 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6595 hdr
->sh_entsize
= 1;
6598 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6600 else if (SGI_COMPAT (abfd
)
6601 && (strcmp (name
, ".hash") == 0
6602 || strcmp (name
, ".dynamic") == 0
6603 || strcmp (name
, ".dynstr") == 0))
6605 if (SGI_COMPAT (abfd
))
6606 hdr
->sh_entsize
= 0;
6608 /* This isn't how the IRIX6 linker behaves. */
6609 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6612 else if (strcmp (name
, ".got") == 0
6613 || strcmp (name
, ".srdata") == 0
6614 || strcmp (name
, ".sdata") == 0
6615 || strcmp (name
, ".sbss") == 0
6616 || strcmp (name
, ".lit4") == 0
6617 || strcmp (name
, ".lit8") == 0)
6618 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
6619 else if (strcmp (name
, ".MIPS.interfaces") == 0)
6621 hdr
->sh_type
= SHT_MIPS_IFACE
;
6622 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6624 else if (CONST_STRNEQ (name
, ".MIPS.content"))
6626 hdr
->sh_type
= SHT_MIPS_CONTENT
;
6627 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6628 /* The sh_info field is set in final_write_processing. */
6630 else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
6632 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
6633 hdr
->sh_entsize
= 1;
6634 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6636 else if (CONST_STRNEQ (name
, ".debug_")
6637 || CONST_STRNEQ (name
, ".zdebug_"))
6639 hdr
->sh_type
= SHT_MIPS_DWARF
;
6641 /* Irix facilities such as libexc expect a single .debug_frame
6642 per executable, the system ones have NOSTRIP set and the linker
6643 doesn't merge sections with different flags so ... */
6644 if (SGI_COMPAT (abfd
) && CONST_STRNEQ (name
, ".debug_frame"))
6645 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6647 else if (strcmp (name
, ".MIPS.symlib") == 0)
6649 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
6650 /* The sh_link and sh_info fields are set in
6651 final_write_processing. */
6653 else if (CONST_STRNEQ (name
, ".MIPS.events")
6654 || CONST_STRNEQ (name
, ".MIPS.post_rel"))
6656 hdr
->sh_type
= SHT_MIPS_EVENTS
;
6657 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6658 /* The sh_link field is set in final_write_processing. */
6660 else if (strcmp (name
, ".msym") == 0)
6662 hdr
->sh_type
= SHT_MIPS_MSYM
;
6663 hdr
->sh_flags
|= SHF_ALLOC
;
6664 hdr
->sh_entsize
= 8;
6667 /* The generic elf_fake_sections will set up REL_HDR using the default
6668 kind of relocations. We used to set up a second header for the
6669 non-default kind of relocations here, but only NewABI would use
6670 these, and the IRIX ld doesn't like resulting empty RELA sections.
6671 Thus we create those header only on demand now. */
6676 /* Given a BFD section, try to locate the corresponding ELF section
6677 index. This is used by both the 32-bit and the 64-bit ABI.
6678 Actually, it's not clear to me that the 64-bit ABI supports these,
6679 but for non-PIC objects we will certainly want support for at least
6680 the .scommon section. */
6683 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6684 asection
*sec
, int *retval
)
6686 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
6688 *retval
= SHN_MIPS_SCOMMON
;
6691 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
6693 *retval
= SHN_MIPS_ACOMMON
;
6699 /* Hook called by the linker routine which adds symbols from an object
6700 file. We must handle the special MIPS section numbers here. */
6703 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
6704 Elf_Internal_Sym
*sym
, const char **namep
,
6705 flagword
*flagsp ATTRIBUTE_UNUSED
,
6706 asection
**secp
, bfd_vma
*valp
)
6708 if (SGI_COMPAT (abfd
)
6709 && (abfd
->flags
& DYNAMIC
) != 0
6710 && strcmp (*namep
, "_rld_new_interface") == 0)
6712 /* Skip IRIX5 rld entry name. */
6717 /* Shared objects may have a dynamic symbol '_gp_disp' defined as
6718 a SECTION *ABS*. This causes ld to think it can resolve _gp_disp
6719 by setting a DT_NEEDED for the shared object. Since _gp_disp is
6720 a magic symbol resolved by the linker, we ignore this bogus definition
6721 of _gp_disp. New ABI objects do not suffer from this problem so this
6722 is not done for them. */
6724 && (sym
->st_shndx
== SHN_ABS
)
6725 && (strcmp (*namep
, "_gp_disp") == 0))
6731 switch (sym
->st_shndx
)
6734 /* Common symbols less than the GP size are automatically
6735 treated as SHN_MIPS_SCOMMON symbols. */
6736 if (sym
->st_size
> elf_gp_size (abfd
)
6737 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
6738 || IRIX_COMPAT (abfd
) == ict_irix6
)
6741 case SHN_MIPS_SCOMMON
:
6742 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
6743 (*secp
)->flags
|= SEC_IS_COMMON
;
6744 *valp
= sym
->st_size
;
6748 /* This section is used in a shared object. */
6749 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
6751 asymbol
*elf_text_symbol
;
6752 asection
*elf_text_section
;
6753 bfd_size_type amt
= sizeof (asection
);
6755 elf_text_section
= bfd_zalloc (abfd
, amt
);
6756 if (elf_text_section
== NULL
)
6759 amt
= sizeof (asymbol
);
6760 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
6761 if (elf_text_symbol
== NULL
)
6764 /* Initialize the section. */
6766 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
6767 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
6769 elf_text_section
->symbol
= elf_text_symbol
;
6770 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
6772 elf_text_section
->name
= ".text";
6773 elf_text_section
->flags
= SEC_NO_FLAGS
;
6774 elf_text_section
->output_section
= NULL
;
6775 elf_text_section
->owner
= abfd
;
6776 elf_text_symbol
->name
= ".text";
6777 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6778 elf_text_symbol
->section
= elf_text_section
;
6780 /* This code used to do *secp = bfd_und_section_ptr if
6781 info->shared. I don't know why, and that doesn't make sense,
6782 so I took it out. */
6783 *secp
= elf_tdata (abfd
)->elf_text_section
;
6786 case SHN_MIPS_ACOMMON
:
6787 /* Fall through. XXX Can we treat this as allocated data? */
6789 /* This section is used in a shared object. */
6790 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
6792 asymbol
*elf_data_symbol
;
6793 asection
*elf_data_section
;
6794 bfd_size_type amt
= sizeof (asection
);
6796 elf_data_section
= bfd_zalloc (abfd
, amt
);
6797 if (elf_data_section
== NULL
)
6800 amt
= sizeof (asymbol
);
6801 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
6802 if (elf_data_symbol
== NULL
)
6805 /* Initialize the section. */
6807 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
6808 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
6810 elf_data_section
->symbol
= elf_data_symbol
;
6811 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
6813 elf_data_section
->name
= ".data";
6814 elf_data_section
->flags
= SEC_NO_FLAGS
;
6815 elf_data_section
->output_section
= NULL
;
6816 elf_data_section
->owner
= abfd
;
6817 elf_data_symbol
->name
= ".data";
6818 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6819 elf_data_symbol
->section
= elf_data_section
;
6821 /* This code used to do *secp = bfd_und_section_ptr if
6822 info->shared. I don't know why, and that doesn't make sense,
6823 so I took it out. */
6824 *secp
= elf_tdata (abfd
)->elf_data_section
;
6827 case SHN_MIPS_SUNDEFINED
:
6828 *secp
= bfd_und_section_ptr
;
6832 if (SGI_COMPAT (abfd
)
6834 && info
->output_bfd
->xvec
== abfd
->xvec
6835 && strcmp (*namep
, "__rld_obj_head") == 0)
6837 struct elf_link_hash_entry
*h
;
6838 struct bfd_link_hash_entry
*bh
;
6840 /* Mark __rld_obj_head as dynamic. */
6842 if (! (_bfd_generic_link_add_one_symbol
6843 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
6844 get_elf_backend_data (abfd
)->collect
, &bh
)))
6847 h
= (struct elf_link_hash_entry
*) bh
;
6850 h
->type
= STT_OBJECT
;
6852 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6855 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
6858 /* If this is a mips16 text symbol, add 1 to the value to make it
6859 odd. This will cause something like .word SYM to come up with
6860 the right value when it is loaded into the PC. */
6861 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6867 /* This hook function is called before the linker writes out a global
6868 symbol. We mark symbols as small common if appropriate. This is
6869 also where we undo the increment of the value for a mips16 symbol. */
6872 _bfd_mips_elf_link_output_symbol_hook
6873 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6874 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
6875 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
6877 /* If we see a common symbol, which implies a relocatable link, then
6878 if a symbol was small common in an input file, mark it as small
6879 common in the output file. */
6880 if (sym
->st_shndx
== SHN_COMMON
6881 && strcmp (input_sec
->name
, ".scommon") == 0)
6882 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
6884 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6885 sym
->st_value
&= ~1;
6890 /* Functions for the dynamic linker. */
6892 /* Create dynamic sections when linking against a dynamic object. */
6895 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
6897 struct elf_link_hash_entry
*h
;
6898 struct bfd_link_hash_entry
*bh
;
6900 register asection
*s
;
6901 const char * const *namep
;
6902 struct mips_elf_link_hash_table
*htab
;
6904 htab
= mips_elf_hash_table (info
);
6905 BFD_ASSERT (htab
!= NULL
);
6907 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6908 | SEC_LINKER_CREATED
| SEC_READONLY
);
6910 /* The psABI requires a read-only .dynamic section, but the VxWorks
6912 if (!htab
->is_vxworks
)
6914 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6917 if (! bfd_set_section_flags (abfd
, s
, flags
))
6922 /* We need to create .got section. */
6923 if (!mips_elf_create_got_section (abfd
, info
))
6926 if (! mips_elf_rel_dyn_section (info
, TRUE
))
6929 /* Create .stub section. */
6930 s
= bfd_make_section_with_flags (abfd
,
6931 MIPS_ELF_STUB_SECTION_NAME (abfd
),
6934 || ! bfd_set_section_alignment (abfd
, s
,
6935 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6939 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
6941 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
6943 s
= bfd_make_section_with_flags (abfd
, ".rld_map",
6944 flags
&~ (flagword
) SEC_READONLY
);
6946 || ! bfd_set_section_alignment (abfd
, s
,
6947 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6951 /* On IRIX5, we adjust add some additional symbols and change the
6952 alignments of several sections. There is no ABI documentation
6953 indicating that this is necessary on IRIX6, nor any evidence that
6954 the linker takes such action. */
6955 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6957 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
6960 if (! (_bfd_generic_link_add_one_symbol
6961 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
6962 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6965 h
= (struct elf_link_hash_entry
*) bh
;
6968 h
->type
= STT_SECTION
;
6970 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6974 /* We need to create a .compact_rel section. */
6975 if (SGI_COMPAT (abfd
))
6977 if (!mips_elf_create_compact_rel_section (abfd
, info
))
6981 /* Change alignments of some sections. */
6982 s
= bfd_get_section_by_name (abfd
, ".hash");
6984 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6985 s
= bfd_get_section_by_name (abfd
, ".dynsym");
6987 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6988 s
= bfd_get_section_by_name (abfd
, ".dynstr");
6990 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6991 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6993 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6994 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6996 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
7003 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
7005 if (!(_bfd_generic_link_add_one_symbol
7006 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
7007 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
7010 h
= (struct elf_link_hash_entry
*) bh
;
7013 h
->type
= STT_SECTION
;
7015 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7018 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
7020 /* __rld_map is a four byte word located in the .data section
7021 and is filled in by the rtld to contain a pointer to
7022 the _r_debug structure. Its symbol value will be set in
7023 _bfd_mips_elf_finish_dynamic_symbol. */
7024 s
= bfd_get_section_by_name (abfd
, ".rld_map");
7025 BFD_ASSERT (s
!= NULL
);
7027 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
7029 if (!(_bfd_generic_link_add_one_symbol
7030 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
7031 get_elf_backend_data (abfd
)->collect
, &bh
)))
7034 h
= (struct elf_link_hash_entry
*) bh
;
7037 h
->type
= STT_OBJECT
;
7039 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7044 /* Create the .plt, .rel(a).plt, .dynbss and .rel(a).bss sections.
7045 Also create the _PROCEDURE_LINKAGE_TABLE symbol. */
7046 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
7049 /* Cache the sections created above. */
7050 htab
->splt
= bfd_get_section_by_name (abfd
, ".plt");
7051 htab
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
7052 if (htab
->is_vxworks
)
7054 htab
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
7055 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
7058 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rel.plt");
7060 || (htab
->is_vxworks
&& !htab
->srelbss
&& !info
->shared
)
7065 if (htab
->is_vxworks
)
7067 /* Do the usual VxWorks handling. */
7068 if (!elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
7071 /* Work out the PLT sizes. */
7074 htab
->plt_header_size
7075 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt0_entry
);
7076 htab
->plt_entry_size
7077 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt_entry
);
7081 htab
->plt_header_size
7082 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt0_entry
);
7083 htab
->plt_entry_size
7084 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt_entry
);
7087 else if (!info
->shared
)
7089 /* All variants of the plt0 entry are the same size. */
7090 htab
->plt_header_size
= 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
);
7091 htab
->plt_entry_size
= 4 * ARRAY_SIZE (mips_exec_plt_entry
);
7097 /* Return true if relocation REL against section SEC is a REL rather than
7098 RELA relocation. RELOCS is the first relocation in the section and
7099 ABFD is the bfd that contains SEC. */
7102 mips_elf_rel_relocation_p (bfd
*abfd
, asection
*sec
,
7103 const Elf_Internal_Rela
*relocs
,
7104 const Elf_Internal_Rela
*rel
)
7106 Elf_Internal_Shdr
*rel_hdr
;
7107 const struct elf_backend_data
*bed
;
7109 /* To determine which flavor of relocation this is, we depend on the
7110 fact that the INPUT_SECTION's REL_HDR is read before RELA_HDR. */
7111 rel_hdr
= elf_section_data (sec
)->rel
.hdr
;
7112 if (rel_hdr
== NULL
)
7114 bed
= get_elf_backend_data (abfd
);
7115 return ((size_t) (rel
- relocs
)
7116 < NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
);
7119 /* Read the addend for REL relocation REL, which belongs to bfd ABFD.
7120 HOWTO is the relocation's howto and CONTENTS points to the contents
7121 of the section that REL is against. */
7124 mips_elf_read_rel_addend (bfd
*abfd
, const Elf_Internal_Rela
*rel
,
7125 reloc_howto_type
*howto
, bfd_byte
*contents
)
7128 unsigned int r_type
;
7131 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7132 location
= contents
+ rel
->r_offset
;
7134 /* Get the addend, which is stored in the input file. */
7135 _bfd_mips16_elf_reloc_unshuffle (abfd
, r_type
, FALSE
, location
);
7136 addend
= mips_elf_obtain_contents (howto
, rel
, abfd
, contents
);
7137 _bfd_mips16_elf_reloc_shuffle (abfd
, r_type
, FALSE
, location
);
7139 return addend
& howto
->src_mask
;
7142 /* REL is a relocation in ABFD that needs a partnering LO16 relocation
7143 and *ADDEND is the addend for REL itself. Look for the LO16 relocation
7144 and update *ADDEND with the final addend. Return true on success
7145 or false if the LO16 could not be found. RELEND is the exclusive
7146 upper bound on the relocations for REL's section. */
7149 mips_elf_add_lo16_rel_addend (bfd
*abfd
,
7150 const Elf_Internal_Rela
*rel
,
7151 const Elf_Internal_Rela
*relend
,
7152 bfd_byte
*contents
, bfd_vma
*addend
)
7154 unsigned int r_type
, lo16_type
;
7155 const Elf_Internal_Rela
*lo16_relocation
;
7156 reloc_howto_type
*lo16_howto
;
7159 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7160 if (mips16_reloc_p (r_type
))
7161 lo16_type
= R_MIPS16_LO16
;
7163 lo16_type
= R_MIPS_LO16
;
7165 /* The combined value is the sum of the HI16 addend, left-shifted by
7166 sixteen bits, and the LO16 addend, sign extended. (Usually, the
7167 code does a `lui' of the HI16 value, and then an `addiu' of the
7170 Scan ahead to find a matching LO16 relocation.
7172 According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
7173 be immediately following. However, for the IRIX6 ABI, the next
7174 relocation may be a composed relocation consisting of several
7175 relocations for the same address. In that case, the R_MIPS_LO16
7176 relocation may occur as one of these. We permit a similar
7177 extension in general, as that is useful for GCC.
7179 In some cases GCC dead code elimination removes the LO16 but keeps
7180 the corresponding HI16. This is strictly speaking a violation of
7181 the ABI but not immediately harmful. */
7182 lo16_relocation
= mips_elf_next_relocation (abfd
, lo16_type
, rel
, relend
);
7183 if (lo16_relocation
== NULL
)
7186 /* Obtain the addend kept there. */
7187 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, lo16_type
, FALSE
);
7188 l
= mips_elf_read_rel_addend (abfd
, lo16_relocation
, lo16_howto
, contents
);
7190 l
<<= lo16_howto
->rightshift
;
7191 l
= _bfd_mips_elf_sign_extend (l
, 16);
7198 /* Try to read the contents of section SEC in bfd ABFD. Return true and
7199 store the contents in *CONTENTS on success. Assume that *CONTENTS
7200 already holds the contents if it is nonull on entry. */
7203 mips_elf_get_section_contents (bfd
*abfd
, asection
*sec
, bfd_byte
**contents
)
7208 /* Get cached copy if it exists. */
7209 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
7211 *contents
= elf_section_data (sec
)->this_hdr
.contents
;
7215 return bfd_malloc_and_get_section (abfd
, sec
, contents
);
7218 /* Look through the relocs for a section during the first phase, and
7219 allocate space in the global offset table. */
7222 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
7223 asection
*sec
, const Elf_Internal_Rela
*relocs
)
7227 Elf_Internal_Shdr
*symtab_hdr
;
7228 struct elf_link_hash_entry
**sym_hashes
;
7230 const Elf_Internal_Rela
*rel
;
7231 const Elf_Internal_Rela
*rel_end
;
7233 const struct elf_backend_data
*bed
;
7234 struct mips_elf_link_hash_table
*htab
;
7237 reloc_howto_type
*howto
;
7239 if (info
->relocatable
)
7242 htab
= mips_elf_hash_table (info
);
7243 BFD_ASSERT (htab
!= NULL
);
7245 dynobj
= elf_hash_table (info
)->dynobj
;
7246 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7247 sym_hashes
= elf_sym_hashes (abfd
);
7248 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7250 bed
= get_elf_backend_data (abfd
);
7251 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
7253 /* Check for the mips16 stub sections. */
7255 name
= bfd_get_section_name (abfd
, sec
);
7256 if (FN_STUB_P (name
))
7258 unsigned long r_symndx
;
7260 /* Look at the relocation information to figure out which symbol
7263 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
7266 (*_bfd_error_handler
)
7267 (_("%B: Warning: cannot determine the target function for"
7268 " stub section `%s'"),
7270 bfd_set_error (bfd_error_bad_value
);
7274 if (r_symndx
< extsymoff
7275 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7279 /* This stub is for a local symbol. This stub will only be
7280 needed if there is some relocation in this BFD, other
7281 than a 16 bit function call, which refers to this symbol. */
7282 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
7284 Elf_Internal_Rela
*sec_relocs
;
7285 const Elf_Internal_Rela
*r
, *rend
;
7287 /* We can ignore stub sections when looking for relocs. */
7288 if ((o
->flags
& SEC_RELOC
) == 0
7289 || o
->reloc_count
== 0
7290 || section_allows_mips16_refs_p (o
))
7294 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
7296 if (sec_relocs
== NULL
)
7299 rend
= sec_relocs
+ o
->reloc_count
;
7300 for (r
= sec_relocs
; r
< rend
; r
++)
7301 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
7302 && !mips16_call_reloc_p (ELF_R_TYPE (abfd
, r
->r_info
)))
7305 if (elf_section_data (o
)->relocs
!= sec_relocs
)
7314 /* There is no non-call reloc for this stub, so we do
7315 not need it. Since this function is called before
7316 the linker maps input sections to output sections, we
7317 can easily discard it by setting the SEC_EXCLUDE
7319 sec
->flags
|= SEC_EXCLUDE
;
7323 /* Record this stub in an array of local symbol stubs for
7325 if (elf_tdata (abfd
)->local_stubs
== NULL
)
7327 unsigned long symcount
;
7331 if (elf_bad_symtab (abfd
))
7332 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
7334 symcount
= symtab_hdr
->sh_info
;
7335 amt
= symcount
* sizeof (asection
*);
7336 n
= bfd_zalloc (abfd
, amt
);
7339 elf_tdata (abfd
)->local_stubs
= n
;
7342 sec
->flags
|= SEC_KEEP
;
7343 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
7345 /* We don't need to set mips16_stubs_seen in this case.
7346 That flag is used to see whether we need to look through
7347 the global symbol table for stubs. We don't need to set
7348 it here, because we just have a local stub. */
7352 struct mips_elf_link_hash_entry
*h
;
7354 h
= ((struct mips_elf_link_hash_entry
*)
7355 sym_hashes
[r_symndx
- extsymoff
]);
7357 while (h
->root
.root
.type
== bfd_link_hash_indirect
7358 || h
->root
.root
.type
== bfd_link_hash_warning
)
7359 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
7361 /* H is the symbol this stub is for. */
7363 /* If we already have an appropriate stub for this function, we
7364 don't need another one, so we can discard this one. Since
7365 this function is called before the linker maps input sections
7366 to output sections, we can easily discard it by setting the
7367 SEC_EXCLUDE flag. */
7368 if (h
->fn_stub
!= NULL
)
7370 sec
->flags
|= SEC_EXCLUDE
;
7374 sec
->flags
|= SEC_KEEP
;
7376 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
7379 else if (CALL_STUB_P (name
) || CALL_FP_STUB_P (name
))
7381 unsigned long r_symndx
;
7382 struct mips_elf_link_hash_entry
*h
;
7385 /* Look at the relocation information to figure out which symbol
7388 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
7391 (*_bfd_error_handler
)
7392 (_("%B: Warning: cannot determine the target function for"
7393 " stub section `%s'"),
7395 bfd_set_error (bfd_error_bad_value
);
7399 if (r_symndx
< extsymoff
7400 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7404 /* This stub is for a local symbol. This stub will only be
7405 needed if there is some relocation (R_MIPS16_26) in this BFD
7406 that refers to this symbol. */
7407 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
7409 Elf_Internal_Rela
*sec_relocs
;
7410 const Elf_Internal_Rela
*r
, *rend
;
7412 /* We can ignore stub sections when looking for relocs. */
7413 if ((o
->flags
& SEC_RELOC
) == 0
7414 || o
->reloc_count
== 0
7415 || section_allows_mips16_refs_p (o
))
7419 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
7421 if (sec_relocs
== NULL
)
7424 rend
= sec_relocs
+ o
->reloc_count
;
7425 for (r
= sec_relocs
; r
< rend
; r
++)
7426 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
7427 && ELF_R_TYPE (abfd
, r
->r_info
) == R_MIPS16_26
)
7430 if (elf_section_data (o
)->relocs
!= sec_relocs
)
7439 /* There is no non-call reloc for this stub, so we do
7440 not need it. Since this function is called before
7441 the linker maps input sections to output sections, we
7442 can easily discard it by setting the SEC_EXCLUDE
7444 sec
->flags
|= SEC_EXCLUDE
;
7448 /* Record this stub in an array of local symbol call_stubs for
7450 if (elf_tdata (abfd
)->local_call_stubs
== NULL
)
7452 unsigned long symcount
;
7456 if (elf_bad_symtab (abfd
))
7457 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
7459 symcount
= symtab_hdr
->sh_info
;
7460 amt
= symcount
* sizeof (asection
*);
7461 n
= bfd_zalloc (abfd
, amt
);
7464 elf_tdata (abfd
)->local_call_stubs
= n
;
7467 sec
->flags
|= SEC_KEEP
;
7468 elf_tdata (abfd
)->local_call_stubs
[r_symndx
] = sec
;
7470 /* We don't need to set mips16_stubs_seen in this case.
7471 That flag is used to see whether we need to look through
7472 the global symbol table for stubs. We don't need to set
7473 it here, because we just have a local stub. */
7477 h
= ((struct mips_elf_link_hash_entry
*)
7478 sym_hashes
[r_symndx
- extsymoff
]);
7480 /* H is the symbol this stub is for. */
7482 if (CALL_FP_STUB_P (name
))
7483 loc
= &h
->call_fp_stub
;
7485 loc
= &h
->call_stub
;
7487 /* If we already have an appropriate stub for this function, we
7488 don't need another one, so we can discard this one. Since
7489 this function is called before the linker maps input sections
7490 to output sections, we can easily discard it by setting the
7491 SEC_EXCLUDE flag. */
7494 sec
->flags
|= SEC_EXCLUDE
;
7498 sec
->flags
|= SEC_KEEP
;
7500 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
7506 for (rel
= relocs
; rel
< rel_end
; ++rel
)
7508 unsigned long r_symndx
;
7509 unsigned int r_type
;
7510 struct elf_link_hash_entry
*h
;
7511 bfd_boolean can_make_dynamic_p
;
7513 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
7514 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7516 if (r_symndx
< extsymoff
)
7518 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
7520 (*_bfd_error_handler
)
7521 (_("%B: Malformed reloc detected for section %s"),
7523 bfd_set_error (bfd_error_bad_value
);
7528 h
= sym_hashes
[r_symndx
- extsymoff
];
7530 && (h
->root
.type
== bfd_link_hash_indirect
7531 || h
->root
.type
== bfd_link_hash_warning
))
7532 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7535 /* Set CAN_MAKE_DYNAMIC_P to true if we can convert this
7536 relocation into a dynamic one. */
7537 can_make_dynamic_p
= FALSE
;
7540 case R_MIPS16_GOT16
:
7541 case R_MIPS16_CALL16
:
7544 case R_MIPS_CALL_HI16
:
7545 case R_MIPS_CALL_LO16
:
7546 case R_MIPS_GOT_HI16
:
7547 case R_MIPS_GOT_LO16
:
7548 case R_MIPS_GOT_PAGE
:
7549 case R_MIPS_GOT_OFST
:
7550 case R_MIPS_GOT_DISP
:
7551 case R_MIPS_TLS_GOTTPREL
:
7553 case R_MIPS_TLS_LDM
:
7555 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7556 if (!mips_elf_create_got_section (dynobj
, info
))
7558 if (htab
->is_vxworks
&& !info
->shared
)
7560 (*_bfd_error_handler
)
7561 (_("%B: GOT reloc at 0x%lx not expected in executables"),
7562 abfd
, (unsigned long) rel
->r_offset
);
7563 bfd_set_error (bfd_error_bad_value
);
7568 /* This is just a hint; it can safely be ignored. Don't set
7569 has_static_relocs for the corresponding symbol. */
7576 /* In VxWorks executables, references to external symbols
7577 must be handled using copy relocs or PLT entries; it is not
7578 possible to convert this relocation into a dynamic one.
7580 For executables that use PLTs and copy-relocs, we have a
7581 choice between converting the relocation into a dynamic
7582 one or using copy relocations or PLT entries. It is
7583 usually better to do the former, unless the relocation is
7584 against a read-only section. */
7587 && !htab
->is_vxworks
7588 && strcmp (h
->root
.root
.string
, "__gnu_local_gp") != 0
7589 && !(!info
->nocopyreloc
7590 && !PIC_OBJECT_P (abfd
)
7591 && MIPS_ELF_READONLY_SECTION (sec
))))
7592 && (sec
->flags
& SEC_ALLOC
) != 0)
7594 can_make_dynamic_p
= TRUE
;
7596 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7599 /* For sections that are not SEC_ALLOC a copy reloc would be
7600 output if possible (implying questionable semantics for
7601 read-only data objects) or otherwise the final link would
7602 fail as ld.so will not process them and could not therefore
7603 handle any outstanding dynamic relocations.
7605 For such sections that are also SEC_DEBUGGING, we can avoid
7606 these problems by simply ignoring any relocs as these
7607 sections have a predefined use and we know it is safe to do
7610 This is needed in cases such as a global symbol definition
7611 in a shared library causing a common symbol from an object
7612 file to be converted to an undefined reference. If that
7613 happens, then all the relocations against this symbol from
7614 SEC_DEBUGGING sections in the object file will resolve to
7616 if ((sec
->flags
& SEC_DEBUGGING
) != 0)
7621 /* Most static relocations require pointer equality, except
7624 h
->pointer_equality_needed
= TRUE
;
7631 ((struct mips_elf_link_hash_entry
*) h
)->has_static_relocs
= TRUE
;
7637 /* Relocations against the special VxWorks __GOTT_BASE__ and
7638 __GOTT_INDEX__ symbols must be left to the loader. Allocate
7639 room for them in .rela.dyn. */
7640 if (is_gott_symbol (info
, h
))
7644 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7648 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7649 if (MIPS_ELF_READONLY_SECTION (sec
))
7650 /* We tell the dynamic linker that there are
7651 relocations against the text segment. */
7652 info
->flags
|= DF_TEXTREL
;
7655 else if (r_type
== R_MIPS_CALL_LO16
7656 || r_type
== R_MIPS_GOT_LO16
7657 || r_type
== R_MIPS_GOT_DISP
7658 || (got16_reloc_p (r_type
) && htab
->is_vxworks
))
7660 /* We may need a local GOT entry for this relocation. We
7661 don't count R_MIPS_GOT_PAGE because we can estimate the
7662 maximum number of pages needed by looking at the size of
7663 the segment. Similar comments apply to R_MIPS*_GOT16 and
7664 R_MIPS*_CALL16, except on VxWorks, where GOT relocations
7665 always evaluate to "G". We don't count R_MIPS_GOT_HI16, or
7666 R_MIPS_CALL_HI16 because these are always followed by an
7667 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
7668 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7669 rel
->r_addend
, info
, 0))
7673 if (h
!= NULL
&& mips_elf_relocation_needs_la25_stub (abfd
, r_type
))
7674 ((struct mips_elf_link_hash_entry
*) h
)->has_nonpic_branches
= TRUE
;
7679 case R_MIPS16_CALL16
:
7682 (*_bfd_error_handler
)
7683 (_("%B: CALL16 reloc at 0x%lx not against global symbol"),
7684 abfd
, (unsigned long) rel
->r_offset
);
7685 bfd_set_error (bfd_error_bad_value
);
7690 case R_MIPS_CALL_HI16
:
7691 case R_MIPS_CALL_LO16
:
7694 /* Make sure there is room in the regular GOT to hold the
7695 function's address. We may eliminate it in favour of
7696 a .got.plt entry later; see mips_elf_count_got_symbols. */
7697 if (!mips_elf_record_global_got_symbol (h
, abfd
, info
, TRUE
, 0))
7700 /* We need a stub, not a plt entry for the undefined
7701 function. But we record it as if it needs plt. See
7702 _bfd_elf_adjust_dynamic_symbol. */
7708 case R_MIPS_GOT_PAGE
:
7709 /* If this is a global, overridable symbol, GOT_PAGE will
7710 decay to GOT_DISP, so we'll need a GOT entry for it. */
7713 struct mips_elf_link_hash_entry
*hmips
=
7714 (struct mips_elf_link_hash_entry
*) h
;
7716 /* This symbol is definitely not overridable. */
7717 if (hmips
->root
.def_regular
7718 && ! (info
->shared
&& ! info
->symbolic
7719 && ! hmips
->root
.forced_local
))
7724 case R_MIPS16_GOT16
:
7726 case R_MIPS_GOT_HI16
:
7727 case R_MIPS_GOT_LO16
:
7728 if (!h
|| r_type
== R_MIPS_GOT_PAGE
)
7730 /* This relocation needs (or may need, if h != NULL) a
7731 page entry in the GOT. For R_MIPS_GOT_PAGE we do not
7732 know for sure until we know whether the symbol is
7734 if (mips_elf_rel_relocation_p (abfd
, sec
, relocs
, rel
))
7736 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
7738 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
7739 addend
= mips_elf_read_rel_addend (abfd
, rel
,
7741 if (got16_reloc_p (r_type
))
7742 mips_elf_add_lo16_rel_addend (abfd
, rel
, rel_end
,
7745 addend
<<= howto
->rightshift
;
7748 addend
= rel
->r_addend
;
7749 if (!mips_elf_record_got_page_entry (info
, abfd
, r_symndx
,
7755 case R_MIPS_GOT_DISP
:
7756 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
, info
,
7761 case R_MIPS_TLS_GOTTPREL
:
7763 info
->flags
|= DF_STATIC_TLS
;
7766 case R_MIPS_TLS_LDM
:
7767 if (r_type
== R_MIPS_TLS_LDM
)
7769 r_symndx
= STN_UNDEF
;
7775 /* This symbol requires a global offset table entry, or two
7776 for TLS GD relocations. */
7778 unsigned char flag
= (r_type
== R_MIPS_TLS_GD
7780 : r_type
== R_MIPS_TLS_LDM
7785 struct mips_elf_link_hash_entry
*hmips
=
7786 (struct mips_elf_link_hash_entry
*) h
;
7787 hmips
->tls_type
|= flag
;
7789 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
, info
,
7795 BFD_ASSERT (flag
== GOT_TLS_LDM
|| r_symndx
!= STN_UNDEF
);
7797 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7808 /* In VxWorks executables, references to external symbols
7809 are handled using copy relocs or PLT stubs, so there's
7810 no need to add a .rela.dyn entry for this relocation. */
7811 if (can_make_dynamic_p
)
7815 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7819 if (info
->shared
&& h
== NULL
)
7821 /* When creating a shared object, we must copy these
7822 reloc types into the output file as R_MIPS_REL32
7823 relocs. Make room for this reloc in .rel(a).dyn. */
7824 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7825 if (MIPS_ELF_READONLY_SECTION (sec
))
7826 /* We tell the dynamic linker that there are
7827 relocations against the text segment. */
7828 info
->flags
|= DF_TEXTREL
;
7832 struct mips_elf_link_hash_entry
*hmips
;
7834 /* For a shared object, we must copy this relocation
7835 unless the symbol turns out to be undefined and
7836 weak with non-default visibility, in which case
7837 it will be left as zero.
7839 We could elide R_MIPS_REL32 for locally binding symbols
7840 in shared libraries, but do not yet do so.
7842 For an executable, we only need to copy this
7843 reloc if the symbol is defined in a dynamic
7845 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7846 ++hmips
->possibly_dynamic_relocs
;
7847 if (MIPS_ELF_READONLY_SECTION (sec
))
7848 /* We need it to tell the dynamic linker if there
7849 are relocations against the text segment. */
7850 hmips
->readonly_reloc
= TRUE
;
7854 if (SGI_COMPAT (abfd
))
7855 mips_elf_hash_table (info
)->compact_rel_size
+=
7856 sizeof (Elf32_External_crinfo
);
7860 case R_MIPS_GPREL16
:
7861 case R_MIPS_LITERAL
:
7862 case R_MIPS_GPREL32
:
7863 if (SGI_COMPAT (abfd
))
7864 mips_elf_hash_table (info
)->compact_rel_size
+=
7865 sizeof (Elf32_External_crinfo
);
7868 /* This relocation describes the C++ object vtable hierarchy.
7869 Reconstruct it for later use during GC. */
7870 case R_MIPS_GNU_VTINHERIT
:
7871 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7875 /* This relocation describes which C++ vtable entries are actually
7876 used. Record for later use during GC. */
7877 case R_MIPS_GNU_VTENTRY
:
7878 BFD_ASSERT (h
!= NULL
);
7880 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7888 /* We must not create a stub for a symbol that has relocations
7889 related to taking the function's address. This doesn't apply to
7890 VxWorks, where CALL relocs refer to a .got.plt entry instead of
7891 a normal .got entry. */
7892 if (!htab
->is_vxworks
&& h
!= NULL
)
7896 ((struct mips_elf_link_hash_entry
*) h
)->no_fn_stub
= TRUE
;
7898 case R_MIPS16_CALL16
:
7900 case R_MIPS_CALL_HI16
:
7901 case R_MIPS_CALL_LO16
:
7906 /* See if this reloc would need to refer to a MIPS16 hard-float stub,
7907 if there is one. We only need to handle global symbols here;
7908 we decide whether to keep or delete stubs for local symbols
7909 when processing the stub's relocations. */
7911 && !mips16_call_reloc_p (r_type
)
7912 && !section_allows_mips16_refs_p (sec
))
7914 struct mips_elf_link_hash_entry
*mh
;
7916 mh
= (struct mips_elf_link_hash_entry
*) h
;
7917 mh
->need_fn_stub
= TRUE
;
7920 /* Refuse some position-dependent relocations when creating a
7921 shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
7922 not PIC, but we can create dynamic relocations and the result
7923 will be fine. Also do not refuse R_MIPS_LO16, which can be
7924 combined with R_MIPS_GOT16. */
7932 case R_MIPS_HIGHEST
:
7933 /* Don't refuse a high part relocation if it's against
7934 no symbol (e.g. part of a compound relocation). */
7935 if (r_symndx
== STN_UNDEF
)
7938 /* R_MIPS_HI16 against _gp_disp is used for $gp setup,
7939 and has a special meaning. */
7940 if (!NEWABI_P (abfd
) && h
!= NULL
7941 && strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
7944 /* Likewise __GOTT_BASE__ and __GOTT_INDEX__ on VxWorks. */
7945 if (is_gott_symbol (info
, h
))
7952 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
7953 (*_bfd_error_handler
)
7954 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
7956 (h
) ? h
->root
.root
.string
: "a local symbol");
7957 bfd_set_error (bfd_error_bad_value
);
7969 _bfd_mips_relax_section (bfd
*abfd
, asection
*sec
,
7970 struct bfd_link_info
*link_info
,
7973 Elf_Internal_Rela
*internal_relocs
;
7974 Elf_Internal_Rela
*irel
, *irelend
;
7975 Elf_Internal_Shdr
*symtab_hdr
;
7976 bfd_byte
*contents
= NULL
;
7978 bfd_boolean changed_contents
= FALSE
;
7979 bfd_vma sec_start
= sec
->output_section
->vma
+ sec
->output_offset
;
7980 Elf_Internal_Sym
*isymbuf
= NULL
;
7982 /* We are not currently changing any sizes, so only one pass. */
7985 if (link_info
->relocatable
)
7988 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
7989 link_info
->keep_memory
);
7990 if (internal_relocs
== NULL
)
7993 irelend
= internal_relocs
+ sec
->reloc_count
7994 * get_elf_backend_data (abfd
)->s
->int_rels_per_ext_rel
;
7995 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7996 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7998 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
8001 bfd_signed_vma sym_offset
;
8002 unsigned int r_type
;
8003 unsigned long r_symndx
;
8005 unsigned long instruction
;
8007 /* Turn jalr into bgezal, and jr into beq, if they're marked
8008 with a JALR relocation, that indicate where they jump to.
8009 This saves some pipeline bubbles. */
8010 r_type
= ELF_R_TYPE (abfd
, irel
->r_info
);
8011 if (r_type
!= R_MIPS_JALR
)
8014 r_symndx
= ELF_R_SYM (abfd
, irel
->r_info
);
8015 /* Compute the address of the jump target. */
8016 if (r_symndx
>= extsymoff
)
8018 struct mips_elf_link_hash_entry
*h
8019 = ((struct mips_elf_link_hash_entry
*)
8020 elf_sym_hashes (abfd
) [r_symndx
- extsymoff
]);
8022 while (h
->root
.root
.type
== bfd_link_hash_indirect
8023 || h
->root
.root
.type
== bfd_link_hash_warning
)
8024 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
8026 /* If a symbol is undefined, or if it may be overridden,
8028 if (! ((h
->root
.root
.type
== bfd_link_hash_defined
8029 || h
->root
.root
.type
== bfd_link_hash_defweak
)
8030 && h
->root
.root
.u
.def
.section
)
8031 || (link_info
->shared
&& ! link_info
->symbolic
8032 && !h
->root
.forced_local
))
8035 sym_sec
= h
->root
.root
.u
.def
.section
;
8036 if (sym_sec
->output_section
)
8037 symval
= (h
->root
.root
.u
.def
.value
8038 + sym_sec
->output_section
->vma
8039 + sym_sec
->output_offset
);
8041 symval
= h
->root
.root
.u
.def
.value
;
8045 Elf_Internal_Sym
*isym
;
8047 /* Read this BFD's symbols if we haven't done so already. */
8048 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
8050 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
8051 if (isymbuf
== NULL
)
8052 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
8053 symtab_hdr
->sh_info
, 0,
8055 if (isymbuf
== NULL
)
8059 isym
= isymbuf
+ r_symndx
;
8060 if (isym
->st_shndx
== SHN_UNDEF
)
8062 else if (isym
->st_shndx
== SHN_ABS
)
8063 sym_sec
= bfd_abs_section_ptr
;
8064 else if (isym
->st_shndx
== SHN_COMMON
)
8065 sym_sec
= bfd_com_section_ptr
;
8068 = bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
8069 symval
= isym
->st_value
8070 + sym_sec
->output_section
->vma
8071 + sym_sec
->output_offset
;
8074 /* Compute branch offset, from delay slot of the jump to the
8076 sym_offset
= (symval
+ irel
->r_addend
)
8077 - (sec_start
+ irel
->r_offset
+ 4);
8079 /* Branch offset must be properly aligned. */
8080 if ((sym_offset
& 3) != 0)
8085 /* Check that it's in range. */
8086 if (sym_offset
< -0x8000 || sym_offset
>= 0x8000)
8089 /* Get the section contents if we haven't done so already. */
8090 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
8093 instruction
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
8095 /* If it was jalr <reg>, turn it into bgezal $zero, <target>. */
8096 if ((instruction
& 0xfc1fffff) == 0x0000f809)
8097 instruction
= 0x04110000;
8098 /* If it was jr <reg>, turn it into b <target>. */
8099 else if ((instruction
& 0xfc1fffff) == 0x00000008)
8100 instruction
= 0x10000000;
8104 instruction
|= (sym_offset
& 0xffff);
8105 bfd_put_32 (abfd
, instruction
, contents
+ irel
->r_offset
);
8106 changed_contents
= TRUE
;
8109 if (contents
!= NULL
8110 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
8112 if (!changed_contents
&& !link_info
->keep_memory
)
8116 /* Cache the section contents for elf_link_input_bfd. */
8117 elf_section_data (sec
)->this_hdr
.contents
= contents
;
8123 if (contents
!= NULL
8124 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
8129 /* Allocate space for global sym dynamic relocs. */
8132 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8134 struct bfd_link_info
*info
= inf
;
8136 struct mips_elf_link_hash_entry
*hmips
;
8137 struct mips_elf_link_hash_table
*htab
;
8139 htab
= mips_elf_hash_table (info
);
8140 BFD_ASSERT (htab
!= NULL
);
8142 dynobj
= elf_hash_table (info
)->dynobj
;
8143 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8145 /* VxWorks executables are handled elsewhere; we only need to
8146 allocate relocations in shared objects. */
8147 if (htab
->is_vxworks
&& !info
->shared
)
8150 /* Ignore indirect and warning symbols. All relocations against
8151 such symbols will be redirected to the target symbol. */
8152 if (h
->root
.type
== bfd_link_hash_indirect
8153 || h
->root
.type
== bfd_link_hash_warning
)
8156 /* If this symbol is defined in a dynamic object, or we are creating
8157 a shared library, we will need to copy any R_MIPS_32 or
8158 R_MIPS_REL32 relocs against it into the output file. */
8159 if (! info
->relocatable
8160 && hmips
->possibly_dynamic_relocs
!= 0
8161 && (h
->root
.type
== bfd_link_hash_defweak
8165 bfd_boolean do_copy
= TRUE
;
8167 if (h
->root
.type
== bfd_link_hash_undefweak
)
8169 /* Do not copy relocations for undefined weak symbols with
8170 non-default visibility. */
8171 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8174 /* Make sure undefined weak symbols are output as a dynamic
8176 else if (h
->dynindx
== -1 && !h
->forced_local
)
8178 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8185 /* Even though we don't directly need a GOT entry for this symbol,
8186 the SVR4 psABI requires it to have a dynamic symbol table
8187 index greater that DT_MIPS_GOTSYM if there are dynamic
8188 relocations against it.
8190 VxWorks does not enforce the same mapping between the GOT
8191 and the symbol table, so the same requirement does not
8193 if (!htab
->is_vxworks
)
8195 if (hmips
->global_got_area
> GGA_RELOC_ONLY
)
8196 hmips
->global_got_area
= GGA_RELOC_ONLY
;
8197 hmips
->got_only_for_calls
= FALSE
;
8200 mips_elf_allocate_dynamic_relocations
8201 (dynobj
, info
, hmips
->possibly_dynamic_relocs
);
8202 if (hmips
->readonly_reloc
)
8203 /* We tell the dynamic linker that there are relocations
8204 against the text segment. */
8205 info
->flags
|= DF_TEXTREL
;
8212 /* Adjust a symbol defined by a dynamic object and referenced by a
8213 regular object. The current definition is in some section of the
8214 dynamic object, but we're not including those sections. We have to
8215 change the definition to something the rest of the link can
8219 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
8220 struct elf_link_hash_entry
*h
)
8223 struct mips_elf_link_hash_entry
*hmips
;
8224 struct mips_elf_link_hash_table
*htab
;
8226 htab
= mips_elf_hash_table (info
);
8227 BFD_ASSERT (htab
!= NULL
);
8229 dynobj
= elf_hash_table (info
)->dynobj
;
8230 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8232 /* Make sure we know what is going on here. */
8233 BFD_ASSERT (dynobj
!= NULL
8235 || h
->u
.weakdef
!= NULL
8238 && !h
->def_regular
)));
8240 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8242 /* If there are call relocations against an externally-defined symbol,
8243 see whether we can create a MIPS lazy-binding stub for it. We can
8244 only do this if all references to the function are through call
8245 relocations, and in that case, the traditional lazy-binding stubs
8246 are much more efficient than PLT entries.
8248 Traditional stubs are only available on SVR4 psABI-based systems;
8249 VxWorks always uses PLTs instead. */
8250 if (!htab
->is_vxworks
&& h
->needs_plt
&& !hmips
->no_fn_stub
)
8252 if (! elf_hash_table (info
)->dynamic_sections_created
)
8255 /* If this symbol is not defined in a regular file, then set
8256 the symbol to the stub location. This is required to make
8257 function pointers compare as equal between the normal
8258 executable and the shared library. */
8259 if (!h
->def_regular
)
8261 hmips
->needs_lazy_stub
= TRUE
;
8262 htab
->lazy_stub_count
++;
8266 /* As above, VxWorks requires PLT entries for externally-defined
8267 functions that are only accessed through call relocations.
8269 Both VxWorks and non-VxWorks targets also need PLT entries if there
8270 are static-only relocations against an externally-defined function.
8271 This can technically occur for shared libraries if there are
8272 branches to the symbol, although it is unlikely that this will be
8273 used in practice due to the short ranges involved. It can occur
8274 for any relative or absolute relocation in executables; in that
8275 case, the PLT entry becomes the function's canonical address. */
8276 else if (((h
->needs_plt
&& !hmips
->no_fn_stub
)
8277 || (h
->type
== STT_FUNC
&& hmips
->has_static_relocs
))
8278 && htab
->use_plts_and_copy_relocs
8279 && !SYMBOL_CALLS_LOCAL (info
, h
)
8280 && !(ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
8281 && h
->root
.type
== bfd_link_hash_undefweak
))
8283 /* If this is the first symbol to need a PLT entry, allocate room
8285 if (htab
->splt
->size
== 0)
8287 BFD_ASSERT (htab
->sgotplt
->size
== 0);
8289 /* If we're using the PLT additions to the psABI, each PLT
8290 entry is 16 bytes and the PLT0 entry is 32 bytes.
8291 Encourage better cache usage by aligning. We do this
8292 lazily to avoid pessimizing traditional objects. */
8293 if (!htab
->is_vxworks
8294 && !bfd_set_section_alignment (dynobj
, htab
->splt
, 5))
8297 /* Make sure that .got.plt is word-aligned. We do this lazily
8298 for the same reason as above. */
8299 if (!bfd_set_section_alignment (dynobj
, htab
->sgotplt
,
8300 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
8303 htab
->splt
->size
+= htab
->plt_header_size
;
8305 /* On non-VxWorks targets, the first two entries in .got.plt
8307 if (!htab
->is_vxworks
)
8308 htab
->sgotplt
->size
+= 2 * MIPS_ELF_GOT_SIZE (dynobj
);
8310 /* On VxWorks, also allocate room for the header's
8311 .rela.plt.unloaded entries. */
8312 if (htab
->is_vxworks
&& !info
->shared
)
8313 htab
->srelplt2
->size
+= 2 * sizeof (Elf32_External_Rela
);
8316 /* Assign the next .plt entry to this symbol. */
8317 h
->plt
.offset
= htab
->splt
->size
;
8318 htab
->splt
->size
+= htab
->plt_entry_size
;
8320 /* If the output file has no definition of the symbol, set the
8321 symbol's value to the address of the stub. */
8322 if (!info
->shared
&& !h
->def_regular
)
8324 h
->root
.u
.def
.section
= htab
->splt
;
8325 h
->root
.u
.def
.value
= h
->plt
.offset
;
8326 /* For VxWorks, point at the PLT load stub rather than the
8327 lazy resolution stub; this stub will become the canonical
8328 function address. */
8329 if (htab
->is_vxworks
)
8330 h
->root
.u
.def
.value
+= 8;
8333 /* Make room for the .got.plt entry and the R_MIPS_JUMP_SLOT
8335 htab
->sgotplt
->size
+= MIPS_ELF_GOT_SIZE (dynobj
);
8336 htab
->srelplt
->size
+= (htab
->is_vxworks
8337 ? MIPS_ELF_RELA_SIZE (dynobj
)
8338 : MIPS_ELF_REL_SIZE (dynobj
));
8340 /* Make room for the .rela.plt.unloaded relocations. */
8341 if (htab
->is_vxworks
&& !info
->shared
)
8342 htab
->srelplt2
->size
+= 3 * sizeof (Elf32_External_Rela
);
8344 /* All relocations against this symbol that could have been made
8345 dynamic will now refer to the PLT entry instead. */
8346 hmips
->possibly_dynamic_relocs
= 0;
8351 /* If this is a weak symbol, and there is a real definition, the
8352 processor independent code will have arranged for us to see the
8353 real definition first, and we can just use the same value. */
8354 if (h
->u
.weakdef
!= NULL
)
8356 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
8357 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
8358 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
8359 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
8363 /* Otherwise, there is nothing further to do for symbols defined
8364 in regular objects. */
8368 /* There's also nothing more to do if we'll convert all relocations
8369 against this symbol into dynamic relocations. */
8370 if (!hmips
->has_static_relocs
)
8373 /* We're now relying on copy relocations. Complain if we have
8374 some that we can't convert. */
8375 if (!htab
->use_plts_and_copy_relocs
|| info
->shared
)
8377 (*_bfd_error_handler
) (_("non-dynamic relocations refer to "
8378 "dynamic symbol %s"),
8379 h
->root
.root
.string
);
8380 bfd_set_error (bfd_error_bad_value
);
8384 /* We must allocate the symbol in our .dynbss section, which will
8385 become part of the .bss section of the executable. There will be
8386 an entry for this symbol in the .dynsym section. The dynamic
8387 object will contain position independent code, so all references
8388 from the dynamic object to this symbol will go through the global
8389 offset table. The dynamic linker will use the .dynsym entry to
8390 determine the address it must put in the global offset table, so
8391 both the dynamic object and the regular object will refer to the
8392 same memory location for the variable. */
8394 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
8396 if (htab
->is_vxworks
)
8397 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
8399 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
8403 /* All relocations against this symbol that could have been made
8404 dynamic will now refer to the local copy instead. */
8405 hmips
->possibly_dynamic_relocs
= 0;
8407 return _bfd_elf_adjust_dynamic_copy (h
, htab
->sdynbss
);
8410 /* This function is called after all the input files have been read,
8411 and the input sections have been assigned to output sections. We
8412 check for any mips16 stub sections that we can discard. */
8415 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
8416 struct bfd_link_info
*info
)
8419 struct mips_elf_link_hash_table
*htab
;
8420 struct mips_htab_traverse_info hti
;
8422 htab
= mips_elf_hash_table (info
);
8423 BFD_ASSERT (htab
!= NULL
);
8425 /* The .reginfo section has a fixed size. */
8426 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
8428 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
8431 hti
.output_bfd
= output_bfd
;
8433 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
8434 mips_elf_check_symbols
, &hti
);
8441 /* If the link uses a GOT, lay it out and work out its size. */
8444 mips_elf_lay_out_got (bfd
*output_bfd
, struct bfd_link_info
*info
)
8448 struct mips_got_info
*g
;
8449 bfd_size_type loadable_size
= 0;
8450 bfd_size_type page_gotno
;
8452 struct mips_elf_count_tls_arg count_tls_arg
;
8453 struct mips_elf_link_hash_table
*htab
;
8455 htab
= mips_elf_hash_table (info
);
8456 BFD_ASSERT (htab
!= NULL
);
8462 dynobj
= elf_hash_table (info
)->dynobj
;
8465 /* Allocate room for the reserved entries. VxWorks always reserves
8466 3 entries; other objects only reserve 2 entries. */
8467 BFD_ASSERT (g
->assigned_gotno
== 0);
8468 if (htab
->is_vxworks
)
8469 htab
->reserved_gotno
= 3;
8471 htab
->reserved_gotno
= 2;
8472 g
->local_gotno
+= htab
->reserved_gotno
;
8473 g
->assigned_gotno
= htab
->reserved_gotno
;
8475 /* Replace entries for indirect and warning symbols with entries for
8476 the target symbol. */
8477 if (!mips_elf_resolve_final_got_entries (g
))
8480 /* Count the number of GOT symbols. */
8481 mips_elf_link_hash_traverse (htab
, mips_elf_count_got_symbols
, info
);
8483 /* Calculate the total loadable size of the output. That
8484 will give us the maximum number of GOT_PAGE entries
8486 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
8488 asection
*subsection
;
8490 for (subsection
= sub
->sections
;
8492 subsection
= subsection
->next
)
8494 if ((subsection
->flags
& SEC_ALLOC
) == 0)
8496 loadable_size
+= ((subsection
->size
+ 0xf)
8497 &~ (bfd_size_type
) 0xf);
8501 if (htab
->is_vxworks
)
8502 /* There's no need to allocate page entries for VxWorks; R_MIPS*_GOT16
8503 relocations against local symbols evaluate to "G", and the EABI does
8504 not include R_MIPS_GOT_PAGE. */
8507 /* Assume there are two loadable segments consisting of contiguous
8508 sections. Is 5 enough? */
8509 page_gotno
= (loadable_size
>> 16) + 5;
8511 /* Choose the smaller of the two estimates; both are intended to be
8513 if (page_gotno
> g
->page_gotno
)
8514 page_gotno
= g
->page_gotno
;
8516 g
->local_gotno
+= page_gotno
;
8517 s
->size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
8518 s
->size
+= g
->global_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
8520 /* We need to calculate tls_gotno for global symbols at this point
8521 instead of building it up earlier, to avoid doublecounting
8522 entries for one global symbol from multiple input files. */
8523 count_tls_arg
.info
= info
;
8524 count_tls_arg
.needed
= 0;
8525 elf_link_hash_traverse (elf_hash_table (info
),
8526 mips_elf_count_global_tls_entries
,
8528 g
->tls_gotno
+= count_tls_arg
.needed
;
8529 s
->size
+= g
->tls_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
8531 /* VxWorks does not support multiple GOTs. It initializes $gp to
8532 __GOTT_BASE__[__GOTT_INDEX__], the value of which is set by the
8534 if (htab
->is_vxworks
)
8536 /* VxWorks executables do not need a GOT. */
8539 /* Each VxWorks GOT entry needs an explicit relocation. */
8542 count
= g
->global_gotno
+ g
->local_gotno
- htab
->reserved_gotno
;
8544 mips_elf_allocate_dynamic_relocations (dynobj
, info
, count
);
8547 else if (s
->size
> MIPS_ELF_GOT_MAX_SIZE (info
))
8549 if (!mips_elf_multi_got (output_bfd
, info
, s
, page_gotno
))
8554 struct mips_elf_count_tls_arg arg
;
8556 /* Set up TLS entries. */
8557 g
->tls_assigned_gotno
= g
->global_gotno
+ g
->local_gotno
;
8558 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
8560 /* Allocate room for the TLS relocations. */
8563 htab_traverse (g
->got_entries
, mips_elf_count_local_tls_relocs
, &arg
);
8564 elf_link_hash_traverse (elf_hash_table (info
),
8565 mips_elf_count_global_tls_relocs
,
8568 mips_elf_allocate_dynamic_relocations (dynobj
, info
, arg
.needed
);
8574 /* Estimate the size of the .MIPS.stubs section. */
8577 mips_elf_estimate_stub_size (bfd
*output_bfd
, struct bfd_link_info
*info
)
8579 struct mips_elf_link_hash_table
*htab
;
8580 bfd_size_type dynsymcount
;
8582 htab
= mips_elf_hash_table (info
);
8583 BFD_ASSERT (htab
!= NULL
);
8585 if (htab
->lazy_stub_count
== 0)
8588 /* IRIX rld assumes that a function stub isn't at the end of the .text
8589 section, so add a dummy entry to the end. */
8590 htab
->lazy_stub_count
++;
8592 /* Get a worst-case estimate of the number of dynamic symbols needed.
8593 At this point, dynsymcount does not account for section symbols
8594 and count_section_dynsyms may overestimate the number that will
8596 dynsymcount
= (elf_hash_table (info
)->dynsymcount
8597 + count_section_dynsyms (output_bfd
, info
));
8599 /* Determine the size of one stub entry. */
8600 htab
->function_stub_size
= (dynsymcount
> 0x10000
8601 ? MIPS_FUNCTION_STUB_BIG_SIZE
8602 : MIPS_FUNCTION_STUB_NORMAL_SIZE
);
8604 htab
->sstubs
->size
= htab
->lazy_stub_count
* htab
->function_stub_size
;
8607 /* A mips_elf_link_hash_traverse callback for which DATA points to the
8608 MIPS hash table. If H needs a traditional MIPS lazy-binding stub,
8609 allocate an entry in the stubs section. */
8612 mips_elf_allocate_lazy_stub (struct mips_elf_link_hash_entry
*h
, void **data
)
8614 struct mips_elf_link_hash_table
*htab
;
8616 htab
= (struct mips_elf_link_hash_table
*) data
;
8617 if (h
->needs_lazy_stub
)
8619 h
->root
.root
.u
.def
.section
= htab
->sstubs
;
8620 h
->root
.root
.u
.def
.value
= htab
->sstubs
->size
;
8621 h
->root
.plt
.offset
= htab
->sstubs
->size
;
8622 htab
->sstubs
->size
+= htab
->function_stub_size
;
8627 /* Allocate offsets in the stubs section to each symbol that needs one.
8628 Set the final size of the .MIPS.stub section. */
8631 mips_elf_lay_out_lazy_stubs (struct bfd_link_info
*info
)
8633 struct mips_elf_link_hash_table
*htab
;
8635 htab
= mips_elf_hash_table (info
);
8636 BFD_ASSERT (htab
!= NULL
);
8638 if (htab
->lazy_stub_count
== 0)
8641 htab
->sstubs
->size
= 0;
8642 mips_elf_link_hash_traverse (htab
, mips_elf_allocate_lazy_stub
, htab
);
8643 htab
->sstubs
->size
+= htab
->function_stub_size
;
8644 BFD_ASSERT (htab
->sstubs
->size
8645 == htab
->lazy_stub_count
* htab
->function_stub_size
);
8648 /* Set the sizes of the dynamic sections. */
8651 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
8652 struct bfd_link_info
*info
)
8655 asection
*s
, *sreldyn
;
8656 bfd_boolean reltext
;
8657 struct mips_elf_link_hash_table
*htab
;
8659 htab
= mips_elf_hash_table (info
);
8660 BFD_ASSERT (htab
!= NULL
);
8661 dynobj
= elf_hash_table (info
)->dynobj
;
8662 BFD_ASSERT (dynobj
!= NULL
);
8664 if (elf_hash_table (info
)->dynamic_sections_created
)
8666 /* Set the contents of the .interp section to the interpreter. */
8667 if (info
->executable
)
8669 s
= bfd_get_section_by_name (dynobj
, ".interp");
8670 BFD_ASSERT (s
!= NULL
);
8672 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
8674 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
8677 /* Create a symbol for the PLT, if we know that we are using it. */
8678 if (htab
->splt
&& htab
->splt
->size
> 0 && htab
->root
.hplt
== NULL
)
8680 struct elf_link_hash_entry
*h
;
8682 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
8684 h
= _bfd_elf_define_linkage_sym (dynobj
, info
, htab
->splt
,
8685 "_PROCEDURE_LINKAGE_TABLE_");
8686 htab
->root
.hplt
= h
;
8693 /* Allocate space for global sym dynamic relocs. */
8694 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
8696 mips_elf_estimate_stub_size (output_bfd
, info
);
8698 if (!mips_elf_lay_out_got (output_bfd
, info
))
8701 mips_elf_lay_out_lazy_stubs (info
);
8703 /* The check_relocs and adjust_dynamic_symbol entry points have
8704 determined the sizes of the various dynamic sections. Allocate
8707 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8711 /* It's OK to base decisions on the section name, because none
8712 of the dynobj section names depend upon the input files. */
8713 name
= bfd_get_section_name (dynobj
, s
);
8715 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8718 if (CONST_STRNEQ (name
, ".rel"))
8722 const char *outname
;
8725 /* If this relocation section applies to a read only
8726 section, then we probably need a DT_TEXTREL entry.
8727 If the relocation section is .rel(a).dyn, we always
8728 assert a DT_TEXTREL entry rather than testing whether
8729 there exists a relocation to a read only section or
8731 outname
= bfd_get_section_name (output_bfd
,
8733 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
8735 && (target
->flags
& SEC_READONLY
) != 0
8736 && (target
->flags
& SEC_ALLOC
) != 0)
8737 || strcmp (outname
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
8740 /* We use the reloc_count field as a counter if we need
8741 to copy relocs into the output file. */
8742 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) != 0)
8745 /* If combreloc is enabled, elf_link_sort_relocs() will
8746 sort relocations, but in a different way than we do,
8747 and before we're done creating relocations. Also, it
8748 will move them around between input sections'
8749 relocation's contents, so our sorting would be
8750 broken, so don't let it run. */
8751 info
->combreloc
= 0;
8754 else if (! info
->shared
8755 && ! mips_elf_hash_table (info
)->use_rld_obj_head
8756 && CONST_STRNEQ (name
, ".rld_map"))
8758 /* We add a room for __rld_map. It will be filled in by the
8759 rtld to contain a pointer to the _r_debug structure. */
8762 else if (SGI_COMPAT (output_bfd
)
8763 && CONST_STRNEQ (name
, ".compact_rel"))
8764 s
->size
+= mips_elf_hash_table (info
)->compact_rel_size
;
8765 else if (s
== htab
->splt
)
8767 /* If the last PLT entry has a branch delay slot, allocate
8768 room for an extra nop to fill the delay slot. This is
8769 for CPUs without load interlocking. */
8770 if (! LOAD_INTERLOCKS_P (output_bfd
)
8771 && ! htab
->is_vxworks
&& s
->size
> 0)
8774 else if (! CONST_STRNEQ (name
, ".init")
8776 && s
!= htab
->sgotplt
8777 && s
!= htab
->sstubs
8778 && s
!= htab
->sdynbss
)
8780 /* It's not one of our sections, so don't allocate space. */
8786 s
->flags
|= SEC_EXCLUDE
;
8790 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8793 /* Allocate memory for the section contents. */
8794 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
8795 if (s
->contents
== NULL
)
8797 bfd_set_error (bfd_error_no_memory
);
8802 if (elf_hash_table (info
)->dynamic_sections_created
)
8804 /* Add some entries to the .dynamic section. We fill in the
8805 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
8806 must add the entries now so that we get the correct size for
8807 the .dynamic section. */
8809 /* SGI object has the equivalence of DT_DEBUG in the
8810 DT_MIPS_RLD_MAP entry. This must come first because glibc
8811 only fills in DT_MIPS_RLD_MAP (not DT_DEBUG) and GDB only
8812 looks at the first one it sees. */
8814 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
8817 /* The DT_DEBUG entry may be filled in by the dynamic linker and
8818 used by the debugger. */
8819 if (info
->executable
8820 && !SGI_COMPAT (output_bfd
)
8821 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
8824 if (reltext
&& (SGI_COMPAT (output_bfd
) || htab
->is_vxworks
))
8825 info
->flags
|= DF_TEXTREL
;
8827 if ((info
->flags
& DF_TEXTREL
) != 0)
8829 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
8832 /* Clear the DF_TEXTREL flag. It will be set again if we
8833 write out an actual text relocation; we may not, because
8834 at this point we do not know whether e.g. any .eh_frame
8835 absolute relocations have been converted to PC-relative. */
8836 info
->flags
&= ~DF_TEXTREL
;
8839 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
8842 sreldyn
= mips_elf_rel_dyn_section (info
, FALSE
);
8843 if (htab
->is_vxworks
)
8845 /* VxWorks uses .rela.dyn instead of .rel.dyn. It does not
8846 use any of the DT_MIPS_* tags. */
8847 if (sreldyn
&& sreldyn
->size
> 0)
8849 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELA
, 0))
8852 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELASZ
, 0))
8855 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELAENT
, 0))
8861 if (sreldyn
&& sreldyn
->size
> 0)
8863 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
8866 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
8869 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
8873 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
8876 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
8879 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
8882 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
8885 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
8888 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
8891 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
8894 if (IRIX_COMPAT (dynobj
) == ict_irix5
8895 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
8898 if (IRIX_COMPAT (dynobj
) == ict_irix6
8899 && (bfd_get_section_by_name
8900 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
8901 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
8904 if (htab
->splt
->size
> 0)
8906 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTREL
, 0))
8909 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_JMPREL
, 0))
8912 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTRELSZ
, 0))
8915 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_PLTGOT
, 0))
8918 if (htab
->is_vxworks
8919 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
8926 /* REL is a relocation in INPUT_BFD that is being copied to OUTPUT_BFD.
8927 Adjust its R_ADDEND field so that it is correct for the output file.
8928 LOCAL_SYMS and LOCAL_SECTIONS are arrays of INPUT_BFD's local symbols
8929 and sections respectively; both use symbol indexes. */
8932 mips_elf_adjust_addend (bfd
*output_bfd
, struct bfd_link_info
*info
,
8933 bfd
*input_bfd
, Elf_Internal_Sym
*local_syms
,
8934 asection
**local_sections
, Elf_Internal_Rela
*rel
)
8936 unsigned int r_type
, r_symndx
;
8937 Elf_Internal_Sym
*sym
;
8940 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
))
8942 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8943 if (r_type
== R_MIPS16_GPREL
8944 || r_type
== R_MIPS_GPREL16
8945 || r_type
== R_MIPS_GPREL32
8946 || r_type
== R_MIPS_LITERAL
)
8948 rel
->r_addend
+= _bfd_get_gp_value (input_bfd
);
8949 rel
->r_addend
-= _bfd_get_gp_value (output_bfd
);
8952 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
8953 sym
= local_syms
+ r_symndx
;
8955 /* Adjust REL's addend to account for section merging. */
8956 if (!info
->relocatable
)
8958 sec
= local_sections
[r_symndx
];
8959 _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
8962 /* This would normally be done by the rela_normal code in elflink.c. */
8963 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8964 rel
->r_addend
+= local_sections
[r_symndx
]->output_offset
;
8968 /* Relocate a MIPS ELF section. */
8971 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
8972 bfd
*input_bfd
, asection
*input_section
,
8973 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
8974 Elf_Internal_Sym
*local_syms
,
8975 asection
**local_sections
)
8977 Elf_Internal_Rela
*rel
;
8978 const Elf_Internal_Rela
*relend
;
8980 bfd_boolean use_saved_addend_p
= FALSE
;
8981 const struct elf_backend_data
*bed
;
8983 bed
= get_elf_backend_data (output_bfd
);
8984 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
8985 for (rel
= relocs
; rel
< relend
; ++rel
)
8989 reloc_howto_type
*howto
;
8990 bfd_boolean cross_mode_jump_p
;
8991 /* TRUE if the relocation is a RELA relocation, rather than a
8993 bfd_boolean rela_relocation_p
= TRUE
;
8994 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8996 unsigned long r_symndx
;
8998 Elf_Internal_Shdr
*symtab_hdr
;
8999 struct elf_link_hash_entry
*h
;
9000 bfd_boolean rel_reloc
;
9002 rel_reloc
= (NEWABI_P (input_bfd
)
9003 && mips_elf_rel_relocation_p (input_bfd
, input_section
,
9005 /* Find the relocation howto for this relocation. */
9006 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
, !rel_reloc
);
9008 r_symndx
= ELF_R_SYM (input_bfd
, rel
->r_info
);
9009 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
9010 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
))
9012 sec
= local_sections
[r_symndx
];
9017 unsigned long extsymoff
;
9020 if (!elf_bad_symtab (input_bfd
))
9021 extsymoff
= symtab_hdr
->sh_info
;
9022 h
= elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
9023 while (h
->root
.type
== bfd_link_hash_indirect
9024 || h
->root
.type
== bfd_link_hash_warning
)
9025 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
9028 if (h
->root
.type
== bfd_link_hash_defined
9029 || h
->root
.type
== bfd_link_hash_defweak
)
9030 sec
= h
->root
.u
.def
.section
;
9033 if (sec
!= NULL
&& elf_discarded_section (sec
))
9034 RELOC_AGAINST_DISCARDED_SECTION (info
, input_bfd
, input_section
,
9035 rel
, relend
, howto
, contents
);
9037 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
9039 /* Some 32-bit code uses R_MIPS_64. In particular, people use
9040 64-bit code, but make sure all their addresses are in the
9041 lowermost or uppermost 32-bit section of the 64-bit address
9042 space. Thus, when they use an R_MIPS_64 they mean what is
9043 usually meant by R_MIPS_32, with the exception that the
9044 stored value is sign-extended to 64 bits. */
9045 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
9047 /* On big-endian systems, we need to lie about the position
9049 if (bfd_big_endian (input_bfd
))
9053 if (!use_saved_addend_p
)
9055 /* If these relocations were originally of the REL variety,
9056 we must pull the addend out of the field that will be
9057 relocated. Otherwise, we simply use the contents of the
9059 if (mips_elf_rel_relocation_p (input_bfd
, input_section
,
9062 rela_relocation_p
= FALSE
;
9063 addend
= mips_elf_read_rel_addend (input_bfd
, rel
,
9065 if (hi16_reloc_p (r_type
)
9066 || (got16_reloc_p (r_type
)
9067 && mips_elf_local_relocation_p (input_bfd
, rel
,
9070 if (!mips_elf_add_lo16_rel_addend (input_bfd
, rel
, relend
,
9074 name
= h
->root
.root
.string
;
9076 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
9077 local_syms
+ r_symndx
,
9079 (*_bfd_error_handler
)
9080 (_("%B: Can't find matching LO16 reloc against `%s' for %s at 0x%lx in section `%A'"),
9081 input_bfd
, input_section
, name
, howto
->name
,
9086 addend
<<= howto
->rightshift
;
9089 addend
= rel
->r_addend
;
9090 mips_elf_adjust_addend (output_bfd
, info
, input_bfd
,
9091 local_syms
, local_sections
, rel
);
9094 if (info
->relocatable
)
9096 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
9097 && bfd_big_endian (input_bfd
))
9100 if (!rela_relocation_p
&& rel
->r_addend
)
9102 addend
+= rel
->r_addend
;
9103 if (hi16_reloc_p (r_type
) || got16_reloc_p (r_type
))
9104 addend
= mips_elf_high (addend
);
9105 else if (r_type
== R_MIPS_HIGHER
)
9106 addend
= mips_elf_higher (addend
);
9107 else if (r_type
== R_MIPS_HIGHEST
)
9108 addend
= mips_elf_highest (addend
);
9110 addend
>>= howto
->rightshift
;
9112 /* We use the source mask, rather than the destination
9113 mask because the place to which we are writing will be
9114 source of the addend in the final link. */
9115 addend
&= howto
->src_mask
;
9117 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
9118 /* See the comment above about using R_MIPS_64 in the 32-bit
9119 ABI. Here, we need to update the addend. It would be
9120 possible to get away with just using the R_MIPS_32 reloc
9121 but for endianness. */
9127 if (addend
& ((bfd_vma
) 1 << 31))
9129 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
9136 /* If we don't know that we have a 64-bit type,
9137 do two separate stores. */
9138 if (bfd_big_endian (input_bfd
))
9140 /* Store the sign-bits (which are most significant)
9142 low_bits
= sign_bits
;
9148 high_bits
= sign_bits
;
9150 bfd_put_32 (input_bfd
, low_bits
,
9151 contents
+ rel
->r_offset
);
9152 bfd_put_32 (input_bfd
, high_bits
,
9153 contents
+ rel
->r_offset
+ 4);
9157 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
9158 input_bfd
, input_section
,
9163 /* Go on to the next relocation. */
9167 /* In the N32 and 64-bit ABIs there may be multiple consecutive
9168 relocations for the same offset. In that case we are
9169 supposed to treat the output of each relocation as the addend
9171 if (rel
+ 1 < relend
9172 && rel
->r_offset
== rel
[1].r_offset
9173 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
9174 use_saved_addend_p
= TRUE
;
9176 use_saved_addend_p
= FALSE
;
9178 /* Figure out what value we are supposed to relocate. */
9179 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
9180 input_section
, info
, rel
,
9181 addend
, howto
, local_syms
,
9182 local_sections
, &value
,
9183 &name
, &cross_mode_jump_p
,
9184 use_saved_addend_p
))
9186 case bfd_reloc_continue
:
9187 /* There's nothing to do. */
9190 case bfd_reloc_undefined
:
9191 /* mips_elf_calculate_relocation already called the
9192 undefined_symbol callback. There's no real point in
9193 trying to perform the relocation at this point, so we
9194 just skip ahead to the next relocation. */
9197 case bfd_reloc_notsupported
:
9198 msg
= _("internal error: unsupported relocation error");
9199 info
->callbacks
->warning
9200 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
9203 case bfd_reloc_overflow
:
9204 if (use_saved_addend_p
)
9205 /* Ignore overflow until we reach the last relocation for
9206 a given location. */
9210 struct mips_elf_link_hash_table
*htab
;
9212 htab
= mips_elf_hash_table (info
);
9213 BFD_ASSERT (htab
!= NULL
);
9214 BFD_ASSERT (name
!= NULL
);
9215 if (!htab
->small_data_overflow_reported
9216 && (gprel16_reloc_p (howto
->type
)
9217 || howto
->type
== R_MIPS_LITERAL
))
9219 msg
= _("small-data section exceeds 64KB;"
9220 " lower small-data size limit (see option -G)");
9222 htab
->small_data_overflow_reported
= TRUE
;
9223 (*info
->callbacks
->einfo
) ("%P: %s\n", msg
);
9225 if (! ((*info
->callbacks
->reloc_overflow
)
9226 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
9227 input_bfd
, input_section
, rel
->r_offset
)))
9240 /* If we've got another relocation for the address, keep going
9241 until we reach the last one. */
9242 if (use_saved_addend_p
)
9248 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
9249 /* See the comment above about using R_MIPS_64 in the 32-bit
9250 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
9251 that calculated the right value. Now, however, we
9252 sign-extend the 32-bit result to 64-bits, and store it as a
9253 64-bit value. We are especially generous here in that we
9254 go to extreme lengths to support this usage on systems with
9255 only a 32-bit VMA. */
9261 if (value
& ((bfd_vma
) 1 << 31))
9263 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
9270 /* If we don't know that we have a 64-bit type,
9271 do two separate stores. */
9272 if (bfd_big_endian (input_bfd
))
9274 /* Undo what we did above. */
9276 /* Store the sign-bits (which are most significant)
9278 low_bits
= sign_bits
;
9284 high_bits
= sign_bits
;
9286 bfd_put_32 (input_bfd
, low_bits
,
9287 contents
+ rel
->r_offset
);
9288 bfd_put_32 (input_bfd
, high_bits
,
9289 contents
+ rel
->r_offset
+ 4);
9293 /* Actually perform the relocation. */
9294 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
9295 input_bfd
, input_section
,
9296 contents
, cross_mode_jump_p
))
9303 /* A function that iterates over each entry in la25_stubs and fills
9304 in the code for each one. DATA points to a mips_htab_traverse_info. */
9307 mips_elf_create_la25_stub (void **slot
, void *data
)
9309 struct mips_htab_traverse_info
*hti
;
9310 struct mips_elf_link_hash_table
*htab
;
9311 struct mips_elf_la25_stub
*stub
;
9314 bfd_vma offset
, target
, target_high
, target_low
;
9316 stub
= (struct mips_elf_la25_stub
*) *slot
;
9317 hti
= (struct mips_htab_traverse_info
*) data
;
9318 htab
= mips_elf_hash_table (hti
->info
);
9319 BFD_ASSERT (htab
!= NULL
);
9321 /* Create the section contents, if we haven't already. */
9322 s
= stub
->stub_section
;
9326 loc
= bfd_malloc (s
->size
);
9335 /* Work out where in the section this stub should go. */
9336 offset
= stub
->offset
;
9338 /* Work out the target address. */
9339 target
= (stub
->h
->root
.root
.u
.def
.section
->output_section
->vma
9340 + stub
->h
->root
.root
.u
.def
.section
->output_offset
9341 + stub
->h
->root
.root
.u
.def
.value
);
9342 target_high
= ((target
+ 0x8000) >> 16) & 0xffff;
9343 target_low
= (target
& 0xffff);
9345 if (stub
->stub_section
!= htab
->strampoline
)
9347 /* This is a simple LUI/ADIDU stub. Zero out the beginning
9348 of the section and write the two instructions at the end. */
9349 memset (loc
, 0, offset
);
9351 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
9352 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 4);
9356 /* This is trampoline. */
9358 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
9359 bfd_put_32 (hti
->output_bfd
, LA25_J (target
), loc
+ 4);
9360 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 8);
9361 bfd_put_32 (hti
->output_bfd
, 0, loc
+ 12);
9366 /* If NAME is one of the special IRIX6 symbols defined by the linker,
9367 adjust it appropriately now. */
9370 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
9371 const char *name
, Elf_Internal_Sym
*sym
)
9373 /* The linker script takes care of providing names and values for
9374 these, but we must place them into the right sections. */
9375 static const char* const text_section_symbols
[] = {
9378 "__dso_displacement",
9380 "__program_header_table",
9384 static const char* const data_section_symbols
[] = {
9392 const char* const *p
;
9395 for (i
= 0; i
< 2; ++i
)
9396 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
9399 if (strcmp (*p
, name
) == 0)
9401 /* All of these symbols are given type STT_SECTION by the
9403 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9404 sym
->st_other
= STO_PROTECTED
;
9406 /* The IRIX linker puts these symbols in special sections. */
9408 sym
->st_shndx
= SHN_MIPS_TEXT
;
9410 sym
->st_shndx
= SHN_MIPS_DATA
;
9416 /* Finish up dynamic symbol handling. We set the contents of various
9417 dynamic sections here. */
9420 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
9421 struct bfd_link_info
*info
,
9422 struct elf_link_hash_entry
*h
,
9423 Elf_Internal_Sym
*sym
)
9427 struct mips_got_info
*g
, *gg
;
9430 struct mips_elf_link_hash_table
*htab
;
9431 struct mips_elf_link_hash_entry
*hmips
;
9433 htab
= mips_elf_hash_table (info
);
9434 BFD_ASSERT (htab
!= NULL
);
9435 dynobj
= elf_hash_table (info
)->dynobj
;
9436 hmips
= (struct mips_elf_link_hash_entry
*) h
;
9438 BFD_ASSERT (!htab
->is_vxworks
);
9440 if (h
->plt
.offset
!= MINUS_ONE
&& hmips
->no_fn_stub
)
9442 /* We've decided to create a PLT entry for this symbol. */
9444 bfd_vma header_address
, plt_index
, got_address
;
9445 bfd_vma got_address_high
, got_address_low
, load
;
9446 const bfd_vma
*plt_entry
;
9448 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
9449 BFD_ASSERT (h
->dynindx
!= -1);
9450 BFD_ASSERT (htab
->splt
!= NULL
);
9451 BFD_ASSERT (h
->plt
.offset
<= htab
->splt
->size
);
9452 BFD_ASSERT (!h
->def_regular
);
9454 /* Calculate the address of the PLT header. */
9455 header_address
= (htab
->splt
->output_section
->vma
9456 + htab
->splt
->output_offset
);
9458 /* Calculate the index of the entry. */
9459 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
9460 / htab
->plt_entry_size
);
9462 /* Calculate the address of the .got.plt entry. */
9463 got_address
= (htab
->sgotplt
->output_section
->vma
9464 + htab
->sgotplt
->output_offset
9465 + (2 + plt_index
) * MIPS_ELF_GOT_SIZE (dynobj
));
9466 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
9467 got_address_low
= got_address
& 0xffff;
9469 /* Initially point the .got.plt entry at the PLT header. */
9470 loc
= (htab
->sgotplt
->contents
9471 + (2 + plt_index
) * MIPS_ELF_GOT_SIZE (dynobj
));
9472 if (ABI_64_P (output_bfd
))
9473 bfd_put_64 (output_bfd
, header_address
, loc
);
9475 bfd_put_32 (output_bfd
, header_address
, loc
);
9477 /* Find out where the .plt entry should go. */
9478 loc
= htab
->splt
->contents
+ h
->plt
.offset
;
9480 /* Pick the load opcode. */
9481 load
= MIPS_ELF_LOAD_WORD (output_bfd
);
9483 /* Fill in the PLT entry itself. */
9484 plt_entry
= mips_exec_plt_entry
;
9485 bfd_put_32 (output_bfd
, plt_entry
[0] | got_address_high
, loc
);
9486 bfd_put_32 (output_bfd
, plt_entry
[1] | got_address_low
| load
, loc
+ 4);
9488 if (! LOAD_INTERLOCKS_P (output_bfd
))
9490 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_low
, loc
+ 8);
9491 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9495 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 8);
9496 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_low
, loc
+ 12);
9499 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
9500 mips_elf_output_dynamic_relocation (output_bfd
, htab
->srelplt
,
9501 plt_index
, h
->dynindx
,
9502 R_MIPS_JUMP_SLOT
, got_address
);
9504 /* We distinguish between PLT entries and lazy-binding stubs by
9505 giving the former an st_other value of STO_MIPS_PLT. Set the
9506 flag and leave the value if there are any relocations in the
9507 binary where pointer equality matters. */
9508 sym
->st_shndx
= SHN_UNDEF
;
9509 if (h
->pointer_equality_needed
)
9510 sym
->st_other
= STO_MIPS_PLT
;
9514 else if (h
->plt
.offset
!= MINUS_ONE
)
9516 /* We've decided to create a lazy-binding stub. */
9517 bfd_byte stub
[MIPS_FUNCTION_STUB_BIG_SIZE
];
9519 /* This symbol has a stub. Set it up. */
9521 BFD_ASSERT (h
->dynindx
!= -1);
9523 BFD_ASSERT ((htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
9524 || (h
->dynindx
<= 0xffff));
9526 /* Values up to 2^31 - 1 are allowed. Larger values would cause
9527 sign extension at runtime in the stub, resulting in a negative
9529 if (h
->dynindx
& ~0x7fffffff)
9532 /* Fill the stub. */
9534 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
+ idx
);
9536 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ idx
);
9538 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
9540 bfd_put_32 (output_bfd
, STUB_LUI ((h
->dynindx
>> 16) & 0x7fff),
9544 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ idx
);
9547 /* If a large stub is not required and sign extension is not a
9548 problem, then use legacy code in the stub. */
9549 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
9550 bfd_put_32 (output_bfd
, STUB_ORI (h
->dynindx
& 0xffff), stub
+ idx
);
9551 else if (h
->dynindx
& ~0x7fff)
9552 bfd_put_32 (output_bfd
, STUB_LI16U (h
->dynindx
& 0xffff), stub
+ idx
);
9554 bfd_put_32 (output_bfd
, STUB_LI16S (output_bfd
, h
->dynindx
),
9557 BFD_ASSERT (h
->plt
.offset
<= htab
->sstubs
->size
);
9558 memcpy (htab
->sstubs
->contents
+ h
->plt
.offset
,
9559 stub
, htab
->function_stub_size
);
9561 /* Mark the symbol as undefined. plt.offset != -1 occurs
9562 only for the referenced symbol. */
9563 sym
->st_shndx
= SHN_UNDEF
;
9565 /* The run-time linker uses the st_value field of the symbol
9566 to reset the global offset table entry for this external
9567 to its stub address when unlinking a shared object. */
9568 sym
->st_value
= (htab
->sstubs
->output_section
->vma
9569 + htab
->sstubs
->output_offset
9573 /* If we have a MIPS16 function with a stub, the dynamic symbol must
9574 refer to the stub, since only the stub uses the standard calling
9576 if (h
->dynindx
!= -1 && hmips
->fn_stub
!= NULL
)
9578 BFD_ASSERT (hmips
->need_fn_stub
);
9579 sym
->st_value
= (hmips
->fn_stub
->output_section
->vma
9580 + hmips
->fn_stub
->output_offset
);
9581 sym
->st_size
= hmips
->fn_stub
->size
;
9582 sym
->st_other
= ELF_ST_VISIBILITY (sym
->st_other
);
9585 BFD_ASSERT (h
->dynindx
!= -1
9586 || h
->forced_local
);
9590 BFD_ASSERT (g
!= NULL
);
9592 /* Run through the global symbol table, creating GOT entries for all
9593 the symbols that need them. */
9594 if (hmips
->global_got_area
!= GGA_NONE
)
9599 value
= sym
->st_value
;
9600 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
9601 R_MIPS_GOT16
, info
);
9602 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
9605 if (hmips
->global_got_area
!= GGA_NONE
&& g
->next
&& h
->type
!= STT_TLS
)
9607 struct mips_got_entry e
, *p
;
9613 e
.abfd
= output_bfd
;
9618 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
9621 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
9626 || (elf_hash_table (info
)->dynamic_sections_created
9628 && p
->d
.h
->root
.def_dynamic
9629 && !p
->d
.h
->root
.def_regular
))
9631 /* Create an R_MIPS_REL32 relocation for this entry. Due to
9632 the various compatibility problems, it's easier to mock
9633 up an R_MIPS_32 or R_MIPS_64 relocation and leave
9634 mips_elf_create_dynamic_relocation to calculate the
9635 appropriate addend. */
9636 Elf_Internal_Rela rel
[3];
9638 memset (rel
, 0, sizeof (rel
));
9639 if (ABI_64_P (output_bfd
))
9640 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
9642 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
9643 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
9646 if (! (mips_elf_create_dynamic_relocation
9647 (output_bfd
, info
, rel
,
9648 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
9652 entry
= sym
->st_value
;
9653 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
9658 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
9659 name
= h
->root
.root
.string
;
9660 if (strcmp (name
, "_DYNAMIC") == 0
9661 || h
== elf_hash_table (info
)->hgot
)
9662 sym
->st_shndx
= SHN_ABS
;
9663 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
9664 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
9666 sym
->st_shndx
= SHN_ABS
;
9667 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9670 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
9672 sym
->st_shndx
= SHN_ABS
;
9673 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9674 sym
->st_value
= elf_gp (output_bfd
);
9676 else if (SGI_COMPAT (output_bfd
))
9678 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
9679 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
9681 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9682 sym
->st_other
= STO_PROTECTED
;
9684 sym
->st_shndx
= SHN_MIPS_DATA
;
9686 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
9688 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9689 sym
->st_other
= STO_PROTECTED
;
9690 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
9691 sym
->st_shndx
= SHN_ABS
;
9693 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
9695 if (h
->type
== STT_FUNC
)
9696 sym
->st_shndx
= SHN_MIPS_TEXT
;
9697 else if (h
->type
== STT_OBJECT
)
9698 sym
->st_shndx
= SHN_MIPS_DATA
;
9702 /* Emit a copy reloc, if needed. */
9708 BFD_ASSERT (h
->dynindx
!= -1);
9709 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
9711 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9712 symval
= (h
->root
.u
.def
.section
->output_section
->vma
9713 + h
->root
.u
.def
.section
->output_offset
9714 + h
->root
.u
.def
.value
);
9715 mips_elf_output_dynamic_relocation (output_bfd
, s
, s
->reloc_count
++,
9716 h
->dynindx
, R_MIPS_COPY
, symval
);
9719 /* Handle the IRIX6-specific symbols. */
9720 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
9721 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
9725 if (! mips_elf_hash_table (info
)->use_rld_obj_head
9726 && (strcmp (name
, "__rld_map") == 0
9727 || strcmp (name
, "__RLD_MAP") == 0))
9729 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
9730 BFD_ASSERT (s
!= NULL
);
9731 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
9732 bfd_put_32 (output_bfd
, 0, s
->contents
);
9733 if (mips_elf_hash_table (info
)->rld_value
== 0)
9734 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
9736 else if (mips_elf_hash_table (info
)->use_rld_obj_head
9737 && strcmp (name
, "__rld_obj_head") == 0)
9739 /* IRIX6 does not use a .rld_map section. */
9740 if (IRIX_COMPAT (output_bfd
) == ict_irix5
9741 || IRIX_COMPAT (output_bfd
) == ict_none
)
9742 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
9744 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
9748 /* Keep dynamic MIPS16 symbols odd. This allows the dynamic linker to
9749 treat MIPS16 symbols like any other. */
9750 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
9752 BFD_ASSERT (sym
->st_value
& 1);
9753 sym
->st_other
-= STO_MIPS16
;
9759 /* Likewise, for VxWorks. */
9762 _bfd_mips_vxworks_finish_dynamic_symbol (bfd
*output_bfd
,
9763 struct bfd_link_info
*info
,
9764 struct elf_link_hash_entry
*h
,
9765 Elf_Internal_Sym
*sym
)
9769 struct mips_got_info
*g
;
9770 struct mips_elf_link_hash_table
*htab
;
9771 struct mips_elf_link_hash_entry
*hmips
;
9773 htab
= mips_elf_hash_table (info
);
9774 BFD_ASSERT (htab
!= NULL
);
9775 dynobj
= elf_hash_table (info
)->dynobj
;
9776 hmips
= (struct mips_elf_link_hash_entry
*) h
;
9778 if (h
->plt
.offset
!= (bfd_vma
) -1)
9781 bfd_vma plt_address
, plt_index
, got_address
, got_offset
, branch_offset
;
9782 Elf_Internal_Rela rel
;
9783 static const bfd_vma
*plt_entry
;
9785 BFD_ASSERT (h
->dynindx
!= -1);
9786 BFD_ASSERT (htab
->splt
!= NULL
);
9787 BFD_ASSERT (h
->plt
.offset
<= htab
->splt
->size
);
9789 /* Calculate the address of the .plt entry. */
9790 plt_address
= (htab
->splt
->output_section
->vma
9791 + htab
->splt
->output_offset
9794 /* Calculate the index of the entry. */
9795 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
9796 / htab
->plt_entry_size
);
9798 /* Calculate the address of the .got.plt entry. */
9799 got_address
= (htab
->sgotplt
->output_section
->vma
9800 + htab
->sgotplt
->output_offset
9803 /* Calculate the offset of the .got.plt entry from
9804 _GLOBAL_OFFSET_TABLE_. */
9805 got_offset
= mips_elf_gotplt_index (info
, h
);
9807 /* Calculate the offset for the branch at the start of the PLT
9808 entry. The branch jumps to the beginning of .plt. */
9809 branch_offset
= -(h
->plt
.offset
/ 4 + 1) & 0xffff;
9811 /* Fill in the initial value of the .got.plt entry. */
9812 bfd_put_32 (output_bfd
, plt_address
,
9813 htab
->sgotplt
->contents
+ plt_index
* 4);
9815 /* Find out where the .plt entry should go. */
9816 loc
= htab
->splt
->contents
+ h
->plt
.offset
;
9820 plt_entry
= mips_vxworks_shared_plt_entry
;
9821 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9822 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9826 bfd_vma got_address_high
, got_address_low
;
9828 plt_entry
= mips_vxworks_exec_plt_entry
;
9829 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
9830 got_address_low
= got_address
& 0xffff;
9832 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9833 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9834 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_high
, loc
+ 8);
9835 bfd_put_32 (output_bfd
, plt_entry
[3] | got_address_low
, loc
+ 12);
9836 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9837 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9838 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
9839 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
9841 loc
= (htab
->srelplt2
->contents
9842 + (plt_index
* 3 + 2) * sizeof (Elf32_External_Rela
));
9844 /* Emit a relocation for the .got.plt entry. */
9845 rel
.r_offset
= got_address
;
9846 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9847 rel
.r_addend
= h
->plt
.offset
;
9848 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9850 /* Emit a relocation for the lui of %hi(<.got.plt slot>). */
9851 loc
+= sizeof (Elf32_External_Rela
);
9852 rel
.r_offset
= plt_address
+ 8;
9853 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9854 rel
.r_addend
= got_offset
;
9855 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9857 /* Emit a relocation for the addiu of %lo(<.got.plt slot>). */
9858 loc
+= sizeof (Elf32_External_Rela
);
9860 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9861 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9864 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
9865 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
9866 rel
.r_offset
= got_address
;
9867 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_JUMP_SLOT
);
9869 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9871 if (!h
->def_regular
)
9872 sym
->st_shndx
= SHN_UNDEF
;
9875 BFD_ASSERT (h
->dynindx
!= -1 || h
->forced_local
);
9879 BFD_ASSERT (g
!= NULL
);
9881 /* See if this symbol has an entry in the GOT. */
9882 if (hmips
->global_got_area
!= GGA_NONE
)
9885 Elf_Internal_Rela outrel
;
9889 /* Install the symbol value in the GOT. */
9890 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
9891 R_MIPS_GOT16
, info
);
9892 MIPS_ELF_PUT_WORD (output_bfd
, sym
->st_value
, sgot
->contents
+ offset
);
9894 /* Add a dynamic relocation for it. */
9895 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9896 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
9897 outrel
.r_offset
= (sgot
->output_section
->vma
9898 + sgot
->output_offset
9900 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_32
);
9901 outrel
.r_addend
= 0;
9902 bfd_elf32_swap_reloca_out (dynobj
, &outrel
, loc
);
9905 /* Emit a copy reloc, if needed. */
9908 Elf_Internal_Rela rel
;
9910 BFD_ASSERT (h
->dynindx
!= -1);
9912 rel
.r_offset
= (h
->root
.u
.def
.section
->output_section
->vma
9913 + h
->root
.u
.def
.section
->output_offset
9914 + h
->root
.u
.def
.value
);
9915 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_COPY
);
9917 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
9918 htab
->srelbss
->contents
9919 + (htab
->srelbss
->reloc_count
9920 * sizeof (Elf32_External_Rela
)));
9921 ++htab
->srelbss
->reloc_count
;
9924 /* If this is a mips16 symbol, force the value to be even. */
9925 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
9926 sym
->st_value
&= ~1;
9931 /* Write out a plt0 entry to the beginning of .plt. */
9934 mips_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9937 bfd_vma gotplt_value
, gotplt_value_high
, gotplt_value_low
;
9938 static const bfd_vma
*plt_entry
;
9939 struct mips_elf_link_hash_table
*htab
;
9941 htab
= mips_elf_hash_table (info
);
9942 BFD_ASSERT (htab
!= NULL
);
9944 if (ABI_64_P (output_bfd
))
9945 plt_entry
= mips_n64_exec_plt0_entry
;
9946 else if (ABI_N32_P (output_bfd
))
9947 plt_entry
= mips_n32_exec_plt0_entry
;
9949 plt_entry
= mips_o32_exec_plt0_entry
;
9951 /* Calculate the value of .got.plt. */
9952 gotplt_value
= (htab
->sgotplt
->output_section
->vma
9953 + htab
->sgotplt
->output_offset
);
9954 gotplt_value_high
= ((gotplt_value
+ 0x8000) >> 16) & 0xffff;
9955 gotplt_value_low
= gotplt_value
& 0xffff;
9957 /* The PLT sequence is not safe for N64 if .got.plt's address can
9958 not be loaded in two instructions. */
9959 BFD_ASSERT ((gotplt_value
& ~(bfd_vma
) 0x7fffffff) == 0
9960 || ~(gotplt_value
| 0x7fffffff) == 0);
9962 /* Install the PLT header. */
9963 loc
= htab
->splt
->contents
;
9964 bfd_put_32 (output_bfd
, plt_entry
[0] | gotplt_value_high
, loc
);
9965 bfd_put_32 (output_bfd
, plt_entry
[1] | gotplt_value_low
, loc
+ 4);
9966 bfd_put_32 (output_bfd
, plt_entry
[2] | gotplt_value_low
, loc
+ 8);
9967 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9968 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9969 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9970 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
9971 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
9974 /* Install the PLT header for a VxWorks executable and finalize the
9975 contents of .rela.plt.unloaded. */
9978 mips_vxworks_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9980 Elf_Internal_Rela rela
;
9982 bfd_vma got_value
, got_value_high
, got_value_low
, plt_address
;
9983 static const bfd_vma
*plt_entry
;
9984 struct mips_elf_link_hash_table
*htab
;
9986 htab
= mips_elf_hash_table (info
);
9987 BFD_ASSERT (htab
!= NULL
);
9989 plt_entry
= mips_vxworks_exec_plt0_entry
;
9991 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
9992 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
9993 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
9994 + htab
->root
.hgot
->root
.u
.def
.value
);
9996 got_value_high
= ((got_value
+ 0x8000) >> 16) & 0xffff;
9997 got_value_low
= got_value
& 0xffff;
9999 /* Calculate the address of the PLT header. */
10000 plt_address
= htab
->splt
->output_section
->vma
+ htab
->splt
->output_offset
;
10002 /* Install the PLT header. */
10003 loc
= htab
->splt
->contents
;
10004 bfd_put_32 (output_bfd
, plt_entry
[0] | got_value_high
, loc
);
10005 bfd_put_32 (output_bfd
, plt_entry
[1] | got_value_low
, loc
+ 4);
10006 bfd_put_32 (output_bfd
, plt_entry
[2], loc
+ 8);
10007 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
10008 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
10009 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
10011 /* Output the relocation for the lui of %hi(_GLOBAL_OFFSET_TABLE_). */
10012 loc
= htab
->srelplt2
->contents
;
10013 rela
.r_offset
= plt_address
;
10014 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
10016 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
10017 loc
+= sizeof (Elf32_External_Rela
);
10019 /* Output the relocation for the following addiu of
10020 %lo(_GLOBAL_OFFSET_TABLE_). */
10021 rela
.r_offset
+= 4;
10022 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
10023 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
10024 loc
+= sizeof (Elf32_External_Rela
);
10026 /* Fix up the remaining relocations. They may have the wrong
10027 symbol index for _G_O_T_ or _P_L_T_ depending on the order
10028 in which symbols were output. */
10029 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
10031 Elf_Internal_Rela rel
;
10033 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
10034 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
10035 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
10036 loc
+= sizeof (Elf32_External_Rela
);
10038 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
10039 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
10040 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
10041 loc
+= sizeof (Elf32_External_Rela
);
10043 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
10044 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
10045 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
10046 loc
+= sizeof (Elf32_External_Rela
);
10050 /* Install the PLT header for a VxWorks shared library. */
10053 mips_vxworks_finish_shared_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
10056 struct mips_elf_link_hash_table
*htab
;
10058 htab
= mips_elf_hash_table (info
);
10059 BFD_ASSERT (htab
!= NULL
);
10061 /* We just need to copy the entry byte-by-byte. */
10062 for (i
= 0; i
< ARRAY_SIZE (mips_vxworks_shared_plt0_entry
); i
++)
10063 bfd_put_32 (output_bfd
, mips_vxworks_shared_plt0_entry
[i
],
10064 htab
->splt
->contents
+ i
* 4);
10067 /* Finish up the dynamic sections. */
10070 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
10071 struct bfd_link_info
*info
)
10076 struct mips_got_info
*gg
, *g
;
10077 struct mips_elf_link_hash_table
*htab
;
10079 htab
= mips_elf_hash_table (info
);
10080 BFD_ASSERT (htab
!= NULL
);
10082 dynobj
= elf_hash_table (info
)->dynobj
;
10084 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
10087 gg
= htab
->got_info
;
10089 if (elf_hash_table (info
)->dynamic_sections_created
)
10092 int dyn_to_skip
= 0, dyn_skipped
= 0;
10094 BFD_ASSERT (sdyn
!= NULL
);
10095 BFD_ASSERT (gg
!= NULL
);
10097 g
= mips_elf_got_for_ibfd (gg
, output_bfd
);
10098 BFD_ASSERT (g
!= NULL
);
10100 for (b
= sdyn
->contents
;
10101 b
< sdyn
->contents
+ sdyn
->size
;
10102 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
10104 Elf_Internal_Dyn dyn
;
10108 bfd_boolean swap_out_p
;
10110 /* Read in the current dynamic entry. */
10111 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
10113 /* Assume that we're going to modify it and write it out. */
10119 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
10123 BFD_ASSERT (htab
->is_vxworks
);
10124 dyn
.d_un
.d_val
= MIPS_ELF_RELA_SIZE (dynobj
);
10128 /* Rewrite DT_STRSZ. */
10130 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
10135 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
10138 case DT_MIPS_PLTGOT
:
10140 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
10143 case DT_MIPS_RLD_VERSION
:
10144 dyn
.d_un
.d_val
= 1; /* XXX */
10147 case DT_MIPS_FLAGS
:
10148 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
10151 case DT_MIPS_TIME_STAMP
:
10155 dyn
.d_un
.d_val
= t
;
10159 case DT_MIPS_ICHECKSUM
:
10161 swap_out_p
= FALSE
;
10164 case DT_MIPS_IVERSION
:
10166 swap_out_p
= FALSE
;
10169 case DT_MIPS_BASE_ADDRESS
:
10170 s
= output_bfd
->sections
;
10171 BFD_ASSERT (s
!= NULL
);
10172 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
10175 case DT_MIPS_LOCAL_GOTNO
:
10176 dyn
.d_un
.d_val
= g
->local_gotno
;
10179 case DT_MIPS_UNREFEXTNO
:
10180 /* The index into the dynamic symbol table which is the
10181 entry of the first external symbol that is not
10182 referenced within the same object. */
10183 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
10186 case DT_MIPS_GOTSYM
:
10187 if (gg
->global_gotsym
)
10189 dyn
.d_un
.d_val
= gg
->global_gotsym
->dynindx
;
10192 /* In case if we don't have global got symbols we default
10193 to setting DT_MIPS_GOTSYM to the same value as
10194 DT_MIPS_SYMTABNO, so we just fall through. */
10196 case DT_MIPS_SYMTABNO
:
10198 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
10199 s
= bfd_get_section_by_name (output_bfd
, name
);
10200 BFD_ASSERT (s
!= NULL
);
10202 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
10205 case DT_MIPS_HIPAGENO
:
10206 dyn
.d_un
.d_val
= g
->local_gotno
- htab
->reserved_gotno
;
10209 case DT_MIPS_RLD_MAP
:
10210 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
10213 case DT_MIPS_OPTIONS
:
10214 s
= (bfd_get_section_by_name
10215 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
10216 dyn
.d_un
.d_ptr
= s
->vma
;
10220 BFD_ASSERT (htab
->is_vxworks
);
10221 /* The count does not include the JUMP_SLOT relocations. */
10223 dyn
.d_un
.d_val
-= htab
->srelplt
->size
;
10227 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10228 if (htab
->is_vxworks
)
10229 dyn
.d_un
.d_val
= DT_RELA
;
10231 dyn
.d_un
.d_val
= DT_REL
;
10235 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10236 dyn
.d_un
.d_val
= htab
->srelplt
->size
;
10240 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10241 dyn
.d_un
.d_ptr
= (htab
->srelplt
->output_section
->vma
10242 + htab
->srelplt
->output_offset
);
10246 /* If we didn't need any text relocations after all, delete
10247 the dynamic tag. */
10248 if (!(info
->flags
& DF_TEXTREL
))
10250 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
10251 swap_out_p
= FALSE
;
10256 /* If we didn't need any text relocations after all, clear
10257 DF_TEXTREL from DT_FLAGS. */
10258 if (!(info
->flags
& DF_TEXTREL
))
10259 dyn
.d_un
.d_val
&= ~DF_TEXTREL
;
10261 swap_out_p
= FALSE
;
10265 swap_out_p
= FALSE
;
10266 if (htab
->is_vxworks
10267 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
10272 if (swap_out_p
|| dyn_skipped
)
10273 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
10274 (dynobj
, &dyn
, b
- dyn_skipped
);
10278 dyn_skipped
+= dyn_to_skip
;
10283 /* Wipe out any trailing entries if we shifted down a dynamic tag. */
10284 if (dyn_skipped
> 0)
10285 memset (b
- dyn_skipped
, 0, dyn_skipped
);
10288 if (sgot
!= NULL
&& sgot
->size
> 0
10289 && !bfd_is_abs_section (sgot
->output_section
))
10291 if (htab
->is_vxworks
)
10293 /* The first entry of the global offset table points to the
10294 ".dynamic" section. The second is initialized by the
10295 loader and contains the shared library identifier.
10296 The third is also initialized by the loader and points
10297 to the lazy resolution stub. */
10298 MIPS_ELF_PUT_WORD (output_bfd
,
10299 sdyn
->output_offset
+ sdyn
->output_section
->vma
,
10301 MIPS_ELF_PUT_WORD (output_bfd
, 0,
10302 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
10303 MIPS_ELF_PUT_WORD (output_bfd
, 0,
10305 + 2 * MIPS_ELF_GOT_SIZE (output_bfd
));
10309 /* The first entry of the global offset table will be filled at
10310 runtime. The second entry will be used by some runtime loaders.
10311 This isn't the case of IRIX rld. */
10312 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
10313 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
10314 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
10317 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
10318 = MIPS_ELF_GOT_SIZE (output_bfd
);
10321 /* Generate dynamic relocations for the non-primary gots. */
10322 if (gg
!= NULL
&& gg
->next
)
10324 Elf_Internal_Rela rel
[3];
10325 bfd_vma addend
= 0;
10327 memset (rel
, 0, sizeof (rel
));
10328 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
10330 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
10332 bfd_vma got_index
= g
->next
->local_gotno
+ g
->next
->global_gotno
10333 + g
->next
->tls_gotno
;
10335 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
10336 + got_index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
10337 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
10339 + got_index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
10341 if (! info
->shared
)
10344 while (got_index
< g
->assigned_gotno
)
10346 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
10347 = got_index
++ * MIPS_ELF_GOT_SIZE (output_bfd
);
10348 if (!(mips_elf_create_dynamic_relocation
10349 (output_bfd
, info
, rel
, NULL
,
10350 bfd_abs_section_ptr
,
10351 0, &addend
, sgot
)))
10353 BFD_ASSERT (addend
== 0);
10358 /* The generation of dynamic relocations for the non-primary gots
10359 adds more dynamic relocations. We cannot count them until
10362 if (elf_hash_table (info
)->dynamic_sections_created
)
10365 bfd_boolean swap_out_p
;
10367 BFD_ASSERT (sdyn
!= NULL
);
10369 for (b
= sdyn
->contents
;
10370 b
< sdyn
->contents
+ sdyn
->size
;
10371 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
10373 Elf_Internal_Dyn dyn
;
10376 /* Read in the current dynamic entry. */
10377 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
10379 /* Assume that we're going to modify it and write it out. */
10385 /* Reduce DT_RELSZ to account for any relocations we
10386 decided not to make. This is for the n64 irix rld,
10387 which doesn't seem to apply any relocations if there
10388 are trailing null entries. */
10389 s
= mips_elf_rel_dyn_section (info
, FALSE
);
10390 dyn
.d_un
.d_val
= (s
->reloc_count
10391 * (ABI_64_P (output_bfd
)
10392 ? sizeof (Elf64_Mips_External_Rel
)
10393 : sizeof (Elf32_External_Rel
)));
10394 /* Adjust the section size too. Tools like the prelinker
10395 can reasonably expect the values to the same. */
10396 elf_section_data (s
->output_section
)->this_hdr
.sh_size
10401 swap_out_p
= FALSE
;
10406 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
10413 Elf32_compact_rel cpt
;
10415 if (SGI_COMPAT (output_bfd
))
10417 /* Write .compact_rel section out. */
10418 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
10422 cpt
.num
= s
->reloc_count
;
10424 cpt
.offset
= (s
->output_section
->filepos
10425 + sizeof (Elf32_External_compact_rel
));
10428 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
10429 ((Elf32_External_compact_rel
*)
10432 /* Clean up a dummy stub function entry in .text. */
10433 if (htab
->sstubs
!= NULL
)
10435 file_ptr dummy_offset
;
10437 BFD_ASSERT (htab
->sstubs
->size
>= htab
->function_stub_size
);
10438 dummy_offset
= htab
->sstubs
->size
- htab
->function_stub_size
;
10439 memset (htab
->sstubs
->contents
+ dummy_offset
, 0,
10440 htab
->function_stub_size
);
10445 /* The psABI says that the dynamic relocations must be sorted in
10446 increasing order of r_symndx. The VxWorks EABI doesn't require
10447 this, and because the code below handles REL rather than RELA
10448 relocations, using it for VxWorks would be outright harmful. */
10449 if (!htab
->is_vxworks
)
10451 s
= mips_elf_rel_dyn_section (info
, FALSE
);
10453 && s
->size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
10455 reldyn_sorting_bfd
= output_bfd
;
10457 if (ABI_64_P (output_bfd
))
10458 qsort ((Elf64_External_Rel
*) s
->contents
+ 1,
10459 s
->reloc_count
- 1, sizeof (Elf64_Mips_External_Rel
),
10460 sort_dynamic_relocs_64
);
10462 qsort ((Elf32_External_Rel
*) s
->contents
+ 1,
10463 s
->reloc_count
- 1, sizeof (Elf32_External_Rel
),
10464 sort_dynamic_relocs
);
10469 if (htab
->splt
&& htab
->splt
->size
> 0)
10471 if (htab
->is_vxworks
)
10474 mips_vxworks_finish_shared_plt (output_bfd
, info
);
10476 mips_vxworks_finish_exec_plt (output_bfd
, info
);
10480 BFD_ASSERT (!info
->shared
);
10481 mips_finish_exec_plt (output_bfd
, info
);
10488 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
10491 mips_set_isa_flags (bfd
*abfd
)
10495 switch (bfd_get_mach (abfd
))
10498 case bfd_mach_mips3000
:
10499 val
= E_MIPS_ARCH_1
;
10502 case bfd_mach_mips3900
:
10503 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
10506 case bfd_mach_mips6000
:
10507 val
= E_MIPS_ARCH_2
;
10510 case bfd_mach_mips4000
:
10511 case bfd_mach_mips4300
:
10512 case bfd_mach_mips4400
:
10513 case bfd_mach_mips4600
:
10514 val
= E_MIPS_ARCH_3
;
10517 case bfd_mach_mips4010
:
10518 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
10521 case bfd_mach_mips4100
:
10522 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
10525 case bfd_mach_mips4111
:
10526 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
10529 case bfd_mach_mips4120
:
10530 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
10533 case bfd_mach_mips4650
:
10534 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
10537 case bfd_mach_mips5400
:
10538 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
10541 case bfd_mach_mips5500
:
10542 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
10545 case bfd_mach_mips9000
:
10546 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_9000
;
10549 case bfd_mach_mips5000
:
10550 case bfd_mach_mips7000
:
10551 case bfd_mach_mips8000
:
10552 case bfd_mach_mips10000
:
10553 case bfd_mach_mips12000
:
10554 case bfd_mach_mips14000
:
10555 case bfd_mach_mips16000
:
10556 val
= E_MIPS_ARCH_4
;
10559 case bfd_mach_mips5
:
10560 val
= E_MIPS_ARCH_5
;
10563 case bfd_mach_mips_loongson_2e
:
10564 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2E
;
10567 case bfd_mach_mips_loongson_2f
:
10568 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2F
;
10571 case bfd_mach_mips_sb1
:
10572 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
10575 case bfd_mach_mips_loongson_3a
:
10576 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_LS3A
;
10579 case bfd_mach_mips_octeon
:
10580 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON
;
10583 case bfd_mach_mips_xlr
:
10584 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_XLR
;
10587 case bfd_mach_mipsisa32
:
10588 val
= E_MIPS_ARCH_32
;
10591 case bfd_mach_mipsisa64
:
10592 val
= E_MIPS_ARCH_64
;
10595 case bfd_mach_mipsisa32r2
:
10596 val
= E_MIPS_ARCH_32R2
;
10599 case bfd_mach_mipsisa64r2
:
10600 val
= E_MIPS_ARCH_64R2
;
10603 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
10604 elf_elfheader (abfd
)->e_flags
|= val
;
10609 /* The final processing done just before writing out a MIPS ELF object
10610 file. This gets the MIPS architecture right based on the machine
10611 number. This is used by both the 32-bit and the 64-bit ABI. */
10614 _bfd_mips_elf_final_write_processing (bfd
*abfd
,
10615 bfd_boolean linker ATTRIBUTE_UNUSED
)
10618 Elf_Internal_Shdr
**hdrpp
;
10622 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
10623 is nonzero. This is for compatibility with old objects, which used
10624 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
10625 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
10626 mips_set_isa_flags (abfd
);
10628 /* Set the sh_info field for .gptab sections and other appropriate
10629 info for each special section. */
10630 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
10631 i
< elf_numsections (abfd
);
10634 switch ((*hdrpp
)->sh_type
)
10636 case SHT_MIPS_MSYM
:
10637 case SHT_MIPS_LIBLIST
:
10638 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
10640 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10643 case SHT_MIPS_GPTAB
:
10644 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
10645 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
10646 BFD_ASSERT (name
!= NULL
10647 && CONST_STRNEQ (name
, ".gptab."));
10648 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
10649 BFD_ASSERT (sec
!= NULL
);
10650 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
10653 case SHT_MIPS_CONTENT
:
10654 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
10655 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
10656 BFD_ASSERT (name
!= NULL
10657 && CONST_STRNEQ (name
, ".MIPS.content"));
10658 sec
= bfd_get_section_by_name (abfd
,
10659 name
+ sizeof ".MIPS.content" - 1);
10660 BFD_ASSERT (sec
!= NULL
);
10661 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10664 case SHT_MIPS_SYMBOL_LIB
:
10665 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
10667 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10668 sec
= bfd_get_section_by_name (abfd
, ".liblist");
10670 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
10673 case SHT_MIPS_EVENTS
:
10674 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
10675 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
10676 BFD_ASSERT (name
!= NULL
);
10677 if (CONST_STRNEQ (name
, ".MIPS.events"))
10678 sec
= bfd_get_section_by_name (abfd
,
10679 name
+ sizeof ".MIPS.events" - 1);
10682 BFD_ASSERT (CONST_STRNEQ (name
, ".MIPS.post_rel"));
10683 sec
= bfd_get_section_by_name (abfd
,
10685 + sizeof ".MIPS.post_rel" - 1));
10687 BFD_ASSERT (sec
!= NULL
);
10688 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10695 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
10699 _bfd_mips_elf_additional_program_headers (bfd
*abfd
,
10700 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
10705 /* See if we need a PT_MIPS_REGINFO segment. */
10706 s
= bfd_get_section_by_name (abfd
, ".reginfo");
10707 if (s
&& (s
->flags
& SEC_LOAD
))
10710 /* See if we need a PT_MIPS_OPTIONS segment. */
10711 if (IRIX_COMPAT (abfd
) == ict_irix6
10712 && bfd_get_section_by_name (abfd
,
10713 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
10716 /* See if we need a PT_MIPS_RTPROC segment. */
10717 if (IRIX_COMPAT (abfd
) == ict_irix5
10718 && bfd_get_section_by_name (abfd
, ".dynamic")
10719 && bfd_get_section_by_name (abfd
, ".mdebug"))
10722 /* Allocate a PT_NULL header in dynamic objects. See
10723 _bfd_mips_elf_modify_segment_map for details. */
10724 if (!SGI_COMPAT (abfd
)
10725 && bfd_get_section_by_name (abfd
, ".dynamic"))
10731 /* Modify the segment map for an IRIX5 executable. */
10734 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
10735 struct bfd_link_info
*info
)
10738 struct elf_segment_map
*m
, **pm
;
10741 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
10743 s
= bfd_get_section_by_name (abfd
, ".reginfo");
10744 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
10746 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
10747 if (m
->p_type
== PT_MIPS_REGINFO
)
10752 m
= bfd_zalloc (abfd
, amt
);
10756 m
->p_type
= PT_MIPS_REGINFO
;
10758 m
->sections
[0] = s
;
10760 /* We want to put it after the PHDR and INTERP segments. */
10761 pm
= &elf_tdata (abfd
)->segment_map
;
10763 && ((*pm
)->p_type
== PT_PHDR
10764 || (*pm
)->p_type
== PT_INTERP
))
10772 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
10773 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
10774 PT_MIPS_OPTIONS segment immediately following the program header
10776 if (NEWABI_P (abfd
)
10777 /* On non-IRIX6 new abi, we'll have already created a segment
10778 for this section, so don't create another. I'm not sure this
10779 is not also the case for IRIX 6, but I can't test it right
10781 && IRIX_COMPAT (abfd
) == ict_irix6
)
10783 for (s
= abfd
->sections
; s
; s
= s
->next
)
10784 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
10789 struct elf_segment_map
*options_segment
;
10791 pm
= &elf_tdata (abfd
)->segment_map
;
10793 && ((*pm
)->p_type
== PT_PHDR
10794 || (*pm
)->p_type
== PT_INTERP
))
10797 if (*pm
== NULL
|| (*pm
)->p_type
!= PT_MIPS_OPTIONS
)
10799 amt
= sizeof (struct elf_segment_map
);
10800 options_segment
= bfd_zalloc (abfd
, amt
);
10801 options_segment
->next
= *pm
;
10802 options_segment
->p_type
= PT_MIPS_OPTIONS
;
10803 options_segment
->p_flags
= PF_R
;
10804 options_segment
->p_flags_valid
= TRUE
;
10805 options_segment
->count
= 1;
10806 options_segment
->sections
[0] = s
;
10807 *pm
= options_segment
;
10813 if (IRIX_COMPAT (abfd
) == ict_irix5
)
10815 /* If there are .dynamic and .mdebug sections, we make a room
10816 for the RTPROC header. FIXME: Rewrite without section names. */
10817 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
10818 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
10819 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
10821 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
10822 if (m
->p_type
== PT_MIPS_RTPROC
)
10827 m
= bfd_zalloc (abfd
, amt
);
10831 m
->p_type
= PT_MIPS_RTPROC
;
10833 s
= bfd_get_section_by_name (abfd
, ".rtproc");
10838 m
->p_flags_valid
= 1;
10843 m
->sections
[0] = s
;
10846 /* We want to put it after the DYNAMIC segment. */
10847 pm
= &elf_tdata (abfd
)->segment_map
;
10848 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
10858 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
10859 .dynstr, .dynsym, and .hash sections, and everything in
10861 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
10863 if ((*pm
)->p_type
== PT_DYNAMIC
)
10866 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
10868 /* For a normal mips executable the permissions for the PT_DYNAMIC
10869 segment are read, write and execute. We do that here since
10870 the code in elf.c sets only the read permission. This matters
10871 sometimes for the dynamic linker. */
10872 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
10874 m
->p_flags
= PF_R
| PF_W
| PF_X
;
10875 m
->p_flags_valid
= 1;
10878 /* GNU/Linux binaries do not need the extended PT_DYNAMIC section.
10879 glibc's dynamic linker has traditionally derived the number of
10880 tags from the p_filesz field, and sometimes allocates stack
10881 arrays of that size. An overly-big PT_DYNAMIC segment can
10882 be actively harmful in such cases. Making PT_DYNAMIC contain
10883 other sections can also make life hard for the prelinker,
10884 which might move one of the other sections to a different
10885 PT_LOAD segment. */
10886 if (SGI_COMPAT (abfd
)
10889 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
10891 static const char *sec_names
[] =
10893 ".dynamic", ".dynstr", ".dynsym", ".hash"
10897 struct elf_segment_map
*n
;
10899 low
= ~(bfd_vma
) 0;
10901 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
10903 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
10904 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
10911 if (high
< s
->vma
+ sz
)
10912 high
= s
->vma
+ sz
;
10917 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10918 if ((s
->flags
& SEC_LOAD
) != 0
10920 && s
->vma
+ s
->size
<= high
)
10923 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
10924 n
= bfd_zalloc (abfd
, amt
);
10931 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10933 if ((s
->flags
& SEC_LOAD
) != 0
10935 && s
->vma
+ s
->size
<= high
)
10937 n
->sections
[i
] = s
;
10946 /* Allocate a spare program header in dynamic objects so that tools
10947 like the prelinker can add an extra PT_LOAD entry.
10949 If the prelinker needs to make room for a new PT_LOAD entry, its
10950 standard procedure is to move the first (read-only) sections into
10951 the new (writable) segment. However, the MIPS ABI requires
10952 .dynamic to be in a read-only segment, and the section will often
10953 start within sizeof (ElfNN_Phdr) bytes of the last program header.
10955 Although the prelinker could in principle move .dynamic to a
10956 writable segment, it seems better to allocate a spare program
10957 header instead, and avoid the need to move any sections.
10958 There is a long tradition of allocating spare dynamic tags,
10959 so allocating a spare program header seems like a natural
10962 If INFO is NULL, we may be copying an already prelinked binary
10963 with objcopy or strip, so do not add this header. */
10965 && !SGI_COMPAT (abfd
)
10966 && bfd_get_section_by_name (abfd
, ".dynamic"))
10968 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
10969 if ((*pm
)->p_type
== PT_NULL
)
10973 m
= bfd_zalloc (abfd
, sizeof (*m
));
10977 m
->p_type
= PT_NULL
;
10985 /* Return the section that should be marked against GC for a given
10989 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
10990 struct bfd_link_info
*info
,
10991 Elf_Internal_Rela
*rel
,
10992 struct elf_link_hash_entry
*h
,
10993 Elf_Internal_Sym
*sym
)
10995 /* ??? Do mips16 stub sections need to be handled special? */
10998 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
11000 case R_MIPS_GNU_VTINHERIT
:
11001 case R_MIPS_GNU_VTENTRY
:
11005 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
11008 /* Update the got entry reference counts for the section being removed. */
11011 _bfd_mips_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
11012 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
11013 asection
*sec ATTRIBUTE_UNUSED
,
11014 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
11017 Elf_Internal_Shdr
*symtab_hdr
;
11018 struct elf_link_hash_entry
**sym_hashes
;
11019 bfd_signed_vma
*local_got_refcounts
;
11020 const Elf_Internal_Rela
*rel
, *relend
;
11021 unsigned long r_symndx
;
11022 struct elf_link_hash_entry
*h
;
11024 if (info
->relocatable
)
11027 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
11028 sym_hashes
= elf_sym_hashes (abfd
);
11029 local_got_refcounts
= elf_local_got_refcounts (abfd
);
11031 relend
= relocs
+ sec
->reloc_count
;
11032 for (rel
= relocs
; rel
< relend
; rel
++)
11033 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
11035 case R_MIPS16_GOT16
:
11036 case R_MIPS16_CALL16
:
11038 case R_MIPS_CALL16
:
11039 case R_MIPS_CALL_HI16
:
11040 case R_MIPS_CALL_LO16
:
11041 case R_MIPS_GOT_HI16
:
11042 case R_MIPS_GOT_LO16
:
11043 case R_MIPS_GOT_DISP
:
11044 case R_MIPS_GOT_PAGE
:
11045 case R_MIPS_GOT_OFST
:
11046 /* ??? It would seem that the existing MIPS code does no sort
11047 of reference counting or whatnot on its GOT and PLT entries,
11048 so it is not possible to garbage collect them at this time. */
11059 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
11060 hiding the old indirect symbol. Process additional relocation
11061 information. Also called for weakdefs, in which case we just let
11062 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
11065 _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
11066 struct elf_link_hash_entry
*dir
,
11067 struct elf_link_hash_entry
*ind
)
11069 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
11071 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
11073 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
11074 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
11075 /* Any absolute non-dynamic relocations against an indirect or weak
11076 definition will be against the target symbol. */
11077 if (indmips
->has_static_relocs
)
11078 dirmips
->has_static_relocs
= TRUE
;
11080 if (ind
->root
.type
!= bfd_link_hash_indirect
)
11083 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
11084 if (indmips
->readonly_reloc
)
11085 dirmips
->readonly_reloc
= TRUE
;
11086 if (indmips
->no_fn_stub
)
11087 dirmips
->no_fn_stub
= TRUE
;
11088 if (indmips
->fn_stub
)
11090 dirmips
->fn_stub
= indmips
->fn_stub
;
11091 indmips
->fn_stub
= NULL
;
11093 if (indmips
->need_fn_stub
)
11095 dirmips
->need_fn_stub
= TRUE
;
11096 indmips
->need_fn_stub
= FALSE
;
11098 if (indmips
->call_stub
)
11100 dirmips
->call_stub
= indmips
->call_stub
;
11101 indmips
->call_stub
= NULL
;
11103 if (indmips
->call_fp_stub
)
11105 dirmips
->call_fp_stub
= indmips
->call_fp_stub
;
11106 indmips
->call_fp_stub
= NULL
;
11108 if (indmips
->global_got_area
< dirmips
->global_got_area
)
11109 dirmips
->global_got_area
= indmips
->global_got_area
;
11110 if (indmips
->global_got_area
< GGA_NONE
)
11111 indmips
->global_got_area
= GGA_NONE
;
11112 if (indmips
->has_nonpic_branches
)
11113 dirmips
->has_nonpic_branches
= TRUE
;
11115 if (dirmips
->tls_type
== 0)
11116 dirmips
->tls_type
= indmips
->tls_type
;
11119 #define PDR_SIZE 32
11122 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
11123 struct bfd_link_info
*info
)
11126 bfd_boolean ret
= FALSE
;
11127 unsigned char *tdata
;
11130 o
= bfd_get_section_by_name (abfd
, ".pdr");
11135 if (o
->size
% PDR_SIZE
!= 0)
11137 if (o
->output_section
!= NULL
11138 && bfd_is_abs_section (o
->output_section
))
11141 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
11145 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
11146 info
->keep_memory
);
11153 cookie
->rel
= cookie
->rels
;
11154 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
11156 for (i
= 0, skip
= 0; i
< o
->size
/ PDR_SIZE
; i
++)
11158 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
11167 mips_elf_section_data (o
)->u
.tdata
= tdata
;
11168 o
->size
-= skip
* PDR_SIZE
;
11174 if (! info
->keep_memory
)
11175 free (cookie
->rels
);
11181 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
11183 if (strcmp (sec
->name
, ".pdr") == 0)
11189 _bfd_mips_elf_write_section (bfd
*output_bfd
,
11190 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
11191 asection
*sec
, bfd_byte
*contents
)
11193 bfd_byte
*to
, *from
, *end
;
11196 if (strcmp (sec
->name
, ".pdr") != 0)
11199 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
11203 end
= contents
+ sec
->size
;
11204 for (from
= contents
, i
= 0;
11206 from
+= PDR_SIZE
, i
++)
11208 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
11211 memcpy (to
, from
, PDR_SIZE
);
11214 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
11215 sec
->output_offset
, sec
->size
);
11219 /* MIPS ELF uses a special find_nearest_line routine in order the
11220 handle the ECOFF debugging information. */
11222 struct mips_elf_find_line
11224 struct ecoff_debug_info d
;
11225 struct ecoff_find_line i
;
11229 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asection
*section
,
11230 asymbol
**symbols
, bfd_vma offset
,
11231 const char **filename_ptr
,
11232 const char **functionname_ptr
,
11233 unsigned int *line_ptr
)
11237 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
11238 filename_ptr
, functionname_ptr
,
11242 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
11243 filename_ptr
, functionname_ptr
,
11244 line_ptr
, ABI_64_P (abfd
) ? 8 : 0,
11245 &elf_tdata (abfd
)->dwarf2_find_line_info
))
11248 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
11251 flagword origflags
;
11252 struct mips_elf_find_line
*fi
;
11253 const struct ecoff_debug_swap
* const swap
=
11254 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
11256 /* If we are called during a link, mips_elf_final_link may have
11257 cleared the SEC_HAS_CONTENTS field. We force it back on here
11258 if appropriate (which it normally will be). */
11259 origflags
= msec
->flags
;
11260 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
11261 msec
->flags
|= SEC_HAS_CONTENTS
;
11263 fi
= elf_tdata (abfd
)->find_line_info
;
11266 bfd_size_type external_fdr_size
;
11269 struct fdr
*fdr_ptr
;
11270 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
11272 fi
= bfd_zalloc (abfd
, amt
);
11275 msec
->flags
= origflags
;
11279 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
11281 msec
->flags
= origflags
;
11285 /* Swap in the FDR information. */
11286 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
11287 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
11288 if (fi
->d
.fdr
== NULL
)
11290 msec
->flags
= origflags
;
11293 external_fdr_size
= swap
->external_fdr_size
;
11294 fdr_ptr
= fi
->d
.fdr
;
11295 fraw_src
= (char *) fi
->d
.external_fdr
;
11296 fraw_end
= (fraw_src
11297 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
11298 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
11299 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
11301 elf_tdata (abfd
)->find_line_info
= fi
;
11303 /* Note that we don't bother to ever free this information.
11304 find_nearest_line is either called all the time, as in
11305 objdump -l, so the information should be saved, or it is
11306 rarely called, as in ld error messages, so the memory
11307 wasted is unimportant. Still, it would probably be a
11308 good idea for free_cached_info to throw it away. */
11311 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
11312 &fi
->i
, filename_ptr
, functionname_ptr
,
11315 msec
->flags
= origflags
;
11319 msec
->flags
= origflags
;
11322 /* Fall back on the generic ELF find_nearest_line routine. */
11324 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
11325 filename_ptr
, functionname_ptr
,
11330 _bfd_mips_elf_find_inliner_info (bfd
*abfd
,
11331 const char **filename_ptr
,
11332 const char **functionname_ptr
,
11333 unsigned int *line_ptr
)
11336 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
11337 functionname_ptr
, line_ptr
,
11338 & elf_tdata (abfd
)->dwarf2_find_line_info
);
11343 /* When are writing out the .options or .MIPS.options section,
11344 remember the bytes we are writing out, so that we can install the
11345 GP value in the section_processing routine. */
11348 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
11349 const void *location
,
11350 file_ptr offset
, bfd_size_type count
)
11352 if (MIPS_ELF_OPTIONS_SECTION_NAME_P (section
->name
))
11356 if (elf_section_data (section
) == NULL
)
11358 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
11359 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
11360 if (elf_section_data (section
) == NULL
)
11363 c
= mips_elf_section_data (section
)->u
.tdata
;
11366 c
= bfd_zalloc (abfd
, section
->size
);
11369 mips_elf_section_data (section
)->u
.tdata
= c
;
11372 memcpy (c
+ offset
, location
, count
);
11375 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
11379 /* This is almost identical to bfd_generic_get_... except that some
11380 MIPS relocations need to be handled specially. Sigh. */
11383 _bfd_elf_mips_get_relocated_section_contents
11385 struct bfd_link_info
*link_info
,
11386 struct bfd_link_order
*link_order
,
11388 bfd_boolean relocatable
,
11391 /* Get enough memory to hold the stuff */
11392 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
11393 asection
*input_section
= link_order
->u
.indirect
.section
;
11396 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
11397 arelent
**reloc_vector
= NULL
;
11400 if (reloc_size
< 0)
11403 reloc_vector
= bfd_malloc (reloc_size
);
11404 if (reloc_vector
== NULL
&& reloc_size
!= 0)
11407 /* read in the section */
11408 sz
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
11409 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0, sz
))
11412 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
11416 if (reloc_count
< 0)
11419 if (reloc_count
> 0)
11424 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
11427 struct bfd_hash_entry
*h
;
11428 struct bfd_link_hash_entry
*lh
;
11429 /* Skip all this stuff if we aren't mixing formats. */
11430 if (abfd
&& input_bfd
11431 && abfd
->xvec
== input_bfd
->xvec
)
11435 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
11436 lh
= (struct bfd_link_hash_entry
*) h
;
11443 case bfd_link_hash_undefined
:
11444 case bfd_link_hash_undefweak
:
11445 case bfd_link_hash_common
:
11448 case bfd_link_hash_defined
:
11449 case bfd_link_hash_defweak
:
11451 gp
= lh
->u
.def
.value
;
11453 case bfd_link_hash_indirect
:
11454 case bfd_link_hash_warning
:
11456 /* @@FIXME ignoring warning for now */
11458 case bfd_link_hash_new
:
11467 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
11469 char *error_message
= NULL
;
11470 bfd_reloc_status_type r
;
11472 /* Specific to MIPS: Deal with relocation types that require
11473 knowing the gp of the output bfd. */
11474 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
11476 /* If we've managed to find the gp and have a special
11477 function for the relocation then go ahead, else default
11478 to the generic handling. */
11480 && (*parent
)->howto
->special_function
11481 == _bfd_mips_elf32_gprel16_reloc
)
11482 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
11483 input_section
, relocatable
,
11486 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
11488 relocatable
? abfd
: NULL
,
11493 asection
*os
= input_section
->output_section
;
11495 /* A partial link, so keep the relocs */
11496 os
->orelocation
[os
->reloc_count
] = *parent
;
11500 if (r
!= bfd_reloc_ok
)
11504 case bfd_reloc_undefined
:
11505 if (!((*link_info
->callbacks
->undefined_symbol
)
11506 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
11507 input_bfd
, input_section
, (*parent
)->address
, TRUE
)))
11510 case bfd_reloc_dangerous
:
11511 BFD_ASSERT (error_message
!= NULL
);
11512 if (!((*link_info
->callbacks
->reloc_dangerous
)
11513 (link_info
, error_message
, input_bfd
, input_section
,
11514 (*parent
)->address
)))
11517 case bfd_reloc_overflow
:
11518 if (!((*link_info
->callbacks
->reloc_overflow
)
11520 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
11521 (*parent
)->howto
->name
, (*parent
)->addend
,
11522 input_bfd
, input_section
, (*parent
)->address
)))
11525 case bfd_reloc_outofrange
:
11534 if (reloc_vector
!= NULL
)
11535 free (reloc_vector
);
11539 if (reloc_vector
!= NULL
)
11540 free (reloc_vector
);
11544 /* Create a MIPS ELF linker hash table. */
11546 struct bfd_link_hash_table
*
11547 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
11549 struct mips_elf_link_hash_table
*ret
;
11550 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
11552 ret
= bfd_malloc (amt
);
11556 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
11557 mips_elf_link_hash_newfunc
,
11558 sizeof (struct mips_elf_link_hash_entry
),
11566 /* We no longer use this. */
11567 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
11568 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
11570 ret
->procedure_count
= 0;
11571 ret
->compact_rel_size
= 0;
11572 ret
->use_rld_obj_head
= FALSE
;
11573 ret
->rld_value
= 0;
11574 ret
->mips16_stubs_seen
= FALSE
;
11575 ret
->use_plts_and_copy_relocs
= FALSE
;
11576 ret
->is_vxworks
= FALSE
;
11577 ret
->small_data_overflow_reported
= FALSE
;
11578 ret
->srelbss
= NULL
;
11579 ret
->sdynbss
= NULL
;
11580 ret
->srelplt
= NULL
;
11581 ret
->srelplt2
= NULL
;
11582 ret
->sgotplt
= NULL
;
11584 ret
->sstubs
= NULL
;
11586 ret
->got_info
= NULL
;
11587 ret
->plt_header_size
= 0;
11588 ret
->plt_entry_size
= 0;
11589 ret
->lazy_stub_count
= 0;
11590 ret
->function_stub_size
= 0;
11591 ret
->strampoline
= NULL
;
11592 ret
->la25_stubs
= NULL
;
11593 ret
->add_stub_section
= NULL
;
11595 return &ret
->root
.root
;
11598 /* Likewise, but indicate that the target is VxWorks. */
11600 struct bfd_link_hash_table
*
11601 _bfd_mips_vxworks_link_hash_table_create (bfd
*abfd
)
11603 struct bfd_link_hash_table
*ret
;
11605 ret
= _bfd_mips_elf_link_hash_table_create (abfd
);
11608 struct mips_elf_link_hash_table
*htab
;
11610 htab
= (struct mips_elf_link_hash_table
*) ret
;
11611 htab
->use_plts_and_copy_relocs
= TRUE
;
11612 htab
->is_vxworks
= TRUE
;
11617 /* A function that the linker calls if we are allowed to use PLTs
11618 and copy relocs. */
11621 _bfd_mips_elf_use_plts_and_copy_relocs (struct bfd_link_info
*info
)
11623 mips_elf_hash_table (info
)->use_plts_and_copy_relocs
= TRUE
;
11626 /* We need to use a special link routine to handle the .reginfo and
11627 the .mdebug sections. We need to merge all instances of these
11628 sections together, not write them all out sequentially. */
11631 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
11634 struct bfd_link_order
*p
;
11635 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
11636 asection
*rtproc_sec
;
11637 Elf32_RegInfo reginfo
;
11638 struct ecoff_debug_info debug
;
11639 struct mips_htab_traverse_info hti
;
11640 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
11641 const struct ecoff_debug_swap
*swap
= bed
->elf_backend_ecoff_debug_swap
;
11642 HDRR
*symhdr
= &debug
.symbolic_header
;
11643 void *mdebug_handle
= NULL
;
11648 struct mips_elf_link_hash_table
*htab
;
11650 static const char * const secname
[] =
11652 ".text", ".init", ".fini", ".data",
11653 ".rodata", ".sdata", ".sbss", ".bss"
11655 static const int sc
[] =
11657 scText
, scInit
, scFini
, scData
,
11658 scRData
, scSData
, scSBss
, scBss
11661 /* Sort the dynamic symbols so that those with GOT entries come after
11663 htab
= mips_elf_hash_table (info
);
11664 BFD_ASSERT (htab
!= NULL
);
11666 if (!mips_elf_sort_hash_table (abfd
, info
))
11669 /* Create any scheduled LA25 stubs. */
11671 hti
.output_bfd
= abfd
;
11673 htab_traverse (htab
->la25_stubs
, mips_elf_create_la25_stub
, &hti
);
11677 /* Get a value for the GP register. */
11678 if (elf_gp (abfd
) == 0)
11680 struct bfd_link_hash_entry
*h
;
11682 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
11683 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
11684 elf_gp (abfd
) = (h
->u
.def
.value
11685 + h
->u
.def
.section
->output_section
->vma
11686 + h
->u
.def
.section
->output_offset
);
11687 else if (htab
->is_vxworks
11688 && (h
= bfd_link_hash_lookup (info
->hash
,
11689 "_GLOBAL_OFFSET_TABLE_",
11690 FALSE
, FALSE
, TRUE
))
11691 && h
->type
== bfd_link_hash_defined
)
11692 elf_gp (abfd
) = (h
->u
.def
.section
->output_section
->vma
11693 + h
->u
.def
.section
->output_offset
11695 else if (info
->relocatable
)
11697 bfd_vma lo
= MINUS_ONE
;
11699 /* Find the GP-relative section with the lowest offset. */
11700 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
11702 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
11705 /* And calculate GP relative to that. */
11706 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (info
);
11710 /* If the relocate_section function needs to do a reloc
11711 involving the GP value, it should make a reloc_dangerous
11712 callback to warn that GP is not defined. */
11716 /* Go through the sections and collect the .reginfo and .mdebug
11718 reginfo_sec
= NULL
;
11720 gptab_data_sec
= NULL
;
11721 gptab_bss_sec
= NULL
;
11722 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
11724 if (strcmp (o
->name
, ".reginfo") == 0)
11726 memset (®info
, 0, sizeof reginfo
);
11728 /* We have found the .reginfo section in the output file.
11729 Look through all the link_orders comprising it and merge
11730 the information together. */
11731 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11733 asection
*input_section
;
11735 Elf32_External_RegInfo ext
;
11738 if (p
->type
!= bfd_indirect_link_order
)
11740 if (p
->type
== bfd_data_link_order
)
11745 input_section
= p
->u
.indirect
.section
;
11746 input_bfd
= input_section
->owner
;
11748 if (! bfd_get_section_contents (input_bfd
, input_section
,
11749 &ext
, 0, sizeof ext
))
11752 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
11754 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
11755 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
11756 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
11757 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
11758 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
11760 /* ri_gp_value is set by the function
11761 mips_elf32_section_processing when the section is
11762 finally written out. */
11764 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11765 elf_link_input_bfd ignores this section. */
11766 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11769 /* Size has been set in _bfd_mips_elf_always_size_sections. */
11770 BFD_ASSERT(o
->size
== sizeof (Elf32_External_RegInfo
));
11772 /* Skip this section later on (I don't think this currently
11773 matters, but someday it might). */
11774 o
->map_head
.link_order
= NULL
;
11779 if (strcmp (o
->name
, ".mdebug") == 0)
11781 struct extsym_info einfo
;
11784 /* We have found the .mdebug section in the output file.
11785 Look through all the link_orders comprising it and merge
11786 the information together. */
11787 symhdr
->magic
= swap
->sym_magic
;
11788 /* FIXME: What should the version stamp be? */
11789 symhdr
->vstamp
= 0;
11790 symhdr
->ilineMax
= 0;
11791 symhdr
->cbLine
= 0;
11792 symhdr
->idnMax
= 0;
11793 symhdr
->ipdMax
= 0;
11794 symhdr
->isymMax
= 0;
11795 symhdr
->ioptMax
= 0;
11796 symhdr
->iauxMax
= 0;
11797 symhdr
->issMax
= 0;
11798 symhdr
->issExtMax
= 0;
11799 symhdr
->ifdMax
= 0;
11801 symhdr
->iextMax
= 0;
11803 /* We accumulate the debugging information itself in the
11804 debug_info structure. */
11806 debug
.external_dnr
= NULL
;
11807 debug
.external_pdr
= NULL
;
11808 debug
.external_sym
= NULL
;
11809 debug
.external_opt
= NULL
;
11810 debug
.external_aux
= NULL
;
11812 debug
.ssext
= debug
.ssext_end
= NULL
;
11813 debug
.external_fdr
= NULL
;
11814 debug
.external_rfd
= NULL
;
11815 debug
.external_ext
= debug
.external_ext_end
= NULL
;
11817 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
11818 if (mdebug_handle
== NULL
)
11822 esym
.cobol_main
= 0;
11826 esym
.asym
.iss
= issNil
;
11827 esym
.asym
.st
= stLocal
;
11828 esym
.asym
.reserved
= 0;
11829 esym
.asym
.index
= indexNil
;
11831 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
11833 esym
.asym
.sc
= sc
[i
];
11834 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
11837 esym
.asym
.value
= s
->vma
;
11838 last
= s
->vma
+ s
->size
;
11841 esym
.asym
.value
= last
;
11842 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
11843 secname
[i
], &esym
))
11847 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11849 asection
*input_section
;
11851 const struct ecoff_debug_swap
*input_swap
;
11852 struct ecoff_debug_info input_debug
;
11856 if (p
->type
!= bfd_indirect_link_order
)
11858 if (p
->type
== bfd_data_link_order
)
11863 input_section
= p
->u
.indirect
.section
;
11864 input_bfd
= input_section
->owner
;
11866 if (!is_mips_elf (input_bfd
))
11868 /* I don't know what a non MIPS ELF bfd would be
11869 doing with a .mdebug section, but I don't really
11870 want to deal with it. */
11874 input_swap
= (get_elf_backend_data (input_bfd
)
11875 ->elf_backend_ecoff_debug_swap
);
11877 BFD_ASSERT (p
->size
== input_section
->size
);
11879 /* The ECOFF linking code expects that we have already
11880 read in the debugging information and set up an
11881 ecoff_debug_info structure, so we do that now. */
11882 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
11886 if (! (bfd_ecoff_debug_accumulate
11887 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
11888 &input_debug
, input_swap
, info
)))
11891 /* Loop through the external symbols. For each one with
11892 interesting information, try to find the symbol in
11893 the linker global hash table and save the information
11894 for the output external symbols. */
11895 eraw_src
= input_debug
.external_ext
;
11896 eraw_end
= (eraw_src
11897 + (input_debug
.symbolic_header
.iextMax
11898 * input_swap
->external_ext_size
));
11900 eraw_src
< eraw_end
;
11901 eraw_src
+= input_swap
->external_ext_size
)
11905 struct mips_elf_link_hash_entry
*h
;
11907 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
11908 if (ext
.asym
.sc
== scNil
11909 || ext
.asym
.sc
== scUndefined
11910 || ext
.asym
.sc
== scSUndefined
)
11913 name
= input_debug
.ssext
+ ext
.asym
.iss
;
11914 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
11915 name
, FALSE
, FALSE
, TRUE
);
11916 if (h
== NULL
|| h
->esym
.ifd
!= -2)
11921 BFD_ASSERT (ext
.ifd
11922 < input_debug
.symbolic_header
.ifdMax
);
11923 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
11929 /* Free up the information we just read. */
11930 free (input_debug
.line
);
11931 free (input_debug
.external_dnr
);
11932 free (input_debug
.external_pdr
);
11933 free (input_debug
.external_sym
);
11934 free (input_debug
.external_opt
);
11935 free (input_debug
.external_aux
);
11936 free (input_debug
.ss
);
11937 free (input_debug
.ssext
);
11938 free (input_debug
.external_fdr
);
11939 free (input_debug
.external_rfd
);
11940 free (input_debug
.external_ext
);
11942 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11943 elf_link_input_bfd ignores this section. */
11944 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11947 if (SGI_COMPAT (abfd
) && info
->shared
)
11949 /* Create .rtproc section. */
11950 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
11951 if (rtproc_sec
== NULL
)
11953 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
11954 | SEC_LINKER_CREATED
| SEC_READONLY
);
11956 rtproc_sec
= bfd_make_section_with_flags (abfd
,
11959 if (rtproc_sec
== NULL
11960 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
11964 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
11970 /* Build the external symbol information. */
11973 einfo
.debug
= &debug
;
11975 einfo
.failed
= FALSE
;
11976 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
11977 mips_elf_output_extsym
, &einfo
);
11981 /* Set the size of the .mdebug section. */
11982 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
11984 /* Skip this section later on (I don't think this currently
11985 matters, but someday it might). */
11986 o
->map_head
.link_order
= NULL
;
11991 if (CONST_STRNEQ (o
->name
, ".gptab."))
11993 const char *subname
;
11996 Elf32_External_gptab
*ext_tab
;
11999 /* The .gptab.sdata and .gptab.sbss sections hold
12000 information describing how the small data area would
12001 change depending upon the -G switch. These sections
12002 not used in executables files. */
12003 if (! info
->relocatable
)
12005 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
12007 asection
*input_section
;
12009 if (p
->type
!= bfd_indirect_link_order
)
12011 if (p
->type
== bfd_data_link_order
)
12016 input_section
= p
->u
.indirect
.section
;
12018 /* Hack: reset the SEC_HAS_CONTENTS flag so that
12019 elf_link_input_bfd ignores this section. */
12020 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
12023 /* Skip this section later on (I don't think this
12024 currently matters, but someday it might). */
12025 o
->map_head
.link_order
= NULL
;
12027 /* Really remove the section. */
12028 bfd_section_list_remove (abfd
, o
);
12029 --abfd
->section_count
;
12034 /* There is one gptab for initialized data, and one for
12035 uninitialized data. */
12036 if (strcmp (o
->name
, ".gptab.sdata") == 0)
12037 gptab_data_sec
= o
;
12038 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
12042 (*_bfd_error_handler
)
12043 (_("%s: illegal section name `%s'"),
12044 bfd_get_filename (abfd
), o
->name
);
12045 bfd_set_error (bfd_error_nonrepresentable_section
);
12049 /* The linker script always combines .gptab.data and
12050 .gptab.sdata into .gptab.sdata, and likewise for
12051 .gptab.bss and .gptab.sbss. It is possible that there is
12052 no .sdata or .sbss section in the output file, in which
12053 case we must change the name of the output section. */
12054 subname
= o
->name
+ sizeof ".gptab" - 1;
12055 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
12057 if (o
== gptab_data_sec
)
12058 o
->name
= ".gptab.data";
12060 o
->name
= ".gptab.bss";
12061 subname
= o
->name
+ sizeof ".gptab" - 1;
12062 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
12065 /* Set up the first entry. */
12067 amt
= c
* sizeof (Elf32_gptab
);
12068 tab
= bfd_malloc (amt
);
12071 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
12072 tab
[0].gt_header
.gt_unused
= 0;
12074 /* Combine the input sections. */
12075 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
12077 asection
*input_section
;
12079 bfd_size_type size
;
12080 unsigned long last
;
12081 bfd_size_type gpentry
;
12083 if (p
->type
!= bfd_indirect_link_order
)
12085 if (p
->type
== bfd_data_link_order
)
12090 input_section
= p
->u
.indirect
.section
;
12091 input_bfd
= input_section
->owner
;
12093 /* Combine the gptab entries for this input section one
12094 by one. We know that the input gptab entries are
12095 sorted by ascending -G value. */
12096 size
= input_section
->size
;
12098 for (gpentry
= sizeof (Elf32_External_gptab
);
12100 gpentry
+= sizeof (Elf32_External_gptab
))
12102 Elf32_External_gptab ext_gptab
;
12103 Elf32_gptab int_gptab
;
12109 if (! (bfd_get_section_contents
12110 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
12111 sizeof (Elf32_External_gptab
))))
12117 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
12119 val
= int_gptab
.gt_entry
.gt_g_value
;
12120 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
12123 for (look
= 1; look
< c
; look
++)
12125 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
12126 tab
[look
].gt_entry
.gt_bytes
+= add
;
12128 if (tab
[look
].gt_entry
.gt_g_value
== val
)
12134 Elf32_gptab
*new_tab
;
12137 /* We need a new table entry. */
12138 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
12139 new_tab
= bfd_realloc (tab
, amt
);
12140 if (new_tab
== NULL
)
12146 tab
[c
].gt_entry
.gt_g_value
= val
;
12147 tab
[c
].gt_entry
.gt_bytes
= add
;
12149 /* Merge in the size for the next smallest -G
12150 value, since that will be implied by this new
12153 for (look
= 1; look
< c
; look
++)
12155 if (tab
[look
].gt_entry
.gt_g_value
< val
12157 || (tab
[look
].gt_entry
.gt_g_value
12158 > tab
[max
].gt_entry
.gt_g_value
)))
12162 tab
[c
].gt_entry
.gt_bytes
+=
12163 tab
[max
].gt_entry
.gt_bytes
;
12168 last
= int_gptab
.gt_entry
.gt_bytes
;
12171 /* Hack: reset the SEC_HAS_CONTENTS flag so that
12172 elf_link_input_bfd ignores this section. */
12173 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
12176 /* The table must be sorted by -G value. */
12178 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
12180 /* Swap out the table. */
12181 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
12182 ext_tab
= bfd_alloc (abfd
, amt
);
12183 if (ext_tab
== NULL
)
12189 for (j
= 0; j
< c
; j
++)
12190 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
12193 o
->size
= c
* sizeof (Elf32_External_gptab
);
12194 o
->contents
= (bfd_byte
*) ext_tab
;
12196 /* Skip this section later on (I don't think this currently
12197 matters, but someday it might). */
12198 o
->map_head
.link_order
= NULL
;
12202 /* Invoke the regular ELF backend linker to do all the work. */
12203 if (!bfd_elf_final_link (abfd
, info
))
12206 /* Now write out the computed sections. */
12208 if (reginfo_sec
!= NULL
)
12210 Elf32_External_RegInfo ext
;
12212 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
12213 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
12217 if (mdebug_sec
!= NULL
)
12219 BFD_ASSERT (abfd
->output_has_begun
);
12220 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
12222 mdebug_sec
->filepos
))
12225 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
12228 if (gptab_data_sec
!= NULL
)
12230 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
12231 gptab_data_sec
->contents
,
12232 0, gptab_data_sec
->size
))
12236 if (gptab_bss_sec
!= NULL
)
12238 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
12239 gptab_bss_sec
->contents
,
12240 0, gptab_bss_sec
->size
))
12244 if (SGI_COMPAT (abfd
))
12246 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
12247 if (rtproc_sec
!= NULL
)
12249 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
12250 rtproc_sec
->contents
,
12251 0, rtproc_sec
->size
))
12259 /* Structure for saying that BFD machine EXTENSION extends BASE. */
12261 struct mips_mach_extension
{
12262 unsigned long extension
, base
;
12266 /* An array describing how BFD machines relate to one another. The entries
12267 are ordered topologically with MIPS I extensions listed last. */
12269 static const struct mips_mach_extension mips_mach_extensions
[] = {
12270 /* MIPS64r2 extensions. */
12271 { bfd_mach_mips_octeon
, bfd_mach_mipsisa64r2
},
12273 /* MIPS64 extensions. */
12274 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
12275 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
12276 { bfd_mach_mips_xlr
, bfd_mach_mipsisa64
},
12277 { bfd_mach_mips_loongson_3a
, bfd_mach_mipsisa64
},
12279 /* MIPS V extensions. */
12280 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
12282 /* R10000 extensions. */
12283 { bfd_mach_mips12000
, bfd_mach_mips10000
},
12284 { bfd_mach_mips14000
, bfd_mach_mips10000
},
12285 { bfd_mach_mips16000
, bfd_mach_mips10000
},
12287 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
12288 vr5400 ISA, but doesn't include the multimedia stuff. It seems
12289 better to allow vr5400 and vr5500 code to be merged anyway, since
12290 many libraries will just use the core ISA. Perhaps we could add
12291 some sort of ASE flag if this ever proves a problem. */
12292 { bfd_mach_mips5500
, bfd_mach_mips5400
},
12293 { bfd_mach_mips5400
, bfd_mach_mips5000
},
12295 /* MIPS IV extensions. */
12296 { bfd_mach_mips5
, bfd_mach_mips8000
},
12297 { bfd_mach_mips10000
, bfd_mach_mips8000
},
12298 { bfd_mach_mips5000
, bfd_mach_mips8000
},
12299 { bfd_mach_mips7000
, bfd_mach_mips8000
},
12300 { bfd_mach_mips9000
, bfd_mach_mips8000
},
12302 /* VR4100 extensions. */
12303 { bfd_mach_mips4120
, bfd_mach_mips4100
},
12304 { bfd_mach_mips4111
, bfd_mach_mips4100
},
12306 /* MIPS III extensions. */
12307 { bfd_mach_mips_loongson_2e
, bfd_mach_mips4000
},
12308 { bfd_mach_mips_loongson_2f
, bfd_mach_mips4000
},
12309 { bfd_mach_mips8000
, bfd_mach_mips4000
},
12310 { bfd_mach_mips4650
, bfd_mach_mips4000
},
12311 { bfd_mach_mips4600
, bfd_mach_mips4000
},
12312 { bfd_mach_mips4400
, bfd_mach_mips4000
},
12313 { bfd_mach_mips4300
, bfd_mach_mips4000
},
12314 { bfd_mach_mips4100
, bfd_mach_mips4000
},
12315 { bfd_mach_mips4010
, bfd_mach_mips4000
},
12317 /* MIPS32 extensions. */
12318 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
12320 /* MIPS II extensions. */
12321 { bfd_mach_mips4000
, bfd_mach_mips6000
},
12322 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
12324 /* MIPS I extensions. */
12325 { bfd_mach_mips6000
, bfd_mach_mips3000
},
12326 { bfd_mach_mips3900
, bfd_mach_mips3000
}
12330 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
12333 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
12337 if (extension
== base
)
12340 if (base
== bfd_mach_mipsisa32
12341 && mips_mach_extends_p (bfd_mach_mipsisa64
, extension
))
12344 if (base
== bfd_mach_mipsisa32r2
12345 && mips_mach_extends_p (bfd_mach_mipsisa64r2
, extension
))
12348 for (i
= 0; i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
12349 if (extension
== mips_mach_extensions
[i
].extension
)
12351 extension
= mips_mach_extensions
[i
].base
;
12352 if (extension
== base
)
12360 /* Return true if the given ELF header flags describe a 32-bit binary. */
12363 mips_32bit_flags_p (flagword flags
)
12365 return ((flags
& EF_MIPS_32BITMODE
) != 0
12366 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
12367 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
12368 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
12369 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
12370 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
12371 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
);
12375 /* Merge object attributes from IBFD into OBFD. Raise an error if
12376 there are conflicting attributes. */
12378 mips_elf_merge_obj_attributes (bfd
*ibfd
, bfd
*obfd
)
12380 obj_attribute
*in_attr
;
12381 obj_attribute
*out_attr
;
12383 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
12385 /* This is the first object. Copy the attributes. */
12386 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
12388 /* Use the Tag_null value to indicate the attributes have been
12390 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
12395 /* Check for conflicting Tag_GNU_MIPS_ABI_FP attributes and merge
12396 non-conflicting ones. */
12397 in_attr
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
12398 out_attr
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
12399 if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12401 out_attr
[Tag_GNU_MIPS_ABI_FP
].type
= 1;
12402 if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
12403 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
12404 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
12406 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
12408 (_("Warning: %B uses unknown floating point ABI %d"), ibfd
,
12409 in_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
12410 else if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
12412 (_("Warning: %B uses unknown floating point ABI %d"), obfd
,
12413 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
12415 switch (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12418 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12422 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
12428 (_("Warning: %B uses hard float, %B uses soft float"),
12434 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
12444 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12448 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
12454 (_("Warning: %B uses hard float, %B uses soft float"),
12460 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
12470 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12476 (_("Warning: %B uses hard float, %B uses soft float"),
12486 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12490 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
12496 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
12502 (_("Warning: %B uses hard float, %B uses soft float"),
12516 /* Merge Tag_compatibility attributes and any common GNU ones. */
12517 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
12522 /* Merge backend specific data from an object file to the output
12523 object file when linking. */
12526 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
12528 flagword old_flags
;
12529 flagword new_flags
;
12531 bfd_boolean null_input_bfd
= TRUE
;
12534 /* Check if we have the same endianness. */
12535 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
12537 (*_bfd_error_handler
)
12538 (_("%B: endianness incompatible with that of the selected emulation"),
12543 if (!is_mips_elf (ibfd
) || !is_mips_elf (obfd
))
12546 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
12548 (*_bfd_error_handler
)
12549 (_("%B: ABI is incompatible with that of the selected emulation"),
12554 if (!mips_elf_merge_obj_attributes (ibfd
, obfd
))
12557 new_flags
= elf_elfheader (ibfd
)->e_flags
;
12558 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
12559 old_flags
= elf_elfheader (obfd
)->e_flags
;
12561 if (! elf_flags_init (obfd
))
12563 elf_flags_init (obfd
) = TRUE
;
12564 elf_elfheader (obfd
)->e_flags
= new_flags
;
12565 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
12566 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
12568 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
12569 && (bfd_get_arch_info (obfd
)->the_default
12570 || mips_mach_extends_p (bfd_get_mach (obfd
),
12571 bfd_get_mach (ibfd
))))
12573 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
12574 bfd_get_mach (ibfd
)))
12581 /* Check flag compatibility. */
12583 new_flags
&= ~EF_MIPS_NOREORDER
;
12584 old_flags
&= ~EF_MIPS_NOREORDER
;
12586 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
12587 doesn't seem to matter. */
12588 new_flags
&= ~EF_MIPS_XGOT
;
12589 old_flags
&= ~EF_MIPS_XGOT
;
12591 /* MIPSpro generates ucode info in n64 objects. Again, we should
12592 just be able to ignore this. */
12593 new_flags
&= ~EF_MIPS_UCODE
;
12594 old_flags
&= ~EF_MIPS_UCODE
;
12596 /* DSOs should only be linked with CPIC code. */
12597 if ((ibfd
->flags
& DYNAMIC
) != 0)
12598 new_flags
|= EF_MIPS_PIC
| EF_MIPS_CPIC
;
12600 if (new_flags
== old_flags
)
12603 /* Check to see if the input BFD actually contains any sections.
12604 If not, its flags may not have been initialised either, but it cannot
12605 actually cause any incompatibility. */
12606 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
12608 /* Ignore synthetic sections and empty .text, .data and .bss sections
12609 which are automatically generated by gas. Also ignore fake
12610 (s)common sections, since merely defining a common symbol does
12611 not affect compatibility. */
12612 if ((sec
->flags
& SEC_IS_COMMON
) == 0
12613 && strcmp (sec
->name
, ".reginfo")
12614 && strcmp (sec
->name
, ".mdebug")
12616 || (strcmp (sec
->name
, ".text")
12617 && strcmp (sec
->name
, ".data")
12618 && strcmp (sec
->name
, ".bss"))))
12620 null_input_bfd
= FALSE
;
12624 if (null_input_bfd
)
12629 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
12630 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
12632 (*_bfd_error_handler
)
12633 (_("%B: warning: linking abicalls files with non-abicalls files"),
12638 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
12639 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
12640 if (! (new_flags
& EF_MIPS_PIC
))
12641 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
12643 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
12644 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
12646 /* Compare the ISAs. */
12647 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
12649 (*_bfd_error_handler
)
12650 (_("%B: linking 32-bit code with 64-bit code"),
12654 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
12656 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
12657 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
12659 /* Copy the architecture info from IBFD to OBFD. Also copy
12660 the 32-bit flag (if set) so that we continue to recognise
12661 OBFD as a 32-bit binary. */
12662 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
12663 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
12664 elf_elfheader (obfd
)->e_flags
12665 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
12667 /* Copy across the ABI flags if OBFD doesn't use them
12668 and if that was what caused us to treat IBFD as 32-bit. */
12669 if ((old_flags
& EF_MIPS_ABI
) == 0
12670 && mips_32bit_flags_p (new_flags
)
12671 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
12672 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
12676 /* The ISAs aren't compatible. */
12677 (*_bfd_error_handler
)
12678 (_("%B: linking %s module with previous %s modules"),
12680 bfd_printable_name (ibfd
),
12681 bfd_printable_name (obfd
));
12686 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
12687 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
12689 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
12690 does set EI_CLASS differently from any 32-bit ABI. */
12691 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
12692 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
12693 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
12695 /* Only error if both are set (to different values). */
12696 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
12697 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
12698 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
12700 (*_bfd_error_handler
)
12701 (_("%B: ABI mismatch: linking %s module with previous %s modules"),
12703 elf_mips_abi_name (ibfd
),
12704 elf_mips_abi_name (obfd
));
12707 new_flags
&= ~EF_MIPS_ABI
;
12708 old_flags
&= ~EF_MIPS_ABI
;
12711 /* For now, allow arbitrary mixing of ASEs (retain the union). */
12712 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
12714 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
12716 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
12717 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
12720 /* Warn about any other mismatches */
12721 if (new_flags
!= old_flags
)
12723 (*_bfd_error_handler
)
12724 (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
12725 ibfd
, (unsigned long) new_flags
,
12726 (unsigned long) old_flags
);
12732 bfd_set_error (bfd_error_bad_value
);
12739 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
12742 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
12744 BFD_ASSERT (!elf_flags_init (abfd
)
12745 || elf_elfheader (abfd
)->e_flags
== flags
);
12747 elf_elfheader (abfd
)->e_flags
= flags
;
12748 elf_flags_init (abfd
) = TRUE
;
12753 _bfd_mips_elf_get_target_dtag (bfd_vma dtag
)
12757 default: return "";
12758 case DT_MIPS_RLD_VERSION
:
12759 return "MIPS_RLD_VERSION";
12760 case DT_MIPS_TIME_STAMP
:
12761 return "MIPS_TIME_STAMP";
12762 case DT_MIPS_ICHECKSUM
:
12763 return "MIPS_ICHECKSUM";
12764 case DT_MIPS_IVERSION
:
12765 return "MIPS_IVERSION";
12766 case DT_MIPS_FLAGS
:
12767 return "MIPS_FLAGS";
12768 case DT_MIPS_BASE_ADDRESS
:
12769 return "MIPS_BASE_ADDRESS";
12771 return "MIPS_MSYM";
12772 case DT_MIPS_CONFLICT
:
12773 return "MIPS_CONFLICT";
12774 case DT_MIPS_LIBLIST
:
12775 return "MIPS_LIBLIST";
12776 case DT_MIPS_LOCAL_GOTNO
:
12777 return "MIPS_LOCAL_GOTNO";
12778 case DT_MIPS_CONFLICTNO
:
12779 return "MIPS_CONFLICTNO";
12780 case DT_MIPS_LIBLISTNO
:
12781 return "MIPS_LIBLISTNO";
12782 case DT_MIPS_SYMTABNO
:
12783 return "MIPS_SYMTABNO";
12784 case DT_MIPS_UNREFEXTNO
:
12785 return "MIPS_UNREFEXTNO";
12786 case DT_MIPS_GOTSYM
:
12787 return "MIPS_GOTSYM";
12788 case DT_MIPS_HIPAGENO
:
12789 return "MIPS_HIPAGENO";
12790 case DT_MIPS_RLD_MAP
:
12791 return "MIPS_RLD_MAP";
12792 case DT_MIPS_DELTA_CLASS
:
12793 return "MIPS_DELTA_CLASS";
12794 case DT_MIPS_DELTA_CLASS_NO
:
12795 return "MIPS_DELTA_CLASS_NO";
12796 case DT_MIPS_DELTA_INSTANCE
:
12797 return "MIPS_DELTA_INSTANCE";
12798 case DT_MIPS_DELTA_INSTANCE_NO
:
12799 return "MIPS_DELTA_INSTANCE_NO";
12800 case DT_MIPS_DELTA_RELOC
:
12801 return "MIPS_DELTA_RELOC";
12802 case DT_MIPS_DELTA_RELOC_NO
:
12803 return "MIPS_DELTA_RELOC_NO";
12804 case DT_MIPS_DELTA_SYM
:
12805 return "MIPS_DELTA_SYM";
12806 case DT_MIPS_DELTA_SYM_NO
:
12807 return "MIPS_DELTA_SYM_NO";
12808 case DT_MIPS_DELTA_CLASSSYM
:
12809 return "MIPS_DELTA_CLASSSYM";
12810 case DT_MIPS_DELTA_CLASSSYM_NO
:
12811 return "MIPS_DELTA_CLASSSYM_NO";
12812 case DT_MIPS_CXX_FLAGS
:
12813 return "MIPS_CXX_FLAGS";
12814 case DT_MIPS_PIXIE_INIT
:
12815 return "MIPS_PIXIE_INIT";
12816 case DT_MIPS_SYMBOL_LIB
:
12817 return "MIPS_SYMBOL_LIB";
12818 case DT_MIPS_LOCALPAGE_GOTIDX
:
12819 return "MIPS_LOCALPAGE_GOTIDX";
12820 case DT_MIPS_LOCAL_GOTIDX
:
12821 return "MIPS_LOCAL_GOTIDX";
12822 case DT_MIPS_HIDDEN_GOTIDX
:
12823 return "MIPS_HIDDEN_GOTIDX";
12824 case DT_MIPS_PROTECTED_GOTIDX
:
12825 return "MIPS_PROTECTED_GOT_IDX";
12826 case DT_MIPS_OPTIONS
:
12827 return "MIPS_OPTIONS";
12828 case DT_MIPS_INTERFACE
:
12829 return "MIPS_INTERFACE";
12830 case DT_MIPS_DYNSTR_ALIGN
:
12831 return "DT_MIPS_DYNSTR_ALIGN";
12832 case DT_MIPS_INTERFACE_SIZE
:
12833 return "DT_MIPS_INTERFACE_SIZE";
12834 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
:
12835 return "DT_MIPS_RLD_TEXT_RESOLVE_ADDR";
12836 case DT_MIPS_PERF_SUFFIX
:
12837 return "DT_MIPS_PERF_SUFFIX";
12838 case DT_MIPS_COMPACT_SIZE
:
12839 return "DT_MIPS_COMPACT_SIZE";
12840 case DT_MIPS_GP_VALUE
:
12841 return "DT_MIPS_GP_VALUE";
12842 case DT_MIPS_AUX_DYNAMIC
:
12843 return "DT_MIPS_AUX_DYNAMIC";
12844 case DT_MIPS_PLTGOT
:
12845 return "DT_MIPS_PLTGOT";
12846 case DT_MIPS_RWPLT
:
12847 return "DT_MIPS_RWPLT";
12852 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
12856 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
12858 /* Print normal ELF private data. */
12859 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
12861 /* xgettext:c-format */
12862 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
12864 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
12865 fprintf (file
, _(" [abi=O32]"));
12866 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
12867 fprintf (file
, _(" [abi=O64]"));
12868 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
12869 fprintf (file
, _(" [abi=EABI32]"));
12870 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
12871 fprintf (file
, _(" [abi=EABI64]"));
12872 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
12873 fprintf (file
, _(" [abi unknown]"));
12874 else if (ABI_N32_P (abfd
))
12875 fprintf (file
, _(" [abi=N32]"));
12876 else if (ABI_64_P (abfd
))
12877 fprintf (file
, _(" [abi=64]"));
12879 fprintf (file
, _(" [no abi set]"));
12881 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
12882 fprintf (file
, " [mips1]");
12883 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
12884 fprintf (file
, " [mips2]");
12885 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
12886 fprintf (file
, " [mips3]");
12887 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
12888 fprintf (file
, " [mips4]");
12889 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
12890 fprintf (file
, " [mips5]");
12891 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
12892 fprintf (file
, " [mips32]");
12893 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
12894 fprintf (file
, " [mips64]");
12895 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
12896 fprintf (file
, " [mips32r2]");
12897 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
12898 fprintf (file
, " [mips64r2]");
12900 fprintf (file
, _(" [unknown ISA]"));
12902 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
12903 fprintf (file
, " [mdmx]");
12905 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
12906 fprintf (file
, " [mips16]");
12908 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
12909 fprintf (file
, " [32bitmode]");
12911 fprintf (file
, _(" [not 32bitmode]"));
12913 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NOREORDER
)
12914 fprintf (file
, " [noreorder]");
12916 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
12917 fprintf (file
, " [PIC]");
12919 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_CPIC
)
12920 fprintf (file
, " [CPIC]");
12922 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_XGOT
)
12923 fprintf (file
, " [XGOT]");
12925 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_UCODE
)
12926 fprintf (file
, " [UCODE]");
12928 fputc ('\n', file
);
12933 const struct bfd_elf_special_section _bfd_mips_elf_special_sections
[] =
12935 { STRING_COMMA_LEN (".lit4"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12936 { STRING_COMMA_LEN (".lit8"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12937 { STRING_COMMA_LEN (".mdebug"), 0, SHT_MIPS_DEBUG
, 0 },
12938 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12939 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12940 { STRING_COMMA_LEN (".ucode"), 0, SHT_MIPS_UCODE
, 0 },
12941 { NULL
, 0, 0, 0, 0 }
12944 /* Merge non visibility st_other attributes. Ensure that the
12945 STO_OPTIONAL flag is copied into h->other, even if this is not a
12946 definiton of the symbol. */
12948 _bfd_mips_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
12949 const Elf_Internal_Sym
*isym
,
12950 bfd_boolean definition
,
12951 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
12953 if ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1)) != 0)
12955 unsigned char other
;
12957 other
= (definition
? isym
->st_other
: h
->other
);
12958 other
&= ~ELF_ST_VISIBILITY (-1);
12959 h
->other
= other
| ELF_ST_VISIBILITY (h
->other
);
12963 && ELF_MIPS_IS_OPTIONAL (isym
->st_other
))
12964 h
->other
|= STO_OPTIONAL
;
12967 /* Decide whether an undefined symbol is special and can be ignored.
12968 This is the case for OPTIONAL symbols on IRIX. */
12970 _bfd_mips_elf_ignore_undef_symbol (struct elf_link_hash_entry
*h
)
12972 return ELF_MIPS_IS_OPTIONAL (h
->other
) ? TRUE
: FALSE
;
12976 _bfd_mips_elf_common_definition (Elf_Internal_Sym
*sym
)
12978 return (sym
->st_shndx
== SHN_COMMON
12979 || sym
->st_shndx
== SHN_MIPS_ACOMMON
12980 || sym
->st_shndx
== SHN_MIPS_SCOMMON
);
12983 /* Return address for Ith PLT stub in section PLT, for relocation REL
12984 or (bfd_vma) -1 if it should not be included. */
12987 _bfd_mips_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
12988 const arelent
*rel ATTRIBUTE_UNUSED
)
12991 + 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
)
12992 + i
* 4 * ARRAY_SIZE (mips_exec_plt_entry
));
12996 _bfd_mips_post_process_headers (bfd
*abfd
, struct bfd_link_info
*link_info
)
12998 struct mips_elf_link_hash_table
*htab
;
12999 Elf_Internal_Ehdr
*i_ehdrp
;
13001 i_ehdrp
= elf_elfheader (abfd
);
13004 htab
= mips_elf_hash_table (link_info
);
13005 BFD_ASSERT (htab
!= NULL
);
13007 if (htab
->use_plts_and_copy_relocs
&& !htab
->is_vxworks
)
13008 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 1;