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 Free Software Foundation, Inc.
5 Most of the information added by Ian Lance Taylor, Cygnus Support,
7 N32/64 ABI support added by Mark Mitchell, CodeSourcery, LLC.
8 <mark@codesourcery.com>
9 Traditional MIPS targets support added by Koundinya.K, Dansk Data
10 Elektronik & Operations Research Group. <kk@ddeorg.soft.net>
12 This file is part of BFD, the Binary File Descriptor library.
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
27 MA 02110-1301, USA. */
30 /* This file handles functionality common to the different MIPS ABI's. */
35 #include "libiberty.h"
37 #include "elfxx-mips.h"
39 #include "elf-vxworks.h"
41 /* Get the ECOFF swapping routines. */
43 #include "coff/symconst.h"
44 #include "coff/ecoff.h"
45 #include "coff/mips.h"
49 /* This structure is used to hold information about one GOT entry.
50 There are three types of entry:
52 (1) absolute addresses
54 (2) SYMBOL + OFFSET addresses, where SYMBOL is local to an input bfd
55 (abfd != NULL, symndx >= 0)
56 (3) SYMBOL addresses, where SYMBOL is not local to an input bfd
57 (abfd != NULL, symndx == -1)
59 Type (3) entries are treated differently for different types of GOT.
60 In the "master" GOT -- i.e. the one that describes every GOT
61 reference needed in the link -- the mips_got_entry is keyed on both
62 the symbol and the input bfd that references it. If it turns out
63 that we need multiple GOTs, we can then use this information to
64 create separate GOTs for each input bfd.
66 However, we want each of these separate GOTs to have at most one
67 entry for a given symbol, so their type (3) entries are keyed only
68 on the symbol. The input bfd given by the "abfd" field is somewhat
69 arbitrary in this case.
71 This means that when there are multiple GOTs, each GOT has a unique
72 mips_got_entry for every symbol within it. We can therefore use the
73 mips_got_entry fields (tls_type and gotidx) to track the symbol's
76 However, if it turns out that we need only a single GOT, we continue
77 to use the master GOT to describe it. There may therefore be several
78 mips_got_entries for the same symbol, each with a different input bfd.
79 We want to make sure that each symbol gets a unique GOT entry, so when
80 there's a single GOT, we use the symbol's hash entry, not the
81 mips_got_entry fields, to track a symbol's GOT index. */
84 /* The input bfd in which the symbol is defined. */
86 /* The index of the symbol, as stored in the relocation r_info, if
87 we have a local symbol; -1 otherwise. */
91 /* If abfd == NULL, an address that must be stored in the got. */
93 /* If abfd != NULL && symndx != -1, the addend of the relocation
94 that should be added to the symbol value. */
96 /* If abfd != NULL && symndx == -1, the hash table entry
97 corresponding to symbol in the GOT. The symbol's entry
98 is in the local area if h->global_got_area is GGA_NONE,
99 otherwise it is in the global area. */
100 struct mips_elf_link_hash_entry
*h
;
103 /* The TLS types included in this GOT entry (specifically, GD and
104 IE). The GD and IE flags can be added as we encounter new
105 relocations. LDM can also be set; it will always be alone, not
106 combined with any GD or IE flags. An LDM GOT entry will be
107 a local symbol entry with r_symndx == 0. */
108 unsigned char tls_type
;
110 /* The offset from the beginning of the .got section to the entry
111 corresponding to this symbol+addend. If it's a global symbol
112 whose offset is yet to be decided, it's going to be -1. */
116 /* This structure describes a range of addends: [MIN_ADDEND, MAX_ADDEND].
117 The structures form a non-overlapping list that is sorted by increasing
119 struct mips_got_page_range
121 struct mips_got_page_range
*next
;
122 bfd_signed_vma min_addend
;
123 bfd_signed_vma max_addend
;
126 /* This structure describes the range of addends that are applied to page
127 relocations against a given symbol. */
128 struct mips_got_page_entry
130 /* The input bfd in which the symbol is defined. */
132 /* The index of the symbol, as stored in the relocation r_info. */
134 /* The ranges for this page entry. */
135 struct mips_got_page_range
*ranges
;
136 /* The maximum number of page entries needed for RANGES. */
140 /* This structure is used to hold .got information when linking. */
144 /* The global symbol in the GOT with the lowest index in the dynamic
146 struct elf_link_hash_entry
*global_gotsym
;
147 /* The number of global .got entries. */
148 unsigned int global_gotno
;
149 /* The number of global .got entries that are in the GGA_RELOC_ONLY area. */
150 unsigned int reloc_only_gotno
;
151 /* The number of .got slots used for TLS. */
152 unsigned int tls_gotno
;
153 /* The first unused TLS .got entry. Used only during
154 mips_elf_initialize_tls_index. */
155 unsigned int tls_assigned_gotno
;
156 /* The number of local .got entries, eventually including page entries. */
157 unsigned int local_gotno
;
158 /* The maximum number of page entries needed. */
159 unsigned int page_gotno
;
160 /* The number of local .got entries we have used. */
161 unsigned int assigned_gotno
;
162 /* A hash table holding members of the got. */
163 struct htab
*got_entries
;
164 /* A hash table of mips_got_page_entry structures. */
165 struct htab
*got_page_entries
;
166 /* A hash table mapping input bfds to other mips_got_info. NULL
167 unless multi-got was necessary. */
168 struct htab
*bfd2got
;
169 /* In multi-got links, a pointer to the next got (err, rather, most
170 of the time, it points to the previous got). */
171 struct mips_got_info
*next
;
172 /* This is the GOT index of the TLS LDM entry for the GOT, MINUS_ONE
173 for none, or MINUS_TWO for not yet assigned. This is needed
174 because a single-GOT link may have multiple hash table entries
175 for the LDM. It does not get initialized in multi-GOT mode. */
176 bfd_vma tls_ldm_offset
;
179 /* Map an input bfd to a got in a multi-got link. */
181 struct mips_elf_bfd2got_hash
184 struct mips_got_info
*g
;
187 /* Structure passed when traversing the bfd2got hash table, used to
188 create and merge bfd's gots. */
190 struct mips_elf_got_per_bfd_arg
192 /* A hashtable that maps bfds to gots. */
194 /* The output bfd. */
196 /* The link information. */
197 struct bfd_link_info
*info
;
198 /* A pointer to the primary got, i.e., the one that's going to get
199 the implicit relocations from DT_MIPS_LOCAL_GOTNO and
201 struct mips_got_info
*primary
;
202 /* A non-primary got we're trying to merge with other input bfd's
204 struct mips_got_info
*current
;
205 /* The maximum number of got entries that can be addressed with a
207 unsigned int max_count
;
208 /* The maximum number of page entries needed by each got. */
209 unsigned int max_pages
;
210 /* The total number of global entries which will live in the
211 primary got and be automatically relocated. This includes
212 those not referenced by the primary GOT but included in
214 unsigned int global_count
;
217 /* Another structure used to pass arguments for got entries traversal. */
219 struct mips_elf_set_global_got_offset_arg
221 struct mips_got_info
*g
;
223 unsigned int needed_relocs
;
224 struct bfd_link_info
*info
;
227 /* A structure used to count TLS relocations or GOT entries, for GOT
228 entry or ELF symbol table traversal. */
230 struct mips_elf_count_tls_arg
232 struct bfd_link_info
*info
;
236 struct _mips_elf_section_data
238 struct bfd_elf_section_data elf
;
245 #define mips_elf_section_data(sec) \
246 ((struct _mips_elf_section_data *) elf_section_data (sec))
248 #define is_mips_elf(bfd) \
249 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
250 && elf_tdata (bfd) != NULL \
251 && elf_object_id (bfd) == MIPS_ELF_DATA)
253 /* The ABI says that every symbol used by dynamic relocations must have
254 a global GOT entry. Among other things, this provides the dynamic
255 linker with a free, directly-indexed cache. The GOT can therefore
256 contain symbols that are not referenced by GOT relocations themselves
257 (in other words, it may have symbols that are not referenced by things
258 like R_MIPS_GOT16 and R_MIPS_GOT_PAGE).
260 GOT relocations are less likely to overflow if we put the associated
261 GOT entries towards the beginning. We therefore divide the global
262 GOT entries into two areas: "normal" and "reloc-only". Entries in
263 the first area can be used for both dynamic relocations and GP-relative
264 accesses, while those in the "reloc-only" area are for dynamic
267 These GGA_* ("Global GOT Area") values are organised so that lower
268 values are more general than higher values. Also, non-GGA_NONE
269 values are ordered by the position of the area in the GOT. */
271 #define GGA_RELOC_ONLY 1
274 /* Information about a non-PIC interface to a PIC function. There are
275 two ways of creating these interfaces. The first is to add:
278 addiu $25,$25,%lo(func)
280 immediately before a PIC function "func". The second is to add:
284 addiu $25,$25,%lo(func)
286 to a separate trampoline section.
288 Stubs of the first kind go in a new section immediately before the
289 target function. Stubs of the second kind go in a single section
290 pointed to by the hash table's "strampoline" field. */
291 struct mips_elf_la25_stub
{
292 /* The generated section that contains this stub. */
293 asection
*stub_section
;
295 /* The offset of the stub from the start of STUB_SECTION. */
298 /* One symbol for the original function. Its location is available
299 in H->root.root.u.def. */
300 struct mips_elf_link_hash_entry
*h
;
303 /* Macros for populating a mips_elf_la25_stub. */
305 #define LA25_LUI(VAL) (0x3c190000 | (VAL)) /* lui t9,VAL */
306 #define LA25_J(VAL) (0x08000000 | (((VAL) >> 2) & 0x3ffffff)) /* j VAL */
307 #define LA25_ADDIU(VAL) (0x27390000 | (VAL)) /* addiu t9,t9,VAL */
309 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
310 the dynamic symbols. */
312 struct mips_elf_hash_sort_data
314 /* The symbol in the global GOT with the lowest dynamic symbol table
316 struct elf_link_hash_entry
*low
;
317 /* The least dynamic symbol table index corresponding to a non-TLS
318 symbol with a GOT entry. */
319 long min_got_dynindx
;
320 /* The greatest dynamic symbol table index corresponding to a symbol
321 with a GOT entry that is not referenced (e.g., a dynamic symbol
322 with dynamic relocations pointing to it from non-primary GOTs). */
323 long max_unref_got_dynindx
;
324 /* The greatest dynamic symbol table index not corresponding to a
325 symbol without a GOT entry. */
326 long max_non_got_dynindx
;
329 /* The MIPS ELF linker needs additional information for each symbol in
330 the global hash table. */
332 struct mips_elf_link_hash_entry
334 struct elf_link_hash_entry root
;
336 /* External symbol information. */
339 /* The la25 stub we have created for ths symbol, if any. */
340 struct mips_elf_la25_stub
*la25_stub
;
342 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
344 unsigned int possibly_dynamic_relocs
;
346 /* If there is a stub that 32 bit functions should use to call this
347 16 bit function, this points to the section containing the stub. */
350 /* If there is a stub that 16 bit functions should use to call this
351 32 bit function, this points to the section containing the stub. */
354 /* This is like the call_stub field, but it is used if the function
355 being called returns a floating point value. */
356 asection
*call_fp_stub
;
360 #define GOT_TLS_LDM 2
362 #define GOT_TLS_OFFSET_DONE 0x40
363 #define GOT_TLS_DONE 0x80
364 unsigned char tls_type
;
366 /* This is only used in single-GOT mode; in multi-GOT mode there
367 is one mips_got_entry per GOT entry, so the offset is stored
368 there. In single-GOT mode there may be many mips_got_entry
369 structures all referring to the same GOT slot. It might be
370 possible to use root.got.offset instead, but that field is
371 overloaded already. */
372 bfd_vma tls_got_offset
;
374 /* The highest GGA_* value that satisfies all references to this symbol. */
375 unsigned int global_got_area
: 2;
377 /* True if one of the relocations described by possibly_dynamic_relocs
378 is against a readonly section. */
379 unsigned int readonly_reloc
: 1;
381 /* True if there is a relocation against this symbol that must be
382 resolved by the static linker (in other words, if the relocation
383 cannot possibly be made dynamic). */
384 unsigned int has_static_relocs
: 1;
386 /* True if we must not create a .MIPS.stubs entry for this symbol.
387 This is set, for example, if there are relocations related to
388 taking the function's address, i.e. any but R_MIPS_CALL*16 ones.
389 See "MIPS ABI Supplement, 3rd Edition", p. 4-20. */
390 unsigned int no_fn_stub
: 1;
392 /* Whether we need the fn_stub; this is true if this symbol appears
393 in any relocs other than a 16 bit call. */
394 unsigned int need_fn_stub
: 1;
396 /* True if this symbol is referenced by branch relocations from
397 any non-PIC input file. This is used to determine whether an
398 la25 stub is required. */
399 unsigned int has_nonpic_branches
: 1;
401 /* Does this symbol need a traditional MIPS lazy-binding stub
402 (as opposed to a PLT entry)? */
403 unsigned int needs_lazy_stub
: 1;
406 /* MIPS ELF linker hash table. */
408 struct mips_elf_link_hash_table
410 struct elf_link_hash_table root
;
412 /* We no longer use this. */
413 /* String section indices for the dynamic section symbols. */
414 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
417 /* The number of .rtproc entries. */
418 bfd_size_type procedure_count
;
420 /* The size of the .compact_rel section (if SGI_COMPAT). */
421 bfd_size_type compact_rel_size
;
423 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
424 entry is set to the address of __rld_obj_head as in IRIX5. */
425 bfd_boolean use_rld_obj_head
;
427 /* This is the value of the __rld_map or __rld_obj_head symbol. */
430 /* This is set if we see any mips16 stub sections. */
431 bfd_boolean mips16_stubs_seen
;
433 /* True if we can generate copy relocs and PLTs. */
434 bfd_boolean use_plts_and_copy_relocs
;
436 /* True if we're generating code for VxWorks. */
437 bfd_boolean is_vxworks
;
439 /* True if we already reported the small-data section overflow. */
440 bfd_boolean small_data_overflow_reported
;
442 /* Shortcuts to some dynamic sections, or NULL if they are not
453 /* The master GOT information. */
454 struct mips_got_info
*got_info
;
456 /* The size of the PLT header in bytes. */
457 bfd_vma plt_header_size
;
459 /* The size of a PLT entry in bytes. */
460 bfd_vma plt_entry_size
;
462 /* The number of functions that need a lazy-binding stub. */
463 bfd_vma lazy_stub_count
;
465 /* The size of a function stub entry in bytes. */
466 bfd_vma function_stub_size
;
468 /* The number of reserved entries at the beginning of the GOT. */
469 unsigned int reserved_gotno
;
471 /* The section used for mips_elf_la25_stub trampolines.
472 See the comment above that structure for details. */
473 asection
*strampoline
;
475 /* A table of mips_elf_la25_stubs, indexed by (input_section, offset)
479 /* A function FN (NAME, IS, OS) that creates a new input section
480 called NAME and links it to output section OS. If IS is nonnull,
481 the new section should go immediately before it, otherwise it
482 should go at the (current) beginning of OS.
484 The function returns the new section on success, otherwise it
486 asection
*(*add_stub_section
) (const char *, asection
*, asection
*);
489 /* Get the MIPS ELF linker hash table from a link_info structure. */
491 #define mips_elf_hash_table(p) \
492 (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \
493 == MIPS_ELF_DATA ? ((struct mips_elf_link_hash_table *) ((p)->hash)) : NULL)
495 /* A structure used to communicate with htab_traverse callbacks. */
496 struct mips_htab_traverse_info
498 /* The usual link-wide information. */
499 struct bfd_link_info
*info
;
502 /* Starts off FALSE and is set to TRUE if the link should be aborted. */
506 #define TLS_RELOC_P(r_type) \
507 (r_type == R_MIPS_TLS_DTPMOD32 \
508 || r_type == R_MIPS_TLS_DTPMOD64 \
509 || r_type == R_MIPS_TLS_DTPREL32 \
510 || r_type == R_MIPS_TLS_DTPREL64 \
511 || r_type == R_MIPS_TLS_GD \
512 || r_type == R_MIPS_TLS_LDM \
513 || r_type == R_MIPS_TLS_DTPREL_HI16 \
514 || r_type == R_MIPS_TLS_DTPREL_LO16 \
515 || r_type == R_MIPS_TLS_GOTTPREL \
516 || r_type == R_MIPS_TLS_TPREL32 \
517 || r_type == R_MIPS_TLS_TPREL64 \
518 || r_type == R_MIPS_TLS_TPREL_HI16 \
519 || r_type == R_MIPS_TLS_TPREL_LO16)
521 /* Structure used to pass information to mips_elf_output_extsym. */
526 struct bfd_link_info
*info
;
527 struct ecoff_debug_info
*debug
;
528 const struct ecoff_debug_swap
*swap
;
532 /* The names of the runtime procedure table symbols used on IRIX5. */
534 static const char * const mips_elf_dynsym_rtproc_names
[] =
537 "_procedure_string_table",
538 "_procedure_table_size",
542 /* These structures are used to generate the .compact_rel section on
547 unsigned long id1
; /* Always one? */
548 unsigned long num
; /* Number of compact relocation entries. */
549 unsigned long id2
; /* Always two? */
550 unsigned long offset
; /* The file offset of the first relocation. */
551 unsigned long reserved0
; /* Zero? */
552 unsigned long reserved1
; /* Zero? */
561 bfd_byte reserved0
[4];
562 bfd_byte reserved1
[4];
563 } Elf32_External_compact_rel
;
567 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
568 unsigned int rtype
: 4; /* Relocation types. See below. */
569 unsigned int dist2to
: 8;
570 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
571 unsigned long konst
; /* KONST field. See below. */
572 unsigned long vaddr
; /* VADDR to be relocated. */
577 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
578 unsigned int rtype
: 4; /* Relocation types. See below. */
579 unsigned int dist2to
: 8;
580 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
581 unsigned long konst
; /* KONST field. See below. */
589 } Elf32_External_crinfo
;
595 } Elf32_External_crinfo2
;
597 /* These are the constants used to swap the bitfields in a crinfo. */
599 #define CRINFO_CTYPE (0x1)
600 #define CRINFO_CTYPE_SH (31)
601 #define CRINFO_RTYPE (0xf)
602 #define CRINFO_RTYPE_SH (27)
603 #define CRINFO_DIST2TO (0xff)
604 #define CRINFO_DIST2TO_SH (19)
605 #define CRINFO_RELVADDR (0x7ffff)
606 #define CRINFO_RELVADDR_SH (0)
608 /* A compact relocation info has long (3 words) or short (2 words)
609 formats. A short format doesn't have VADDR field and relvaddr
610 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
611 #define CRF_MIPS_LONG 1
612 #define CRF_MIPS_SHORT 0
614 /* There are 4 types of compact relocation at least. The value KONST
615 has different meaning for each type:
618 CT_MIPS_REL32 Address in data
619 CT_MIPS_WORD Address in word (XXX)
620 CT_MIPS_GPHI_LO GP - vaddr
621 CT_MIPS_JMPAD Address to jump
624 #define CRT_MIPS_REL32 0xa
625 #define CRT_MIPS_WORD 0xb
626 #define CRT_MIPS_GPHI_LO 0xc
627 #define CRT_MIPS_JMPAD 0xd
629 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
630 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
631 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
632 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
634 /* The structure of the runtime procedure descriptor created by the
635 loader for use by the static exception system. */
637 typedef struct runtime_pdr
{
638 bfd_vma adr
; /* Memory address of start of procedure. */
639 long regmask
; /* Save register mask. */
640 long regoffset
; /* Save register offset. */
641 long fregmask
; /* Save floating point register mask. */
642 long fregoffset
; /* Save floating point register offset. */
643 long frameoffset
; /* Frame size. */
644 short framereg
; /* Frame pointer register. */
645 short pcreg
; /* Offset or reg of return pc. */
646 long irpss
; /* Index into the runtime string table. */
648 struct exception_info
*exception_info
;/* Pointer to exception array. */
650 #define cbRPDR sizeof (RPDR)
651 #define rpdNil ((pRPDR) 0)
653 static struct mips_got_entry
*mips_elf_create_local_got_entry
654 (bfd
*, struct bfd_link_info
*, bfd
*, bfd_vma
, unsigned long,
655 struct mips_elf_link_hash_entry
*, int);
656 static bfd_boolean mips_elf_sort_hash_table_f
657 (struct mips_elf_link_hash_entry
*, void *);
658 static bfd_vma mips_elf_high
660 static bfd_boolean mips_elf_create_dynamic_relocation
661 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
662 struct mips_elf_link_hash_entry
*, asection
*, bfd_vma
,
663 bfd_vma
*, asection
*);
664 static hashval_t mips_elf_got_entry_hash
666 static bfd_vma mips_elf_adjust_gp
667 (bfd
*, struct mips_got_info
*, bfd
*);
668 static struct mips_got_info
*mips_elf_got_for_ibfd
669 (struct mips_got_info
*, bfd
*);
671 /* This will be used when we sort the dynamic relocation records. */
672 static bfd
*reldyn_sorting_bfd
;
674 /* True if ABFD is for CPUs with load interlocking that include
675 non-MIPS1 CPUs and R3900. */
676 #define LOAD_INTERLOCKS_P(abfd) \
677 ( ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) != E_MIPS_ARCH_1) \
678 || ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_3900))
680 /* True if ABFD is for CPUs that are faster if JAL is converted to BAL.
681 This should be safe for all architectures. We enable this predicate
682 for RM9000 for now. */
683 #define JAL_TO_BAL_P(abfd) \
684 ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_9000)
686 /* True if ABFD is for CPUs that are faster if JALR is converted to BAL.
687 This should be safe for all architectures. We enable this predicate for
689 #define JALR_TO_BAL_P(abfd) 1
691 /* True if ABFD is for CPUs that are faster if JR is converted to B.
692 This should be safe for all architectures. We enable this predicate for
694 #define JR_TO_B_P(abfd) 1
696 /* True if ABFD is a PIC object. */
697 #define PIC_OBJECT_P(abfd) \
698 ((elf_elfheader (abfd)->e_flags & EF_MIPS_PIC) != 0)
700 /* Nonzero if ABFD is using the N32 ABI. */
701 #define ABI_N32_P(abfd) \
702 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
704 /* Nonzero if ABFD is using the N64 ABI. */
705 #define ABI_64_P(abfd) \
706 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
708 /* Nonzero if ABFD is using NewABI conventions. */
709 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
711 /* The IRIX compatibility level we are striving for. */
712 #define IRIX_COMPAT(abfd) \
713 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
715 /* Whether we are trying to be compatible with IRIX at all. */
716 #define SGI_COMPAT(abfd) \
717 (IRIX_COMPAT (abfd) != ict_none)
719 /* The name of the options section. */
720 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
721 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
723 /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
724 Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
725 #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
726 (strcmp (NAME, ".MIPS.options") == 0 || strcmp (NAME, ".options") == 0)
728 /* Whether the section is readonly. */
729 #define MIPS_ELF_READONLY_SECTION(sec) \
730 ((sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) \
731 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
733 /* The name of the stub section. */
734 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
736 /* The size of an external REL relocation. */
737 #define MIPS_ELF_REL_SIZE(abfd) \
738 (get_elf_backend_data (abfd)->s->sizeof_rel)
740 /* The size of an external RELA relocation. */
741 #define MIPS_ELF_RELA_SIZE(abfd) \
742 (get_elf_backend_data (abfd)->s->sizeof_rela)
744 /* The size of an external dynamic table entry. */
745 #define MIPS_ELF_DYN_SIZE(abfd) \
746 (get_elf_backend_data (abfd)->s->sizeof_dyn)
748 /* The size of a GOT entry. */
749 #define MIPS_ELF_GOT_SIZE(abfd) \
750 (get_elf_backend_data (abfd)->s->arch_size / 8)
752 /* The size of a symbol-table entry. */
753 #define MIPS_ELF_SYM_SIZE(abfd) \
754 (get_elf_backend_data (abfd)->s->sizeof_sym)
756 /* The default alignment for sections, as a power of two. */
757 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
758 (get_elf_backend_data (abfd)->s->log_file_align)
760 /* Get word-sized data. */
761 #define MIPS_ELF_GET_WORD(abfd, ptr) \
762 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
764 /* Put out word-sized data. */
765 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
767 ? bfd_put_64 (abfd, val, ptr) \
768 : bfd_put_32 (abfd, val, ptr))
770 /* The opcode for word-sized loads (LW or LD). */
771 #define MIPS_ELF_LOAD_WORD(abfd) \
772 (ABI_64_P (abfd) ? 0xdc000000 : 0x8c000000)
774 /* Add a dynamic symbol table-entry. */
775 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
776 _bfd_elf_add_dynamic_entry (info, tag, val)
778 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
779 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
781 /* Determine whether the internal relocation of index REL_IDX is REL
782 (zero) or RELA (non-zero). The assumption is that, if there are
783 two relocation sections for this section, one of them is REL and
784 the other is RELA. If the index of the relocation we're testing is
785 in range for the first relocation section, check that the external
786 relocation size is that for RELA. It is also assumed that, if
787 rel_idx is not in range for the first section, and this first
788 section contains REL relocs, then the relocation is in the second
789 section, that is RELA. */
790 #define MIPS_RELOC_RELA_P(abfd, sec, rel_idx) \
791 ((NUM_SHDR_ENTRIES (&elf_section_data (sec)->rel_hdr) \
792 * get_elf_backend_data (abfd)->s->int_rels_per_ext_rel \
793 > (bfd_vma)(rel_idx)) \
794 == (elf_section_data (sec)->rel_hdr.sh_entsize \
795 == (ABI_64_P (abfd) ? sizeof (Elf64_External_Rela) \
796 : sizeof (Elf32_External_Rela))))
798 /* The name of the dynamic relocation section. */
799 #define MIPS_ELF_REL_DYN_NAME(INFO) \
800 (mips_elf_hash_table (INFO)->is_vxworks ? ".rela.dyn" : ".rel.dyn")
802 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
803 from smaller values. Start with zero, widen, *then* decrement. */
804 #define MINUS_ONE (((bfd_vma)0) - 1)
805 #define MINUS_TWO (((bfd_vma)0) - 2)
807 /* The value to write into got[1] for SVR4 targets, to identify it is
808 a GNU object. The dynamic linker can then use got[1] to store the
810 #define MIPS_ELF_GNU_GOT1_MASK(abfd) \
811 ((bfd_vma) 1 << (ABI_64_P (abfd) ? 63 : 31))
813 /* The offset of $gp from the beginning of the .got section. */
814 #define ELF_MIPS_GP_OFFSET(INFO) \
815 (mips_elf_hash_table (INFO)->is_vxworks ? 0x0 : 0x7ff0)
817 /* The maximum size of the GOT for it to be addressable using 16-bit
819 #define MIPS_ELF_GOT_MAX_SIZE(INFO) (ELF_MIPS_GP_OFFSET (INFO) + 0x7fff)
821 /* Instructions which appear in a stub. */
822 #define STUB_LW(abfd) \
824 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
825 : 0x8f998010)) /* lw t9,0x8010(gp) */
826 #define STUB_MOVE(abfd) \
828 ? 0x03e0782d /* daddu t7,ra */ \
829 : 0x03e07821)) /* addu t7,ra */
830 #define STUB_LUI(VAL) (0x3c180000 + (VAL)) /* lui t8,VAL */
831 #define STUB_JALR 0x0320f809 /* jalr t9,ra */
832 #define STUB_ORI(VAL) (0x37180000 + (VAL)) /* ori t8,t8,VAL */
833 #define STUB_LI16U(VAL) (0x34180000 + (VAL)) /* ori t8,zero,VAL unsigned */
834 #define STUB_LI16S(abfd, VAL) \
836 ? (0x64180000 + (VAL)) /* daddiu t8,zero,VAL sign extended */ \
837 : (0x24180000 + (VAL)))) /* addiu t8,zero,VAL sign extended */
839 #define MIPS_FUNCTION_STUB_NORMAL_SIZE 16
840 #define MIPS_FUNCTION_STUB_BIG_SIZE 20
842 /* The name of the dynamic interpreter. This is put in the .interp
845 #define ELF_DYNAMIC_INTERPRETER(abfd) \
846 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
847 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
848 : "/usr/lib/libc.so.1")
851 #define MNAME(bfd,pre,pos) \
852 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
853 #define ELF_R_SYM(bfd, i) \
854 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
855 #define ELF_R_TYPE(bfd, i) \
856 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
857 #define ELF_R_INFO(bfd, s, t) \
858 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
860 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
861 #define ELF_R_SYM(bfd, i) \
863 #define ELF_R_TYPE(bfd, i) \
865 #define ELF_R_INFO(bfd, s, t) \
866 (ELF32_R_INFO (s, t))
869 /* The mips16 compiler uses a couple of special sections to handle
870 floating point arguments.
872 Section names that look like .mips16.fn.FNNAME contain stubs that
873 copy floating point arguments from the fp regs to the gp regs and
874 then jump to FNNAME. If any 32 bit function calls FNNAME, the
875 call should be redirected to the stub instead. If no 32 bit
876 function calls FNNAME, the stub should be discarded. We need to
877 consider any reference to the function, not just a call, because
878 if the address of the function is taken we will need the stub,
879 since the address might be passed to a 32 bit function.
881 Section names that look like .mips16.call.FNNAME contain stubs
882 that copy floating point arguments from the gp regs to the fp
883 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
884 then any 16 bit function that calls FNNAME should be redirected
885 to the stub instead. If FNNAME is not a 32 bit function, the
886 stub should be discarded.
888 .mips16.call.fp.FNNAME sections are similar, but contain stubs
889 which call FNNAME and then copy the return value from the fp regs
890 to the gp regs. These stubs store the return value in $18 while
891 calling FNNAME; any function which might call one of these stubs
892 must arrange to save $18 around the call. (This case is not
893 needed for 32 bit functions that call 16 bit functions, because
894 16 bit functions always return floating point values in both
897 Note that in all cases FNNAME might be defined statically.
898 Therefore, FNNAME is not used literally. Instead, the relocation
899 information will indicate which symbol the section is for.
901 We record any stubs that we find in the symbol table. */
903 #define FN_STUB ".mips16.fn."
904 #define CALL_STUB ".mips16.call."
905 #define CALL_FP_STUB ".mips16.call.fp."
907 #define FN_STUB_P(name) CONST_STRNEQ (name, FN_STUB)
908 #define CALL_STUB_P(name) CONST_STRNEQ (name, CALL_STUB)
909 #define CALL_FP_STUB_P(name) CONST_STRNEQ (name, CALL_FP_STUB)
911 /* The format of the first PLT entry in an O32 executable. */
912 static const bfd_vma mips_o32_exec_plt0_entry
[] =
914 0x3c1c0000, /* lui $28, %hi(&GOTPLT[0]) */
915 0x8f990000, /* lw $25, %lo(&GOTPLT[0])($28) */
916 0x279c0000, /* addiu $28, $28, %lo(&GOTPLT[0]) */
917 0x031cc023, /* subu $24, $24, $28 */
918 0x03e07821, /* move $15, $31 */
919 0x0018c082, /* srl $24, $24, 2 */
920 0x0320f809, /* jalr $25 */
921 0x2718fffe /* subu $24, $24, 2 */
924 /* The format of the first PLT entry in an N32 executable. Different
925 because gp ($28) is not available; we use t2 ($14) instead. */
926 static const bfd_vma mips_n32_exec_plt0_entry
[] =
928 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
929 0x8dd90000, /* lw $25, %lo(&GOTPLT[0])($14) */
930 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
931 0x030ec023, /* subu $24, $24, $14 */
932 0x03e07821, /* move $15, $31 */
933 0x0018c082, /* srl $24, $24, 2 */
934 0x0320f809, /* jalr $25 */
935 0x2718fffe /* subu $24, $24, 2 */
938 /* The format of the first PLT entry in an N64 executable. Different
939 from N32 because of the increased size of GOT entries. */
940 static const bfd_vma mips_n64_exec_plt0_entry
[] =
942 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
943 0xddd90000, /* ld $25, %lo(&GOTPLT[0])($14) */
944 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
945 0x030ec023, /* subu $24, $24, $14 */
946 0x03e07821, /* move $15, $31 */
947 0x0018c0c2, /* srl $24, $24, 3 */
948 0x0320f809, /* jalr $25 */
949 0x2718fffe /* subu $24, $24, 2 */
952 /* The format of subsequent PLT entries. */
953 static const bfd_vma mips_exec_plt_entry
[] =
955 0x3c0f0000, /* lui $15, %hi(.got.plt entry) */
956 0x01f90000, /* l[wd] $25, %lo(.got.plt entry)($15) */
957 0x25f80000, /* addiu $24, $15, %lo(.got.plt entry) */
958 0x03200008 /* jr $25 */
961 /* The format of the first PLT entry in a VxWorks executable. */
962 static const bfd_vma mips_vxworks_exec_plt0_entry
[] =
964 0x3c190000, /* lui t9, %hi(_GLOBAL_OFFSET_TABLE_) */
965 0x27390000, /* addiu t9, t9, %lo(_GLOBAL_OFFSET_TABLE_) */
966 0x8f390008, /* lw t9, 8(t9) */
967 0x00000000, /* nop */
968 0x03200008, /* jr t9 */
972 /* The format of subsequent PLT entries. */
973 static const bfd_vma mips_vxworks_exec_plt_entry
[] =
975 0x10000000, /* b .PLT_resolver */
976 0x24180000, /* li t8, <pltindex> */
977 0x3c190000, /* lui t9, %hi(<.got.plt slot>) */
978 0x27390000, /* addiu t9, t9, %lo(<.got.plt slot>) */
979 0x8f390000, /* lw t9, 0(t9) */
980 0x00000000, /* nop */
981 0x03200008, /* jr t9 */
985 /* The format of the first PLT entry in a VxWorks shared object. */
986 static const bfd_vma mips_vxworks_shared_plt0_entry
[] =
988 0x8f990008, /* lw t9, 8(gp) */
989 0x00000000, /* nop */
990 0x03200008, /* jr t9 */
991 0x00000000, /* nop */
992 0x00000000, /* nop */
996 /* The format of subsequent PLT entries. */
997 static const bfd_vma mips_vxworks_shared_plt_entry
[] =
999 0x10000000, /* b .PLT_resolver */
1000 0x24180000 /* li t8, <pltindex> */
1003 /* Look up an entry in a MIPS ELF linker hash table. */
1005 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
1006 ((struct mips_elf_link_hash_entry *) \
1007 elf_link_hash_lookup (&(table)->root, (string), (create), \
1010 /* Traverse a MIPS ELF linker hash table. */
1012 #define mips_elf_link_hash_traverse(table, func, info) \
1013 (elf_link_hash_traverse \
1015 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1018 /* Find the base offsets for thread-local storage in this object,
1019 for GD/LD and IE/LE respectively. */
1021 #define TP_OFFSET 0x7000
1022 #define DTP_OFFSET 0x8000
1025 dtprel_base (struct bfd_link_info
*info
)
1027 /* If tls_sec is NULL, we should have signalled an error already. */
1028 if (elf_hash_table (info
)->tls_sec
== NULL
)
1030 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
1034 tprel_base (struct bfd_link_info
*info
)
1036 /* If tls_sec is NULL, we should have signalled an error already. */
1037 if (elf_hash_table (info
)->tls_sec
== NULL
)
1039 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
1042 /* Create an entry in a MIPS ELF linker hash table. */
1044 static struct bfd_hash_entry
*
1045 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1046 struct bfd_hash_table
*table
, const char *string
)
1048 struct mips_elf_link_hash_entry
*ret
=
1049 (struct mips_elf_link_hash_entry
*) entry
;
1051 /* Allocate the structure if it has not already been allocated by a
1054 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
1056 return (struct bfd_hash_entry
*) ret
;
1058 /* Call the allocation method of the superclass. */
1059 ret
= ((struct mips_elf_link_hash_entry
*)
1060 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1064 /* Set local fields. */
1065 memset (&ret
->esym
, 0, sizeof (EXTR
));
1066 /* We use -2 as a marker to indicate that the information has
1067 not been set. -1 means there is no associated ifd. */
1070 ret
->possibly_dynamic_relocs
= 0;
1071 ret
->fn_stub
= NULL
;
1072 ret
->call_stub
= NULL
;
1073 ret
->call_fp_stub
= NULL
;
1074 ret
->tls_type
= GOT_NORMAL
;
1075 ret
->global_got_area
= GGA_NONE
;
1076 ret
->readonly_reloc
= FALSE
;
1077 ret
->has_static_relocs
= FALSE
;
1078 ret
->no_fn_stub
= FALSE
;
1079 ret
->need_fn_stub
= FALSE
;
1080 ret
->has_nonpic_branches
= FALSE
;
1081 ret
->needs_lazy_stub
= FALSE
;
1084 return (struct bfd_hash_entry
*) ret
;
1088 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
1090 if (!sec
->used_by_bfd
)
1092 struct _mips_elf_section_data
*sdata
;
1093 bfd_size_type amt
= sizeof (*sdata
);
1095 sdata
= bfd_zalloc (abfd
, amt
);
1098 sec
->used_by_bfd
= sdata
;
1101 return _bfd_elf_new_section_hook (abfd
, sec
);
1104 /* Read ECOFF debugging information from a .mdebug section into a
1105 ecoff_debug_info structure. */
1108 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
1109 struct ecoff_debug_info
*debug
)
1112 const struct ecoff_debug_swap
*swap
;
1115 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1116 memset (debug
, 0, sizeof (*debug
));
1118 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
1119 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1122 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
1123 swap
->external_hdr_size
))
1126 symhdr
= &debug
->symbolic_header
;
1127 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1129 /* The symbolic header contains absolute file offsets and sizes to
1131 #define READ(ptr, offset, count, size, type) \
1132 if (symhdr->count == 0) \
1133 debug->ptr = NULL; \
1136 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
1137 debug->ptr = bfd_malloc (amt); \
1138 if (debug->ptr == NULL) \
1139 goto error_return; \
1140 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0 \
1141 || bfd_bread (debug->ptr, amt, abfd) != amt) \
1142 goto error_return; \
1145 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1146 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
1147 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
1148 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
1149 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
1150 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1152 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1153 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
1154 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
1155 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
1156 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
1164 if (ext_hdr
!= NULL
)
1166 if (debug
->line
!= NULL
)
1168 if (debug
->external_dnr
!= NULL
)
1169 free (debug
->external_dnr
);
1170 if (debug
->external_pdr
!= NULL
)
1171 free (debug
->external_pdr
);
1172 if (debug
->external_sym
!= NULL
)
1173 free (debug
->external_sym
);
1174 if (debug
->external_opt
!= NULL
)
1175 free (debug
->external_opt
);
1176 if (debug
->external_aux
!= NULL
)
1177 free (debug
->external_aux
);
1178 if (debug
->ss
!= NULL
)
1180 if (debug
->ssext
!= NULL
)
1181 free (debug
->ssext
);
1182 if (debug
->external_fdr
!= NULL
)
1183 free (debug
->external_fdr
);
1184 if (debug
->external_rfd
!= NULL
)
1185 free (debug
->external_rfd
);
1186 if (debug
->external_ext
!= NULL
)
1187 free (debug
->external_ext
);
1191 /* Swap RPDR (runtime procedure table entry) for output. */
1194 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
1196 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
1197 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
1198 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
1199 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
1200 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
1201 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
1203 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
1204 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
1206 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
1209 /* Create a runtime procedure table from the .mdebug section. */
1212 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
1213 struct bfd_link_info
*info
, asection
*s
,
1214 struct ecoff_debug_info
*debug
)
1216 const struct ecoff_debug_swap
*swap
;
1217 HDRR
*hdr
= &debug
->symbolic_header
;
1219 struct rpdr_ext
*erp
;
1221 struct pdr_ext
*epdr
;
1222 struct sym_ext
*esym
;
1226 bfd_size_type count
;
1227 unsigned long sindex
;
1231 const char *no_name_func
= _("static procedure (no name)");
1239 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1241 sindex
= strlen (no_name_func
) + 1;
1242 count
= hdr
->ipdMax
;
1245 size
= swap
->external_pdr_size
;
1247 epdr
= bfd_malloc (size
* count
);
1251 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
1254 size
= sizeof (RPDR
);
1255 rp
= rpdr
= bfd_malloc (size
* count
);
1259 size
= sizeof (char *);
1260 sv
= bfd_malloc (size
* count
);
1264 count
= hdr
->isymMax
;
1265 size
= swap
->external_sym_size
;
1266 esym
= bfd_malloc (size
* count
);
1270 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
1273 count
= hdr
->issMax
;
1274 ss
= bfd_malloc (count
);
1277 if (! _bfd_ecoff_get_accumulated_ss (handle
, (bfd_byte
*) ss
))
1280 count
= hdr
->ipdMax
;
1281 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
1283 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
1284 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
1285 rp
->adr
= sym
.value
;
1286 rp
->regmask
= pdr
.regmask
;
1287 rp
->regoffset
= pdr
.regoffset
;
1288 rp
->fregmask
= pdr
.fregmask
;
1289 rp
->fregoffset
= pdr
.fregoffset
;
1290 rp
->frameoffset
= pdr
.frameoffset
;
1291 rp
->framereg
= pdr
.framereg
;
1292 rp
->pcreg
= pdr
.pcreg
;
1294 sv
[i
] = ss
+ sym
.iss
;
1295 sindex
+= strlen (sv
[i
]) + 1;
1299 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
1300 size
= BFD_ALIGN (size
, 16);
1301 rtproc
= bfd_alloc (abfd
, size
);
1304 mips_elf_hash_table (info
)->procedure_count
= 0;
1308 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
1311 memset (erp
, 0, sizeof (struct rpdr_ext
));
1313 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
1314 strcpy (str
, no_name_func
);
1315 str
+= strlen (no_name_func
) + 1;
1316 for (i
= 0; i
< count
; i
++)
1318 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
1319 strcpy (str
, sv
[i
]);
1320 str
+= strlen (sv
[i
]) + 1;
1322 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
1324 /* Set the size and contents of .rtproc section. */
1326 s
->contents
= rtproc
;
1328 /* Skip this section later on (I don't think this currently
1329 matters, but someday it might). */
1330 s
->map_head
.link_order
= NULL
;
1359 /* We're going to create a stub for H. Create a symbol for the stub's
1360 value and size, to help make the disassembly easier to read. */
1363 mips_elf_create_stub_symbol (struct bfd_link_info
*info
,
1364 struct mips_elf_link_hash_entry
*h
,
1365 const char *prefix
, asection
*s
, bfd_vma value
,
1368 struct bfd_link_hash_entry
*bh
;
1369 struct elf_link_hash_entry
*elfh
;
1372 /* Create a new symbol. */
1373 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1375 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1376 BSF_LOCAL
, s
, value
, NULL
,
1380 /* Make it a local function. */
1381 elfh
= (struct elf_link_hash_entry
*) bh
;
1382 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
1384 elfh
->forced_local
= 1;
1388 /* We're about to redefine H. Create a symbol to represent H's
1389 current value and size, to help make the disassembly easier
1393 mips_elf_create_shadow_symbol (struct bfd_link_info
*info
,
1394 struct mips_elf_link_hash_entry
*h
,
1397 struct bfd_link_hash_entry
*bh
;
1398 struct elf_link_hash_entry
*elfh
;
1403 /* Read the symbol's value. */
1404 BFD_ASSERT (h
->root
.root
.type
== bfd_link_hash_defined
1405 || h
->root
.root
.type
== bfd_link_hash_defweak
);
1406 s
= h
->root
.root
.u
.def
.section
;
1407 value
= h
->root
.root
.u
.def
.value
;
1409 /* Create a new symbol. */
1410 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1412 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1413 BSF_LOCAL
, s
, value
, NULL
,
1417 /* Make it local and copy the other attributes from H. */
1418 elfh
= (struct elf_link_hash_entry
*) bh
;
1419 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (h
->root
.type
));
1420 elfh
->other
= h
->root
.other
;
1421 elfh
->size
= h
->root
.size
;
1422 elfh
->forced_local
= 1;
1426 /* Return TRUE if relocations in SECTION can refer directly to a MIPS16
1427 function rather than to a hard-float stub. */
1430 section_allows_mips16_refs_p (asection
*section
)
1434 name
= bfd_get_section_name (section
->owner
, section
);
1435 return (FN_STUB_P (name
)
1436 || CALL_STUB_P (name
)
1437 || CALL_FP_STUB_P (name
)
1438 || strcmp (name
, ".pdr") == 0);
1441 /* [RELOCS, RELEND) are the relocations against SEC, which is a MIPS16
1442 stub section of some kind. Return the R_SYMNDX of the target
1443 function, or 0 if we can't decide which function that is. */
1445 static unsigned long
1446 mips16_stub_symndx (asection
*sec ATTRIBUTE_UNUSED
,
1447 const Elf_Internal_Rela
*relocs
,
1448 const Elf_Internal_Rela
*relend
)
1450 const Elf_Internal_Rela
*rel
;
1452 /* Trust the first R_MIPS_NONE relocation, if any. */
1453 for (rel
= relocs
; rel
< relend
; rel
++)
1454 if (ELF_R_TYPE (sec
->owner
, rel
->r_info
) == R_MIPS_NONE
)
1455 return ELF_R_SYM (sec
->owner
, rel
->r_info
);
1457 /* Otherwise trust the first relocation, whatever its kind. This is
1458 the traditional behavior. */
1459 if (relocs
< relend
)
1460 return ELF_R_SYM (sec
->owner
, relocs
->r_info
);
1465 /* Check the mips16 stubs for a particular symbol, and see if we can
1469 mips_elf_check_mips16_stubs (struct bfd_link_info
*info
,
1470 struct mips_elf_link_hash_entry
*h
)
1472 /* Dynamic symbols must use the standard call interface, in case other
1473 objects try to call them. */
1474 if (h
->fn_stub
!= NULL
1475 && h
->root
.dynindx
!= -1)
1477 mips_elf_create_shadow_symbol (info
, h
, ".mips16.");
1478 h
->need_fn_stub
= TRUE
;
1481 if (h
->fn_stub
!= NULL
1482 && ! h
->need_fn_stub
)
1484 /* We don't need the fn_stub; the only references to this symbol
1485 are 16 bit calls. Clobber the size to 0 to prevent it from
1486 being included in the link. */
1487 h
->fn_stub
->size
= 0;
1488 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1489 h
->fn_stub
->reloc_count
= 0;
1490 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1493 if (h
->call_stub
!= NULL
1494 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1496 /* We don't need the call_stub; this is a 16 bit function, so
1497 calls from other 16 bit functions are OK. Clobber the size
1498 to 0 to prevent it from being included in the link. */
1499 h
->call_stub
->size
= 0;
1500 h
->call_stub
->flags
&= ~SEC_RELOC
;
1501 h
->call_stub
->reloc_count
= 0;
1502 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1505 if (h
->call_fp_stub
!= NULL
1506 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1508 /* We don't need the call_stub; this is a 16 bit function, so
1509 calls from other 16 bit functions are OK. Clobber the size
1510 to 0 to prevent it from being included in the link. */
1511 h
->call_fp_stub
->size
= 0;
1512 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1513 h
->call_fp_stub
->reloc_count
= 0;
1514 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1518 /* Hashtable callbacks for mips_elf_la25_stubs. */
1521 mips_elf_la25_stub_hash (const void *entry_
)
1523 const struct mips_elf_la25_stub
*entry
;
1525 entry
= (struct mips_elf_la25_stub
*) entry_
;
1526 return entry
->h
->root
.root
.u
.def
.section
->id
1527 + entry
->h
->root
.root
.u
.def
.value
;
1531 mips_elf_la25_stub_eq (const void *entry1_
, const void *entry2_
)
1533 const struct mips_elf_la25_stub
*entry1
, *entry2
;
1535 entry1
= (struct mips_elf_la25_stub
*) entry1_
;
1536 entry2
= (struct mips_elf_la25_stub
*) entry2_
;
1537 return ((entry1
->h
->root
.root
.u
.def
.section
1538 == entry2
->h
->root
.root
.u
.def
.section
)
1539 && (entry1
->h
->root
.root
.u
.def
.value
1540 == entry2
->h
->root
.root
.u
.def
.value
));
1543 /* Called by the linker to set up the la25 stub-creation code. FN is
1544 the linker's implementation of add_stub_function. Return true on
1548 _bfd_mips_elf_init_stubs (struct bfd_link_info
*info
,
1549 asection
*(*fn
) (const char *, asection
*,
1552 struct mips_elf_link_hash_table
*htab
;
1554 htab
= mips_elf_hash_table (info
);
1558 htab
->add_stub_section
= fn
;
1559 htab
->la25_stubs
= htab_try_create (1, mips_elf_la25_stub_hash
,
1560 mips_elf_la25_stub_eq
, NULL
);
1561 if (htab
->la25_stubs
== NULL
)
1567 /* Return true if H is a locally-defined PIC function, in the sense
1568 that it might need $25 to be valid on entry. Note that MIPS16
1569 functions never need $25 to be valid on entry; they set up $gp
1570 using PC-relative instructions instead. */
1573 mips_elf_local_pic_function_p (struct mips_elf_link_hash_entry
*h
)
1575 return ((h
->root
.root
.type
== bfd_link_hash_defined
1576 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1577 && h
->root
.def_regular
1578 && !bfd_is_abs_section (h
->root
.root
.u
.def
.section
)
1579 && !ELF_ST_IS_MIPS16 (h
->root
.other
)
1580 && (PIC_OBJECT_P (h
->root
.root
.u
.def
.section
->owner
)
1581 || ELF_ST_IS_MIPS_PIC (h
->root
.other
)));
1584 /* STUB describes an la25 stub that we have decided to implement
1585 by inserting an LUI/ADDIU pair before the target function.
1586 Create the section and redirect the function symbol to it. */
1589 mips_elf_add_la25_intro (struct mips_elf_la25_stub
*stub
,
1590 struct bfd_link_info
*info
)
1592 struct mips_elf_link_hash_table
*htab
;
1594 asection
*s
, *input_section
;
1597 htab
= mips_elf_hash_table (info
);
1601 /* Create a unique name for the new section. */
1602 name
= bfd_malloc (11 + sizeof (".text.stub."));
1605 sprintf (name
, ".text.stub.%d", (int) htab_elements (htab
->la25_stubs
));
1607 /* Create the section. */
1608 input_section
= stub
->h
->root
.root
.u
.def
.section
;
1609 s
= htab
->add_stub_section (name
, input_section
,
1610 input_section
->output_section
);
1614 /* Make sure that any padding goes before the stub. */
1615 align
= input_section
->alignment_power
;
1616 if (!bfd_set_section_alignment (s
->owner
, s
, align
))
1619 s
->size
= (1 << align
) - 8;
1621 /* Create a symbol for the stub. */
1622 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 8);
1623 stub
->stub_section
= s
;
1624 stub
->offset
= s
->size
;
1626 /* Allocate room for it. */
1631 /* STUB describes an la25 stub that we have decided to implement
1632 with a separate trampoline. Allocate room for it and redirect
1633 the function symbol to it. */
1636 mips_elf_add_la25_trampoline (struct mips_elf_la25_stub
*stub
,
1637 struct bfd_link_info
*info
)
1639 struct mips_elf_link_hash_table
*htab
;
1642 htab
= mips_elf_hash_table (info
);
1646 /* Create a trampoline section, if we haven't already. */
1647 s
= htab
->strampoline
;
1650 asection
*input_section
= stub
->h
->root
.root
.u
.def
.section
;
1651 s
= htab
->add_stub_section (".text", NULL
,
1652 input_section
->output_section
);
1653 if (s
== NULL
|| !bfd_set_section_alignment (s
->owner
, s
, 4))
1655 htab
->strampoline
= s
;
1658 /* Create a symbol for the stub. */
1659 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 16);
1660 stub
->stub_section
= s
;
1661 stub
->offset
= s
->size
;
1663 /* Allocate room for it. */
1668 /* H describes a symbol that needs an la25 stub. Make sure that an
1669 appropriate stub exists and point H at it. */
1672 mips_elf_add_la25_stub (struct bfd_link_info
*info
,
1673 struct mips_elf_link_hash_entry
*h
)
1675 struct mips_elf_link_hash_table
*htab
;
1676 struct mips_elf_la25_stub search
, *stub
;
1677 bfd_boolean use_trampoline_p
;
1682 /* Prefer to use LUI/ADDIU stubs if the function is at the beginning
1683 of the section and if we would need no more than 2 nops. */
1684 s
= h
->root
.root
.u
.def
.section
;
1685 value
= h
->root
.root
.u
.def
.value
;
1686 use_trampoline_p
= (value
!= 0 || s
->alignment_power
> 4);
1688 /* Describe the stub we want. */
1689 search
.stub_section
= NULL
;
1693 /* See if we've already created an equivalent stub. */
1694 htab
= mips_elf_hash_table (info
);
1698 slot
= htab_find_slot (htab
->la25_stubs
, &search
, INSERT
);
1702 stub
= (struct mips_elf_la25_stub
*) *slot
;
1705 /* We can reuse the existing stub. */
1706 h
->la25_stub
= stub
;
1710 /* Create a permanent copy of ENTRY and add it to the hash table. */
1711 stub
= bfd_malloc (sizeof (search
));
1717 h
->la25_stub
= stub
;
1718 return (use_trampoline_p
1719 ? mips_elf_add_la25_trampoline (stub
, info
)
1720 : mips_elf_add_la25_intro (stub
, info
));
1723 /* A mips_elf_link_hash_traverse callback that is called before sizing
1724 sections. DATA points to a mips_htab_traverse_info structure. */
1727 mips_elf_check_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
1729 struct mips_htab_traverse_info
*hti
;
1731 hti
= (struct mips_htab_traverse_info
*) data
;
1732 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1733 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1735 if (!hti
->info
->relocatable
)
1736 mips_elf_check_mips16_stubs (hti
->info
, h
);
1738 if (mips_elf_local_pic_function_p (h
))
1740 /* H is a function that might need $25 to be valid on entry.
1741 If we're creating a non-PIC relocatable object, mark H as
1742 being PIC. If we're creating a non-relocatable object with
1743 non-PIC branches and jumps to H, make sure that H has an la25
1745 if (hti
->info
->relocatable
)
1747 if (!PIC_OBJECT_P (hti
->output_bfd
))
1748 h
->root
.other
= ELF_ST_SET_MIPS_PIC (h
->root
.other
);
1750 else if (h
->has_nonpic_branches
&& !mips_elf_add_la25_stub (hti
->info
, h
))
1759 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
1760 Most mips16 instructions are 16 bits, but these instructions
1763 The format of these instructions is:
1765 +--------------+--------------------------------+
1766 | JALX | X| Imm 20:16 | Imm 25:21 |
1767 +--------------+--------------------------------+
1769 +-----------------------------------------------+
1771 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
1772 Note that the immediate value in the first word is swapped.
1774 When producing a relocatable object file, R_MIPS16_26 is
1775 handled mostly like R_MIPS_26. In particular, the addend is
1776 stored as a straight 26-bit value in a 32-bit instruction.
1777 (gas makes life simpler for itself by never adjusting a
1778 R_MIPS16_26 reloc to be against a section, so the addend is
1779 always zero). However, the 32 bit instruction is stored as 2
1780 16-bit values, rather than a single 32-bit value. In a
1781 big-endian file, the result is the same; in a little-endian
1782 file, the two 16-bit halves of the 32 bit value are swapped.
1783 This is so that a disassembler can recognize the jal
1786 When doing a final link, R_MIPS16_26 is treated as a 32 bit
1787 instruction stored as two 16-bit values. The addend A is the
1788 contents of the targ26 field. The calculation is the same as
1789 R_MIPS_26. When storing the calculated value, reorder the
1790 immediate value as shown above, and don't forget to store the
1791 value as two 16-bit values.
1793 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
1797 +--------+----------------------+
1801 +--------+----------------------+
1804 +----------+------+-------------+
1808 +----------+--------------------+
1809 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
1810 ((sub1 << 16) | sub2)).
1812 When producing a relocatable object file, the calculation is
1813 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1814 When producing a fully linked file, the calculation is
1815 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1816 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
1818 The table below lists the other MIPS16 instruction relocations.
1819 Each one is calculated in the same way as the non-MIPS16 relocation
1820 given on the right, but using the extended MIPS16 layout of 16-bit
1823 R_MIPS16_GPREL R_MIPS_GPREL16
1824 R_MIPS16_GOT16 R_MIPS_GOT16
1825 R_MIPS16_CALL16 R_MIPS_CALL16
1826 R_MIPS16_HI16 R_MIPS_HI16
1827 R_MIPS16_LO16 R_MIPS_LO16
1829 A typical instruction will have a format like this:
1831 +--------------+--------------------------------+
1832 | EXTEND | Imm 10:5 | Imm 15:11 |
1833 +--------------+--------------------------------+
1834 | Major | rx | ry | Imm 4:0 |
1835 +--------------+--------------------------------+
1837 EXTEND is the five bit value 11110. Major is the instruction
1840 All we need to do here is shuffle the bits appropriately.
1841 As above, the two 16-bit halves must be swapped on a
1842 little-endian system. */
1844 static inline bfd_boolean
1845 mips16_reloc_p (int r_type
)
1850 case R_MIPS16_GPREL
:
1851 case R_MIPS16_GOT16
:
1852 case R_MIPS16_CALL16
:
1862 static inline bfd_boolean
1863 got16_reloc_p (int r_type
)
1865 return r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS16_GOT16
;
1868 static inline bfd_boolean
1869 call16_reloc_p (int r_type
)
1871 return r_type
== R_MIPS_CALL16
|| r_type
== R_MIPS16_CALL16
;
1874 static inline bfd_boolean
1875 hi16_reloc_p (int r_type
)
1877 return r_type
== R_MIPS_HI16
|| r_type
== R_MIPS16_HI16
;
1880 static inline bfd_boolean
1881 lo16_reloc_p (int r_type
)
1883 return r_type
== R_MIPS_LO16
|| r_type
== R_MIPS16_LO16
;
1886 static inline bfd_boolean
1887 mips16_call_reloc_p (int r_type
)
1889 return r_type
== R_MIPS16_26
|| r_type
== R_MIPS16_CALL16
;
1892 static inline bfd_boolean
1893 jal_reloc_p (int r_type
)
1895 return r_type
== R_MIPS_26
|| r_type
== R_MIPS16_26
;
1899 _bfd_mips16_elf_reloc_unshuffle (bfd
*abfd
, int r_type
,
1900 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1902 bfd_vma extend
, insn
, val
;
1904 if (!mips16_reloc_p (r_type
))
1907 /* Pick up the mips16 extend instruction and the real instruction. */
1908 extend
= bfd_get_16 (abfd
, data
);
1909 insn
= bfd_get_16 (abfd
, data
+ 2);
1910 if (r_type
== R_MIPS16_26
)
1913 val
= ((extend
& 0xfc00) << 16) | ((extend
& 0x3e0) << 11)
1914 | ((extend
& 0x1f) << 21) | insn
;
1916 val
= extend
<< 16 | insn
;
1919 val
= ((extend
& 0xf800) << 16) | ((insn
& 0xffe0) << 11)
1920 | ((extend
& 0x1f) << 11) | (extend
& 0x7e0) | (insn
& 0x1f);
1921 bfd_put_32 (abfd
, val
, data
);
1925 _bfd_mips16_elf_reloc_shuffle (bfd
*abfd
, int r_type
,
1926 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1928 bfd_vma extend
, insn
, val
;
1930 if (!mips16_reloc_p (r_type
))
1933 val
= bfd_get_32 (abfd
, data
);
1934 if (r_type
== R_MIPS16_26
)
1938 insn
= val
& 0xffff;
1939 extend
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
1940 | ((val
>> 21) & 0x1f);
1944 insn
= val
& 0xffff;
1950 insn
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
1951 extend
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
1953 bfd_put_16 (abfd
, insn
, data
+ 2);
1954 bfd_put_16 (abfd
, extend
, data
);
1957 bfd_reloc_status_type
1958 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
1959 arelent
*reloc_entry
, asection
*input_section
,
1960 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
1964 bfd_reloc_status_type status
;
1966 if (bfd_is_com_section (symbol
->section
))
1969 relocation
= symbol
->value
;
1971 relocation
+= symbol
->section
->output_section
->vma
;
1972 relocation
+= symbol
->section
->output_offset
;
1974 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1975 return bfd_reloc_outofrange
;
1977 /* Set val to the offset into the section or symbol. */
1978 val
= reloc_entry
->addend
;
1980 _bfd_mips_elf_sign_extend (val
, 16);
1982 /* Adjust val for the final section location and GP value. If we
1983 are producing relocatable output, we don't want to do this for
1984 an external symbol. */
1986 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1987 val
+= relocation
- gp
;
1989 if (reloc_entry
->howto
->partial_inplace
)
1991 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1993 + reloc_entry
->address
);
1994 if (status
!= bfd_reloc_ok
)
1998 reloc_entry
->addend
= val
;
2001 reloc_entry
->address
+= input_section
->output_offset
;
2003 return bfd_reloc_ok
;
2006 /* Used to store a REL high-part relocation such as R_MIPS_HI16 or
2007 R_MIPS_GOT16. REL is the relocation, INPUT_SECTION is the section
2008 that contains the relocation field and DATA points to the start of
2013 struct mips_hi16
*next
;
2015 asection
*input_section
;
2019 /* FIXME: This should not be a static variable. */
2021 static struct mips_hi16
*mips_hi16_list
;
2023 /* A howto special_function for REL *HI16 relocations. We can only
2024 calculate the correct value once we've seen the partnering
2025 *LO16 relocation, so just save the information for later.
2027 The ABI requires that the *LO16 immediately follow the *HI16.
2028 However, as a GNU extension, we permit an arbitrary number of
2029 *HI16s to be associated with a single *LO16. This significantly
2030 simplies the relocation handling in gcc. */
2032 bfd_reloc_status_type
2033 _bfd_mips_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2034 asymbol
*symbol ATTRIBUTE_UNUSED
, void *data
,
2035 asection
*input_section
, bfd
*output_bfd
,
2036 char **error_message ATTRIBUTE_UNUSED
)
2038 struct mips_hi16
*n
;
2040 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2041 return bfd_reloc_outofrange
;
2043 n
= bfd_malloc (sizeof *n
);
2045 return bfd_reloc_outofrange
;
2047 n
->next
= mips_hi16_list
;
2049 n
->input_section
= input_section
;
2050 n
->rel
= *reloc_entry
;
2053 if (output_bfd
!= NULL
)
2054 reloc_entry
->address
+= input_section
->output_offset
;
2056 return bfd_reloc_ok
;
2059 /* A howto special_function for REL R_MIPS*_GOT16 relocations. This is just
2060 like any other 16-bit relocation when applied to global symbols, but is
2061 treated in the same as R_MIPS_HI16 when applied to local symbols. */
2063 bfd_reloc_status_type
2064 _bfd_mips_elf_got16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2065 void *data
, asection
*input_section
,
2066 bfd
*output_bfd
, char **error_message
)
2068 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
2069 || bfd_is_und_section (bfd_get_section (symbol
))
2070 || bfd_is_com_section (bfd_get_section (symbol
)))
2071 /* The relocation is against a global symbol. */
2072 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2073 input_section
, output_bfd
,
2076 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
2077 input_section
, output_bfd
, error_message
);
2080 /* A howto special_function for REL *LO16 relocations. The *LO16 itself
2081 is a straightforward 16 bit inplace relocation, but we must deal with
2082 any partnering high-part relocations as well. */
2084 bfd_reloc_status_type
2085 _bfd_mips_elf_lo16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2086 void *data
, asection
*input_section
,
2087 bfd
*output_bfd
, char **error_message
)
2090 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2092 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2093 return bfd_reloc_outofrange
;
2095 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2097 vallo
= bfd_get_32 (abfd
, location
);
2098 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2101 while (mips_hi16_list
!= NULL
)
2103 bfd_reloc_status_type ret
;
2104 struct mips_hi16
*hi
;
2106 hi
= mips_hi16_list
;
2108 /* R_MIPS*_GOT16 relocations are something of a special case. We
2109 want to install the addend in the same way as for a R_MIPS*_HI16
2110 relocation (with a rightshift of 16). However, since GOT16
2111 relocations can also be used with global symbols, their howto
2112 has a rightshift of 0. */
2113 if (hi
->rel
.howto
->type
== R_MIPS_GOT16
)
2114 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS_HI16
, FALSE
);
2115 else if (hi
->rel
.howto
->type
== R_MIPS16_GOT16
)
2116 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS16_HI16
, FALSE
);
2118 /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
2119 carry or borrow will induce a change of +1 or -1 in the high part. */
2120 hi
->rel
.addend
+= (vallo
+ 0x8000) & 0xffff;
2122 ret
= _bfd_mips_elf_generic_reloc (abfd
, &hi
->rel
, symbol
, hi
->data
,
2123 hi
->input_section
, output_bfd
,
2125 if (ret
!= bfd_reloc_ok
)
2128 mips_hi16_list
= hi
->next
;
2132 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2133 input_section
, output_bfd
,
2137 /* A generic howto special_function. This calculates and installs the
2138 relocation itself, thus avoiding the oft-discussed problems in
2139 bfd_perform_relocation and bfd_install_relocation. */
2141 bfd_reloc_status_type
2142 _bfd_mips_elf_generic_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2143 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
2144 asection
*input_section
, bfd
*output_bfd
,
2145 char **error_message ATTRIBUTE_UNUSED
)
2148 bfd_reloc_status_type status
;
2149 bfd_boolean relocatable
;
2151 relocatable
= (output_bfd
!= NULL
);
2153 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2154 return bfd_reloc_outofrange
;
2156 /* Build up the field adjustment in VAL. */
2158 if (!relocatable
|| (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2160 /* Either we're calculating the final field value or we have a
2161 relocation against a section symbol. Add in the section's
2162 offset or address. */
2163 val
+= symbol
->section
->output_section
->vma
;
2164 val
+= symbol
->section
->output_offset
;
2169 /* We're calculating the final field value. Add in the symbol's value
2170 and, if pc-relative, subtract the address of the field itself. */
2171 val
+= symbol
->value
;
2172 if (reloc_entry
->howto
->pc_relative
)
2174 val
-= input_section
->output_section
->vma
;
2175 val
-= input_section
->output_offset
;
2176 val
-= reloc_entry
->address
;
2180 /* VAL is now the final adjustment. If we're keeping this relocation
2181 in the output file, and if the relocation uses a separate addend,
2182 we just need to add VAL to that addend. Otherwise we need to add
2183 VAL to the relocation field itself. */
2184 if (relocatable
&& !reloc_entry
->howto
->partial_inplace
)
2185 reloc_entry
->addend
+= val
;
2188 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2190 /* Add in the separate addend, if any. */
2191 val
+= reloc_entry
->addend
;
2193 /* Add VAL to the relocation field. */
2194 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2196 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
2198 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2201 if (status
!= bfd_reloc_ok
)
2206 reloc_entry
->address
+= input_section
->output_offset
;
2208 return bfd_reloc_ok
;
2211 /* Swap an entry in a .gptab section. Note that these routines rely
2212 on the equivalence of the two elements of the union. */
2215 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
2218 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
2219 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
2223 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
2224 Elf32_External_gptab
*ex
)
2226 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
2227 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
2231 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
2232 Elf32_External_compact_rel
*ex
)
2234 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
2235 H_PUT_32 (abfd
, in
->num
, ex
->num
);
2236 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
2237 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
2238 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
2239 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
2243 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
2244 Elf32_External_crinfo
*ex
)
2248 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2249 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2250 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2251 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2252 H_PUT_32 (abfd
, l
, ex
->info
);
2253 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
2254 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
2257 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2258 routines swap this structure in and out. They are used outside of
2259 BFD, so they are globally visible. */
2262 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
2265 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2266 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2267 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2268 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2269 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2270 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
2274 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
2275 Elf32_External_RegInfo
*ex
)
2277 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2278 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2279 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2280 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2281 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2282 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2285 /* In the 64 bit ABI, the .MIPS.options section holds register
2286 information in an Elf64_Reginfo structure. These routines swap
2287 them in and out. They are globally visible because they are used
2288 outside of BFD. These routines are here so that gas can call them
2289 without worrying about whether the 64 bit ABI has been included. */
2292 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
2293 Elf64_Internal_RegInfo
*in
)
2295 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2296 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
2297 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2298 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2299 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2300 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2301 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
2305 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
2306 Elf64_External_RegInfo
*ex
)
2308 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2309 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
2310 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2311 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2312 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2313 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2314 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2317 /* Swap in an options header. */
2320 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
2321 Elf_Internal_Options
*in
)
2323 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
2324 in
->size
= H_GET_8 (abfd
, ex
->size
);
2325 in
->section
= H_GET_16 (abfd
, ex
->section
);
2326 in
->info
= H_GET_32 (abfd
, ex
->info
);
2329 /* Swap out an options header. */
2332 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
2333 Elf_External_Options
*ex
)
2335 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
2336 H_PUT_8 (abfd
, in
->size
, ex
->size
);
2337 H_PUT_16 (abfd
, in
->section
, ex
->section
);
2338 H_PUT_32 (abfd
, in
->info
, ex
->info
);
2341 /* This function is called via qsort() to sort the dynamic relocation
2342 entries by increasing r_symndx value. */
2345 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
2347 Elf_Internal_Rela int_reloc1
;
2348 Elf_Internal_Rela int_reloc2
;
2351 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
2352 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
2354 diff
= ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
2358 if (int_reloc1
.r_offset
< int_reloc2
.r_offset
)
2360 if (int_reloc1
.r_offset
> int_reloc2
.r_offset
)
2365 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
2368 sort_dynamic_relocs_64 (const void *arg1 ATTRIBUTE_UNUSED
,
2369 const void *arg2 ATTRIBUTE_UNUSED
)
2372 Elf_Internal_Rela int_reloc1
[3];
2373 Elf_Internal_Rela int_reloc2
[3];
2375 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2376 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
2377 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2378 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
2380 if (ELF64_R_SYM (int_reloc1
[0].r_info
) < ELF64_R_SYM (int_reloc2
[0].r_info
))
2382 if (ELF64_R_SYM (int_reloc1
[0].r_info
) > ELF64_R_SYM (int_reloc2
[0].r_info
))
2385 if (int_reloc1
[0].r_offset
< int_reloc2
[0].r_offset
)
2387 if (int_reloc1
[0].r_offset
> int_reloc2
[0].r_offset
)
2396 /* This routine is used to write out ECOFF debugging external symbol
2397 information. It is called via mips_elf_link_hash_traverse. The
2398 ECOFF external symbol information must match the ELF external
2399 symbol information. Unfortunately, at this point we don't know
2400 whether a symbol is required by reloc information, so the two
2401 tables may wind up being different. We must sort out the external
2402 symbol information before we can set the final size of the .mdebug
2403 section, and we must set the size of the .mdebug section before we
2404 can relocate any sections, and we can't know which symbols are
2405 required by relocation until we relocate the sections.
2406 Fortunately, it is relatively unlikely that any symbol will be
2407 stripped but required by a reloc. In particular, it can not happen
2408 when generating a final executable. */
2411 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
2413 struct extsym_info
*einfo
= data
;
2415 asection
*sec
, *output_section
;
2417 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2418 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2420 if (h
->root
.indx
== -2)
2422 else if ((h
->root
.def_dynamic
2423 || h
->root
.ref_dynamic
2424 || h
->root
.type
== bfd_link_hash_new
)
2425 && !h
->root
.def_regular
2426 && !h
->root
.ref_regular
)
2428 else if (einfo
->info
->strip
== strip_all
2429 || (einfo
->info
->strip
== strip_some
2430 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2431 h
->root
.root
.root
.string
,
2432 FALSE
, FALSE
) == NULL
))
2440 if (h
->esym
.ifd
== -2)
2443 h
->esym
.cobol_main
= 0;
2444 h
->esym
.weakext
= 0;
2445 h
->esym
.reserved
= 0;
2446 h
->esym
.ifd
= ifdNil
;
2447 h
->esym
.asym
.value
= 0;
2448 h
->esym
.asym
.st
= stGlobal
;
2450 if (h
->root
.root
.type
== bfd_link_hash_undefined
2451 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
2455 /* Use undefined class. Also, set class and type for some
2457 name
= h
->root
.root
.root
.string
;
2458 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2459 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2461 h
->esym
.asym
.sc
= scData
;
2462 h
->esym
.asym
.st
= stLabel
;
2463 h
->esym
.asym
.value
= 0;
2465 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2467 h
->esym
.asym
.sc
= scAbs
;
2468 h
->esym
.asym
.st
= stLabel
;
2469 h
->esym
.asym
.value
=
2470 mips_elf_hash_table (einfo
->info
)->procedure_count
;
2472 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
2474 h
->esym
.asym
.sc
= scAbs
;
2475 h
->esym
.asym
.st
= stLabel
;
2476 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
2479 h
->esym
.asym
.sc
= scUndefined
;
2481 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2482 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2483 h
->esym
.asym
.sc
= scAbs
;
2488 sec
= h
->root
.root
.u
.def
.section
;
2489 output_section
= sec
->output_section
;
2491 /* When making a shared library and symbol h is the one from
2492 the another shared library, OUTPUT_SECTION may be null. */
2493 if (output_section
== NULL
)
2494 h
->esym
.asym
.sc
= scUndefined
;
2497 name
= bfd_section_name (output_section
->owner
, output_section
);
2499 if (strcmp (name
, ".text") == 0)
2500 h
->esym
.asym
.sc
= scText
;
2501 else if (strcmp (name
, ".data") == 0)
2502 h
->esym
.asym
.sc
= scData
;
2503 else if (strcmp (name
, ".sdata") == 0)
2504 h
->esym
.asym
.sc
= scSData
;
2505 else if (strcmp (name
, ".rodata") == 0
2506 || strcmp (name
, ".rdata") == 0)
2507 h
->esym
.asym
.sc
= scRData
;
2508 else if (strcmp (name
, ".bss") == 0)
2509 h
->esym
.asym
.sc
= scBss
;
2510 else if (strcmp (name
, ".sbss") == 0)
2511 h
->esym
.asym
.sc
= scSBss
;
2512 else if (strcmp (name
, ".init") == 0)
2513 h
->esym
.asym
.sc
= scInit
;
2514 else if (strcmp (name
, ".fini") == 0)
2515 h
->esym
.asym
.sc
= scFini
;
2517 h
->esym
.asym
.sc
= scAbs
;
2521 h
->esym
.asym
.reserved
= 0;
2522 h
->esym
.asym
.index
= indexNil
;
2525 if (h
->root
.root
.type
== bfd_link_hash_common
)
2526 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2527 else if (h
->root
.root
.type
== bfd_link_hash_defined
2528 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2530 if (h
->esym
.asym
.sc
== scCommon
)
2531 h
->esym
.asym
.sc
= scBss
;
2532 else if (h
->esym
.asym
.sc
== scSCommon
)
2533 h
->esym
.asym
.sc
= scSBss
;
2535 sec
= h
->root
.root
.u
.def
.section
;
2536 output_section
= sec
->output_section
;
2537 if (output_section
!= NULL
)
2538 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2539 + sec
->output_offset
2540 + output_section
->vma
);
2542 h
->esym
.asym
.value
= 0;
2546 struct mips_elf_link_hash_entry
*hd
= h
;
2548 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
2549 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2551 if (hd
->needs_lazy_stub
)
2553 /* Set type and value for a symbol with a function stub. */
2554 h
->esym
.asym
.st
= stProc
;
2555 sec
= hd
->root
.root
.u
.def
.section
;
2557 h
->esym
.asym
.value
= 0;
2560 output_section
= sec
->output_section
;
2561 if (output_section
!= NULL
)
2562 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
2563 + sec
->output_offset
2564 + output_section
->vma
);
2566 h
->esym
.asym
.value
= 0;
2571 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2572 h
->root
.root
.root
.string
,
2575 einfo
->failed
= TRUE
;
2582 /* A comparison routine used to sort .gptab entries. */
2585 gptab_compare (const void *p1
, const void *p2
)
2587 const Elf32_gptab
*a1
= p1
;
2588 const Elf32_gptab
*a2
= p2
;
2590 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
2593 /* Functions to manage the got entry hash table. */
2595 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
2598 static INLINE hashval_t
2599 mips_elf_hash_bfd_vma (bfd_vma addr
)
2602 return addr
+ (addr
>> 32);
2608 /* got_entries only match if they're identical, except for gotidx, so
2609 use all fields to compute the hash, and compare the appropriate
2613 mips_elf_got_entry_hash (const void *entry_
)
2615 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2617 return entry
->symndx
2618 + ((entry
->tls_type
& GOT_TLS_LDM
) << 17)
2619 + (! entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
2621 + (entry
->symndx
>= 0 ? mips_elf_hash_bfd_vma (entry
->d
.addend
)
2622 : entry
->d
.h
->root
.root
.root
.hash
));
2626 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
2628 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2629 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2631 /* An LDM entry can only match another LDM entry. */
2632 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2635 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
2636 && (! e1
->abfd
? e1
->d
.address
== e2
->d
.address
2637 : e1
->symndx
>= 0 ? e1
->d
.addend
== e2
->d
.addend
2638 : e1
->d
.h
== e2
->d
.h
);
2641 /* multi_got_entries are still a match in the case of global objects,
2642 even if the input bfd in which they're referenced differs, so the
2643 hash computation and compare functions are adjusted
2647 mips_elf_multi_got_entry_hash (const void *entry_
)
2649 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2651 return entry
->symndx
2653 ? mips_elf_hash_bfd_vma (entry
->d
.address
)
2654 : entry
->symndx
>= 0
2655 ? ((entry
->tls_type
& GOT_TLS_LDM
)
2656 ? (GOT_TLS_LDM
<< 17)
2658 + mips_elf_hash_bfd_vma (entry
->d
.addend
)))
2659 : entry
->d
.h
->root
.root
.root
.hash
);
2663 mips_elf_multi_got_entry_eq (const void *entry1
, const void *entry2
)
2665 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2666 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2668 /* Any two LDM entries match. */
2669 if (e1
->tls_type
& e2
->tls_type
& GOT_TLS_LDM
)
2672 /* Nothing else matches an LDM entry. */
2673 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2676 return e1
->symndx
== e2
->symndx
2677 && (e1
->symndx
>= 0 ? e1
->abfd
== e2
->abfd
&& e1
->d
.addend
== e2
->d
.addend
2678 : e1
->abfd
== NULL
|| e2
->abfd
== NULL
2679 ? e1
->abfd
== e2
->abfd
&& e1
->d
.address
== e2
->d
.address
2680 : e1
->d
.h
== e2
->d
.h
);
2684 mips_got_page_entry_hash (const void *entry_
)
2686 const struct mips_got_page_entry
*entry
;
2688 entry
= (const struct mips_got_page_entry
*) entry_
;
2689 return entry
->abfd
->id
+ entry
->symndx
;
2693 mips_got_page_entry_eq (const void *entry1_
, const void *entry2_
)
2695 const struct mips_got_page_entry
*entry1
, *entry2
;
2697 entry1
= (const struct mips_got_page_entry
*) entry1_
;
2698 entry2
= (const struct mips_got_page_entry
*) entry2_
;
2699 return entry1
->abfd
== entry2
->abfd
&& entry1
->symndx
== entry2
->symndx
;
2702 /* Return the dynamic relocation section. If it doesn't exist, try to
2703 create a new it if CREATE_P, otherwise return NULL. Also return NULL
2704 if creation fails. */
2707 mips_elf_rel_dyn_section (struct bfd_link_info
*info
, bfd_boolean create_p
)
2713 dname
= MIPS_ELF_REL_DYN_NAME (info
);
2714 dynobj
= elf_hash_table (info
)->dynobj
;
2715 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
2716 if (sreloc
== NULL
&& create_p
)
2718 sreloc
= bfd_make_section_with_flags (dynobj
, dname
,
2723 | SEC_LINKER_CREATED
2726 || ! bfd_set_section_alignment (dynobj
, sreloc
,
2727 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
2733 /* Count the number of relocations needed for a TLS GOT entry, with
2734 access types from TLS_TYPE, and symbol H (or a local symbol if H
2738 mips_tls_got_relocs (struct bfd_link_info
*info
, unsigned char tls_type
,
2739 struct elf_link_hash_entry
*h
)
2743 bfd_boolean need_relocs
= FALSE
;
2744 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2746 if (h
&& WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2747 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, h
)))
2750 if ((info
->shared
|| indx
!= 0)
2752 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2753 || h
->root
.type
!= bfd_link_hash_undefweak
))
2759 if (tls_type
& GOT_TLS_GD
)
2766 if (tls_type
& GOT_TLS_IE
)
2769 if ((tls_type
& GOT_TLS_LDM
) && info
->shared
)
2775 /* Count the number of TLS relocations required for the GOT entry in
2776 ARG1, if it describes a local symbol. */
2779 mips_elf_count_local_tls_relocs (void **arg1
, void *arg2
)
2781 struct mips_got_entry
*entry
= * (struct mips_got_entry
**) arg1
;
2782 struct mips_elf_count_tls_arg
*arg
= arg2
;
2784 if (entry
->abfd
!= NULL
&& entry
->symndx
!= -1)
2785 arg
->needed
+= mips_tls_got_relocs (arg
->info
, entry
->tls_type
, NULL
);
2790 /* Count the number of TLS GOT entries required for the global (or
2791 forced-local) symbol in ARG1. */
2794 mips_elf_count_global_tls_entries (void *arg1
, void *arg2
)
2796 struct mips_elf_link_hash_entry
*hm
2797 = (struct mips_elf_link_hash_entry
*) arg1
;
2798 struct mips_elf_count_tls_arg
*arg
= arg2
;
2800 if (hm
->tls_type
& GOT_TLS_GD
)
2802 if (hm
->tls_type
& GOT_TLS_IE
)
2808 /* Count the number of TLS relocations required for the global (or
2809 forced-local) symbol in ARG1. */
2812 mips_elf_count_global_tls_relocs (void *arg1
, void *arg2
)
2814 struct mips_elf_link_hash_entry
*hm
2815 = (struct mips_elf_link_hash_entry
*) arg1
;
2816 struct mips_elf_count_tls_arg
*arg
= arg2
;
2818 arg
->needed
+= mips_tls_got_relocs (arg
->info
, hm
->tls_type
, &hm
->root
);
2823 /* Output a simple dynamic relocation into SRELOC. */
2826 mips_elf_output_dynamic_relocation (bfd
*output_bfd
,
2828 unsigned long reloc_index
,
2833 Elf_Internal_Rela rel
[3];
2835 memset (rel
, 0, sizeof (rel
));
2837 rel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, r_type
);
2838 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
2840 if (ABI_64_P (output_bfd
))
2842 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
2843 (output_bfd
, &rel
[0],
2845 + reloc_index
* sizeof (Elf64_Mips_External_Rel
)));
2848 bfd_elf32_swap_reloc_out
2849 (output_bfd
, &rel
[0],
2851 + reloc_index
* sizeof (Elf32_External_Rel
)));
2854 /* Initialize a set of TLS GOT entries for one symbol. */
2857 mips_elf_initialize_tls_slots (bfd
*abfd
, bfd_vma got_offset
,
2858 unsigned char *tls_type_p
,
2859 struct bfd_link_info
*info
,
2860 struct mips_elf_link_hash_entry
*h
,
2863 struct mips_elf_link_hash_table
*htab
;
2865 asection
*sreloc
, *sgot
;
2866 bfd_vma offset
, offset2
;
2867 bfd_boolean need_relocs
= FALSE
;
2869 htab
= mips_elf_hash_table (info
);
2878 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2880 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, &h
->root
)
2881 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
2882 indx
= h
->root
.dynindx
;
2885 if (*tls_type_p
& GOT_TLS_DONE
)
2888 if ((info
->shared
|| indx
!= 0)
2890 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
2891 || h
->root
.type
!= bfd_link_hash_undefweak
))
2894 /* MINUS_ONE means the symbol is not defined in this object. It may not
2895 be defined at all; assume that the value doesn't matter in that
2896 case. Otherwise complain if we would use the value. */
2897 BFD_ASSERT (value
!= MINUS_ONE
|| (indx
!= 0 && need_relocs
)
2898 || h
->root
.root
.type
== bfd_link_hash_undefweak
);
2900 /* Emit necessary relocations. */
2901 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
2903 /* General Dynamic. */
2904 if (*tls_type_p
& GOT_TLS_GD
)
2906 offset
= got_offset
;
2907 offset2
= offset
+ MIPS_ELF_GOT_SIZE (abfd
);
2911 mips_elf_output_dynamic_relocation
2912 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2913 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2914 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2917 mips_elf_output_dynamic_relocation
2918 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2919 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPREL64
: R_MIPS_TLS_DTPREL32
,
2920 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset2
);
2922 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2923 sgot
->contents
+ offset2
);
2927 MIPS_ELF_PUT_WORD (abfd
, 1,
2928 sgot
->contents
+ offset
);
2929 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2930 sgot
->contents
+ offset2
);
2933 got_offset
+= 2 * MIPS_ELF_GOT_SIZE (abfd
);
2936 /* Initial Exec model. */
2937 if (*tls_type_p
& GOT_TLS_IE
)
2939 offset
= got_offset
;
2944 MIPS_ELF_PUT_WORD (abfd
, value
- elf_hash_table (info
)->tls_sec
->vma
,
2945 sgot
->contents
+ offset
);
2947 MIPS_ELF_PUT_WORD (abfd
, 0,
2948 sgot
->contents
+ offset
);
2950 mips_elf_output_dynamic_relocation
2951 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2952 ABI_64_P (abfd
) ? R_MIPS_TLS_TPREL64
: R_MIPS_TLS_TPREL32
,
2953 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2956 MIPS_ELF_PUT_WORD (abfd
, value
- tprel_base (info
),
2957 sgot
->contents
+ offset
);
2960 if (*tls_type_p
& GOT_TLS_LDM
)
2962 /* The initial offset is zero, and the LD offsets will include the
2963 bias by DTP_OFFSET. */
2964 MIPS_ELF_PUT_WORD (abfd
, 0,
2965 sgot
->contents
+ got_offset
2966 + MIPS_ELF_GOT_SIZE (abfd
));
2969 MIPS_ELF_PUT_WORD (abfd
, 1,
2970 sgot
->contents
+ got_offset
);
2972 mips_elf_output_dynamic_relocation
2973 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2974 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2975 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
2978 *tls_type_p
|= GOT_TLS_DONE
;
2981 /* Return the GOT index to use for a relocation of type R_TYPE against
2982 a symbol accessed using TLS_TYPE models. The GOT entries for this
2983 symbol in this GOT start at GOT_INDEX. This function initializes the
2984 GOT entries and corresponding relocations. */
2987 mips_tls_got_index (bfd
*abfd
, bfd_vma got_index
, unsigned char *tls_type
,
2988 int r_type
, struct bfd_link_info
*info
,
2989 struct mips_elf_link_hash_entry
*h
, bfd_vma symbol
)
2991 BFD_ASSERT (r_type
== R_MIPS_TLS_GOTTPREL
|| r_type
== R_MIPS_TLS_GD
2992 || r_type
== R_MIPS_TLS_LDM
);
2994 mips_elf_initialize_tls_slots (abfd
, got_index
, tls_type
, info
, h
, symbol
);
2996 if (r_type
== R_MIPS_TLS_GOTTPREL
)
2998 BFD_ASSERT (*tls_type
& GOT_TLS_IE
);
2999 if (*tls_type
& GOT_TLS_GD
)
3000 return got_index
+ 2 * MIPS_ELF_GOT_SIZE (abfd
);
3005 if (r_type
== R_MIPS_TLS_GD
)
3007 BFD_ASSERT (*tls_type
& GOT_TLS_GD
);
3011 if (r_type
== R_MIPS_TLS_LDM
)
3013 BFD_ASSERT (*tls_type
& GOT_TLS_LDM
);
3020 /* Return the offset from _GLOBAL_OFFSET_TABLE_ of the .got.plt entry
3021 for global symbol H. .got.plt comes before the GOT, so the offset
3022 will be negative. */
3025 mips_elf_gotplt_index (struct bfd_link_info
*info
,
3026 struct elf_link_hash_entry
*h
)
3028 bfd_vma plt_index
, got_address
, got_value
;
3029 struct mips_elf_link_hash_table
*htab
;
3031 htab
= mips_elf_hash_table (info
);
3032 BFD_ASSERT (htab
!= NULL
);
3034 BFD_ASSERT (h
->plt
.offset
!= (bfd_vma
) -1);
3036 /* This function only works for VxWorks, because a non-VxWorks .got.plt
3037 section starts with reserved entries. */
3038 BFD_ASSERT (htab
->is_vxworks
);
3040 /* Calculate the index of the symbol's PLT entry. */
3041 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
3043 /* Calculate the address of the associated .got.plt entry. */
3044 got_address
= (htab
->sgotplt
->output_section
->vma
3045 + htab
->sgotplt
->output_offset
3048 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
3049 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
3050 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
3051 + htab
->root
.hgot
->root
.u
.def
.value
);
3053 return got_address
- got_value
;
3056 /* Return the GOT offset for address VALUE. If there is not yet a GOT
3057 entry for this value, create one. If R_SYMNDX refers to a TLS symbol,
3058 create a TLS GOT entry instead. Return -1 if no satisfactory GOT
3059 offset can be found. */
3062 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3063 bfd_vma value
, unsigned long r_symndx
,
3064 struct mips_elf_link_hash_entry
*h
, int r_type
)
3066 struct mips_elf_link_hash_table
*htab
;
3067 struct mips_got_entry
*entry
;
3069 htab
= mips_elf_hash_table (info
);
3070 BFD_ASSERT (htab
!= NULL
);
3072 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
,
3073 r_symndx
, h
, r_type
);
3077 if (TLS_RELOC_P (r_type
))
3079 if (entry
->symndx
== -1 && htab
->got_info
->next
== NULL
)
3080 /* A type (3) entry in the single-GOT case. We use the symbol's
3081 hash table entry to track the index. */
3082 return mips_tls_got_index (abfd
, h
->tls_got_offset
, &h
->tls_type
,
3083 r_type
, info
, h
, value
);
3085 return mips_tls_got_index (abfd
, entry
->gotidx
, &entry
->tls_type
,
3086 r_type
, info
, h
, value
);
3089 return entry
->gotidx
;
3092 /* Returns the GOT index for the global symbol indicated by H. */
3095 mips_elf_global_got_index (bfd
*abfd
, bfd
*ibfd
, struct elf_link_hash_entry
*h
,
3096 int r_type
, struct bfd_link_info
*info
)
3098 struct mips_elf_link_hash_table
*htab
;
3100 struct mips_got_info
*g
, *gg
;
3101 long global_got_dynindx
= 0;
3103 htab
= mips_elf_hash_table (info
);
3104 BFD_ASSERT (htab
!= NULL
);
3106 gg
= g
= htab
->got_info
;
3107 if (g
->bfd2got
&& ibfd
)
3109 struct mips_got_entry e
, *p
;
3111 BFD_ASSERT (h
->dynindx
>= 0);
3113 g
= mips_elf_got_for_ibfd (g
, ibfd
);
3114 if (g
->next
!= gg
|| TLS_RELOC_P (r_type
))
3118 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
3121 p
= htab_find (g
->got_entries
, &e
);
3123 BFD_ASSERT (p
->gotidx
> 0);
3125 if (TLS_RELOC_P (r_type
))
3127 bfd_vma value
= MINUS_ONE
;
3128 if ((h
->root
.type
== bfd_link_hash_defined
3129 || h
->root
.type
== bfd_link_hash_defweak
)
3130 && h
->root
.u
.def
.section
->output_section
)
3131 value
= (h
->root
.u
.def
.value
3132 + h
->root
.u
.def
.section
->output_offset
3133 + h
->root
.u
.def
.section
->output_section
->vma
);
3135 return mips_tls_got_index (abfd
, p
->gotidx
, &p
->tls_type
, r_type
,
3136 info
, e
.d
.h
, value
);
3143 if (gg
->global_gotsym
!= NULL
)
3144 global_got_dynindx
= gg
->global_gotsym
->dynindx
;
3146 if (TLS_RELOC_P (r_type
))
3148 struct mips_elf_link_hash_entry
*hm
3149 = (struct mips_elf_link_hash_entry
*) h
;
3150 bfd_vma value
= MINUS_ONE
;
3152 if ((h
->root
.type
== bfd_link_hash_defined
3153 || h
->root
.type
== bfd_link_hash_defweak
)
3154 && h
->root
.u
.def
.section
->output_section
)
3155 value
= (h
->root
.u
.def
.value
3156 + h
->root
.u
.def
.section
->output_offset
3157 + h
->root
.u
.def
.section
->output_section
->vma
);
3159 got_index
= mips_tls_got_index (abfd
, hm
->tls_got_offset
, &hm
->tls_type
,
3160 r_type
, info
, hm
, value
);
3164 /* Once we determine the global GOT entry with the lowest dynamic
3165 symbol table index, we must put all dynamic symbols with greater
3166 indices into the GOT. That makes it easy to calculate the GOT
3168 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
3169 got_index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
3170 * MIPS_ELF_GOT_SIZE (abfd
));
3172 BFD_ASSERT (got_index
< htab
->sgot
->size
);
3177 /* Find a GOT page entry that points to within 32KB of VALUE. These
3178 entries are supposed to be placed at small offsets in the GOT, i.e.,
3179 within 32KB of GP. Return the index of the GOT entry, or -1 if no
3180 entry could be created. If OFFSETP is nonnull, use it to return the
3181 offset of the GOT entry from VALUE. */
3184 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3185 bfd_vma value
, bfd_vma
*offsetp
)
3187 bfd_vma page
, got_index
;
3188 struct mips_got_entry
*entry
;
3190 page
= (value
+ 0x8000) & ~(bfd_vma
) 0xffff;
3191 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, page
, 0,
3192 NULL
, R_MIPS_GOT_PAGE
);
3197 got_index
= entry
->gotidx
;
3200 *offsetp
= value
- entry
->d
.address
;
3205 /* Find a local GOT entry for an R_MIPS*_GOT16 relocation against VALUE.
3206 EXTERNAL is true if the relocation was originally against a global
3207 symbol that binds locally. */
3210 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3211 bfd_vma value
, bfd_boolean external
)
3213 struct mips_got_entry
*entry
;
3215 /* GOT16 relocations against local symbols are followed by a LO16
3216 relocation; those against global symbols are not. Thus if the
3217 symbol was originally local, the GOT16 relocation should load the
3218 equivalent of %hi(VALUE), otherwise it should load VALUE itself. */
3220 value
= mips_elf_high (value
) << 16;
3222 /* It doesn't matter whether the original relocation was R_MIPS_GOT16,
3223 R_MIPS16_GOT16, R_MIPS_CALL16, etc. The format of the entry is the
3224 same in all cases. */
3225 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
, 0,
3226 NULL
, R_MIPS_GOT16
);
3228 return entry
->gotidx
;
3233 /* Returns the offset for the entry at the INDEXth position
3237 mips_elf_got_offset_from_index (struct bfd_link_info
*info
, bfd
*output_bfd
,
3238 bfd
*input_bfd
, bfd_vma got_index
)
3240 struct mips_elf_link_hash_table
*htab
;
3244 htab
= mips_elf_hash_table (info
);
3245 BFD_ASSERT (htab
!= NULL
);
3248 gp
= _bfd_get_gp_value (output_bfd
)
3249 + mips_elf_adjust_gp (output_bfd
, htab
->got_info
, input_bfd
);
3251 return sgot
->output_section
->vma
+ sgot
->output_offset
+ got_index
- gp
;
3254 /* Create and return a local GOT entry for VALUE, which was calculated
3255 from a symbol belonging to INPUT_SECTON. Return NULL if it could not
3256 be created. If R_SYMNDX refers to a TLS symbol, create a TLS entry
3259 static struct mips_got_entry
*
3260 mips_elf_create_local_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
3261 bfd
*ibfd
, bfd_vma value
,
3262 unsigned long r_symndx
,
3263 struct mips_elf_link_hash_entry
*h
,
3266 struct mips_got_entry entry
, **loc
;
3267 struct mips_got_info
*g
;
3268 struct mips_elf_link_hash_table
*htab
;
3270 htab
= mips_elf_hash_table (info
);
3271 BFD_ASSERT (htab
!= NULL
);
3275 entry
.d
.address
= value
;
3278 g
= mips_elf_got_for_ibfd (htab
->got_info
, ibfd
);
3281 g
= mips_elf_got_for_ibfd (htab
->got_info
, abfd
);
3282 BFD_ASSERT (g
!= NULL
);
3285 /* This function shouldn't be called for symbols that live in the global
3287 BFD_ASSERT (h
== NULL
|| h
->global_got_area
== GGA_NONE
);
3288 if (TLS_RELOC_P (r_type
))
3290 struct mips_got_entry
*p
;
3293 if (r_type
== R_MIPS_TLS_LDM
)
3295 entry
.tls_type
= GOT_TLS_LDM
;
3301 entry
.symndx
= r_symndx
;
3307 p
= (struct mips_got_entry
*)
3308 htab_find (g
->got_entries
, &entry
);
3314 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
3319 entry
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
3322 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3327 memcpy (*loc
, &entry
, sizeof entry
);
3329 if (g
->assigned_gotno
> g
->local_gotno
)
3331 (*loc
)->gotidx
= -1;
3332 /* We didn't allocate enough space in the GOT. */
3333 (*_bfd_error_handler
)
3334 (_("not enough GOT space for local GOT entries"));
3335 bfd_set_error (bfd_error_bad_value
);
3339 MIPS_ELF_PUT_WORD (abfd
, value
,
3340 (htab
->sgot
->contents
+ entry
.gotidx
));
3342 /* These GOT entries need a dynamic relocation on VxWorks. */
3343 if (htab
->is_vxworks
)
3345 Elf_Internal_Rela outrel
;
3348 bfd_vma got_address
;
3350 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3351 got_address
= (htab
->sgot
->output_section
->vma
3352 + htab
->sgot
->output_offset
3355 rloc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
3356 outrel
.r_offset
= got_address
;
3357 outrel
.r_info
= ELF32_R_INFO (STN_UNDEF
, R_MIPS_32
);
3358 outrel
.r_addend
= value
;
3359 bfd_elf32_swap_reloca_out (abfd
, &outrel
, rloc
);
3365 /* Return the number of dynamic section symbols required by OUTPUT_BFD.
3366 The number might be exact or a worst-case estimate, depending on how
3367 much information is available to elf_backend_omit_section_dynsym at
3368 the current linking stage. */
3370 static bfd_size_type
3371 count_section_dynsyms (bfd
*output_bfd
, struct bfd_link_info
*info
)
3373 bfd_size_type count
;
3376 if (info
->shared
|| elf_hash_table (info
)->is_relocatable_executable
)
3379 const struct elf_backend_data
*bed
;
3381 bed
= get_elf_backend_data (output_bfd
);
3382 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
3383 if ((p
->flags
& SEC_EXCLUDE
) == 0
3384 && (p
->flags
& SEC_ALLOC
) != 0
3385 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
3391 /* Sort the dynamic symbol table so that symbols that need GOT entries
3392 appear towards the end. */
3395 mips_elf_sort_hash_table (bfd
*abfd
, struct bfd_link_info
*info
)
3397 struct mips_elf_link_hash_table
*htab
;
3398 struct mips_elf_hash_sort_data hsd
;
3399 struct mips_got_info
*g
;
3401 if (elf_hash_table (info
)->dynsymcount
== 0)
3404 htab
= mips_elf_hash_table (info
);
3405 BFD_ASSERT (htab
!= NULL
);
3412 hsd
.max_unref_got_dynindx
3413 = hsd
.min_got_dynindx
3414 = (elf_hash_table (info
)->dynsymcount
- g
->reloc_only_gotno
);
3415 hsd
.max_non_got_dynindx
= count_section_dynsyms (abfd
, info
) + 1;
3416 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
3417 elf_hash_table (info
)),
3418 mips_elf_sort_hash_table_f
,
3421 /* There should have been enough room in the symbol table to
3422 accommodate both the GOT and non-GOT symbols. */
3423 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
3424 BFD_ASSERT ((unsigned long) hsd
.max_unref_got_dynindx
3425 == elf_hash_table (info
)->dynsymcount
);
3426 BFD_ASSERT (elf_hash_table (info
)->dynsymcount
- hsd
.min_got_dynindx
3427 == g
->global_gotno
);
3429 /* Now we know which dynamic symbol has the lowest dynamic symbol
3430 table index in the GOT. */
3431 g
->global_gotsym
= hsd
.low
;
3436 /* If H needs a GOT entry, assign it the highest available dynamic
3437 index. Otherwise, assign it the lowest available dynamic
3441 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
3443 struct mips_elf_hash_sort_data
*hsd
= data
;
3445 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3446 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3448 /* Symbols without dynamic symbol table entries aren't interesting
3450 if (h
->root
.dynindx
== -1)
3453 switch (h
->global_got_area
)
3456 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
3460 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
3462 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
3463 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3466 case GGA_RELOC_ONLY
:
3467 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
3469 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
3470 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3471 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
3478 /* If H is a symbol that needs a global GOT entry, but has a dynamic
3479 symbol table index lower than any we've seen to date, record it for
3483 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
3484 bfd
*abfd
, struct bfd_link_info
*info
,
3485 unsigned char tls_flag
)
3487 struct mips_elf_link_hash_table
*htab
;
3488 struct mips_elf_link_hash_entry
*hmips
;
3489 struct mips_got_entry entry
, **loc
;
3490 struct mips_got_info
*g
;
3492 htab
= mips_elf_hash_table (info
);
3493 BFD_ASSERT (htab
!= NULL
);
3495 hmips
= (struct mips_elf_link_hash_entry
*) h
;
3497 /* A global symbol in the GOT must also be in the dynamic symbol
3499 if (h
->dynindx
== -1)
3501 switch (ELF_ST_VISIBILITY (h
->other
))
3505 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
3508 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3512 /* Make sure we have a GOT to put this entry into. */
3514 BFD_ASSERT (g
!= NULL
);
3518 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
3521 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
3524 /* If we've already marked this entry as needing GOT space, we don't
3525 need to do it again. */
3528 (*loc
)->tls_type
|= tls_flag
;
3532 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3538 entry
.tls_type
= tls_flag
;
3540 memcpy (*loc
, &entry
, sizeof entry
);
3543 hmips
->global_got_area
= GGA_NORMAL
;
3548 /* Reserve space in G for a GOT entry containing the value of symbol
3549 SYMNDX in input bfd ABDF, plus ADDEND. */
3552 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
3553 struct bfd_link_info
*info
,
3554 unsigned char tls_flag
)
3556 struct mips_elf_link_hash_table
*htab
;
3557 struct mips_got_info
*g
;
3558 struct mips_got_entry entry
, **loc
;
3560 htab
= mips_elf_hash_table (info
);
3561 BFD_ASSERT (htab
!= NULL
);
3564 BFD_ASSERT (g
!= NULL
);
3567 entry
.symndx
= symndx
;
3568 entry
.d
.addend
= addend
;
3569 entry
.tls_type
= tls_flag
;
3570 loc
= (struct mips_got_entry
**)
3571 htab_find_slot (g
->got_entries
, &entry
, INSERT
);
3575 if (tls_flag
== GOT_TLS_GD
&& !((*loc
)->tls_type
& GOT_TLS_GD
))
3578 (*loc
)->tls_type
|= tls_flag
;
3580 else if (tls_flag
== GOT_TLS_IE
&& !((*loc
)->tls_type
& GOT_TLS_IE
))
3583 (*loc
)->tls_type
|= tls_flag
;
3591 entry
.tls_type
= tls_flag
;
3592 if (tls_flag
== GOT_TLS_IE
)
3594 else if (tls_flag
== GOT_TLS_GD
)
3596 else if (g
->tls_ldm_offset
== MINUS_ONE
)
3598 g
->tls_ldm_offset
= MINUS_TWO
;
3604 entry
.gotidx
= g
->local_gotno
++;
3608 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3613 memcpy (*loc
, &entry
, sizeof entry
);
3618 /* Return the maximum number of GOT page entries required for RANGE. */
3621 mips_elf_pages_for_range (const struct mips_got_page_range
*range
)
3623 return (range
->max_addend
- range
->min_addend
+ 0x1ffff) >> 16;
3626 /* Record that ABFD has a page relocation against symbol SYMNDX and
3627 that ADDEND is the addend for that relocation.
3629 This function creates an upper bound on the number of GOT slots
3630 required; no attempt is made to combine references to non-overridable
3631 global symbols across multiple input files. */
3634 mips_elf_record_got_page_entry (struct bfd_link_info
*info
, bfd
*abfd
,
3635 long symndx
, bfd_signed_vma addend
)
3637 struct mips_elf_link_hash_table
*htab
;
3638 struct mips_got_info
*g
;
3639 struct mips_got_page_entry lookup
, *entry
;
3640 struct mips_got_page_range
**range_ptr
, *range
;
3641 bfd_vma old_pages
, new_pages
;
3644 htab
= mips_elf_hash_table (info
);
3645 BFD_ASSERT (htab
!= NULL
);
3648 BFD_ASSERT (g
!= NULL
);
3650 /* Find the mips_got_page_entry hash table entry for this symbol. */
3652 lookup
.symndx
= symndx
;
3653 loc
= htab_find_slot (g
->got_page_entries
, &lookup
, INSERT
);
3657 /* Create a mips_got_page_entry if this is the first time we've
3659 entry
= (struct mips_got_page_entry
*) *loc
;
3662 entry
= bfd_alloc (abfd
, sizeof (*entry
));
3667 entry
->symndx
= symndx
;
3668 entry
->ranges
= NULL
;
3669 entry
->num_pages
= 0;
3673 /* Skip over ranges whose maximum extent cannot share a page entry
3675 range_ptr
= &entry
->ranges
;
3676 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
3677 range_ptr
= &(*range_ptr
)->next
;
3679 /* If we scanned to the end of the list, or found a range whose
3680 minimum extent cannot share a page entry with ADDEND, create
3681 a new singleton range. */
3683 if (!range
|| addend
< range
->min_addend
- 0xffff)
3685 range
= bfd_alloc (abfd
, sizeof (*range
));
3689 range
->next
= *range_ptr
;
3690 range
->min_addend
= addend
;
3691 range
->max_addend
= addend
;
3699 /* Remember how many pages the old range contributed. */
3700 old_pages
= mips_elf_pages_for_range (range
);
3702 /* Update the ranges. */
3703 if (addend
< range
->min_addend
)
3704 range
->min_addend
= addend
;
3705 else if (addend
> range
->max_addend
)
3707 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
3709 old_pages
+= mips_elf_pages_for_range (range
->next
);
3710 range
->max_addend
= range
->next
->max_addend
;
3711 range
->next
= range
->next
->next
;
3714 range
->max_addend
= addend
;
3717 /* Record any change in the total estimate. */
3718 new_pages
= mips_elf_pages_for_range (range
);
3719 if (old_pages
!= new_pages
)
3721 entry
->num_pages
+= new_pages
- old_pages
;
3722 g
->page_gotno
+= new_pages
- old_pages
;
3728 /* Add room for N relocations to the .rel(a).dyn section in ABFD. */
3731 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, struct bfd_link_info
*info
,
3735 struct mips_elf_link_hash_table
*htab
;
3737 htab
= mips_elf_hash_table (info
);
3738 BFD_ASSERT (htab
!= NULL
);
3740 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3741 BFD_ASSERT (s
!= NULL
);
3743 if (htab
->is_vxworks
)
3744 s
->size
+= n
* MIPS_ELF_RELA_SIZE (abfd
);
3749 /* Make room for a null element. */
3750 s
->size
+= MIPS_ELF_REL_SIZE (abfd
);
3753 s
->size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
3757 /* A htab_traverse callback for GOT entries. Set boolean *DATA to true
3758 if the GOT entry is for an indirect or warning symbol. */
3761 mips_elf_check_recreate_got (void **entryp
, void *data
)
3763 struct mips_got_entry
*entry
;
3764 bfd_boolean
*must_recreate
;
3766 entry
= (struct mips_got_entry
*) *entryp
;
3767 must_recreate
= (bfd_boolean
*) data
;
3768 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3770 struct mips_elf_link_hash_entry
*h
;
3773 if (h
->root
.root
.type
== bfd_link_hash_indirect
3774 || h
->root
.root
.type
== bfd_link_hash_warning
)
3776 *must_recreate
= TRUE
;
3783 /* A htab_traverse callback for GOT entries. Add all entries to
3784 hash table *DATA, converting entries for indirect and warning
3785 symbols into entries for the target symbol. Set *DATA to null
3789 mips_elf_recreate_got (void **entryp
, void *data
)
3792 struct mips_got_entry
*entry
;
3795 new_got
= (htab_t
*) data
;
3796 entry
= (struct mips_got_entry
*) *entryp
;
3797 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3799 struct mips_elf_link_hash_entry
*h
;
3802 while (h
->root
.root
.type
== bfd_link_hash_indirect
3803 || h
->root
.root
.type
== bfd_link_hash_warning
)
3805 BFD_ASSERT (h
->global_got_area
== GGA_NONE
);
3806 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3810 slot
= htab_find_slot (*new_got
, entry
, INSERT
);
3823 /* If any entries in G->got_entries are for indirect or warning symbols,
3824 replace them with entries for the target symbol. */
3827 mips_elf_resolve_final_got_entries (struct mips_got_info
*g
)
3829 bfd_boolean must_recreate
;
3832 must_recreate
= FALSE
;
3833 htab_traverse (g
->got_entries
, mips_elf_check_recreate_got
, &must_recreate
);
3836 new_got
= htab_create (htab_size (g
->got_entries
),
3837 mips_elf_got_entry_hash
,
3838 mips_elf_got_entry_eq
, NULL
);
3839 htab_traverse (g
->got_entries
, mips_elf_recreate_got
, &new_got
);
3840 if (new_got
== NULL
)
3843 /* Each entry in g->got_entries has either been copied to new_got
3844 or freed. Now delete the hash table itself. */
3845 htab_delete (g
->got_entries
);
3846 g
->got_entries
= new_got
;
3851 /* A mips_elf_link_hash_traverse callback for which DATA points
3852 to the link_info structure. Count the number of type (3) entries
3853 in the master GOT. */
3856 mips_elf_count_got_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
3858 struct bfd_link_info
*info
;
3859 struct mips_got_info
*g
;
3861 info
= (struct bfd_link_info
*) data
;
3862 g
= mips_elf_hash_table (info
)->got_info
;
3863 if (h
->global_got_area
!= GGA_NONE
)
3865 /* Make a final decision about whether the symbol belongs in the
3866 local or global GOT. Symbols that bind locally can (and in the
3867 case of forced-local symbols, must) live in the local GOT.
3868 Those that are aren't in the dynamic symbol table must also
3869 live in the local GOT.
3871 Note that the former condition does not always imply the
3872 latter: symbols do not bind locally if they are completely
3873 undefined. We'll report undefined symbols later if appropriate. */
3874 if (h
->root
.dynindx
== -1 || SYMBOL_REFERENCES_LOCAL (info
, &h
->root
))
3876 /* The symbol belongs in the local GOT. We no longer need this
3877 entry if it was only used for relocations; those relocations
3878 will be against the null or section symbol instead of H. */
3879 if (h
->global_got_area
!= GGA_RELOC_ONLY
)
3881 h
->global_got_area
= GGA_NONE
;
3886 if (h
->global_got_area
== GGA_RELOC_ONLY
)
3887 g
->reloc_only_gotno
++;
3893 /* Compute the hash value of the bfd in a bfd2got hash entry. */
3896 mips_elf_bfd2got_entry_hash (const void *entry_
)
3898 const struct mips_elf_bfd2got_hash
*entry
3899 = (struct mips_elf_bfd2got_hash
*)entry_
;
3901 return entry
->bfd
->id
;
3904 /* Check whether two hash entries have the same bfd. */
3907 mips_elf_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
3909 const struct mips_elf_bfd2got_hash
*e1
3910 = (const struct mips_elf_bfd2got_hash
*)entry1
;
3911 const struct mips_elf_bfd2got_hash
*e2
3912 = (const struct mips_elf_bfd2got_hash
*)entry2
;
3914 return e1
->bfd
== e2
->bfd
;
3917 /* In a multi-got link, determine the GOT to be used for IBFD. G must
3918 be the master GOT data. */
3920 static struct mips_got_info
*
3921 mips_elf_got_for_ibfd (struct mips_got_info
*g
, bfd
*ibfd
)
3923 struct mips_elf_bfd2got_hash e
, *p
;
3929 p
= htab_find (g
->bfd2got
, &e
);
3930 return p
? p
->g
: NULL
;
3933 /* Use BFD2GOT to find ABFD's got entry, creating one if none exists.
3934 Return NULL if an error occured. */
3936 static struct mips_got_info
*
3937 mips_elf_get_got_for_bfd (struct htab
*bfd2got
, bfd
*output_bfd
,
3940 struct mips_elf_bfd2got_hash bfdgot_entry
, *bfdgot
;
3941 struct mips_got_info
*g
;
3944 bfdgot_entry
.bfd
= input_bfd
;
3945 bfdgotp
= htab_find_slot (bfd2got
, &bfdgot_entry
, INSERT
);
3946 bfdgot
= (struct mips_elf_bfd2got_hash
*) *bfdgotp
;
3950 bfdgot
= ((struct mips_elf_bfd2got_hash
*)
3951 bfd_alloc (output_bfd
, sizeof (struct mips_elf_bfd2got_hash
)));
3957 g
= ((struct mips_got_info
*)
3958 bfd_alloc (output_bfd
, sizeof (struct mips_got_info
)));
3962 bfdgot
->bfd
= input_bfd
;
3965 g
->global_gotsym
= NULL
;
3966 g
->global_gotno
= 0;
3967 g
->reloc_only_gotno
= 0;
3970 g
->assigned_gotno
= -1;
3972 g
->tls_assigned_gotno
= 0;
3973 g
->tls_ldm_offset
= MINUS_ONE
;
3974 g
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3975 mips_elf_multi_got_entry_eq
, NULL
);
3976 if (g
->got_entries
== NULL
)
3979 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
3980 mips_got_page_entry_eq
, NULL
);
3981 if (g
->got_page_entries
== NULL
)
3991 /* A htab_traverse callback for the entries in the master got.
3992 Create one separate got for each bfd that has entries in the global
3993 got, such that we can tell how many local and global entries each
3997 mips_elf_make_got_per_bfd (void **entryp
, void *p
)
3999 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
4000 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
4001 struct mips_got_info
*g
;
4003 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
4010 /* Insert the GOT entry in the bfd's got entry hash table. */
4011 entryp
= htab_find_slot (g
->got_entries
, entry
, INSERT
);
4012 if (*entryp
!= NULL
)
4017 if (entry
->tls_type
)
4019 if (entry
->tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
4021 if (entry
->tls_type
& GOT_TLS_IE
)
4024 else if (entry
->symndx
>= 0 || entry
->d
.h
->global_got_area
== GGA_NONE
)
4032 /* A htab_traverse callback for the page entries in the master got.
4033 Associate each page entry with the bfd's got. */
4036 mips_elf_make_got_pages_per_bfd (void **entryp
, void *p
)
4038 struct mips_got_page_entry
*entry
= (struct mips_got_page_entry
*) *entryp
;
4039 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*) p
;
4040 struct mips_got_info
*g
;
4042 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
4049 /* Insert the GOT entry in the bfd's got entry hash table. */
4050 entryp
= htab_find_slot (g
->got_page_entries
, entry
, INSERT
);
4051 if (*entryp
!= NULL
)
4055 g
->page_gotno
+= entry
->num_pages
;
4059 /* Consider merging the got described by BFD2GOT with TO, using the
4060 information given by ARG. Return -1 if this would lead to overflow,
4061 1 if they were merged successfully, and 0 if a merge failed due to
4062 lack of memory. (These values are chosen so that nonnegative return
4063 values can be returned by a htab_traverse callback.) */
4066 mips_elf_merge_got_with (struct mips_elf_bfd2got_hash
*bfd2got
,
4067 struct mips_got_info
*to
,
4068 struct mips_elf_got_per_bfd_arg
*arg
)
4070 struct mips_got_info
*from
= bfd2got
->g
;
4071 unsigned int estimate
;
4073 /* Work out how many page entries we would need for the combined GOT. */
4074 estimate
= arg
->max_pages
;
4075 if (estimate
>= from
->page_gotno
+ to
->page_gotno
)
4076 estimate
= from
->page_gotno
+ to
->page_gotno
;
4078 /* And conservatively estimate how many local, global and TLS entries
4080 estimate
+= (from
->local_gotno
4081 + from
->global_gotno
4087 /* Bail out if the combined GOT might be too big. */
4088 if (estimate
> arg
->max_count
)
4091 /* Commit to the merge. Record that TO is now the bfd for this got. */
4094 /* Transfer the bfd's got information from FROM to TO. */
4095 htab_traverse (from
->got_entries
, mips_elf_make_got_per_bfd
, arg
);
4096 if (arg
->obfd
== NULL
)
4099 htab_traverse (from
->got_page_entries
, mips_elf_make_got_pages_per_bfd
, arg
);
4100 if (arg
->obfd
== NULL
)
4103 /* We don't have to worry about releasing memory of the actual
4104 got entries, since they're all in the master got_entries hash
4106 htab_delete (from
->got_entries
);
4107 htab_delete (from
->got_page_entries
);
4111 /* Attempt to merge gots of different input bfds. Try to use as much
4112 as possible of the primary got, since it doesn't require explicit
4113 dynamic relocations, but don't use bfds that would reference global
4114 symbols out of the addressable range. Failing the primary got,
4115 attempt to merge with the current got, or finish the current got
4116 and then make make the new got current. */
4119 mips_elf_merge_gots (void **bfd2got_
, void *p
)
4121 struct mips_elf_bfd2got_hash
*bfd2got
4122 = (struct mips_elf_bfd2got_hash
*)*bfd2got_
;
4123 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
4124 struct mips_got_info
*g
;
4125 unsigned int estimate
;
4130 /* Work out the number of page, local and TLS entries. */
4131 estimate
= arg
->max_pages
;
4132 if (estimate
> g
->page_gotno
)
4133 estimate
= g
->page_gotno
;
4134 estimate
+= g
->local_gotno
+ g
->tls_gotno
;
4136 /* We place TLS GOT entries after both locals and globals. The globals
4137 for the primary GOT may overflow the normal GOT size limit, so be
4138 sure not to merge a GOT which requires TLS with the primary GOT in that
4139 case. This doesn't affect non-primary GOTs. */
4140 estimate
+= (g
->tls_gotno
> 0 ? arg
->global_count
: g
->global_gotno
);
4142 if (estimate
<= arg
->max_count
)
4144 /* If we don't have a primary GOT, use it as
4145 a starting point for the primary GOT. */
4148 arg
->primary
= bfd2got
->g
;
4152 /* Try merging with the primary GOT. */
4153 result
= mips_elf_merge_got_with (bfd2got
, arg
->primary
, arg
);
4158 /* If we can merge with the last-created got, do it. */
4161 result
= mips_elf_merge_got_with (bfd2got
, arg
->current
, arg
);
4166 /* Well, we couldn't merge, so create a new GOT. Don't check if it
4167 fits; if it turns out that it doesn't, we'll get relocation
4168 overflows anyway. */
4169 g
->next
= arg
->current
;
4175 /* Set the TLS GOT index for the GOT entry in ENTRYP. ENTRYP's NEXT field
4176 is null iff there is just a single GOT. */
4179 mips_elf_initialize_tls_index (void **entryp
, void *p
)
4181 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
4182 struct mips_got_info
*g
= p
;
4184 unsigned char tls_type
;
4186 /* We're only interested in TLS symbols. */
4187 if (entry
->tls_type
== 0)
4190 next_index
= MIPS_ELF_GOT_SIZE (entry
->abfd
) * (long) g
->tls_assigned_gotno
;
4192 if (entry
->symndx
== -1 && g
->next
== NULL
)
4194 /* A type (3) got entry in the single-GOT case. We use the symbol's
4195 hash table entry to track its index. */
4196 if (entry
->d
.h
->tls_type
& GOT_TLS_OFFSET_DONE
)
4198 entry
->d
.h
->tls_type
|= GOT_TLS_OFFSET_DONE
;
4199 entry
->d
.h
->tls_got_offset
= next_index
;
4200 tls_type
= entry
->d
.h
->tls_type
;
4204 if (entry
->tls_type
& GOT_TLS_LDM
)
4206 /* There are separate mips_got_entry objects for each input bfd
4207 that requires an LDM entry. Make sure that all LDM entries in
4208 a GOT resolve to the same index. */
4209 if (g
->tls_ldm_offset
!= MINUS_TWO
&& g
->tls_ldm_offset
!= MINUS_ONE
)
4211 entry
->gotidx
= g
->tls_ldm_offset
;
4214 g
->tls_ldm_offset
= next_index
;
4216 entry
->gotidx
= next_index
;
4217 tls_type
= entry
->tls_type
;
4220 /* Account for the entries we've just allocated. */
4221 if (tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
4222 g
->tls_assigned_gotno
+= 2;
4223 if (tls_type
& GOT_TLS_IE
)
4224 g
->tls_assigned_gotno
+= 1;
4229 /* If passed a NULL mips_got_info in the argument, set the marker used
4230 to tell whether a global symbol needs a got entry (in the primary
4231 got) to the given VALUE.
4233 If passed a pointer G to a mips_got_info in the argument (it must
4234 not be the primary GOT), compute the offset from the beginning of
4235 the (primary) GOT section to the entry in G corresponding to the
4236 global symbol. G's assigned_gotno must contain the index of the
4237 first available global GOT entry in G. VALUE must contain the size
4238 of a GOT entry in bytes. For each global GOT entry that requires a
4239 dynamic relocation, NEEDED_RELOCS is incremented, and the symbol is
4240 marked as not eligible for lazy resolution through a function
4243 mips_elf_set_global_got_offset (void **entryp
, void *p
)
4245 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
4246 struct mips_elf_set_global_got_offset_arg
*arg
4247 = (struct mips_elf_set_global_got_offset_arg
*)p
;
4248 struct mips_got_info
*g
= arg
->g
;
4250 if (g
&& entry
->tls_type
!= GOT_NORMAL
)
4251 arg
->needed_relocs
+=
4252 mips_tls_got_relocs (arg
->info
, entry
->tls_type
,
4253 entry
->symndx
== -1 ? &entry
->d
.h
->root
: NULL
);
4255 if (entry
->abfd
!= NULL
4256 && entry
->symndx
== -1
4257 && entry
->d
.h
->global_got_area
!= GGA_NONE
)
4261 BFD_ASSERT (g
->global_gotsym
== NULL
);
4263 entry
->gotidx
= arg
->value
* (long) g
->assigned_gotno
++;
4264 if (arg
->info
->shared
4265 || (elf_hash_table (arg
->info
)->dynamic_sections_created
4266 && entry
->d
.h
->root
.def_dynamic
4267 && !entry
->d
.h
->root
.def_regular
))
4268 ++arg
->needed_relocs
;
4271 entry
->d
.h
->global_got_area
= arg
->value
;
4277 /* A htab_traverse callback for GOT entries for which DATA is the
4278 bfd_link_info. Forbid any global symbols from having traditional
4279 lazy-binding stubs. */
4282 mips_elf_forbid_lazy_stubs (void **entryp
, void *data
)
4284 struct bfd_link_info
*info
;
4285 struct mips_elf_link_hash_table
*htab
;
4286 struct mips_got_entry
*entry
;
4288 entry
= (struct mips_got_entry
*) *entryp
;
4289 info
= (struct bfd_link_info
*) data
;
4290 htab
= mips_elf_hash_table (info
);
4291 BFD_ASSERT (htab
!= NULL
);
4293 if (entry
->abfd
!= NULL
4294 && entry
->symndx
== -1
4295 && entry
->d
.h
->needs_lazy_stub
)
4297 entry
->d
.h
->needs_lazy_stub
= FALSE
;
4298 htab
->lazy_stub_count
--;
4304 /* Return the offset of an input bfd IBFD's GOT from the beginning of
4307 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
4309 if (g
->bfd2got
== NULL
)
4312 g
= mips_elf_got_for_ibfd (g
, ibfd
);
4316 BFD_ASSERT (g
->next
);
4320 return (g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
)
4321 * MIPS_ELF_GOT_SIZE (abfd
);
4324 /* Turn a single GOT that is too big for 16-bit addressing into
4325 a sequence of GOTs, each one 16-bit addressable. */
4328 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
4329 asection
*got
, bfd_size_type pages
)
4331 struct mips_elf_link_hash_table
*htab
;
4332 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
4333 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
4334 struct mips_got_info
*g
, *gg
;
4335 unsigned int assign
, needed_relocs
;
4338 dynobj
= elf_hash_table (info
)->dynobj
;
4339 htab
= mips_elf_hash_table (info
);
4340 BFD_ASSERT (htab
!= NULL
);
4343 g
->bfd2got
= htab_try_create (1, mips_elf_bfd2got_entry_hash
,
4344 mips_elf_bfd2got_entry_eq
, NULL
);
4345 if (g
->bfd2got
== NULL
)
4348 got_per_bfd_arg
.bfd2got
= g
->bfd2got
;
4349 got_per_bfd_arg
.obfd
= abfd
;
4350 got_per_bfd_arg
.info
= info
;
4352 /* Count how many GOT entries each input bfd requires, creating a
4353 map from bfd to got info while at that. */
4354 htab_traverse (g
->got_entries
, mips_elf_make_got_per_bfd
, &got_per_bfd_arg
);
4355 if (got_per_bfd_arg
.obfd
== NULL
)
4358 /* Also count how many page entries each input bfd requires. */
4359 htab_traverse (g
->got_page_entries
, mips_elf_make_got_pages_per_bfd
,
4361 if (got_per_bfd_arg
.obfd
== NULL
)
4364 got_per_bfd_arg
.current
= NULL
;
4365 got_per_bfd_arg
.primary
= NULL
;
4366 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (info
)
4367 / MIPS_ELF_GOT_SIZE (abfd
))
4368 - htab
->reserved_gotno
);
4369 got_per_bfd_arg
.max_pages
= pages
;
4370 /* The number of globals that will be included in the primary GOT.
4371 See the calls to mips_elf_set_global_got_offset below for more
4373 got_per_bfd_arg
.global_count
= g
->global_gotno
;
4375 /* Try to merge the GOTs of input bfds together, as long as they
4376 don't seem to exceed the maximum GOT size, choosing one of them
4377 to be the primary GOT. */
4378 htab_traverse (g
->bfd2got
, mips_elf_merge_gots
, &got_per_bfd_arg
);
4379 if (got_per_bfd_arg
.obfd
== NULL
)
4382 /* If we do not find any suitable primary GOT, create an empty one. */
4383 if (got_per_bfd_arg
.primary
== NULL
)
4385 g
->next
= (struct mips_got_info
*)
4386 bfd_alloc (abfd
, sizeof (struct mips_got_info
));
4387 if (g
->next
== NULL
)
4390 g
->next
->global_gotsym
= NULL
;
4391 g
->next
->global_gotno
= 0;
4392 g
->next
->reloc_only_gotno
= 0;
4393 g
->next
->local_gotno
= 0;
4394 g
->next
->page_gotno
= 0;
4395 g
->next
->tls_gotno
= 0;
4396 g
->next
->assigned_gotno
= 0;
4397 g
->next
->tls_assigned_gotno
= 0;
4398 g
->next
->tls_ldm_offset
= MINUS_ONE
;
4399 g
->next
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
4400 mips_elf_multi_got_entry_eq
,
4402 if (g
->next
->got_entries
== NULL
)
4404 g
->next
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4405 mips_got_page_entry_eq
,
4407 if (g
->next
->got_page_entries
== NULL
)
4409 g
->next
->bfd2got
= NULL
;
4412 g
->next
= got_per_bfd_arg
.primary
;
4413 g
->next
->next
= got_per_bfd_arg
.current
;
4415 /* GG is now the master GOT, and G is the primary GOT. */
4419 /* Map the output bfd to the primary got. That's what we're going
4420 to use for bfds that use GOT16 or GOT_PAGE relocations that we
4421 didn't mark in check_relocs, and we want a quick way to find it.
4422 We can't just use gg->next because we're going to reverse the
4425 struct mips_elf_bfd2got_hash
*bfdgot
;
4428 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
4429 (abfd
, sizeof (struct mips_elf_bfd2got_hash
));
4436 bfdgotp
= htab_find_slot (gg
->bfd2got
, bfdgot
, INSERT
);
4438 BFD_ASSERT (*bfdgotp
== NULL
);
4442 /* Every symbol that is referenced in a dynamic relocation must be
4443 present in the primary GOT, so arrange for them to appear after
4444 those that are actually referenced. */
4445 gg
->reloc_only_gotno
= gg
->global_gotno
- g
->global_gotno
;
4446 g
->global_gotno
= gg
->global_gotno
;
4448 set_got_offset_arg
.g
= NULL
;
4449 set_got_offset_arg
.value
= GGA_RELOC_ONLY
;
4450 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_offset
,
4451 &set_got_offset_arg
);
4452 set_got_offset_arg
.value
= GGA_NORMAL
;
4453 htab_traverse (g
->got_entries
, mips_elf_set_global_got_offset
,
4454 &set_got_offset_arg
);
4456 /* Now go through the GOTs assigning them offset ranges.
4457 [assigned_gotno, local_gotno[ will be set to the range of local
4458 entries in each GOT. We can then compute the end of a GOT by
4459 adding local_gotno to global_gotno. We reverse the list and make
4460 it circular since then we'll be able to quickly compute the
4461 beginning of a GOT, by computing the end of its predecessor. To
4462 avoid special cases for the primary GOT, while still preserving
4463 assertions that are valid for both single- and multi-got links,
4464 we arrange for the main got struct to have the right number of
4465 global entries, but set its local_gotno such that the initial
4466 offset of the primary GOT is zero. Remember that the primary GOT
4467 will become the last item in the circular linked list, so it
4468 points back to the master GOT. */
4469 gg
->local_gotno
= -g
->global_gotno
;
4470 gg
->global_gotno
= g
->global_gotno
;
4477 struct mips_got_info
*gn
;
4479 assign
+= htab
->reserved_gotno
;
4480 g
->assigned_gotno
= assign
;
4481 g
->local_gotno
+= assign
;
4482 g
->local_gotno
+= (pages
< g
->page_gotno
? pages
: g
->page_gotno
);
4483 assign
= g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
;
4485 /* Take g out of the direct list, and push it onto the reversed
4486 list that gg points to. g->next is guaranteed to be nonnull after
4487 this operation, as required by mips_elf_initialize_tls_index. */
4492 /* Set up any TLS entries. We always place the TLS entries after
4493 all non-TLS entries. */
4494 g
->tls_assigned_gotno
= g
->local_gotno
+ g
->global_gotno
;
4495 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
4497 /* Move onto the next GOT. It will be a secondary GOT if nonull. */
4500 /* Forbid global symbols in every non-primary GOT from having
4501 lazy-binding stubs. */
4503 htab_traverse (g
->got_entries
, mips_elf_forbid_lazy_stubs
, info
);
4507 got
->size
= (gg
->next
->local_gotno
4508 + gg
->next
->global_gotno
4509 + gg
->next
->tls_gotno
) * MIPS_ELF_GOT_SIZE (abfd
);
4512 set_got_offset_arg
.value
= MIPS_ELF_GOT_SIZE (abfd
);
4513 set_got_offset_arg
.info
= info
;
4514 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
4516 unsigned int save_assign
;
4518 /* Assign offsets to global GOT entries. */
4519 save_assign
= g
->assigned_gotno
;
4520 g
->assigned_gotno
= g
->local_gotno
;
4521 set_got_offset_arg
.g
= g
;
4522 set_got_offset_arg
.needed_relocs
= 0;
4523 htab_traverse (g
->got_entries
,
4524 mips_elf_set_global_got_offset
,
4525 &set_got_offset_arg
);
4526 needed_relocs
+= set_got_offset_arg
.needed_relocs
;
4527 BFD_ASSERT (g
->assigned_gotno
- g
->local_gotno
<= g
->global_gotno
);
4529 g
->assigned_gotno
= save_assign
;
4532 needed_relocs
+= g
->local_gotno
- g
->assigned_gotno
;
4533 BFD_ASSERT (g
->assigned_gotno
== g
->next
->local_gotno
4534 + g
->next
->global_gotno
4535 + g
->next
->tls_gotno
4536 + htab
->reserved_gotno
);
4541 mips_elf_allocate_dynamic_relocations (dynobj
, info
,
4548 /* Returns the first relocation of type r_type found, beginning with
4549 RELOCATION. RELEND is one-past-the-end of the relocation table. */
4551 static const Elf_Internal_Rela
*
4552 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
4553 const Elf_Internal_Rela
*relocation
,
4554 const Elf_Internal_Rela
*relend
)
4556 unsigned long r_symndx
= ELF_R_SYM (abfd
, relocation
->r_info
);
4558 while (relocation
< relend
)
4560 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
4561 && ELF_R_SYM (abfd
, relocation
->r_info
) == r_symndx
)
4567 /* We didn't find it. */
4571 /* Return whether an input relocation is against a local symbol. */
4574 mips_elf_local_relocation_p (bfd
*input_bfd
,
4575 const Elf_Internal_Rela
*relocation
,
4576 asection
**local_sections
)
4578 unsigned long r_symndx
;
4579 Elf_Internal_Shdr
*symtab_hdr
;
4582 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4583 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4584 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
4586 if (r_symndx
< extsymoff
)
4588 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
4594 /* Sign-extend VALUE, which has the indicated number of BITS. */
4597 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
4599 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
4600 /* VALUE is negative. */
4601 value
|= ((bfd_vma
) - 1) << bits
;
4606 /* Return non-zero if the indicated VALUE has overflowed the maximum
4607 range expressible by a signed number with the indicated number of
4611 mips_elf_overflow_p (bfd_vma value
, int bits
)
4613 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
4615 if (svalue
> (1 << (bits
- 1)) - 1)
4616 /* The value is too big. */
4618 else if (svalue
< -(1 << (bits
- 1)))
4619 /* The value is too small. */
4626 /* Calculate the %high function. */
4629 mips_elf_high (bfd_vma value
)
4631 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
4634 /* Calculate the %higher function. */
4637 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
4640 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
4647 /* Calculate the %highest function. */
4650 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
4653 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
4660 /* Create the .compact_rel section. */
4663 mips_elf_create_compact_rel_section
4664 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4667 register asection
*s
;
4669 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4671 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
4674 s
= bfd_make_section_with_flags (abfd
, ".compact_rel", flags
);
4676 || ! bfd_set_section_alignment (abfd
, s
,
4677 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
4680 s
->size
= sizeof (Elf32_External_compact_rel
);
4686 /* Create the .got section to hold the global offset table. */
4689 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4692 register asection
*s
;
4693 struct elf_link_hash_entry
*h
;
4694 struct bfd_link_hash_entry
*bh
;
4695 struct mips_got_info
*g
;
4697 struct mips_elf_link_hash_table
*htab
;
4699 htab
= mips_elf_hash_table (info
);
4700 BFD_ASSERT (htab
!= NULL
);
4702 /* This function may be called more than once. */
4706 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4707 | SEC_LINKER_CREATED
);
4709 /* We have to use an alignment of 2**4 here because this is hardcoded
4710 in the function stub generation and in the linker script. */
4711 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
4713 || ! bfd_set_section_alignment (abfd
, s
, 4))
4717 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4718 linker script because we don't want to define the symbol if we
4719 are not creating a global offset table. */
4721 if (! (_bfd_generic_link_add_one_symbol
4722 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4723 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
4726 h
= (struct elf_link_hash_entry
*) bh
;
4729 h
->type
= STT_OBJECT
;
4730 elf_hash_table (info
)->hgot
= h
;
4733 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4736 amt
= sizeof (struct mips_got_info
);
4737 g
= bfd_alloc (abfd
, amt
);
4740 g
->global_gotsym
= NULL
;
4741 g
->global_gotno
= 0;
4742 g
->reloc_only_gotno
= 0;
4746 g
->assigned_gotno
= 0;
4749 g
->tls_ldm_offset
= MINUS_ONE
;
4750 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
4751 mips_elf_got_entry_eq
, NULL
);
4752 if (g
->got_entries
== NULL
)
4754 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4755 mips_got_page_entry_eq
, NULL
);
4756 if (g
->got_page_entries
== NULL
)
4759 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
4760 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
4762 /* We also need a .got.plt section when generating PLTs. */
4763 s
= bfd_make_section_with_flags (abfd
, ".got.plt",
4764 SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
4765 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4773 /* Return true if H refers to the special VxWorks __GOTT_BASE__ or
4774 __GOTT_INDEX__ symbols. These symbols are only special for
4775 shared objects; they are not used in executables. */
4778 is_gott_symbol (struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
)
4780 return (mips_elf_hash_table (info
)->is_vxworks
4782 && (strcmp (h
->root
.root
.string
, "__GOTT_BASE__") == 0
4783 || strcmp (h
->root
.root
.string
, "__GOTT_INDEX__") == 0));
4786 /* Return TRUE if a relocation of type R_TYPE from INPUT_BFD might
4787 require an la25 stub. See also mips_elf_local_pic_function_p,
4788 which determines whether the destination function ever requires a
4792 mips_elf_relocation_needs_la25_stub (bfd
*input_bfd
, int r_type
)
4794 /* We specifically ignore branches and jumps from EF_PIC objects,
4795 where the onus is on the compiler or programmer to perform any
4796 necessary initialization of $25. Sometimes such initialization
4797 is unnecessary; for example, -mno-shared functions do not use
4798 the incoming value of $25, and may therefore be called directly. */
4799 if (PIC_OBJECT_P (input_bfd
))
4814 /* Calculate the value produced by the RELOCATION (which comes from
4815 the INPUT_BFD). The ADDEND is the addend to use for this
4816 RELOCATION; RELOCATION->R_ADDEND is ignored.
4818 The result of the relocation calculation is stored in VALUEP.
4819 On exit, set *CROSS_MODE_JUMP_P to true if the relocation field
4820 is a MIPS16 jump to non-MIPS16 code, or vice versa.
4822 This function returns bfd_reloc_continue if the caller need take no
4823 further action regarding this relocation, bfd_reloc_notsupported if
4824 something goes dramatically wrong, bfd_reloc_overflow if an
4825 overflow occurs, and bfd_reloc_ok to indicate success. */
4827 static bfd_reloc_status_type
4828 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
4829 asection
*input_section
,
4830 struct bfd_link_info
*info
,
4831 const Elf_Internal_Rela
*relocation
,
4832 bfd_vma addend
, reloc_howto_type
*howto
,
4833 Elf_Internal_Sym
*local_syms
,
4834 asection
**local_sections
, bfd_vma
*valuep
,
4836 bfd_boolean
*cross_mode_jump_p
,
4837 bfd_boolean save_addend
)
4839 /* The eventual value we will return. */
4841 /* The address of the symbol against which the relocation is
4844 /* The final GP value to be used for the relocatable, executable, or
4845 shared object file being produced. */
4847 /* The place (section offset or address) of the storage unit being
4850 /* The value of GP used to create the relocatable object. */
4852 /* The offset into the global offset table at which the address of
4853 the relocation entry symbol, adjusted by the addend, resides
4854 during execution. */
4855 bfd_vma g
= MINUS_ONE
;
4856 /* The section in which the symbol referenced by the relocation is
4858 asection
*sec
= NULL
;
4859 struct mips_elf_link_hash_entry
*h
= NULL
;
4860 /* TRUE if the symbol referred to by this relocation is a local
4862 bfd_boolean local_p
, was_local_p
;
4863 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
4864 bfd_boolean gp_disp_p
= FALSE
;
4865 /* TRUE if the symbol referred to by this relocation is
4866 "__gnu_local_gp". */
4867 bfd_boolean gnu_local_gp_p
= FALSE
;
4868 Elf_Internal_Shdr
*symtab_hdr
;
4870 unsigned long r_symndx
;
4872 /* TRUE if overflow occurred during the calculation of the
4873 relocation value. */
4874 bfd_boolean overflowed_p
;
4875 /* TRUE if this relocation refers to a MIPS16 function. */
4876 bfd_boolean target_is_16_bit_code_p
= FALSE
;
4877 struct mips_elf_link_hash_table
*htab
;
4880 dynobj
= elf_hash_table (info
)->dynobj
;
4881 htab
= mips_elf_hash_table (info
);
4882 BFD_ASSERT (htab
!= NULL
);
4884 /* Parse the relocation. */
4885 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4886 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
4887 p
= (input_section
->output_section
->vma
4888 + input_section
->output_offset
4889 + relocation
->r_offset
);
4891 /* Assume that there will be no overflow. */
4892 overflowed_p
= FALSE
;
4894 /* Figure out whether or not the symbol is local, and get the offset
4895 used in the array of hash table entries. */
4896 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4897 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
4899 was_local_p
= local_p
;
4900 if (! elf_bad_symtab (input_bfd
))
4901 extsymoff
= symtab_hdr
->sh_info
;
4904 /* The symbol table does not follow the rule that local symbols
4905 must come before globals. */
4909 /* Figure out the value of the symbol. */
4912 Elf_Internal_Sym
*sym
;
4914 sym
= local_syms
+ r_symndx
;
4915 sec
= local_sections
[r_symndx
];
4917 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4918 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
4919 || (sec
->flags
& SEC_MERGE
))
4920 symbol
+= sym
->st_value
;
4921 if ((sec
->flags
& SEC_MERGE
)
4922 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4924 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
4926 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
4929 /* MIPS16 text labels should be treated as odd. */
4930 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
4933 /* Record the name of this symbol, for our caller. */
4934 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
4935 symtab_hdr
->sh_link
,
4938 *namep
= bfd_section_name (input_bfd
, sec
);
4940 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (sym
->st_other
);
4944 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
4946 /* For global symbols we look up the symbol in the hash-table. */
4947 h
= ((struct mips_elf_link_hash_entry
*)
4948 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
4949 /* Find the real hash-table entry for this symbol. */
4950 while (h
->root
.root
.type
== bfd_link_hash_indirect
4951 || h
->root
.root
.type
== bfd_link_hash_warning
)
4952 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4954 /* Record the name of this symbol, for our caller. */
4955 *namep
= h
->root
.root
.root
.string
;
4957 /* See if this is the special _gp_disp symbol. Note that such a
4958 symbol must always be a global symbol. */
4959 if (strcmp (*namep
, "_gp_disp") == 0
4960 && ! NEWABI_P (input_bfd
))
4962 /* Relocations against _gp_disp are permitted only with
4963 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
4964 if (!hi16_reloc_p (r_type
) && !lo16_reloc_p (r_type
))
4965 return bfd_reloc_notsupported
;
4969 /* See if this is the special _gp symbol. Note that such a
4970 symbol must always be a global symbol. */
4971 else if (strcmp (*namep
, "__gnu_local_gp") == 0)
4972 gnu_local_gp_p
= TRUE
;
4975 /* If this symbol is defined, calculate its address. Note that
4976 _gp_disp is a magic symbol, always implicitly defined by the
4977 linker, so it's inappropriate to check to see whether or not
4979 else if ((h
->root
.root
.type
== bfd_link_hash_defined
4980 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4981 && h
->root
.root
.u
.def
.section
)
4983 sec
= h
->root
.root
.u
.def
.section
;
4984 if (sec
->output_section
)
4985 symbol
= (h
->root
.root
.u
.def
.value
4986 + sec
->output_section
->vma
4987 + sec
->output_offset
);
4989 symbol
= h
->root
.root
.u
.def
.value
;
4991 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
4992 /* We allow relocations against undefined weak symbols, giving
4993 it the value zero, so that you can undefined weak functions
4994 and check to see if they exist by looking at their
4997 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
4998 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
5000 else if (strcmp (*namep
, SGI_COMPAT (input_bfd
)
5001 ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING") == 0)
5003 /* If this is a dynamic link, we should have created a
5004 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
5005 in in _bfd_mips_elf_create_dynamic_sections.
5006 Otherwise, we should define the symbol with a value of 0.
5007 FIXME: It should probably get into the symbol table
5009 BFD_ASSERT (! info
->shared
);
5010 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
5013 else if (ELF_MIPS_IS_OPTIONAL (h
->root
.other
))
5015 /* This is an optional symbol - an Irix specific extension to the
5016 ELF spec. Ignore it for now.
5017 XXX - FIXME - there is more to the spec for OPTIONAL symbols
5018 than simply ignoring them, but we do not handle this for now.
5019 For information see the "64-bit ELF Object File Specification"
5020 which is available from here:
5021 http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf */
5024 else if ((*info
->callbacks
->undefined_symbol
)
5025 (info
, h
->root
.root
.root
.string
, input_bfd
,
5026 input_section
, relocation
->r_offset
,
5027 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
5028 || ELF_ST_VISIBILITY (h
->root
.other
)))
5030 return bfd_reloc_undefined
;
5034 return bfd_reloc_notsupported
;
5037 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (h
->root
.other
);
5040 /* If this is a reference to a 16-bit function with a stub, we need
5041 to redirect the relocation to the stub unless:
5043 (a) the relocation is for a MIPS16 JAL;
5045 (b) the relocation is for a MIPS16 PIC call, and there are no
5046 non-MIPS16 uses of the GOT slot; or
5048 (c) the section allows direct references to MIPS16 functions. */
5049 if (r_type
!= R_MIPS16_26
5050 && !info
->relocatable
5052 && h
->fn_stub
!= NULL
5053 && (r_type
!= R_MIPS16_CALL16
|| h
->need_fn_stub
))
5055 && elf_tdata (input_bfd
)->local_stubs
!= NULL
5056 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5057 && !section_allows_mips16_refs_p (input_section
))
5059 /* This is a 32- or 64-bit call to a 16-bit function. We should
5060 have already noticed that we were going to need the
5063 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5066 BFD_ASSERT (h
->need_fn_stub
);
5070 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5071 /* The target is 16-bit, but the stub isn't. */
5072 target_is_16_bit_code_p
= FALSE
;
5074 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
5075 need to redirect the call to the stub. Note that we specifically
5076 exclude R_MIPS16_CALL16 from this behavior; indirect calls should
5077 use an indirect stub instead. */
5078 else if (r_type
== R_MIPS16_26
&& !info
->relocatable
5079 && ((h
!= NULL
&& (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
))
5081 && elf_tdata (input_bfd
)->local_call_stubs
!= NULL
5082 && elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
] != NULL
))
5083 && !target_is_16_bit_code_p
)
5086 sec
= elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
];
5089 /* If both call_stub and call_fp_stub are defined, we can figure
5090 out which one to use by checking which one appears in the input
5092 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
5097 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5099 if (CALL_FP_STUB_P (bfd_get_section_name (input_bfd
, o
)))
5101 sec
= h
->call_fp_stub
;
5108 else if (h
->call_stub
!= NULL
)
5111 sec
= h
->call_fp_stub
;
5114 BFD_ASSERT (sec
->size
> 0);
5115 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5117 /* If this is a direct call to a PIC function, redirect to the
5119 else if (h
!= NULL
&& h
->la25_stub
5120 && mips_elf_relocation_needs_la25_stub (input_bfd
, r_type
))
5121 symbol
= (h
->la25_stub
->stub_section
->output_section
->vma
5122 + h
->la25_stub
->stub_section
->output_offset
5123 + h
->la25_stub
->offset
);
5125 /* Calls from 16-bit code to 32-bit code and vice versa require the
5127 *cross_mode_jump_p
= !info
->relocatable
5128 && ((r_type
== R_MIPS16_26
&& !target_is_16_bit_code_p
)
5129 || ((r_type
== R_MIPS_26
|| r_type
== R_MIPS_JALR
)
5130 && target_is_16_bit_code_p
));
5132 local_p
= h
== NULL
|| SYMBOL_REFERENCES_LOCAL (info
, &h
->root
);
5134 gp0
= _bfd_get_gp_value (input_bfd
);
5135 gp
= _bfd_get_gp_value (abfd
);
5137 gp
+= mips_elf_adjust_gp (abfd
, htab
->got_info
, input_bfd
);
5142 /* Global R_MIPS_GOT_PAGE relocations are equivalent to R_MIPS_GOT_DISP.
5143 The addend is applied by the corresponding R_MIPS_GOT_OFST. */
5144 if (r_type
== R_MIPS_GOT_PAGE
&& !local_p
)
5146 r_type
= R_MIPS_GOT_DISP
;
5150 /* If we haven't already determined the GOT offset, oand we're going
5151 to need it, get it now. */
5154 case R_MIPS16_CALL16
:
5155 case R_MIPS16_GOT16
:
5158 case R_MIPS_GOT_DISP
:
5159 case R_MIPS_GOT_HI16
:
5160 case R_MIPS_CALL_HI16
:
5161 case R_MIPS_GOT_LO16
:
5162 case R_MIPS_CALL_LO16
:
5164 case R_MIPS_TLS_GOTTPREL
:
5165 case R_MIPS_TLS_LDM
:
5166 /* Find the index into the GOT where this value is located. */
5167 if (r_type
== R_MIPS_TLS_LDM
)
5169 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5170 0, 0, NULL
, r_type
);
5172 return bfd_reloc_outofrange
;
5176 /* On VxWorks, CALL relocations should refer to the .got.plt
5177 entry, which is initialized to point at the PLT stub. */
5178 if (htab
->is_vxworks
5179 && (r_type
== R_MIPS_CALL_HI16
5180 || r_type
== R_MIPS_CALL_LO16
5181 || call16_reloc_p (r_type
)))
5183 BFD_ASSERT (addend
== 0);
5184 BFD_ASSERT (h
->root
.needs_plt
);
5185 g
= mips_elf_gotplt_index (info
, &h
->root
);
5189 BFD_ASSERT (addend
== 0);
5190 g
= mips_elf_global_got_index (dynobj
, input_bfd
,
5191 &h
->root
, r_type
, info
);
5192 if (h
->tls_type
== GOT_NORMAL
5193 && !elf_hash_table (info
)->dynamic_sections_created
)
5194 /* This is a static link. We must initialize the GOT entry. */
5195 MIPS_ELF_PUT_WORD (dynobj
, symbol
, htab
->sgot
->contents
+ g
);
5198 else if (!htab
->is_vxworks
5199 && (call16_reloc_p (r_type
) || got16_reloc_p (r_type
)))
5200 /* The calculation below does not involve "g". */
5204 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5205 symbol
+ addend
, r_symndx
, h
, r_type
);
5207 return bfd_reloc_outofrange
;
5210 /* Convert GOT indices to actual offsets. */
5211 g
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, g
);
5215 /* Relocations against the VxWorks __GOTT_BASE__ and __GOTT_INDEX__
5216 symbols are resolved by the loader. Add them to .rela.dyn. */
5217 if (h
!= NULL
&& is_gott_symbol (info
, &h
->root
))
5219 Elf_Internal_Rela outrel
;
5223 s
= mips_elf_rel_dyn_section (info
, FALSE
);
5224 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5226 outrel
.r_offset
= (input_section
->output_section
->vma
5227 + input_section
->output_offset
5228 + relocation
->r_offset
);
5229 outrel
.r_info
= ELF32_R_INFO (h
->root
.dynindx
, r_type
);
5230 outrel
.r_addend
= addend
;
5231 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
5233 /* If we've written this relocation for a readonly section,
5234 we need to set DF_TEXTREL again, so that we do not delete the
5236 if (MIPS_ELF_READONLY_SECTION (input_section
))
5237 info
->flags
|= DF_TEXTREL
;
5240 return bfd_reloc_ok
;
5243 /* Figure out what kind of relocation is being performed. */
5247 return bfd_reloc_continue
;
5250 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 16);
5251 overflowed_p
= mips_elf_overflow_p (value
, 16);
5258 || (htab
->root
.dynamic_sections_created
5260 && h
->root
.def_dynamic
5261 && !h
->root
.def_regular
5262 && !h
->has_static_relocs
))
5265 || h
->root
.root
.type
!= bfd_link_hash_undefweak
5266 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
5267 && (input_section
->flags
& SEC_ALLOC
) != 0)
5269 /* If we're creating a shared library, then we can't know
5270 where the symbol will end up. So, we create a relocation
5271 record in the output, and leave the job up to the dynamic
5272 linker. We must do the same for executable references to
5273 shared library symbols, unless we've decided to use copy
5274 relocs or PLTs instead. */
5276 if (!mips_elf_create_dynamic_relocation (abfd
,
5284 return bfd_reloc_undefined
;
5288 if (r_type
!= R_MIPS_REL32
)
5289 value
= symbol
+ addend
;
5293 value
&= howto
->dst_mask
;
5297 value
= symbol
+ addend
- p
;
5298 value
&= howto
->dst_mask
;
5302 /* The calculation for R_MIPS16_26 is just the same as for an
5303 R_MIPS_26. It's only the storage of the relocated field into
5304 the output file that's different. That's handled in
5305 mips_elf_perform_relocation. So, we just fall through to the
5306 R_MIPS_26 case here. */
5309 value
= ((addend
| ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
5312 value
= (_bfd_mips_elf_sign_extend (addend
, 28) + symbol
) >> 2;
5313 if (h
->root
.root
.type
!= bfd_link_hash_undefweak
)
5314 overflowed_p
= (value
>> 26) != ((p
+ 4) >> 28);
5316 value
&= howto
->dst_mask
;
5319 case R_MIPS_TLS_DTPREL_HI16
:
5320 value
= (mips_elf_high (addend
+ symbol
- dtprel_base (info
))
5324 case R_MIPS_TLS_DTPREL_LO16
:
5325 case R_MIPS_TLS_DTPREL32
:
5326 case R_MIPS_TLS_DTPREL64
:
5327 value
= (symbol
+ addend
- dtprel_base (info
)) & howto
->dst_mask
;
5330 case R_MIPS_TLS_TPREL_HI16
:
5331 value
= (mips_elf_high (addend
+ symbol
- tprel_base (info
))
5335 case R_MIPS_TLS_TPREL_LO16
:
5336 value
= (symbol
+ addend
- tprel_base (info
)) & howto
->dst_mask
;
5343 value
= mips_elf_high (addend
+ symbol
);
5344 value
&= howto
->dst_mask
;
5348 /* For MIPS16 ABI code we generate this sequence
5349 0: li $v0,%hi(_gp_disp)
5350 4: addiupc $v1,%lo(_gp_disp)
5354 So the offsets of hi and lo relocs are the same, but the
5355 $pc is four higher than $t9 would be, so reduce
5356 both reloc addends by 4. */
5357 if (r_type
== R_MIPS16_HI16
)
5358 value
= mips_elf_high (addend
+ gp
- p
- 4);
5360 value
= mips_elf_high (addend
+ gp
- p
);
5361 overflowed_p
= mips_elf_overflow_p (value
, 16);
5368 value
= (symbol
+ addend
) & howto
->dst_mask
;
5371 /* See the comment for R_MIPS16_HI16 above for the reason
5372 for this conditional. */
5373 if (r_type
== R_MIPS16_LO16
)
5374 value
= addend
+ gp
- p
;
5376 value
= addend
+ gp
- p
+ 4;
5377 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
5378 for overflow. But, on, say, IRIX5, relocations against
5379 _gp_disp are normally generated from the .cpload
5380 pseudo-op. It generates code that normally looks like
5383 lui $gp,%hi(_gp_disp)
5384 addiu $gp,$gp,%lo(_gp_disp)
5387 Here $t9 holds the address of the function being called,
5388 as required by the MIPS ELF ABI. The R_MIPS_LO16
5389 relocation can easily overflow in this situation, but the
5390 R_MIPS_HI16 relocation will handle the overflow.
5391 Therefore, we consider this a bug in the MIPS ABI, and do
5392 not check for overflow here. */
5396 case R_MIPS_LITERAL
:
5397 /* Because we don't merge literal sections, we can handle this
5398 just like R_MIPS_GPREL16. In the long run, we should merge
5399 shared literals, and then we will need to additional work
5404 case R_MIPS16_GPREL
:
5405 /* The R_MIPS16_GPREL performs the same calculation as
5406 R_MIPS_GPREL16, but stores the relocated bits in a different
5407 order. We don't need to do anything special here; the
5408 differences are handled in mips_elf_perform_relocation. */
5409 case R_MIPS_GPREL16
:
5410 /* Only sign-extend the addend if it was extracted from the
5411 instruction. If the addend was separate, leave it alone,
5412 otherwise we may lose significant bits. */
5413 if (howto
->partial_inplace
)
5414 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
5415 value
= symbol
+ addend
- gp
;
5416 /* If the symbol was local, any earlier relocatable links will
5417 have adjusted its addend with the gp offset, so compensate
5418 for that now. Don't do it for symbols forced local in this
5419 link, though, since they won't have had the gp offset applied
5423 overflowed_p
= mips_elf_overflow_p (value
, 16);
5426 case R_MIPS16_GOT16
:
5427 case R_MIPS16_CALL16
:
5430 /* VxWorks does not have separate local and global semantics for
5431 R_MIPS*_GOT16; every relocation evaluates to "G". */
5432 if (!htab
->is_vxworks
&& local_p
)
5434 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
,
5435 symbol
+ addend
, !was_local_p
);
5436 if (value
== MINUS_ONE
)
5437 return bfd_reloc_outofrange
;
5439 = mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
5440 overflowed_p
= mips_elf_overflow_p (value
, 16);
5447 case R_MIPS_TLS_GOTTPREL
:
5448 case R_MIPS_TLS_LDM
:
5449 case R_MIPS_GOT_DISP
:
5451 overflowed_p
= mips_elf_overflow_p (value
, 16);
5454 case R_MIPS_GPREL32
:
5455 value
= (addend
+ symbol
+ gp0
- gp
);
5457 value
&= howto
->dst_mask
;
5461 case R_MIPS_GNU_REL16_S2
:
5462 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 18) - p
;
5463 overflowed_p
= mips_elf_overflow_p (value
, 18);
5464 value
>>= howto
->rightshift
;
5465 value
&= howto
->dst_mask
;
5468 case R_MIPS_GOT_HI16
:
5469 case R_MIPS_CALL_HI16
:
5470 /* We're allowed to handle these two relocations identically.
5471 The dynamic linker is allowed to handle the CALL relocations
5472 differently by creating a lazy evaluation stub. */
5474 value
= mips_elf_high (value
);
5475 value
&= howto
->dst_mask
;
5478 case R_MIPS_GOT_LO16
:
5479 case R_MIPS_CALL_LO16
:
5480 value
= g
& howto
->dst_mask
;
5483 case R_MIPS_GOT_PAGE
:
5484 value
= mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, NULL
);
5485 if (value
== MINUS_ONE
)
5486 return bfd_reloc_outofrange
;
5487 value
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
5488 overflowed_p
= mips_elf_overflow_p (value
, 16);
5491 case R_MIPS_GOT_OFST
:
5493 mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, &value
);
5496 overflowed_p
= mips_elf_overflow_p (value
, 16);
5500 value
= symbol
- addend
;
5501 value
&= howto
->dst_mask
;
5505 value
= mips_elf_higher (addend
+ symbol
);
5506 value
&= howto
->dst_mask
;
5509 case R_MIPS_HIGHEST
:
5510 value
= mips_elf_highest (addend
+ symbol
);
5511 value
&= howto
->dst_mask
;
5514 case R_MIPS_SCN_DISP
:
5515 value
= symbol
+ addend
- sec
->output_offset
;
5516 value
&= howto
->dst_mask
;
5520 /* This relocation is only a hint. In some cases, we optimize
5521 it into a bal instruction. But we don't try to optimize
5522 when the symbol does not resolve locally. */
5523 if (h
!= NULL
&& !SYMBOL_CALLS_LOCAL (info
, &h
->root
))
5524 return bfd_reloc_continue
;
5525 value
= symbol
+ addend
;
5529 case R_MIPS_GNU_VTINHERIT
:
5530 case R_MIPS_GNU_VTENTRY
:
5531 /* We don't do anything with these at present. */
5532 return bfd_reloc_continue
;
5535 /* An unrecognized relocation type. */
5536 return bfd_reloc_notsupported
;
5539 /* Store the VALUE for our caller. */
5541 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
5544 /* Obtain the field relocated by RELOCATION. */
5547 mips_elf_obtain_contents (reloc_howto_type
*howto
,
5548 const Elf_Internal_Rela
*relocation
,
5549 bfd
*input_bfd
, bfd_byte
*contents
)
5552 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5554 /* Obtain the bytes. */
5555 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
5560 /* It has been determined that the result of the RELOCATION is the
5561 VALUE. Use HOWTO to place VALUE into the output file at the
5562 appropriate position. The SECTION is the section to which the
5564 CROSS_MODE_JUMP_P is true if the relocation field
5565 is a MIPS16 jump to non-MIPS16 code, or vice versa.
5567 Returns FALSE if anything goes wrong. */
5570 mips_elf_perform_relocation (struct bfd_link_info
*info
,
5571 reloc_howto_type
*howto
,
5572 const Elf_Internal_Rela
*relocation
,
5573 bfd_vma value
, bfd
*input_bfd
,
5574 asection
*input_section
, bfd_byte
*contents
,
5575 bfd_boolean cross_mode_jump_p
)
5579 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
5581 /* Figure out where the relocation is occurring. */
5582 location
= contents
+ relocation
->r_offset
;
5584 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
5586 /* Obtain the current value. */
5587 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
5589 /* Clear the field we are setting. */
5590 x
&= ~howto
->dst_mask
;
5592 /* Set the field. */
5593 x
|= (value
& howto
->dst_mask
);
5595 /* If required, turn JAL into JALX. */
5596 if (cross_mode_jump_p
&& jal_reloc_p (r_type
))
5599 bfd_vma opcode
= x
>> 26;
5600 bfd_vma jalx_opcode
;
5602 /* Check to see if the opcode is already JAL or JALX. */
5603 if (r_type
== R_MIPS16_26
)
5605 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
5610 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
5614 /* If the opcode is not JAL or JALX, there's a problem. */
5617 (*_bfd_error_handler
)
5618 (_("%B: %A+0x%lx: Direct jumps between ISA modes are not allowed; consider recompiling with interlinking enabled."),
5621 (unsigned long) relocation
->r_offset
);
5622 bfd_set_error (bfd_error_bad_value
);
5626 /* Make this the JALX opcode. */
5627 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
5630 /* Try converting JAL to BAL and J(AL)R to B(AL), if the target is in
5632 if (!info
->relocatable
5633 && !cross_mode_jump_p
5634 && ((JAL_TO_BAL_P (input_bfd
)
5635 && r_type
== R_MIPS_26
5636 && (x
>> 26) == 0x3) /* jal addr */
5637 || (JALR_TO_BAL_P (input_bfd
)
5638 && r_type
== R_MIPS_JALR
5639 && x
== 0x0320f809) /* jalr t9 */
5640 || (JR_TO_B_P (input_bfd
)
5641 && r_type
== R_MIPS_JALR
5642 && x
== 0x03200008))) /* jr t9 */
5648 addr
= (input_section
->output_section
->vma
5649 + input_section
->output_offset
5650 + relocation
->r_offset
5652 if (r_type
== R_MIPS_26
)
5653 dest
= (value
<< 2) | ((addr
>> 28) << 28);
5657 if (off
<= 0x1ffff && off
>= -0x20000)
5659 if (x
== 0x03200008) /* jr t9 */
5660 x
= 0x10000000 | (((bfd_vma
) off
>> 2) & 0xffff); /* b addr */
5662 x
= 0x04110000 | (((bfd_vma
) off
>> 2) & 0xffff); /* bal addr */
5666 /* Put the value into the output. */
5667 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
5669 _bfd_mips16_elf_reloc_shuffle(input_bfd
, r_type
, !info
->relocatable
,
5675 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
5676 is the original relocation, which is now being transformed into a
5677 dynamic relocation. The ADDENDP is adjusted if necessary; the
5678 caller should store the result in place of the original addend. */
5681 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
5682 struct bfd_link_info
*info
,
5683 const Elf_Internal_Rela
*rel
,
5684 struct mips_elf_link_hash_entry
*h
,
5685 asection
*sec
, bfd_vma symbol
,
5686 bfd_vma
*addendp
, asection
*input_section
)
5688 Elf_Internal_Rela outrel
[3];
5693 bfd_boolean defined_p
;
5694 struct mips_elf_link_hash_table
*htab
;
5696 htab
= mips_elf_hash_table (info
);
5697 BFD_ASSERT (htab
!= NULL
);
5699 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
5700 dynobj
= elf_hash_table (info
)->dynobj
;
5701 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
5702 BFD_ASSERT (sreloc
!= NULL
);
5703 BFD_ASSERT (sreloc
->contents
!= NULL
);
5704 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
5707 outrel
[0].r_offset
=
5708 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
5709 if (ABI_64_P (output_bfd
))
5711 outrel
[1].r_offset
=
5712 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
5713 outrel
[2].r_offset
=
5714 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
5717 if (outrel
[0].r_offset
== MINUS_ONE
)
5718 /* The relocation field has been deleted. */
5721 if (outrel
[0].r_offset
== MINUS_TWO
)
5723 /* The relocation field has been converted into a relative value of
5724 some sort. Functions like _bfd_elf_write_section_eh_frame expect
5725 the field to be fully relocated, so add in the symbol's value. */
5730 /* We must now calculate the dynamic symbol table index to use
5731 in the relocation. */
5732 if (h
!= NULL
&& ! SYMBOL_REFERENCES_LOCAL (info
, &h
->root
))
5734 BFD_ASSERT (htab
->is_vxworks
|| h
->global_got_area
!= GGA_NONE
);
5735 indx
= h
->root
.dynindx
;
5736 if (SGI_COMPAT (output_bfd
))
5737 defined_p
= h
->root
.def_regular
;
5739 /* ??? glibc's ld.so just adds the final GOT entry to the
5740 relocation field. It therefore treats relocs against
5741 defined symbols in the same way as relocs against
5742 undefined symbols. */
5747 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5749 else if (sec
== NULL
|| sec
->owner
== NULL
)
5751 bfd_set_error (bfd_error_bad_value
);
5756 indx
= elf_section_data (sec
->output_section
)->dynindx
;
5759 asection
*osec
= htab
->root
.text_index_section
;
5760 indx
= elf_section_data (osec
)->dynindx
;
5766 /* Instead of generating a relocation using the section
5767 symbol, we may as well make it a fully relative
5768 relocation. We want to avoid generating relocations to
5769 local symbols because we used to generate them
5770 incorrectly, without adding the original symbol value,
5771 which is mandated by the ABI for section symbols. In
5772 order to give dynamic loaders and applications time to
5773 phase out the incorrect use, we refrain from emitting
5774 section-relative relocations. It's not like they're
5775 useful, after all. This should be a bit more efficient
5777 /* ??? Although this behavior is compatible with glibc's ld.so,
5778 the ABI says that relocations against STN_UNDEF should have
5779 a symbol value of 0. Irix rld honors this, so relocations
5780 against STN_UNDEF have no effect. */
5781 if (!SGI_COMPAT (output_bfd
))
5786 /* If the relocation was previously an absolute relocation and
5787 this symbol will not be referred to by the relocation, we must
5788 adjust it by the value we give it in the dynamic symbol table.
5789 Otherwise leave the job up to the dynamic linker. */
5790 if (defined_p
&& r_type
!= R_MIPS_REL32
)
5793 if (htab
->is_vxworks
)
5794 /* VxWorks uses non-relative relocations for this. */
5795 outrel
[0].r_info
= ELF32_R_INFO (indx
, R_MIPS_32
);
5797 /* The relocation is always an REL32 relocation because we don't
5798 know where the shared library will wind up at load-time. */
5799 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
5802 /* For strict adherence to the ABI specification, we should
5803 generate a R_MIPS_64 relocation record by itself before the
5804 _REL32/_64 record as well, such that the addend is read in as
5805 a 64-bit value (REL32 is a 32-bit relocation, after all).
5806 However, since none of the existing ELF64 MIPS dynamic
5807 loaders seems to care, we don't waste space with these
5808 artificial relocations. If this turns out to not be true,
5809 mips_elf_allocate_dynamic_relocation() should be tweaked so
5810 as to make room for a pair of dynamic relocations per
5811 invocation if ABI_64_P, and here we should generate an
5812 additional relocation record with R_MIPS_64 by itself for a
5813 NULL symbol before this relocation record. */
5814 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
5815 ABI_64_P (output_bfd
)
5818 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
5820 /* Adjust the output offset of the relocation to reference the
5821 correct location in the output file. */
5822 outrel
[0].r_offset
+= (input_section
->output_section
->vma
5823 + input_section
->output_offset
);
5824 outrel
[1].r_offset
+= (input_section
->output_section
->vma
5825 + input_section
->output_offset
);
5826 outrel
[2].r_offset
+= (input_section
->output_section
->vma
5827 + input_section
->output_offset
);
5829 /* Put the relocation back out. We have to use the special
5830 relocation outputter in the 64-bit case since the 64-bit
5831 relocation format is non-standard. */
5832 if (ABI_64_P (output_bfd
))
5834 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
5835 (output_bfd
, &outrel
[0],
5837 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
5839 else if (htab
->is_vxworks
)
5841 /* VxWorks uses RELA rather than REL dynamic relocations. */
5842 outrel
[0].r_addend
= *addendp
;
5843 bfd_elf32_swap_reloca_out
5844 (output_bfd
, &outrel
[0],
5846 + sreloc
->reloc_count
* sizeof (Elf32_External_Rela
)));
5849 bfd_elf32_swap_reloc_out
5850 (output_bfd
, &outrel
[0],
5851 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
5853 /* We've now added another relocation. */
5854 ++sreloc
->reloc_count
;
5856 /* Make sure the output section is writable. The dynamic linker
5857 will be writing to it. */
5858 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5861 /* On IRIX5, make an entry of compact relocation info. */
5862 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
5864 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5869 Elf32_crinfo cptrel
;
5871 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5872 cptrel
.vaddr
= (rel
->r_offset
5873 + input_section
->output_section
->vma
5874 + input_section
->output_offset
);
5875 if (r_type
== R_MIPS_REL32
)
5876 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5878 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5879 mips_elf_set_cr_dist2to (cptrel
, 0);
5880 cptrel
.konst
= *addendp
;
5882 cr
= (scpt
->contents
5883 + sizeof (Elf32_External_compact_rel
));
5884 mips_elf_set_cr_relvaddr (cptrel
, 0);
5885 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5886 ((Elf32_External_crinfo
*) cr
5887 + scpt
->reloc_count
));
5888 ++scpt
->reloc_count
;
5892 /* If we've written this relocation for a readonly section,
5893 we need to set DF_TEXTREL again, so that we do not delete the
5895 if (MIPS_ELF_READONLY_SECTION (input_section
))
5896 info
->flags
|= DF_TEXTREL
;
5901 /* Return the MACH for a MIPS e_flags value. */
5904 _bfd_elf_mips_mach (flagword flags
)
5906 switch (flags
& EF_MIPS_MACH
)
5908 case E_MIPS_MACH_3900
:
5909 return bfd_mach_mips3900
;
5911 case E_MIPS_MACH_4010
:
5912 return bfd_mach_mips4010
;
5914 case E_MIPS_MACH_4100
:
5915 return bfd_mach_mips4100
;
5917 case E_MIPS_MACH_4111
:
5918 return bfd_mach_mips4111
;
5920 case E_MIPS_MACH_4120
:
5921 return bfd_mach_mips4120
;
5923 case E_MIPS_MACH_4650
:
5924 return bfd_mach_mips4650
;
5926 case E_MIPS_MACH_5400
:
5927 return bfd_mach_mips5400
;
5929 case E_MIPS_MACH_5500
:
5930 return bfd_mach_mips5500
;
5932 case E_MIPS_MACH_9000
:
5933 return bfd_mach_mips9000
;
5935 case E_MIPS_MACH_SB1
:
5936 return bfd_mach_mips_sb1
;
5938 case E_MIPS_MACH_LS2E
:
5939 return bfd_mach_mips_loongson_2e
;
5941 case E_MIPS_MACH_LS2F
:
5942 return bfd_mach_mips_loongson_2f
;
5944 case E_MIPS_MACH_OCTEON
:
5945 return bfd_mach_mips_octeon
;
5947 case E_MIPS_MACH_XLR
:
5948 return bfd_mach_mips_xlr
;
5951 switch (flags
& EF_MIPS_ARCH
)
5955 return bfd_mach_mips3000
;
5958 return bfd_mach_mips6000
;
5961 return bfd_mach_mips4000
;
5964 return bfd_mach_mips8000
;
5967 return bfd_mach_mips5
;
5969 case E_MIPS_ARCH_32
:
5970 return bfd_mach_mipsisa32
;
5972 case E_MIPS_ARCH_64
:
5973 return bfd_mach_mipsisa64
;
5975 case E_MIPS_ARCH_32R2
:
5976 return bfd_mach_mipsisa32r2
;
5978 case E_MIPS_ARCH_64R2
:
5979 return bfd_mach_mipsisa64r2
;
5986 /* Return printable name for ABI. */
5988 static INLINE
char *
5989 elf_mips_abi_name (bfd
*abfd
)
5993 flags
= elf_elfheader (abfd
)->e_flags
;
5994 switch (flags
& EF_MIPS_ABI
)
5997 if (ABI_N32_P (abfd
))
5999 else if (ABI_64_P (abfd
))
6003 case E_MIPS_ABI_O32
:
6005 case E_MIPS_ABI_O64
:
6007 case E_MIPS_ABI_EABI32
:
6009 case E_MIPS_ABI_EABI64
:
6012 return "unknown abi";
6016 /* MIPS ELF uses two common sections. One is the usual one, and the
6017 other is for small objects. All the small objects are kept
6018 together, and then referenced via the gp pointer, which yields
6019 faster assembler code. This is what we use for the small common
6020 section. This approach is copied from ecoff.c. */
6021 static asection mips_elf_scom_section
;
6022 static asymbol mips_elf_scom_symbol
;
6023 static asymbol
*mips_elf_scom_symbol_ptr
;
6025 /* MIPS ELF also uses an acommon section, which represents an
6026 allocated common symbol which may be overridden by a
6027 definition in a shared library. */
6028 static asection mips_elf_acom_section
;
6029 static asymbol mips_elf_acom_symbol
;
6030 static asymbol
*mips_elf_acom_symbol_ptr
;
6032 /* This is used for both the 32-bit and the 64-bit ABI. */
6035 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
6037 elf_symbol_type
*elfsym
;
6039 /* Handle the special MIPS section numbers that a symbol may use. */
6040 elfsym
= (elf_symbol_type
*) asym
;
6041 switch (elfsym
->internal_elf_sym
.st_shndx
)
6043 case SHN_MIPS_ACOMMON
:
6044 /* This section is used in a dynamically linked executable file.
6045 It is an allocated common section. The dynamic linker can
6046 either resolve these symbols to something in a shared
6047 library, or it can just leave them here. For our purposes,
6048 we can consider these symbols to be in a new section. */
6049 if (mips_elf_acom_section
.name
== NULL
)
6051 /* Initialize the acommon section. */
6052 mips_elf_acom_section
.name
= ".acommon";
6053 mips_elf_acom_section
.flags
= SEC_ALLOC
;
6054 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
6055 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
6056 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
6057 mips_elf_acom_symbol
.name
= ".acommon";
6058 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
6059 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
6060 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
6062 asym
->section
= &mips_elf_acom_section
;
6066 /* Common symbols less than the GP size are automatically
6067 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
6068 if (asym
->value
> elf_gp_size (abfd
)
6069 || ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_TLS
6070 || IRIX_COMPAT (abfd
) == ict_irix6
)
6073 case SHN_MIPS_SCOMMON
:
6074 if (mips_elf_scom_section
.name
== NULL
)
6076 /* Initialize the small common section. */
6077 mips_elf_scom_section
.name
= ".scommon";
6078 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
6079 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
6080 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
6081 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
6082 mips_elf_scom_symbol
.name
= ".scommon";
6083 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
6084 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
6085 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
6087 asym
->section
= &mips_elf_scom_section
;
6088 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
6091 case SHN_MIPS_SUNDEFINED
:
6092 asym
->section
= bfd_und_section_ptr
;
6097 asection
*section
= bfd_get_section_by_name (abfd
, ".text");
6099 BFD_ASSERT (SGI_COMPAT (abfd
));
6100 if (section
!= NULL
)
6102 asym
->section
= section
;
6103 /* MIPS_TEXT is a bit special, the address is not an offset
6104 to the base of the .text section. So substract the section
6105 base address to make it an offset. */
6106 asym
->value
-= section
->vma
;
6113 asection
*section
= bfd_get_section_by_name (abfd
, ".data");
6115 BFD_ASSERT (SGI_COMPAT (abfd
));
6116 if (section
!= NULL
)
6118 asym
->section
= section
;
6119 /* MIPS_DATA is a bit special, the address is not an offset
6120 to the base of the .data section. So substract the section
6121 base address to make it an offset. */
6122 asym
->value
-= section
->vma
;
6128 /* If this is an odd-valued function symbol, assume it's a MIPS16 one. */
6129 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_FUNC
6130 && (asym
->value
& 1) != 0)
6133 elfsym
->internal_elf_sym
.st_other
6134 = ELF_ST_SET_MIPS16 (elfsym
->internal_elf_sym
.st_other
);
6138 /* Implement elf_backend_eh_frame_address_size. This differs from
6139 the default in the way it handles EABI64.
6141 EABI64 was originally specified as an LP64 ABI, and that is what
6142 -mabi=eabi normally gives on a 64-bit target. However, gcc has
6143 historically accepted the combination of -mabi=eabi and -mlong32,
6144 and this ILP32 variation has become semi-official over time.
6145 Both forms use elf32 and have pointer-sized FDE addresses.
6147 If an EABI object was generated by GCC 4.0 or above, it will have
6148 an empty .gcc_compiled_longXX section, where XX is the size of longs
6149 in bits. Unfortunately, ILP32 objects generated by earlier compilers
6150 have no special marking to distinguish them from LP64 objects.
6152 We don't want users of the official LP64 ABI to be punished for the
6153 existence of the ILP32 variant, but at the same time, we don't want
6154 to mistakenly interpret pre-4.0 ILP32 objects as being LP64 objects.
6155 We therefore take the following approach:
6157 - If ABFD contains a .gcc_compiled_longXX section, use it to
6158 determine the pointer size.
6160 - Otherwise check the type of the first relocation. Assume that
6161 the LP64 ABI is being used if the relocation is of type R_MIPS_64.
6165 The second check is enough to detect LP64 objects generated by pre-4.0
6166 compilers because, in the kind of output generated by those compilers,
6167 the first relocation will be associated with either a CIE personality
6168 routine or an FDE start address. Furthermore, the compilers never
6169 used a special (non-pointer) encoding for this ABI.
6171 Checking the relocation type should also be safe because there is no
6172 reason to use R_MIPS_64 in an ILP32 object. Pre-4.0 compilers never
6176 _bfd_mips_elf_eh_frame_address_size (bfd
*abfd
, asection
*sec
)
6178 if (elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
6180 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
6182 bfd_boolean long32_p
, long64_p
;
6184 long32_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long32") != 0;
6185 long64_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long64") != 0;
6186 if (long32_p
&& long64_p
)
6193 if (sec
->reloc_count
> 0
6194 && elf_section_data (sec
)->relocs
!= NULL
6195 && (ELF32_R_TYPE (elf_section_data (sec
)->relocs
[0].r_info
)
6204 /* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
6205 relocations against two unnamed section symbols to resolve to the
6206 same address. For example, if we have code like:
6208 lw $4,%got_disp(.data)($gp)
6209 lw $25,%got_disp(.text)($gp)
6212 then the linker will resolve both relocations to .data and the program
6213 will jump there rather than to .text.
6215 We can work around this problem by giving names to local section symbols.
6216 This is also what the MIPSpro tools do. */
6219 _bfd_mips_elf_name_local_section_symbols (bfd
*abfd
)
6221 return SGI_COMPAT (abfd
);
6224 /* Work over a section just before writing it out. This routine is
6225 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
6226 sections that need the SHF_MIPS_GPREL flag by name; there has to be
6230 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
6232 if (hdr
->sh_type
== SHT_MIPS_REGINFO
6233 && hdr
->sh_size
> 0)
6237 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
6238 BFD_ASSERT (hdr
->contents
== NULL
);
6241 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
6244 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
6245 if (bfd_bwrite (buf
, 4, abfd
) != 4)
6249 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
6250 && hdr
->bfd_section
!= NULL
6251 && mips_elf_section_data (hdr
->bfd_section
) != NULL
6252 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
6254 bfd_byte
*contents
, *l
, *lend
;
6256 /* We stored the section contents in the tdata field in the
6257 set_section_contents routine. We save the section contents
6258 so that we don't have to read them again.
6259 At this point we know that elf_gp is set, so we can look
6260 through the section contents to see if there is an
6261 ODK_REGINFO structure. */
6263 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
6265 lend
= contents
+ hdr
->sh_size
;
6266 while (l
+ sizeof (Elf_External_Options
) <= lend
)
6268 Elf_Internal_Options intopt
;
6270 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
6272 if (intopt
.size
< sizeof (Elf_External_Options
))
6274 (*_bfd_error_handler
)
6275 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
6276 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
6279 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
6286 + sizeof (Elf_External_Options
)
6287 + (sizeof (Elf64_External_RegInfo
) - 8)),
6290 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
6291 if (bfd_bwrite (buf
, 8, abfd
) != 8)
6294 else if (intopt
.kind
== ODK_REGINFO
)
6301 + sizeof (Elf_External_Options
)
6302 + (sizeof (Elf32_External_RegInfo
) - 4)),
6305 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
6306 if (bfd_bwrite (buf
, 4, abfd
) != 4)
6313 if (hdr
->bfd_section
!= NULL
)
6315 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
6317 /* .sbss is not handled specially here because the GNU/Linux
6318 prelinker can convert .sbss from NOBITS to PROGBITS and
6319 changing it back to NOBITS breaks the binary. The entry in
6320 _bfd_mips_elf_special_sections will ensure the correct flags
6321 are set on .sbss if BFD creates it without reading it from an
6322 input file, and without special handling here the flags set
6323 on it in an input file will be followed. */
6324 if (strcmp (name
, ".sdata") == 0
6325 || strcmp (name
, ".lit8") == 0
6326 || strcmp (name
, ".lit4") == 0)
6328 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
6329 hdr
->sh_type
= SHT_PROGBITS
;
6331 else if (strcmp (name
, ".srdata") == 0)
6333 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
6334 hdr
->sh_type
= SHT_PROGBITS
;
6336 else if (strcmp (name
, ".compact_rel") == 0)
6339 hdr
->sh_type
= SHT_PROGBITS
;
6341 else if (strcmp (name
, ".rtproc") == 0)
6343 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
6345 unsigned int adjust
;
6347 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
6349 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
6357 /* Handle a MIPS specific section when reading an object file. This
6358 is called when elfcode.h finds a section with an unknown type.
6359 This routine supports both the 32-bit and 64-bit ELF ABI.
6361 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
6365 _bfd_mips_elf_section_from_shdr (bfd
*abfd
,
6366 Elf_Internal_Shdr
*hdr
,
6372 /* There ought to be a place to keep ELF backend specific flags, but
6373 at the moment there isn't one. We just keep track of the
6374 sections by their name, instead. Fortunately, the ABI gives
6375 suggested names for all the MIPS specific sections, so we will
6376 probably get away with this. */
6377 switch (hdr
->sh_type
)
6379 case SHT_MIPS_LIBLIST
:
6380 if (strcmp (name
, ".liblist") != 0)
6384 if (strcmp (name
, ".msym") != 0)
6387 case SHT_MIPS_CONFLICT
:
6388 if (strcmp (name
, ".conflict") != 0)
6391 case SHT_MIPS_GPTAB
:
6392 if (! CONST_STRNEQ (name
, ".gptab."))
6395 case SHT_MIPS_UCODE
:
6396 if (strcmp (name
, ".ucode") != 0)
6399 case SHT_MIPS_DEBUG
:
6400 if (strcmp (name
, ".mdebug") != 0)
6402 flags
= SEC_DEBUGGING
;
6404 case SHT_MIPS_REGINFO
:
6405 if (strcmp (name
, ".reginfo") != 0
6406 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
6408 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
6410 case SHT_MIPS_IFACE
:
6411 if (strcmp (name
, ".MIPS.interfaces") != 0)
6414 case SHT_MIPS_CONTENT
:
6415 if (! CONST_STRNEQ (name
, ".MIPS.content"))
6418 case SHT_MIPS_OPTIONS
:
6419 if (!MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
6422 case SHT_MIPS_DWARF
:
6423 if (! CONST_STRNEQ (name
, ".debug_")
6424 && ! CONST_STRNEQ (name
, ".zdebug_"))
6427 case SHT_MIPS_SYMBOL_LIB
:
6428 if (strcmp (name
, ".MIPS.symlib") != 0)
6431 case SHT_MIPS_EVENTS
:
6432 if (! CONST_STRNEQ (name
, ".MIPS.events")
6433 && ! CONST_STRNEQ (name
, ".MIPS.post_rel"))
6440 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6445 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
6446 (bfd_get_section_flags (abfd
,
6452 /* FIXME: We should record sh_info for a .gptab section. */
6454 /* For a .reginfo section, set the gp value in the tdata information
6455 from the contents of this section. We need the gp value while
6456 processing relocs, so we just get it now. The .reginfo section
6457 is not used in the 64-bit MIPS ELF ABI. */
6458 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
6460 Elf32_External_RegInfo ext
;
6463 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
6464 &ext
, 0, sizeof ext
))
6466 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
6467 elf_gp (abfd
) = s
.ri_gp_value
;
6470 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
6471 set the gp value based on what we find. We may see both
6472 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
6473 they should agree. */
6474 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
6476 bfd_byte
*contents
, *l
, *lend
;
6478 contents
= bfd_malloc (hdr
->sh_size
);
6479 if (contents
== NULL
)
6481 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
6488 lend
= contents
+ hdr
->sh_size
;
6489 while (l
+ sizeof (Elf_External_Options
) <= lend
)
6491 Elf_Internal_Options intopt
;
6493 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
6495 if (intopt
.size
< sizeof (Elf_External_Options
))
6497 (*_bfd_error_handler
)
6498 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
6499 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
6502 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
6504 Elf64_Internal_RegInfo intreg
;
6506 bfd_mips_elf64_swap_reginfo_in
6508 ((Elf64_External_RegInfo
*)
6509 (l
+ sizeof (Elf_External_Options
))),
6511 elf_gp (abfd
) = intreg
.ri_gp_value
;
6513 else if (intopt
.kind
== ODK_REGINFO
)
6515 Elf32_RegInfo intreg
;
6517 bfd_mips_elf32_swap_reginfo_in
6519 ((Elf32_External_RegInfo
*)
6520 (l
+ sizeof (Elf_External_Options
))),
6522 elf_gp (abfd
) = intreg
.ri_gp_value
;
6532 /* Set the correct type for a MIPS ELF section. We do this by the
6533 section name, which is a hack, but ought to work. This routine is
6534 used by both the 32-bit and the 64-bit ABI. */
6537 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
6539 const char *name
= bfd_get_section_name (abfd
, sec
);
6541 if (strcmp (name
, ".liblist") == 0)
6543 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
6544 hdr
->sh_info
= sec
->size
/ sizeof (Elf32_Lib
);
6545 /* The sh_link field is set in final_write_processing. */
6547 else if (strcmp (name
, ".conflict") == 0)
6548 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
6549 else if (CONST_STRNEQ (name
, ".gptab."))
6551 hdr
->sh_type
= SHT_MIPS_GPTAB
;
6552 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
6553 /* The sh_info field is set in final_write_processing. */
6555 else if (strcmp (name
, ".ucode") == 0)
6556 hdr
->sh_type
= SHT_MIPS_UCODE
;
6557 else if (strcmp (name
, ".mdebug") == 0)
6559 hdr
->sh_type
= SHT_MIPS_DEBUG
;
6560 /* In a shared object on IRIX 5.3, the .mdebug section has an
6561 entsize of 0. FIXME: Does this matter? */
6562 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
6563 hdr
->sh_entsize
= 0;
6565 hdr
->sh_entsize
= 1;
6567 else if (strcmp (name
, ".reginfo") == 0)
6569 hdr
->sh_type
= SHT_MIPS_REGINFO
;
6570 /* In a shared object on IRIX 5.3, the .reginfo section has an
6571 entsize of 0x18. FIXME: Does this matter? */
6572 if (SGI_COMPAT (abfd
))
6574 if ((abfd
->flags
& DYNAMIC
) != 0)
6575 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6577 hdr
->sh_entsize
= 1;
6580 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6582 else if (SGI_COMPAT (abfd
)
6583 && (strcmp (name
, ".hash") == 0
6584 || strcmp (name
, ".dynamic") == 0
6585 || strcmp (name
, ".dynstr") == 0))
6587 if (SGI_COMPAT (abfd
))
6588 hdr
->sh_entsize
= 0;
6590 /* This isn't how the IRIX6 linker behaves. */
6591 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6594 else if (strcmp (name
, ".got") == 0
6595 || strcmp (name
, ".srdata") == 0
6596 || strcmp (name
, ".sdata") == 0
6597 || strcmp (name
, ".sbss") == 0
6598 || strcmp (name
, ".lit4") == 0
6599 || strcmp (name
, ".lit8") == 0)
6600 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
6601 else if (strcmp (name
, ".MIPS.interfaces") == 0)
6603 hdr
->sh_type
= SHT_MIPS_IFACE
;
6604 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6606 else if (CONST_STRNEQ (name
, ".MIPS.content"))
6608 hdr
->sh_type
= SHT_MIPS_CONTENT
;
6609 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6610 /* The sh_info field is set in final_write_processing. */
6612 else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
6614 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
6615 hdr
->sh_entsize
= 1;
6616 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6618 else if (CONST_STRNEQ (name
, ".debug_")
6619 || CONST_STRNEQ (name
, ".zdebug_"))
6621 hdr
->sh_type
= SHT_MIPS_DWARF
;
6623 /* Irix facilities such as libexc expect a single .debug_frame
6624 per executable, the system ones have NOSTRIP set and the linker
6625 doesn't merge sections with different flags so ... */
6626 if (SGI_COMPAT (abfd
) && CONST_STRNEQ (name
, ".debug_frame"))
6627 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6629 else if (strcmp (name
, ".MIPS.symlib") == 0)
6631 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
6632 /* The sh_link and sh_info fields are set in
6633 final_write_processing. */
6635 else if (CONST_STRNEQ (name
, ".MIPS.events")
6636 || CONST_STRNEQ (name
, ".MIPS.post_rel"))
6638 hdr
->sh_type
= SHT_MIPS_EVENTS
;
6639 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6640 /* The sh_link field is set in final_write_processing. */
6642 else if (strcmp (name
, ".msym") == 0)
6644 hdr
->sh_type
= SHT_MIPS_MSYM
;
6645 hdr
->sh_flags
|= SHF_ALLOC
;
6646 hdr
->sh_entsize
= 8;
6649 /* The generic elf_fake_sections will set up REL_HDR using the default
6650 kind of relocations. We used to set up a second header for the
6651 non-default kind of relocations here, but only NewABI would use
6652 these, and the IRIX ld doesn't like resulting empty RELA sections.
6653 Thus we create those header only on demand now. */
6658 /* Given a BFD section, try to locate the corresponding ELF section
6659 index. This is used by both the 32-bit and the 64-bit ABI.
6660 Actually, it's not clear to me that the 64-bit ABI supports these,
6661 but for non-PIC objects we will certainly want support for at least
6662 the .scommon section. */
6665 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6666 asection
*sec
, int *retval
)
6668 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
6670 *retval
= SHN_MIPS_SCOMMON
;
6673 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
6675 *retval
= SHN_MIPS_ACOMMON
;
6681 /* Hook called by the linker routine which adds symbols from an object
6682 file. We must handle the special MIPS section numbers here. */
6685 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
6686 Elf_Internal_Sym
*sym
, const char **namep
,
6687 flagword
*flagsp ATTRIBUTE_UNUSED
,
6688 asection
**secp
, bfd_vma
*valp
)
6690 if (SGI_COMPAT (abfd
)
6691 && (abfd
->flags
& DYNAMIC
) != 0
6692 && strcmp (*namep
, "_rld_new_interface") == 0)
6694 /* Skip IRIX5 rld entry name. */
6699 /* Shared objects may have a dynamic symbol '_gp_disp' defined as
6700 a SECTION *ABS*. This causes ld to think it can resolve _gp_disp
6701 by setting a DT_NEEDED for the shared object. Since _gp_disp is
6702 a magic symbol resolved by the linker, we ignore this bogus definition
6703 of _gp_disp. New ABI objects do not suffer from this problem so this
6704 is not done for them. */
6706 && (sym
->st_shndx
== SHN_ABS
)
6707 && (strcmp (*namep
, "_gp_disp") == 0))
6713 switch (sym
->st_shndx
)
6716 /* Common symbols less than the GP size are automatically
6717 treated as SHN_MIPS_SCOMMON symbols. */
6718 if (sym
->st_size
> elf_gp_size (abfd
)
6719 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
6720 || IRIX_COMPAT (abfd
) == ict_irix6
)
6723 case SHN_MIPS_SCOMMON
:
6724 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
6725 (*secp
)->flags
|= SEC_IS_COMMON
;
6726 *valp
= sym
->st_size
;
6730 /* This section is used in a shared object. */
6731 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
6733 asymbol
*elf_text_symbol
;
6734 asection
*elf_text_section
;
6735 bfd_size_type amt
= sizeof (asection
);
6737 elf_text_section
= bfd_zalloc (abfd
, amt
);
6738 if (elf_text_section
== NULL
)
6741 amt
= sizeof (asymbol
);
6742 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
6743 if (elf_text_symbol
== NULL
)
6746 /* Initialize the section. */
6748 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
6749 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
6751 elf_text_section
->symbol
= elf_text_symbol
;
6752 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
6754 elf_text_section
->name
= ".text";
6755 elf_text_section
->flags
= SEC_NO_FLAGS
;
6756 elf_text_section
->output_section
= NULL
;
6757 elf_text_section
->owner
= abfd
;
6758 elf_text_symbol
->name
= ".text";
6759 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6760 elf_text_symbol
->section
= elf_text_section
;
6762 /* This code used to do *secp = bfd_und_section_ptr if
6763 info->shared. I don't know why, and that doesn't make sense,
6764 so I took it out. */
6765 *secp
= elf_tdata (abfd
)->elf_text_section
;
6768 case SHN_MIPS_ACOMMON
:
6769 /* Fall through. XXX Can we treat this as allocated data? */
6771 /* This section is used in a shared object. */
6772 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
6774 asymbol
*elf_data_symbol
;
6775 asection
*elf_data_section
;
6776 bfd_size_type amt
= sizeof (asection
);
6778 elf_data_section
= bfd_zalloc (abfd
, amt
);
6779 if (elf_data_section
== NULL
)
6782 amt
= sizeof (asymbol
);
6783 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
6784 if (elf_data_symbol
== NULL
)
6787 /* Initialize the section. */
6789 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
6790 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
6792 elf_data_section
->symbol
= elf_data_symbol
;
6793 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
6795 elf_data_section
->name
= ".data";
6796 elf_data_section
->flags
= SEC_NO_FLAGS
;
6797 elf_data_section
->output_section
= NULL
;
6798 elf_data_section
->owner
= abfd
;
6799 elf_data_symbol
->name
= ".data";
6800 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6801 elf_data_symbol
->section
= elf_data_section
;
6803 /* This code used to do *secp = bfd_und_section_ptr if
6804 info->shared. I don't know why, and that doesn't make sense,
6805 so I took it out. */
6806 *secp
= elf_tdata (abfd
)->elf_data_section
;
6809 case SHN_MIPS_SUNDEFINED
:
6810 *secp
= bfd_und_section_ptr
;
6814 if (SGI_COMPAT (abfd
)
6816 && info
->output_bfd
->xvec
== abfd
->xvec
6817 && strcmp (*namep
, "__rld_obj_head") == 0)
6819 struct elf_link_hash_entry
*h
;
6820 struct bfd_link_hash_entry
*bh
;
6822 /* Mark __rld_obj_head as dynamic. */
6824 if (! (_bfd_generic_link_add_one_symbol
6825 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
6826 get_elf_backend_data (abfd
)->collect
, &bh
)))
6829 h
= (struct elf_link_hash_entry
*) bh
;
6832 h
->type
= STT_OBJECT
;
6834 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6837 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
6840 /* If this is a mips16 text symbol, add 1 to the value to make it
6841 odd. This will cause something like .word SYM to come up with
6842 the right value when it is loaded into the PC. */
6843 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6849 /* This hook function is called before the linker writes out a global
6850 symbol. We mark symbols as small common if appropriate. This is
6851 also where we undo the increment of the value for a mips16 symbol. */
6854 _bfd_mips_elf_link_output_symbol_hook
6855 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6856 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
6857 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
6859 /* If we see a common symbol, which implies a relocatable link, then
6860 if a symbol was small common in an input file, mark it as small
6861 common in the output file. */
6862 if (sym
->st_shndx
== SHN_COMMON
6863 && strcmp (input_sec
->name
, ".scommon") == 0)
6864 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
6866 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6867 sym
->st_value
&= ~1;
6872 /* Functions for the dynamic linker. */
6874 /* Create dynamic sections when linking against a dynamic object. */
6877 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
6879 struct elf_link_hash_entry
*h
;
6880 struct bfd_link_hash_entry
*bh
;
6882 register asection
*s
;
6883 const char * const *namep
;
6884 struct mips_elf_link_hash_table
*htab
;
6886 htab
= mips_elf_hash_table (info
);
6887 BFD_ASSERT (htab
!= NULL
);
6889 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6890 | SEC_LINKER_CREATED
| SEC_READONLY
);
6892 /* The psABI requires a read-only .dynamic section, but the VxWorks
6894 if (!htab
->is_vxworks
)
6896 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6899 if (! bfd_set_section_flags (abfd
, s
, flags
))
6904 /* We need to create .got section. */
6905 if (!mips_elf_create_got_section (abfd
, info
))
6908 if (! mips_elf_rel_dyn_section (info
, TRUE
))
6911 /* Create .stub section. */
6912 s
= bfd_make_section_with_flags (abfd
,
6913 MIPS_ELF_STUB_SECTION_NAME (abfd
),
6916 || ! bfd_set_section_alignment (abfd
, s
,
6917 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6921 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
6923 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
6925 s
= bfd_make_section_with_flags (abfd
, ".rld_map",
6926 flags
&~ (flagword
) SEC_READONLY
);
6928 || ! bfd_set_section_alignment (abfd
, s
,
6929 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6933 /* On IRIX5, we adjust add some additional symbols and change the
6934 alignments of several sections. There is no ABI documentation
6935 indicating that this is necessary on IRIX6, nor any evidence that
6936 the linker takes such action. */
6937 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6939 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
6942 if (! (_bfd_generic_link_add_one_symbol
6943 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
6944 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6947 h
= (struct elf_link_hash_entry
*) bh
;
6950 h
->type
= STT_SECTION
;
6952 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6956 /* We need to create a .compact_rel section. */
6957 if (SGI_COMPAT (abfd
))
6959 if (!mips_elf_create_compact_rel_section (abfd
, info
))
6963 /* Change alignments of some sections. */
6964 s
= bfd_get_section_by_name (abfd
, ".hash");
6966 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6967 s
= bfd_get_section_by_name (abfd
, ".dynsym");
6969 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6970 s
= bfd_get_section_by_name (abfd
, ".dynstr");
6972 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6973 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6975 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6976 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6978 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6985 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
6987 if (!(_bfd_generic_link_add_one_symbol
6988 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
6989 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6992 h
= (struct elf_link_hash_entry
*) bh
;
6995 h
->type
= STT_SECTION
;
6997 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7000 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
7002 /* __rld_map is a four byte word located in the .data section
7003 and is filled in by the rtld to contain a pointer to
7004 the _r_debug structure. Its symbol value will be set in
7005 _bfd_mips_elf_finish_dynamic_symbol. */
7006 s
= bfd_get_section_by_name (abfd
, ".rld_map");
7007 BFD_ASSERT (s
!= NULL
);
7009 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
7011 if (!(_bfd_generic_link_add_one_symbol
7012 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
7013 get_elf_backend_data (abfd
)->collect
, &bh
)))
7016 h
= (struct elf_link_hash_entry
*) bh
;
7019 h
->type
= STT_OBJECT
;
7021 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
7026 /* Create the .plt, .rel(a).plt, .dynbss and .rel(a).bss sections.
7027 Also create the _PROCEDURE_LINKAGE_TABLE symbol. */
7028 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
7031 /* Cache the sections created above. */
7032 htab
->splt
= bfd_get_section_by_name (abfd
, ".plt");
7033 htab
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
7034 if (htab
->is_vxworks
)
7036 htab
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
7037 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
7040 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rel.plt");
7042 || (htab
->is_vxworks
&& !htab
->srelbss
&& !info
->shared
)
7047 if (htab
->is_vxworks
)
7049 /* Do the usual VxWorks handling. */
7050 if (!elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
7053 /* Work out the PLT sizes. */
7056 htab
->plt_header_size
7057 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt0_entry
);
7058 htab
->plt_entry_size
7059 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt_entry
);
7063 htab
->plt_header_size
7064 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt0_entry
);
7065 htab
->plt_entry_size
7066 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt_entry
);
7069 else if (!info
->shared
)
7071 /* All variants of the plt0 entry are the same size. */
7072 htab
->plt_header_size
= 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
);
7073 htab
->plt_entry_size
= 4 * ARRAY_SIZE (mips_exec_plt_entry
);
7079 /* Return true if relocation REL against section SEC is a REL rather than
7080 RELA relocation. RELOCS is the first relocation in the section and
7081 ABFD is the bfd that contains SEC. */
7084 mips_elf_rel_relocation_p (bfd
*abfd
, asection
*sec
,
7085 const Elf_Internal_Rela
*relocs
,
7086 const Elf_Internal_Rela
*rel
)
7088 Elf_Internal_Shdr
*rel_hdr
;
7089 const struct elf_backend_data
*bed
;
7091 /* To determine which flavor or relocation this is, we depend on the
7092 fact that the INPUT_SECTION's REL_HDR is read before its REL_HDR2. */
7093 rel_hdr
= &elf_section_data (sec
)->rel_hdr
;
7094 bed
= get_elf_backend_data (abfd
);
7095 if ((size_t) (rel
- relocs
)
7096 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
7097 rel_hdr
= elf_section_data (sec
)->rel_hdr2
;
7098 return rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (abfd
);
7101 /* Read the addend for REL relocation REL, which belongs to bfd ABFD.
7102 HOWTO is the relocation's howto and CONTENTS points to the contents
7103 of the section that REL is against. */
7106 mips_elf_read_rel_addend (bfd
*abfd
, const Elf_Internal_Rela
*rel
,
7107 reloc_howto_type
*howto
, bfd_byte
*contents
)
7110 unsigned int r_type
;
7113 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7114 location
= contents
+ rel
->r_offset
;
7116 /* Get the addend, which is stored in the input file. */
7117 _bfd_mips16_elf_reloc_unshuffle (abfd
, r_type
, FALSE
, location
);
7118 addend
= mips_elf_obtain_contents (howto
, rel
, abfd
, contents
);
7119 _bfd_mips16_elf_reloc_shuffle (abfd
, r_type
, FALSE
, location
);
7121 return addend
& howto
->src_mask
;
7124 /* REL is a relocation in ABFD that needs a partnering LO16 relocation
7125 and *ADDEND is the addend for REL itself. Look for the LO16 relocation
7126 and update *ADDEND with the final addend. Return true on success
7127 or false if the LO16 could not be found. RELEND is the exclusive
7128 upper bound on the relocations for REL's section. */
7131 mips_elf_add_lo16_rel_addend (bfd
*abfd
,
7132 const Elf_Internal_Rela
*rel
,
7133 const Elf_Internal_Rela
*relend
,
7134 bfd_byte
*contents
, bfd_vma
*addend
)
7136 unsigned int r_type
, lo16_type
;
7137 const Elf_Internal_Rela
*lo16_relocation
;
7138 reloc_howto_type
*lo16_howto
;
7141 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7142 if (mips16_reloc_p (r_type
))
7143 lo16_type
= R_MIPS16_LO16
;
7145 lo16_type
= R_MIPS_LO16
;
7147 /* The combined value is the sum of the HI16 addend, left-shifted by
7148 sixteen bits, and the LO16 addend, sign extended. (Usually, the
7149 code does a `lui' of the HI16 value, and then an `addiu' of the
7152 Scan ahead to find a matching LO16 relocation.
7154 According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
7155 be immediately following. However, for the IRIX6 ABI, the next
7156 relocation may be a composed relocation consisting of several
7157 relocations for the same address. In that case, the R_MIPS_LO16
7158 relocation may occur as one of these. We permit a similar
7159 extension in general, as that is useful for GCC.
7161 In some cases GCC dead code elimination removes the LO16 but keeps
7162 the corresponding HI16. This is strictly speaking a violation of
7163 the ABI but not immediately harmful. */
7164 lo16_relocation
= mips_elf_next_relocation (abfd
, lo16_type
, rel
, relend
);
7165 if (lo16_relocation
== NULL
)
7168 /* Obtain the addend kept there. */
7169 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, lo16_type
, FALSE
);
7170 l
= mips_elf_read_rel_addend (abfd
, lo16_relocation
, lo16_howto
, contents
);
7172 l
<<= lo16_howto
->rightshift
;
7173 l
= _bfd_mips_elf_sign_extend (l
, 16);
7180 /* Try to read the contents of section SEC in bfd ABFD. Return true and
7181 store the contents in *CONTENTS on success. Assume that *CONTENTS
7182 already holds the contents if it is nonull on entry. */
7185 mips_elf_get_section_contents (bfd
*abfd
, asection
*sec
, bfd_byte
**contents
)
7190 /* Get cached copy if it exists. */
7191 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
7193 *contents
= elf_section_data (sec
)->this_hdr
.contents
;
7197 return bfd_malloc_and_get_section (abfd
, sec
, contents
);
7200 /* Look through the relocs for a section during the first phase, and
7201 allocate space in the global offset table. */
7204 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
7205 asection
*sec
, const Elf_Internal_Rela
*relocs
)
7209 Elf_Internal_Shdr
*symtab_hdr
;
7210 struct elf_link_hash_entry
**sym_hashes
;
7212 const Elf_Internal_Rela
*rel
;
7213 const Elf_Internal_Rela
*rel_end
;
7215 const struct elf_backend_data
*bed
;
7216 struct mips_elf_link_hash_table
*htab
;
7219 reloc_howto_type
*howto
;
7221 if (info
->relocatable
)
7224 htab
= mips_elf_hash_table (info
);
7225 BFD_ASSERT (htab
!= NULL
);
7227 dynobj
= elf_hash_table (info
)->dynobj
;
7228 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7229 sym_hashes
= elf_sym_hashes (abfd
);
7230 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7232 bed
= get_elf_backend_data (abfd
);
7233 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
7235 /* Check for the mips16 stub sections. */
7237 name
= bfd_get_section_name (abfd
, sec
);
7238 if (FN_STUB_P (name
))
7240 unsigned long r_symndx
;
7242 /* Look at the relocation information to figure out which symbol
7245 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
7248 (*_bfd_error_handler
)
7249 (_("%B: Warning: cannot determine the target function for"
7250 " stub section `%s'"),
7252 bfd_set_error (bfd_error_bad_value
);
7256 if (r_symndx
< extsymoff
7257 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7261 /* This stub is for a local symbol. This stub will only be
7262 needed if there is some relocation in this BFD, other
7263 than a 16 bit function call, which refers to this symbol. */
7264 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
7266 Elf_Internal_Rela
*sec_relocs
;
7267 const Elf_Internal_Rela
*r
, *rend
;
7269 /* We can ignore stub sections when looking for relocs. */
7270 if ((o
->flags
& SEC_RELOC
) == 0
7271 || o
->reloc_count
== 0
7272 || section_allows_mips16_refs_p (o
))
7276 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
7278 if (sec_relocs
== NULL
)
7281 rend
= sec_relocs
+ o
->reloc_count
;
7282 for (r
= sec_relocs
; r
< rend
; r
++)
7283 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
7284 && !mips16_call_reloc_p (ELF_R_TYPE (abfd
, r
->r_info
)))
7287 if (elf_section_data (o
)->relocs
!= sec_relocs
)
7296 /* There is no non-call reloc for this stub, so we do
7297 not need it. Since this function is called before
7298 the linker maps input sections to output sections, we
7299 can easily discard it by setting the SEC_EXCLUDE
7301 sec
->flags
|= SEC_EXCLUDE
;
7305 /* Record this stub in an array of local symbol stubs for
7307 if (elf_tdata (abfd
)->local_stubs
== NULL
)
7309 unsigned long symcount
;
7313 if (elf_bad_symtab (abfd
))
7314 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
7316 symcount
= symtab_hdr
->sh_info
;
7317 amt
= symcount
* sizeof (asection
*);
7318 n
= bfd_zalloc (abfd
, amt
);
7321 elf_tdata (abfd
)->local_stubs
= n
;
7324 sec
->flags
|= SEC_KEEP
;
7325 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
7327 /* We don't need to set mips16_stubs_seen in this case.
7328 That flag is used to see whether we need to look through
7329 the global symbol table for stubs. We don't need to set
7330 it here, because we just have a local stub. */
7334 struct mips_elf_link_hash_entry
*h
;
7336 h
= ((struct mips_elf_link_hash_entry
*)
7337 sym_hashes
[r_symndx
- extsymoff
]);
7339 while (h
->root
.root
.type
== bfd_link_hash_indirect
7340 || h
->root
.root
.type
== bfd_link_hash_warning
)
7341 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
7343 /* H is the symbol this stub is for. */
7345 /* If we already have an appropriate stub for this function, we
7346 don't need another one, so we can discard this one. Since
7347 this function is called before the linker maps input sections
7348 to output sections, we can easily discard it by setting the
7349 SEC_EXCLUDE flag. */
7350 if (h
->fn_stub
!= NULL
)
7352 sec
->flags
|= SEC_EXCLUDE
;
7356 sec
->flags
|= SEC_KEEP
;
7358 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
7361 else if (CALL_STUB_P (name
) || CALL_FP_STUB_P (name
))
7363 unsigned long r_symndx
;
7364 struct mips_elf_link_hash_entry
*h
;
7367 /* Look at the relocation information to figure out which symbol
7370 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
7373 (*_bfd_error_handler
)
7374 (_("%B: Warning: cannot determine the target function for"
7375 " stub section `%s'"),
7377 bfd_set_error (bfd_error_bad_value
);
7381 if (r_symndx
< extsymoff
7382 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7386 /* This stub is for a local symbol. This stub will only be
7387 needed if there is some relocation (R_MIPS16_26) in this BFD
7388 that refers to this symbol. */
7389 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
7391 Elf_Internal_Rela
*sec_relocs
;
7392 const Elf_Internal_Rela
*r
, *rend
;
7394 /* We can ignore stub sections when looking for relocs. */
7395 if ((o
->flags
& SEC_RELOC
) == 0
7396 || o
->reloc_count
== 0
7397 || section_allows_mips16_refs_p (o
))
7401 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
7403 if (sec_relocs
== NULL
)
7406 rend
= sec_relocs
+ o
->reloc_count
;
7407 for (r
= sec_relocs
; r
< rend
; r
++)
7408 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
7409 && ELF_R_TYPE (abfd
, r
->r_info
) == R_MIPS16_26
)
7412 if (elf_section_data (o
)->relocs
!= sec_relocs
)
7421 /* There is no non-call reloc for this stub, so we do
7422 not need it. Since this function is called before
7423 the linker maps input sections to output sections, we
7424 can easily discard it by setting the SEC_EXCLUDE
7426 sec
->flags
|= SEC_EXCLUDE
;
7430 /* Record this stub in an array of local symbol call_stubs for
7432 if (elf_tdata (abfd
)->local_call_stubs
== NULL
)
7434 unsigned long symcount
;
7438 if (elf_bad_symtab (abfd
))
7439 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
7441 symcount
= symtab_hdr
->sh_info
;
7442 amt
= symcount
* sizeof (asection
*);
7443 n
= bfd_zalloc (abfd
, amt
);
7446 elf_tdata (abfd
)->local_call_stubs
= n
;
7449 sec
->flags
|= SEC_KEEP
;
7450 elf_tdata (abfd
)->local_call_stubs
[r_symndx
] = sec
;
7452 /* We don't need to set mips16_stubs_seen in this case.
7453 That flag is used to see whether we need to look through
7454 the global symbol table for stubs. We don't need to set
7455 it here, because we just have a local stub. */
7459 h
= ((struct mips_elf_link_hash_entry
*)
7460 sym_hashes
[r_symndx
- extsymoff
]);
7462 /* H is the symbol this stub is for. */
7464 if (CALL_FP_STUB_P (name
))
7465 loc
= &h
->call_fp_stub
;
7467 loc
= &h
->call_stub
;
7469 /* If we already have an appropriate stub for this function, we
7470 don't need another one, so we can discard this one. Since
7471 this function is called before the linker maps input sections
7472 to output sections, we can easily discard it by setting the
7473 SEC_EXCLUDE flag. */
7476 sec
->flags
|= SEC_EXCLUDE
;
7480 sec
->flags
|= SEC_KEEP
;
7482 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
7488 for (rel
= relocs
; rel
< rel_end
; ++rel
)
7490 unsigned long r_symndx
;
7491 unsigned int r_type
;
7492 struct elf_link_hash_entry
*h
;
7493 bfd_boolean can_make_dynamic_p
;
7495 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
7496 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7498 if (r_symndx
< extsymoff
)
7500 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
7502 (*_bfd_error_handler
)
7503 (_("%B: Malformed reloc detected for section %s"),
7505 bfd_set_error (bfd_error_bad_value
);
7510 h
= sym_hashes
[r_symndx
- extsymoff
];
7512 && (h
->root
.type
== bfd_link_hash_indirect
7513 || h
->root
.type
== bfd_link_hash_warning
))
7514 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7517 /* Set CAN_MAKE_DYNAMIC_P to true if we can convert this
7518 relocation into a dynamic one. */
7519 can_make_dynamic_p
= FALSE
;
7522 case R_MIPS16_GOT16
:
7523 case R_MIPS16_CALL16
:
7526 case R_MIPS_CALL_HI16
:
7527 case R_MIPS_CALL_LO16
:
7528 case R_MIPS_GOT_HI16
:
7529 case R_MIPS_GOT_LO16
:
7530 case R_MIPS_GOT_PAGE
:
7531 case R_MIPS_GOT_OFST
:
7532 case R_MIPS_GOT_DISP
:
7533 case R_MIPS_TLS_GOTTPREL
:
7535 case R_MIPS_TLS_LDM
:
7537 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7538 if (!mips_elf_create_got_section (dynobj
, info
))
7540 if (htab
->is_vxworks
&& !info
->shared
)
7542 (*_bfd_error_handler
)
7543 (_("%B: GOT reloc at 0x%lx not expected in executables"),
7544 abfd
, (unsigned long) rel
->r_offset
);
7545 bfd_set_error (bfd_error_bad_value
);
7550 /* This is just a hint; it can safely be ignored. Don't set
7551 has_static_relocs for the corresponding symbol. */
7558 /* In VxWorks executables, references to external symbols
7559 must be handled using copy relocs or PLT entries; it is not
7560 possible to convert this relocation into a dynamic one.
7562 For executables that use PLTs and copy-relocs, we have a
7563 choice between converting the relocation into a dynamic
7564 one or using copy relocations or PLT entries. It is
7565 usually better to do the former, unless the relocation is
7566 against a read-only section. */
7569 && !htab
->is_vxworks
7570 && strcmp (h
->root
.root
.string
, "__gnu_local_gp") != 0
7571 && !(!info
->nocopyreloc
7572 && !PIC_OBJECT_P (abfd
)
7573 && MIPS_ELF_READONLY_SECTION (sec
))))
7574 && (sec
->flags
& SEC_ALLOC
) != 0)
7576 can_make_dynamic_p
= TRUE
;
7578 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7584 /* Most static relocations require pointer equality, except
7587 h
->pointer_equality_needed
= TRUE
;
7594 ((struct mips_elf_link_hash_entry
*) h
)->has_static_relocs
= TRUE
;
7600 /* Relocations against the special VxWorks __GOTT_BASE__ and
7601 __GOTT_INDEX__ symbols must be left to the loader. Allocate
7602 room for them in .rela.dyn. */
7603 if (is_gott_symbol (info
, h
))
7607 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7611 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7612 if (MIPS_ELF_READONLY_SECTION (sec
))
7613 /* We tell the dynamic linker that there are
7614 relocations against the text segment. */
7615 info
->flags
|= DF_TEXTREL
;
7618 else if (r_type
== R_MIPS_CALL_LO16
7619 || r_type
== R_MIPS_GOT_LO16
7620 || r_type
== R_MIPS_GOT_DISP
7621 || (got16_reloc_p (r_type
) && htab
->is_vxworks
))
7623 /* We may need a local GOT entry for this relocation. We
7624 don't count R_MIPS_GOT_PAGE because we can estimate the
7625 maximum number of pages needed by looking at the size of
7626 the segment. Similar comments apply to R_MIPS*_GOT16 and
7627 R_MIPS*_CALL16, except on VxWorks, where GOT relocations
7628 always evaluate to "G". We don't count R_MIPS_GOT_HI16, or
7629 R_MIPS_CALL_HI16 because these are always followed by an
7630 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
7631 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7632 rel
->r_addend
, info
, 0))
7636 if (h
!= NULL
&& mips_elf_relocation_needs_la25_stub (abfd
, r_type
))
7637 ((struct mips_elf_link_hash_entry
*) h
)->has_nonpic_branches
= TRUE
;
7642 case R_MIPS16_CALL16
:
7645 (*_bfd_error_handler
)
7646 (_("%B: CALL16 reloc at 0x%lx not against global symbol"),
7647 abfd
, (unsigned long) rel
->r_offset
);
7648 bfd_set_error (bfd_error_bad_value
);
7653 case R_MIPS_CALL_HI16
:
7654 case R_MIPS_CALL_LO16
:
7657 /* VxWorks call relocations point at the function's .got.plt
7658 entry, which will be allocated by adjust_dynamic_symbol.
7659 Otherwise, this symbol requires a global GOT entry. */
7660 if ((!htab
->is_vxworks
|| h
->forced_local
)
7661 && !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7664 /* We need a stub, not a plt entry for the undefined
7665 function. But we record it as if it needs plt. See
7666 _bfd_elf_adjust_dynamic_symbol. */
7672 case R_MIPS_GOT_PAGE
:
7673 /* If this is a global, overridable symbol, GOT_PAGE will
7674 decay to GOT_DISP, so we'll need a GOT entry for it. */
7677 struct mips_elf_link_hash_entry
*hmips
=
7678 (struct mips_elf_link_hash_entry
*) h
;
7680 /* This symbol is definitely not overridable. */
7681 if (hmips
->root
.def_regular
7682 && ! (info
->shared
&& ! info
->symbolic
7683 && ! hmips
->root
.forced_local
))
7688 case R_MIPS16_GOT16
:
7690 case R_MIPS_GOT_HI16
:
7691 case R_MIPS_GOT_LO16
:
7692 if (!h
|| r_type
== R_MIPS_GOT_PAGE
)
7694 /* This relocation needs (or may need, if h != NULL) a
7695 page entry in the GOT. For R_MIPS_GOT_PAGE we do not
7696 know for sure until we know whether the symbol is
7698 if (mips_elf_rel_relocation_p (abfd
, sec
, relocs
, rel
))
7700 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
7702 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
7703 addend
= mips_elf_read_rel_addend (abfd
, rel
,
7705 if (got16_reloc_p (r_type
))
7706 mips_elf_add_lo16_rel_addend (abfd
, rel
, rel_end
,
7709 addend
<<= howto
->rightshift
;
7712 addend
= rel
->r_addend
;
7713 if (!mips_elf_record_got_page_entry (info
, abfd
, r_symndx
,
7720 case R_MIPS_GOT_DISP
:
7721 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7725 case R_MIPS_TLS_GOTTPREL
:
7727 info
->flags
|= DF_STATIC_TLS
;
7730 case R_MIPS_TLS_LDM
:
7731 if (r_type
== R_MIPS_TLS_LDM
)
7739 /* This symbol requires a global offset table entry, or two
7740 for TLS GD relocations. */
7742 unsigned char flag
= (r_type
== R_MIPS_TLS_GD
7744 : r_type
== R_MIPS_TLS_LDM
7749 struct mips_elf_link_hash_entry
*hmips
=
7750 (struct mips_elf_link_hash_entry
*) h
;
7751 hmips
->tls_type
|= flag
;
7753 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
,
7759 BFD_ASSERT (flag
== GOT_TLS_LDM
|| r_symndx
!= 0);
7761 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7772 /* In VxWorks executables, references to external symbols
7773 are handled using copy relocs or PLT stubs, so there's
7774 no need to add a .rela.dyn entry for this relocation. */
7775 if (can_make_dynamic_p
)
7779 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7783 if (info
->shared
&& h
== NULL
)
7785 /* When creating a shared object, we must copy these
7786 reloc types into the output file as R_MIPS_REL32
7787 relocs. Make room for this reloc in .rel(a).dyn. */
7788 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7789 if (MIPS_ELF_READONLY_SECTION (sec
))
7790 /* We tell the dynamic linker that there are
7791 relocations against the text segment. */
7792 info
->flags
|= DF_TEXTREL
;
7796 struct mips_elf_link_hash_entry
*hmips
;
7798 /* For a shared object, we must copy this relocation
7799 unless the symbol turns out to be undefined and
7800 weak with non-default visibility, in which case
7801 it will be left as zero.
7803 We could elide R_MIPS_REL32 for locally binding symbols
7804 in shared libraries, but do not yet do so.
7806 For an executable, we only need to copy this
7807 reloc if the symbol is defined in a dynamic
7809 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7810 ++hmips
->possibly_dynamic_relocs
;
7811 if (MIPS_ELF_READONLY_SECTION (sec
))
7812 /* We need it to tell the dynamic linker if there
7813 are relocations against the text segment. */
7814 hmips
->readonly_reloc
= TRUE
;
7818 if (SGI_COMPAT (abfd
))
7819 mips_elf_hash_table (info
)->compact_rel_size
+=
7820 sizeof (Elf32_External_crinfo
);
7824 case R_MIPS_GPREL16
:
7825 case R_MIPS_LITERAL
:
7826 case R_MIPS_GPREL32
:
7827 if (SGI_COMPAT (abfd
))
7828 mips_elf_hash_table (info
)->compact_rel_size
+=
7829 sizeof (Elf32_External_crinfo
);
7832 /* This relocation describes the C++ object vtable hierarchy.
7833 Reconstruct it for later use during GC. */
7834 case R_MIPS_GNU_VTINHERIT
:
7835 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7839 /* This relocation describes which C++ vtable entries are actually
7840 used. Record for later use during GC. */
7841 case R_MIPS_GNU_VTENTRY
:
7842 BFD_ASSERT (h
!= NULL
);
7844 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7852 /* We must not create a stub for a symbol that has relocations
7853 related to taking the function's address. This doesn't apply to
7854 VxWorks, where CALL relocs refer to a .got.plt entry instead of
7855 a normal .got entry. */
7856 if (!htab
->is_vxworks
&& h
!= NULL
)
7860 ((struct mips_elf_link_hash_entry
*) h
)->no_fn_stub
= TRUE
;
7862 case R_MIPS16_CALL16
:
7864 case R_MIPS_CALL_HI16
:
7865 case R_MIPS_CALL_LO16
:
7870 /* See if this reloc would need to refer to a MIPS16 hard-float stub,
7871 if there is one. We only need to handle global symbols here;
7872 we decide whether to keep or delete stubs for local symbols
7873 when processing the stub's relocations. */
7875 && !mips16_call_reloc_p (r_type
)
7876 && !section_allows_mips16_refs_p (sec
))
7878 struct mips_elf_link_hash_entry
*mh
;
7880 mh
= (struct mips_elf_link_hash_entry
*) h
;
7881 mh
->need_fn_stub
= TRUE
;
7884 /* Refuse some position-dependent relocations when creating a
7885 shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
7886 not PIC, but we can create dynamic relocations and the result
7887 will be fine. Also do not refuse R_MIPS_LO16, which can be
7888 combined with R_MIPS_GOT16. */
7896 case R_MIPS_HIGHEST
:
7897 /* Don't refuse a high part relocation if it's against
7898 no symbol (e.g. part of a compound relocation). */
7902 /* R_MIPS_HI16 against _gp_disp is used for $gp setup,
7903 and has a special meaning. */
7904 if (!NEWABI_P (abfd
) && h
!= NULL
7905 && strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
7908 /* Likewise __GOTT_BASE__ and __GOTT_INDEX__ on VxWorks. */
7909 if (is_gott_symbol (info
, h
))
7916 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
7917 (*_bfd_error_handler
)
7918 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
7920 (h
) ? h
->root
.root
.string
: "a local symbol");
7921 bfd_set_error (bfd_error_bad_value
);
7933 _bfd_mips_relax_section (bfd
*abfd
, asection
*sec
,
7934 struct bfd_link_info
*link_info
,
7937 Elf_Internal_Rela
*internal_relocs
;
7938 Elf_Internal_Rela
*irel
, *irelend
;
7939 Elf_Internal_Shdr
*symtab_hdr
;
7940 bfd_byte
*contents
= NULL
;
7942 bfd_boolean changed_contents
= FALSE
;
7943 bfd_vma sec_start
= sec
->output_section
->vma
+ sec
->output_offset
;
7944 Elf_Internal_Sym
*isymbuf
= NULL
;
7946 /* We are not currently changing any sizes, so only one pass. */
7949 if (link_info
->relocatable
)
7952 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
7953 link_info
->keep_memory
);
7954 if (internal_relocs
== NULL
)
7957 irelend
= internal_relocs
+ sec
->reloc_count
7958 * get_elf_backend_data (abfd
)->s
->int_rels_per_ext_rel
;
7959 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7960 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7962 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
7965 bfd_signed_vma sym_offset
;
7966 unsigned int r_type
;
7967 unsigned long r_symndx
;
7969 unsigned long instruction
;
7971 /* Turn jalr into bgezal, and jr into beq, if they're marked
7972 with a JALR relocation, that indicate where they jump to.
7973 This saves some pipeline bubbles. */
7974 r_type
= ELF_R_TYPE (abfd
, irel
->r_info
);
7975 if (r_type
!= R_MIPS_JALR
)
7978 r_symndx
= ELF_R_SYM (abfd
, irel
->r_info
);
7979 /* Compute the address of the jump target. */
7980 if (r_symndx
>= extsymoff
)
7982 struct mips_elf_link_hash_entry
*h
7983 = ((struct mips_elf_link_hash_entry
*)
7984 elf_sym_hashes (abfd
) [r_symndx
- extsymoff
]);
7986 while (h
->root
.root
.type
== bfd_link_hash_indirect
7987 || h
->root
.root
.type
== bfd_link_hash_warning
)
7988 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
7990 /* If a symbol is undefined, or if it may be overridden,
7992 if (! ((h
->root
.root
.type
== bfd_link_hash_defined
7993 || h
->root
.root
.type
== bfd_link_hash_defweak
)
7994 && h
->root
.root
.u
.def
.section
)
7995 || (link_info
->shared
&& ! link_info
->symbolic
7996 && !h
->root
.forced_local
))
7999 sym_sec
= h
->root
.root
.u
.def
.section
;
8000 if (sym_sec
->output_section
)
8001 symval
= (h
->root
.root
.u
.def
.value
8002 + sym_sec
->output_section
->vma
8003 + sym_sec
->output_offset
);
8005 symval
= h
->root
.root
.u
.def
.value
;
8009 Elf_Internal_Sym
*isym
;
8011 /* Read this BFD's symbols if we haven't done so already. */
8012 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
8014 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
8015 if (isymbuf
== NULL
)
8016 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
8017 symtab_hdr
->sh_info
, 0,
8019 if (isymbuf
== NULL
)
8023 isym
= isymbuf
+ r_symndx
;
8024 if (isym
->st_shndx
== SHN_UNDEF
)
8026 else if (isym
->st_shndx
== SHN_ABS
)
8027 sym_sec
= bfd_abs_section_ptr
;
8028 else if (isym
->st_shndx
== SHN_COMMON
)
8029 sym_sec
= bfd_com_section_ptr
;
8032 = bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
8033 symval
= isym
->st_value
8034 + sym_sec
->output_section
->vma
8035 + sym_sec
->output_offset
;
8038 /* Compute branch offset, from delay slot of the jump to the
8040 sym_offset
= (symval
+ irel
->r_addend
)
8041 - (sec_start
+ irel
->r_offset
+ 4);
8043 /* Branch offset must be properly aligned. */
8044 if ((sym_offset
& 3) != 0)
8049 /* Check that it's in range. */
8050 if (sym_offset
< -0x8000 || sym_offset
>= 0x8000)
8053 /* Get the section contents if we haven't done so already. */
8054 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
8057 instruction
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
8059 /* If it was jalr <reg>, turn it into bgezal $zero, <target>. */
8060 if ((instruction
& 0xfc1fffff) == 0x0000f809)
8061 instruction
= 0x04110000;
8062 /* If it was jr <reg>, turn it into b <target>. */
8063 else if ((instruction
& 0xfc1fffff) == 0x00000008)
8064 instruction
= 0x10000000;
8068 instruction
|= (sym_offset
& 0xffff);
8069 bfd_put_32 (abfd
, instruction
, contents
+ irel
->r_offset
);
8070 changed_contents
= TRUE
;
8073 if (contents
!= NULL
8074 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
8076 if (!changed_contents
&& !link_info
->keep_memory
)
8080 /* Cache the section contents for elf_link_input_bfd. */
8081 elf_section_data (sec
)->this_hdr
.contents
= contents
;
8087 if (contents
!= NULL
8088 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
8093 /* Allocate space for global sym dynamic relocs. */
8096 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8098 struct bfd_link_info
*info
= inf
;
8100 struct mips_elf_link_hash_entry
*hmips
;
8101 struct mips_elf_link_hash_table
*htab
;
8103 htab
= mips_elf_hash_table (info
);
8104 BFD_ASSERT (htab
!= NULL
);
8106 dynobj
= elf_hash_table (info
)->dynobj
;
8107 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8109 /* VxWorks executables are handled elsewhere; we only need to
8110 allocate relocations in shared objects. */
8111 if (htab
->is_vxworks
&& !info
->shared
)
8114 /* Ignore indirect and warning symbols. All relocations against
8115 such symbols will be redirected to the target symbol. */
8116 if (h
->root
.type
== bfd_link_hash_indirect
8117 || h
->root
.type
== bfd_link_hash_warning
)
8120 /* If this symbol is defined in a dynamic object, or we are creating
8121 a shared library, we will need to copy any R_MIPS_32 or
8122 R_MIPS_REL32 relocs against it into the output file. */
8123 if (! info
->relocatable
8124 && hmips
->possibly_dynamic_relocs
!= 0
8125 && (h
->root
.type
== bfd_link_hash_defweak
8129 bfd_boolean do_copy
= TRUE
;
8131 if (h
->root
.type
== bfd_link_hash_undefweak
)
8133 /* Do not copy relocations for undefined weak symbols with
8134 non-default visibility. */
8135 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8138 /* Make sure undefined weak symbols are output as a dynamic
8140 else if (h
->dynindx
== -1 && !h
->forced_local
)
8142 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8149 /* Even though we don't directly need a GOT entry for this symbol,
8150 the SVR4 psABI requires it to have a dynamic symbol table
8151 index greater that DT_MIPS_GOTSYM if there are dynamic
8152 relocations against it.
8154 VxWorks does not enforce the same mapping between the GOT
8155 and the symbol table, so the same requirement does not
8157 if (!htab
->is_vxworks
&& hmips
->global_got_area
> GGA_RELOC_ONLY
)
8158 hmips
->global_got_area
= GGA_RELOC_ONLY
;
8160 mips_elf_allocate_dynamic_relocations
8161 (dynobj
, info
, hmips
->possibly_dynamic_relocs
);
8162 if (hmips
->readonly_reloc
)
8163 /* We tell the dynamic linker that there are relocations
8164 against the text segment. */
8165 info
->flags
|= DF_TEXTREL
;
8172 /* Adjust a symbol defined by a dynamic object and referenced by a
8173 regular object. The current definition is in some section of the
8174 dynamic object, but we're not including those sections. We have to
8175 change the definition to something the rest of the link can
8179 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
8180 struct elf_link_hash_entry
*h
)
8183 struct mips_elf_link_hash_entry
*hmips
;
8184 struct mips_elf_link_hash_table
*htab
;
8186 htab
= mips_elf_hash_table (info
);
8187 BFD_ASSERT (htab
!= NULL
);
8189 dynobj
= elf_hash_table (info
)->dynobj
;
8190 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8192 /* Make sure we know what is going on here. */
8193 BFD_ASSERT (dynobj
!= NULL
8195 || h
->u
.weakdef
!= NULL
8198 && !h
->def_regular
)));
8200 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8202 /* If there are call relocations against an externally-defined symbol,
8203 see whether we can create a MIPS lazy-binding stub for it. We can
8204 only do this if all references to the function are through call
8205 relocations, and in that case, the traditional lazy-binding stubs
8206 are much more efficient than PLT entries.
8208 Traditional stubs are only available on SVR4 psABI-based systems;
8209 VxWorks always uses PLTs instead. */
8210 if (!htab
->is_vxworks
&& h
->needs_plt
&& !hmips
->no_fn_stub
)
8212 if (! elf_hash_table (info
)->dynamic_sections_created
)
8215 /* If this symbol is not defined in a regular file, then set
8216 the symbol to the stub location. This is required to make
8217 function pointers compare as equal between the normal
8218 executable and the shared library. */
8219 if (!h
->def_regular
)
8221 hmips
->needs_lazy_stub
= TRUE
;
8222 htab
->lazy_stub_count
++;
8226 /* As above, VxWorks requires PLT entries for externally-defined
8227 functions that are only accessed through call relocations.
8229 Both VxWorks and non-VxWorks targets also need PLT entries if there
8230 are static-only relocations against an externally-defined function.
8231 This can technically occur for shared libraries if there are
8232 branches to the symbol, although it is unlikely that this will be
8233 used in practice due to the short ranges involved. It can occur
8234 for any relative or absolute relocation in executables; in that
8235 case, the PLT entry becomes the function's canonical address. */
8236 else if (((h
->needs_plt
&& !hmips
->no_fn_stub
)
8237 || (h
->type
== STT_FUNC
&& hmips
->has_static_relocs
))
8238 && htab
->use_plts_and_copy_relocs
8239 && !SYMBOL_CALLS_LOCAL (info
, h
)
8240 && !(ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
8241 && h
->root
.type
== bfd_link_hash_undefweak
))
8243 /* If this is the first symbol to need a PLT entry, allocate room
8245 if (htab
->splt
->size
== 0)
8247 BFD_ASSERT (htab
->sgotplt
->size
== 0);
8249 /* If we're using the PLT additions to the psABI, each PLT
8250 entry is 16 bytes and the PLT0 entry is 32 bytes.
8251 Encourage better cache usage by aligning. We do this
8252 lazily to avoid pessimizing traditional objects. */
8253 if (!htab
->is_vxworks
8254 && !bfd_set_section_alignment (dynobj
, htab
->splt
, 5))
8257 /* Make sure that .got.plt is word-aligned. We do this lazily
8258 for the same reason as above. */
8259 if (!bfd_set_section_alignment (dynobj
, htab
->sgotplt
,
8260 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
8263 htab
->splt
->size
+= htab
->plt_header_size
;
8265 /* On non-VxWorks targets, the first two entries in .got.plt
8267 if (!htab
->is_vxworks
)
8268 htab
->sgotplt
->size
+= 2 * MIPS_ELF_GOT_SIZE (dynobj
);
8270 /* On VxWorks, also allocate room for the header's
8271 .rela.plt.unloaded entries. */
8272 if (htab
->is_vxworks
&& !info
->shared
)
8273 htab
->srelplt2
->size
+= 2 * sizeof (Elf32_External_Rela
);
8276 /* Assign the next .plt entry to this symbol. */
8277 h
->plt
.offset
= htab
->splt
->size
;
8278 htab
->splt
->size
+= htab
->plt_entry_size
;
8280 /* If the output file has no definition of the symbol, set the
8281 symbol's value to the address of the stub. */
8282 if (!info
->shared
&& !h
->def_regular
)
8284 h
->root
.u
.def
.section
= htab
->splt
;
8285 h
->root
.u
.def
.value
= h
->plt
.offset
;
8286 /* For VxWorks, point at the PLT load stub rather than the
8287 lazy resolution stub; this stub will become the canonical
8288 function address. */
8289 if (htab
->is_vxworks
)
8290 h
->root
.u
.def
.value
+= 8;
8293 /* Make room for the .got.plt entry and the R_MIPS_JUMP_SLOT
8295 htab
->sgotplt
->size
+= MIPS_ELF_GOT_SIZE (dynobj
);
8296 htab
->srelplt
->size
+= (htab
->is_vxworks
8297 ? MIPS_ELF_RELA_SIZE (dynobj
)
8298 : MIPS_ELF_REL_SIZE (dynobj
));
8300 /* Make room for the .rela.plt.unloaded relocations. */
8301 if (htab
->is_vxworks
&& !info
->shared
)
8302 htab
->srelplt2
->size
+= 3 * sizeof (Elf32_External_Rela
);
8304 /* All relocations against this symbol that could have been made
8305 dynamic will now refer to the PLT entry instead. */
8306 hmips
->possibly_dynamic_relocs
= 0;
8311 /* If this is a weak symbol, and there is a real definition, the
8312 processor independent code will have arranged for us to see the
8313 real definition first, and we can just use the same value. */
8314 if (h
->u
.weakdef
!= NULL
)
8316 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
8317 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
8318 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
8319 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
8323 /* Otherwise, there is nothing further to do for symbols defined
8324 in regular objects. */
8328 /* There's also nothing more to do if we'll convert all relocations
8329 against this symbol into dynamic relocations. */
8330 if (!hmips
->has_static_relocs
)
8333 /* We're now relying on copy relocations. Complain if we have
8334 some that we can't convert. */
8335 if (!htab
->use_plts_and_copy_relocs
|| info
->shared
)
8337 (*_bfd_error_handler
) (_("non-dynamic relocations refer to "
8338 "dynamic symbol %s"),
8339 h
->root
.root
.string
);
8340 bfd_set_error (bfd_error_bad_value
);
8344 /* We must allocate the symbol in our .dynbss section, which will
8345 become part of the .bss section of the executable. There will be
8346 an entry for this symbol in the .dynsym section. The dynamic
8347 object will contain position independent code, so all references
8348 from the dynamic object to this symbol will go through the global
8349 offset table. The dynamic linker will use the .dynsym entry to
8350 determine the address it must put in the global offset table, so
8351 both the dynamic object and the regular object will refer to the
8352 same memory location for the variable. */
8354 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
8356 if (htab
->is_vxworks
)
8357 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
8359 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
8363 /* All relocations against this symbol that could have been made
8364 dynamic will now refer to the local copy instead. */
8365 hmips
->possibly_dynamic_relocs
= 0;
8367 return _bfd_elf_adjust_dynamic_copy (h
, htab
->sdynbss
);
8370 /* This function is called after all the input files have been read,
8371 and the input sections have been assigned to output sections. We
8372 check for any mips16 stub sections that we can discard. */
8375 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
8376 struct bfd_link_info
*info
)
8379 struct mips_elf_link_hash_table
*htab
;
8380 struct mips_htab_traverse_info hti
;
8382 htab
= mips_elf_hash_table (info
);
8383 BFD_ASSERT (htab
!= NULL
);
8385 /* The .reginfo section has a fixed size. */
8386 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
8388 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
8391 hti
.output_bfd
= output_bfd
;
8393 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
8394 mips_elf_check_symbols
, &hti
);
8401 /* If the link uses a GOT, lay it out and work out its size. */
8404 mips_elf_lay_out_got (bfd
*output_bfd
, struct bfd_link_info
*info
)
8408 struct mips_got_info
*g
;
8409 bfd_size_type loadable_size
= 0;
8410 bfd_size_type page_gotno
;
8412 struct mips_elf_count_tls_arg count_tls_arg
;
8413 struct mips_elf_link_hash_table
*htab
;
8415 htab
= mips_elf_hash_table (info
);
8416 BFD_ASSERT (htab
!= NULL
);
8422 dynobj
= elf_hash_table (info
)->dynobj
;
8425 /* Allocate room for the reserved entries. VxWorks always reserves
8426 3 entries; other objects only reserve 2 entries. */
8427 BFD_ASSERT (g
->assigned_gotno
== 0);
8428 if (htab
->is_vxworks
)
8429 htab
->reserved_gotno
= 3;
8431 htab
->reserved_gotno
= 2;
8432 g
->local_gotno
+= htab
->reserved_gotno
;
8433 g
->assigned_gotno
= htab
->reserved_gotno
;
8435 /* Replace entries for indirect and warning symbols with entries for
8436 the target symbol. */
8437 if (!mips_elf_resolve_final_got_entries (g
))
8440 /* Count the number of GOT symbols. */
8441 mips_elf_link_hash_traverse (htab
, mips_elf_count_got_symbols
, info
);
8443 /* Calculate the total loadable size of the output. That
8444 will give us the maximum number of GOT_PAGE entries
8446 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
8448 asection
*subsection
;
8450 for (subsection
= sub
->sections
;
8452 subsection
= subsection
->next
)
8454 if ((subsection
->flags
& SEC_ALLOC
) == 0)
8456 loadable_size
+= ((subsection
->size
+ 0xf)
8457 &~ (bfd_size_type
) 0xf);
8461 if (htab
->is_vxworks
)
8462 /* There's no need to allocate page entries for VxWorks; R_MIPS*_GOT16
8463 relocations against local symbols evaluate to "G", and the EABI does
8464 not include R_MIPS_GOT_PAGE. */
8467 /* Assume there are two loadable segments consisting of contiguous
8468 sections. Is 5 enough? */
8469 page_gotno
= (loadable_size
>> 16) + 5;
8471 /* Choose the smaller of the two estimates; both are intended to be
8473 if (page_gotno
> g
->page_gotno
)
8474 page_gotno
= g
->page_gotno
;
8476 g
->local_gotno
+= page_gotno
;
8477 s
->size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
8478 s
->size
+= g
->global_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
8480 /* We need to calculate tls_gotno for global symbols at this point
8481 instead of building it up earlier, to avoid doublecounting
8482 entries for one global symbol from multiple input files. */
8483 count_tls_arg
.info
= info
;
8484 count_tls_arg
.needed
= 0;
8485 elf_link_hash_traverse (elf_hash_table (info
),
8486 mips_elf_count_global_tls_entries
,
8488 g
->tls_gotno
+= count_tls_arg
.needed
;
8489 s
->size
+= g
->tls_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
8491 /* VxWorks does not support multiple GOTs. It initializes $gp to
8492 __GOTT_BASE__[__GOTT_INDEX__], the value of which is set by the
8494 if (htab
->is_vxworks
)
8496 /* VxWorks executables do not need a GOT. */
8499 /* Each VxWorks GOT entry needs an explicit relocation. */
8502 count
= g
->global_gotno
+ g
->local_gotno
- htab
->reserved_gotno
;
8504 mips_elf_allocate_dynamic_relocations (dynobj
, info
, count
);
8507 else if (s
->size
> MIPS_ELF_GOT_MAX_SIZE (info
))
8509 if (!mips_elf_multi_got (output_bfd
, info
, s
, page_gotno
))
8514 struct mips_elf_count_tls_arg arg
;
8516 /* Set up TLS entries. */
8517 g
->tls_assigned_gotno
= g
->global_gotno
+ g
->local_gotno
;
8518 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
8520 /* Allocate room for the TLS relocations. */
8523 htab_traverse (g
->got_entries
, mips_elf_count_local_tls_relocs
, &arg
);
8524 elf_link_hash_traverse (elf_hash_table (info
),
8525 mips_elf_count_global_tls_relocs
,
8528 mips_elf_allocate_dynamic_relocations (dynobj
, info
, arg
.needed
);
8534 /* Estimate the size of the .MIPS.stubs section. */
8537 mips_elf_estimate_stub_size (bfd
*output_bfd
, struct bfd_link_info
*info
)
8539 struct mips_elf_link_hash_table
*htab
;
8540 bfd_size_type dynsymcount
;
8542 htab
= mips_elf_hash_table (info
);
8543 BFD_ASSERT (htab
!= NULL
);
8545 if (htab
->lazy_stub_count
== 0)
8548 /* IRIX rld assumes that a function stub isn't at the end of the .text
8549 section, so add a dummy entry to the end. */
8550 htab
->lazy_stub_count
++;
8552 /* Get a worst-case estimate of the number of dynamic symbols needed.
8553 At this point, dynsymcount does not account for section symbols
8554 and count_section_dynsyms may overestimate the number that will
8556 dynsymcount
= (elf_hash_table (info
)->dynsymcount
8557 + count_section_dynsyms (output_bfd
, info
));
8559 /* Determine the size of one stub entry. */
8560 htab
->function_stub_size
= (dynsymcount
> 0x10000
8561 ? MIPS_FUNCTION_STUB_BIG_SIZE
8562 : MIPS_FUNCTION_STUB_NORMAL_SIZE
);
8564 htab
->sstubs
->size
= htab
->lazy_stub_count
* htab
->function_stub_size
;
8567 /* A mips_elf_link_hash_traverse callback for which DATA points to the
8568 MIPS hash table. If H needs a traditional MIPS lazy-binding stub,
8569 allocate an entry in the stubs section. */
8572 mips_elf_allocate_lazy_stub (struct mips_elf_link_hash_entry
*h
, void **data
)
8574 struct mips_elf_link_hash_table
*htab
;
8576 htab
= (struct mips_elf_link_hash_table
*) data
;
8577 if (h
->needs_lazy_stub
)
8579 h
->root
.root
.u
.def
.section
= htab
->sstubs
;
8580 h
->root
.root
.u
.def
.value
= htab
->sstubs
->size
;
8581 h
->root
.plt
.offset
= htab
->sstubs
->size
;
8582 htab
->sstubs
->size
+= htab
->function_stub_size
;
8587 /* Allocate offsets in the stubs section to each symbol that needs one.
8588 Set the final size of the .MIPS.stub section. */
8591 mips_elf_lay_out_lazy_stubs (struct bfd_link_info
*info
)
8593 struct mips_elf_link_hash_table
*htab
;
8595 htab
= mips_elf_hash_table (info
);
8596 BFD_ASSERT (htab
!= NULL
);
8598 if (htab
->lazy_stub_count
== 0)
8601 htab
->sstubs
->size
= 0;
8602 mips_elf_link_hash_traverse (htab
, mips_elf_allocate_lazy_stub
, htab
);
8603 htab
->sstubs
->size
+= htab
->function_stub_size
;
8604 BFD_ASSERT (htab
->sstubs
->size
8605 == htab
->lazy_stub_count
* htab
->function_stub_size
);
8608 /* Set the sizes of the dynamic sections. */
8611 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
8612 struct bfd_link_info
*info
)
8615 asection
*s
, *sreldyn
;
8616 bfd_boolean reltext
;
8617 struct mips_elf_link_hash_table
*htab
;
8619 htab
= mips_elf_hash_table (info
);
8620 BFD_ASSERT (htab
!= NULL
);
8621 dynobj
= elf_hash_table (info
)->dynobj
;
8622 BFD_ASSERT (dynobj
!= NULL
);
8624 if (elf_hash_table (info
)->dynamic_sections_created
)
8626 /* Set the contents of the .interp section to the interpreter. */
8627 if (info
->executable
)
8629 s
= bfd_get_section_by_name (dynobj
, ".interp");
8630 BFD_ASSERT (s
!= NULL
);
8632 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
8634 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
8637 /* Create a symbol for the PLT, if we know that we are using it. */
8638 if (htab
->splt
&& htab
->splt
->size
> 0 && htab
->root
.hplt
== NULL
)
8640 struct elf_link_hash_entry
*h
;
8642 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
8644 h
= _bfd_elf_define_linkage_sym (dynobj
, info
, htab
->splt
,
8645 "_PROCEDURE_LINKAGE_TABLE_");
8646 htab
->root
.hplt
= h
;
8653 /* Allocate space for global sym dynamic relocs. */
8654 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
8656 mips_elf_estimate_stub_size (output_bfd
, info
);
8658 if (!mips_elf_lay_out_got (output_bfd
, info
))
8661 mips_elf_lay_out_lazy_stubs (info
);
8663 /* The check_relocs and adjust_dynamic_symbol entry points have
8664 determined the sizes of the various dynamic sections. Allocate
8667 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8671 /* It's OK to base decisions on the section name, because none
8672 of the dynobj section names depend upon the input files. */
8673 name
= bfd_get_section_name (dynobj
, s
);
8675 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8678 if (CONST_STRNEQ (name
, ".rel"))
8682 const char *outname
;
8685 /* If this relocation section applies to a read only
8686 section, then we probably need a DT_TEXTREL entry.
8687 If the relocation section is .rel(a).dyn, we always
8688 assert a DT_TEXTREL entry rather than testing whether
8689 there exists a relocation to a read only section or
8691 outname
= bfd_get_section_name (output_bfd
,
8693 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
8695 && (target
->flags
& SEC_READONLY
) != 0
8696 && (target
->flags
& SEC_ALLOC
) != 0)
8697 || strcmp (outname
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
8700 /* We use the reloc_count field as a counter if we need
8701 to copy relocs into the output file. */
8702 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) != 0)
8705 /* If combreloc is enabled, elf_link_sort_relocs() will
8706 sort relocations, but in a different way than we do,
8707 and before we're done creating relocations. Also, it
8708 will move them around between input sections'
8709 relocation's contents, so our sorting would be
8710 broken, so don't let it run. */
8711 info
->combreloc
= 0;
8714 else if (! info
->shared
8715 && ! mips_elf_hash_table (info
)->use_rld_obj_head
8716 && CONST_STRNEQ (name
, ".rld_map"))
8718 /* We add a room for __rld_map. It will be filled in by the
8719 rtld to contain a pointer to the _r_debug structure. */
8722 else if (SGI_COMPAT (output_bfd
)
8723 && CONST_STRNEQ (name
, ".compact_rel"))
8724 s
->size
+= mips_elf_hash_table (info
)->compact_rel_size
;
8725 else if (s
== htab
->splt
)
8727 /* If the last PLT entry has a branch delay slot, allocate
8728 room for an extra nop to fill the delay slot. This is
8729 for CPUs without load interlocking. */
8730 if (! LOAD_INTERLOCKS_P (output_bfd
)
8731 && ! htab
->is_vxworks
&& s
->size
> 0)
8734 else if (! CONST_STRNEQ (name
, ".init")
8736 && s
!= htab
->sgotplt
8737 && s
!= htab
->sstubs
8738 && s
!= htab
->sdynbss
)
8740 /* It's not one of our sections, so don't allocate space. */
8746 s
->flags
|= SEC_EXCLUDE
;
8750 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8753 /* Allocate memory for the section contents. */
8754 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
8755 if (s
->contents
== NULL
)
8757 bfd_set_error (bfd_error_no_memory
);
8762 if (elf_hash_table (info
)->dynamic_sections_created
)
8764 /* Add some entries to the .dynamic section. We fill in the
8765 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
8766 must add the entries now so that we get the correct size for
8767 the .dynamic section. */
8769 /* SGI object has the equivalence of DT_DEBUG in the
8770 DT_MIPS_RLD_MAP entry. This must come first because glibc
8771 only fills in DT_MIPS_RLD_MAP (not DT_DEBUG) and GDB only
8772 looks at the first one it sees. */
8774 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
8777 /* The DT_DEBUG entry may be filled in by the dynamic linker and
8778 used by the debugger. */
8779 if (info
->executable
8780 && !SGI_COMPAT (output_bfd
)
8781 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
8784 if (reltext
&& (SGI_COMPAT (output_bfd
) || htab
->is_vxworks
))
8785 info
->flags
|= DF_TEXTREL
;
8787 if ((info
->flags
& DF_TEXTREL
) != 0)
8789 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
8792 /* Clear the DF_TEXTREL flag. It will be set again if we
8793 write out an actual text relocation; we may not, because
8794 at this point we do not know whether e.g. any .eh_frame
8795 absolute relocations have been converted to PC-relative. */
8796 info
->flags
&= ~DF_TEXTREL
;
8799 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
8802 sreldyn
= mips_elf_rel_dyn_section (info
, FALSE
);
8803 if (htab
->is_vxworks
)
8805 /* VxWorks uses .rela.dyn instead of .rel.dyn. It does not
8806 use any of the DT_MIPS_* tags. */
8807 if (sreldyn
&& sreldyn
->size
> 0)
8809 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELA
, 0))
8812 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELASZ
, 0))
8815 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELAENT
, 0))
8821 if (sreldyn
&& sreldyn
->size
> 0)
8823 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
8826 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
8829 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
8833 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
8836 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
8839 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
8842 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
8845 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
8848 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
8851 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
8854 if (IRIX_COMPAT (dynobj
) == ict_irix5
8855 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
8858 if (IRIX_COMPAT (dynobj
) == ict_irix6
8859 && (bfd_get_section_by_name
8860 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
8861 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
8864 if (htab
->splt
->size
> 0)
8866 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTREL
, 0))
8869 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_JMPREL
, 0))
8872 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTRELSZ
, 0))
8875 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_PLTGOT
, 0))
8878 if (htab
->is_vxworks
8879 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
8886 /* REL is a relocation in INPUT_BFD that is being copied to OUTPUT_BFD.
8887 Adjust its R_ADDEND field so that it is correct for the output file.
8888 LOCAL_SYMS and LOCAL_SECTIONS are arrays of INPUT_BFD's local symbols
8889 and sections respectively; both use symbol indexes. */
8892 mips_elf_adjust_addend (bfd
*output_bfd
, struct bfd_link_info
*info
,
8893 bfd
*input_bfd
, Elf_Internal_Sym
*local_syms
,
8894 asection
**local_sections
, Elf_Internal_Rela
*rel
)
8896 unsigned int r_type
, r_symndx
;
8897 Elf_Internal_Sym
*sym
;
8900 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
))
8902 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8903 if (r_type
== R_MIPS16_GPREL
8904 || r_type
== R_MIPS_GPREL16
8905 || r_type
== R_MIPS_GPREL32
8906 || r_type
== R_MIPS_LITERAL
)
8908 rel
->r_addend
+= _bfd_get_gp_value (input_bfd
);
8909 rel
->r_addend
-= _bfd_get_gp_value (output_bfd
);
8912 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
8913 sym
= local_syms
+ r_symndx
;
8915 /* Adjust REL's addend to account for section merging. */
8916 if (!info
->relocatable
)
8918 sec
= local_sections
[r_symndx
];
8919 _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
8922 /* This would normally be done by the rela_normal code in elflink.c. */
8923 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8924 rel
->r_addend
+= local_sections
[r_symndx
]->output_offset
;
8928 /* Relocate a MIPS ELF section. */
8931 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
8932 bfd
*input_bfd
, asection
*input_section
,
8933 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
8934 Elf_Internal_Sym
*local_syms
,
8935 asection
**local_sections
)
8937 Elf_Internal_Rela
*rel
;
8938 const Elf_Internal_Rela
*relend
;
8940 bfd_boolean use_saved_addend_p
= FALSE
;
8941 const struct elf_backend_data
*bed
;
8943 bed
= get_elf_backend_data (output_bfd
);
8944 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
8945 for (rel
= relocs
; rel
< relend
; ++rel
)
8949 reloc_howto_type
*howto
;
8950 bfd_boolean cross_mode_jump_p
;
8951 /* TRUE if the relocation is a RELA relocation, rather than a
8953 bfd_boolean rela_relocation_p
= TRUE
;
8954 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8956 unsigned long r_symndx
;
8958 Elf_Internal_Shdr
*symtab_hdr
;
8959 struct elf_link_hash_entry
*h
;
8961 /* Find the relocation howto for this relocation. */
8962 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
8963 NEWABI_P (input_bfd
)
8964 && (MIPS_RELOC_RELA_P
8965 (input_bfd
, input_section
,
8968 r_symndx
= ELF_R_SYM (input_bfd
, rel
->r_info
);
8969 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
8970 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
))
8972 sec
= local_sections
[r_symndx
];
8977 unsigned long extsymoff
;
8980 if (!elf_bad_symtab (input_bfd
))
8981 extsymoff
= symtab_hdr
->sh_info
;
8982 h
= elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
8983 while (h
->root
.type
== bfd_link_hash_indirect
8984 || h
->root
.type
== bfd_link_hash_warning
)
8985 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8988 if (h
->root
.type
== bfd_link_hash_defined
8989 || h
->root
.type
== bfd_link_hash_defweak
)
8990 sec
= h
->root
.u
.def
.section
;
8993 if (sec
!= NULL
&& elf_discarded_section (sec
))
8995 /* For relocs against symbols from removed linkonce sections,
8996 or sections discarded by a linker script, we just want the
8997 section contents zeroed. Avoid any special processing. */
8998 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
9004 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
9006 /* Some 32-bit code uses R_MIPS_64. In particular, people use
9007 64-bit code, but make sure all their addresses are in the
9008 lowermost or uppermost 32-bit section of the 64-bit address
9009 space. Thus, when they use an R_MIPS_64 they mean what is
9010 usually meant by R_MIPS_32, with the exception that the
9011 stored value is sign-extended to 64 bits. */
9012 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
9014 /* On big-endian systems, we need to lie about the position
9016 if (bfd_big_endian (input_bfd
))
9020 if (!use_saved_addend_p
)
9022 /* If these relocations were originally of the REL variety,
9023 we must pull the addend out of the field that will be
9024 relocated. Otherwise, we simply use the contents of the
9026 if (mips_elf_rel_relocation_p (input_bfd
, input_section
,
9029 rela_relocation_p
= FALSE
;
9030 addend
= mips_elf_read_rel_addend (input_bfd
, rel
,
9032 if (hi16_reloc_p (r_type
)
9033 || (got16_reloc_p (r_type
)
9034 && mips_elf_local_relocation_p (input_bfd
, rel
,
9037 if (!mips_elf_add_lo16_rel_addend (input_bfd
, rel
, relend
,
9041 name
= h
->root
.root
.string
;
9043 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
9044 local_syms
+ r_symndx
,
9046 (*_bfd_error_handler
)
9047 (_("%B: Can't find matching LO16 reloc against `%s' for %s at 0x%lx in section `%A'"),
9048 input_bfd
, input_section
, name
, howto
->name
,
9053 addend
<<= howto
->rightshift
;
9056 addend
= rel
->r_addend
;
9057 mips_elf_adjust_addend (output_bfd
, info
, input_bfd
,
9058 local_syms
, local_sections
, rel
);
9061 if (info
->relocatable
)
9063 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
9064 && bfd_big_endian (input_bfd
))
9067 if (!rela_relocation_p
&& rel
->r_addend
)
9069 addend
+= rel
->r_addend
;
9070 if (hi16_reloc_p (r_type
) || got16_reloc_p (r_type
))
9071 addend
= mips_elf_high (addend
);
9072 else if (r_type
== R_MIPS_HIGHER
)
9073 addend
= mips_elf_higher (addend
);
9074 else if (r_type
== R_MIPS_HIGHEST
)
9075 addend
= mips_elf_highest (addend
);
9077 addend
>>= howto
->rightshift
;
9079 /* We use the source mask, rather than the destination
9080 mask because the place to which we are writing will be
9081 source of the addend in the final link. */
9082 addend
&= howto
->src_mask
;
9084 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
9085 /* See the comment above about using R_MIPS_64 in the 32-bit
9086 ABI. Here, we need to update the addend. It would be
9087 possible to get away with just using the R_MIPS_32 reloc
9088 but for endianness. */
9094 if (addend
& ((bfd_vma
) 1 << 31))
9096 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
9103 /* If we don't know that we have a 64-bit type,
9104 do two separate stores. */
9105 if (bfd_big_endian (input_bfd
))
9107 /* Store the sign-bits (which are most significant)
9109 low_bits
= sign_bits
;
9115 high_bits
= sign_bits
;
9117 bfd_put_32 (input_bfd
, low_bits
,
9118 contents
+ rel
->r_offset
);
9119 bfd_put_32 (input_bfd
, high_bits
,
9120 contents
+ rel
->r_offset
+ 4);
9124 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
9125 input_bfd
, input_section
,
9130 /* Go on to the next relocation. */
9134 /* In the N32 and 64-bit ABIs there may be multiple consecutive
9135 relocations for the same offset. In that case we are
9136 supposed to treat the output of each relocation as the addend
9138 if (rel
+ 1 < relend
9139 && rel
->r_offset
== rel
[1].r_offset
9140 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
9141 use_saved_addend_p
= TRUE
;
9143 use_saved_addend_p
= FALSE
;
9145 /* Figure out what value we are supposed to relocate. */
9146 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
9147 input_section
, info
, rel
,
9148 addend
, howto
, local_syms
,
9149 local_sections
, &value
,
9150 &name
, &cross_mode_jump_p
,
9151 use_saved_addend_p
))
9153 case bfd_reloc_continue
:
9154 /* There's nothing to do. */
9157 case bfd_reloc_undefined
:
9158 /* mips_elf_calculate_relocation already called the
9159 undefined_symbol callback. There's no real point in
9160 trying to perform the relocation at this point, so we
9161 just skip ahead to the next relocation. */
9164 case bfd_reloc_notsupported
:
9165 msg
= _("internal error: unsupported relocation error");
9166 info
->callbacks
->warning
9167 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
9170 case bfd_reloc_overflow
:
9171 if (use_saved_addend_p
)
9172 /* Ignore overflow until we reach the last relocation for
9173 a given location. */
9177 struct mips_elf_link_hash_table
*htab
;
9179 htab
= mips_elf_hash_table (info
);
9180 BFD_ASSERT (htab
!= NULL
);
9181 BFD_ASSERT (name
!= NULL
);
9182 if (!htab
->small_data_overflow_reported
9183 && (gprel16_reloc_p (howto
->type
)
9184 || howto
->type
== R_MIPS_LITERAL
))
9186 msg
= _("small-data section exceeds 64KB;"
9187 " lower small-data size limit (see option -G)");
9189 htab
->small_data_overflow_reported
= TRUE
;
9190 (*info
->callbacks
->einfo
) ("%P: %s\n", msg
);
9192 if (! ((*info
->callbacks
->reloc_overflow
)
9193 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
9194 input_bfd
, input_section
, rel
->r_offset
)))
9207 /* If we've got another relocation for the address, keep going
9208 until we reach the last one. */
9209 if (use_saved_addend_p
)
9215 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
9216 /* See the comment above about using R_MIPS_64 in the 32-bit
9217 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
9218 that calculated the right value. Now, however, we
9219 sign-extend the 32-bit result to 64-bits, and store it as a
9220 64-bit value. We are especially generous here in that we
9221 go to extreme lengths to support this usage on systems with
9222 only a 32-bit VMA. */
9228 if (value
& ((bfd_vma
) 1 << 31))
9230 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
9237 /* If we don't know that we have a 64-bit type,
9238 do two separate stores. */
9239 if (bfd_big_endian (input_bfd
))
9241 /* Undo what we did above. */
9243 /* Store the sign-bits (which are most significant)
9245 low_bits
= sign_bits
;
9251 high_bits
= sign_bits
;
9253 bfd_put_32 (input_bfd
, low_bits
,
9254 contents
+ rel
->r_offset
);
9255 bfd_put_32 (input_bfd
, high_bits
,
9256 contents
+ rel
->r_offset
+ 4);
9260 /* Actually perform the relocation. */
9261 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
9262 input_bfd
, input_section
,
9263 contents
, cross_mode_jump_p
))
9270 /* A function that iterates over each entry in la25_stubs and fills
9271 in the code for each one. DATA points to a mips_htab_traverse_info. */
9274 mips_elf_create_la25_stub (void **slot
, void *data
)
9276 struct mips_htab_traverse_info
*hti
;
9277 struct mips_elf_link_hash_table
*htab
;
9278 struct mips_elf_la25_stub
*stub
;
9281 bfd_vma offset
, target
, target_high
, target_low
;
9283 stub
= (struct mips_elf_la25_stub
*) *slot
;
9284 hti
= (struct mips_htab_traverse_info
*) data
;
9285 htab
= mips_elf_hash_table (hti
->info
);
9286 BFD_ASSERT (htab
!= NULL
);
9288 /* Create the section contents, if we haven't already. */
9289 s
= stub
->stub_section
;
9293 loc
= bfd_malloc (s
->size
);
9302 /* Work out where in the section this stub should go. */
9303 offset
= stub
->offset
;
9305 /* Work out the target address. */
9306 target
= (stub
->h
->root
.root
.u
.def
.section
->output_section
->vma
9307 + stub
->h
->root
.root
.u
.def
.section
->output_offset
9308 + stub
->h
->root
.root
.u
.def
.value
);
9309 target_high
= ((target
+ 0x8000) >> 16) & 0xffff;
9310 target_low
= (target
& 0xffff);
9312 if (stub
->stub_section
!= htab
->strampoline
)
9314 /* This is a simple LUI/ADIDU stub. Zero out the beginning
9315 of the section and write the two instructions at the end. */
9316 memset (loc
, 0, offset
);
9318 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
9319 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 4);
9323 /* This is trampoline. */
9325 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
9326 bfd_put_32 (hti
->output_bfd
, LA25_J (target
), loc
+ 4);
9327 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 8);
9328 bfd_put_32 (hti
->output_bfd
, 0, loc
+ 12);
9333 /* If NAME is one of the special IRIX6 symbols defined by the linker,
9334 adjust it appropriately now. */
9337 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
9338 const char *name
, Elf_Internal_Sym
*sym
)
9340 /* The linker script takes care of providing names and values for
9341 these, but we must place them into the right sections. */
9342 static const char* const text_section_symbols
[] = {
9345 "__dso_displacement",
9347 "__program_header_table",
9351 static const char* const data_section_symbols
[] = {
9359 const char* const *p
;
9362 for (i
= 0; i
< 2; ++i
)
9363 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
9366 if (strcmp (*p
, name
) == 0)
9368 /* All of these symbols are given type STT_SECTION by the
9370 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9371 sym
->st_other
= STO_PROTECTED
;
9373 /* The IRIX linker puts these symbols in special sections. */
9375 sym
->st_shndx
= SHN_MIPS_TEXT
;
9377 sym
->st_shndx
= SHN_MIPS_DATA
;
9383 /* Finish up dynamic symbol handling. We set the contents of various
9384 dynamic sections here. */
9387 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
9388 struct bfd_link_info
*info
,
9389 struct elf_link_hash_entry
*h
,
9390 Elf_Internal_Sym
*sym
)
9394 struct mips_got_info
*g
, *gg
;
9397 struct mips_elf_link_hash_table
*htab
;
9398 struct mips_elf_link_hash_entry
*hmips
;
9400 htab
= mips_elf_hash_table (info
);
9401 BFD_ASSERT (htab
!= NULL
);
9402 dynobj
= elf_hash_table (info
)->dynobj
;
9403 hmips
= (struct mips_elf_link_hash_entry
*) h
;
9405 BFD_ASSERT (!htab
->is_vxworks
);
9407 if (h
->plt
.offset
!= MINUS_ONE
&& hmips
->no_fn_stub
)
9409 /* We've decided to create a PLT entry for this symbol. */
9411 bfd_vma header_address
, plt_index
, got_address
;
9412 bfd_vma got_address_high
, got_address_low
, load
;
9413 const bfd_vma
*plt_entry
;
9415 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
9416 BFD_ASSERT (h
->dynindx
!= -1);
9417 BFD_ASSERT (htab
->splt
!= NULL
);
9418 BFD_ASSERT (h
->plt
.offset
<= htab
->splt
->size
);
9419 BFD_ASSERT (!h
->def_regular
);
9421 /* Calculate the address of the PLT header. */
9422 header_address
= (htab
->splt
->output_section
->vma
9423 + htab
->splt
->output_offset
);
9425 /* Calculate the index of the entry. */
9426 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
9427 / htab
->plt_entry_size
);
9429 /* Calculate the address of the .got.plt entry. */
9430 got_address
= (htab
->sgotplt
->output_section
->vma
9431 + htab
->sgotplt
->output_offset
9432 + (2 + plt_index
) * MIPS_ELF_GOT_SIZE (dynobj
));
9433 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
9434 got_address_low
= got_address
& 0xffff;
9436 /* Initially point the .got.plt entry at the PLT header. */
9437 loc
= (htab
->sgotplt
->contents
9438 + (2 + plt_index
) * MIPS_ELF_GOT_SIZE (dynobj
));
9439 if (ABI_64_P (output_bfd
))
9440 bfd_put_64 (output_bfd
, header_address
, loc
);
9442 bfd_put_32 (output_bfd
, header_address
, loc
);
9444 /* Find out where the .plt entry should go. */
9445 loc
= htab
->splt
->contents
+ h
->plt
.offset
;
9447 /* Pick the load opcode. */
9448 load
= MIPS_ELF_LOAD_WORD (output_bfd
);
9450 /* Fill in the PLT entry itself. */
9451 plt_entry
= mips_exec_plt_entry
;
9452 bfd_put_32 (output_bfd
, plt_entry
[0] | got_address_high
, loc
);
9453 bfd_put_32 (output_bfd
, plt_entry
[1] | got_address_low
| load
, loc
+ 4);
9455 if (! LOAD_INTERLOCKS_P (output_bfd
))
9457 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_low
, loc
+ 8);
9458 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9462 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 8);
9463 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_low
, loc
+ 12);
9466 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
9467 mips_elf_output_dynamic_relocation (output_bfd
, htab
->srelplt
,
9468 plt_index
, h
->dynindx
,
9469 R_MIPS_JUMP_SLOT
, got_address
);
9471 /* We distinguish between PLT entries and lazy-binding stubs by
9472 giving the former an st_other value of STO_MIPS_PLT. Set the
9473 flag and leave the value if there are any relocations in the
9474 binary where pointer equality matters. */
9475 sym
->st_shndx
= SHN_UNDEF
;
9476 if (h
->pointer_equality_needed
)
9477 sym
->st_other
= STO_MIPS_PLT
;
9481 else if (h
->plt
.offset
!= MINUS_ONE
)
9483 /* We've decided to create a lazy-binding stub. */
9484 bfd_byte stub
[MIPS_FUNCTION_STUB_BIG_SIZE
];
9486 /* This symbol has a stub. Set it up. */
9488 BFD_ASSERT (h
->dynindx
!= -1);
9490 BFD_ASSERT ((htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
9491 || (h
->dynindx
<= 0xffff));
9493 /* Values up to 2^31 - 1 are allowed. Larger values would cause
9494 sign extension at runtime in the stub, resulting in a negative
9496 if (h
->dynindx
& ~0x7fffffff)
9499 /* Fill the stub. */
9501 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
+ idx
);
9503 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ idx
);
9505 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
9507 bfd_put_32 (output_bfd
, STUB_LUI ((h
->dynindx
>> 16) & 0x7fff),
9511 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ idx
);
9514 /* If a large stub is not required and sign extension is not a
9515 problem, then use legacy code in the stub. */
9516 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
9517 bfd_put_32 (output_bfd
, STUB_ORI (h
->dynindx
& 0xffff), stub
+ idx
);
9518 else if (h
->dynindx
& ~0x7fff)
9519 bfd_put_32 (output_bfd
, STUB_LI16U (h
->dynindx
& 0xffff), stub
+ idx
);
9521 bfd_put_32 (output_bfd
, STUB_LI16S (output_bfd
, h
->dynindx
),
9524 BFD_ASSERT (h
->plt
.offset
<= htab
->sstubs
->size
);
9525 memcpy (htab
->sstubs
->contents
+ h
->plt
.offset
,
9526 stub
, htab
->function_stub_size
);
9528 /* Mark the symbol as undefined. plt.offset != -1 occurs
9529 only for the referenced symbol. */
9530 sym
->st_shndx
= SHN_UNDEF
;
9532 /* The run-time linker uses the st_value field of the symbol
9533 to reset the global offset table entry for this external
9534 to its stub address when unlinking a shared object. */
9535 sym
->st_value
= (htab
->sstubs
->output_section
->vma
9536 + htab
->sstubs
->output_offset
9540 /* If we have a MIPS16 function with a stub, the dynamic symbol must
9541 refer to the stub, since only the stub uses the standard calling
9543 if (h
->dynindx
!= -1 && hmips
->fn_stub
!= NULL
)
9545 BFD_ASSERT (hmips
->need_fn_stub
);
9546 sym
->st_value
= (hmips
->fn_stub
->output_section
->vma
9547 + hmips
->fn_stub
->output_offset
);
9548 sym
->st_size
= hmips
->fn_stub
->size
;
9549 sym
->st_other
= ELF_ST_VISIBILITY (sym
->st_other
);
9552 BFD_ASSERT (h
->dynindx
!= -1
9553 || h
->forced_local
);
9557 BFD_ASSERT (g
!= NULL
);
9559 /* Run through the global symbol table, creating GOT entries for all
9560 the symbols that need them. */
9561 if (hmips
->global_got_area
!= GGA_NONE
)
9566 value
= sym
->st_value
;
9567 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
9568 R_MIPS_GOT16
, info
);
9569 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
9572 if (hmips
->global_got_area
!= GGA_NONE
&& g
->next
&& h
->type
!= STT_TLS
)
9574 struct mips_got_entry e
, *p
;
9580 e
.abfd
= output_bfd
;
9585 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
9588 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
9593 || (elf_hash_table (info
)->dynamic_sections_created
9595 && p
->d
.h
->root
.def_dynamic
9596 && !p
->d
.h
->root
.def_regular
))
9598 /* Create an R_MIPS_REL32 relocation for this entry. Due to
9599 the various compatibility problems, it's easier to mock
9600 up an R_MIPS_32 or R_MIPS_64 relocation and leave
9601 mips_elf_create_dynamic_relocation to calculate the
9602 appropriate addend. */
9603 Elf_Internal_Rela rel
[3];
9605 memset (rel
, 0, sizeof (rel
));
9606 if (ABI_64_P (output_bfd
))
9607 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
9609 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
9610 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
9613 if (! (mips_elf_create_dynamic_relocation
9614 (output_bfd
, info
, rel
,
9615 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
9619 entry
= sym
->st_value
;
9620 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
9625 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
9626 name
= h
->root
.root
.string
;
9627 if (strcmp (name
, "_DYNAMIC") == 0
9628 || h
== elf_hash_table (info
)->hgot
)
9629 sym
->st_shndx
= SHN_ABS
;
9630 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
9631 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
9633 sym
->st_shndx
= SHN_ABS
;
9634 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9637 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
9639 sym
->st_shndx
= SHN_ABS
;
9640 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9641 sym
->st_value
= elf_gp (output_bfd
);
9643 else if (SGI_COMPAT (output_bfd
))
9645 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
9646 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
9648 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9649 sym
->st_other
= STO_PROTECTED
;
9651 sym
->st_shndx
= SHN_MIPS_DATA
;
9653 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
9655 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9656 sym
->st_other
= STO_PROTECTED
;
9657 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
9658 sym
->st_shndx
= SHN_ABS
;
9660 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
9662 if (h
->type
== STT_FUNC
)
9663 sym
->st_shndx
= SHN_MIPS_TEXT
;
9664 else if (h
->type
== STT_OBJECT
)
9665 sym
->st_shndx
= SHN_MIPS_DATA
;
9669 /* Emit a copy reloc, if needed. */
9675 BFD_ASSERT (h
->dynindx
!= -1);
9676 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
9678 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9679 symval
= (h
->root
.u
.def
.section
->output_section
->vma
9680 + h
->root
.u
.def
.section
->output_offset
9681 + h
->root
.u
.def
.value
);
9682 mips_elf_output_dynamic_relocation (output_bfd
, s
, s
->reloc_count
++,
9683 h
->dynindx
, R_MIPS_COPY
, symval
);
9686 /* Handle the IRIX6-specific symbols. */
9687 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
9688 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
9692 if (! mips_elf_hash_table (info
)->use_rld_obj_head
9693 && (strcmp (name
, "__rld_map") == 0
9694 || strcmp (name
, "__RLD_MAP") == 0))
9696 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
9697 BFD_ASSERT (s
!= NULL
);
9698 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
9699 bfd_put_32 (output_bfd
, 0, s
->contents
);
9700 if (mips_elf_hash_table (info
)->rld_value
== 0)
9701 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
9703 else if (mips_elf_hash_table (info
)->use_rld_obj_head
9704 && strcmp (name
, "__rld_obj_head") == 0)
9706 /* IRIX6 does not use a .rld_map section. */
9707 if (IRIX_COMPAT (output_bfd
) == ict_irix5
9708 || IRIX_COMPAT (output_bfd
) == ict_none
)
9709 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
9711 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
9715 /* Keep dynamic MIPS16 symbols odd. This allows the dynamic linker to
9716 treat MIPS16 symbols like any other. */
9717 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
9719 BFD_ASSERT (sym
->st_value
& 1);
9720 sym
->st_other
-= STO_MIPS16
;
9726 /* Likewise, for VxWorks. */
9729 _bfd_mips_vxworks_finish_dynamic_symbol (bfd
*output_bfd
,
9730 struct bfd_link_info
*info
,
9731 struct elf_link_hash_entry
*h
,
9732 Elf_Internal_Sym
*sym
)
9736 struct mips_got_info
*g
;
9737 struct mips_elf_link_hash_table
*htab
;
9738 struct mips_elf_link_hash_entry
*hmips
;
9740 htab
= mips_elf_hash_table (info
);
9741 BFD_ASSERT (htab
!= NULL
);
9742 dynobj
= elf_hash_table (info
)->dynobj
;
9743 hmips
= (struct mips_elf_link_hash_entry
*) h
;
9745 if (h
->plt
.offset
!= (bfd_vma
) -1)
9748 bfd_vma plt_address
, plt_index
, got_address
, got_offset
, branch_offset
;
9749 Elf_Internal_Rela rel
;
9750 static const bfd_vma
*plt_entry
;
9752 BFD_ASSERT (h
->dynindx
!= -1);
9753 BFD_ASSERT (htab
->splt
!= NULL
);
9754 BFD_ASSERT (h
->plt
.offset
<= htab
->splt
->size
);
9756 /* Calculate the address of the .plt entry. */
9757 plt_address
= (htab
->splt
->output_section
->vma
9758 + htab
->splt
->output_offset
9761 /* Calculate the index of the entry. */
9762 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
9763 / htab
->plt_entry_size
);
9765 /* Calculate the address of the .got.plt entry. */
9766 got_address
= (htab
->sgotplt
->output_section
->vma
9767 + htab
->sgotplt
->output_offset
9770 /* Calculate the offset of the .got.plt entry from
9771 _GLOBAL_OFFSET_TABLE_. */
9772 got_offset
= mips_elf_gotplt_index (info
, h
);
9774 /* Calculate the offset for the branch at the start of the PLT
9775 entry. The branch jumps to the beginning of .plt. */
9776 branch_offset
= -(h
->plt
.offset
/ 4 + 1) & 0xffff;
9778 /* Fill in the initial value of the .got.plt entry. */
9779 bfd_put_32 (output_bfd
, plt_address
,
9780 htab
->sgotplt
->contents
+ plt_index
* 4);
9782 /* Find out where the .plt entry should go. */
9783 loc
= htab
->splt
->contents
+ h
->plt
.offset
;
9787 plt_entry
= mips_vxworks_shared_plt_entry
;
9788 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9789 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9793 bfd_vma got_address_high
, got_address_low
;
9795 plt_entry
= mips_vxworks_exec_plt_entry
;
9796 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
9797 got_address_low
= got_address
& 0xffff;
9799 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9800 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9801 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_high
, loc
+ 8);
9802 bfd_put_32 (output_bfd
, plt_entry
[3] | got_address_low
, loc
+ 12);
9803 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9804 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9805 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
9806 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
9808 loc
= (htab
->srelplt2
->contents
9809 + (plt_index
* 3 + 2) * sizeof (Elf32_External_Rela
));
9811 /* Emit a relocation for the .got.plt entry. */
9812 rel
.r_offset
= got_address
;
9813 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9814 rel
.r_addend
= h
->plt
.offset
;
9815 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9817 /* Emit a relocation for the lui of %hi(<.got.plt slot>). */
9818 loc
+= sizeof (Elf32_External_Rela
);
9819 rel
.r_offset
= plt_address
+ 8;
9820 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9821 rel
.r_addend
= got_offset
;
9822 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9824 /* Emit a relocation for the addiu of %lo(<.got.plt slot>). */
9825 loc
+= sizeof (Elf32_External_Rela
);
9827 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9828 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9831 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
9832 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
9833 rel
.r_offset
= got_address
;
9834 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_JUMP_SLOT
);
9836 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9838 if (!h
->def_regular
)
9839 sym
->st_shndx
= SHN_UNDEF
;
9842 BFD_ASSERT (h
->dynindx
!= -1 || h
->forced_local
);
9846 BFD_ASSERT (g
!= NULL
);
9848 /* See if this symbol has an entry in the GOT. */
9849 if (hmips
->global_got_area
!= GGA_NONE
)
9852 Elf_Internal_Rela outrel
;
9856 /* Install the symbol value in the GOT. */
9857 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
9858 R_MIPS_GOT16
, info
);
9859 MIPS_ELF_PUT_WORD (output_bfd
, sym
->st_value
, sgot
->contents
+ offset
);
9861 /* Add a dynamic relocation for it. */
9862 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9863 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
9864 outrel
.r_offset
= (sgot
->output_section
->vma
9865 + sgot
->output_offset
9867 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_32
);
9868 outrel
.r_addend
= 0;
9869 bfd_elf32_swap_reloca_out (dynobj
, &outrel
, loc
);
9872 /* Emit a copy reloc, if needed. */
9875 Elf_Internal_Rela rel
;
9877 BFD_ASSERT (h
->dynindx
!= -1);
9879 rel
.r_offset
= (h
->root
.u
.def
.section
->output_section
->vma
9880 + h
->root
.u
.def
.section
->output_offset
9881 + h
->root
.u
.def
.value
);
9882 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_COPY
);
9884 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
9885 htab
->srelbss
->contents
9886 + (htab
->srelbss
->reloc_count
9887 * sizeof (Elf32_External_Rela
)));
9888 ++htab
->srelbss
->reloc_count
;
9891 /* If this is a mips16 symbol, force the value to be even. */
9892 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
9893 sym
->st_value
&= ~1;
9898 /* Write out a plt0 entry to the beginning of .plt. */
9901 mips_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9904 bfd_vma gotplt_value
, gotplt_value_high
, gotplt_value_low
;
9905 static const bfd_vma
*plt_entry
;
9906 struct mips_elf_link_hash_table
*htab
;
9908 htab
= mips_elf_hash_table (info
);
9909 BFD_ASSERT (htab
!= NULL
);
9911 if (ABI_64_P (output_bfd
))
9912 plt_entry
= mips_n64_exec_plt0_entry
;
9913 else if (ABI_N32_P (output_bfd
))
9914 plt_entry
= mips_n32_exec_plt0_entry
;
9916 plt_entry
= mips_o32_exec_plt0_entry
;
9918 /* Calculate the value of .got.plt. */
9919 gotplt_value
= (htab
->sgotplt
->output_section
->vma
9920 + htab
->sgotplt
->output_offset
);
9921 gotplt_value_high
= ((gotplt_value
+ 0x8000) >> 16) & 0xffff;
9922 gotplt_value_low
= gotplt_value
& 0xffff;
9924 /* The PLT sequence is not safe for N64 if .got.plt's address can
9925 not be loaded in two instructions. */
9926 BFD_ASSERT ((gotplt_value
& ~(bfd_vma
) 0x7fffffff) == 0
9927 || ~(gotplt_value
| 0x7fffffff) == 0);
9929 /* Install the PLT header. */
9930 loc
= htab
->splt
->contents
;
9931 bfd_put_32 (output_bfd
, plt_entry
[0] | gotplt_value_high
, loc
);
9932 bfd_put_32 (output_bfd
, plt_entry
[1] | gotplt_value_low
, loc
+ 4);
9933 bfd_put_32 (output_bfd
, plt_entry
[2] | gotplt_value_low
, loc
+ 8);
9934 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9935 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9936 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9937 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
9938 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
9941 /* Install the PLT header for a VxWorks executable and finalize the
9942 contents of .rela.plt.unloaded. */
9945 mips_vxworks_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9947 Elf_Internal_Rela rela
;
9949 bfd_vma got_value
, got_value_high
, got_value_low
, plt_address
;
9950 static const bfd_vma
*plt_entry
;
9951 struct mips_elf_link_hash_table
*htab
;
9953 htab
= mips_elf_hash_table (info
);
9954 BFD_ASSERT (htab
!= NULL
);
9956 plt_entry
= mips_vxworks_exec_plt0_entry
;
9958 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
9959 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
9960 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
9961 + htab
->root
.hgot
->root
.u
.def
.value
);
9963 got_value_high
= ((got_value
+ 0x8000) >> 16) & 0xffff;
9964 got_value_low
= got_value
& 0xffff;
9966 /* Calculate the address of the PLT header. */
9967 plt_address
= htab
->splt
->output_section
->vma
+ htab
->splt
->output_offset
;
9969 /* Install the PLT header. */
9970 loc
= htab
->splt
->contents
;
9971 bfd_put_32 (output_bfd
, plt_entry
[0] | got_value_high
, loc
);
9972 bfd_put_32 (output_bfd
, plt_entry
[1] | got_value_low
, loc
+ 4);
9973 bfd_put_32 (output_bfd
, plt_entry
[2], loc
+ 8);
9974 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9975 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9976 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9978 /* Output the relocation for the lui of %hi(_GLOBAL_OFFSET_TABLE_). */
9979 loc
= htab
->srelplt2
->contents
;
9980 rela
.r_offset
= plt_address
;
9981 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9983 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9984 loc
+= sizeof (Elf32_External_Rela
);
9986 /* Output the relocation for the following addiu of
9987 %lo(_GLOBAL_OFFSET_TABLE_). */
9989 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9990 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9991 loc
+= sizeof (Elf32_External_Rela
);
9993 /* Fix up the remaining relocations. They may have the wrong
9994 symbol index for _G_O_T_ or _P_L_T_ depending on the order
9995 in which symbols were output. */
9996 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
9998 Elf_Internal_Rela rel
;
10000 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
10001 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
10002 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
10003 loc
+= sizeof (Elf32_External_Rela
);
10005 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
10006 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
10007 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
10008 loc
+= sizeof (Elf32_External_Rela
);
10010 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
10011 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
10012 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
10013 loc
+= sizeof (Elf32_External_Rela
);
10017 /* Install the PLT header for a VxWorks shared library. */
10020 mips_vxworks_finish_shared_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
10023 struct mips_elf_link_hash_table
*htab
;
10025 htab
= mips_elf_hash_table (info
);
10026 BFD_ASSERT (htab
!= NULL
);
10028 /* We just need to copy the entry byte-by-byte. */
10029 for (i
= 0; i
< ARRAY_SIZE (mips_vxworks_shared_plt0_entry
); i
++)
10030 bfd_put_32 (output_bfd
, mips_vxworks_shared_plt0_entry
[i
],
10031 htab
->splt
->contents
+ i
* 4);
10034 /* Finish up the dynamic sections. */
10037 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
10038 struct bfd_link_info
*info
)
10043 struct mips_got_info
*gg
, *g
;
10044 struct mips_elf_link_hash_table
*htab
;
10046 htab
= mips_elf_hash_table (info
);
10047 BFD_ASSERT (htab
!= NULL
);
10049 dynobj
= elf_hash_table (info
)->dynobj
;
10051 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
10054 gg
= htab
->got_info
;
10056 if (elf_hash_table (info
)->dynamic_sections_created
)
10059 int dyn_to_skip
= 0, dyn_skipped
= 0;
10061 BFD_ASSERT (sdyn
!= NULL
);
10062 BFD_ASSERT (gg
!= NULL
);
10064 g
= mips_elf_got_for_ibfd (gg
, output_bfd
);
10065 BFD_ASSERT (g
!= NULL
);
10067 for (b
= sdyn
->contents
;
10068 b
< sdyn
->contents
+ sdyn
->size
;
10069 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
10071 Elf_Internal_Dyn dyn
;
10075 bfd_boolean swap_out_p
;
10077 /* Read in the current dynamic entry. */
10078 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
10080 /* Assume that we're going to modify it and write it out. */
10086 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
10090 BFD_ASSERT (htab
->is_vxworks
);
10091 dyn
.d_un
.d_val
= MIPS_ELF_RELA_SIZE (dynobj
);
10095 /* Rewrite DT_STRSZ. */
10097 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
10102 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
10105 case DT_MIPS_PLTGOT
:
10107 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
10110 case DT_MIPS_RLD_VERSION
:
10111 dyn
.d_un
.d_val
= 1; /* XXX */
10114 case DT_MIPS_FLAGS
:
10115 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
10118 case DT_MIPS_TIME_STAMP
:
10122 dyn
.d_un
.d_val
= t
;
10126 case DT_MIPS_ICHECKSUM
:
10128 swap_out_p
= FALSE
;
10131 case DT_MIPS_IVERSION
:
10133 swap_out_p
= FALSE
;
10136 case DT_MIPS_BASE_ADDRESS
:
10137 s
= output_bfd
->sections
;
10138 BFD_ASSERT (s
!= NULL
);
10139 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
10142 case DT_MIPS_LOCAL_GOTNO
:
10143 dyn
.d_un
.d_val
= g
->local_gotno
;
10146 case DT_MIPS_UNREFEXTNO
:
10147 /* The index into the dynamic symbol table which is the
10148 entry of the first external symbol that is not
10149 referenced within the same object. */
10150 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
10153 case DT_MIPS_GOTSYM
:
10154 if (gg
->global_gotsym
)
10156 dyn
.d_un
.d_val
= gg
->global_gotsym
->dynindx
;
10159 /* In case if we don't have global got symbols we default
10160 to setting DT_MIPS_GOTSYM to the same value as
10161 DT_MIPS_SYMTABNO, so we just fall through. */
10163 case DT_MIPS_SYMTABNO
:
10165 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
10166 s
= bfd_get_section_by_name (output_bfd
, name
);
10167 BFD_ASSERT (s
!= NULL
);
10169 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
10172 case DT_MIPS_HIPAGENO
:
10173 dyn
.d_un
.d_val
= g
->local_gotno
- htab
->reserved_gotno
;
10176 case DT_MIPS_RLD_MAP
:
10177 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
10180 case DT_MIPS_OPTIONS
:
10181 s
= (bfd_get_section_by_name
10182 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
10183 dyn
.d_un
.d_ptr
= s
->vma
;
10187 BFD_ASSERT (htab
->is_vxworks
);
10188 /* The count does not include the JUMP_SLOT relocations. */
10190 dyn
.d_un
.d_val
-= htab
->srelplt
->size
;
10194 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10195 if (htab
->is_vxworks
)
10196 dyn
.d_un
.d_val
= DT_RELA
;
10198 dyn
.d_un
.d_val
= DT_REL
;
10202 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10203 dyn
.d_un
.d_val
= htab
->srelplt
->size
;
10207 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10208 dyn
.d_un
.d_ptr
= (htab
->srelplt
->output_section
->vma
10209 + htab
->srelplt
->output_offset
);
10213 /* If we didn't need any text relocations after all, delete
10214 the dynamic tag. */
10215 if (!(info
->flags
& DF_TEXTREL
))
10217 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
10218 swap_out_p
= FALSE
;
10223 /* If we didn't need any text relocations after all, clear
10224 DF_TEXTREL from DT_FLAGS. */
10225 if (!(info
->flags
& DF_TEXTREL
))
10226 dyn
.d_un
.d_val
&= ~DF_TEXTREL
;
10228 swap_out_p
= FALSE
;
10232 swap_out_p
= FALSE
;
10233 if (htab
->is_vxworks
10234 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
10239 if (swap_out_p
|| dyn_skipped
)
10240 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
10241 (dynobj
, &dyn
, b
- dyn_skipped
);
10245 dyn_skipped
+= dyn_to_skip
;
10250 /* Wipe out any trailing entries if we shifted down a dynamic tag. */
10251 if (dyn_skipped
> 0)
10252 memset (b
- dyn_skipped
, 0, dyn_skipped
);
10255 if (sgot
!= NULL
&& sgot
->size
> 0
10256 && !bfd_is_abs_section (sgot
->output_section
))
10258 if (htab
->is_vxworks
)
10260 /* The first entry of the global offset table points to the
10261 ".dynamic" section. The second is initialized by the
10262 loader and contains the shared library identifier.
10263 The third is also initialized by the loader and points
10264 to the lazy resolution stub. */
10265 MIPS_ELF_PUT_WORD (output_bfd
,
10266 sdyn
->output_offset
+ sdyn
->output_section
->vma
,
10268 MIPS_ELF_PUT_WORD (output_bfd
, 0,
10269 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
10270 MIPS_ELF_PUT_WORD (output_bfd
, 0,
10272 + 2 * MIPS_ELF_GOT_SIZE (output_bfd
));
10276 /* The first entry of the global offset table will be filled at
10277 runtime. The second entry will be used by some runtime loaders.
10278 This isn't the case of IRIX rld. */
10279 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
10280 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
10281 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
10284 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
10285 = MIPS_ELF_GOT_SIZE (output_bfd
);
10288 /* Generate dynamic relocations for the non-primary gots. */
10289 if (gg
!= NULL
&& gg
->next
)
10291 Elf_Internal_Rela rel
[3];
10292 bfd_vma addend
= 0;
10294 memset (rel
, 0, sizeof (rel
));
10295 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
10297 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
10299 bfd_vma got_index
= g
->next
->local_gotno
+ g
->next
->global_gotno
10300 + g
->next
->tls_gotno
;
10302 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
10303 + got_index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
10304 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
10306 + got_index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
10308 if (! info
->shared
)
10311 while (got_index
< g
->assigned_gotno
)
10313 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
10314 = got_index
++ * MIPS_ELF_GOT_SIZE (output_bfd
);
10315 if (!(mips_elf_create_dynamic_relocation
10316 (output_bfd
, info
, rel
, NULL
,
10317 bfd_abs_section_ptr
,
10318 0, &addend
, sgot
)))
10320 BFD_ASSERT (addend
== 0);
10325 /* The generation of dynamic relocations for the non-primary gots
10326 adds more dynamic relocations. We cannot count them until
10329 if (elf_hash_table (info
)->dynamic_sections_created
)
10332 bfd_boolean swap_out_p
;
10334 BFD_ASSERT (sdyn
!= NULL
);
10336 for (b
= sdyn
->contents
;
10337 b
< sdyn
->contents
+ sdyn
->size
;
10338 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
10340 Elf_Internal_Dyn dyn
;
10343 /* Read in the current dynamic entry. */
10344 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
10346 /* Assume that we're going to modify it and write it out. */
10352 /* Reduce DT_RELSZ to account for any relocations we
10353 decided not to make. This is for the n64 irix rld,
10354 which doesn't seem to apply any relocations if there
10355 are trailing null entries. */
10356 s
= mips_elf_rel_dyn_section (info
, FALSE
);
10357 dyn
.d_un
.d_val
= (s
->reloc_count
10358 * (ABI_64_P (output_bfd
)
10359 ? sizeof (Elf64_Mips_External_Rel
)
10360 : sizeof (Elf32_External_Rel
)));
10361 /* Adjust the section size too. Tools like the prelinker
10362 can reasonably expect the values to the same. */
10363 elf_section_data (s
->output_section
)->this_hdr
.sh_size
10368 swap_out_p
= FALSE
;
10373 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
10380 Elf32_compact_rel cpt
;
10382 if (SGI_COMPAT (output_bfd
))
10384 /* Write .compact_rel section out. */
10385 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
10389 cpt
.num
= s
->reloc_count
;
10391 cpt
.offset
= (s
->output_section
->filepos
10392 + sizeof (Elf32_External_compact_rel
));
10395 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
10396 ((Elf32_External_compact_rel
*)
10399 /* Clean up a dummy stub function entry in .text. */
10400 if (htab
->sstubs
!= NULL
)
10402 file_ptr dummy_offset
;
10404 BFD_ASSERT (htab
->sstubs
->size
>= htab
->function_stub_size
);
10405 dummy_offset
= htab
->sstubs
->size
- htab
->function_stub_size
;
10406 memset (htab
->sstubs
->contents
+ dummy_offset
, 0,
10407 htab
->function_stub_size
);
10412 /* The psABI says that the dynamic relocations must be sorted in
10413 increasing order of r_symndx. The VxWorks EABI doesn't require
10414 this, and because the code below handles REL rather than RELA
10415 relocations, using it for VxWorks would be outright harmful. */
10416 if (!htab
->is_vxworks
)
10418 s
= mips_elf_rel_dyn_section (info
, FALSE
);
10420 && s
->size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
10422 reldyn_sorting_bfd
= output_bfd
;
10424 if (ABI_64_P (output_bfd
))
10425 qsort ((Elf64_External_Rel
*) s
->contents
+ 1,
10426 s
->reloc_count
- 1, sizeof (Elf64_Mips_External_Rel
),
10427 sort_dynamic_relocs_64
);
10429 qsort ((Elf32_External_Rel
*) s
->contents
+ 1,
10430 s
->reloc_count
- 1, sizeof (Elf32_External_Rel
),
10431 sort_dynamic_relocs
);
10436 if (htab
->splt
&& htab
->splt
->size
> 0)
10438 if (htab
->is_vxworks
)
10441 mips_vxworks_finish_shared_plt (output_bfd
, info
);
10443 mips_vxworks_finish_exec_plt (output_bfd
, info
);
10447 BFD_ASSERT (!info
->shared
);
10448 mips_finish_exec_plt (output_bfd
, info
);
10455 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
10458 mips_set_isa_flags (bfd
*abfd
)
10462 switch (bfd_get_mach (abfd
))
10465 case bfd_mach_mips3000
:
10466 val
= E_MIPS_ARCH_1
;
10469 case bfd_mach_mips3900
:
10470 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
10473 case bfd_mach_mips6000
:
10474 val
= E_MIPS_ARCH_2
;
10477 case bfd_mach_mips4000
:
10478 case bfd_mach_mips4300
:
10479 case bfd_mach_mips4400
:
10480 case bfd_mach_mips4600
:
10481 val
= E_MIPS_ARCH_3
;
10484 case bfd_mach_mips4010
:
10485 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
10488 case bfd_mach_mips4100
:
10489 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
10492 case bfd_mach_mips4111
:
10493 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
10496 case bfd_mach_mips4120
:
10497 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
10500 case bfd_mach_mips4650
:
10501 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
10504 case bfd_mach_mips5400
:
10505 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
10508 case bfd_mach_mips5500
:
10509 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
10512 case bfd_mach_mips9000
:
10513 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_9000
;
10516 case bfd_mach_mips5000
:
10517 case bfd_mach_mips7000
:
10518 case bfd_mach_mips8000
:
10519 case bfd_mach_mips10000
:
10520 case bfd_mach_mips12000
:
10521 case bfd_mach_mips14000
:
10522 case bfd_mach_mips16000
:
10523 val
= E_MIPS_ARCH_4
;
10526 case bfd_mach_mips5
:
10527 val
= E_MIPS_ARCH_5
;
10530 case bfd_mach_mips_loongson_2e
:
10531 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2E
;
10534 case bfd_mach_mips_loongson_2f
:
10535 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2F
;
10538 case bfd_mach_mips_sb1
:
10539 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
10542 case bfd_mach_mips_octeon
:
10543 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON
;
10546 case bfd_mach_mips_xlr
:
10547 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_XLR
;
10550 case bfd_mach_mipsisa32
:
10551 val
= E_MIPS_ARCH_32
;
10554 case bfd_mach_mipsisa64
:
10555 val
= E_MIPS_ARCH_64
;
10558 case bfd_mach_mipsisa32r2
:
10559 val
= E_MIPS_ARCH_32R2
;
10562 case bfd_mach_mipsisa64r2
:
10563 val
= E_MIPS_ARCH_64R2
;
10566 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
10567 elf_elfheader (abfd
)->e_flags
|= val
;
10572 /* The final processing done just before writing out a MIPS ELF object
10573 file. This gets the MIPS architecture right based on the machine
10574 number. This is used by both the 32-bit and the 64-bit ABI. */
10577 _bfd_mips_elf_final_write_processing (bfd
*abfd
,
10578 bfd_boolean linker ATTRIBUTE_UNUSED
)
10581 Elf_Internal_Shdr
**hdrpp
;
10585 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
10586 is nonzero. This is for compatibility with old objects, which used
10587 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
10588 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
10589 mips_set_isa_flags (abfd
);
10591 /* Set the sh_info field for .gptab sections and other appropriate
10592 info for each special section. */
10593 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
10594 i
< elf_numsections (abfd
);
10597 switch ((*hdrpp
)->sh_type
)
10599 case SHT_MIPS_MSYM
:
10600 case SHT_MIPS_LIBLIST
:
10601 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
10603 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10606 case SHT_MIPS_GPTAB
:
10607 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
10608 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
10609 BFD_ASSERT (name
!= NULL
10610 && CONST_STRNEQ (name
, ".gptab."));
10611 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
10612 BFD_ASSERT (sec
!= NULL
);
10613 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
10616 case SHT_MIPS_CONTENT
:
10617 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
10618 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
10619 BFD_ASSERT (name
!= NULL
10620 && CONST_STRNEQ (name
, ".MIPS.content"));
10621 sec
= bfd_get_section_by_name (abfd
,
10622 name
+ sizeof ".MIPS.content" - 1);
10623 BFD_ASSERT (sec
!= NULL
);
10624 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10627 case SHT_MIPS_SYMBOL_LIB
:
10628 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
10630 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10631 sec
= bfd_get_section_by_name (abfd
, ".liblist");
10633 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
10636 case SHT_MIPS_EVENTS
:
10637 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
10638 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
10639 BFD_ASSERT (name
!= NULL
);
10640 if (CONST_STRNEQ (name
, ".MIPS.events"))
10641 sec
= bfd_get_section_by_name (abfd
,
10642 name
+ sizeof ".MIPS.events" - 1);
10645 BFD_ASSERT (CONST_STRNEQ (name
, ".MIPS.post_rel"));
10646 sec
= bfd_get_section_by_name (abfd
,
10648 + sizeof ".MIPS.post_rel" - 1));
10650 BFD_ASSERT (sec
!= NULL
);
10651 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10658 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
10662 _bfd_mips_elf_additional_program_headers (bfd
*abfd
,
10663 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
10668 /* See if we need a PT_MIPS_REGINFO segment. */
10669 s
= bfd_get_section_by_name (abfd
, ".reginfo");
10670 if (s
&& (s
->flags
& SEC_LOAD
))
10673 /* See if we need a PT_MIPS_OPTIONS segment. */
10674 if (IRIX_COMPAT (abfd
) == ict_irix6
10675 && bfd_get_section_by_name (abfd
,
10676 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
10679 /* See if we need a PT_MIPS_RTPROC segment. */
10680 if (IRIX_COMPAT (abfd
) == ict_irix5
10681 && bfd_get_section_by_name (abfd
, ".dynamic")
10682 && bfd_get_section_by_name (abfd
, ".mdebug"))
10685 /* Allocate a PT_NULL header in dynamic objects. See
10686 _bfd_mips_elf_modify_segment_map for details. */
10687 if (!SGI_COMPAT (abfd
)
10688 && bfd_get_section_by_name (abfd
, ".dynamic"))
10694 /* Modify the segment map for an IRIX5 executable. */
10697 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
10698 struct bfd_link_info
*info
)
10701 struct elf_segment_map
*m
, **pm
;
10704 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
10706 s
= bfd_get_section_by_name (abfd
, ".reginfo");
10707 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
10709 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
10710 if (m
->p_type
== PT_MIPS_REGINFO
)
10715 m
= bfd_zalloc (abfd
, amt
);
10719 m
->p_type
= PT_MIPS_REGINFO
;
10721 m
->sections
[0] = s
;
10723 /* We want to put it after the PHDR and INTERP segments. */
10724 pm
= &elf_tdata (abfd
)->segment_map
;
10726 && ((*pm
)->p_type
== PT_PHDR
10727 || (*pm
)->p_type
== PT_INTERP
))
10735 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
10736 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
10737 PT_MIPS_OPTIONS segment immediately following the program header
10739 if (NEWABI_P (abfd
)
10740 /* On non-IRIX6 new abi, we'll have already created a segment
10741 for this section, so don't create another. I'm not sure this
10742 is not also the case for IRIX 6, but I can't test it right
10744 && IRIX_COMPAT (abfd
) == ict_irix6
)
10746 for (s
= abfd
->sections
; s
; s
= s
->next
)
10747 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
10752 struct elf_segment_map
*options_segment
;
10754 pm
= &elf_tdata (abfd
)->segment_map
;
10756 && ((*pm
)->p_type
== PT_PHDR
10757 || (*pm
)->p_type
== PT_INTERP
))
10760 if (*pm
== NULL
|| (*pm
)->p_type
!= PT_MIPS_OPTIONS
)
10762 amt
= sizeof (struct elf_segment_map
);
10763 options_segment
= bfd_zalloc (abfd
, amt
);
10764 options_segment
->next
= *pm
;
10765 options_segment
->p_type
= PT_MIPS_OPTIONS
;
10766 options_segment
->p_flags
= PF_R
;
10767 options_segment
->p_flags_valid
= TRUE
;
10768 options_segment
->count
= 1;
10769 options_segment
->sections
[0] = s
;
10770 *pm
= options_segment
;
10776 if (IRIX_COMPAT (abfd
) == ict_irix5
)
10778 /* If there are .dynamic and .mdebug sections, we make a room
10779 for the RTPROC header. FIXME: Rewrite without section names. */
10780 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
10781 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
10782 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
10784 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
10785 if (m
->p_type
== PT_MIPS_RTPROC
)
10790 m
= bfd_zalloc (abfd
, amt
);
10794 m
->p_type
= PT_MIPS_RTPROC
;
10796 s
= bfd_get_section_by_name (abfd
, ".rtproc");
10801 m
->p_flags_valid
= 1;
10806 m
->sections
[0] = s
;
10809 /* We want to put it after the DYNAMIC segment. */
10810 pm
= &elf_tdata (abfd
)->segment_map
;
10811 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
10821 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
10822 .dynstr, .dynsym, and .hash sections, and everything in
10824 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
10826 if ((*pm
)->p_type
== PT_DYNAMIC
)
10829 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
10831 /* For a normal mips executable the permissions for the PT_DYNAMIC
10832 segment are read, write and execute. We do that here since
10833 the code in elf.c sets only the read permission. This matters
10834 sometimes for the dynamic linker. */
10835 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
10837 m
->p_flags
= PF_R
| PF_W
| PF_X
;
10838 m
->p_flags_valid
= 1;
10841 /* GNU/Linux binaries do not need the extended PT_DYNAMIC section.
10842 glibc's dynamic linker has traditionally derived the number of
10843 tags from the p_filesz field, and sometimes allocates stack
10844 arrays of that size. An overly-big PT_DYNAMIC segment can
10845 be actively harmful in such cases. Making PT_DYNAMIC contain
10846 other sections can also make life hard for the prelinker,
10847 which might move one of the other sections to a different
10848 PT_LOAD segment. */
10849 if (SGI_COMPAT (abfd
)
10852 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
10854 static const char *sec_names
[] =
10856 ".dynamic", ".dynstr", ".dynsym", ".hash"
10860 struct elf_segment_map
*n
;
10862 low
= ~(bfd_vma
) 0;
10864 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
10866 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
10867 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
10874 if (high
< s
->vma
+ sz
)
10875 high
= s
->vma
+ sz
;
10880 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10881 if ((s
->flags
& SEC_LOAD
) != 0
10883 && s
->vma
+ s
->size
<= high
)
10886 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
10887 n
= bfd_zalloc (abfd
, amt
);
10894 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10896 if ((s
->flags
& SEC_LOAD
) != 0
10898 && s
->vma
+ s
->size
<= high
)
10900 n
->sections
[i
] = s
;
10909 /* Allocate a spare program header in dynamic objects so that tools
10910 like the prelinker can add an extra PT_LOAD entry.
10912 If the prelinker needs to make room for a new PT_LOAD entry, its
10913 standard procedure is to move the first (read-only) sections into
10914 the new (writable) segment. However, the MIPS ABI requires
10915 .dynamic to be in a read-only segment, and the section will often
10916 start within sizeof (ElfNN_Phdr) bytes of the last program header.
10918 Although the prelinker could in principle move .dynamic to a
10919 writable segment, it seems better to allocate a spare program
10920 header instead, and avoid the need to move any sections.
10921 There is a long tradition of allocating spare dynamic tags,
10922 so allocating a spare program header seems like a natural
10925 If INFO is NULL, we may be copying an already prelinked binary
10926 with objcopy or strip, so do not add this header. */
10928 && !SGI_COMPAT (abfd
)
10929 && bfd_get_section_by_name (abfd
, ".dynamic"))
10931 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
10932 if ((*pm
)->p_type
== PT_NULL
)
10936 m
= bfd_zalloc (abfd
, sizeof (*m
));
10940 m
->p_type
= PT_NULL
;
10948 /* Return the section that should be marked against GC for a given
10952 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
10953 struct bfd_link_info
*info
,
10954 Elf_Internal_Rela
*rel
,
10955 struct elf_link_hash_entry
*h
,
10956 Elf_Internal_Sym
*sym
)
10958 /* ??? Do mips16 stub sections need to be handled special? */
10961 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
10963 case R_MIPS_GNU_VTINHERIT
:
10964 case R_MIPS_GNU_VTENTRY
:
10968 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
10971 /* Update the got entry reference counts for the section being removed. */
10974 _bfd_mips_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
10975 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
10976 asection
*sec ATTRIBUTE_UNUSED
,
10977 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
10980 Elf_Internal_Shdr
*symtab_hdr
;
10981 struct elf_link_hash_entry
**sym_hashes
;
10982 bfd_signed_vma
*local_got_refcounts
;
10983 const Elf_Internal_Rela
*rel
, *relend
;
10984 unsigned long r_symndx
;
10985 struct elf_link_hash_entry
*h
;
10987 if (info
->relocatable
)
10990 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
10991 sym_hashes
= elf_sym_hashes (abfd
);
10992 local_got_refcounts
= elf_local_got_refcounts (abfd
);
10994 relend
= relocs
+ sec
->reloc_count
;
10995 for (rel
= relocs
; rel
< relend
; rel
++)
10996 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
10998 case R_MIPS16_GOT16
:
10999 case R_MIPS16_CALL16
:
11001 case R_MIPS_CALL16
:
11002 case R_MIPS_CALL_HI16
:
11003 case R_MIPS_CALL_LO16
:
11004 case R_MIPS_GOT_HI16
:
11005 case R_MIPS_GOT_LO16
:
11006 case R_MIPS_GOT_DISP
:
11007 case R_MIPS_GOT_PAGE
:
11008 case R_MIPS_GOT_OFST
:
11009 /* ??? It would seem that the existing MIPS code does no sort
11010 of reference counting or whatnot on its GOT and PLT entries,
11011 so it is not possible to garbage collect them at this time. */
11022 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
11023 hiding the old indirect symbol. Process additional relocation
11024 information. Also called for weakdefs, in which case we just let
11025 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
11028 _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
11029 struct elf_link_hash_entry
*dir
,
11030 struct elf_link_hash_entry
*ind
)
11032 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
11034 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
11036 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
11037 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
11038 /* Any absolute non-dynamic relocations against an indirect or weak
11039 definition will be against the target symbol. */
11040 if (indmips
->has_static_relocs
)
11041 dirmips
->has_static_relocs
= TRUE
;
11043 if (ind
->root
.type
!= bfd_link_hash_indirect
)
11046 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
11047 if (indmips
->readonly_reloc
)
11048 dirmips
->readonly_reloc
= TRUE
;
11049 if (indmips
->no_fn_stub
)
11050 dirmips
->no_fn_stub
= TRUE
;
11051 if (indmips
->fn_stub
)
11053 dirmips
->fn_stub
= indmips
->fn_stub
;
11054 indmips
->fn_stub
= NULL
;
11056 if (indmips
->need_fn_stub
)
11058 dirmips
->need_fn_stub
= TRUE
;
11059 indmips
->need_fn_stub
= FALSE
;
11061 if (indmips
->call_stub
)
11063 dirmips
->call_stub
= indmips
->call_stub
;
11064 indmips
->call_stub
= NULL
;
11066 if (indmips
->call_fp_stub
)
11068 dirmips
->call_fp_stub
= indmips
->call_fp_stub
;
11069 indmips
->call_fp_stub
= NULL
;
11071 if (indmips
->global_got_area
< dirmips
->global_got_area
)
11072 dirmips
->global_got_area
= indmips
->global_got_area
;
11073 if (indmips
->global_got_area
< GGA_NONE
)
11074 indmips
->global_got_area
= GGA_NONE
;
11075 if (indmips
->has_nonpic_branches
)
11076 dirmips
->has_nonpic_branches
= TRUE
;
11078 if (dirmips
->tls_type
== 0)
11079 dirmips
->tls_type
= indmips
->tls_type
;
11082 #define PDR_SIZE 32
11085 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
11086 struct bfd_link_info
*info
)
11089 bfd_boolean ret
= FALSE
;
11090 unsigned char *tdata
;
11093 o
= bfd_get_section_by_name (abfd
, ".pdr");
11098 if (o
->size
% PDR_SIZE
!= 0)
11100 if (o
->output_section
!= NULL
11101 && bfd_is_abs_section (o
->output_section
))
11104 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
11108 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
11109 info
->keep_memory
);
11116 cookie
->rel
= cookie
->rels
;
11117 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
11119 for (i
= 0, skip
= 0; i
< o
->size
/ PDR_SIZE
; i
++)
11121 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
11130 mips_elf_section_data (o
)->u
.tdata
= tdata
;
11131 o
->size
-= skip
* PDR_SIZE
;
11137 if (! info
->keep_memory
)
11138 free (cookie
->rels
);
11144 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
11146 if (strcmp (sec
->name
, ".pdr") == 0)
11152 _bfd_mips_elf_write_section (bfd
*output_bfd
,
11153 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
11154 asection
*sec
, bfd_byte
*contents
)
11156 bfd_byte
*to
, *from
, *end
;
11159 if (strcmp (sec
->name
, ".pdr") != 0)
11162 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
11166 end
= contents
+ sec
->size
;
11167 for (from
= contents
, i
= 0;
11169 from
+= PDR_SIZE
, i
++)
11171 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
11174 memcpy (to
, from
, PDR_SIZE
);
11177 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
11178 sec
->output_offset
, sec
->size
);
11182 /* MIPS ELF uses a special find_nearest_line routine in order the
11183 handle the ECOFF debugging information. */
11185 struct mips_elf_find_line
11187 struct ecoff_debug_info d
;
11188 struct ecoff_find_line i
;
11192 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asection
*section
,
11193 asymbol
**symbols
, bfd_vma offset
,
11194 const char **filename_ptr
,
11195 const char **functionname_ptr
,
11196 unsigned int *line_ptr
)
11200 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
11201 filename_ptr
, functionname_ptr
,
11205 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
11206 filename_ptr
, functionname_ptr
,
11207 line_ptr
, ABI_64_P (abfd
) ? 8 : 0,
11208 &elf_tdata (abfd
)->dwarf2_find_line_info
))
11211 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
11214 flagword origflags
;
11215 struct mips_elf_find_line
*fi
;
11216 const struct ecoff_debug_swap
* const swap
=
11217 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
11219 /* If we are called during a link, mips_elf_final_link may have
11220 cleared the SEC_HAS_CONTENTS field. We force it back on here
11221 if appropriate (which it normally will be). */
11222 origflags
= msec
->flags
;
11223 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
11224 msec
->flags
|= SEC_HAS_CONTENTS
;
11226 fi
= elf_tdata (abfd
)->find_line_info
;
11229 bfd_size_type external_fdr_size
;
11232 struct fdr
*fdr_ptr
;
11233 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
11235 fi
= bfd_zalloc (abfd
, amt
);
11238 msec
->flags
= origflags
;
11242 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
11244 msec
->flags
= origflags
;
11248 /* Swap in the FDR information. */
11249 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
11250 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
11251 if (fi
->d
.fdr
== NULL
)
11253 msec
->flags
= origflags
;
11256 external_fdr_size
= swap
->external_fdr_size
;
11257 fdr_ptr
= fi
->d
.fdr
;
11258 fraw_src
= (char *) fi
->d
.external_fdr
;
11259 fraw_end
= (fraw_src
11260 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
11261 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
11262 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
11264 elf_tdata (abfd
)->find_line_info
= fi
;
11266 /* Note that we don't bother to ever free this information.
11267 find_nearest_line is either called all the time, as in
11268 objdump -l, so the information should be saved, or it is
11269 rarely called, as in ld error messages, so the memory
11270 wasted is unimportant. Still, it would probably be a
11271 good idea for free_cached_info to throw it away. */
11274 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
11275 &fi
->i
, filename_ptr
, functionname_ptr
,
11278 msec
->flags
= origflags
;
11282 msec
->flags
= origflags
;
11285 /* Fall back on the generic ELF find_nearest_line routine. */
11287 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
11288 filename_ptr
, functionname_ptr
,
11293 _bfd_mips_elf_find_inliner_info (bfd
*abfd
,
11294 const char **filename_ptr
,
11295 const char **functionname_ptr
,
11296 unsigned int *line_ptr
)
11299 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
11300 functionname_ptr
, line_ptr
,
11301 & elf_tdata (abfd
)->dwarf2_find_line_info
);
11306 /* When are writing out the .options or .MIPS.options section,
11307 remember the bytes we are writing out, so that we can install the
11308 GP value in the section_processing routine. */
11311 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
11312 const void *location
,
11313 file_ptr offset
, bfd_size_type count
)
11315 if (MIPS_ELF_OPTIONS_SECTION_NAME_P (section
->name
))
11319 if (elf_section_data (section
) == NULL
)
11321 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
11322 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
11323 if (elf_section_data (section
) == NULL
)
11326 c
= mips_elf_section_data (section
)->u
.tdata
;
11329 c
= bfd_zalloc (abfd
, section
->size
);
11332 mips_elf_section_data (section
)->u
.tdata
= c
;
11335 memcpy (c
+ offset
, location
, count
);
11338 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
11342 /* This is almost identical to bfd_generic_get_... except that some
11343 MIPS relocations need to be handled specially. Sigh. */
11346 _bfd_elf_mips_get_relocated_section_contents
11348 struct bfd_link_info
*link_info
,
11349 struct bfd_link_order
*link_order
,
11351 bfd_boolean relocatable
,
11354 /* Get enough memory to hold the stuff */
11355 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
11356 asection
*input_section
= link_order
->u
.indirect
.section
;
11359 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
11360 arelent
**reloc_vector
= NULL
;
11363 if (reloc_size
< 0)
11366 reloc_vector
= bfd_malloc (reloc_size
);
11367 if (reloc_vector
== NULL
&& reloc_size
!= 0)
11370 /* read in the section */
11371 sz
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
11372 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0, sz
))
11375 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
11379 if (reloc_count
< 0)
11382 if (reloc_count
> 0)
11387 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
11390 struct bfd_hash_entry
*h
;
11391 struct bfd_link_hash_entry
*lh
;
11392 /* Skip all this stuff if we aren't mixing formats. */
11393 if (abfd
&& input_bfd
11394 && abfd
->xvec
== input_bfd
->xvec
)
11398 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
11399 lh
= (struct bfd_link_hash_entry
*) h
;
11406 case bfd_link_hash_undefined
:
11407 case bfd_link_hash_undefweak
:
11408 case bfd_link_hash_common
:
11411 case bfd_link_hash_defined
:
11412 case bfd_link_hash_defweak
:
11414 gp
= lh
->u
.def
.value
;
11416 case bfd_link_hash_indirect
:
11417 case bfd_link_hash_warning
:
11419 /* @@FIXME ignoring warning for now */
11421 case bfd_link_hash_new
:
11430 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
11432 char *error_message
= NULL
;
11433 bfd_reloc_status_type r
;
11435 /* Specific to MIPS: Deal with relocation types that require
11436 knowing the gp of the output bfd. */
11437 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
11439 /* If we've managed to find the gp and have a special
11440 function for the relocation then go ahead, else default
11441 to the generic handling. */
11443 && (*parent
)->howto
->special_function
11444 == _bfd_mips_elf32_gprel16_reloc
)
11445 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
11446 input_section
, relocatable
,
11449 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
11451 relocatable
? abfd
: NULL
,
11456 asection
*os
= input_section
->output_section
;
11458 /* A partial link, so keep the relocs */
11459 os
->orelocation
[os
->reloc_count
] = *parent
;
11463 if (r
!= bfd_reloc_ok
)
11467 case bfd_reloc_undefined
:
11468 if (!((*link_info
->callbacks
->undefined_symbol
)
11469 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
11470 input_bfd
, input_section
, (*parent
)->address
, TRUE
)))
11473 case bfd_reloc_dangerous
:
11474 BFD_ASSERT (error_message
!= NULL
);
11475 if (!((*link_info
->callbacks
->reloc_dangerous
)
11476 (link_info
, error_message
, input_bfd
, input_section
,
11477 (*parent
)->address
)))
11480 case bfd_reloc_overflow
:
11481 if (!((*link_info
->callbacks
->reloc_overflow
)
11483 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
11484 (*parent
)->howto
->name
, (*parent
)->addend
,
11485 input_bfd
, input_section
, (*parent
)->address
)))
11488 case bfd_reloc_outofrange
:
11497 if (reloc_vector
!= NULL
)
11498 free (reloc_vector
);
11502 if (reloc_vector
!= NULL
)
11503 free (reloc_vector
);
11507 /* Create a MIPS ELF linker hash table. */
11509 struct bfd_link_hash_table
*
11510 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
11512 struct mips_elf_link_hash_table
*ret
;
11513 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
11515 ret
= bfd_malloc (amt
);
11519 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
11520 mips_elf_link_hash_newfunc
,
11521 sizeof (struct mips_elf_link_hash_entry
),
11529 /* We no longer use this. */
11530 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
11531 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
11533 ret
->procedure_count
= 0;
11534 ret
->compact_rel_size
= 0;
11535 ret
->use_rld_obj_head
= FALSE
;
11536 ret
->rld_value
= 0;
11537 ret
->mips16_stubs_seen
= FALSE
;
11538 ret
->use_plts_and_copy_relocs
= FALSE
;
11539 ret
->is_vxworks
= FALSE
;
11540 ret
->small_data_overflow_reported
= FALSE
;
11541 ret
->srelbss
= NULL
;
11542 ret
->sdynbss
= NULL
;
11543 ret
->srelplt
= NULL
;
11544 ret
->srelplt2
= NULL
;
11545 ret
->sgotplt
= NULL
;
11547 ret
->sstubs
= NULL
;
11549 ret
->got_info
= NULL
;
11550 ret
->plt_header_size
= 0;
11551 ret
->plt_entry_size
= 0;
11552 ret
->lazy_stub_count
= 0;
11553 ret
->function_stub_size
= 0;
11554 ret
->strampoline
= NULL
;
11555 ret
->la25_stubs
= NULL
;
11556 ret
->add_stub_section
= NULL
;
11558 return &ret
->root
.root
;
11561 /* Likewise, but indicate that the target is VxWorks. */
11563 struct bfd_link_hash_table
*
11564 _bfd_mips_vxworks_link_hash_table_create (bfd
*abfd
)
11566 struct bfd_link_hash_table
*ret
;
11568 ret
= _bfd_mips_elf_link_hash_table_create (abfd
);
11571 struct mips_elf_link_hash_table
*htab
;
11573 htab
= (struct mips_elf_link_hash_table
*) ret
;
11574 htab
->use_plts_and_copy_relocs
= TRUE
;
11575 htab
->is_vxworks
= TRUE
;
11580 /* A function that the linker calls if we are allowed to use PLTs
11581 and copy relocs. */
11584 _bfd_mips_elf_use_plts_and_copy_relocs (struct bfd_link_info
*info
)
11586 mips_elf_hash_table (info
)->use_plts_and_copy_relocs
= TRUE
;
11589 /* We need to use a special link routine to handle the .reginfo and
11590 the .mdebug sections. We need to merge all instances of these
11591 sections together, not write them all out sequentially. */
11594 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
11597 struct bfd_link_order
*p
;
11598 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
11599 asection
*rtproc_sec
;
11600 Elf32_RegInfo reginfo
;
11601 struct ecoff_debug_info debug
;
11602 struct mips_htab_traverse_info hti
;
11603 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
11604 const struct ecoff_debug_swap
*swap
= bed
->elf_backend_ecoff_debug_swap
;
11605 HDRR
*symhdr
= &debug
.symbolic_header
;
11606 void *mdebug_handle
= NULL
;
11611 struct mips_elf_link_hash_table
*htab
;
11613 static const char * const secname
[] =
11615 ".text", ".init", ".fini", ".data",
11616 ".rodata", ".sdata", ".sbss", ".bss"
11618 static const int sc
[] =
11620 scText
, scInit
, scFini
, scData
,
11621 scRData
, scSData
, scSBss
, scBss
11624 /* Sort the dynamic symbols so that those with GOT entries come after
11626 htab
= mips_elf_hash_table (info
);
11627 BFD_ASSERT (htab
!= NULL
);
11629 if (!mips_elf_sort_hash_table (abfd
, info
))
11632 /* Create any scheduled LA25 stubs. */
11634 hti
.output_bfd
= abfd
;
11636 htab_traverse (htab
->la25_stubs
, mips_elf_create_la25_stub
, &hti
);
11640 /* Get a value for the GP register. */
11641 if (elf_gp (abfd
) == 0)
11643 struct bfd_link_hash_entry
*h
;
11645 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
11646 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
11647 elf_gp (abfd
) = (h
->u
.def
.value
11648 + h
->u
.def
.section
->output_section
->vma
11649 + h
->u
.def
.section
->output_offset
);
11650 else if (htab
->is_vxworks
11651 && (h
= bfd_link_hash_lookup (info
->hash
,
11652 "_GLOBAL_OFFSET_TABLE_",
11653 FALSE
, FALSE
, TRUE
))
11654 && h
->type
== bfd_link_hash_defined
)
11655 elf_gp (abfd
) = (h
->u
.def
.section
->output_section
->vma
11656 + h
->u
.def
.section
->output_offset
11658 else if (info
->relocatable
)
11660 bfd_vma lo
= MINUS_ONE
;
11662 /* Find the GP-relative section with the lowest offset. */
11663 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
11665 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
11668 /* And calculate GP relative to that. */
11669 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (info
);
11673 /* If the relocate_section function needs to do a reloc
11674 involving the GP value, it should make a reloc_dangerous
11675 callback to warn that GP is not defined. */
11679 /* Go through the sections and collect the .reginfo and .mdebug
11681 reginfo_sec
= NULL
;
11683 gptab_data_sec
= NULL
;
11684 gptab_bss_sec
= NULL
;
11685 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
11687 if (strcmp (o
->name
, ".reginfo") == 0)
11689 memset (®info
, 0, sizeof reginfo
);
11691 /* We have found the .reginfo section in the output file.
11692 Look through all the link_orders comprising it and merge
11693 the information together. */
11694 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11696 asection
*input_section
;
11698 Elf32_External_RegInfo ext
;
11701 if (p
->type
!= bfd_indirect_link_order
)
11703 if (p
->type
== bfd_data_link_order
)
11708 input_section
= p
->u
.indirect
.section
;
11709 input_bfd
= input_section
->owner
;
11711 if (! bfd_get_section_contents (input_bfd
, input_section
,
11712 &ext
, 0, sizeof ext
))
11715 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
11717 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
11718 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
11719 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
11720 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
11721 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
11723 /* ri_gp_value is set by the function
11724 mips_elf32_section_processing when the section is
11725 finally written out. */
11727 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11728 elf_link_input_bfd ignores this section. */
11729 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11732 /* Size has been set in _bfd_mips_elf_always_size_sections. */
11733 BFD_ASSERT(o
->size
== sizeof (Elf32_External_RegInfo
));
11735 /* Skip this section later on (I don't think this currently
11736 matters, but someday it might). */
11737 o
->map_head
.link_order
= NULL
;
11742 if (strcmp (o
->name
, ".mdebug") == 0)
11744 struct extsym_info einfo
;
11747 /* We have found the .mdebug section in the output file.
11748 Look through all the link_orders comprising it and merge
11749 the information together. */
11750 symhdr
->magic
= swap
->sym_magic
;
11751 /* FIXME: What should the version stamp be? */
11752 symhdr
->vstamp
= 0;
11753 symhdr
->ilineMax
= 0;
11754 symhdr
->cbLine
= 0;
11755 symhdr
->idnMax
= 0;
11756 symhdr
->ipdMax
= 0;
11757 symhdr
->isymMax
= 0;
11758 symhdr
->ioptMax
= 0;
11759 symhdr
->iauxMax
= 0;
11760 symhdr
->issMax
= 0;
11761 symhdr
->issExtMax
= 0;
11762 symhdr
->ifdMax
= 0;
11764 symhdr
->iextMax
= 0;
11766 /* We accumulate the debugging information itself in the
11767 debug_info structure. */
11769 debug
.external_dnr
= NULL
;
11770 debug
.external_pdr
= NULL
;
11771 debug
.external_sym
= NULL
;
11772 debug
.external_opt
= NULL
;
11773 debug
.external_aux
= NULL
;
11775 debug
.ssext
= debug
.ssext_end
= NULL
;
11776 debug
.external_fdr
= NULL
;
11777 debug
.external_rfd
= NULL
;
11778 debug
.external_ext
= debug
.external_ext_end
= NULL
;
11780 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
11781 if (mdebug_handle
== NULL
)
11785 esym
.cobol_main
= 0;
11789 esym
.asym
.iss
= issNil
;
11790 esym
.asym
.st
= stLocal
;
11791 esym
.asym
.reserved
= 0;
11792 esym
.asym
.index
= indexNil
;
11794 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
11796 esym
.asym
.sc
= sc
[i
];
11797 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
11800 esym
.asym
.value
= s
->vma
;
11801 last
= s
->vma
+ s
->size
;
11804 esym
.asym
.value
= last
;
11805 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
11806 secname
[i
], &esym
))
11810 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11812 asection
*input_section
;
11814 const struct ecoff_debug_swap
*input_swap
;
11815 struct ecoff_debug_info input_debug
;
11819 if (p
->type
!= bfd_indirect_link_order
)
11821 if (p
->type
== bfd_data_link_order
)
11826 input_section
= p
->u
.indirect
.section
;
11827 input_bfd
= input_section
->owner
;
11829 if (!is_mips_elf (input_bfd
))
11831 /* I don't know what a non MIPS ELF bfd would be
11832 doing with a .mdebug section, but I don't really
11833 want to deal with it. */
11837 input_swap
= (get_elf_backend_data (input_bfd
)
11838 ->elf_backend_ecoff_debug_swap
);
11840 BFD_ASSERT (p
->size
== input_section
->size
);
11842 /* The ECOFF linking code expects that we have already
11843 read in the debugging information and set up an
11844 ecoff_debug_info structure, so we do that now. */
11845 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
11849 if (! (bfd_ecoff_debug_accumulate
11850 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
11851 &input_debug
, input_swap
, info
)))
11854 /* Loop through the external symbols. For each one with
11855 interesting information, try to find the symbol in
11856 the linker global hash table and save the information
11857 for the output external symbols. */
11858 eraw_src
= input_debug
.external_ext
;
11859 eraw_end
= (eraw_src
11860 + (input_debug
.symbolic_header
.iextMax
11861 * input_swap
->external_ext_size
));
11863 eraw_src
< eraw_end
;
11864 eraw_src
+= input_swap
->external_ext_size
)
11868 struct mips_elf_link_hash_entry
*h
;
11870 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
11871 if (ext
.asym
.sc
== scNil
11872 || ext
.asym
.sc
== scUndefined
11873 || ext
.asym
.sc
== scSUndefined
)
11876 name
= input_debug
.ssext
+ ext
.asym
.iss
;
11877 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
11878 name
, FALSE
, FALSE
, TRUE
);
11879 if (h
== NULL
|| h
->esym
.ifd
!= -2)
11884 BFD_ASSERT (ext
.ifd
11885 < input_debug
.symbolic_header
.ifdMax
);
11886 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
11892 /* Free up the information we just read. */
11893 free (input_debug
.line
);
11894 free (input_debug
.external_dnr
);
11895 free (input_debug
.external_pdr
);
11896 free (input_debug
.external_sym
);
11897 free (input_debug
.external_opt
);
11898 free (input_debug
.external_aux
);
11899 free (input_debug
.ss
);
11900 free (input_debug
.ssext
);
11901 free (input_debug
.external_fdr
);
11902 free (input_debug
.external_rfd
);
11903 free (input_debug
.external_ext
);
11905 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11906 elf_link_input_bfd ignores this section. */
11907 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11910 if (SGI_COMPAT (abfd
) && info
->shared
)
11912 /* Create .rtproc section. */
11913 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
11914 if (rtproc_sec
== NULL
)
11916 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
11917 | SEC_LINKER_CREATED
| SEC_READONLY
);
11919 rtproc_sec
= bfd_make_section_with_flags (abfd
,
11922 if (rtproc_sec
== NULL
11923 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
11927 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
11933 /* Build the external symbol information. */
11936 einfo
.debug
= &debug
;
11938 einfo
.failed
= FALSE
;
11939 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
11940 mips_elf_output_extsym
, &einfo
);
11944 /* Set the size of the .mdebug section. */
11945 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
11947 /* Skip this section later on (I don't think this currently
11948 matters, but someday it might). */
11949 o
->map_head
.link_order
= NULL
;
11954 if (CONST_STRNEQ (o
->name
, ".gptab."))
11956 const char *subname
;
11959 Elf32_External_gptab
*ext_tab
;
11962 /* The .gptab.sdata and .gptab.sbss sections hold
11963 information describing how the small data area would
11964 change depending upon the -G switch. These sections
11965 not used in executables files. */
11966 if (! info
->relocatable
)
11968 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11970 asection
*input_section
;
11972 if (p
->type
!= bfd_indirect_link_order
)
11974 if (p
->type
== bfd_data_link_order
)
11979 input_section
= p
->u
.indirect
.section
;
11981 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11982 elf_link_input_bfd ignores this section. */
11983 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11986 /* Skip this section later on (I don't think this
11987 currently matters, but someday it might). */
11988 o
->map_head
.link_order
= NULL
;
11990 /* Really remove the section. */
11991 bfd_section_list_remove (abfd
, o
);
11992 --abfd
->section_count
;
11997 /* There is one gptab for initialized data, and one for
11998 uninitialized data. */
11999 if (strcmp (o
->name
, ".gptab.sdata") == 0)
12000 gptab_data_sec
= o
;
12001 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
12005 (*_bfd_error_handler
)
12006 (_("%s: illegal section name `%s'"),
12007 bfd_get_filename (abfd
), o
->name
);
12008 bfd_set_error (bfd_error_nonrepresentable_section
);
12012 /* The linker script always combines .gptab.data and
12013 .gptab.sdata into .gptab.sdata, and likewise for
12014 .gptab.bss and .gptab.sbss. It is possible that there is
12015 no .sdata or .sbss section in the output file, in which
12016 case we must change the name of the output section. */
12017 subname
= o
->name
+ sizeof ".gptab" - 1;
12018 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
12020 if (o
== gptab_data_sec
)
12021 o
->name
= ".gptab.data";
12023 o
->name
= ".gptab.bss";
12024 subname
= o
->name
+ sizeof ".gptab" - 1;
12025 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
12028 /* Set up the first entry. */
12030 amt
= c
* sizeof (Elf32_gptab
);
12031 tab
= bfd_malloc (amt
);
12034 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
12035 tab
[0].gt_header
.gt_unused
= 0;
12037 /* Combine the input sections. */
12038 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
12040 asection
*input_section
;
12042 bfd_size_type size
;
12043 unsigned long last
;
12044 bfd_size_type gpentry
;
12046 if (p
->type
!= bfd_indirect_link_order
)
12048 if (p
->type
== bfd_data_link_order
)
12053 input_section
= p
->u
.indirect
.section
;
12054 input_bfd
= input_section
->owner
;
12056 /* Combine the gptab entries for this input section one
12057 by one. We know that the input gptab entries are
12058 sorted by ascending -G value. */
12059 size
= input_section
->size
;
12061 for (gpentry
= sizeof (Elf32_External_gptab
);
12063 gpentry
+= sizeof (Elf32_External_gptab
))
12065 Elf32_External_gptab ext_gptab
;
12066 Elf32_gptab int_gptab
;
12072 if (! (bfd_get_section_contents
12073 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
12074 sizeof (Elf32_External_gptab
))))
12080 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
12082 val
= int_gptab
.gt_entry
.gt_g_value
;
12083 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
12086 for (look
= 1; look
< c
; look
++)
12088 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
12089 tab
[look
].gt_entry
.gt_bytes
+= add
;
12091 if (tab
[look
].gt_entry
.gt_g_value
== val
)
12097 Elf32_gptab
*new_tab
;
12100 /* We need a new table entry. */
12101 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
12102 new_tab
= bfd_realloc (tab
, amt
);
12103 if (new_tab
== NULL
)
12109 tab
[c
].gt_entry
.gt_g_value
= val
;
12110 tab
[c
].gt_entry
.gt_bytes
= add
;
12112 /* Merge in the size for the next smallest -G
12113 value, since that will be implied by this new
12116 for (look
= 1; look
< c
; look
++)
12118 if (tab
[look
].gt_entry
.gt_g_value
< val
12120 || (tab
[look
].gt_entry
.gt_g_value
12121 > tab
[max
].gt_entry
.gt_g_value
)))
12125 tab
[c
].gt_entry
.gt_bytes
+=
12126 tab
[max
].gt_entry
.gt_bytes
;
12131 last
= int_gptab
.gt_entry
.gt_bytes
;
12134 /* Hack: reset the SEC_HAS_CONTENTS flag so that
12135 elf_link_input_bfd ignores this section. */
12136 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
12139 /* The table must be sorted by -G value. */
12141 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
12143 /* Swap out the table. */
12144 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
12145 ext_tab
= bfd_alloc (abfd
, amt
);
12146 if (ext_tab
== NULL
)
12152 for (j
= 0; j
< c
; j
++)
12153 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
12156 o
->size
= c
* sizeof (Elf32_External_gptab
);
12157 o
->contents
= (bfd_byte
*) ext_tab
;
12159 /* Skip this section later on (I don't think this currently
12160 matters, but someday it might). */
12161 o
->map_head
.link_order
= NULL
;
12165 /* Invoke the regular ELF backend linker to do all the work. */
12166 if (!bfd_elf_final_link (abfd
, info
))
12169 /* Now write out the computed sections. */
12171 if (reginfo_sec
!= NULL
)
12173 Elf32_External_RegInfo ext
;
12175 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
12176 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
12180 if (mdebug_sec
!= NULL
)
12182 BFD_ASSERT (abfd
->output_has_begun
);
12183 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
12185 mdebug_sec
->filepos
))
12188 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
12191 if (gptab_data_sec
!= NULL
)
12193 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
12194 gptab_data_sec
->contents
,
12195 0, gptab_data_sec
->size
))
12199 if (gptab_bss_sec
!= NULL
)
12201 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
12202 gptab_bss_sec
->contents
,
12203 0, gptab_bss_sec
->size
))
12207 if (SGI_COMPAT (abfd
))
12209 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
12210 if (rtproc_sec
!= NULL
)
12212 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
12213 rtproc_sec
->contents
,
12214 0, rtproc_sec
->size
))
12222 /* Structure for saying that BFD machine EXTENSION extends BASE. */
12224 struct mips_mach_extension
{
12225 unsigned long extension
, base
;
12229 /* An array describing how BFD machines relate to one another. The entries
12230 are ordered topologically with MIPS I extensions listed last. */
12232 static const struct mips_mach_extension mips_mach_extensions
[] = {
12233 /* MIPS64r2 extensions. */
12234 { bfd_mach_mips_octeon
, bfd_mach_mipsisa64r2
},
12236 /* MIPS64 extensions. */
12237 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
12238 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
12239 { bfd_mach_mips_xlr
, bfd_mach_mipsisa64
},
12241 /* MIPS V extensions. */
12242 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
12244 /* R10000 extensions. */
12245 { bfd_mach_mips12000
, bfd_mach_mips10000
},
12246 { bfd_mach_mips14000
, bfd_mach_mips10000
},
12247 { bfd_mach_mips16000
, bfd_mach_mips10000
},
12249 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
12250 vr5400 ISA, but doesn't include the multimedia stuff. It seems
12251 better to allow vr5400 and vr5500 code to be merged anyway, since
12252 many libraries will just use the core ISA. Perhaps we could add
12253 some sort of ASE flag if this ever proves a problem. */
12254 { bfd_mach_mips5500
, bfd_mach_mips5400
},
12255 { bfd_mach_mips5400
, bfd_mach_mips5000
},
12257 /* MIPS IV extensions. */
12258 { bfd_mach_mips5
, bfd_mach_mips8000
},
12259 { bfd_mach_mips10000
, bfd_mach_mips8000
},
12260 { bfd_mach_mips5000
, bfd_mach_mips8000
},
12261 { bfd_mach_mips7000
, bfd_mach_mips8000
},
12262 { bfd_mach_mips9000
, bfd_mach_mips8000
},
12264 /* VR4100 extensions. */
12265 { bfd_mach_mips4120
, bfd_mach_mips4100
},
12266 { bfd_mach_mips4111
, bfd_mach_mips4100
},
12268 /* MIPS III extensions. */
12269 { bfd_mach_mips_loongson_2e
, bfd_mach_mips4000
},
12270 { bfd_mach_mips_loongson_2f
, bfd_mach_mips4000
},
12271 { bfd_mach_mips8000
, bfd_mach_mips4000
},
12272 { bfd_mach_mips4650
, bfd_mach_mips4000
},
12273 { bfd_mach_mips4600
, bfd_mach_mips4000
},
12274 { bfd_mach_mips4400
, bfd_mach_mips4000
},
12275 { bfd_mach_mips4300
, bfd_mach_mips4000
},
12276 { bfd_mach_mips4100
, bfd_mach_mips4000
},
12277 { bfd_mach_mips4010
, bfd_mach_mips4000
},
12279 /* MIPS32 extensions. */
12280 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
12282 /* MIPS II extensions. */
12283 { bfd_mach_mips4000
, bfd_mach_mips6000
},
12284 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
12286 /* MIPS I extensions. */
12287 { bfd_mach_mips6000
, bfd_mach_mips3000
},
12288 { bfd_mach_mips3900
, bfd_mach_mips3000
}
12292 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
12295 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
12299 if (extension
== base
)
12302 if (base
== bfd_mach_mipsisa32
12303 && mips_mach_extends_p (bfd_mach_mipsisa64
, extension
))
12306 if (base
== bfd_mach_mipsisa32r2
12307 && mips_mach_extends_p (bfd_mach_mipsisa64r2
, extension
))
12310 for (i
= 0; i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
12311 if (extension
== mips_mach_extensions
[i
].extension
)
12313 extension
= mips_mach_extensions
[i
].base
;
12314 if (extension
== base
)
12322 /* Return true if the given ELF header flags describe a 32-bit binary. */
12325 mips_32bit_flags_p (flagword flags
)
12327 return ((flags
& EF_MIPS_32BITMODE
) != 0
12328 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
12329 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
12330 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
12331 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
12332 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
12333 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
);
12337 /* Merge object attributes from IBFD into OBFD. Raise an error if
12338 there are conflicting attributes. */
12340 mips_elf_merge_obj_attributes (bfd
*ibfd
, bfd
*obfd
)
12342 obj_attribute
*in_attr
;
12343 obj_attribute
*out_attr
;
12345 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
12347 /* This is the first object. Copy the attributes. */
12348 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
12350 /* Use the Tag_null value to indicate the attributes have been
12352 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
12357 /* Check for conflicting Tag_GNU_MIPS_ABI_FP attributes and merge
12358 non-conflicting ones. */
12359 in_attr
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
12360 out_attr
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
12361 if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12363 out_attr
[Tag_GNU_MIPS_ABI_FP
].type
= 1;
12364 if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
12365 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
12366 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
12368 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
12370 (_("Warning: %B uses unknown floating point ABI %d"), ibfd
,
12371 in_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
12372 else if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
12374 (_("Warning: %B uses unknown floating point ABI %d"), obfd
,
12375 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
12377 switch (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12380 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12384 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
12390 (_("Warning: %B uses hard float, %B uses soft float"),
12396 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
12406 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12410 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
12416 (_("Warning: %B uses hard float, %B uses soft float"),
12422 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
12432 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12438 (_("Warning: %B uses hard float, %B uses soft float"),
12448 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12452 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
12458 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
12464 (_("Warning: %B uses hard float, %B uses soft float"),
12478 /* Merge Tag_compatibility attributes and any common GNU ones. */
12479 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
12484 /* Merge backend specific data from an object file to the output
12485 object file when linking. */
12488 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
12490 flagword old_flags
;
12491 flagword new_flags
;
12493 bfd_boolean null_input_bfd
= TRUE
;
12496 /* Check if we have the same endianess */
12497 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
12499 (*_bfd_error_handler
)
12500 (_("%B: endianness incompatible with that of the selected emulation"),
12505 if (!is_mips_elf (ibfd
) || !is_mips_elf (obfd
))
12508 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
12510 (*_bfd_error_handler
)
12511 (_("%B: ABI is incompatible with that of the selected emulation"),
12516 if (!mips_elf_merge_obj_attributes (ibfd
, obfd
))
12519 new_flags
= elf_elfheader (ibfd
)->e_flags
;
12520 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
12521 old_flags
= elf_elfheader (obfd
)->e_flags
;
12523 if (! elf_flags_init (obfd
))
12525 elf_flags_init (obfd
) = TRUE
;
12526 elf_elfheader (obfd
)->e_flags
= new_flags
;
12527 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
12528 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
12530 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
12531 && (bfd_get_arch_info (obfd
)->the_default
12532 || mips_mach_extends_p (bfd_get_mach (obfd
),
12533 bfd_get_mach (ibfd
))))
12535 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
12536 bfd_get_mach (ibfd
)))
12543 /* Check flag compatibility. */
12545 new_flags
&= ~EF_MIPS_NOREORDER
;
12546 old_flags
&= ~EF_MIPS_NOREORDER
;
12548 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
12549 doesn't seem to matter. */
12550 new_flags
&= ~EF_MIPS_XGOT
;
12551 old_flags
&= ~EF_MIPS_XGOT
;
12553 /* MIPSpro generates ucode info in n64 objects. Again, we should
12554 just be able to ignore this. */
12555 new_flags
&= ~EF_MIPS_UCODE
;
12556 old_flags
&= ~EF_MIPS_UCODE
;
12558 /* DSOs should only be linked with CPIC code. */
12559 if ((ibfd
->flags
& DYNAMIC
) != 0)
12560 new_flags
|= EF_MIPS_PIC
| EF_MIPS_CPIC
;
12562 if (new_flags
== old_flags
)
12565 /* Check to see if the input BFD actually contains any sections.
12566 If not, its flags may not have been initialised either, but it cannot
12567 actually cause any incompatibility. */
12568 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
12570 /* Ignore synthetic sections and empty .text, .data and .bss sections
12571 which are automatically generated by gas. */
12572 if (strcmp (sec
->name
, ".reginfo")
12573 && strcmp (sec
->name
, ".mdebug")
12575 || (strcmp (sec
->name
, ".text")
12576 && strcmp (sec
->name
, ".data")
12577 && strcmp (sec
->name
, ".bss"))))
12579 null_input_bfd
= FALSE
;
12583 if (null_input_bfd
)
12588 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
12589 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
12591 (*_bfd_error_handler
)
12592 (_("%B: warning: linking abicalls files with non-abicalls files"),
12597 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
12598 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
12599 if (! (new_flags
& EF_MIPS_PIC
))
12600 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
12602 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
12603 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
12605 /* Compare the ISAs. */
12606 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
12608 (*_bfd_error_handler
)
12609 (_("%B: linking 32-bit code with 64-bit code"),
12613 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
12615 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
12616 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
12618 /* Copy the architecture info from IBFD to OBFD. Also copy
12619 the 32-bit flag (if set) so that we continue to recognise
12620 OBFD as a 32-bit binary. */
12621 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
12622 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
12623 elf_elfheader (obfd
)->e_flags
12624 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
12626 /* Copy across the ABI flags if OBFD doesn't use them
12627 and if that was what caused us to treat IBFD as 32-bit. */
12628 if ((old_flags
& EF_MIPS_ABI
) == 0
12629 && mips_32bit_flags_p (new_flags
)
12630 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
12631 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
12635 /* The ISAs aren't compatible. */
12636 (*_bfd_error_handler
)
12637 (_("%B: linking %s module with previous %s modules"),
12639 bfd_printable_name (ibfd
),
12640 bfd_printable_name (obfd
));
12645 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
12646 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
12648 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
12649 does set EI_CLASS differently from any 32-bit ABI. */
12650 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
12651 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
12652 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
12654 /* Only error if both are set (to different values). */
12655 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
12656 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
12657 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
12659 (*_bfd_error_handler
)
12660 (_("%B: ABI mismatch: linking %s module with previous %s modules"),
12662 elf_mips_abi_name (ibfd
),
12663 elf_mips_abi_name (obfd
));
12666 new_flags
&= ~EF_MIPS_ABI
;
12667 old_flags
&= ~EF_MIPS_ABI
;
12670 /* For now, allow arbitrary mixing of ASEs (retain the union). */
12671 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
12673 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
12675 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
12676 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
12679 /* Warn about any other mismatches */
12680 if (new_flags
!= old_flags
)
12682 (*_bfd_error_handler
)
12683 (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
12684 ibfd
, (unsigned long) new_flags
,
12685 (unsigned long) old_flags
);
12691 bfd_set_error (bfd_error_bad_value
);
12698 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
12701 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
12703 BFD_ASSERT (!elf_flags_init (abfd
)
12704 || elf_elfheader (abfd
)->e_flags
== flags
);
12706 elf_elfheader (abfd
)->e_flags
= flags
;
12707 elf_flags_init (abfd
) = TRUE
;
12712 _bfd_mips_elf_get_target_dtag (bfd_vma dtag
)
12716 default: return "";
12717 case DT_MIPS_RLD_VERSION
:
12718 return "MIPS_RLD_VERSION";
12719 case DT_MIPS_TIME_STAMP
:
12720 return "MIPS_TIME_STAMP";
12721 case DT_MIPS_ICHECKSUM
:
12722 return "MIPS_ICHECKSUM";
12723 case DT_MIPS_IVERSION
:
12724 return "MIPS_IVERSION";
12725 case DT_MIPS_FLAGS
:
12726 return "MIPS_FLAGS";
12727 case DT_MIPS_BASE_ADDRESS
:
12728 return "MIPS_BASE_ADDRESS";
12730 return "MIPS_MSYM";
12731 case DT_MIPS_CONFLICT
:
12732 return "MIPS_CONFLICT";
12733 case DT_MIPS_LIBLIST
:
12734 return "MIPS_LIBLIST";
12735 case DT_MIPS_LOCAL_GOTNO
:
12736 return "MIPS_LOCAL_GOTNO";
12737 case DT_MIPS_CONFLICTNO
:
12738 return "MIPS_CONFLICTNO";
12739 case DT_MIPS_LIBLISTNO
:
12740 return "MIPS_LIBLISTNO";
12741 case DT_MIPS_SYMTABNO
:
12742 return "MIPS_SYMTABNO";
12743 case DT_MIPS_UNREFEXTNO
:
12744 return "MIPS_UNREFEXTNO";
12745 case DT_MIPS_GOTSYM
:
12746 return "MIPS_GOTSYM";
12747 case DT_MIPS_HIPAGENO
:
12748 return "MIPS_HIPAGENO";
12749 case DT_MIPS_RLD_MAP
:
12750 return "MIPS_RLD_MAP";
12751 case DT_MIPS_DELTA_CLASS
:
12752 return "MIPS_DELTA_CLASS";
12753 case DT_MIPS_DELTA_CLASS_NO
:
12754 return "MIPS_DELTA_CLASS_NO";
12755 case DT_MIPS_DELTA_INSTANCE
:
12756 return "MIPS_DELTA_INSTANCE";
12757 case DT_MIPS_DELTA_INSTANCE_NO
:
12758 return "MIPS_DELTA_INSTANCE_NO";
12759 case DT_MIPS_DELTA_RELOC
:
12760 return "MIPS_DELTA_RELOC";
12761 case DT_MIPS_DELTA_RELOC_NO
:
12762 return "MIPS_DELTA_RELOC_NO";
12763 case DT_MIPS_DELTA_SYM
:
12764 return "MIPS_DELTA_SYM";
12765 case DT_MIPS_DELTA_SYM_NO
:
12766 return "MIPS_DELTA_SYM_NO";
12767 case DT_MIPS_DELTA_CLASSSYM
:
12768 return "MIPS_DELTA_CLASSSYM";
12769 case DT_MIPS_DELTA_CLASSSYM_NO
:
12770 return "MIPS_DELTA_CLASSSYM_NO";
12771 case DT_MIPS_CXX_FLAGS
:
12772 return "MIPS_CXX_FLAGS";
12773 case DT_MIPS_PIXIE_INIT
:
12774 return "MIPS_PIXIE_INIT";
12775 case DT_MIPS_SYMBOL_LIB
:
12776 return "MIPS_SYMBOL_LIB";
12777 case DT_MIPS_LOCALPAGE_GOTIDX
:
12778 return "MIPS_LOCALPAGE_GOTIDX";
12779 case DT_MIPS_LOCAL_GOTIDX
:
12780 return "MIPS_LOCAL_GOTIDX";
12781 case DT_MIPS_HIDDEN_GOTIDX
:
12782 return "MIPS_HIDDEN_GOTIDX";
12783 case DT_MIPS_PROTECTED_GOTIDX
:
12784 return "MIPS_PROTECTED_GOT_IDX";
12785 case DT_MIPS_OPTIONS
:
12786 return "MIPS_OPTIONS";
12787 case DT_MIPS_INTERFACE
:
12788 return "MIPS_INTERFACE";
12789 case DT_MIPS_DYNSTR_ALIGN
:
12790 return "DT_MIPS_DYNSTR_ALIGN";
12791 case DT_MIPS_INTERFACE_SIZE
:
12792 return "DT_MIPS_INTERFACE_SIZE";
12793 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
:
12794 return "DT_MIPS_RLD_TEXT_RESOLVE_ADDR";
12795 case DT_MIPS_PERF_SUFFIX
:
12796 return "DT_MIPS_PERF_SUFFIX";
12797 case DT_MIPS_COMPACT_SIZE
:
12798 return "DT_MIPS_COMPACT_SIZE";
12799 case DT_MIPS_GP_VALUE
:
12800 return "DT_MIPS_GP_VALUE";
12801 case DT_MIPS_AUX_DYNAMIC
:
12802 return "DT_MIPS_AUX_DYNAMIC";
12803 case DT_MIPS_PLTGOT
:
12804 return "DT_MIPS_PLTGOT";
12805 case DT_MIPS_RWPLT
:
12806 return "DT_MIPS_RWPLT";
12811 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
12815 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
12817 /* Print normal ELF private data. */
12818 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
12820 /* xgettext:c-format */
12821 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
12823 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
12824 fprintf (file
, _(" [abi=O32]"));
12825 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
12826 fprintf (file
, _(" [abi=O64]"));
12827 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
12828 fprintf (file
, _(" [abi=EABI32]"));
12829 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
12830 fprintf (file
, _(" [abi=EABI64]"));
12831 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
12832 fprintf (file
, _(" [abi unknown]"));
12833 else if (ABI_N32_P (abfd
))
12834 fprintf (file
, _(" [abi=N32]"));
12835 else if (ABI_64_P (abfd
))
12836 fprintf (file
, _(" [abi=64]"));
12838 fprintf (file
, _(" [no abi set]"));
12840 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
12841 fprintf (file
, " [mips1]");
12842 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
12843 fprintf (file
, " [mips2]");
12844 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
12845 fprintf (file
, " [mips3]");
12846 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
12847 fprintf (file
, " [mips4]");
12848 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
12849 fprintf (file
, " [mips5]");
12850 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
12851 fprintf (file
, " [mips32]");
12852 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
12853 fprintf (file
, " [mips64]");
12854 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
12855 fprintf (file
, " [mips32r2]");
12856 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
12857 fprintf (file
, " [mips64r2]");
12859 fprintf (file
, _(" [unknown ISA]"));
12861 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
12862 fprintf (file
, " [mdmx]");
12864 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
12865 fprintf (file
, " [mips16]");
12867 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
12868 fprintf (file
, " [32bitmode]");
12870 fprintf (file
, _(" [not 32bitmode]"));
12872 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NOREORDER
)
12873 fprintf (file
, " [noreorder]");
12875 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
12876 fprintf (file
, " [PIC]");
12878 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_CPIC
)
12879 fprintf (file
, " [CPIC]");
12881 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_XGOT
)
12882 fprintf (file
, " [XGOT]");
12884 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_UCODE
)
12885 fprintf (file
, " [UCODE]");
12887 fputc ('\n', file
);
12892 const struct bfd_elf_special_section _bfd_mips_elf_special_sections
[] =
12894 { STRING_COMMA_LEN (".lit4"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12895 { STRING_COMMA_LEN (".lit8"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12896 { STRING_COMMA_LEN (".mdebug"), 0, SHT_MIPS_DEBUG
, 0 },
12897 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12898 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12899 { STRING_COMMA_LEN (".ucode"), 0, SHT_MIPS_UCODE
, 0 },
12900 { NULL
, 0, 0, 0, 0 }
12903 /* Merge non visibility st_other attributes. Ensure that the
12904 STO_OPTIONAL flag is copied into h->other, even if this is not a
12905 definiton of the symbol. */
12907 _bfd_mips_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
12908 const Elf_Internal_Sym
*isym
,
12909 bfd_boolean definition
,
12910 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
12912 if ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1)) != 0)
12914 unsigned char other
;
12916 other
= (definition
? isym
->st_other
: h
->other
);
12917 other
&= ~ELF_ST_VISIBILITY (-1);
12918 h
->other
= other
| ELF_ST_VISIBILITY (h
->other
);
12922 && ELF_MIPS_IS_OPTIONAL (isym
->st_other
))
12923 h
->other
|= STO_OPTIONAL
;
12926 /* Decide whether an undefined symbol is special and can be ignored.
12927 This is the case for OPTIONAL symbols on IRIX. */
12929 _bfd_mips_elf_ignore_undef_symbol (struct elf_link_hash_entry
*h
)
12931 return ELF_MIPS_IS_OPTIONAL (h
->other
) ? TRUE
: FALSE
;
12935 _bfd_mips_elf_common_definition (Elf_Internal_Sym
*sym
)
12937 return (sym
->st_shndx
== SHN_COMMON
12938 || sym
->st_shndx
== SHN_MIPS_ACOMMON
12939 || sym
->st_shndx
== SHN_MIPS_SCOMMON
);
12942 /* Return address for Ith PLT stub in section PLT, for relocation REL
12943 or (bfd_vma) -1 if it should not be included. */
12946 _bfd_mips_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
12947 const arelent
*rel ATTRIBUTE_UNUSED
)
12950 + 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
)
12951 + i
* 4 * ARRAY_SIZE (mips_exec_plt_entry
));
12955 _bfd_mips_post_process_headers (bfd
*abfd
, struct bfd_link_info
*link_info
)
12957 struct mips_elf_link_hash_table
*htab
;
12958 Elf_Internal_Ehdr
*i_ehdrp
;
12960 i_ehdrp
= elf_elfheader (abfd
);
12963 htab
= mips_elf_hash_table (link_info
);
12964 BFD_ASSERT (htab
!= NULL
);
12966 if (htab
->use_plts_and_copy_relocs
&& !htab
->is_vxworks
)
12967 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 1;