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 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) global and forced-local symbols
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 a global symbol in the got (or, local, if
99 struct mips_elf_link_hash_entry
*h
;
102 /* The TLS types included in this GOT entry (specifically, GD and
103 IE). The GD and IE flags can be added as we encounter new
104 relocations. LDM can also be set; it will always be alone, not
105 combined with any GD or IE flags. An LDM GOT entry will be
106 a local symbol entry with r_symndx == 0. */
107 unsigned char tls_type
;
109 /* The offset from the beginning of the .got section to the entry
110 corresponding to this symbol+addend. If it's a global symbol
111 whose offset is yet to be decided, it's going to be -1. */
115 /* This structure describes a range of addends: [MIN_ADDEND, MAX_ADDEND].
116 The structures form a non-overlapping list that is sorted by increasing
118 struct mips_got_page_range
120 struct mips_got_page_range
*next
;
121 bfd_signed_vma min_addend
;
122 bfd_signed_vma max_addend
;
125 /* This structure describes the range of addends that are applied to page
126 relocations against a given symbol. */
127 struct mips_got_page_entry
129 /* The input bfd in which the symbol is defined. */
131 /* The index of the symbol, as stored in the relocation r_info. */
133 /* The ranges for this page entry. */
134 struct mips_got_page_range
*ranges
;
135 /* The maximum number of page entries needed for RANGES. */
139 /* This structure is used to hold .got information when linking. */
143 /* The global symbol in the GOT with the lowest index in the dynamic
145 struct elf_link_hash_entry
*global_gotsym
;
146 /* The number of global .got entries. */
147 unsigned int global_gotno
;
148 /* The number of global .got entries that are in the GGA_RELOC_ONLY area. */
149 unsigned int reloc_only_gotno
;
150 /* The number of .got slots used for TLS. */
151 unsigned int tls_gotno
;
152 /* The first unused TLS .got entry. Used only during
153 mips_elf_initialize_tls_index. */
154 unsigned int tls_assigned_gotno
;
155 /* The number of local .got entries, eventually including page entries. */
156 unsigned int local_gotno
;
157 /* The maximum number of page entries needed. */
158 unsigned int page_gotno
;
159 /* The number of local .got entries we have used. */
160 unsigned int assigned_gotno
;
161 /* A hash table holding members of the got. */
162 struct htab
*got_entries
;
163 /* A hash table of mips_got_page_entry structures. */
164 struct htab
*got_page_entries
;
165 /* A hash table mapping input bfds to other mips_got_info. NULL
166 unless multi-got was necessary. */
167 struct htab
*bfd2got
;
168 /* In multi-got links, a pointer to the next got (err, rather, most
169 of the time, it points to the previous got). */
170 struct mips_got_info
*next
;
171 /* This is the GOT index of the TLS LDM entry for the GOT, MINUS_ONE
172 for none, or MINUS_TWO for not yet assigned. This is needed
173 because a single-GOT link may have multiple hash table entries
174 for the LDM. It does not get initialized in multi-GOT mode. */
175 bfd_vma tls_ldm_offset
;
178 /* Map an input bfd to a got in a multi-got link. */
180 struct mips_elf_bfd2got_hash
{
182 struct mips_got_info
*g
;
185 /* Structure passed when traversing the bfd2got hash table, used to
186 create and merge bfd's gots. */
188 struct mips_elf_got_per_bfd_arg
190 /* A hashtable that maps bfds to gots. */
192 /* The output bfd. */
194 /* The link information. */
195 struct bfd_link_info
*info
;
196 /* A pointer to the primary got, i.e., the one that's going to get
197 the implicit relocations from DT_MIPS_LOCAL_GOTNO and
199 struct mips_got_info
*primary
;
200 /* A non-primary got we're trying to merge with other input bfd's
202 struct mips_got_info
*current
;
203 /* The maximum number of got entries that can be addressed with a
205 unsigned int max_count
;
206 /* The maximum number of page entries needed by each got. */
207 unsigned int max_pages
;
208 /* The total number of global entries which will live in the
209 primary got and be automatically relocated. This includes
210 those not referenced by the primary GOT but included in
212 unsigned int global_count
;
215 /* Another structure used to pass arguments for got entries traversal. */
217 struct mips_elf_set_global_got_offset_arg
219 struct mips_got_info
*g
;
221 unsigned int needed_relocs
;
222 struct bfd_link_info
*info
;
225 /* A structure used to count TLS relocations or GOT entries, for GOT
226 entry or ELF symbol table traversal. */
228 struct mips_elf_count_tls_arg
230 struct bfd_link_info
*info
;
234 struct _mips_elf_section_data
236 struct bfd_elf_section_data elf
;
243 #define mips_elf_section_data(sec) \
244 ((struct _mips_elf_section_data *) elf_section_data (sec))
246 #define is_mips_elf(bfd) \
247 (bfd_get_flavour (bfd) == bfd_target_elf_flavour \
248 && elf_tdata (bfd) != NULL \
249 && elf_object_id (bfd) == MIPS_ELF_TDATA)
251 /* The ABI says that every symbol used by dynamic relocations must have
252 a global GOT entry. Among other things, this provides the dynamic
253 linker with a free, directly-indexed cache. The GOT can therefore
254 contain symbols that are not referenced by GOT relocations themselves
255 (in other words, it may have symbols that are not referenced by things
256 like R_MIPS_GOT16 and R_MIPS_GOT_PAGE).
258 GOT relocations are less likely to overflow if we put the associated
259 GOT entries towards the beginning. We therefore divide the global
260 GOT entries into two areas: "normal" and "reloc-only". Entries in
261 the first area can be used for both dynamic relocations and GP-relative
262 accesses, while those in the "reloc-only" area are for dynamic
265 These GGA_* ("Global GOT Area") values are organised so that lower
266 values are more general than higher values. Also, non-GGA_NONE
267 values are ordered by the position of the area in the GOT. */
269 #define GGA_RELOC_ONLY 1
272 /* Information about a non-PIC interface to a PIC function. There are
273 two ways of creating these interfaces. The first is to add:
276 addiu $25,$25,%lo(func)
278 immediately before a PIC function "func". The second is to add:
282 addiu $25,$25,%lo(func)
284 to a separate trampoline section.
286 Stubs of the first kind go in a new section immediately before the
287 target function. Stubs of the second kind go in a single section
288 pointed to by the hash table's "strampoline" field. */
289 struct mips_elf_la25_stub
{
290 /* The generated section that contains this stub. */
291 asection
*stub_section
;
293 /* The offset of the stub from the start of STUB_SECTION. */
296 /* One symbol for the original function. Its location is available
297 in H->root.root.u.def. */
298 struct mips_elf_link_hash_entry
*h
;
301 /* Macros for populating a mips_elf_la25_stub. */
303 #define LA25_LUI(VAL) (0x3c190000 | (VAL)) /* lui t9,VAL */
304 #define LA25_J(VAL) (0x08000000 | (((VAL) >> 2) & 0x3ffffff)) /* j VAL */
305 #define LA25_ADDIU(VAL) (0x27390000 | (VAL)) /* addiu t9,t9,VAL */
307 /* This structure is passed to mips_elf_sort_hash_table_f when sorting
308 the dynamic symbols. */
310 struct mips_elf_hash_sort_data
312 /* The symbol in the global GOT with the lowest dynamic symbol table
314 struct elf_link_hash_entry
*low
;
315 /* The least dynamic symbol table index corresponding to a non-TLS
316 symbol with a GOT entry. */
317 long min_got_dynindx
;
318 /* The greatest dynamic symbol table index corresponding to a symbol
319 with a GOT entry that is not referenced (e.g., a dynamic symbol
320 with dynamic relocations pointing to it from non-primary GOTs). */
321 long max_unref_got_dynindx
;
322 /* The greatest dynamic symbol table index not corresponding to a
323 symbol without a GOT entry. */
324 long max_non_got_dynindx
;
327 /* The MIPS ELF linker needs additional information for each symbol in
328 the global hash table. */
330 struct mips_elf_link_hash_entry
332 struct elf_link_hash_entry root
;
334 /* External symbol information. */
337 /* The la25 stub we have created for ths symbol, if any. */
338 struct mips_elf_la25_stub
*la25_stub
;
340 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against
342 unsigned int possibly_dynamic_relocs
;
344 /* If there is a stub that 32 bit functions should use to call this
345 16 bit function, this points to the section containing the stub. */
348 /* If there is a stub that 16 bit functions should use to call this
349 32 bit function, this points to the section containing the stub. */
352 /* This is like the call_stub field, but it is used if the function
353 being called returns a floating point value. */
354 asection
*call_fp_stub
;
358 #define GOT_TLS_LDM 2
360 #define GOT_TLS_OFFSET_DONE 0x40
361 #define GOT_TLS_DONE 0x80
362 unsigned char tls_type
;
364 /* This is only used in single-GOT mode; in multi-GOT mode there
365 is one mips_got_entry per GOT entry, so the offset is stored
366 there. In single-GOT mode there may be many mips_got_entry
367 structures all referring to the same GOT slot. It might be
368 possible to use root.got.offset instead, but that field is
369 overloaded already. */
370 bfd_vma tls_got_offset
;
372 /* The highest GGA_* value that satisfies all references to this symbol. */
373 unsigned int global_got_area
: 2;
375 /* True if one of the relocations described by possibly_dynamic_relocs
376 is against a readonly section. */
377 unsigned int readonly_reloc
: 1;
379 /* True if there is a relocation against this symbol that must be
380 resolved by the static linker (in other words, if the relocation
381 cannot possibly be made dynamic). */
382 unsigned int has_static_relocs
: 1;
384 /* True if we must not create a .MIPS.stubs entry for this symbol.
385 This is set, for example, if there are relocations related to
386 taking the function's address, i.e. any but R_MIPS_CALL*16 ones.
387 See "MIPS ABI Supplement, 3rd Edition", p. 4-20. */
388 unsigned int no_fn_stub
: 1;
390 /* Whether we need the fn_stub; this is true if this symbol appears
391 in any relocs other than a 16 bit call. */
392 unsigned int need_fn_stub
: 1;
394 /* True if this symbol is referenced by branch relocations from
395 any non-PIC input file. This is used to determine whether an
396 la25 stub is required. */
397 unsigned int has_nonpic_branches
: 1;
399 /* Does this symbol need a traditional MIPS lazy-binding stub
400 (as opposed to a PLT entry)? */
401 unsigned int needs_lazy_stub
: 1;
404 /* MIPS ELF linker hash table. */
406 struct mips_elf_link_hash_table
408 struct elf_link_hash_table root
;
410 /* We no longer use this. */
411 /* String section indices for the dynamic section symbols. */
412 bfd_size_type dynsym_sec_strindex
[SIZEOF_MIPS_DYNSYM_SECNAMES
];
415 /* The number of .rtproc entries. */
416 bfd_size_type procedure_count
;
418 /* The size of the .compact_rel section (if SGI_COMPAT). */
419 bfd_size_type compact_rel_size
;
421 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic
422 entry is set to the address of __rld_obj_head as in IRIX5. */
423 bfd_boolean use_rld_obj_head
;
425 /* This is the value of the __rld_map or __rld_obj_head symbol. */
428 /* This is set if we see any mips16 stub sections. */
429 bfd_boolean mips16_stubs_seen
;
431 /* True if we can generate copy relocs and PLTs. */
432 bfd_boolean use_plts_and_copy_relocs
;
434 /* True if we're generating code for VxWorks. */
435 bfd_boolean is_vxworks
;
437 /* True if we already reported the small-data section overflow. */
438 bfd_boolean small_data_overflow_reported
;
440 /* Shortcuts to some dynamic sections, or NULL if they are not
451 /* The master GOT information. */
452 struct mips_got_info
*got_info
;
454 /* The size of the PLT header in bytes. */
455 bfd_vma plt_header_size
;
457 /* The size of a PLT entry in bytes. */
458 bfd_vma plt_entry_size
;
460 /* The number of functions that need a lazy-binding stub. */
461 bfd_vma lazy_stub_count
;
463 /* The size of a function stub entry in bytes. */
464 bfd_vma function_stub_size
;
466 /* The number of reserved entries at the beginning of the GOT. */
467 unsigned int reserved_gotno
;
469 /* The section used for mips_elf_la25_stub trampolines.
470 See the comment above that structure for details. */
471 asection
*strampoline
;
473 /* A table of mips_elf_la25_stubs, indexed by (input_section, offset)
477 /* A function FN (NAME, IS, OS) that creates a new input section
478 called NAME and links it to output section OS. If IS is nonnull,
479 the new section should go immediately before it, otherwise it
480 should go at the (current) beginning of OS.
482 The function returns the new section on success, otherwise it
484 asection
*(*add_stub_section
) (const char *, asection
*, asection
*);
487 /* A structure used to communicate with htab_traverse callbacks. */
488 struct mips_htab_traverse_info
{
489 /* The usual link-wide information. */
490 struct bfd_link_info
*info
;
493 /* Starts off FALSE and is set to TRUE if the link should be aborted. */
497 #define TLS_RELOC_P(r_type) \
498 (r_type == R_MIPS_TLS_DTPMOD32 \
499 || r_type == R_MIPS_TLS_DTPMOD64 \
500 || r_type == R_MIPS_TLS_DTPREL32 \
501 || r_type == R_MIPS_TLS_DTPREL64 \
502 || r_type == R_MIPS_TLS_GD \
503 || r_type == R_MIPS_TLS_LDM \
504 || r_type == R_MIPS_TLS_DTPREL_HI16 \
505 || r_type == R_MIPS_TLS_DTPREL_LO16 \
506 || r_type == R_MIPS_TLS_GOTTPREL \
507 || r_type == R_MIPS_TLS_TPREL32 \
508 || r_type == R_MIPS_TLS_TPREL64 \
509 || r_type == R_MIPS_TLS_TPREL_HI16 \
510 || r_type == R_MIPS_TLS_TPREL_LO16)
512 /* Structure used to pass information to mips_elf_output_extsym. */
517 struct bfd_link_info
*info
;
518 struct ecoff_debug_info
*debug
;
519 const struct ecoff_debug_swap
*swap
;
523 /* The names of the runtime procedure table symbols used on IRIX5. */
525 static const char * const mips_elf_dynsym_rtproc_names
[] =
528 "_procedure_string_table",
529 "_procedure_table_size",
533 /* These structures are used to generate the .compact_rel section on
538 unsigned long id1
; /* Always one? */
539 unsigned long num
; /* Number of compact relocation entries. */
540 unsigned long id2
; /* Always two? */
541 unsigned long offset
; /* The file offset of the first relocation. */
542 unsigned long reserved0
; /* Zero? */
543 unsigned long reserved1
; /* Zero? */
552 bfd_byte reserved0
[4];
553 bfd_byte reserved1
[4];
554 } Elf32_External_compact_rel
;
558 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
559 unsigned int rtype
: 4; /* Relocation types. See below. */
560 unsigned int dist2to
: 8;
561 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
562 unsigned long konst
; /* KONST field. See below. */
563 unsigned long vaddr
; /* VADDR to be relocated. */
568 unsigned int ctype
: 1; /* 1: long 0: short format. See below. */
569 unsigned int rtype
: 4; /* Relocation types. See below. */
570 unsigned int dist2to
: 8;
571 unsigned int relvaddr
: 19; /* (VADDR - vaddr of the previous entry)/ 4 */
572 unsigned long konst
; /* KONST field. See below. */
580 } Elf32_External_crinfo
;
586 } Elf32_External_crinfo2
;
588 /* These are the constants used to swap the bitfields in a crinfo. */
590 #define CRINFO_CTYPE (0x1)
591 #define CRINFO_CTYPE_SH (31)
592 #define CRINFO_RTYPE (0xf)
593 #define CRINFO_RTYPE_SH (27)
594 #define CRINFO_DIST2TO (0xff)
595 #define CRINFO_DIST2TO_SH (19)
596 #define CRINFO_RELVADDR (0x7ffff)
597 #define CRINFO_RELVADDR_SH (0)
599 /* A compact relocation info has long (3 words) or short (2 words)
600 formats. A short format doesn't have VADDR field and relvaddr
601 fields contains ((VADDR - vaddr of the previous entry) >> 2). */
602 #define CRF_MIPS_LONG 1
603 #define CRF_MIPS_SHORT 0
605 /* There are 4 types of compact relocation at least. The value KONST
606 has different meaning for each type:
609 CT_MIPS_REL32 Address in data
610 CT_MIPS_WORD Address in word (XXX)
611 CT_MIPS_GPHI_LO GP - vaddr
612 CT_MIPS_JMPAD Address to jump
615 #define CRT_MIPS_REL32 0xa
616 #define CRT_MIPS_WORD 0xb
617 #define CRT_MIPS_GPHI_LO 0xc
618 #define CRT_MIPS_JMPAD 0xd
620 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))
621 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))
622 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))
623 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)
625 /* The structure of the runtime procedure descriptor created by the
626 loader for use by the static exception system. */
628 typedef struct runtime_pdr
{
629 bfd_vma adr
; /* Memory address of start of procedure. */
630 long regmask
; /* Save register mask. */
631 long regoffset
; /* Save register offset. */
632 long fregmask
; /* Save floating point register mask. */
633 long fregoffset
; /* Save floating point register offset. */
634 long frameoffset
; /* Frame size. */
635 short framereg
; /* Frame pointer register. */
636 short pcreg
; /* Offset or reg of return pc. */
637 long irpss
; /* Index into the runtime string table. */
639 struct exception_info
*exception_info
;/* Pointer to exception array. */
641 #define cbRPDR sizeof (RPDR)
642 #define rpdNil ((pRPDR) 0)
644 static struct mips_got_entry
*mips_elf_create_local_got_entry
645 (bfd
*, struct bfd_link_info
*, bfd
*, bfd_vma
, unsigned long,
646 struct mips_elf_link_hash_entry
*, int);
647 static bfd_boolean mips_elf_sort_hash_table_f
648 (struct mips_elf_link_hash_entry
*, void *);
649 static bfd_vma mips_elf_high
651 static bfd_boolean mips_elf_create_dynamic_relocation
652 (bfd
*, struct bfd_link_info
*, const Elf_Internal_Rela
*,
653 struct mips_elf_link_hash_entry
*, asection
*, bfd_vma
,
654 bfd_vma
*, asection
*);
655 static hashval_t mips_elf_got_entry_hash
657 static bfd_vma mips_elf_adjust_gp
658 (bfd
*, struct mips_got_info
*, bfd
*);
659 static struct mips_got_info
*mips_elf_got_for_ibfd
660 (struct mips_got_info
*, bfd
*);
662 /* This will be used when we sort the dynamic relocation records. */
663 static bfd
*reldyn_sorting_bfd
;
665 /* True if ABFD is for CPUs with load interlocking that include
666 non-MIPS1 CPUs and R3900. */
667 #define LOAD_INTERLOCKS_P(abfd) \
668 ( ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) != E_MIPS_ARCH_1) \
669 || ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_3900))
671 /* True if ABFD is for CPUs that are faster if JAL is converted to BAL.
672 This should be safe for all architectures. We enable this predicate
673 for RM9000 for now. */
674 #define JAL_TO_BAL_P(abfd) \
675 ((elf_elfheader (abfd)->e_flags & EF_MIPS_MACH) == E_MIPS_MACH_9000)
677 /* True if ABFD is for CPUs that are faster if JALR is converted to BAL.
678 This should be safe for all architectures. We enable this predicate for
680 #define JALR_TO_BAL_P(abfd) 1
682 /* True if ABFD is a PIC object. */
683 #define PIC_OBJECT_P(abfd) \
684 ((elf_elfheader (abfd)->e_flags & EF_MIPS_PIC) != 0)
686 /* Nonzero if ABFD is using the N32 ABI. */
687 #define ABI_N32_P(abfd) \
688 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
690 /* Nonzero if ABFD is using the N64 ABI. */
691 #define ABI_64_P(abfd) \
692 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
694 /* Nonzero if ABFD is using NewABI conventions. */
695 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
697 /* The IRIX compatibility level we are striving for. */
698 #define IRIX_COMPAT(abfd) \
699 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
701 /* Whether we are trying to be compatible with IRIX at all. */
702 #define SGI_COMPAT(abfd) \
703 (IRIX_COMPAT (abfd) != ict_none)
705 /* The name of the options section. */
706 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
707 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
709 /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
710 Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
711 #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
712 (strcmp (NAME, ".MIPS.options") == 0 || strcmp (NAME, ".options") == 0)
714 /* Whether the section is readonly. */
715 #define MIPS_ELF_READONLY_SECTION(sec) \
716 ((sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) \
717 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
719 /* The name of the stub section. */
720 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
722 /* The size of an external REL relocation. */
723 #define MIPS_ELF_REL_SIZE(abfd) \
724 (get_elf_backend_data (abfd)->s->sizeof_rel)
726 /* The size of an external RELA relocation. */
727 #define MIPS_ELF_RELA_SIZE(abfd) \
728 (get_elf_backend_data (abfd)->s->sizeof_rela)
730 /* The size of an external dynamic table entry. */
731 #define MIPS_ELF_DYN_SIZE(abfd) \
732 (get_elf_backend_data (abfd)->s->sizeof_dyn)
734 /* The size of a GOT entry. */
735 #define MIPS_ELF_GOT_SIZE(abfd) \
736 (get_elf_backend_data (abfd)->s->arch_size / 8)
738 /* The size of a symbol-table entry. */
739 #define MIPS_ELF_SYM_SIZE(abfd) \
740 (get_elf_backend_data (abfd)->s->sizeof_sym)
742 /* The default alignment for sections, as a power of two. */
743 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
744 (get_elf_backend_data (abfd)->s->log_file_align)
746 /* Get word-sized data. */
747 #define MIPS_ELF_GET_WORD(abfd, ptr) \
748 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
750 /* Put out word-sized data. */
751 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
753 ? bfd_put_64 (abfd, val, ptr) \
754 : bfd_put_32 (abfd, val, ptr))
756 /* The opcode for word-sized loads (LW or LD). */
757 #define MIPS_ELF_LOAD_WORD(abfd) \
758 (ABI_64_P (abfd) ? 0xdc000000 : 0x8c000000)
760 /* Add a dynamic symbol table-entry. */
761 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
762 _bfd_elf_add_dynamic_entry (info, tag, val)
764 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
765 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
767 /* Determine whether the internal relocation of index REL_IDX is REL
768 (zero) or RELA (non-zero). The assumption is that, if there are
769 two relocation sections for this section, one of them is REL and
770 the other is RELA. If the index of the relocation we're testing is
771 in range for the first relocation section, check that the external
772 relocation size is that for RELA. It is also assumed that, if
773 rel_idx is not in range for the first section, and this first
774 section contains REL relocs, then the relocation is in the second
775 section, that is RELA. */
776 #define MIPS_RELOC_RELA_P(abfd, sec, rel_idx) \
777 ((NUM_SHDR_ENTRIES (&elf_section_data (sec)->rel_hdr) \
778 * get_elf_backend_data (abfd)->s->int_rels_per_ext_rel \
779 > (bfd_vma)(rel_idx)) \
780 == (elf_section_data (sec)->rel_hdr.sh_entsize \
781 == (ABI_64_P (abfd) ? sizeof (Elf64_External_Rela) \
782 : sizeof (Elf32_External_Rela))))
784 /* The name of the dynamic relocation section. */
785 #define MIPS_ELF_REL_DYN_NAME(INFO) \
786 (mips_elf_hash_table (INFO)->is_vxworks ? ".rela.dyn" : ".rel.dyn")
788 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
789 from smaller values. Start with zero, widen, *then* decrement. */
790 #define MINUS_ONE (((bfd_vma)0) - 1)
791 #define MINUS_TWO (((bfd_vma)0) - 2)
793 /* The value to write into got[1] for SVR4 targets, to identify it is
794 a GNU object. The dynamic linker can then use got[1] to store the
796 #define MIPS_ELF_GNU_GOT1_MASK(abfd) \
797 ((bfd_vma) 1 << (ABI_64_P (abfd) ? 63 : 31))
799 /* The offset of $gp from the beginning of the .got section. */
800 #define ELF_MIPS_GP_OFFSET(INFO) \
801 (mips_elf_hash_table (INFO)->is_vxworks ? 0x0 : 0x7ff0)
803 /* The maximum size of the GOT for it to be addressable using 16-bit
805 #define MIPS_ELF_GOT_MAX_SIZE(INFO) (ELF_MIPS_GP_OFFSET (INFO) + 0x7fff)
807 /* Instructions which appear in a stub. */
808 #define STUB_LW(abfd) \
810 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
811 : 0x8f998010)) /* lw t9,0x8010(gp) */
812 #define STUB_MOVE(abfd) \
814 ? 0x03e0782d /* daddu t7,ra */ \
815 : 0x03e07821)) /* addu t7,ra */
816 #define STUB_LUI(VAL) (0x3c180000 + (VAL)) /* lui t8,VAL */
817 #define STUB_JALR 0x0320f809 /* jalr t9,ra */
818 #define STUB_ORI(VAL) (0x37180000 + (VAL)) /* ori t8,t8,VAL */
819 #define STUB_LI16U(VAL) (0x34180000 + (VAL)) /* ori t8,zero,VAL unsigned */
820 #define STUB_LI16S(abfd, VAL) \
822 ? (0x64180000 + (VAL)) /* daddiu t8,zero,VAL sign extended */ \
823 : (0x24180000 + (VAL)))) /* addiu t8,zero,VAL sign extended */
825 #define MIPS_FUNCTION_STUB_NORMAL_SIZE 16
826 #define MIPS_FUNCTION_STUB_BIG_SIZE 20
828 /* The name of the dynamic interpreter. This is put in the .interp
831 #define ELF_DYNAMIC_INTERPRETER(abfd) \
832 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
833 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
834 : "/usr/lib/libc.so.1")
837 #define MNAME(bfd,pre,pos) \
838 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
839 #define ELF_R_SYM(bfd, i) \
840 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
841 #define ELF_R_TYPE(bfd, i) \
842 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
843 #define ELF_R_INFO(bfd, s, t) \
844 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
846 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
847 #define ELF_R_SYM(bfd, i) \
849 #define ELF_R_TYPE(bfd, i) \
851 #define ELF_R_INFO(bfd, s, t) \
852 (ELF32_R_INFO (s, t))
855 /* The mips16 compiler uses a couple of special sections to handle
856 floating point arguments.
858 Section names that look like .mips16.fn.FNNAME contain stubs that
859 copy floating point arguments from the fp regs to the gp regs and
860 then jump to FNNAME. If any 32 bit function calls FNNAME, the
861 call should be redirected to the stub instead. If no 32 bit
862 function calls FNNAME, the stub should be discarded. We need to
863 consider any reference to the function, not just a call, because
864 if the address of the function is taken we will need the stub,
865 since the address might be passed to a 32 bit function.
867 Section names that look like .mips16.call.FNNAME contain stubs
868 that copy floating point arguments from the gp regs to the fp
869 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
870 then any 16 bit function that calls FNNAME should be redirected
871 to the stub instead. If FNNAME is not a 32 bit function, the
872 stub should be discarded.
874 .mips16.call.fp.FNNAME sections are similar, but contain stubs
875 which call FNNAME and then copy the return value from the fp regs
876 to the gp regs. These stubs store the return value in $18 while
877 calling FNNAME; any function which might call one of these stubs
878 must arrange to save $18 around the call. (This case is not
879 needed for 32 bit functions that call 16 bit functions, because
880 16 bit functions always return floating point values in both
883 Note that in all cases FNNAME might be defined statically.
884 Therefore, FNNAME is not used literally. Instead, the relocation
885 information will indicate which symbol the section is for.
887 We record any stubs that we find in the symbol table. */
889 #define FN_STUB ".mips16.fn."
890 #define CALL_STUB ".mips16.call."
891 #define CALL_FP_STUB ".mips16.call.fp."
893 #define FN_STUB_P(name) CONST_STRNEQ (name, FN_STUB)
894 #define CALL_STUB_P(name) CONST_STRNEQ (name, CALL_STUB)
895 #define CALL_FP_STUB_P(name) CONST_STRNEQ (name, CALL_FP_STUB)
897 /* The format of the first PLT entry in an O32 executable. */
898 static const bfd_vma mips_o32_exec_plt0_entry
[] =
900 0x3c1c0000, /* lui $28, %hi(&GOTPLT[0]) */
901 0x8f990000, /* lw $25, %lo(&GOTPLT[0])($28) */
902 0x279c0000, /* addiu $28, $28, %lo(&GOTPLT[0]) */
903 0x031cc023, /* subu $24, $24, $28 */
904 0x03e07821, /* move $15, $31 */
905 0x0018c082, /* srl $24, $24, 2 */
906 0x0320f809, /* jalr $25 */
907 0x2718fffe /* subu $24, $24, 2 */
910 /* The format of the first PLT entry in an N32 executable. Different
911 because gp ($28) is not available; we use t2 ($14) instead. */
912 static const bfd_vma mips_n32_exec_plt0_entry
[] =
914 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
915 0x8dd90000, /* lw $25, %lo(&GOTPLT[0])($14) */
916 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
917 0x030ec023, /* subu $24, $24, $14 */
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 N64 executable. Different
925 from N32 because of the increased size of GOT entries. */
926 static const bfd_vma mips_n64_exec_plt0_entry
[] =
928 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
929 0xddd90000, /* ld $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 0x0018c0c2, /* srl $24, $24, 3 */
934 0x0320f809, /* jalr $25 */
935 0x2718fffe /* subu $24, $24, 2 */
938 /* The format of subsequent PLT entries. */
939 static const bfd_vma mips_exec_plt_entry
[] =
941 0x3c0f0000, /* lui $15, %hi(.got.plt entry) */
942 0x01f90000, /* l[wd] $25, %lo(.got.plt entry)($15) */
943 0x25f80000, /* addiu $24, $15, %lo(.got.plt entry) */
944 0x03200008 /* jr $25 */
947 /* The format of the first PLT entry in a VxWorks executable. */
948 static const bfd_vma mips_vxworks_exec_plt0_entry
[] =
950 0x3c190000, /* lui t9, %hi(_GLOBAL_OFFSET_TABLE_) */
951 0x27390000, /* addiu t9, t9, %lo(_GLOBAL_OFFSET_TABLE_) */
952 0x8f390008, /* lw t9, 8(t9) */
953 0x00000000, /* nop */
954 0x03200008, /* jr t9 */
958 /* The format of subsequent PLT entries. */
959 static const bfd_vma mips_vxworks_exec_plt_entry
[] =
961 0x10000000, /* b .PLT_resolver */
962 0x24180000, /* li t8, <pltindex> */
963 0x3c190000, /* lui t9, %hi(<.got.plt slot>) */
964 0x27390000, /* addiu t9, t9, %lo(<.got.plt slot>) */
965 0x8f390000, /* lw t9, 0(t9) */
966 0x00000000, /* nop */
967 0x03200008, /* jr t9 */
971 /* The format of the first PLT entry in a VxWorks shared object. */
972 static const bfd_vma mips_vxworks_shared_plt0_entry
[] =
974 0x8f990008, /* lw t9, 8(gp) */
975 0x00000000, /* nop */
976 0x03200008, /* jr t9 */
977 0x00000000, /* nop */
978 0x00000000, /* nop */
982 /* The format of subsequent PLT entries. */
983 static const bfd_vma mips_vxworks_shared_plt_entry
[] =
985 0x10000000, /* b .PLT_resolver */
986 0x24180000 /* li t8, <pltindex> */
989 /* Look up an entry in a MIPS ELF linker hash table. */
991 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
992 ((struct mips_elf_link_hash_entry *) \
993 elf_link_hash_lookup (&(table)->root, (string), (create), \
996 /* Traverse a MIPS ELF linker hash table. */
998 #define mips_elf_link_hash_traverse(table, func, info) \
999 (elf_link_hash_traverse \
1001 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
1004 /* Get the MIPS ELF linker hash table from a link_info structure. */
1006 #define mips_elf_hash_table(p) \
1007 ((struct mips_elf_link_hash_table *) ((p)->hash))
1009 /* Find the base offsets for thread-local storage in this object,
1010 for GD/LD and IE/LE respectively. */
1012 #define TP_OFFSET 0x7000
1013 #define DTP_OFFSET 0x8000
1016 dtprel_base (struct bfd_link_info
*info
)
1018 /* If tls_sec is NULL, we should have signalled an error already. */
1019 if (elf_hash_table (info
)->tls_sec
== NULL
)
1021 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
1025 tprel_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
+ TP_OFFSET
;
1033 /* Create an entry in a MIPS ELF linker hash table. */
1035 static struct bfd_hash_entry
*
1036 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1037 struct bfd_hash_table
*table
, const char *string
)
1039 struct mips_elf_link_hash_entry
*ret
=
1040 (struct mips_elf_link_hash_entry
*) entry
;
1042 /* Allocate the structure if it has not already been allocated by a
1045 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
1047 return (struct bfd_hash_entry
*) ret
;
1049 /* Call the allocation method of the superclass. */
1050 ret
= ((struct mips_elf_link_hash_entry
*)
1051 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1055 /* Set local fields. */
1056 memset (&ret
->esym
, 0, sizeof (EXTR
));
1057 /* We use -2 as a marker to indicate that the information has
1058 not been set. -1 means there is no associated ifd. */
1061 ret
->possibly_dynamic_relocs
= 0;
1062 ret
->fn_stub
= NULL
;
1063 ret
->call_stub
= NULL
;
1064 ret
->call_fp_stub
= NULL
;
1065 ret
->tls_type
= GOT_NORMAL
;
1066 ret
->global_got_area
= GGA_NONE
;
1067 ret
->readonly_reloc
= FALSE
;
1068 ret
->has_static_relocs
= FALSE
;
1069 ret
->no_fn_stub
= FALSE
;
1070 ret
->need_fn_stub
= FALSE
;
1071 ret
->has_nonpic_branches
= FALSE
;
1072 ret
->needs_lazy_stub
= FALSE
;
1075 return (struct bfd_hash_entry
*) ret
;
1079 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
1081 if (!sec
->used_by_bfd
)
1083 struct _mips_elf_section_data
*sdata
;
1084 bfd_size_type amt
= sizeof (*sdata
);
1086 sdata
= bfd_zalloc (abfd
, amt
);
1089 sec
->used_by_bfd
= sdata
;
1092 return _bfd_elf_new_section_hook (abfd
, sec
);
1095 /* Read ECOFF debugging information from a .mdebug section into a
1096 ecoff_debug_info structure. */
1099 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
1100 struct ecoff_debug_info
*debug
)
1103 const struct ecoff_debug_swap
*swap
;
1106 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1107 memset (debug
, 0, sizeof (*debug
));
1109 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
1110 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1113 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
1114 swap
->external_hdr_size
))
1117 symhdr
= &debug
->symbolic_header
;
1118 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1120 /* The symbolic header contains absolute file offsets and sizes to
1122 #define READ(ptr, offset, count, size, type) \
1123 if (symhdr->count == 0) \
1124 debug->ptr = NULL; \
1127 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
1128 debug->ptr = bfd_malloc (amt); \
1129 if (debug->ptr == NULL) \
1130 goto error_return; \
1131 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0 \
1132 || bfd_bread (debug->ptr, amt, abfd) != amt) \
1133 goto error_return; \
1136 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1137 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
1138 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
1139 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
1140 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
1141 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1143 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1144 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
1145 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
1146 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
1147 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
1155 if (ext_hdr
!= NULL
)
1157 if (debug
->line
!= NULL
)
1159 if (debug
->external_dnr
!= NULL
)
1160 free (debug
->external_dnr
);
1161 if (debug
->external_pdr
!= NULL
)
1162 free (debug
->external_pdr
);
1163 if (debug
->external_sym
!= NULL
)
1164 free (debug
->external_sym
);
1165 if (debug
->external_opt
!= NULL
)
1166 free (debug
->external_opt
);
1167 if (debug
->external_aux
!= NULL
)
1168 free (debug
->external_aux
);
1169 if (debug
->ss
!= NULL
)
1171 if (debug
->ssext
!= NULL
)
1172 free (debug
->ssext
);
1173 if (debug
->external_fdr
!= NULL
)
1174 free (debug
->external_fdr
);
1175 if (debug
->external_rfd
!= NULL
)
1176 free (debug
->external_rfd
);
1177 if (debug
->external_ext
!= NULL
)
1178 free (debug
->external_ext
);
1182 /* Swap RPDR (runtime procedure table entry) for output. */
1185 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
1187 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
1188 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
1189 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
1190 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
1191 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
1192 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
1194 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
1195 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
1197 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
1200 /* Create a runtime procedure table from the .mdebug section. */
1203 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
1204 struct bfd_link_info
*info
, asection
*s
,
1205 struct ecoff_debug_info
*debug
)
1207 const struct ecoff_debug_swap
*swap
;
1208 HDRR
*hdr
= &debug
->symbolic_header
;
1210 struct rpdr_ext
*erp
;
1212 struct pdr_ext
*epdr
;
1213 struct sym_ext
*esym
;
1217 bfd_size_type count
;
1218 unsigned long sindex
;
1222 const char *no_name_func
= _("static procedure (no name)");
1230 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1232 sindex
= strlen (no_name_func
) + 1;
1233 count
= hdr
->ipdMax
;
1236 size
= swap
->external_pdr_size
;
1238 epdr
= bfd_malloc (size
* count
);
1242 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
1245 size
= sizeof (RPDR
);
1246 rp
= rpdr
= bfd_malloc (size
* count
);
1250 size
= sizeof (char *);
1251 sv
= bfd_malloc (size
* count
);
1255 count
= hdr
->isymMax
;
1256 size
= swap
->external_sym_size
;
1257 esym
= bfd_malloc (size
* count
);
1261 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
1264 count
= hdr
->issMax
;
1265 ss
= bfd_malloc (count
);
1268 if (! _bfd_ecoff_get_accumulated_ss (handle
, (bfd_byte
*) ss
))
1271 count
= hdr
->ipdMax
;
1272 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
1274 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
1275 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
1276 rp
->adr
= sym
.value
;
1277 rp
->regmask
= pdr
.regmask
;
1278 rp
->regoffset
= pdr
.regoffset
;
1279 rp
->fregmask
= pdr
.fregmask
;
1280 rp
->fregoffset
= pdr
.fregoffset
;
1281 rp
->frameoffset
= pdr
.frameoffset
;
1282 rp
->framereg
= pdr
.framereg
;
1283 rp
->pcreg
= pdr
.pcreg
;
1285 sv
[i
] = ss
+ sym
.iss
;
1286 sindex
+= strlen (sv
[i
]) + 1;
1290 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
1291 size
= BFD_ALIGN (size
, 16);
1292 rtproc
= bfd_alloc (abfd
, size
);
1295 mips_elf_hash_table (info
)->procedure_count
= 0;
1299 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
1302 memset (erp
, 0, sizeof (struct rpdr_ext
));
1304 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
1305 strcpy (str
, no_name_func
);
1306 str
+= strlen (no_name_func
) + 1;
1307 for (i
= 0; i
< count
; i
++)
1309 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
1310 strcpy (str
, sv
[i
]);
1311 str
+= strlen (sv
[i
]) + 1;
1313 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
1315 /* Set the size and contents of .rtproc section. */
1317 s
->contents
= rtproc
;
1319 /* Skip this section later on (I don't think this currently
1320 matters, but someday it might). */
1321 s
->map_head
.link_order
= NULL
;
1350 /* We're going to create a stub for H. Create a symbol for the stub's
1351 value and size, to help make the disassembly easier to read. */
1354 mips_elf_create_stub_symbol (struct bfd_link_info
*info
,
1355 struct mips_elf_link_hash_entry
*h
,
1356 const char *prefix
, asection
*s
, bfd_vma value
,
1359 struct bfd_link_hash_entry
*bh
;
1360 struct elf_link_hash_entry
*elfh
;
1363 /* Create a new symbol. */
1364 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1366 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1367 BSF_LOCAL
, s
, value
, NULL
,
1371 /* Make it a local function. */
1372 elfh
= (struct elf_link_hash_entry
*) bh
;
1373 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
1375 elfh
->forced_local
= 1;
1379 /* We're about to redefine H. Create a symbol to represent H's
1380 current value and size, to help make the disassembly easier
1384 mips_elf_create_shadow_symbol (struct bfd_link_info
*info
,
1385 struct mips_elf_link_hash_entry
*h
,
1388 struct bfd_link_hash_entry
*bh
;
1389 struct elf_link_hash_entry
*elfh
;
1394 /* Read the symbol's value. */
1395 BFD_ASSERT (h
->root
.root
.type
== bfd_link_hash_defined
1396 || h
->root
.root
.type
== bfd_link_hash_defweak
);
1397 s
= h
->root
.root
.u
.def
.section
;
1398 value
= h
->root
.root
.u
.def
.value
;
1400 /* Create a new symbol. */
1401 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1403 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1404 BSF_LOCAL
, s
, value
, NULL
,
1408 /* Make it local and copy the other attributes from H. */
1409 elfh
= (struct elf_link_hash_entry
*) bh
;
1410 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (h
->root
.type
));
1411 elfh
->other
= h
->root
.other
;
1412 elfh
->size
= h
->root
.size
;
1413 elfh
->forced_local
= 1;
1417 /* Return TRUE if relocations in SECTION can refer directly to a MIPS16
1418 function rather than to a hard-float stub. */
1421 section_allows_mips16_refs_p (asection
*section
)
1425 name
= bfd_get_section_name (section
->owner
, section
);
1426 return (FN_STUB_P (name
)
1427 || CALL_STUB_P (name
)
1428 || CALL_FP_STUB_P (name
)
1429 || strcmp (name
, ".pdr") == 0);
1432 /* [RELOCS, RELEND) are the relocations against SEC, which is a MIPS16
1433 stub section of some kind. Return the R_SYMNDX of the target
1434 function, or 0 if we can't decide which function that is. */
1436 static unsigned long
1437 mips16_stub_symndx (asection
*sec ATTRIBUTE_UNUSED
,
1438 const Elf_Internal_Rela
*relocs
,
1439 const Elf_Internal_Rela
*relend
)
1441 const Elf_Internal_Rela
*rel
;
1443 /* Trust the first R_MIPS_NONE relocation, if any. */
1444 for (rel
= relocs
; rel
< relend
; rel
++)
1445 if (ELF_R_TYPE (sec
->owner
, rel
->r_info
) == R_MIPS_NONE
)
1446 return ELF_R_SYM (sec
->owner
, rel
->r_info
);
1448 /* Otherwise trust the first relocation, whatever its kind. This is
1449 the traditional behavior. */
1450 if (relocs
< relend
)
1451 return ELF_R_SYM (sec
->owner
, relocs
->r_info
);
1456 /* Check the mips16 stubs for a particular symbol, and see if we can
1460 mips_elf_check_mips16_stubs (struct bfd_link_info
*info
,
1461 struct mips_elf_link_hash_entry
*h
)
1463 /* Dynamic symbols must use the standard call interface, in case other
1464 objects try to call them. */
1465 if (h
->fn_stub
!= NULL
1466 && h
->root
.dynindx
!= -1)
1468 mips_elf_create_shadow_symbol (info
, h
, ".mips16.");
1469 h
->need_fn_stub
= TRUE
;
1472 if (h
->fn_stub
!= NULL
1473 && ! h
->need_fn_stub
)
1475 /* We don't need the fn_stub; the only references to this symbol
1476 are 16 bit calls. Clobber the size to 0 to prevent it from
1477 being included in the link. */
1478 h
->fn_stub
->size
= 0;
1479 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1480 h
->fn_stub
->reloc_count
= 0;
1481 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1484 if (h
->call_stub
!= NULL
1485 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1487 /* We don't need the call_stub; this is a 16 bit function, so
1488 calls from other 16 bit functions are OK. Clobber the size
1489 to 0 to prevent it from being included in the link. */
1490 h
->call_stub
->size
= 0;
1491 h
->call_stub
->flags
&= ~SEC_RELOC
;
1492 h
->call_stub
->reloc_count
= 0;
1493 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1496 if (h
->call_fp_stub
!= NULL
1497 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1499 /* We don't need the call_stub; this is a 16 bit function, so
1500 calls from other 16 bit functions are OK. Clobber the size
1501 to 0 to prevent it from being included in the link. */
1502 h
->call_fp_stub
->size
= 0;
1503 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1504 h
->call_fp_stub
->reloc_count
= 0;
1505 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1509 /* Hashtable callbacks for mips_elf_la25_stubs. */
1512 mips_elf_la25_stub_hash (const void *entry_
)
1514 const struct mips_elf_la25_stub
*entry
;
1516 entry
= (struct mips_elf_la25_stub
*) entry_
;
1517 return entry
->h
->root
.root
.u
.def
.section
->id
1518 + entry
->h
->root
.root
.u
.def
.value
;
1522 mips_elf_la25_stub_eq (const void *entry1_
, const void *entry2_
)
1524 const struct mips_elf_la25_stub
*entry1
, *entry2
;
1526 entry1
= (struct mips_elf_la25_stub
*) entry1_
;
1527 entry2
= (struct mips_elf_la25_stub
*) entry2_
;
1528 return ((entry1
->h
->root
.root
.u
.def
.section
1529 == entry2
->h
->root
.root
.u
.def
.section
)
1530 && (entry1
->h
->root
.root
.u
.def
.value
1531 == entry2
->h
->root
.root
.u
.def
.value
));
1534 /* Called by the linker to set up the la25 stub-creation code. FN is
1535 the linker's implementation of add_stub_function. Return true on
1539 _bfd_mips_elf_init_stubs (struct bfd_link_info
*info
,
1540 asection
*(*fn
) (const char *, asection
*,
1543 struct mips_elf_link_hash_table
*htab
;
1545 htab
= mips_elf_hash_table (info
);
1546 htab
->add_stub_section
= fn
;
1547 htab
->la25_stubs
= htab_try_create (1, mips_elf_la25_stub_hash
,
1548 mips_elf_la25_stub_eq
, NULL
);
1549 if (htab
->la25_stubs
== NULL
)
1555 /* Return true if H is a locally-defined PIC function, in the sense
1556 that it might need $25 to be valid on entry. Note that MIPS16
1557 functions never need $25 to be valid on entry; they set up $gp
1558 using PC-relative instructions instead. */
1561 mips_elf_local_pic_function_p (struct mips_elf_link_hash_entry
*h
)
1563 return ((h
->root
.root
.type
== bfd_link_hash_defined
1564 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1565 && h
->root
.def_regular
1566 && !bfd_is_abs_section (h
->root
.root
.u
.def
.section
)
1567 && !ELF_ST_IS_MIPS16 (h
->root
.other
)
1568 && (PIC_OBJECT_P (h
->root
.root
.u
.def
.section
->owner
)
1569 || ELF_ST_IS_MIPS_PIC (h
->root
.other
)));
1572 /* STUB describes an la25 stub that we have decided to implement
1573 by inserting an LUI/ADDIU pair before the target function.
1574 Create the section and redirect the function symbol to it. */
1577 mips_elf_add_la25_intro (struct mips_elf_la25_stub
*stub
,
1578 struct bfd_link_info
*info
)
1580 struct mips_elf_link_hash_table
*htab
;
1582 asection
*s
, *input_section
;
1585 htab
= mips_elf_hash_table (info
);
1587 /* Create a unique name for the new section. */
1588 name
= bfd_malloc (11 + sizeof (".text.stub."));
1591 sprintf (name
, ".text.stub.%d", (int) htab_elements (htab
->la25_stubs
));
1593 /* Create the section. */
1594 input_section
= stub
->h
->root
.root
.u
.def
.section
;
1595 s
= htab
->add_stub_section (name
, input_section
,
1596 input_section
->output_section
);
1600 /* Make sure that any padding goes before the stub. */
1601 align
= input_section
->alignment_power
;
1602 if (!bfd_set_section_alignment (s
->owner
, s
, align
))
1605 s
->size
= (1 << align
) - 8;
1607 /* Create a symbol for the stub. */
1608 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 8);
1609 stub
->stub_section
= s
;
1610 stub
->offset
= s
->size
;
1612 /* Allocate room for it. */
1617 /* STUB describes an la25 stub that we have decided to implement
1618 with a separate trampoline. Allocate room for it and redirect
1619 the function symbol to it. */
1622 mips_elf_add_la25_trampoline (struct mips_elf_la25_stub
*stub
,
1623 struct bfd_link_info
*info
)
1625 struct mips_elf_link_hash_table
*htab
;
1628 htab
= mips_elf_hash_table (info
);
1630 /* Create a trampoline section, if we haven't already. */
1631 s
= htab
->strampoline
;
1634 asection
*input_section
= stub
->h
->root
.root
.u
.def
.section
;
1635 s
= htab
->add_stub_section (".text", NULL
,
1636 input_section
->output_section
);
1637 if (s
== NULL
|| !bfd_set_section_alignment (s
->owner
, s
, 4))
1639 htab
->strampoline
= s
;
1642 /* Create a symbol for the stub. */
1643 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 16);
1644 stub
->stub_section
= s
;
1645 stub
->offset
= s
->size
;
1647 /* Allocate room for it. */
1652 /* H describes a symbol that needs an la25 stub. Make sure that an
1653 appropriate stub exists and point H at it. */
1656 mips_elf_add_la25_stub (struct bfd_link_info
*info
,
1657 struct mips_elf_link_hash_entry
*h
)
1659 struct mips_elf_link_hash_table
*htab
;
1660 struct mips_elf_la25_stub search
, *stub
;
1661 bfd_boolean use_trampoline_p
;
1666 /* Prefer to use LUI/ADDIU stubs if the function is at the beginning
1667 of the section and if we would need no more than 2 nops. */
1668 s
= h
->root
.root
.u
.def
.section
;
1669 value
= h
->root
.root
.u
.def
.value
;
1670 use_trampoline_p
= (value
!= 0 || s
->alignment_power
> 4);
1672 /* Describe the stub we want. */
1673 search
.stub_section
= NULL
;
1677 /* See if we've already created an equivalent stub. */
1678 htab
= mips_elf_hash_table (info
);
1679 slot
= htab_find_slot (htab
->la25_stubs
, &search
, INSERT
);
1683 stub
= (struct mips_elf_la25_stub
*) *slot
;
1686 /* We can reuse the existing stub. */
1687 h
->la25_stub
= stub
;
1691 /* Create a permanent copy of ENTRY and add it to the hash table. */
1692 stub
= bfd_malloc (sizeof (search
));
1698 h
->la25_stub
= stub
;
1699 return (use_trampoline_p
1700 ? mips_elf_add_la25_trampoline (stub
, info
)
1701 : mips_elf_add_la25_intro (stub
, info
));
1704 /* A mips_elf_link_hash_traverse callback that is called before sizing
1705 sections. DATA points to a mips_htab_traverse_info structure. */
1708 mips_elf_check_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
1710 struct mips_htab_traverse_info
*hti
;
1712 hti
= (struct mips_htab_traverse_info
*) data
;
1713 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1714 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1716 if (!hti
->info
->relocatable
)
1717 mips_elf_check_mips16_stubs (hti
->info
, h
);
1719 if (mips_elf_local_pic_function_p (h
))
1721 /* H is a function that might need $25 to be valid on entry.
1722 If we're creating a non-PIC relocatable object, mark H as
1723 being PIC. If we're creating a non-relocatable object with
1724 non-PIC branches and jumps to H, make sure that H has an la25
1726 if (hti
->info
->relocatable
)
1728 if (!PIC_OBJECT_P (hti
->output_bfd
))
1729 h
->root
.other
= ELF_ST_SET_MIPS_PIC (h
->root
.other
);
1731 else if (h
->has_nonpic_branches
&& !mips_elf_add_la25_stub (hti
->info
, h
))
1740 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
1741 Most mips16 instructions are 16 bits, but these instructions
1744 The format of these instructions is:
1746 +--------------+--------------------------------+
1747 | JALX | X| Imm 20:16 | Imm 25:21 |
1748 +--------------+--------------------------------+
1750 +-----------------------------------------------+
1752 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
1753 Note that the immediate value in the first word is swapped.
1755 When producing a relocatable object file, R_MIPS16_26 is
1756 handled mostly like R_MIPS_26. In particular, the addend is
1757 stored as a straight 26-bit value in a 32-bit instruction.
1758 (gas makes life simpler for itself by never adjusting a
1759 R_MIPS16_26 reloc to be against a section, so the addend is
1760 always zero). However, the 32 bit instruction is stored as 2
1761 16-bit values, rather than a single 32-bit value. In a
1762 big-endian file, the result is the same; in a little-endian
1763 file, the two 16-bit halves of the 32 bit value are swapped.
1764 This is so that a disassembler can recognize the jal
1767 When doing a final link, R_MIPS16_26 is treated as a 32 bit
1768 instruction stored as two 16-bit values. The addend A is the
1769 contents of the targ26 field. The calculation is the same as
1770 R_MIPS_26. When storing the calculated value, reorder the
1771 immediate value as shown above, and don't forget to store the
1772 value as two 16-bit values.
1774 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
1778 +--------+----------------------+
1782 +--------+----------------------+
1785 +----------+------+-------------+
1789 +----------+--------------------+
1790 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
1791 ((sub1 << 16) | sub2)).
1793 When producing a relocatable object file, the calculation is
1794 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1795 When producing a fully linked file, the calculation is
1796 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1797 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
1799 The table below lists the other MIPS16 instruction relocations.
1800 Each one is calculated in the same way as the non-MIPS16 relocation
1801 given on the right, but using the extended MIPS16 layout of 16-bit
1804 R_MIPS16_GPREL R_MIPS_GPREL16
1805 R_MIPS16_GOT16 R_MIPS_GOT16
1806 R_MIPS16_CALL16 R_MIPS_CALL16
1807 R_MIPS16_HI16 R_MIPS_HI16
1808 R_MIPS16_LO16 R_MIPS_LO16
1810 A typical instruction will have a format like this:
1812 +--------------+--------------------------------+
1813 | EXTEND | Imm 10:5 | Imm 15:11 |
1814 +--------------+--------------------------------+
1815 | Major | rx | ry | Imm 4:0 |
1816 +--------------+--------------------------------+
1818 EXTEND is the five bit value 11110. Major is the instruction
1821 All we need to do here is shuffle the bits appropriately.
1822 As above, the two 16-bit halves must be swapped on a
1823 little-endian system. */
1825 static inline bfd_boolean
1826 mips16_reloc_p (int r_type
)
1831 case R_MIPS16_GPREL
:
1832 case R_MIPS16_GOT16
:
1833 case R_MIPS16_CALL16
:
1843 static inline bfd_boolean
1844 got16_reloc_p (int r_type
)
1846 return r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS16_GOT16
;
1849 static inline bfd_boolean
1850 call16_reloc_p (int r_type
)
1852 return r_type
== R_MIPS_CALL16
|| r_type
== R_MIPS16_CALL16
;
1855 static inline bfd_boolean
1856 hi16_reloc_p (int r_type
)
1858 return r_type
== R_MIPS_HI16
|| r_type
== R_MIPS16_HI16
;
1861 static inline bfd_boolean
1862 lo16_reloc_p (int r_type
)
1864 return r_type
== R_MIPS_LO16
|| r_type
== R_MIPS16_LO16
;
1867 static inline bfd_boolean
1868 mips16_call_reloc_p (int r_type
)
1870 return r_type
== R_MIPS16_26
|| r_type
== R_MIPS16_CALL16
;
1874 _bfd_mips16_elf_reloc_unshuffle (bfd
*abfd
, int r_type
,
1875 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1877 bfd_vma extend
, insn
, val
;
1879 if (!mips16_reloc_p (r_type
))
1882 /* Pick up the mips16 extend instruction and the real instruction. */
1883 extend
= bfd_get_16 (abfd
, data
);
1884 insn
= bfd_get_16 (abfd
, data
+ 2);
1885 if (r_type
== R_MIPS16_26
)
1888 val
= ((extend
& 0xfc00) << 16) | ((extend
& 0x3e0) << 11)
1889 | ((extend
& 0x1f) << 21) | insn
;
1891 val
= extend
<< 16 | insn
;
1894 val
= ((extend
& 0xf800) << 16) | ((insn
& 0xffe0) << 11)
1895 | ((extend
& 0x1f) << 11) | (extend
& 0x7e0) | (insn
& 0x1f);
1896 bfd_put_32 (abfd
, val
, data
);
1900 _bfd_mips16_elf_reloc_shuffle (bfd
*abfd
, int r_type
,
1901 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1903 bfd_vma extend
, insn
, val
;
1905 if (!mips16_reloc_p (r_type
))
1908 val
= bfd_get_32 (abfd
, data
);
1909 if (r_type
== R_MIPS16_26
)
1913 insn
= val
& 0xffff;
1914 extend
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
1915 | ((val
>> 21) & 0x1f);
1919 insn
= val
& 0xffff;
1925 insn
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
1926 extend
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
1928 bfd_put_16 (abfd
, insn
, data
+ 2);
1929 bfd_put_16 (abfd
, extend
, data
);
1932 bfd_reloc_status_type
1933 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
1934 arelent
*reloc_entry
, asection
*input_section
,
1935 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
1939 bfd_reloc_status_type status
;
1941 if (bfd_is_com_section (symbol
->section
))
1944 relocation
= symbol
->value
;
1946 relocation
+= symbol
->section
->output_section
->vma
;
1947 relocation
+= symbol
->section
->output_offset
;
1949 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1950 return bfd_reloc_outofrange
;
1952 /* Set val to the offset into the section or symbol. */
1953 val
= reloc_entry
->addend
;
1955 _bfd_mips_elf_sign_extend (val
, 16);
1957 /* Adjust val for the final section location and GP value. If we
1958 are producing relocatable output, we don't want to do this for
1959 an external symbol. */
1961 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1962 val
+= relocation
- gp
;
1964 if (reloc_entry
->howto
->partial_inplace
)
1966 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1968 + reloc_entry
->address
);
1969 if (status
!= bfd_reloc_ok
)
1973 reloc_entry
->addend
= val
;
1976 reloc_entry
->address
+= input_section
->output_offset
;
1978 return bfd_reloc_ok
;
1981 /* Used to store a REL high-part relocation such as R_MIPS_HI16 or
1982 R_MIPS_GOT16. REL is the relocation, INPUT_SECTION is the section
1983 that contains the relocation field and DATA points to the start of
1988 struct mips_hi16
*next
;
1990 asection
*input_section
;
1994 /* FIXME: This should not be a static variable. */
1996 static struct mips_hi16
*mips_hi16_list
;
1998 /* A howto special_function for REL *HI16 relocations. We can only
1999 calculate the correct value once we've seen the partnering
2000 *LO16 relocation, so just save the information for later.
2002 The ABI requires that the *LO16 immediately follow the *HI16.
2003 However, as a GNU extension, we permit an arbitrary number of
2004 *HI16s to be associated with a single *LO16. This significantly
2005 simplies the relocation handling in gcc. */
2007 bfd_reloc_status_type
2008 _bfd_mips_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2009 asymbol
*symbol ATTRIBUTE_UNUSED
, void *data
,
2010 asection
*input_section
, bfd
*output_bfd
,
2011 char **error_message ATTRIBUTE_UNUSED
)
2013 struct mips_hi16
*n
;
2015 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2016 return bfd_reloc_outofrange
;
2018 n
= bfd_malloc (sizeof *n
);
2020 return bfd_reloc_outofrange
;
2022 n
->next
= mips_hi16_list
;
2024 n
->input_section
= input_section
;
2025 n
->rel
= *reloc_entry
;
2028 if (output_bfd
!= NULL
)
2029 reloc_entry
->address
+= input_section
->output_offset
;
2031 return bfd_reloc_ok
;
2034 /* A howto special_function for REL R_MIPS*_GOT16 relocations. This is just
2035 like any other 16-bit relocation when applied to global symbols, but is
2036 treated in the same as R_MIPS_HI16 when applied to local symbols. */
2038 bfd_reloc_status_type
2039 _bfd_mips_elf_got16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2040 void *data
, asection
*input_section
,
2041 bfd
*output_bfd
, char **error_message
)
2043 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
2044 || bfd_is_und_section (bfd_get_section (symbol
))
2045 || bfd_is_com_section (bfd_get_section (symbol
)))
2046 /* The relocation is against a global symbol. */
2047 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2048 input_section
, output_bfd
,
2051 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
2052 input_section
, output_bfd
, error_message
);
2055 /* A howto special_function for REL *LO16 relocations. The *LO16 itself
2056 is a straightforward 16 bit inplace relocation, but we must deal with
2057 any partnering high-part relocations as well. */
2059 bfd_reloc_status_type
2060 _bfd_mips_elf_lo16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2061 void *data
, asection
*input_section
,
2062 bfd
*output_bfd
, char **error_message
)
2065 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2067 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2068 return bfd_reloc_outofrange
;
2070 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2072 vallo
= bfd_get_32 (abfd
, location
);
2073 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2076 while (mips_hi16_list
!= NULL
)
2078 bfd_reloc_status_type ret
;
2079 struct mips_hi16
*hi
;
2081 hi
= mips_hi16_list
;
2083 /* R_MIPS*_GOT16 relocations are something of a special case. We
2084 want to install the addend in the same way as for a R_MIPS*_HI16
2085 relocation (with a rightshift of 16). However, since GOT16
2086 relocations can also be used with global symbols, their howto
2087 has a rightshift of 0. */
2088 if (hi
->rel
.howto
->type
== R_MIPS_GOT16
)
2089 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS_HI16
, FALSE
);
2090 else if (hi
->rel
.howto
->type
== R_MIPS16_GOT16
)
2091 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS16_HI16
, FALSE
);
2093 /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
2094 carry or borrow will induce a change of +1 or -1 in the high part. */
2095 hi
->rel
.addend
+= (vallo
+ 0x8000) & 0xffff;
2097 ret
= _bfd_mips_elf_generic_reloc (abfd
, &hi
->rel
, symbol
, hi
->data
,
2098 hi
->input_section
, output_bfd
,
2100 if (ret
!= bfd_reloc_ok
)
2103 mips_hi16_list
= hi
->next
;
2107 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2108 input_section
, output_bfd
,
2112 /* A generic howto special_function. This calculates and installs the
2113 relocation itself, thus avoiding the oft-discussed problems in
2114 bfd_perform_relocation and bfd_install_relocation. */
2116 bfd_reloc_status_type
2117 _bfd_mips_elf_generic_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2118 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
2119 asection
*input_section
, bfd
*output_bfd
,
2120 char **error_message ATTRIBUTE_UNUSED
)
2123 bfd_reloc_status_type status
;
2124 bfd_boolean relocatable
;
2126 relocatable
= (output_bfd
!= NULL
);
2128 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2129 return bfd_reloc_outofrange
;
2131 /* Build up the field adjustment in VAL. */
2133 if (!relocatable
|| (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2135 /* Either we're calculating the final field value or we have a
2136 relocation against a section symbol. Add in the section's
2137 offset or address. */
2138 val
+= symbol
->section
->output_section
->vma
;
2139 val
+= symbol
->section
->output_offset
;
2144 /* We're calculating the final field value. Add in the symbol's value
2145 and, if pc-relative, subtract the address of the field itself. */
2146 val
+= symbol
->value
;
2147 if (reloc_entry
->howto
->pc_relative
)
2149 val
-= input_section
->output_section
->vma
;
2150 val
-= input_section
->output_offset
;
2151 val
-= reloc_entry
->address
;
2155 /* VAL is now the final adjustment. If we're keeping this relocation
2156 in the output file, and if the relocation uses a separate addend,
2157 we just need to add VAL to that addend. Otherwise we need to add
2158 VAL to the relocation field itself. */
2159 if (relocatable
&& !reloc_entry
->howto
->partial_inplace
)
2160 reloc_entry
->addend
+= val
;
2163 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2165 /* Add in the separate addend, if any. */
2166 val
+= reloc_entry
->addend
;
2168 /* Add VAL to the relocation field. */
2169 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2171 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
2173 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2176 if (status
!= bfd_reloc_ok
)
2181 reloc_entry
->address
+= input_section
->output_offset
;
2183 return bfd_reloc_ok
;
2186 /* Swap an entry in a .gptab section. Note that these routines rely
2187 on the equivalence of the two elements of the union. */
2190 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
2193 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
2194 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
2198 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
2199 Elf32_External_gptab
*ex
)
2201 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
2202 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
2206 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
2207 Elf32_External_compact_rel
*ex
)
2209 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
2210 H_PUT_32 (abfd
, in
->num
, ex
->num
);
2211 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
2212 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
2213 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
2214 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
2218 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
2219 Elf32_External_crinfo
*ex
)
2223 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2224 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2225 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2226 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2227 H_PUT_32 (abfd
, l
, ex
->info
);
2228 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
2229 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
2232 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2233 routines swap this structure in and out. They are used outside of
2234 BFD, so they are globally visible. */
2237 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
2240 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2241 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2242 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2243 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2244 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2245 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
2249 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
2250 Elf32_External_RegInfo
*ex
)
2252 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2253 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2254 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2255 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2256 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2257 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2260 /* In the 64 bit ABI, the .MIPS.options section holds register
2261 information in an Elf64_Reginfo structure. These routines swap
2262 them in and out. They are globally visible because they are used
2263 outside of BFD. These routines are here so that gas can call them
2264 without worrying about whether the 64 bit ABI has been included. */
2267 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
2268 Elf64_Internal_RegInfo
*in
)
2270 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2271 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
2272 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2273 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2274 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2275 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2276 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
2280 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
2281 Elf64_External_RegInfo
*ex
)
2283 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2284 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
2285 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2286 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2287 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2288 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2289 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2292 /* Swap in an options header. */
2295 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
2296 Elf_Internal_Options
*in
)
2298 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
2299 in
->size
= H_GET_8 (abfd
, ex
->size
);
2300 in
->section
= H_GET_16 (abfd
, ex
->section
);
2301 in
->info
= H_GET_32 (abfd
, ex
->info
);
2304 /* Swap out an options header. */
2307 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
2308 Elf_External_Options
*ex
)
2310 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
2311 H_PUT_8 (abfd
, in
->size
, ex
->size
);
2312 H_PUT_16 (abfd
, in
->section
, ex
->section
);
2313 H_PUT_32 (abfd
, in
->info
, ex
->info
);
2316 /* This function is called via qsort() to sort the dynamic relocation
2317 entries by increasing r_symndx value. */
2320 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
2322 Elf_Internal_Rela int_reloc1
;
2323 Elf_Internal_Rela int_reloc2
;
2326 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
2327 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
2329 diff
= ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
2333 if (int_reloc1
.r_offset
< int_reloc2
.r_offset
)
2335 if (int_reloc1
.r_offset
> int_reloc2
.r_offset
)
2340 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
2343 sort_dynamic_relocs_64 (const void *arg1 ATTRIBUTE_UNUSED
,
2344 const void *arg2 ATTRIBUTE_UNUSED
)
2347 Elf_Internal_Rela int_reloc1
[3];
2348 Elf_Internal_Rela int_reloc2
[3];
2350 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2351 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
2352 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2353 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
2355 if (ELF64_R_SYM (int_reloc1
[0].r_info
) < ELF64_R_SYM (int_reloc2
[0].r_info
))
2357 if (ELF64_R_SYM (int_reloc1
[0].r_info
) > ELF64_R_SYM (int_reloc2
[0].r_info
))
2360 if (int_reloc1
[0].r_offset
< int_reloc2
[0].r_offset
)
2362 if (int_reloc1
[0].r_offset
> int_reloc2
[0].r_offset
)
2371 /* This routine is used to write out ECOFF debugging external symbol
2372 information. It is called via mips_elf_link_hash_traverse. The
2373 ECOFF external symbol information must match the ELF external
2374 symbol information. Unfortunately, at this point we don't know
2375 whether a symbol is required by reloc information, so the two
2376 tables may wind up being different. We must sort out the external
2377 symbol information before we can set the final size of the .mdebug
2378 section, and we must set the size of the .mdebug section before we
2379 can relocate any sections, and we can't know which symbols are
2380 required by relocation until we relocate the sections.
2381 Fortunately, it is relatively unlikely that any symbol will be
2382 stripped but required by a reloc. In particular, it can not happen
2383 when generating a final executable. */
2386 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
2388 struct extsym_info
*einfo
= data
;
2390 asection
*sec
, *output_section
;
2392 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2393 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2395 if (h
->root
.indx
== -2)
2397 else if ((h
->root
.def_dynamic
2398 || h
->root
.ref_dynamic
2399 || h
->root
.type
== bfd_link_hash_new
)
2400 && !h
->root
.def_regular
2401 && !h
->root
.ref_regular
)
2403 else if (einfo
->info
->strip
== strip_all
2404 || (einfo
->info
->strip
== strip_some
2405 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2406 h
->root
.root
.root
.string
,
2407 FALSE
, FALSE
) == NULL
))
2415 if (h
->esym
.ifd
== -2)
2418 h
->esym
.cobol_main
= 0;
2419 h
->esym
.weakext
= 0;
2420 h
->esym
.reserved
= 0;
2421 h
->esym
.ifd
= ifdNil
;
2422 h
->esym
.asym
.value
= 0;
2423 h
->esym
.asym
.st
= stGlobal
;
2425 if (h
->root
.root
.type
== bfd_link_hash_undefined
2426 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
2430 /* Use undefined class. Also, set class and type for some
2432 name
= h
->root
.root
.root
.string
;
2433 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2434 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2436 h
->esym
.asym
.sc
= scData
;
2437 h
->esym
.asym
.st
= stLabel
;
2438 h
->esym
.asym
.value
= 0;
2440 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2442 h
->esym
.asym
.sc
= scAbs
;
2443 h
->esym
.asym
.st
= stLabel
;
2444 h
->esym
.asym
.value
=
2445 mips_elf_hash_table (einfo
->info
)->procedure_count
;
2447 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
2449 h
->esym
.asym
.sc
= scAbs
;
2450 h
->esym
.asym
.st
= stLabel
;
2451 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
2454 h
->esym
.asym
.sc
= scUndefined
;
2456 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2457 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2458 h
->esym
.asym
.sc
= scAbs
;
2463 sec
= h
->root
.root
.u
.def
.section
;
2464 output_section
= sec
->output_section
;
2466 /* When making a shared library and symbol h is the one from
2467 the another shared library, OUTPUT_SECTION may be null. */
2468 if (output_section
== NULL
)
2469 h
->esym
.asym
.sc
= scUndefined
;
2472 name
= bfd_section_name (output_section
->owner
, output_section
);
2474 if (strcmp (name
, ".text") == 0)
2475 h
->esym
.asym
.sc
= scText
;
2476 else if (strcmp (name
, ".data") == 0)
2477 h
->esym
.asym
.sc
= scData
;
2478 else if (strcmp (name
, ".sdata") == 0)
2479 h
->esym
.asym
.sc
= scSData
;
2480 else if (strcmp (name
, ".rodata") == 0
2481 || strcmp (name
, ".rdata") == 0)
2482 h
->esym
.asym
.sc
= scRData
;
2483 else if (strcmp (name
, ".bss") == 0)
2484 h
->esym
.asym
.sc
= scBss
;
2485 else if (strcmp (name
, ".sbss") == 0)
2486 h
->esym
.asym
.sc
= scSBss
;
2487 else if (strcmp (name
, ".init") == 0)
2488 h
->esym
.asym
.sc
= scInit
;
2489 else if (strcmp (name
, ".fini") == 0)
2490 h
->esym
.asym
.sc
= scFini
;
2492 h
->esym
.asym
.sc
= scAbs
;
2496 h
->esym
.asym
.reserved
= 0;
2497 h
->esym
.asym
.index
= indexNil
;
2500 if (h
->root
.root
.type
== bfd_link_hash_common
)
2501 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2502 else if (h
->root
.root
.type
== bfd_link_hash_defined
2503 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2505 if (h
->esym
.asym
.sc
== scCommon
)
2506 h
->esym
.asym
.sc
= scBss
;
2507 else if (h
->esym
.asym
.sc
== scSCommon
)
2508 h
->esym
.asym
.sc
= scSBss
;
2510 sec
= h
->root
.root
.u
.def
.section
;
2511 output_section
= sec
->output_section
;
2512 if (output_section
!= NULL
)
2513 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2514 + sec
->output_offset
2515 + output_section
->vma
);
2517 h
->esym
.asym
.value
= 0;
2521 struct mips_elf_link_hash_entry
*hd
= h
;
2523 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
2524 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2526 if (hd
->needs_lazy_stub
)
2528 /* Set type and value for a symbol with a function stub. */
2529 h
->esym
.asym
.st
= stProc
;
2530 sec
= hd
->root
.root
.u
.def
.section
;
2532 h
->esym
.asym
.value
= 0;
2535 output_section
= sec
->output_section
;
2536 if (output_section
!= NULL
)
2537 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
2538 + sec
->output_offset
2539 + output_section
->vma
);
2541 h
->esym
.asym
.value
= 0;
2546 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2547 h
->root
.root
.root
.string
,
2550 einfo
->failed
= TRUE
;
2557 /* A comparison routine used to sort .gptab entries. */
2560 gptab_compare (const void *p1
, const void *p2
)
2562 const Elf32_gptab
*a1
= p1
;
2563 const Elf32_gptab
*a2
= p2
;
2565 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
2568 /* Functions to manage the got entry hash table. */
2570 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
2573 static INLINE hashval_t
2574 mips_elf_hash_bfd_vma (bfd_vma addr
)
2577 return addr
+ (addr
>> 32);
2583 /* got_entries only match if they're identical, except for gotidx, so
2584 use all fields to compute the hash, and compare the appropriate
2588 mips_elf_got_entry_hash (const void *entry_
)
2590 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2592 return entry
->symndx
2593 + ((entry
->tls_type
& GOT_TLS_LDM
) << 17)
2594 + (! entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
2596 + (entry
->symndx
>= 0 ? mips_elf_hash_bfd_vma (entry
->d
.addend
)
2597 : entry
->d
.h
->root
.root
.root
.hash
));
2601 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
2603 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2604 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2606 /* An LDM entry can only match another LDM entry. */
2607 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2610 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
2611 && (! e1
->abfd
? e1
->d
.address
== e2
->d
.address
2612 : e1
->symndx
>= 0 ? e1
->d
.addend
== e2
->d
.addend
2613 : e1
->d
.h
== e2
->d
.h
);
2616 /* multi_got_entries are still a match in the case of global objects,
2617 even if the input bfd in which they're referenced differs, so the
2618 hash computation and compare functions are adjusted
2622 mips_elf_multi_got_entry_hash (const void *entry_
)
2624 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2626 return entry
->symndx
2628 ? mips_elf_hash_bfd_vma (entry
->d
.address
)
2629 : entry
->symndx
>= 0
2630 ? ((entry
->tls_type
& GOT_TLS_LDM
)
2631 ? (GOT_TLS_LDM
<< 17)
2633 + mips_elf_hash_bfd_vma (entry
->d
.addend
)))
2634 : entry
->d
.h
->root
.root
.root
.hash
);
2638 mips_elf_multi_got_entry_eq (const void *entry1
, const void *entry2
)
2640 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2641 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2643 /* Any two LDM entries match. */
2644 if (e1
->tls_type
& e2
->tls_type
& GOT_TLS_LDM
)
2647 /* Nothing else matches an LDM entry. */
2648 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2651 return e1
->symndx
== e2
->symndx
2652 && (e1
->symndx
>= 0 ? e1
->abfd
== e2
->abfd
&& e1
->d
.addend
== e2
->d
.addend
2653 : e1
->abfd
== NULL
|| e2
->abfd
== NULL
2654 ? e1
->abfd
== e2
->abfd
&& e1
->d
.address
== e2
->d
.address
2655 : e1
->d
.h
== e2
->d
.h
);
2659 mips_got_page_entry_hash (const void *entry_
)
2661 const struct mips_got_page_entry
*entry
;
2663 entry
= (const struct mips_got_page_entry
*) entry_
;
2664 return entry
->abfd
->id
+ entry
->symndx
;
2668 mips_got_page_entry_eq (const void *entry1_
, const void *entry2_
)
2670 const struct mips_got_page_entry
*entry1
, *entry2
;
2672 entry1
= (const struct mips_got_page_entry
*) entry1_
;
2673 entry2
= (const struct mips_got_page_entry
*) entry2_
;
2674 return entry1
->abfd
== entry2
->abfd
&& entry1
->symndx
== entry2
->symndx
;
2677 /* Return the dynamic relocation section. If it doesn't exist, try to
2678 create a new it if CREATE_P, otherwise return NULL. Also return NULL
2679 if creation fails. */
2682 mips_elf_rel_dyn_section (struct bfd_link_info
*info
, bfd_boolean create_p
)
2688 dname
= MIPS_ELF_REL_DYN_NAME (info
);
2689 dynobj
= elf_hash_table (info
)->dynobj
;
2690 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
2691 if (sreloc
== NULL
&& create_p
)
2693 sreloc
= bfd_make_section_with_flags (dynobj
, dname
,
2698 | SEC_LINKER_CREATED
2701 || ! bfd_set_section_alignment (dynobj
, sreloc
,
2702 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
2708 /* Count the number of relocations needed for a TLS GOT entry, with
2709 access types from TLS_TYPE, and symbol H (or a local symbol if H
2713 mips_tls_got_relocs (struct bfd_link_info
*info
, unsigned char tls_type
,
2714 struct elf_link_hash_entry
*h
)
2718 bfd_boolean need_relocs
= FALSE
;
2719 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2721 if (h
&& WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2722 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, h
)))
2725 if ((info
->shared
|| indx
!= 0)
2727 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2728 || h
->root
.type
!= bfd_link_hash_undefweak
))
2734 if (tls_type
& GOT_TLS_GD
)
2741 if (tls_type
& GOT_TLS_IE
)
2744 if ((tls_type
& GOT_TLS_LDM
) && info
->shared
)
2750 /* Count the number of TLS relocations required for the GOT entry in
2751 ARG1, if it describes a local symbol. */
2754 mips_elf_count_local_tls_relocs (void **arg1
, void *arg2
)
2756 struct mips_got_entry
*entry
= * (struct mips_got_entry
**) arg1
;
2757 struct mips_elf_count_tls_arg
*arg
= arg2
;
2759 if (entry
->abfd
!= NULL
&& entry
->symndx
!= -1)
2760 arg
->needed
+= mips_tls_got_relocs (arg
->info
, entry
->tls_type
, NULL
);
2765 /* Count the number of TLS GOT entries required for the global (or
2766 forced-local) symbol in ARG1. */
2769 mips_elf_count_global_tls_entries (void *arg1
, void *arg2
)
2771 struct mips_elf_link_hash_entry
*hm
2772 = (struct mips_elf_link_hash_entry
*) arg1
;
2773 struct mips_elf_count_tls_arg
*arg
= arg2
;
2775 if (hm
->tls_type
& GOT_TLS_GD
)
2777 if (hm
->tls_type
& GOT_TLS_IE
)
2783 /* Count the number of TLS relocations required for the global (or
2784 forced-local) symbol in ARG1. */
2787 mips_elf_count_global_tls_relocs (void *arg1
, void *arg2
)
2789 struct mips_elf_link_hash_entry
*hm
2790 = (struct mips_elf_link_hash_entry
*) arg1
;
2791 struct mips_elf_count_tls_arg
*arg
= arg2
;
2793 arg
->needed
+= mips_tls_got_relocs (arg
->info
, hm
->tls_type
, &hm
->root
);
2798 /* Output a simple dynamic relocation into SRELOC. */
2801 mips_elf_output_dynamic_relocation (bfd
*output_bfd
,
2803 unsigned long reloc_index
,
2808 Elf_Internal_Rela rel
[3];
2810 memset (rel
, 0, sizeof (rel
));
2812 rel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, r_type
);
2813 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
2815 if (ABI_64_P (output_bfd
))
2817 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
2818 (output_bfd
, &rel
[0],
2820 + reloc_index
* sizeof (Elf64_Mips_External_Rel
)));
2823 bfd_elf32_swap_reloc_out
2824 (output_bfd
, &rel
[0],
2826 + reloc_index
* sizeof (Elf32_External_Rel
)));
2829 /* Initialize a set of TLS GOT entries for one symbol. */
2832 mips_elf_initialize_tls_slots (bfd
*abfd
, bfd_vma got_offset
,
2833 unsigned char *tls_type_p
,
2834 struct bfd_link_info
*info
,
2835 struct mips_elf_link_hash_entry
*h
,
2838 struct mips_elf_link_hash_table
*htab
;
2840 asection
*sreloc
, *sgot
;
2841 bfd_vma offset
, offset2
;
2842 bfd_boolean need_relocs
= FALSE
;
2844 htab
= mips_elf_hash_table (info
);
2850 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2852 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, &h
->root
)
2853 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
2854 indx
= h
->root
.dynindx
;
2857 if (*tls_type_p
& GOT_TLS_DONE
)
2860 if ((info
->shared
|| indx
!= 0)
2862 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
2863 || h
->root
.type
!= bfd_link_hash_undefweak
))
2866 /* MINUS_ONE means the symbol is not defined in this object. It may not
2867 be defined at all; assume that the value doesn't matter in that
2868 case. Otherwise complain if we would use the value. */
2869 BFD_ASSERT (value
!= MINUS_ONE
|| (indx
!= 0 && need_relocs
)
2870 || h
->root
.root
.type
== bfd_link_hash_undefweak
);
2872 /* Emit necessary relocations. */
2873 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
2875 /* General Dynamic. */
2876 if (*tls_type_p
& GOT_TLS_GD
)
2878 offset
= got_offset
;
2879 offset2
= offset
+ MIPS_ELF_GOT_SIZE (abfd
);
2883 mips_elf_output_dynamic_relocation
2884 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2885 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2886 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2889 mips_elf_output_dynamic_relocation
2890 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2891 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPREL64
: R_MIPS_TLS_DTPREL32
,
2892 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset2
);
2894 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2895 sgot
->contents
+ offset2
);
2899 MIPS_ELF_PUT_WORD (abfd
, 1,
2900 sgot
->contents
+ offset
);
2901 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2902 sgot
->contents
+ offset2
);
2905 got_offset
+= 2 * MIPS_ELF_GOT_SIZE (abfd
);
2908 /* Initial Exec model. */
2909 if (*tls_type_p
& GOT_TLS_IE
)
2911 offset
= got_offset
;
2916 MIPS_ELF_PUT_WORD (abfd
, value
- elf_hash_table (info
)->tls_sec
->vma
,
2917 sgot
->contents
+ offset
);
2919 MIPS_ELF_PUT_WORD (abfd
, 0,
2920 sgot
->contents
+ offset
);
2922 mips_elf_output_dynamic_relocation
2923 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2924 ABI_64_P (abfd
) ? R_MIPS_TLS_TPREL64
: R_MIPS_TLS_TPREL32
,
2925 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2928 MIPS_ELF_PUT_WORD (abfd
, value
- tprel_base (info
),
2929 sgot
->contents
+ offset
);
2932 if (*tls_type_p
& GOT_TLS_LDM
)
2934 /* The initial offset is zero, and the LD offsets will include the
2935 bias by DTP_OFFSET. */
2936 MIPS_ELF_PUT_WORD (abfd
, 0,
2937 sgot
->contents
+ got_offset
2938 + MIPS_ELF_GOT_SIZE (abfd
));
2941 MIPS_ELF_PUT_WORD (abfd
, 1,
2942 sgot
->contents
+ got_offset
);
2944 mips_elf_output_dynamic_relocation
2945 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2946 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2947 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
2950 *tls_type_p
|= GOT_TLS_DONE
;
2953 /* Return the GOT index to use for a relocation of type R_TYPE against
2954 a symbol accessed using TLS_TYPE models. The GOT entries for this
2955 symbol in this GOT start at GOT_INDEX. This function initializes the
2956 GOT entries and corresponding relocations. */
2959 mips_tls_got_index (bfd
*abfd
, bfd_vma got_index
, unsigned char *tls_type
,
2960 int r_type
, struct bfd_link_info
*info
,
2961 struct mips_elf_link_hash_entry
*h
, bfd_vma symbol
)
2963 BFD_ASSERT (r_type
== R_MIPS_TLS_GOTTPREL
|| r_type
== R_MIPS_TLS_GD
2964 || r_type
== R_MIPS_TLS_LDM
);
2966 mips_elf_initialize_tls_slots (abfd
, got_index
, tls_type
, info
, h
, symbol
);
2968 if (r_type
== R_MIPS_TLS_GOTTPREL
)
2970 BFD_ASSERT (*tls_type
& GOT_TLS_IE
);
2971 if (*tls_type
& GOT_TLS_GD
)
2972 return got_index
+ 2 * MIPS_ELF_GOT_SIZE (abfd
);
2977 if (r_type
== R_MIPS_TLS_GD
)
2979 BFD_ASSERT (*tls_type
& GOT_TLS_GD
);
2983 if (r_type
== R_MIPS_TLS_LDM
)
2985 BFD_ASSERT (*tls_type
& GOT_TLS_LDM
);
2992 /* Return the offset from _GLOBAL_OFFSET_TABLE_ of the .got.plt entry
2993 for global symbol H. .got.plt comes before the GOT, so the offset
2994 will be negative. */
2997 mips_elf_gotplt_index (struct bfd_link_info
*info
,
2998 struct elf_link_hash_entry
*h
)
3000 bfd_vma plt_index
, got_address
, got_value
;
3001 struct mips_elf_link_hash_table
*htab
;
3003 htab
= mips_elf_hash_table (info
);
3004 BFD_ASSERT (h
->plt
.offset
!= (bfd_vma
) -1);
3006 /* This function only works for VxWorks, because a non-VxWorks .got.plt
3007 section starts with reserved entries. */
3008 BFD_ASSERT (htab
->is_vxworks
);
3010 /* Calculate the index of the symbol's PLT entry. */
3011 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
3013 /* Calculate the address of the associated .got.plt entry. */
3014 got_address
= (htab
->sgotplt
->output_section
->vma
3015 + htab
->sgotplt
->output_offset
3018 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
3019 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
3020 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
3021 + htab
->root
.hgot
->root
.u
.def
.value
);
3023 return got_address
- got_value
;
3026 /* Return the GOT offset for address VALUE. If there is not yet a GOT
3027 entry for this value, create one. If R_SYMNDX refers to a TLS symbol,
3028 create a TLS GOT entry instead. Return -1 if no satisfactory GOT
3029 offset can be found. */
3032 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3033 bfd_vma value
, unsigned long r_symndx
,
3034 struct mips_elf_link_hash_entry
*h
, int r_type
)
3036 struct mips_elf_link_hash_table
*htab
;
3037 struct mips_got_entry
*entry
;
3039 htab
= mips_elf_hash_table (info
);
3040 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
,
3041 r_symndx
, h
, r_type
);
3045 if (TLS_RELOC_P (r_type
))
3047 if (entry
->symndx
== -1 && htab
->got_info
->next
== NULL
)
3048 /* A type (3) entry in the single-GOT case. We use the symbol's
3049 hash table entry to track the index. */
3050 return mips_tls_got_index (abfd
, h
->tls_got_offset
, &h
->tls_type
,
3051 r_type
, info
, h
, value
);
3053 return mips_tls_got_index (abfd
, entry
->gotidx
, &entry
->tls_type
,
3054 r_type
, info
, h
, value
);
3057 return entry
->gotidx
;
3060 /* Returns the GOT index for the global symbol indicated by H. */
3063 mips_elf_global_got_index (bfd
*abfd
, bfd
*ibfd
, struct elf_link_hash_entry
*h
,
3064 int r_type
, struct bfd_link_info
*info
)
3066 struct mips_elf_link_hash_table
*htab
;
3068 struct mips_got_info
*g
, *gg
;
3069 long global_got_dynindx
= 0;
3071 htab
= mips_elf_hash_table (info
);
3072 gg
= g
= htab
->got_info
;
3073 if (g
->bfd2got
&& ibfd
)
3075 struct mips_got_entry e
, *p
;
3077 BFD_ASSERT (h
->dynindx
>= 0);
3079 g
= mips_elf_got_for_ibfd (g
, ibfd
);
3080 if (g
->next
!= gg
|| TLS_RELOC_P (r_type
))
3084 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
3087 p
= htab_find (g
->got_entries
, &e
);
3089 BFD_ASSERT (p
->gotidx
> 0);
3091 if (TLS_RELOC_P (r_type
))
3093 bfd_vma value
= MINUS_ONE
;
3094 if ((h
->root
.type
== bfd_link_hash_defined
3095 || h
->root
.type
== bfd_link_hash_defweak
)
3096 && h
->root
.u
.def
.section
->output_section
)
3097 value
= (h
->root
.u
.def
.value
3098 + h
->root
.u
.def
.section
->output_offset
3099 + h
->root
.u
.def
.section
->output_section
->vma
);
3101 return mips_tls_got_index (abfd
, p
->gotidx
, &p
->tls_type
, r_type
,
3102 info
, e
.d
.h
, value
);
3109 if (gg
->global_gotsym
!= NULL
)
3110 global_got_dynindx
= gg
->global_gotsym
->dynindx
;
3112 if (TLS_RELOC_P (r_type
))
3114 struct mips_elf_link_hash_entry
*hm
3115 = (struct mips_elf_link_hash_entry
*) h
;
3116 bfd_vma value
= MINUS_ONE
;
3118 if ((h
->root
.type
== bfd_link_hash_defined
3119 || h
->root
.type
== bfd_link_hash_defweak
)
3120 && h
->root
.u
.def
.section
->output_section
)
3121 value
= (h
->root
.u
.def
.value
3122 + h
->root
.u
.def
.section
->output_offset
3123 + h
->root
.u
.def
.section
->output_section
->vma
);
3125 index
= mips_tls_got_index (abfd
, hm
->tls_got_offset
, &hm
->tls_type
,
3126 r_type
, info
, hm
, value
);
3130 /* Once we determine the global GOT entry with the lowest dynamic
3131 symbol table index, we must put all dynamic symbols with greater
3132 indices into the GOT. That makes it easy to calculate the GOT
3134 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
3135 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
3136 * MIPS_ELF_GOT_SIZE (abfd
));
3138 BFD_ASSERT (index
< htab
->sgot
->size
);
3143 /* Find a GOT page entry that points to within 32KB of VALUE. These
3144 entries are supposed to be placed at small offsets in the GOT, i.e.,
3145 within 32KB of GP. Return the index of the GOT entry, or -1 if no
3146 entry could be created. If OFFSETP is nonnull, use it to return the
3147 offset of the GOT entry from VALUE. */
3150 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3151 bfd_vma value
, bfd_vma
*offsetp
)
3153 bfd_vma page
, index
;
3154 struct mips_got_entry
*entry
;
3156 page
= (value
+ 0x8000) & ~(bfd_vma
) 0xffff;
3157 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, page
, 0,
3158 NULL
, R_MIPS_GOT_PAGE
);
3163 index
= entry
->gotidx
;
3166 *offsetp
= value
- entry
->d
.address
;
3171 /* Find a local GOT entry for an R_MIPS*_GOT16 relocation against VALUE.
3172 EXTERNAL is true if the relocation was against a global symbol
3173 that has been forced local. */
3176 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3177 bfd_vma value
, bfd_boolean external
)
3179 struct mips_got_entry
*entry
;
3181 /* GOT16 relocations against local symbols are followed by a LO16
3182 relocation; those against global symbols are not. Thus if the
3183 symbol was originally local, the GOT16 relocation should load the
3184 equivalent of %hi(VALUE), otherwise it should load VALUE itself. */
3186 value
= mips_elf_high (value
) << 16;
3188 /* It doesn't matter whether the original relocation was R_MIPS_GOT16,
3189 R_MIPS16_GOT16, R_MIPS_CALL16, etc. The format of the entry is the
3190 same in all cases. */
3191 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
, 0,
3192 NULL
, R_MIPS_GOT16
);
3194 return entry
->gotidx
;
3199 /* Returns the offset for the entry at the INDEXth position
3203 mips_elf_got_offset_from_index (struct bfd_link_info
*info
, bfd
*output_bfd
,
3204 bfd
*input_bfd
, bfd_vma index
)
3206 struct mips_elf_link_hash_table
*htab
;
3210 htab
= mips_elf_hash_table (info
);
3212 gp
= _bfd_get_gp_value (output_bfd
)
3213 + mips_elf_adjust_gp (output_bfd
, htab
->got_info
, input_bfd
);
3215 return sgot
->output_section
->vma
+ sgot
->output_offset
+ index
- gp
;
3218 /* Create and return a local GOT entry for VALUE, which was calculated
3219 from a symbol belonging to INPUT_SECTON. Return NULL if it could not
3220 be created. If R_SYMNDX refers to a TLS symbol, create a TLS entry
3223 static struct mips_got_entry
*
3224 mips_elf_create_local_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
3225 bfd
*ibfd
, bfd_vma value
,
3226 unsigned long r_symndx
,
3227 struct mips_elf_link_hash_entry
*h
,
3230 struct mips_got_entry entry
, **loc
;
3231 struct mips_got_info
*g
;
3232 struct mips_elf_link_hash_table
*htab
;
3234 htab
= mips_elf_hash_table (info
);
3238 entry
.d
.address
= value
;
3241 g
= mips_elf_got_for_ibfd (htab
->got_info
, ibfd
);
3244 g
= mips_elf_got_for_ibfd (htab
->got_info
, abfd
);
3245 BFD_ASSERT (g
!= NULL
);
3248 /* We might have a symbol, H, if it has been forced local. Use the
3249 global entry then. It doesn't matter whether an entry is local
3250 or global for TLS, since the dynamic linker does not
3251 automatically relocate TLS GOT entries. */
3252 BFD_ASSERT (h
== NULL
|| h
->root
.forced_local
);
3253 if (TLS_RELOC_P (r_type
))
3255 struct mips_got_entry
*p
;
3258 if (r_type
== R_MIPS_TLS_LDM
)
3260 entry
.tls_type
= GOT_TLS_LDM
;
3266 entry
.symndx
= r_symndx
;
3272 p
= (struct mips_got_entry
*)
3273 htab_find (g
->got_entries
, &entry
);
3279 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
3284 entry
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
3287 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3292 memcpy (*loc
, &entry
, sizeof entry
);
3294 if (g
->assigned_gotno
> g
->local_gotno
)
3296 (*loc
)->gotidx
= -1;
3297 /* We didn't allocate enough space in the GOT. */
3298 (*_bfd_error_handler
)
3299 (_("not enough GOT space for local GOT entries"));
3300 bfd_set_error (bfd_error_bad_value
);
3304 MIPS_ELF_PUT_WORD (abfd
, value
,
3305 (htab
->sgot
->contents
+ entry
.gotidx
));
3307 /* These GOT entries need a dynamic relocation on VxWorks. */
3308 if (htab
->is_vxworks
)
3310 Elf_Internal_Rela outrel
;
3313 bfd_vma got_address
;
3315 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3316 got_address
= (htab
->sgot
->output_section
->vma
3317 + htab
->sgot
->output_offset
3320 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
3321 outrel
.r_offset
= got_address
;
3322 outrel
.r_info
= ELF32_R_INFO (STN_UNDEF
, R_MIPS_32
);
3323 outrel
.r_addend
= value
;
3324 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
3330 /* Return the number of dynamic section symbols required by OUTPUT_BFD.
3331 The number might be exact or a worst-case estimate, depending on how
3332 much information is available to elf_backend_omit_section_dynsym at
3333 the current linking stage. */
3335 static bfd_size_type
3336 count_section_dynsyms (bfd
*output_bfd
, struct bfd_link_info
*info
)
3338 bfd_size_type count
;
3341 if (info
->shared
|| elf_hash_table (info
)->is_relocatable_executable
)
3344 const struct elf_backend_data
*bed
;
3346 bed
= get_elf_backend_data (output_bfd
);
3347 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
3348 if ((p
->flags
& SEC_EXCLUDE
) == 0
3349 && (p
->flags
& SEC_ALLOC
) != 0
3350 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
3356 /* Sort the dynamic symbol table so that symbols that need GOT entries
3357 appear towards the end. */
3360 mips_elf_sort_hash_table (bfd
*abfd
, struct bfd_link_info
*info
)
3362 struct mips_elf_link_hash_table
*htab
;
3363 struct mips_elf_hash_sort_data hsd
;
3364 struct mips_got_info
*g
;
3366 if (elf_hash_table (info
)->dynsymcount
== 0)
3369 htab
= mips_elf_hash_table (info
);
3375 hsd
.max_unref_got_dynindx
3376 = hsd
.min_got_dynindx
3377 = (elf_hash_table (info
)->dynsymcount
- g
->reloc_only_gotno
);
3378 hsd
.max_non_got_dynindx
= count_section_dynsyms (abfd
, info
) + 1;
3379 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
3380 elf_hash_table (info
)),
3381 mips_elf_sort_hash_table_f
,
3384 /* There should have been enough room in the symbol table to
3385 accommodate both the GOT and non-GOT symbols. */
3386 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
3387 BFD_ASSERT ((unsigned long) hsd
.max_unref_got_dynindx
3388 == elf_hash_table (info
)->dynsymcount
);
3389 BFD_ASSERT (elf_hash_table (info
)->dynsymcount
- hsd
.min_got_dynindx
3390 == g
->global_gotno
);
3392 /* Now we know which dynamic symbol has the lowest dynamic symbol
3393 table index in the GOT. */
3394 g
->global_gotsym
= hsd
.low
;
3399 /* If H needs a GOT entry, assign it the highest available dynamic
3400 index. Otherwise, assign it the lowest available dynamic
3404 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
3406 struct mips_elf_hash_sort_data
*hsd
= data
;
3408 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3409 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3411 /* Symbols without dynamic symbol table entries aren't interesting
3413 if (h
->root
.dynindx
== -1)
3416 switch (h
->global_got_area
)
3419 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
3423 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
3425 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
3426 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3429 case GGA_RELOC_ONLY
:
3430 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
3432 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
3433 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3434 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
3441 /* If H is a symbol that needs a global GOT entry, but has a dynamic
3442 symbol table index lower than any we've seen to date, record it for
3446 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
3447 bfd
*abfd
, struct bfd_link_info
*info
,
3448 unsigned char tls_flag
)
3450 struct mips_elf_link_hash_table
*htab
;
3451 struct mips_elf_link_hash_entry
*hmips
;
3452 struct mips_got_entry entry
, **loc
;
3453 struct mips_got_info
*g
;
3455 htab
= mips_elf_hash_table (info
);
3456 hmips
= (struct mips_elf_link_hash_entry
*) h
;
3458 /* A global symbol in the GOT must also be in the dynamic symbol
3460 if (h
->dynindx
== -1)
3462 switch (ELF_ST_VISIBILITY (h
->other
))
3466 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
3469 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3473 /* Make sure we have a GOT to put this entry into. */
3475 BFD_ASSERT (g
!= NULL
);
3479 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
3482 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
3485 /* If we've already marked this entry as needing GOT space, we don't
3486 need to do it again. */
3489 (*loc
)->tls_type
|= tls_flag
;
3493 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3499 entry
.tls_type
= tls_flag
;
3501 memcpy (*loc
, &entry
, sizeof entry
);
3504 hmips
->global_got_area
= GGA_NORMAL
;
3509 /* Reserve space in G for a GOT entry containing the value of symbol
3510 SYMNDX in input bfd ABDF, plus ADDEND. */
3513 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
3514 struct bfd_link_info
*info
,
3515 unsigned char tls_flag
)
3517 struct mips_elf_link_hash_table
*htab
;
3518 struct mips_got_info
*g
;
3519 struct mips_got_entry entry
, **loc
;
3521 htab
= mips_elf_hash_table (info
);
3523 BFD_ASSERT (g
!= NULL
);
3526 entry
.symndx
= symndx
;
3527 entry
.d
.addend
= addend
;
3528 entry
.tls_type
= tls_flag
;
3529 loc
= (struct mips_got_entry
**)
3530 htab_find_slot (g
->got_entries
, &entry
, INSERT
);
3534 if (tls_flag
== GOT_TLS_GD
&& !((*loc
)->tls_type
& GOT_TLS_GD
))
3537 (*loc
)->tls_type
|= tls_flag
;
3539 else if (tls_flag
== GOT_TLS_IE
&& !((*loc
)->tls_type
& GOT_TLS_IE
))
3542 (*loc
)->tls_type
|= tls_flag
;
3550 entry
.tls_type
= tls_flag
;
3551 if (tls_flag
== GOT_TLS_IE
)
3553 else if (tls_flag
== GOT_TLS_GD
)
3555 else if (g
->tls_ldm_offset
== MINUS_ONE
)
3557 g
->tls_ldm_offset
= MINUS_TWO
;
3563 entry
.gotidx
= g
->local_gotno
++;
3567 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3572 memcpy (*loc
, &entry
, sizeof entry
);
3577 /* Return the maximum number of GOT page entries required for RANGE. */
3580 mips_elf_pages_for_range (const struct mips_got_page_range
*range
)
3582 return (range
->max_addend
- range
->min_addend
+ 0x1ffff) >> 16;
3585 /* Record that ABFD has a page relocation against symbol SYMNDX and
3586 that ADDEND is the addend for that relocation.
3588 This function creates an upper bound on the number of GOT slots
3589 required; no attempt is made to combine references to non-overridable
3590 global symbols across multiple input files. */
3593 mips_elf_record_got_page_entry (struct bfd_link_info
*info
, bfd
*abfd
,
3594 long symndx
, bfd_signed_vma addend
)
3596 struct mips_elf_link_hash_table
*htab
;
3597 struct mips_got_info
*g
;
3598 struct mips_got_page_entry lookup
, *entry
;
3599 struct mips_got_page_range
**range_ptr
, *range
;
3600 bfd_vma old_pages
, new_pages
;
3603 htab
= mips_elf_hash_table (info
);
3605 BFD_ASSERT (g
!= NULL
);
3607 /* Find the mips_got_page_entry hash table entry for this symbol. */
3609 lookup
.symndx
= symndx
;
3610 loc
= htab_find_slot (g
->got_page_entries
, &lookup
, INSERT
);
3614 /* Create a mips_got_page_entry if this is the first time we've
3616 entry
= (struct mips_got_page_entry
*) *loc
;
3619 entry
= bfd_alloc (abfd
, sizeof (*entry
));
3624 entry
->symndx
= symndx
;
3625 entry
->ranges
= NULL
;
3626 entry
->num_pages
= 0;
3630 /* Skip over ranges whose maximum extent cannot share a page entry
3632 range_ptr
= &entry
->ranges
;
3633 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
3634 range_ptr
= &(*range_ptr
)->next
;
3636 /* If we scanned to the end of the list, or found a range whose
3637 minimum extent cannot share a page entry with ADDEND, create
3638 a new singleton range. */
3640 if (!range
|| addend
< range
->min_addend
- 0xffff)
3642 range
= bfd_alloc (abfd
, sizeof (*range
));
3646 range
->next
= *range_ptr
;
3647 range
->min_addend
= addend
;
3648 range
->max_addend
= addend
;
3656 /* Remember how many pages the old range contributed. */
3657 old_pages
= mips_elf_pages_for_range (range
);
3659 /* Update the ranges. */
3660 if (addend
< range
->min_addend
)
3661 range
->min_addend
= addend
;
3662 else if (addend
> range
->max_addend
)
3664 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
3666 old_pages
+= mips_elf_pages_for_range (range
->next
);
3667 range
->max_addend
= range
->next
->max_addend
;
3668 range
->next
= range
->next
->next
;
3671 range
->max_addend
= addend
;
3674 /* Record any change in the total estimate. */
3675 new_pages
= mips_elf_pages_for_range (range
);
3676 if (old_pages
!= new_pages
)
3678 entry
->num_pages
+= new_pages
- old_pages
;
3679 g
->page_gotno
+= new_pages
- old_pages
;
3685 /* Add room for N relocations to the .rel(a).dyn section in ABFD. */
3688 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, struct bfd_link_info
*info
,
3692 struct mips_elf_link_hash_table
*htab
;
3694 htab
= mips_elf_hash_table (info
);
3695 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3696 BFD_ASSERT (s
!= NULL
);
3698 if (htab
->is_vxworks
)
3699 s
->size
+= n
* MIPS_ELF_RELA_SIZE (abfd
);
3704 /* Make room for a null element. */
3705 s
->size
+= MIPS_ELF_REL_SIZE (abfd
);
3708 s
->size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
3712 /* A htab_traverse callback for GOT entries. Set boolean *DATA to true
3713 if the GOT entry is for an indirect or warning symbol. */
3716 mips_elf_check_recreate_got (void **entryp
, void *data
)
3718 struct mips_got_entry
*entry
;
3719 bfd_boolean
*must_recreate
;
3721 entry
= (struct mips_got_entry
*) *entryp
;
3722 must_recreate
= (bfd_boolean
*) data
;
3723 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3725 struct mips_elf_link_hash_entry
*h
;
3728 if (h
->root
.root
.type
== bfd_link_hash_indirect
3729 || h
->root
.root
.type
== bfd_link_hash_warning
)
3731 *must_recreate
= TRUE
;
3738 /* A htab_traverse callback for GOT entries. Add all entries to
3739 hash table *DATA, converting entries for indirect and warning
3740 symbols into entries for the target symbol. Set *DATA to null
3744 mips_elf_recreate_got (void **entryp
, void *data
)
3747 struct mips_got_entry
*entry
;
3750 new_got
= (htab_t
*) data
;
3751 entry
= (struct mips_got_entry
*) *entryp
;
3752 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3754 struct mips_elf_link_hash_entry
*h
;
3757 while (h
->root
.root
.type
== bfd_link_hash_indirect
3758 || h
->root
.root
.type
== bfd_link_hash_warning
)
3760 BFD_ASSERT (h
->global_got_area
== GGA_NONE
);
3761 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3765 slot
= htab_find_slot (*new_got
, entry
, INSERT
);
3778 /* If any entries in G->got_entries are for indirect or warning symbols,
3779 replace them with entries for the target symbol. */
3782 mips_elf_resolve_final_got_entries (struct mips_got_info
*g
)
3784 bfd_boolean must_recreate
;
3787 must_recreate
= FALSE
;
3788 htab_traverse (g
->got_entries
, mips_elf_check_recreate_got
, &must_recreate
);
3791 new_got
= htab_create (htab_size (g
->got_entries
),
3792 mips_elf_got_entry_hash
,
3793 mips_elf_got_entry_eq
, NULL
);
3794 htab_traverse (g
->got_entries
, mips_elf_recreate_got
, &new_got
);
3795 if (new_got
== NULL
)
3798 /* Each entry in g->got_entries has either been copied to new_got
3799 or freed. Now delete the hash table itself. */
3800 htab_delete (g
->got_entries
);
3801 g
->got_entries
= new_got
;
3806 /* A mips_elf_link_hash_traverse callback for which DATA points
3807 to a mips_got_info. Count the number of type (3) entries. */
3810 mips_elf_count_got_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
3812 struct mips_got_info
*g
;
3814 g
= (struct mips_got_info
*) data
;
3815 if (h
->global_got_area
!= GGA_NONE
)
3817 if (h
->root
.forced_local
|| h
->root
.dynindx
== -1)
3819 /* We no longer need this entry if it was only used for
3820 relocations; those relocations will be against the
3821 null or section symbol instead of H. */
3822 if (h
->global_got_area
!= GGA_RELOC_ONLY
)
3824 h
->global_got_area
= GGA_NONE
;
3829 if (h
->global_got_area
== GGA_RELOC_ONLY
)
3830 g
->reloc_only_gotno
++;
3836 /* Compute the hash value of the bfd in a bfd2got hash entry. */
3839 mips_elf_bfd2got_entry_hash (const void *entry_
)
3841 const struct mips_elf_bfd2got_hash
*entry
3842 = (struct mips_elf_bfd2got_hash
*)entry_
;
3844 return entry
->bfd
->id
;
3847 /* Check whether two hash entries have the same bfd. */
3850 mips_elf_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
3852 const struct mips_elf_bfd2got_hash
*e1
3853 = (const struct mips_elf_bfd2got_hash
*)entry1
;
3854 const struct mips_elf_bfd2got_hash
*e2
3855 = (const struct mips_elf_bfd2got_hash
*)entry2
;
3857 return e1
->bfd
== e2
->bfd
;
3860 /* In a multi-got link, determine the GOT to be used for IBFD. G must
3861 be the master GOT data. */
3863 static struct mips_got_info
*
3864 mips_elf_got_for_ibfd (struct mips_got_info
*g
, bfd
*ibfd
)
3866 struct mips_elf_bfd2got_hash e
, *p
;
3872 p
= htab_find (g
->bfd2got
, &e
);
3873 return p
? p
->g
: NULL
;
3876 /* Use BFD2GOT to find ABFD's got entry, creating one if none exists.
3877 Return NULL if an error occured. */
3879 static struct mips_got_info
*
3880 mips_elf_get_got_for_bfd (struct htab
*bfd2got
, bfd
*output_bfd
,
3883 struct mips_elf_bfd2got_hash bfdgot_entry
, *bfdgot
;
3884 struct mips_got_info
*g
;
3887 bfdgot_entry
.bfd
= input_bfd
;
3888 bfdgotp
= htab_find_slot (bfd2got
, &bfdgot_entry
, INSERT
);
3889 bfdgot
= (struct mips_elf_bfd2got_hash
*) *bfdgotp
;
3893 bfdgot
= ((struct mips_elf_bfd2got_hash
*)
3894 bfd_alloc (output_bfd
, sizeof (struct mips_elf_bfd2got_hash
)));
3900 g
= ((struct mips_got_info
*)
3901 bfd_alloc (output_bfd
, sizeof (struct mips_got_info
)));
3905 bfdgot
->bfd
= input_bfd
;
3908 g
->global_gotsym
= NULL
;
3909 g
->global_gotno
= 0;
3910 g
->reloc_only_gotno
= 0;
3913 g
->assigned_gotno
= -1;
3915 g
->tls_assigned_gotno
= 0;
3916 g
->tls_ldm_offset
= MINUS_ONE
;
3917 g
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3918 mips_elf_multi_got_entry_eq
, NULL
);
3919 if (g
->got_entries
== NULL
)
3922 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
3923 mips_got_page_entry_eq
, NULL
);
3924 if (g
->got_page_entries
== NULL
)
3934 /* A htab_traverse callback for the entries in the master got.
3935 Create one separate got for each bfd that has entries in the global
3936 got, such that we can tell how many local and global entries each
3940 mips_elf_make_got_per_bfd (void **entryp
, void *p
)
3942 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3943 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
3944 struct mips_got_info
*g
;
3946 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
3953 /* Insert the GOT entry in the bfd's got entry hash table. */
3954 entryp
= htab_find_slot (g
->got_entries
, entry
, INSERT
);
3955 if (*entryp
!= NULL
)
3960 if (entry
->tls_type
)
3962 if (entry
->tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
3964 if (entry
->tls_type
& GOT_TLS_IE
)
3967 else if (entry
->symndx
>= 0 || entry
->d
.h
->root
.forced_local
)
3975 /* A htab_traverse callback for the page entries in the master got.
3976 Associate each page entry with the bfd's got. */
3979 mips_elf_make_got_pages_per_bfd (void **entryp
, void *p
)
3981 struct mips_got_page_entry
*entry
= (struct mips_got_page_entry
*) *entryp
;
3982 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*) p
;
3983 struct mips_got_info
*g
;
3985 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
3992 /* Insert the GOT entry in the bfd's got entry hash table. */
3993 entryp
= htab_find_slot (g
->got_page_entries
, entry
, INSERT
);
3994 if (*entryp
!= NULL
)
3998 g
->page_gotno
+= entry
->num_pages
;
4002 /* Consider merging the got described by BFD2GOT with TO, using the
4003 information given by ARG. Return -1 if this would lead to overflow,
4004 1 if they were merged successfully, and 0 if a merge failed due to
4005 lack of memory. (These values are chosen so that nonnegative return
4006 values can be returned by a htab_traverse callback.) */
4009 mips_elf_merge_got_with (struct mips_elf_bfd2got_hash
*bfd2got
,
4010 struct mips_got_info
*to
,
4011 struct mips_elf_got_per_bfd_arg
*arg
)
4013 struct mips_got_info
*from
= bfd2got
->g
;
4014 unsigned int estimate
;
4016 /* Work out how many page entries we would need for the combined GOT. */
4017 estimate
= arg
->max_pages
;
4018 if (estimate
>= from
->page_gotno
+ to
->page_gotno
)
4019 estimate
= from
->page_gotno
+ to
->page_gotno
;
4021 /* And conservatively estimate how many local, global and TLS entries
4023 estimate
+= (from
->local_gotno
4024 + from
->global_gotno
4030 /* Bail out if the combined GOT might be too big. */
4031 if (estimate
> arg
->max_count
)
4034 /* Commit to the merge. Record that TO is now the bfd for this got. */
4037 /* Transfer the bfd's got information from FROM to TO. */
4038 htab_traverse (from
->got_entries
, mips_elf_make_got_per_bfd
, arg
);
4039 if (arg
->obfd
== NULL
)
4042 htab_traverse (from
->got_page_entries
, mips_elf_make_got_pages_per_bfd
, arg
);
4043 if (arg
->obfd
== NULL
)
4046 /* We don't have to worry about releasing memory of the actual
4047 got entries, since they're all in the master got_entries hash
4049 htab_delete (from
->got_entries
);
4050 htab_delete (from
->got_page_entries
);
4054 /* Attempt to merge gots of different input bfds. Try to use as much
4055 as possible of the primary got, since it doesn't require explicit
4056 dynamic relocations, but don't use bfds that would reference global
4057 symbols out of the addressable range. Failing the primary got,
4058 attempt to merge with the current got, or finish the current got
4059 and then make make the new got current. */
4062 mips_elf_merge_gots (void **bfd2got_
, void *p
)
4064 struct mips_elf_bfd2got_hash
*bfd2got
4065 = (struct mips_elf_bfd2got_hash
*)*bfd2got_
;
4066 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
4067 struct mips_got_info
*g
;
4068 unsigned int estimate
;
4073 /* Work out the number of page, local and TLS entries. */
4074 estimate
= arg
->max_pages
;
4075 if (estimate
> g
->page_gotno
)
4076 estimate
= g
->page_gotno
;
4077 estimate
+= g
->local_gotno
+ g
->tls_gotno
;
4079 /* We place TLS GOT entries after both locals and globals. The globals
4080 for the primary GOT may overflow the normal GOT size limit, so be
4081 sure not to merge a GOT which requires TLS with the primary GOT in that
4082 case. This doesn't affect non-primary GOTs. */
4083 estimate
+= (g
->tls_gotno
> 0 ? arg
->global_count
: g
->global_gotno
);
4085 if (estimate
<= arg
->max_count
)
4087 /* If we don't have a primary GOT, use it as
4088 a starting point for the primary GOT. */
4091 arg
->primary
= bfd2got
->g
;
4095 /* Try merging with the primary GOT. */
4096 result
= mips_elf_merge_got_with (bfd2got
, arg
->primary
, arg
);
4101 /* If we can merge with the last-created got, do it. */
4104 result
= mips_elf_merge_got_with (bfd2got
, arg
->current
, arg
);
4109 /* Well, we couldn't merge, so create a new GOT. Don't check if it
4110 fits; if it turns out that it doesn't, we'll get relocation
4111 overflows anyway. */
4112 g
->next
= arg
->current
;
4118 /* Set the TLS GOT index for the GOT entry in ENTRYP. ENTRYP's NEXT field
4119 is null iff there is just a single GOT. */
4122 mips_elf_initialize_tls_index (void **entryp
, void *p
)
4124 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
4125 struct mips_got_info
*g
= p
;
4127 unsigned char tls_type
;
4129 /* We're only interested in TLS symbols. */
4130 if (entry
->tls_type
== 0)
4133 next_index
= MIPS_ELF_GOT_SIZE (entry
->abfd
) * (long) g
->tls_assigned_gotno
;
4135 if (entry
->symndx
== -1 && g
->next
== NULL
)
4137 /* A type (3) got entry in the single-GOT case. We use the symbol's
4138 hash table entry to track its index. */
4139 if (entry
->d
.h
->tls_type
& GOT_TLS_OFFSET_DONE
)
4141 entry
->d
.h
->tls_type
|= GOT_TLS_OFFSET_DONE
;
4142 entry
->d
.h
->tls_got_offset
= next_index
;
4143 tls_type
= entry
->d
.h
->tls_type
;
4147 if (entry
->tls_type
& GOT_TLS_LDM
)
4149 /* There are separate mips_got_entry objects for each input bfd
4150 that requires an LDM entry. Make sure that all LDM entries in
4151 a GOT resolve to the same index. */
4152 if (g
->tls_ldm_offset
!= MINUS_TWO
&& g
->tls_ldm_offset
!= MINUS_ONE
)
4154 entry
->gotidx
= g
->tls_ldm_offset
;
4157 g
->tls_ldm_offset
= next_index
;
4159 entry
->gotidx
= next_index
;
4160 tls_type
= entry
->tls_type
;
4163 /* Account for the entries we've just allocated. */
4164 if (tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
4165 g
->tls_assigned_gotno
+= 2;
4166 if (tls_type
& GOT_TLS_IE
)
4167 g
->tls_assigned_gotno
+= 1;
4172 /* If passed a NULL mips_got_info in the argument, set the marker used
4173 to tell whether a global symbol needs a got entry (in the primary
4174 got) to the given VALUE.
4176 If passed a pointer G to a mips_got_info in the argument (it must
4177 not be the primary GOT), compute the offset from the beginning of
4178 the (primary) GOT section to the entry in G corresponding to the
4179 global symbol. G's assigned_gotno must contain the index of the
4180 first available global GOT entry in G. VALUE must contain the size
4181 of a GOT entry in bytes. For each global GOT entry that requires a
4182 dynamic relocation, NEEDED_RELOCS is incremented, and the symbol is
4183 marked as not eligible for lazy resolution through a function
4186 mips_elf_set_global_got_offset (void **entryp
, void *p
)
4188 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
4189 struct mips_elf_set_global_got_offset_arg
*arg
4190 = (struct mips_elf_set_global_got_offset_arg
*)p
;
4191 struct mips_got_info
*g
= arg
->g
;
4193 if (g
&& entry
->tls_type
!= GOT_NORMAL
)
4194 arg
->needed_relocs
+=
4195 mips_tls_got_relocs (arg
->info
, entry
->tls_type
,
4196 entry
->symndx
== -1 ? &entry
->d
.h
->root
: NULL
);
4198 if (entry
->abfd
!= NULL
4199 && entry
->symndx
== -1
4200 && entry
->d
.h
->global_got_area
!= GGA_NONE
)
4204 BFD_ASSERT (g
->global_gotsym
== NULL
);
4206 entry
->gotidx
= arg
->value
* (long) g
->assigned_gotno
++;
4207 if (arg
->info
->shared
4208 || (elf_hash_table (arg
->info
)->dynamic_sections_created
4209 && entry
->d
.h
->root
.def_dynamic
4210 && !entry
->d
.h
->root
.def_regular
))
4211 ++arg
->needed_relocs
;
4214 entry
->d
.h
->global_got_area
= arg
->value
;
4220 /* A htab_traverse callback for GOT entries for which DATA is the
4221 bfd_link_info. Forbid any global symbols from having traditional
4222 lazy-binding stubs. */
4225 mips_elf_forbid_lazy_stubs (void **entryp
, void *data
)
4227 struct bfd_link_info
*info
;
4228 struct mips_elf_link_hash_table
*htab
;
4229 struct mips_got_entry
*entry
;
4231 entry
= (struct mips_got_entry
*) *entryp
;
4232 info
= (struct bfd_link_info
*) data
;
4233 htab
= mips_elf_hash_table (info
);
4234 if (entry
->abfd
!= NULL
4235 && entry
->symndx
== -1
4236 && entry
->d
.h
->needs_lazy_stub
)
4238 entry
->d
.h
->needs_lazy_stub
= FALSE
;
4239 htab
->lazy_stub_count
--;
4245 /* Return the offset of an input bfd IBFD's GOT from the beginning of
4248 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
4250 if (g
->bfd2got
== NULL
)
4253 g
= mips_elf_got_for_ibfd (g
, ibfd
);
4257 BFD_ASSERT (g
->next
);
4261 return (g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
)
4262 * MIPS_ELF_GOT_SIZE (abfd
);
4265 /* Turn a single GOT that is too big for 16-bit addressing into
4266 a sequence of GOTs, each one 16-bit addressable. */
4269 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
4270 asection
*got
, bfd_size_type pages
)
4272 struct mips_elf_link_hash_table
*htab
;
4273 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
4274 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
4275 struct mips_got_info
*g
, *gg
;
4276 unsigned int assign
, needed_relocs
;
4279 dynobj
= elf_hash_table (info
)->dynobj
;
4280 htab
= mips_elf_hash_table (info
);
4282 g
->bfd2got
= htab_try_create (1, mips_elf_bfd2got_entry_hash
,
4283 mips_elf_bfd2got_entry_eq
, NULL
);
4284 if (g
->bfd2got
== NULL
)
4287 got_per_bfd_arg
.bfd2got
= g
->bfd2got
;
4288 got_per_bfd_arg
.obfd
= abfd
;
4289 got_per_bfd_arg
.info
= info
;
4291 /* Count how many GOT entries each input bfd requires, creating a
4292 map from bfd to got info while at that. */
4293 htab_traverse (g
->got_entries
, mips_elf_make_got_per_bfd
, &got_per_bfd_arg
);
4294 if (got_per_bfd_arg
.obfd
== NULL
)
4297 /* Also count how many page entries each input bfd requires. */
4298 htab_traverse (g
->got_page_entries
, mips_elf_make_got_pages_per_bfd
,
4300 if (got_per_bfd_arg
.obfd
== NULL
)
4303 got_per_bfd_arg
.current
= NULL
;
4304 got_per_bfd_arg
.primary
= NULL
;
4305 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (info
)
4306 / MIPS_ELF_GOT_SIZE (abfd
))
4307 - htab
->reserved_gotno
);
4308 got_per_bfd_arg
.max_pages
= pages
;
4309 /* The number of globals that will be included in the primary GOT.
4310 See the calls to mips_elf_set_global_got_offset below for more
4312 got_per_bfd_arg
.global_count
= g
->global_gotno
;
4314 /* Try to merge the GOTs of input bfds together, as long as they
4315 don't seem to exceed the maximum GOT size, choosing one of them
4316 to be the primary GOT. */
4317 htab_traverse (g
->bfd2got
, mips_elf_merge_gots
, &got_per_bfd_arg
);
4318 if (got_per_bfd_arg
.obfd
== NULL
)
4321 /* If we do not find any suitable primary GOT, create an empty one. */
4322 if (got_per_bfd_arg
.primary
== NULL
)
4324 g
->next
= (struct mips_got_info
*)
4325 bfd_alloc (abfd
, sizeof (struct mips_got_info
));
4326 if (g
->next
== NULL
)
4329 g
->next
->global_gotsym
= NULL
;
4330 g
->next
->global_gotno
= 0;
4331 g
->next
->reloc_only_gotno
= 0;
4332 g
->next
->local_gotno
= 0;
4333 g
->next
->page_gotno
= 0;
4334 g
->next
->tls_gotno
= 0;
4335 g
->next
->assigned_gotno
= 0;
4336 g
->next
->tls_assigned_gotno
= 0;
4337 g
->next
->tls_ldm_offset
= MINUS_ONE
;
4338 g
->next
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
4339 mips_elf_multi_got_entry_eq
,
4341 if (g
->next
->got_entries
== NULL
)
4343 g
->next
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4344 mips_got_page_entry_eq
,
4346 if (g
->next
->got_page_entries
== NULL
)
4348 g
->next
->bfd2got
= NULL
;
4351 g
->next
= got_per_bfd_arg
.primary
;
4352 g
->next
->next
= got_per_bfd_arg
.current
;
4354 /* GG is now the master GOT, and G is the primary GOT. */
4358 /* Map the output bfd to the primary got. That's what we're going
4359 to use for bfds that use GOT16 or GOT_PAGE relocations that we
4360 didn't mark in check_relocs, and we want a quick way to find it.
4361 We can't just use gg->next because we're going to reverse the
4364 struct mips_elf_bfd2got_hash
*bfdgot
;
4367 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
4368 (abfd
, sizeof (struct mips_elf_bfd2got_hash
));
4375 bfdgotp
= htab_find_slot (gg
->bfd2got
, bfdgot
, INSERT
);
4377 BFD_ASSERT (*bfdgotp
== NULL
);
4381 /* Every symbol that is referenced in a dynamic relocation must be
4382 present in the primary GOT, so arrange for them to appear after
4383 those that are actually referenced. */
4384 gg
->reloc_only_gotno
= gg
->global_gotno
- g
->global_gotno
;
4385 g
->global_gotno
= gg
->global_gotno
;
4387 set_got_offset_arg
.g
= NULL
;
4388 set_got_offset_arg
.value
= GGA_RELOC_ONLY
;
4389 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_offset
,
4390 &set_got_offset_arg
);
4391 set_got_offset_arg
.value
= GGA_NORMAL
;
4392 htab_traverse (g
->got_entries
, mips_elf_set_global_got_offset
,
4393 &set_got_offset_arg
);
4395 /* Now go through the GOTs assigning them offset ranges.
4396 [assigned_gotno, local_gotno[ will be set to the range of local
4397 entries in each GOT. We can then compute the end of a GOT by
4398 adding local_gotno to global_gotno. We reverse the list and make
4399 it circular since then we'll be able to quickly compute the
4400 beginning of a GOT, by computing the end of its predecessor. To
4401 avoid special cases for the primary GOT, while still preserving
4402 assertions that are valid for both single- and multi-got links,
4403 we arrange for the main got struct to have the right number of
4404 global entries, but set its local_gotno such that the initial
4405 offset of the primary GOT is zero. Remember that the primary GOT
4406 will become the last item in the circular linked list, so it
4407 points back to the master GOT. */
4408 gg
->local_gotno
= -g
->global_gotno
;
4409 gg
->global_gotno
= g
->global_gotno
;
4416 struct mips_got_info
*gn
;
4418 assign
+= htab
->reserved_gotno
;
4419 g
->assigned_gotno
= assign
;
4420 g
->local_gotno
+= assign
;
4421 g
->local_gotno
+= (pages
< g
->page_gotno
? pages
: g
->page_gotno
);
4422 assign
= g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
;
4424 /* Take g out of the direct list, and push it onto the reversed
4425 list that gg points to. g->next is guaranteed to be nonnull after
4426 this operation, as required by mips_elf_initialize_tls_index. */
4431 /* Set up any TLS entries. We always place the TLS entries after
4432 all non-TLS entries. */
4433 g
->tls_assigned_gotno
= g
->local_gotno
+ g
->global_gotno
;
4434 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
4436 /* Move onto the next GOT. It will be a secondary GOT if nonull. */
4439 /* Forbid global symbols in every non-primary GOT from having
4440 lazy-binding stubs. */
4442 htab_traverse (g
->got_entries
, mips_elf_forbid_lazy_stubs
, info
);
4446 got
->size
= (gg
->next
->local_gotno
4447 + gg
->next
->global_gotno
4448 + gg
->next
->tls_gotno
) * MIPS_ELF_GOT_SIZE (abfd
);
4451 set_got_offset_arg
.value
= MIPS_ELF_GOT_SIZE (abfd
);
4452 set_got_offset_arg
.info
= info
;
4453 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
4455 unsigned int save_assign
;
4457 /* Assign offsets to global GOT entries. */
4458 save_assign
= g
->assigned_gotno
;
4459 g
->assigned_gotno
= g
->local_gotno
;
4460 set_got_offset_arg
.g
= g
;
4461 set_got_offset_arg
.needed_relocs
= 0;
4462 htab_traverse (g
->got_entries
,
4463 mips_elf_set_global_got_offset
,
4464 &set_got_offset_arg
);
4465 needed_relocs
+= set_got_offset_arg
.needed_relocs
;
4466 BFD_ASSERT (g
->assigned_gotno
- g
->local_gotno
<= g
->global_gotno
);
4468 g
->assigned_gotno
= save_assign
;
4471 needed_relocs
+= g
->local_gotno
- g
->assigned_gotno
;
4472 BFD_ASSERT (g
->assigned_gotno
== g
->next
->local_gotno
4473 + g
->next
->global_gotno
4474 + g
->next
->tls_gotno
4475 + htab
->reserved_gotno
);
4480 mips_elf_allocate_dynamic_relocations (dynobj
, info
,
4487 /* Returns the first relocation of type r_type found, beginning with
4488 RELOCATION. RELEND is one-past-the-end of the relocation table. */
4490 static const Elf_Internal_Rela
*
4491 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
4492 const Elf_Internal_Rela
*relocation
,
4493 const Elf_Internal_Rela
*relend
)
4495 unsigned long r_symndx
= ELF_R_SYM (abfd
, relocation
->r_info
);
4497 while (relocation
< relend
)
4499 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
4500 && ELF_R_SYM (abfd
, relocation
->r_info
) == r_symndx
)
4506 /* We didn't find it. */
4510 /* Return whether a relocation is against a local symbol. */
4513 mips_elf_local_relocation_p (bfd
*input_bfd
,
4514 const Elf_Internal_Rela
*relocation
,
4515 asection
**local_sections
,
4516 bfd_boolean check_forced
)
4518 unsigned long r_symndx
;
4519 Elf_Internal_Shdr
*symtab_hdr
;
4520 struct mips_elf_link_hash_entry
*h
;
4523 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4524 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4525 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
4527 if (r_symndx
< extsymoff
)
4529 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
4534 /* Look up the hash table to check whether the symbol
4535 was forced local. */
4536 h
= (struct mips_elf_link_hash_entry
*)
4537 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
4538 /* Find the real hash-table entry for this symbol. */
4539 while (h
->root
.root
.type
== bfd_link_hash_indirect
4540 || h
->root
.root
.type
== bfd_link_hash_warning
)
4541 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4542 if (h
->root
.forced_local
)
4549 /* Sign-extend VALUE, which has the indicated number of BITS. */
4552 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
4554 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
4555 /* VALUE is negative. */
4556 value
|= ((bfd_vma
) - 1) << bits
;
4561 /* Return non-zero if the indicated VALUE has overflowed the maximum
4562 range expressible by a signed number with the indicated number of
4566 mips_elf_overflow_p (bfd_vma value
, int bits
)
4568 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
4570 if (svalue
> (1 << (bits
- 1)) - 1)
4571 /* The value is too big. */
4573 else if (svalue
< -(1 << (bits
- 1)))
4574 /* The value is too small. */
4581 /* Calculate the %high function. */
4584 mips_elf_high (bfd_vma value
)
4586 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
4589 /* Calculate the %higher function. */
4592 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
4595 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
4602 /* Calculate the %highest function. */
4605 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
4608 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
4615 /* Create the .compact_rel section. */
4618 mips_elf_create_compact_rel_section
4619 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4622 register asection
*s
;
4624 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4626 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
4629 s
= bfd_make_section_with_flags (abfd
, ".compact_rel", flags
);
4631 || ! bfd_set_section_alignment (abfd
, s
,
4632 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
4635 s
->size
= sizeof (Elf32_External_compact_rel
);
4641 /* Create the .got section to hold the global offset table. */
4644 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4647 register asection
*s
;
4648 struct elf_link_hash_entry
*h
;
4649 struct bfd_link_hash_entry
*bh
;
4650 struct mips_got_info
*g
;
4652 struct mips_elf_link_hash_table
*htab
;
4654 htab
= mips_elf_hash_table (info
);
4656 /* This function may be called more than once. */
4660 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4661 | SEC_LINKER_CREATED
);
4663 /* We have to use an alignment of 2**4 here because this is hardcoded
4664 in the function stub generation and in the linker script. */
4665 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
4667 || ! bfd_set_section_alignment (abfd
, s
, 4))
4671 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4672 linker script because we don't want to define the symbol if we
4673 are not creating a global offset table. */
4675 if (! (_bfd_generic_link_add_one_symbol
4676 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4677 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
4680 h
= (struct elf_link_hash_entry
*) bh
;
4683 h
->type
= STT_OBJECT
;
4684 elf_hash_table (info
)->hgot
= h
;
4687 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4690 amt
= sizeof (struct mips_got_info
);
4691 g
= bfd_alloc (abfd
, amt
);
4694 g
->global_gotsym
= NULL
;
4695 g
->global_gotno
= 0;
4696 g
->reloc_only_gotno
= 0;
4700 g
->assigned_gotno
= 0;
4703 g
->tls_ldm_offset
= MINUS_ONE
;
4704 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
4705 mips_elf_got_entry_eq
, NULL
);
4706 if (g
->got_entries
== NULL
)
4708 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4709 mips_got_page_entry_eq
, NULL
);
4710 if (g
->got_page_entries
== NULL
)
4713 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
4714 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
4716 /* We also need a .got.plt section when generating PLTs. */
4717 s
= bfd_make_section_with_flags (abfd
, ".got.plt",
4718 SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
4719 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4727 /* Return true if H refers to the special VxWorks __GOTT_BASE__ or
4728 __GOTT_INDEX__ symbols. These symbols are only special for
4729 shared objects; they are not used in executables. */
4732 is_gott_symbol (struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
)
4734 return (mips_elf_hash_table (info
)->is_vxworks
4736 && (strcmp (h
->root
.root
.string
, "__GOTT_BASE__") == 0
4737 || strcmp (h
->root
.root
.string
, "__GOTT_INDEX__") == 0));
4740 /* Return TRUE if a relocation of type R_TYPE from INPUT_BFD might
4741 require an la25 stub. See also mips_elf_local_pic_function_p,
4742 which determines whether the destination function ever requires a
4746 mips_elf_relocation_needs_la25_stub (bfd
*input_bfd
, int r_type
)
4748 /* We specifically ignore branches and jumps from EF_PIC objects,
4749 where the onus is on the compiler or programmer to perform any
4750 necessary initialization of $25. Sometimes such initialization
4751 is unnecessary; for example, -mno-shared functions do not use
4752 the incoming value of $25, and may therefore be called directly. */
4753 if (PIC_OBJECT_P (input_bfd
))
4768 /* Calculate the value produced by the RELOCATION (which comes from
4769 the INPUT_BFD). The ADDEND is the addend to use for this
4770 RELOCATION; RELOCATION->R_ADDEND is ignored.
4772 The result of the relocation calculation is stored in VALUEP.
4773 REQUIRE_JALXP indicates whether or not the opcode used with this
4774 relocation must be JALX.
4776 This function returns bfd_reloc_continue if the caller need take no
4777 further action regarding this relocation, bfd_reloc_notsupported if
4778 something goes dramatically wrong, bfd_reloc_overflow if an
4779 overflow occurs, and bfd_reloc_ok to indicate success. */
4781 static bfd_reloc_status_type
4782 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
4783 asection
*input_section
,
4784 struct bfd_link_info
*info
,
4785 const Elf_Internal_Rela
*relocation
,
4786 bfd_vma addend
, reloc_howto_type
*howto
,
4787 Elf_Internal_Sym
*local_syms
,
4788 asection
**local_sections
, bfd_vma
*valuep
,
4789 const char **namep
, bfd_boolean
*require_jalxp
,
4790 bfd_boolean save_addend
)
4792 /* The eventual value we will return. */
4794 /* The address of the symbol against which the relocation is
4797 /* The final GP value to be used for the relocatable, executable, or
4798 shared object file being produced. */
4800 /* The place (section offset or address) of the storage unit being
4803 /* The value of GP used to create the relocatable object. */
4805 /* The offset into the global offset table at which the address of
4806 the relocation entry symbol, adjusted by the addend, resides
4807 during execution. */
4808 bfd_vma g
= MINUS_ONE
;
4809 /* The section in which the symbol referenced by the relocation is
4811 asection
*sec
= NULL
;
4812 struct mips_elf_link_hash_entry
*h
= NULL
;
4813 /* TRUE if the symbol referred to by this relocation is a local
4815 bfd_boolean local_p
, was_local_p
;
4816 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
4817 bfd_boolean gp_disp_p
= FALSE
;
4818 /* TRUE if the symbol referred to by this relocation is
4819 "__gnu_local_gp". */
4820 bfd_boolean gnu_local_gp_p
= FALSE
;
4821 Elf_Internal_Shdr
*symtab_hdr
;
4823 unsigned long r_symndx
;
4825 /* TRUE if overflow occurred during the calculation of the
4826 relocation value. */
4827 bfd_boolean overflowed_p
;
4828 /* TRUE if this relocation refers to a MIPS16 function. */
4829 bfd_boolean target_is_16_bit_code_p
= FALSE
;
4830 struct mips_elf_link_hash_table
*htab
;
4833 dynobj
= elf_hash_table (info
)->dynobj
;
4834 htab
= mips_elf_hash_table (info
);
4836 /* Parse the relocation. */
4837 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4838 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
4839 p
= (input_section
->output_section
->vma
4840 + input_section
->output_offset
4841 + relocation
->r_offset
);
4843 /* Assume that there will be no overflow. */
4844 overflowed_p
= FALSE
;
4846 /* Figure out whether or not the symbol is local, and get the offset
4847 used in the array of hash table entries. */
4848 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4849 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
4850 local_sections
, FALSE
);
4851 was_local_p
= local_p
;
4852 if (! elf_bad_symtab (input_bfd
))
4853 extsymoff
= symtab_hdr
->sh_info
;
4856 /* The symbol table does not follow the rule that local symbols
4857 must come before globals. */
4861 /* Figure out the value of the symbol. */
4864 Elf_Internal_Sym
*sym
;
4866 sym
= local_syms
+ r_symndx
;
4867 sec
= local_sections
[r_symndx
];
4869 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4870 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
4871 || (sec
->flags
& SEC_MERGE
))
4872 symbol
+= sym
->st_value
;
4873 if ((sec
->flags
& SEC_MERGE
)
4874 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4876 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
4878 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
4881 /* MIPS16 text labels should be treated as odd. */
4882 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
4885 /* Record the name of this symbol, for our caller. */
4886 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
4887 symtab_hdr
->sh_link
,
4890 *namep
= bfd_section_name (input_bfd
, sec
);
4892 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (sym
->st_other
);
4896 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
4898 /* For global symbols we look up the symbol in the hash-table. */
4899 h
= ((struct mips_elf_link_hash_entry
*)
4900 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
4901 /* Find the real hash-table entry for this symbol. */
4902 while (h
->root
.root
.type
== bfd_link_hash_indirect
4903 || h
->root
.root
.type
== bfd_link_hash_warning
)
4904 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4906 /* Record the name of this symbol, for our caller. */
4907 *namep
= h
->root
.root
.root
.string
;
4909 /* See if this is the special _gp_disp symbol. Note that such a
4910 symbol must always be a global symbol. */
4911 if (strcmp (*namep
, "_gp_disp") == 0
4912 && ! NEWABI_P (input_bfd
))
4914 /* Relocations against _gp_disp are permitted only with
4915 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
4916 if (!hi16_reloc_p (r_type
) && !lo16_reloc_p (r_type
))
4917 return bfd_reloc_notsupported
;
4921 /* See if this is the special _gp symbol. Note that such a
4922 symbol must always be a global symbol. */
4923 else if (strcmp (*namep
, "__gnu_local_gp") == 0)
4924 gnu_local_gp_p
= TRUE
;
4927 /* If this symbol is defined, calculate its address. Note that
4928 _gp_disp is a magic symbol, always implicitly defined by the
4929 linker, so it's inappropriate to check to see whether or not
4931 else if ((h
->root
.root
.type
== bfd_link_hash_defined
4932 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4933 && h
->root
.root
.u
.def
.section
)
4935 sec
= h
->root
.root
.u
.def
.section
;
4936 if (sec
->output_section
)
4937 symbol
= (h
->root
.root
.u
.def
.value
4938 + sec
->output_section
->vma
4939 + sec
->output_offset
);
4941 symbol
= h
->root
.root
.u
.def
.value
;
4943 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
4944 /* We allow relocations against undefined weak symbols, giving
4945 it the value zero, so that you can undefined weak functions
4946 and check to see if they exist by looking at their
4949 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
4950 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
4952 else if (strcmp (*namep
, SGI_COMPAT (input_bfd
)
4953 ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING") == 0)
4955 /* If this is a dynamic link, we should have created a
4956 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
4957 in in _bfd_mips_elf_create_dynamic_sections.
4958 Otherwise, we should define the symbol with a value of 0.
4959 FIXME: It should probably get into the symbol table
4961 BFD_ASSERT (! info
->shared
);
4962 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
4965 else if (ELF_MIPS_IS_OPTIONAL (h
->root
.other
))
4967 /* This is an optional symbol - an Irix specific extension to the
4968 ELF spec. Ignore it for now.
4969 XXX - FIXME - there is more to the spec for OPTIONAL symbols
4970 than simply ignoring them, but we do not handle this for now.
4971 For information see the "64-bit ELF Object File Specification"
4972 which is available from here:
4973 http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf */
4978 if (! ((*info
->callbacks
->undefined_symbol
)
4979 (info
, h
->root
.root
.root
.string
, input_bfd
,
4980 input_section
, relocation
->r_offset
,
4981 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
4982 || ELF_ST_VISIBILITY (h
->root
.other
))))
4983 return bfd_reloc_undefined
;
4987 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (h
->root
.other
);
4990 /* If this is a reference to a 16-bit function with a stub, we need
4991 to redirect the relocation to the stub unless:
4993 (a) the relocation is for a MIPS16 JAL;
4995 (b) the relocation is for a MIPS16 PIC call, and there are no
4996 non-MIPS16 uses of the GOT slot; or
4998 (c) the section allows direct references to MIPS16 functions. */
4999 if (r_type
!= R_MIPS16_26
5000 && !info
->relocatable
5002 && h
->fn_stub
!= NULL
5003 && (r_type
!= R_MIPS16_CALL16
|| h
->need_fn_stub
))
5005 && elf_tdata (input_bfd
)->local_stubs
!= NULL
5006 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
5007 && !section_allows_mips16_refs_p (input_section
))
5009 /* This is a 32- or 64-bit call to a 16-bit function. We should
5010 have already noticed that we were going to need the
5013 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
5016 BFD_ASSERT (h
->need_fn_stub
);
5020 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5021 /* The target is 16-bit, but the stub isn't. */
5022 target_is_16_bit_code_p
= FALSE
;
5024 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
5025 need to redirect the call to the stub. Note that we specifically
5026 exclude R_MIPS16_CALL16 from this behavior; indirect calls should
5027 use an indirect stub instead. */
5028 else if (r_type
== R_MIPS16_26
&& !info
->relocatable
5029 && ((h
!= NULL
&& (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
))
5031 && elf_tdata (input_bfd
)->local_call_stubs
!= NULL
5032 && elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
] != NULL
))
5033 && !target_is_16_bit_code_p
)
5036 sec
= elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
];
5039 /* If both call_stub and call_fp_stub are defined, we can figure
5040 out which one to use by checking which one appears in the input
5042 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
5047 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5049 if (CALL_FP_STUB_P (bfd_get_section_name (input_bfd
, o
)))
5051 sec
= h
->call_fp_stub
;
5058 else if (h
->call_stub
!= NULL
)
5061 sec
= h
->call_fp_stub
;
5064 BFD_ASSERT (sec
->size
> 0);
5065 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5067 /* If this is a direct call to a PIC function, redirect to the
5069 else if (h
!= NULL
&& h
->la25_stub
5070 && mips_elf_relocation_needs_la25_stub (input_bfd
, r_type
))
5071 symbol
= (h
->la25_stub
->stub_section
->output_section
->vma
5072 + h
->la25_stub
->stub_section
->output_offset
5073 + h
->la25_stub
->offset
);
5075 /* Calls from 16-bit code to 32-bit code and vice versa require the
5076 special jalx instruction. */
5077 *require_jalxp
= (!info
->relocatable
5078 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
5079 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
5081 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
5082 local_sections
, TRUE
);
5084 gp0
= _bfd_get_gp_value (input_bfd
);
5085 gp
= _bfd_get_gp_value (abfd
);
5087 gp
+= mips_elf_adjust_gp (abfd
, htab
->got_info
, input_bfd
);
5092 /* If we haven't already determined the GOT offset, oand we're going
5093 to need it, get it now. */
5096 case R_MIPS_GOT_PAGE
:
5097 case R_MIPS_GOT_OFST
:
5098 /* We need to decay to GOT_DISP/addend if the symbol doesn't
5100 local_p
= local_p
|| _bfd_elf_symbol_refs_local_p (&h
->root
, info
, 1);
5101 if (local_p
|| r_type
== R_MIPS_GOT_OFST
)
5105 case R_MIPS16_CALL16
:
5106 case R_MIPS16_GOT16
:
5109 case R_MIPS_GOT_DISP
:
5110 case R_MIPS_GOT_HI16
:
5111 case R_MIPS_CALL_HI16
:
5112 case R_MIPS_GOT_LO16
:
5113 case R_MIPS_CALL_LO16
:
5115 case R_MIPS_TLS_GOTTPREL
:
5116 case R_MIPS_TLS_LDM
:
5117 /* Find the index into the GOT where this value is located. */
5118 if (r_type
== R_MIPS_TLS_LDM
)
5120 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5121 0, 0, NULL
, r_type
);
5123 return bfd_reloc_outofrange
;
5127 /* On VxWorks, CALL relocations should refer to the .got.plt
5128 entry, which is initialized to point at the PLT stub. */
5129 if (htab
->is_vxworks
5130 && (r_type
== R_MIPS_CALL_HI16
5131 || r_type
== R_MIPS_CALL_LO16
5132 || call16_reloc_p (r_type
)))
5134 BFD_ASSERT (addend
== 0);
5135 BFD_ASSERT (h
->root
.needs_plt
);
5136 g
= mips_elf_gotplt_index (info
, &h
->root
);
5140 /* GOT_PAGE may take a non-zero addend, that is ignored in a
5141 GOT_PAGE relocation that decays to GOT_DISP because the
5142 symbol turns out to be global. The addend is then added
5144 BFD_ASSERT (addend
== 0 || r_type
== R_MIPS_GOT_PAGE
);
5145 g
= mips_elf_global_got_index (dynobj
, input_bfd
,
5146 &h
->root
, r_type
, info
);
5147 if (h
->tls_type
== GOT_NORMAL
5148 && (! elf_hash_table(info
)->dynamic_sections_created
5150 && (info
->symbolic
|| h
->root
.forced_local
)
5151 && h
->root
.def_regular
)))
5152 /* This is a static link or a -Bsymbolic link. The
5153 symbol is defined locally, or was forced to be local.
5154 We must initialize this entry in the GOT. */
5155 MIPS_ELF_PUT_WORD (dynobj
, symbol
, htab
->sgot
->contents
+ g
);
5158 else if (!htab
->is_vxworks
5159 && (call16_reloc_p (r_type
) || got16_reloc_p (r_type
)))
5160 /* The calculation below does not involve "g". */
5164 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5165 symbol
+ addend
, r_symndx
, h
, r_type
);
5167 return bfd_reloc_outofrange
;
5170 /* Convert GOT indices to actual offsets. */
5171 g
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, g
);
5175 /* Relocations against the VxWorks __GOTT_BASE__ and __GOTT_INDEX__
5176 symbols are resolved by the loader. Add them to .rela.dyn. */
5177 if (h
!= NULL
&& is_gott_symbol (info
, &h
->root
))
5179 Elf_Internal_Rela outrel
;
5183 s
= mips_elf_rel_dyn_section (info
, FALSE
);
5184 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5186 outrel
.r_offset
= (input_section
->output_section
->vma
5187 + input_section
->output_offset
5188 + relocation
->r_offset
);
5189 outrel
.r_info
= ELF32_R_INFO (h
->root
.dynindx
, r_type
);
5190 outrel
.r_addend
= addend
;
5191 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
5193 /* If we've written this relocation for a readonly section,
5194 we need to set DF_TEXTREL again, so that we do not delete the
5196 if (MIPS_ELF_READONLY_SECTION (input_section
))
5197 info
->flags
|= DF_TEXTREL
;
5200 return bfd_reloc_ok
;
5203 /* Figure out what kind of relocation is being performed. */
5207 return bfd_reloc_continue
;
5210 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 16);
5211 overflowed_p
= mips_elf_overflow_p (value
, 16);
5218 || (htab
->root
.dynamic_sections_created
5220 && h
->root
.def_dynamic
5221 && !h
->root
.def_regular
5222 && !h
->has_static_relocs
))
5225 || h
->root
.root
.type
!= bfd_link_hash_undefweak
5226 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
5227 && (input_section
->flags
& SEC_ALLOC
) != 0)
5229 /* If we're creating a shared library, then we can't know
5230 where the symbol will end up. So, we create a relocation
5231 record in the output, and leave the job up to the dynamic
5232 linker. We must do the same for executable references to
5233 shared library symbols, unless we've decided to use copy
5234 relocs or PLTs instead. */
5236 if (!mips_elf_create_dynamic_relocation (abfd
,
5244 return bfd_reloc_undefined
;
5248 if (r_type
!= R_MIPS_REL32
)
5249 value
= symbol
+ addend
;
5253 value
&= howto
->dst_mask
;
5257 value
= symbol
+ addend
- p
;
5258 value
&= howto
->dst_mask
;
5262 /* The calculation for R_MIPS16_26 is just the same as for an
5263 R_MIPS_26. It's only the storage of the relocated field into
5264 the output file that's different. That's handled in
5265 mips_elf_perform_relocation. So, we just fall through to the
5266 R_MIPS_26 case here. */
5269 value
= ((addend
| ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
5272 value
= (_bfd_mips_elf_sign_extend (addend
, 28) + symbol
) >> 2;
5273 if (h
->root
.root
.type
!= bfd_link_hash_undefweak
)
5274 overflowed_p
= (value
>> 26) != ((p
+ 4) >> 28);
5276 value
&= howto
->dst_mask
;
5279 case R_MIPS_TLS_DTPREL_HI16
:
5280 value
= (mips_elf_high (addend
+ symbol
- dtprel_base (info
))
5284 case R_MIPS_TLS_DTPREL_LO16
:
5285 case R_MIPS_TLS_DTPREL32
:
5286 case R_MIPS_TLS_DTPREL64
:
5287 value
= (symbol
+ addend
- dtprel_base (info
)) & howto
->dst_mask
;
5290 case R_MIPS_TLS_TPREL_HI16
:
5291 value
= (mips_elf_high (addend
+ symbol
- tprel_base (info
))
5295 case R_MIPS_TLS_TPREL_LO16
:
5296 value
= (symbol
+ addend
- tprel_base (info
)) & howto
->dst_mask
;
5303 value
= mips_elf_high (addend
+ symbol
);
5304 value
&= howto
->dst_mask
;
5308 /* For MIPS16 ABI code we generate this sequence
5309 0: li $v0,%hi(_gp_disp)
5310 4: addiupc $v1,%lo(_gp_disp)
5314 So the offsets of hi and lo relocs are the same, but the
5315 $pc is four higher than $t9 would be, so reduce
5316 both reloc addends by 4. */
5317 if (r_type
== R_MIPS16_HI16
)
5318 value
= mips_elf_high (addend
+ gp
- p
- 4);
5320 value
= mips_elf_high (addend
+ gp
- p
);
5321 overflowed_p
= mips_elf_overflow_p (value
, 16);
5328 value
= (symbol
+ addend
) & howto
->dst_mask
;
5331 /* See the comment for R_MIPS16_HI16 above for the reason
5332 for this conditional. */
5333 if (r_type
== R_MIPS16_LO16
)
5334 value
= addend
+ gp
- p
;
5336 value
= addend
+ gp
- p
+ 4;
5337 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
5338 for overflow. But, on, say, IRIX5, relocations against
5339 _gp_disp are normally generated from the .cpload
5340 pseudo-op. It generates code that normally looks like
5343 lui $gp,%hi(_gp_disp)
5344 addiu $gp,$gp,%lo(_gp_disp)
5347 Here $t9 holds the address of the function being called,
5348 as required by the MIPS ELF ABI. The R_MIPS_LO16
5349 relocation can easily overflow in this situation, but the
5350 R_MIPS_HI16 relocation will handle the overflow.
5351 Therefore, we consider this a bug in the MIPS ABI, and do
5352 not check for overflow here. */
5356 case R_MIPS_LITERAL
:
5357 /* Because we don't merge literal sections, we can handle this
5358 just like R_MIPS_GPREL16. In the long run, we should merge
5359 shared literals, and then we will need to additional work
5364 case R_MIPS16_GPREL
:
5365 /* The R_MIPS16_GPREL performs the same calculation as
5366 R_MIPS_GPREL16, but stores the relocated bits in a different
5367 order. We don't need to do anything special here; the
5368 differences are handled in mips_elf_perform_relocation. */
5369 case R_MIPS_GPREL16
:
5370 /* Only sign-extend the addend if it was extracted from the
5371 instruction. If the addend was separate, leave it alone,
5372 otherwise we may lose significant bits. */
5373 if (howto
->partial_inplace
)
5374 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
5375 value
= symbol
+ addend
- gp
;
5376 /* If the symbol was local, any earlier relocatable links will
5377 have adjusted its addend with the gp offset, so compensate
5378 for that now. Don't do it for symbols forced local in this
5379 link, though, since they won't have had the gp offset applied
5383 overflowed_p
= mips_elf_overflow_p (value
, 16);
5386 case R_MIPS16_GOT16
:
5387 case R_MIPS16_CALL16
:
5390 /* VxWorks does not have separate local and global semantics for
5391 R_MIPS*_GOT16; every relocation evaluates to "G". */
5392 if (!htab
->is_vxworks
&& local_p
)
5396 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
5397 local_sections
, FALSE
);
5398 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
,
5399 symbol
+ addend
, forced
);
5400 if (value
== MINUS_ONE
)
5401 return bfd_reloc_outofrange
;
5403 = mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
5404 overflowed_p
= mips_elf_overflow_p (value
, 16);
5411 case R_MIPS_TLS_GOTTPREL
:
5412 case R_MIPS_TLS_LDM
:
5413 case R_MIPS_GOT_DISP
:
5416 overflowed_p
= mips_elf_overflow_p (value
, 16);
5419 case R_MIPS_GPREL32
:
5420 value
= (addend
+ symbol
+ gp0
- gp
);
5422 value
&= howto
->dst_mask
;
5426 case R_MIPS_GNU_REL16_S2
:
5427 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 18) - p
;
5428 overflowed_p
= mips_elf_overflow_p (value
, 18);
5429 value
>>= howto
->rightshift
;
5430 value
&= howto
->dst_mask
;
5433 case R_MIPS_GOT_HI16
:
5434 case R_MIPS_CALL_HI16
:
5435 /* We're allowed to handle these two relocations identically.
5436 The dynamic linker is allowed to handle the CALL relocations
5437 differently by creating a lazy evaluation stub. */
5439 value
= mips_elf_high (value
);
5440 value
&= howto
->dst_mask
;
5443 case R_MIPS_GOT_LO16
:
5444 case R_MIPS_CALL_LO16
:
5445 value
= g
& howto
->dst_mask
;
5448 case R_MIPS_GOT_PAGE
:
5449 /* GOT_PAGE relocations that reference non-local symbols decay
5450 to GOT_DISP. The corresponding GOT_OFST relocation decays to
5454 value
= mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, NULL
);
5455 if (value
== MINUS_ONE
)
5456 return bfd_reloc_outofrange
;
5457 value
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
5458 overflowed_p
= mips_elf_overflow_p (value
, 16);
5461 case R_MIPS_GOT_OFST
:
5463 mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, &value
);
5466 overflowed_p
= mips_elf_overflow_p (value
, 16);
5470 value
= symbol
- addend
;
5471 value
&= howto
->dst_mask
;
5475 value
= mips_elf_higher (addend
+ symbol
);
5476 value
&= howto
->dst_mask
;
5479 case R_MIPS_HIGHEST
:
5480 value
= mips_elf_highest (addend
+ symbol
);
5481 value
&= howto
->dst_mask
;
5484 case R_MIPS_SCN_DISP
:
5485 value
= symbol
+ addend
- sec
->output_offset
;
5486 value
&= howto
->dst_mask
;
5490 /* This relocation is only a hint. In some cases, we optimize
5491 it into a bal instruction. But we don't try to optimize
5492 branches to the PLT; that will wind up wasting time. */
5493 if (h
!= NULL
&& h
->root
.plt
.offset
!= (bfd_vma
) -1)
5494 return bfd_reloc_continue
;
5495 value
= symbol
+ addend
;
5499 case R_MIPS_GNU_VTINHERIT
:
5500 case R_MIPS_GNU_VTENTRY
:
5501 /* We don't do anything with these at present. */
5502 return bfd_reloc_continue
;
5505 /* An unrecognized relocation type. */
5506 return bfd_reloc_notsupported
;
5509 /* Store the VALUE for our caller. */
5511 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
5514 /* Obtain the field relocated by RELOCATION. */
5517 mips_elf_obtain_contents (reloc_howto_type
*howto
,
5518 const Elf_Internal_Rela
*relocation
,
5519 bfd
*input_bfd
, bfd_byte
*contents
)
5522 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5524 /* Obtain the bytes. */
5525 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
5530 /* It has been determined that the result of the RELOCATION is the
5531 VALUE. Use HOWTO to place VALUE into the output file at the
5532 appropriate position. The SECTION is the section to which the
5533 relocation applies. If REQUIRE_JALX is TRUE, then the opcode used
5534 for the relocation must be either JAL or JALX, and it is
5535 unconditionally converted to JALX.
5537 Returns FALSE if anything goes wrong. */
5540 mips_elf_perform_relocation (struct bfd_link_info
*info
,
5541 reloc_howto_type
*howto
,
5542 const Elf_Internal_Rela
*relocation
,
5543 bfd_vma value
, bfd
*input_bfd
,
5544 asection
*input_section
, bfd_byte
*contents
,
5545 bfd_boolean require_jalx
)
5549 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
5551 /* Figure out where the relocation is occurring. */
5552 location
= contents
+ relocation
->r_offset
;
5554 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
5556 /* Obtain the current value. */
5557 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
5559 /* Clear the field we are setting. */
5560 x
&= ~howto
->dst_mask
;
5562 /* Set the field. */
5563 x
|= (value
& howto
->dst_mask
);
5565 /* If required, turn JAL into JALX. */
5569 bfd_vma opcode
= x
>> 26;
5570 bfd_vma jalx_opcode
;
5572 /* Check to see if the opcode is already JAL or JALX. */
5573 if (r_type
== R_MIPS16_26
)
5575 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
5580 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
5584 /* If the opcode is not JAL or JALX, there's a problem. */
5587 (*_bfd_error_handler
)
5588 (_("%B: %A+0x%lx: jump to stub routine which is not jal"),
5591 (unsigned long) relocation
->r_offset
);
5592 bfd_set_error (bfd_error_bad_value
);
5596 /* Make this the JALX opcode. */
5597 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
5600 /* Try converting JAL and JALR to BAL, if the target is in range. */
5601 if (!info
->relocatable
5603 && ((JAL_TO_BAL_P (input_bfd
)
5604 && r_type
== R_MIPS_26
5605 && (x
>> 26) == 0x3) /* jal addr */
5606 || (JALR_TO_BAL_P (input_bfd
)
5607 && r_type
== R_MIPS_JALR
5608 && x
== 0x0320f809))) /* jalr t9 */
5614 addr
= (input_section
->output_section
->vma
5615 + input_section
->output_offset
5616 + relocation
->r_offset
5618 if (r_type
== R_MIPS_26
)
5619 dest
= (value
<< 2) | ((addr
>> 28) << 28);
5623 if (off
<= 0x1ffff && off
>= -0x20000)
5624 x
= 0x04110000 | (((bfd_vma
) off
>> 2) & 0xffff); /* bal addr */
5627 /* Put the value into the output. */
5628 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
5630 _bfd_mips16_elf_reloc_shuffle(input_bfd
, r_type
, !info
->relocatable
,
5636 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
5637 is the original relocation, which is now being transformed into a
5638 dynamic relocation. The ADDENDP is adjusted if necessary; the
5639 caller should store the result in place of the original addend. */
5642 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
5643 struct bfd_link_info
*info
,
5644 const Elf_Internal_Rela
*rel
,
5645 struct mips_elf_link_hash_entry
*h
,
5646 asection
*sec
, bfd_vma symbol
,
5647 bfd_vma
*addendp
, asection
*input_section
)
5649 Elf_Internal_Rela outrel
[3];
5654 bfd_boolean defined_p
;
5655 struct mips_elf_link_hash_table
*htab
;
5657 htab
= mips_elf_hash_table (info
);
5658 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
5659 dynobj
= elf_hash_table (info
)->dynobj
;
5660 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
5661 BFD_ASSERT (sreloc
!= NULL
);
5662 BFD_ASSERT (sreloc
->contents
!= NULL
);
5663 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
5666 outrel
[0].r_offset
=
5667 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
5668 if (ABI_64_P (output_bfd
))
5670 outrel
[1].r_offset
=
5671 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
5672 outrel
[2].r_offset
=
5673 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
5676 if (outrel
[0].r_offset
== MINUS_ONE
)
5677 /* The relocation field has been deleted. */
5680 if (outrel
[0].r_offset
== MINUS_TWO
)
5682 /* The relocation field has been converted into a relative value of
5683 some sort. Functions like _bfd_elf_write_section_eh_frame expect
5684 the field to be fully relocated, so add in the symbol's value. */
5689 /* We must now calculate the dynamic symbol table index to use
5690 in the relocation. */
5692 && (!h
->root
.def_regular
5693 || (info
->shared
&& !info
->symbolic
&& !h
->root
.forced_local
)))
5695 indx
= h
->root
.dynindx
;
5696 if (SGI_COMPAT (output_bfd
))
5697 defined_p
= h
->root
.def_regular
;
5699 /* ??? glibc's ld.so just adds the final GOT entry to the
5700 relocation field. It therefore treats relocs against
5701 defined symbols in the same way as relocs against
5702 undefined symbols. */
5707 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5709 else if (sec
== NULL
|| sec
->owner
== NULL
)
5711 bfd_set_error (bfd_error_bad_value
);
5716 indx
= elf_section_data (sec
->output_section
)->dynindx
;
5719 asection
*osec
= htab
->root
.text_index_section
;
5720 indx
= elf_section_data (osec
)->dynindx
;
5726 /* Instead of generating a relocation using the section
5727 symbol, we may as well make it a fully relative
5728 relocation. We want to avoid generating relocations to
5729 local symbols because we used to generate them
5730 incorrectly, without adding the original symbol value,
5731 which is mandated by the ABI for section symbols. In
5732 order to give dynamic loaders and applications time to
5733 phase out the incorrect use, we refrain from emitting
5734 section-relative relocations. It's not like they're
5735 useful, after all. This should be a bit more efficient
5737 /* ??? Although this behavior is compatible with glibc's ld.so,
5738 the ABI says that relocations against STN_UNDEF should have
5739 a symbol value of 0. Irix rld honors this, so relocations
5740 against STN_UNDEF have no effect. */
5741 if (!SGI_COMPAT (output_bfd
))
5746 /* If the relocation was previously an absolute relocation and
5747 this symbol will not be referred to by the relocation, we must
5748 adjust it by the value we give it in the dynamic symbol table.
5749 Otherwise leave the job up to the dynamic linker. */
5750 if (defined_p
&& r_type
!= R_MIPS_REL32
)
5753 if (htab
->is_vxworks
)
5754 /* VxWorks uses non-relative relocations for this. */
5755 outrel
[0].r_info
= ELF32_R_INFO (indx
, R_MIPS_32
);
5757 /* The relocation is always an REL32 relocation because we don't
5758 know where the shared library will wind up at load-time. */
5759 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
5762 /* For strict adherence to the ABI specification, we should
5763 generate a R_MIPS_64 relocation record by itself before the
5764 _REL32/_64 record as well, such that the addend is read in as
5765 a 64-bit value (REL32 is a 32-bit relocation, after all).
5766 However, since none of the existing ELF64 MIPS dynamic
5767 loaders seems to care, we don't waste space with these
5768 artificial relocations. If this turns out to not be true,
5769 mips_elf_allocate_dynamic_relocation() should be tweaked so
5770 as to make room for a pair of dynamic relocations per
5771 invocation if ABI_64_P, and here we should generate an
5772 additional relocation record with R_MIPS_64 by itself for a
5773 NULL symbol before this relocation record. */
5774 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
5775 ABI_64_P (output_bfd
)
5778 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
5780 /* Adjust the output offset of the relocation to reference the
5781 correct location in the output file. */
5782 outrel
[0].r_offset
+= (input_section
->output_section
->vma
5783 + input_section
->output_offset
);
5784 outrel
[1].r_offset
+= (input_section
->output_section
->vma
5785 + input_section
->output_offset
);
5786 outrel
[2].r_offset
+= (input_section
->output_section
->vma
5787 + input_section
->output_offset
);
5789 /* Put the relocation back out. We have to use the special
5790 relocation outputter in the 64-bit case since the 64-bit
5791 relocation format is non-standard. */
5792 if (ABI_64_P (output_bfd
))
5794 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
5795 (output_bfd
, &outrel
[0],
5797 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
5799 else if (htab
->is_vxworks
)
5801 /* VxWorks uses RELA rather than REL dynamic relocations. */
5802 outrel
[0].r_addend
= *addendp
;
5803 bfd_elf32_swap_reloca_out
5804 (output_bfd
, &outrel
[0],
5806 + sreloc
->reloc_count
* sizeof (Elf32_External_Rela
)));
5809 bfd_elf32_swap_reloc_out
5810 (output_bfd
, &outrel
[0],
5811 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
5813 /* We've now added another relocation. */
5814 ++sreloc
->reloc_count
;
5816 /* Make sure the output section is writable. The dynamic linker
5817 will be writing to it. */
5818 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5821 /* On IRIX5, make an entry of compact relocation info. */
5822 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
5824 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5829 Elf32_crinfo cptrel
;
5831 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5832 cptrel
.vaddr
= (rel
->r_offset
5833 + input_section
->output_section
->vma
5834 + input_section
->output_offset
);
5835 if (r_type
== R_MIPS_REL32
)
5836 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5838 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5839 mips_elf_set_cr_dist2to (cptrel
, 0);
5840 cptrel
.konst
= *addendp
;
5842 cr
= (scpt
->contents
5843 + sizeof (Elf32_External_compact_rel
));
5844 mips_elf_set_cr_relvaddr (cptrel
, 0);
5845 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5846 ((Elf32_External_crinfo
*) cr
5847 + scpt
->reloc_count
));
5848 ++scpt
->reloc_count
;
5852 /* If we've written this relocation for a readonly section,
5853 we need to set DF_TEXTREL again, so that we do not delete the
5855 if (MIPS_ELF_READONLY_SECTION (input_section
))
5856 info
->flags
|= DF_TEXTREL
;
5861 /* Return the MACH for a MIPS e_flags value. */
5864 _bfd_elf_mips_mach (flagword flags
)
5866 switch (flags
& EF_MIPS_MACH
)
5868 case E_MIPS_MACH_3900
:
5869 return bfd_mach_mips3900
;
5871 case E_MIPS_MACH_4010
:
5872 return bfd_mach_mips4010
;
5874 case E_MIPS_MACH_4100
:
5875 return bfd_mach_mips4100
;
5877 case E_MIPS_MACH_4111
:
5878 return bfd_mach_mips4111
;
5880 case E_MIPS_MACH_4120
:
5881 return bfd_mach_mips4120
;
5883 case E_MIPS_MACH_4650
:
5884 return bfd_mach_mips4650
;
5886 case E_MIPS_MACH_5400
:
5887 return bfd_mach_mips5400
;
5889 case E_MIPS_MACH_5500
:
5890 return bfd_mach_mips5500
;
5892 case E_MIPS_MACH_9000
:
5893 return bfd_mach_mips9000
;
5895 case E_MIPS_MACH_SB1
:
5896 return bfd_mach_mips_sb1
;
5898 case E_MIPS_MACH_LS2E
:
5899 return bfd_mach_mips_loongson_2e
;
5901 case E_MIPS_MACH_LS2F
:
5902 return bfd_mach_mips_loongson_2f
;
5904 case E_MIPS_MACH_OCTEON
:
5905 return bfd_mach_mips_octeon
;
5907 case E_MIPS_MACH_XLR
:
5908 return bfd_mach_mips_xlr
;
5911 switch (flags
& EF_MIPS_ARCH
)
5915 return bfd_mach_mips3000
;
5918 return bfd_mach_mips6000
;
5921 return bfd_mach_mips4000
;
5924 return bfd_mach_mips8000
;
5927 return bfd_mach_mips5
;
5929 case E_MIPS_ARCH_32
:
5930 return bfd_mach_mipsisa32
;
5932 case E_MIPS_ARCH_64
:
5933 return bfd_mach_mipsisa64
;
5935 case E_MIPS_ARCH_32R2
:
5936 return bfd_mach_mipsisa32r2
;
5938 case E_MIPS_ARCH_64R2
:
5939 return bfd_mach_mipsisa64r2
;
5946 /* Return printable name for ABI. */
5948 static INLINE
char *
5949 elf_mips_abi_name (bfd
*abfd
)
5953 flags
= elf_elfheader (abfd
)->e_flags
;
5954 switch (flags
& EF_MIPS_ABI
)
5957 if (ABI_N32_P (abfd
))
5959 else if (ABI_64_P (abfd
))
5963 case E_MIPS_ABI_O32
:
5965 case E_MIPS_ABI_O64
:
5967 case E_MIPS_ABI_EABI32
:
5969 case E_MIPS_ABI_EABI64
:
5972 return "unknown abi";
5976 /* MIPS ELF uses two common sections. One is the usual one, and the
5977 other is for small objects. All the small objects are kept
5978 together, and then referenced via the gp pointer, which yields
5979 faster assembler code. This is what we use for the small common
5980 section. This approach is copied from ecoff.c. */
5981 static asection mips_elf_scom_section
;
5982 static asymbol mips_elf_scom_symbol
;
5983 static asymbol
*mips_elf_scom_symbol_ptr
;
5985 /* MIPS ELF also uses an acommon section, which represents an
5986 allocated common symbol which may be overridden by a
5987 definition in a shared library. */
5988 static asection mips_elf_acom_section
;
5989 static asymbol mips_elf_acom_symbol
;
5990 static asymbol
*mips_elf_acom_symbol_ptr
;
5992 /* This is used for both the 32-bit and the 64-bit ABI. */
5995 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
5997 elf_symbol_type
*elfsym
;
5999 /* Handle the special MIPS section numbers that a symbol may use. */
6000 elfsym
= (elf_symbol_type
*) asym
;
6001 switch (elfsym
->internal_elf_sym
.st_shndx
)
6003 case SHN_MIPS_ACOMMON
:
6004 /* This section is used in a dynamically linked executable file.
6005 It is an allocated common section. The dynamic linker can
6006 either resolve these symbols to something in a shared
6007 library, or it can just leave them here. For our purposes,
6008 we can consider these symbols to be in a new section. */
6009 if (mips_elf_acom_section
.name
== NULL
)
6011 /* Initialize the acommon section. */
6012 mips_elf_acom_section
.name
= ".acommon";
6013 mips_elf_acom_section
.flags
= SEC_ALLOC
;
6014 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
6015 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
6016 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
6017 mips_elf_acom_symbol
.name
= ".acommon";
6018 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
6019 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
6020 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
6022 asym
->section
= &mips_elf_acom_section
;
6026 /* Common symbols less than the GP size are automatically
6027 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
6028 if (asym
->value
> elf_gp_size (abfd
)
6029 || ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_TLS
6030 || IRIX_COMPAT (abfd
) == ict_irix6
)
6033 case SHN_MIPS_SCOMMON
:
6034 if (mips_elf_scom_section
.name
== NULL
)
6036 /* Initialize the small common section. */
6037 mips_elf_scom_section
.name
= ".scommon";
6038 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
6039 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
6040 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
6041 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
6042 mips_elf_scom_symbol
.name
= ".scommon";
6043 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
6044 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
6045 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
6047 asym
->section
= &mips_elf_scom_section
;
6048 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
6051 case SHN_MIPS_SUNDEFINED
:
6052 asym
->section
= bfd_und_section_ptr
;
6057 asection
*section
= bfd_get_section_by_name (abfd
, ".text");
6059 BFD_ASSERT (SGI_COMPAT (abfd
));
6060 if (section
!= NULL
)
6062 asym
->section
= section
;
6063 /* MIPS_TEXT is a bit special, the address is not an offset
6064 to the base of the .text section. So substract the section
6065 base address to make it an offset. */
6066 asym
->value
-= section
->vma
;
6073 asection
*section
= bfd_get_section_by_name (abfd
, ".data");
6075 BFD_ASSERT (SGI_COMPAT (abfd
));
6076 if (section
!= NULL
)
6078 asym
->section
= section
;
6079 /* MIPS_DATA is a bit special, the address is not an offset
6080 to the base of the .data section. So substract the section
6081 base address to make it an offset. */
6082 asym
->value
-= section
->vma
;
6088 /* If this is an odd-valued function symbol, assume it's a MIPS16 one. */
6089 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_FUNC
6090 && (asym
->value
& 1) != 0)
6093 elfsym
->internal_elf_sym
.st_other
6094 = ELF_ST_SET_MIPS16 (elfsym
->internal_elf_sym
.st_other
);
6098 /* Implement elf_backend_eh_frame_address_size. This differs from
6099 the default in the way it handles EABI64.
6101 EABI64 was originally specified as an LP64 ABI, and that is what
6102 -mabi=eabi normally gives on a 64-bit target. However, gcc has
6103 historically accepted the combination of -mabi=eabi and -mlong32,
6104 and this ILP32 variation has become semi-official over time.
6105 Both forms use elf32 and have pointer-sized FDE addresses.
6107 If an EABI object was generated by GCC 4.0 or above, it will have
6108 an empty .gcc_compiled_longXX section, where XX is the size of longs
6109 in bits. Unfortunately, ILP32 objects generated by earlier compilers
6110 have no special marking to distinguish them from LP64 objects.
6112 We don't want users of the official LP64 ABI to be punished for the
6113 existence of the ILP32 variant, but at the same time, we don't want
6114 to mistakenly interpret pre-4.0 ILP32 objects as being LP64 objects.
6115 We therefore take the following approach:
6117 - If ABFD contains a .gcc_compiled_longXX section, use it to
6118 determine the pointer size.
6120 - Otherwise check the type of the first relocation. Assume that
6121 the LP64 ABI is being used if the relocation is of type R_MIPS_64.
6125 The second check is enough to detect LP64 objects generated by pre-4.0
6126 compilers because, in the kind of output generated by those compilers,
6127 the first relocation will be associated with either a CIE personality
6128 routine or an FDE start address. Furthermore, the compilers never
6129 used a special (non-pointer) encoding for this ABI.
6131 Checking the relocation type should also be safe because there is no
6132 reason to use R_MIPS_64 in an ILP32 object. Pre-4.0 compilers never
6136 _bfd_mips_elf_eh_frame_address_size (bfd
*abfd
, asection
*sec
)
6138 if (elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
6140 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
6142 bfd_boolean long32_p
, long64_p
;
6144 long32_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long32") != 0;
6145 long64_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long64") != 0;
6146 if (long32_p
&& long64_p
)
6153 if (sec
->reloc_count
> 0
6154 && elf_section_data (sec
)->relocs
!= NULL
6155 && (ELF32_R_TYPE (elf_section_data (sec
)->relocs
[0].r_info
)
6164 /* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
6165 relocations against two unnamed section symbols to resolve to the
6166 same address. For example, if we have code like:
6168 lw $4,%got_disp(.data)($gp)
6169 lw $25,%got_disp(.text)($gp)
6172 then the linker will resolve both relocations to .data and the program
6173 will jump there rather than to .text.
6175 We can work around this problem by giving names to local section symbols.
6176 This is also what the MIPSpro tools do. */
6179 _bfd_mips_elf_name_local_section_symbols (bfd
*abfd
)
6181 return SGI_COMPAT (abfd
);
6184 /* Work over a section just before writing it out. This routine is
6185 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
6186 sections that need the SHF_MIPS_GPREL flag by name; there has to be
6190 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
6192 if (hdr
->sh_type
== SHT_MIPS_REGINFO
6193 && hdr
->sh_size
> 0)
6197 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
6198 BFD_ASSERT (hdr
->contents
== NULL
);
6201 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
6204 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
6205 if (bfd_bwrite (buf
, 4, abfd
) != 4)
6209 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
6210 && hdr
->bfd_section
!= NULL
6211 && mips_elf_section_data (hdr
->bfd_section
) != NULL
6212 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
6214 bfd_byte
*contents
, *l
, *lend
;
6216 /* We stored the section contents in the tdata field in the
6217 set_section_contents routine. We save the section contents
6218 so that we don't have to read them again.
6219 At this point we know that elf_gp is set, so we can look
6220 through the section contents to see if there is an
6221 ODK_REGINFO structure. */
6223 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
6225 lend
= contents
+ hdr
->sh_size
;
6226 while (l
+ sizeof (Elf_External_Options
) <= lend
)
6228 Elf_Internal_Options intopt
;
6230 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
6232 if (intopt
.size
< sizeof (Elf_External_Options
))
6234 (*_bfd_error_handler
)
6235 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
6236 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
6239 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
6246 + sizeof (Elf_External_Options
)
6247 + (sizeof (Elf64_External_RegInfo
) - 8)),
6250 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
6251 if (bfd_bwrite (buf
, 8, abfd
) != 8)
6254 else if (intopt
.kind
== ODK_REGINFO
)
6261 + sizeof (Elf_External_Options
)
6262 + (sizeof (Elf32_External_RegInfo
) - 4)),
6265 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
6266 if (bfd_bwrite (buf
, 4, abfd
) != 4)
6273 if (hdr
->bfd_section
!= NULL
)
6275 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
6277 /* .sbss is not handled specially here because the GNU/Linux
6278 prelinker can convert .sbss from NOBITS to PROGBITS and
6279 changing it back to NOBITS breaks the binary. The entry in
6280 _bfd_mips_elf_special_sections will ensure the correct flags
6281 are set on .sbss if BFD creates it without reading it from an
6282 input file, and without special handling here the flags set
6283 on it in an input file will be followed. */
6284 if (strcmp (name
, ".sdata") == 0
6285 || strcmp (name
, ".lit8") == 0
6286 || strcmp (name
, ".lit4") == 0)
6288 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
6289 hdr
->sh_type
= SHT_PROGBITS
;
6291 else if (strcmp (name
, ".srdata") == 0)
6293 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
6294 hdr
->sh_type
= SHT_PROGBITS
;
6296 else if (strcmp (name
, ".compact_rel") == 0)
6299 hdr
->sh_type
= SHT_PROGBITS
;
6301 else if (strcmp (name
, ".rtproc") == 0)
6303 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
6305 unsigned int adjust
;
6307 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
6309 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
6317 /* Handle a MIPS specific section when reading an object file. This
6318 is called when elfcode.h finds a section with an unknown type.
6319 This routine supports both the 32-bit and 64-bit ELF ABI.
6321 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
6325 _bfd_mips_elf_section_from_shdr (bfd
*abfd
,
6326 Elf_Internal_Shdr
*hdr
,
6332 /* There ought to be a place to keep ELF backend specific flags, but
6333 at the moment there isn't one. We just keep track of the
6334 sections by their name, instead. Fortunately, the ABI gives
6335 suggested names for all the MIPS specific sections, so we will
6336 probably get away with this. */
6337 switch (hdr
->sh_type
)
6339 case SHT_MIPS_LIBLIST
:
6340 if (strcmp (name
, ".liblist") != 0)
6344 if (strcmp (name
, ".msym") != 0)
6347 case SHT_MIPS_CONFLICT
:
6348 if (strcmp (name
, ".conflict") != 0)
6351 case SHT_MIPS_GPTAB
:
6352 if (! CONST_STRNEQ (name
, ".gptab."))
6355 case SHT_MIPS_UCODE
:
6356 if (strcmp (name
, ".ucode") != 0)
6359 case SHT_MIPS_DEBUG
:
6360 if (strcmp (name
, ".mdebug") != 0)
6362 flags
= SEC_DEBUGGING
;
6364 case SHT_MIPS_REGINFO
:
6365 if (strcmp (name
, ".reginfo") != 0
6366 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
6368 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
6370 case SHT_MIPS_IFACE
:
6371 if (strcmp (name
, ".MIPS.interfaces") != 0)
6374 case SHT_MIPS_CONTENT
:
6375 if (! CONST_STRNEQ (name
, ".MIPS.content"))
6378 case SHT_MIPS_OPTIONS
:
6379 if (!MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
6382 case SHT_MIPS_DWARF
:
6383 if (! CONST_STRNEQ (name
, ".debug_")
6384 && ! CONST_STRNEQ (name
, ".zdebug_"))
6387 case SHT_MIPS_SYMBOL_LIB
:
6388 if (strcmp (name
, ".MIPS.symlib") != 0)
6391 case SHT_MIPS_EVENTS
:
6392 if (! CONST_STRNEQ (name
, ".MIPS.events")
6393 && ! CONST_STRNEQ (name
, ".MIPS.post_rel"))
6400 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6405 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
6406 (bfd_get_section_flags (abfd
,
6412 /* FIXME: We should record sh_info for a .gptab section. */
6414 /* For a .reginfo section, set the gp value in the tdata information
6415 from the contents of this section. We need the gp value while
6416 processing relocs, so we just get it now. The .reginfo section
6417 is not used in the 64-bit MIPS ELF ABI. */
6418 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
6420 Elf32_External_RegInfo ext
;
6423 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
6424 &ext
, 0, sizeof ext
))
6426 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
6427 elf_gp (abfd
) = s
.ri_gp_value
;
6430 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
6431 set the gp value based on what we find. We may see both
6432 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
6433 they should agree. */
6434 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
6436 bfd_byte
*contents
, *l
, *lend
;
6438 contents
= bfd_malloc (hdr
->sh_size
);
6439 if (contents
== NULL
)
6441 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
6448 lend
= contents
+ hdr
->sh_size
;
6449 while (l
+ sizeof (Elf_External_Options
) <= lend
)
6451 Elf_Internal_Options intopt
;
6453 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
6455 if (intopt
.size
< sizeof (Elf_External_Options
))
6457 (*_bfd_error_handler
)
6458 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
6459 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
6462 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
6464 Elf64_Internal_RegInfo intreg
;
6466 bfd_mips_elf64_swap_reginfo_in
6468 ((Elf64_External_RegInfo
*)
6469 (l
+ sizeof (Elf_External_Options
))),
6471 elf_gp (abfd
) = intreg
.ri_gp_value
;
6473 else if (intopt
.kind
== ODK_REGINFO
)
6475 Elf32_RegInfo intreg
;
6477 bfd_mips_elf32_swap_reginfo_in
6479 ((Elf32_External_RegInfo
*)
6480 (l
+ sizeof (Elf_External_Options
))),
6482 elf_gp (abfd
) = intreg
.ri_gp_value
;
6492 /* Set the correct type for a MIPS ELF section. We do this by the
6493 section name, which is a hack, but ought to work. This routine is
6494 used by both the 32-bit and the 64-bit ABI. */
6497 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
6499 const char *name
= bfd_get_section_name (abfd
, sec
);
6501 if (strcmp (name
, ".liblist") == 0)
6503 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
6504 hdr
->sh_info
= sec
->size
/ sizeof (Elf32_Lib
);
6505 /* The sh_link field is set in final_write_processing. */
6507 else if (strcmp (name
, ".conflict") == 0)
6508 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
6509 else if (CONST_STRNEQ (name
, ".gptab."))
6511 hdr
->sh_type
= SHT_MIPS_GPTAB
;
6512 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
6513 /* The sh_info field is set in final_write_processing. */
6515 else if (strcmp (name
, ".ucode") == 0)
6516 hdr
->sh_type
= SHT_MIPS_UCODE
;
6517 else if (strcmp (name
, ".mdebug") == 0)
6519 hdr
->sh_type
= SHT_MIPS_DEBUG
;
6520 /* In a shared object on IRIX 5.3, the .mdebug section has an
6521 entsize of 0. FIXME: Does this matter? */
6522 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
6523 hdr
->sh_entsize
= 0;
6525 hdr
->sh_entsize
= 1;
6527 else if (strcmp (name
, ".reginfo") == 0)
6529 hdr
->sh_type
= SHT_MIPS_REGINFO
;
6530 /* In a shared object on IRIX 5.3, the .reginfo section has an
6531 entsize of 0x18. FIXME: Does this matter? */
6532 if (SGI_COMPAT (abfd
))
6534 if ((abfd
->flags
& DYNAMIC
) != 0)
6535 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6537 hdr
->sh_entsize
= 1;
6540 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6542 else if (SGI_COMPAT (abfd
)
6543 && (strcmp (name
, ".hash") == 0
6544 || strcmp (name
, ".dynamic") == 0
6545 || strcmp (name
, ".dynstr") == 0))
6547 if (SGI_COMPAT (abfd
))
6548 hdr
->sh_entsize
= 0;
6550 /* This isn't how the IRIX6 linker behaves. */
6551 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6554 else if (strcmp (name
, ".got") == 0
6555 || strcmp (name
, ".srdata") == 0
6556 || strcmp (name
, ".sdata") == 0
6557 || strcmp (name
, ".sbss") == 0
6558 || strcmp (name
, ".lit4") == 0
6559 || strcmp (name
, ".lit8") == 0)
6560 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
6561 else if (strcmp (name
, ".MIPS.interfaces") == 0)
6563 hdr
->sh_type
= SHT_MIPS_IFACE
;
6564 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6566 else if (CONST_STRNEQ (name
, ".MIPS.content"))
6568 hdr
->sh_type
= SHT_MIPS_CONTENT
;
6569 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6570 /* The sh_info field is set in final_write_processing. */
6572 else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
6574 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
6575 hdr
->sh_entsize
= 1;
6576 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6578 else if (CONST_STRNEQ (name
, ".debug_")
6579 || CONST_STRNEQ (name
, ".zdebug_"))
6581 hdr
->sh_type
= SHT_MIPS_DWARF
;
6583 /* Irix facilities such as libexc expect a single .debug_frame
6584 per executable, the system ones have NOSTRIP set and the linker
6585 doesn't merge sections with different flags so ... */
6586 if (SGI_COMPAT (abfd
) && CONST_STRNEQ (name
, ".debug_frame"))
6587 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6589 else if (strcmp (name
, ".MIPS.symlib") == 0)
6591 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
6592 /* The sh_link and sh_info fields are set in
6593 final_write_processing. */
6595 else if (CONST_STRNEQ (name
, ".MIPS.events")
6596 || CONST_STRNEQ (name
, ".MIPS.post_rel"))
6598 hdr
->sh_type
= SHT_MIPS_EVENTS
;
6599 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6600 /* The sh_link field is set in final_write_processing. */
6602 else if (strcmp (name
, ".msym") == 0)
6604 hdr
->sh_type
= SHT_MIPS_MSYM
;
6605 hdr
->sh_flags
|= SHF_ALLOC
;
6606 hdr
->sh_entsize
= 8;
6609 /* The generic elf_fake_sections will set up REL_HDR using the default
6610 kind of relocations. We used to set up a second header for the
6611 non-default kind of relocations here, but only NewABI would use
6612 these, and the IRIX ld doesn't like resulting empty RELA sections.
6613 Thus we create those header only on demand now. */
6618 /* Given a BFD section, try to locate the corresponding ELF section
6619 index. This is used by both the 32-bit and the 64-bit ABI.
6620 Actually, it's not clear to me that the 64-bit ABI supports these,
6621 but for non-PIC objects we will certainly want support for at least
6622 the .scommon section. */
6625 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6626 asection
*sec
, int *retval
)
6628 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
6630 *retval
= SHN_MIPS_SCOMMON
;
6633 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
6635 *retval
= SHN_MIPS_ACOMMON
;
6641 /* Hook called by the linker routine which adds symbols from an object
6642 file. We must handle the special MIPS section numbers here. */
6645 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
6646 Elf_Internal_Sym
*sym
, const char **namep
,
6647 flagword
*flagsp ATTRIBUTE_UNUSED
,
6648 asection
**secp
, bfd_vma
*valp
)
6650 if (SGI_COMPAT (abfd
)
6651 && (abfd
->flags
& DYNAMIC
) != 0
6652 && strcmp (*namep
, "_rld_new_interface") == 0)
6654 /* Skip IRIX5 rld entry name. */
6659 /* Shared objects may have a dynamic symbol '_gp_disp' defined as
6660 a SECTION *ABS*. This causes ld to think it can resolve _gp_disp
6661 by setting a DT_NEEDED for the shared object. Since _gp_disp is
6662 a magic symbol resolved by the linker, we ignore this bogus definition
6663 of _gp_disp. New ABI objects do not suffer from this problem so this
6664 is not done for them. */
6666 && (sym
->st_shndx
== SHN_ABS
)
6667 && (strcmp (*namep
, "_gp_disp") == 0))
6673 switch (sym
->st_shndx
)
6676 /* Common symbols less than the GP size are automatically
6677 treated as SHN_MIPS_SCOMMON symbols. */
6678 if (sym
->st_size
> elf_gp_size (abfd
)
6679 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
6680 || IRIX_COMPAT (abfd
) == ict_irix6
)
6683 case SHN_MIPS_SCOMMON
:
6684 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
6685 (*secp
)->flags
|= SEC_IS_COMMON
;
6686 *valp
= sym
->st_size
;
6690 /* This section is used in a shared object. */
6691 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
6693 asymbol
*elf_text_symbol
;
6694 asection
*elf_text_section
;
6695 bfd_size_type amt
= sizeof (asection
);
6697 elf_text_section
= bfd_zalloc (abfd
, amt
);
6698 if (elf_text_section
== NULL
)
6701 amt
= sizeof (asymbol
);
6702 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
6703 if (elf_text_symbol
== NULL
)
6706 /* Initialize the section. */
6708 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
6709 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
6711 elf_text_section
->symbol
= elf_text_symbol
;
6712 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
6714 elf_text_section
->name
= ".text";
6715 elf_text_section
->flags
= SEC_NO_FLAGS
;
6716 elf_text_section
->output_section
= NULL
;
6717 elf_text_section
->owner
= abfd
;
6718 elf_text_symbol
->name
= ".text";
6719 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6720 elf_text_symbol
->section
= elf_text_section
;
6722 /* This code used to do *secp = bfd_und_section_ptr if
6723 info->shared. I don't know why, and that doesn't make sense,
6724 so I took it out. */
6725 *secp
= elf_tdata (abfd
)->elf_text_section
;
6728 case SHN_MIPS_ACOMMON
:
6729 /* Fall through. XXX Can we treat this as allocated data? */
6731 /* This section is used in a shared object. */
6732 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
6734 asymbol
*elf_data_symbol
;
6735 asection
*elf_data_section
;
6736 bfd_size_type amt
= sizeof (asection
);
6738 elf_data_section
= bfd_zalloc (abfd
, amt
);
6739 if (elf_data_section
== NULL
)
6742 amt
= sizeof (asymbol
);
6743 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
6744 if (elf_data_symbol
== NULL
)
6747 /* Initialize the section. */
6749 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
6750 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
6752 elf_data_section
->symbol
= elf_data_symbol
;
6753 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
6755 elf_data_section
->name
= ".data";
6756 elf_data_section
->flags
= SEC_NO_FLAGS
;
6757 elf_data_section
->output_section
= NULL
;
6758 elf_data_section
->owner
= abfd
;
6759 elf_data_symbol
->name
= ".data";
6760 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6761 elf_data_symbol
->section
= elf_data_section
;
6763 /* This code used to do *secp = bfd_und_section_ptr if
6764 info->shared. I don't know why, and that doesn't make sense,
6765 so I took it out. */
6766 *secp
= elf_tdata (abfd
)->elf_data_section
;
6769 case SHN_MIPS_SUNDEFINED
:
6770 *secp
= bfd_und_section_ptr
;
6774 if (SGI_COMPAT (abfd
)
6776 && info
->output_bfd
->xvec
== abfd
->xvec
6777 && strcmp (*namep
, "__rld_obj_head") == 0)
6779 struct elf_link_hash_entry
*h
;
6780 struct bfd_link_hash_entry
*bh
;
6782 /* Mark __rld_obj_head as dynamic. */
6784 if (! (_bfd_generic_link_add_one_symbol
6785 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
6786 get_elf_backend_data (abfd
)->collect
, &bh
)))
6789 h
= (struct elf_link_hash_entry
*) bh
;
6792 h
->type
= STT_OBJECT
;
6794 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6797 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
6800 /* If this is a mips16 text symbol, add 1 to the value to make it
6801 odd. This will cause something like .word SYM to come up with
6802 the right value when it is loaded into the PC. */
6803 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6809 /* This hook function is called before the linker writes out a global
6810 symbol. We mark symbols as small common if appropriate. This is
6811 also where we undo the increment of the value for a mips16 symbol. */
6814 _bfd_mips_elf_link_output_symbol_hook
6815 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6816 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
6817 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
6819 /* If we see a common symbol, which implies a relocatable link, then
6820 if a symbol was small common in an input file, mark it as small
6821 common in the output file. */
6822 if (sym
->st_shndx
== SHN_COMMON
6823 && strcmp (input_sec
->name
, ".scommon") == 0)
6824 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
6826 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6827 sym
->st_value
&= ~1;
6832 /* Functions for the dynamic linker. */
6834 /* Create dynamic sections when linking against a dynamic object. */
6837 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
6839 struct elf_link_hash_entry
*h
;
6840 struct bfd_link_hash_entry
*bh
;
6842 register asection
*s
;
6843 const char * const *namep
;
6844 struct mips_elf_link_hash_table
*htab
;
6846 htab
= mips_elf_hash_table (info
);
6847 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6848 | SEC_LINKER_CREATED
| SEC_READONLY
);
6850 /* The psABI requires a read-only .dynamic section, but the VxWorks
6852 if (!htab
->is_vxworks
)
6854 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6857 if (! bfd_set_section_flags (abfd
, s
, flags
))
6862 /* We need to create .got section. */
6863 if (!mips_elf_create_got_section (abfd
, info
))
6866 if (! mips_elf_rel_dyn_section (info
, TRUE
))
6869 /* Create .stub section. */
6870 s
= bfd_make_section_with_flags (abfd
,
6871 MIPS_ELF_STUB_SECTION_NAME (abfd
),
6874 || ! bfd_set_section_alignment (abfd
, s
,
6875 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6879 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
6881 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
6883 s
= bfd_make_section_with_flags (abfd
, ".rld_map",
6884 flags
&~ (flagword
) SEC_READONLY
);
6886 || ! bfd_set_section_alignment (abfd
, s
,
6887 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6891 /* On IRIX5, we adjust add some additional symbols and change the
6892 alignments of several sections. There is no ABI documentation
6893 indicating that this is necessary on IRIX6, nor any evidence that
6894 the linker takes such action. */
6895 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6897 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
6900 if (! (_bfd_generic_link_add_one_symbol
6901 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
6902 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6905 h
= (struct elf_link_hash_entry
*) bh
;
6908 h
->type
= STT_SECTION
;
6910 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6914 /* We need to create a .compact_rel section. */
6915 if (SGI_COMPAT (abfd
))
6917 if (!mips_elf_create_compact_rel_section (abfd
, info
))
6921 /* Change alignments of some sections. */
6922 s
= bfd_get_section_by_name (abfd
, ".hash");
6924 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6925 s
= bfd_get_section_by_name (abfd
, ".dynsym");
6927 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6928 s
= bfd_get_section_by_name (abfd
, ".dynstr");
6930 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6931 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6933 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6934 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6936 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6943 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
6945 if (!(_bfd_generic_link_add_one_symbol
6946 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
6947 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6950 h
= (struct elf_link_hash_entry
*) bh
;
6953 h
->type
= STT_SECTION
;
6955 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6958 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
6960 /* __rld_map is a four byte word located in the .data section
6961 and is filled in by the rtld to contain a pointer to
6962 the _r_debug structure. Its symbol value will be set in
6963 _bfd_mips_elf_finish_dynamic_symbol. */
6964 s
= bfd_get_section_by_name (abfd
, ".rld_map");
6965 BFD_ASSERT (s
!= NULL
);
6967 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
6969 if (!(_bfd_generic_link_add_one_symbol
6970 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
6971 get_elf_backend_data (abfd
)->collect
, &bh
)))
6974 h
= (struct elf_link_hash_entry
*) bh
;
6977 h
->type
= STT_OBJECT
;
6979 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6984 /* Create the .plt, .rel(a).plt, .dynbss and .rel(a).bss sections.
6985 Also create the _PROCEDURE_LINKAGE_TABLE symbol. */
6986 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
6989 /* Cache the sections created above. */
6990 htab
->splt
= bfd_get_section_by_name (abfd
, ".plt");
6991 htab
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
6992 if (htab
->is_vxworks
)
6994 htab
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
6995 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
6998 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rel.plt");
7000 || (htab
->is_vxworks
&& !htab
->srelbss
&& !info
->shared
)
7005 if (htab
->is_vxworks
)
7007 /* Do the usual VxWorks handling. */
7008 if (!elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
7011 /* Work out the PLT sizes. */
7014 htab
->plt_header_size
7015 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt0_entry
);
7016 htab
->plt_entry_size
7017 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt_entry
);
7021 htab
->plt_header_size
7022 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt0_entry
);
7023 htab
->plt_entry_size
7024 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt_entry
);
7027 else if (!info
->shared
)
7029 /* All variants of the plt0 entry are the same size. */
7030 htab
->plt_header_size
= 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
);
7031 htab
->plt_entry_size
= 4 * ARRAY_SIZE (mips_exec_plt_entry
);
7037 /* Return true if relocation REL against section SEC is a REL rather than
7038 RELA relocation. RELOCS is the first relocation in the section and
7039 ABFD is the bfd that contains SEC. */
7042 mips_elf_rel_relocation_p (bfd
*abfd
, asection
*sec
,
7043 const Elf_Internal_Rela
*relocs
,
7044 const Elf_Internal_Rela
*rel
)
7046 Elf_Internal_Shdr
*rel_hdr
;
7047 const struct elf_backend_data
*bed
;
7049 /* To determine which flavor or relocation this is, we depend on the
7050 fact that the INPUT_SECTION's REL_HDR is read before its REL_HDR2. */
7051 rel_hdr
= &elf_section_data (sec
)->rel_hdr
;
7052 bed
= get_elf_backend_data (abfd
);
7053 if ((size_t) (rel
- relocs
)
7054 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
7055 rel_hdr
= elf_section_data (sec
)->rel_hdr2
;
7056 return rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (abfd
);
7059 /* Read the addend for REL relocation REL, which belongs to bfd ABFD.
7060 HOWTO is the relocation's howto and CONTENTS points to the contents
7061 of the section that REL is against. */
7064 mips_elf_read_rel_addend (bfd
*abfd
, const Elf_Internal_Rela
*rel
,
7065 reloc_howto_type
*howto
, bfd_byte
*contents
)
7068 unsigned int r_type
;
7071 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7072 location
= contents
+ rel
->r_offset
;
7074 /* Get the addend, which is stored in the input file. */
7075 _bfd_mips16_elf_reloc_unshuffle (abfd
, r_type
, FALSE
, location
);
7076 addend
= mips_elf_obtain_contents (howto
, rel
, abfd
, contents
);
7077 _bfd_mips16_elf_reloc_shuffle (abfd
, r_type
, FALSE
, location
);
7079 return addend
& howto
->src_mask
;
7082 /* REL is a relocation in ABFD that needs a partnering LO16 relocation
7083 and *ADDEND is the addend for REL itself. Look for the LO16 relocation
7084 and update *ADDEND with the final addend. Return true on success
7085 or false if the LO16 could not be found. RELEND is the exclusive
7086 upper bound on the relocations for REL's section. */
7089 mips_elf_add_lo16_rel_addend (bfd
*abfd
,
7090 const Elf_Internal_Rela
*rel
,
7091 const Elf_Internal_Rela
*relend
,
7092 bfd_byte
*contents
, bfd_vma
*addend
)
7094 unsigned int r_type
, lo16_type
;
7095 const Elf_Internal_Rela
*lo16_relocation
;
7096 reloc_howto_type
*lo16_howto
;
7099 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7100 if (mips16_reloc_p (r_type
))
7101 lo16_type
= R_MIPS16_LO16
;
7103 lo16_type
= R_MIPS_LO16
;
7105 /* The combined value is the sum of the HI16 addend, left-shifted by
7106 sixteen bits, and the LO16 addend, sign extended. (Usually, the
7107 code does a `lui' of the HI16 value, and then an `addiu' of the
7110 Scan ahead to find a matching LO16 relocation.
7112 According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
7113 be immediately following. However, for the IRIX6 ABI, the next
7114 relocation may be a composed relocation consisting of several
7115 relocations for the same address. In that case, the R_MIPS_LO16
7116 relocation may occur as one of these. We permit a similar
7117 extension in general, as that is useful for GCC.
7119 In some cases GCC dead code elimination removes the LO16 but keeps
7120 the corresponding HI16. This is strictly speaking a violation of
7121 the ABI but not immediately harmful. */
7122 lo16_relocation
= mips_elf_next_relocation (abfd
, lo16_type
, rel
, relend
);
7123 if (lo16_relocation
== NULL
)
7126 /* Obtain the addend kept there. */
7127 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, lo16_type
, FALSE
);
7128 l
= mips_elf_read_rel_addend (abfd
, lo16_relocation
, lo16_howto
, contents
);
7130 l
<<= lo16_howto
->rightshift
;
7131 l
= _bfd_mips_elf_sign_extend (l
, 16);
7138 /* Try to read the contents of section SEC in bfd ABFD. Return true and
7139 store the contents in *CONTENTS on success. Assume that *CONTENTS
7140 already holds the contents if it is nonull on entry. */
7143 mips_elf_get_section_contents (bfd
*abfd
, asection
*sec
, bfd_byte
**contents
)
7148 /* Get cached copy if it exists. */
7149 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
7151 *contents
= elf_section_data (sec
)->this_hdr
.contents
;
7155 return bfd_malloc_and_get_section (abfd
, sec
, contents
);
7158 /* Look through the relocs for a section during the first phase, and
7159 allocate space in the global offset table. */
7162 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
7163 asection
*sec
, const Elf_Internal_Rela
*relocs
)
7167 Elf_Internal_Shdr
*symtab_hdr
;
7168 struct elf_link_hash_entry
**sym_hashes
;
7170 const Elf_Internal_Rela
*rel
;
7171 const Elf_Internal_Rela
*rel_end
;
7173 const struct elf_backend_data
*bed
;
7174 struct mips_elf_link_hash_table
*htab
;
7177 reloc_howto_type
*howto
;
7179 if (info
->relocatable
)
7182 htab
= mips_elf_hash_table (info
);
7183 dynobj
= elf_hash_table (info
)->dynobj
;
7184 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7185 sym_hashes
= elf_sym_hashes (abfd
);
7186 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7188 bed
= get_elf_backend_data (abfd
);
7189 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
7191 /* Check for the mips16 stub sections. */
7193 name
= bfd_get_section_name (abfd
, sec
);
7194 if (FN_STUB_P (name
))
7196 unsigned long r_symndx
;
7198 /* Look at the relocation information to figure out which symbol
7201 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
7204 (*_bfd_error_handler
)
7205 (_("%B: Warning: cannot determine the target function for"
7206 " stub section `%s'"),
7208 bfd_set_error (bfd_error_bad_value
);
7212 if (r_symndx
< extsymoff
7213 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7217 /* This stub is for a local symbol. This stub will only be
7218 needed if there is some relocation in this BFD, other
7219 than a 16 bit function call, which refers to this symbol. */
7220 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
7222 Elf_Internal_Rela
*sec_relocs
;
7223 const Elf_Internal_Rela
*r
, *rend
;
7225 /* We can ignore stub sections when looking for relocs. */
7226 if ((o
->flags
& SEC_RELOC
) == 0
7227 || o
->reloc_count
== 0
7228 || section_allows_mips16_refs_p (o
))
7232 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
7234 if (sec_relocs
== NULL
)
7237 rend
= sec_relocs
+ o
->reloc_count
;
7238 for (r
= sec_relocs
; r
< rend
; r
++)
7239 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
7240 && !mips16_call_reloc_p (ELF_R_TYPE (abfd
, r
->r_info
)))
7243 if (elf_section_data (o
)->relocs
!= sec_relocs
)
7252 /* There is no non-call reloc for this stub, so we do
7253 not need it. Since this function is called before
7254 the linker maps input sections to output sections, we
7255 can easily discard it by setting the SEC_EXCLUDE
7257 sec
->flags
|= SEC_EXCLUDE
;
7261 /* Record this stub in an array of local symbol stubs for
7263 if (elf_tdata (abfd
)->local_stubs
== NULL
)
7265 unsigned long symcount
;
7269 if (elf_bad_symtab (abfd
))
7270 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
7272 symcount
= symtab_hdr
->sh_info
;
7273 amt
= symcount
* sizeof (asection
*);
7274 n
= bfd_zalloc (abfd
, amt
);
7277 elf_tdata (abfd
)->local_stubs
= n
;
7280 sec
->flags
|= SEC_KEEP
;
7281 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
7283 /* We don't need to set mips16_stubs_seen in this case.
7284 That flag is used to see whether we need to look through
7285 the global symbol table for stubs. We don't need to set
7286 it here, because we just have a local stub. */
7290 struct mips_elf_link_hash_entry
*h
;
7292 h
= ((struct mips_elf_link_hash_entry
*)
7293 sym_hashes
[r_symndx
- extsymoff
]);
7295 while (h
->root
.root
.type
== bfd_link_hash_indirect
7296 || h
->root
.root
.type
== bfd_link_hash_warning
)
7297 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
7299 /* H is the symbol this stub is for. */
7301 /* If we already have an appropriate stub for this function, we
7302 don't need another one, so we can discard this one. Since
7303 this function is called before the linker maps input sections
7304 to output sections, we can easily discard it by setting the
7305 SEC_EXCLUDE flag. */
7306 if (h
->fn_stub
!= NULL
)
7308 sec
->flags
|= SEC_EXCLUDE
;
7312 sec
->flags
|= SEC_KEEP
;
7314 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
7317 else if (CALL_STUB_P (name
) || CALL_FP_STUB_P (name
))
7319 unsigned long r_symndx
;
7320 struct mips_elf_link_hash_entry
*h
;
7323 /* Look at the relocation information to figure out which symbol
7326 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
7329 (*_bfd_error_handler
)
7330 (_("%B: Warning: cannot determine the target function for"
7331 " stub section `%s'"),
7333 bfd_set_error (bfd_error_bad_value
);
7337 if (r_symndx
< extsymoff
7338 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7342 /* This stub is for a local symbol. This stub will only be
7343 needed if there is some relocation (R_MIPS16_26) in this BFD
7344 that refers to this symbol. */
7345 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
7347 Elf_Internal_Rela
*sec_relocs
;
7348 const Elf_Internal_Rela
*r
, *rend
;
7350 /* We can ignore stub sections when looking for relocs. */
7351 if ((o
->flags
& SEC_RELOC
) == 0
7352 || o
->reloc_count
== 0
7353 || section_allows_mips16_refs_p (o
))
7357 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
7359 if (sec_relocs
== NULL
)
7362 rend
= sec_relocs
+ o
->reloc_count
;
7363 for (r
= sec_relocs
; r
< rend
; r
++)
7364 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
7365 && ELF_R_TYPE (abfd
, r
->r_info
) == R_MIPS16_26
)
7368 if (elf_section_data (o
)->relocs
!= sec_relocs
)
7377 /* There is no non-call reloc for this stub, so we do
7378 not need it. Since this function is called before
7379 the linker maps input sections to output sections, we
7380 can easily discard it by setting the SEC_EXCLUDE
7382 sec
->flags
|= SEC_EXCLUDE
;
7386 /* Record this stub in an array of local symbol call_stubs for
7388 if (elf_tdata (abfd
)->local_call_stubs
== NULL
)
7390 unsigned long symcount
;
7394 if (elf_bad_symtab (abfd
))
7395 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
7397 symcount
= symtab_hdr
->sh_info
;
7398 amt
= symcount
* sizeof (asection
*);
7399 n
= bfd_zalloc (abfd
, amt
);
7402 elf_tdata (abfd
)->local_call_stubs
= n
;
7405 sec
->flags
|= SEC_KEEP
;
7406 elf_tdata (abfd
)->local_call_stubs
[r_symndx
] = sec
;
7408 /* We don't need to set mips16_stubs_seen in this case.
7409 That flag is used to see whether we need to look through
7410 the global symbol table for stubs. We don't need to set
7411 it here, because we just have a local stub. */
7415 h
= ((struct mips_elf_link_hash_entry
*)
7416 sym_hashes
[r_symndx
- extsymoff
]);
7418 /* H is the symbol this stub is for. */
7420 if (CALL_FP_STUB_P (name
))
7421 loc
= &h
->call_fp_stub
;
7423 loc
= &h
->call_stub
;
7425 /* If we already have an appropriate stub for this function, we
7426 don't need another one, so we can discard this one. Since
7427 this function is called before the linker maps input sections
7428 to output sections, we can easily discard it by setting the
7429 SEC_EXCLUDE flag. */
7432 sec
->flags
|= SEC_EXCLUDE
;
7436 sec
->flags
|= SEC_KEEP
;
7438 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
7444 for (rel
= relocs
; rel
< rel_end
; ++rel
)
7446 unsigned long r_symndx
;
7447 unsigned int r_type
;
7448 struct elf_link_hash_entry
*h
;
7449 bfd_boolean can_make_dynamic_p
;
7451 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
7452 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7454 if (r_symndx
< extsymoff
)
7456 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
7458 (*_bfd_error_handler
)
7459 (_("%B: Malformed reloc detected for section %s"),
7461 bfd_set_error (bfd_error_bad_value
);
7466 h
= sym_hashes
[r_symndx
- extsymoff
];
7468 && (h
->root
.type
== bfd_link_hash_indirect
7469 || h
->root
.type
== bfd_link_hash_warning
))
7470 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7473 /* Set CAN_MAKE_DYNAMIC_P to true if we can convert this
7474 relocation into a dynamic one. */
7475 can_make_dynamic_p
= FALSE
;
7478 case R_MIPS16_GOT16
:
7479 case R_MIPS16_CALL16
:
7482 case R_MIPS_CALL_HI16
:
7483 case R_MIPS_CALL_LO16
:
7484 case R_MIPS_GOT_HI16
:
7485 case R_MIPS_GOT_LO16
:
7486 case R_MIPS_GOT_PAGE
:
7487 case R_MIPS_GOT_OFST
:
7488 case R_MIPS_GOT_DISP
:
7489 case R_MIPS_TLS_GOTTPREL
:
7491 case R_MIPS_TLS_LDM
:
7493 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7494 if (!mips_elf_create_got_section (dynobj
, info
))
7496 if (htab
->is_vxworks
&& !info
->shared
)
7498 (*_bfd_error_handler
)
7499 (_("%B: GOT reloc at 0x%lx not expected in executables"),
7500 abfd
, (unsigned long) rel
->r_offset
);
7501 bfd_set_error (bfd_error_bad_value
);
7509 /* In VxWorks executables, references to external symbols
7510 must be handled using copy relocs or PLT entries; it is not
7511 possible to convert this relocation into a dynamic one.
7513 For executables that use PLTs and copy-relocs, we have a
7514 choice between converting the relocation into a dynamic
7515 one or using copy relocations or PLT entries. It is
7516 usually better to do the former, unless the relocation is
7517 against a read-only section. */
7520 && !htab
->is_vxworks
7521 && strcmp (h
->root
.root
.string
, "__gnu_local_gp") != 0
7522 && !(!info
->nocopyreloc
7523 && !PIC_OBJECT_P (abfd
)
7524 && MIPS_ELF_READONLY_SECTION (sec
))))
7525 && (sec
->flags
& SEC_ALLOC
) != 0)
7527 can_make_dynamic_p
= TRUE
;
7529 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7535 /* Most static relocations require pointer equality, except
7538 h
->pointer_equality_needed
= TRUE
;
7545 ((struct mips_elf_link_hash_entry
*) h
)->has_static_relocs
= TRUE
;
7551 /* Relocations against the special VxWorks __GOTT_BASE__ and
7552 __GOTT_INDEX__ symbols must be left to the loader. Allocate
7553 room for them in .rela.dyn. */
7554 if (is_gott_symbol (info
, h
))
7558 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7562 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7563 if (MIPS_ELF_READONLY_SECTION (sec
))
7564 /* We tell the dynamic linker that there are
7565 relocations against the text segment. */
7566 info
->flags
|= DF_TEXTREL
;
7569 else if (r_type
== R_MIPS_CALL_LO16
7570 || r_type
== R_MIPS_GOT_LO16
7571 || r_type
== R_MIPS_GOT_DISP
7572 || (got16_reloc_p (r_type
) && htab
->is_vxworks
))
7574 /* We may need a local GOT entry for this relocation. We
7575 don't count R_MIPS_GOT_PAGE because we can estimate the
7576 maximum number of pages needed by looking at the size of
7577 the segment. Similar comments apply to R_MIPS*_GOT16 and
7578 R_MIPS*_CALL16, except on VxWorks, where GOT relocations
7579 always evaluate to "G". We don't count R_MIPS_GOT_HI16, or
7580 R_MIPS_CALL_HI16 because these are always followed by an
7581 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
7582 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7583 rel
->r_addend
, info
, 0))
7587 if (h
!= NULL
&& mips_elf_relocation_needs_la25_stub (abfd
, r_type
))
7588 ((struct mips_elf_link_hash_entry
*) h
)->has_nonpic_branches
= TRUE
;
7593 case R_MIPS16_CALL16
:
7596 (*_bfd_error_handler
)
7597 (_("%B: CALL16 reloc at 0x%lx not against global symbol"),
7598 abfd
, (unsigned long) rel
->r_offset
);
7599 bfd_set_error (bfd_error_bad_value
);
7604 case R_MIPS_CALL_HI16
:
7605 case R_MIPS_CALL_LO16
:
7608 /* VxWorks call relocations point at the function's .got.plt
7609 entry, which will be allocated by adjust_dynamic_symbol.
7610 Otherwise, this symbol requires a global GOT entry. */
7611 if ((!htab
->is_vxworks
|| h
->forced_local
)
7612 && !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7615 /* We need a stub, not a plt entry for the undefined
7616 function. But we record it as if it needs plt. See
7617 _bfd_elf_adjust_dynamic_symbol. */
7623 case R_MIPS_GOT_PAGE
:
7624 /* If this is a global, overridable symbol, GOT_PAGE will
7625 decay to GOT_DISP, so we'll need a GOT entry for it. */
7628 struct mips_elf_link_hash_entry
*hmips
=
7629 (struct mips_elf_link_hash_entry
*) h
;
7631 /* This symbol is definitely not overridable. */
7632 if (hmips
->root
.def_regular
7633 && ! (info
->shared
&& ! info
->symbolic
7634 && ! hmips
->root
.forced_local
))
7639 case R_MIPS16_GOT16
:
7641 case R_MIPS_GOT_HI16
:
7642 case R_MIPS_GOT_LO16
:
7643 if (!h
|| r_type
== R_MIPS_GOT_PAGE
)
7645 /* This relocation needs (or may need, if h != NULL) a
7646 page entry in the GOT. For R_MIPS_GOT_PAGE we do not
7647 know for sure until we know whether the symbol is
7649 if (mips_elf_rel_relocation_p (abfd
, sec
, relocs
, rel
))
7651 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
7653 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
7654 addend
= mips_elf_read_rel_addend (abfd
, rel
,
7656 if (r_type
== R_MIPS_GOT16
)
7657 mips_elf_add_lo16_rel_addend (abfd
, rel
, rel_end
,
7660 addend
<<= howto
->rightshift
;
7663 addend
= rel
->r_addend
;
7664 if (!mips_elf_record_got_page_entry (info
, abfd
, r_symndx
,
7671 case R_MIPS_GOT_DISP
:
7672 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7676 case R_MIPS_TLS_GOTTPREL
:
7678 info
->flags
|= DF_STATIC_TLS
;
7681 case R_MIPS_TLS_LDM
:
7682 if (r_type
== R_MIPS_TLS_LDM
)
7690 /* This symbol requires a global offset table entry, or two
7691 for TLS GD relocations. */
7693 unsigned char flag
= (r_type
== R_MIPS_TLS_GD
7695 : r_type
== R_MIPS_TLS_LDM
7700 struct mips_elf_link_hash_entry
*hmips
=
7701 (struct mips_elf_link_hash_entry
*) h
;
7702 hmips
->tls_type
|= flag
;
7704 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
,
7710 BFD_ASSERT (flag
== GOT_TLS_LDM
|| r_symndx
!= 0);
7712 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7723 /* In VxWorks executables, references to external symbols
7724 are handled using copy relocs or PLT stubs, so there's
7725 no need to add a .rela.dyn entry for this relocation. */
7726 if (can_make_dynamic_p
)
7730 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7734 if (info
->shared
&& h
== NULL
)
7736 /* When creating a shared object, we must copy these
7737 reloc types into the output file as R_MIPS_REL32
7738 relocs. Make room for this reloc in .rel(a).dyn. */
7739 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7740 if (MIPS_ELF_READONLY_SECTION (sec
))
7741 /* We tell the dynamic linker that there are
7742 relocations against the text segment. */
7743 info
->flags
|= DF_TEXTREL
;
7747 struct mips_elf_link_hash_entry
*hmips
;
7749 /* For a shared object, we must copy this relocation
7750 unless the symbol turns out to be undefined and
7751 weak with non-default visibility, in which case
7752 it will be left as zero.
7754 We could elide R_MIPS_REL32 for locally binding symbols
7755 in shared libraries, but do not yet do so.
7757 For an executable, we only need to copy this
7758 reloc if the symbol is defined in a dynamic
7760 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7761 ++hmips
->possibly_dynamic_relocs
;
7762 if (MIPS_ELF_READONLY_SECTION (sec
))
7763 /* We need it to tell the dynamic linker if there
7764 are relocations against the text segment. */
7765 hmips
->readonly_reloc
= TRUE
;
7769 if (SGI_COMPAT (abfd
))
7770 mips_elf_hash_table (info
)->compact_rel_size
+=
7771 sizeof (Elf32_External_crinfo
);
7775 case R_MIPS_GPREL16
:
7776 case R_MIPS_LITERAL
:
7777 case R_MIPS_GPREL32
:
7778 if (SGI_COMPAT (abfd
))
7779 mips_elf_hash_table (info
)->compact_rel_size
+=
7780 sizeof (Elf32_External_crinfo
);
7783 /* This relocation describes the C++ object vtable hierarchy.
7784 Reconstruct it for later use during GC. */
7785 case R_MIPS_GNU_VTINHERIT
:
7786 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7790 /* This relocation describes which C++ vtable entries are actually
7791 used. Record for later use during GC. */
7792 case R_MIPS_GNU_VTENTRY
:
7793 BFD_ASSERT (h
!= NULL
);
7795 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7803 /* We must not create a stub for a symbol that has relocations
7804 related to taking the function's address. This doesn't apply to
7805 VxWorks, where CALL relocs refer to a .got.plt entry instead of
7806 a normal .got entry. */
7807 if (!htab
->is_vxworks
&& h
!= NULL
)
7811 ((struct mips_elf_link_hash_entry
*) h
)->no_fn_stub
= TRUE
;
7813 case R_MIPS16_CALL16
:
7815 case R_MIPS_CALL_HI16
:
7816 case R_MIPS_CALL_LO16
:
7821 /* See if this reloc would need to refer to a MIPS16 hard-float stub,
7822 if there is one. We only need to handle global symbols here;
7823 we decide whether to keep or delete stubs for local symbols
7824 when processing the stub's relocations. */
7826 && !mips16_call_reloc_p (r_type
)
7827 && !section_allows_mips16_refs_p (sec
))
7829 struct mips_elf_link_hash_entry
*mh
;
7831 mh
= (struct mips_elf_link_hash_entry
*) h
;
7832 mh
->need_fn_stub
= TRUE
;
7835 /* Refuse some position-dependent relocations when creating a
7836 shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
7837 not PIC, but we can create dynamic relocations and the result
7838 will be fine. Also do not refuse R_MIPS_LO16, which can be
7839 combined with R_MIPS_GOT16. */
7847 case R_MIPS_HIGHEST
:
7848 /* Don't refuse a high part relocation if it's against
7849 no symbol (e.g. part of a compound relocation). */
7853 /* R_MIPS_HI16 against _gp_disp is used for $gp setup,
7854 and has a special meaning. */
7855 if (!NEWABI_P (abfd
) && h
!= NULL
7856 && strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
7863 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
7864 (*_bfd_error_handler
)
7865 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
7867 (h
) ? h
->root
.root
.string
: "a local symbol");
7868 bfd_set_error (bfd_error_bad_value
);
7880 _bfd_mips_relax_section (bfd
*abfd
, asection
*sec
,
7881 struct bfd_link_info
*link_info
,
7884 Elf_Internal_Rela
*internal_relocs
;
7885 Elf_Internal_Rela
*irel
, *irelend
;
7886 Elf_Internal_Shdr
*symtab_hdr
;
7887 bfd_byte
*contents
= NULL
;
7889 bfd_boolean changed_contents
= FALSE
;
7890 bfd_vma sec_start
= sec
->output_section
->vma
+ sec
->output_offset
;
7891 Elf_Internal_Sym
*isymbuf
= NULL
;
7893 /* We are not currently changing any sizes, so only one pass. */
7896 if (link_info
->relocatable
)
7899 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
7900 link_info
->keep_memory
);
7901 if (internal_relocs
== NULL
)
7904 irelend
= internal_relocs
+ sec
->reloc_count
7905 * get_elf_backend_data (abfd
)->s
->int_rels_per_ext_rel
;
7906 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7907 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7909 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
7912 bfd_signed_vma sym_offset
;
7913 unsigned int r_type
;
7914 unsigned long r_symndx
;
7916 unsigned long instruction
;
7918 /* Turn jalr into bgezal, and jr into beq, if they're marked
7919 with a JALR relocation, that indicate where they jump to.
7920 This saves some pipeline bubbles. */
7921 r_type
= ELF_R_TYPE (abfd
, irel
->r_info
);
7922 if (r_type
!= R_MIPS_JALR
)
7925 r_symndx
= ELF_R_SYM (abfd
, irel
->r_info
);
7926 /* Compute the address of the jump target. */
7927 if (r_symndx
>= extsymoff
)
7929 struct mips_elf_link_hash_entry
*h
7930 = ((struct mips_elf_link_hash_entry
*)
7931 elf_sym_hashes (abfd
) [r_symndx
- extsymoff
]);
7933 while (h
->root
.root
.type
== bfd_link_hash_indirect
7934 || h
->root
.root
.type
== bfd_link_hash_warning
)
7935 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
7937 /* If a symbol is undefined, or if it may be overridden,
7939 if (! ((h
->root
.root
.type
== bfd_link_hash_defined
7940 || h
->root
.root
.type
== bfd_link_hash_defweak
)
7941 && h
->root
.root
.u
.def
.section
)
7942 || (link_info
->shared
&& ! link_info
->symbolic
7943 && !h
->root
.forced_local
))
7946 sym_sec
= h
->root
.root
.u
.def
.section
;
7947 if (sym_sec
->output_section
)
7948 symval
= (h
->root
.root
.u
.def
.value
7949 + sym_sec
->output_section
->vma
7950 + sym_sec
->output_offset
);
7952 symval
= h
->root
.root
.u
.def
.value
;
7956 Elf_Internal_Sym
*isym
;
7958 /* Read this BFD's symbols if we haven't done so already. */
7959 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
7961 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
7962 if (isymbuf
== NULL
)
7963 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
7964 symtab_hdr
->sh_info
, 0,
7966 if (isymbuf
== NULL
)
7970 isym
= isymbuf
+ r_symndx
;
7971 if (isym
->st_shndx
== SHN_UNDEF
)
7973 else if (isym
->st_shndx
== SHN_ABS
)
7974 sym_sec
= bfd_abs_section_ptr
;
7975 else if (isym
->st_shndx
== SHN_COMMON
)
7976 sym_sec
= bfd_com_section_ptr
;
7979 = bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7980 symval
= isym
->st_value
7981 + sym_sec
->output_section
->vma
7982 + sym_sec
->output_offset
;
7985 /* Compute branch offset, from delay slot of the jump to the
7987 sym_offset
= (symval
+ irel
->r_addend
)
7988 - (sec_start
+ irel
->r_offset
+ 4);
7990 /* Branch offset must be properly aligned. */
7991 if ((sym_offset
& 3) != 0)
7996 /* Check that it's in range. */
7997 if (sym_offset
< -0x8000 || sym_offset
>= 0x8000)
8000 /* Get the section contents if we haven't done so already. */
8001 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
8004 instruction
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
8006 /* If it was jalr <reg>, turn it into bgezal $zero, <target>. */
8007 if ((instruction
& 0xfc1fffff) == 0x0000f809)
8008 instruction
= 0x04110000;
8009 /* If it was jr <reg>, turn it into b <target>. */
8010 else if ((instruction
& 0xfc1fffff) == 0x00000008)
8011 instruction
= 0x10000000;
8015 instruction
|= (sym_offset
& 0xffff);
8016 bfd_put_32 (abfd
, instruction
, contents
+ irel
->r_offset
);
8017 changed_contents
= TRUE
;
8020 if (contents
!= NULL
8021 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
8023 if (!changed_contents
&& !link_info
->keep_memory
)
8027 /* Cache the section contents for elf_link_input_bfd. */
8028 elf_section_data (sec
)->this_hdr
.contents
= contents
;
8034 if (contents
!= NULL
8035 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
8040 /* Allocate space for global sym dynamic relocs. */
8043 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8045 struct bfd_link_info
*info
= inf
;
8047 struct mips_elf_link_hash_entry
*hmips
;
8048 struct mips_elf_link_hash_table
*htab
;
8050 htab
= mips_elf_hash_table (info
);
8051 dynobj
= elf_hash_table (info
)->dynobj
;
8052 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8054 /* VxWorks executables are handled elsewhere; we only need to
8055 allocate relocations in shared objects. */
8056 if (htab
->is_vxworks
&& !info
->shared
)
8059 /* Ignore indirect and warning symbols. All relocations against
8060 such symbols will be redirected to the target symbol. */
8061 if (h
->root
.type
== bfd_link_hash_indirect
8062 || h
->root
.type
== bfd_link_hash_warning
)
8065 /* If this symbol is defined in a dynamic object, or we are creating
8066 a shared library, we will need to copy any R_MIPS_32 or
8067 R_MIPS_REL32 relocs against it into the output file. */
8068 if (! info
->relocatable
8069 && hmips
->possibly_dynamic_relocs
!= 0
8070 && (h
->root
.type
== bfd_link_hash_defweak
8074 bfd_boolean do_copy
= TRUE
;
8076 if (h
->root
.type
== bfd_link_hash_undefweak
)
8078 /* Do not copy relocations for undefined weak symbols with
8079 non-default visibility. */
8080 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8083 /* Make sure undefined weak symbols are output as a dynamic
8085 else if (h
->dynindx
== -1 && !h
->forced_local
)
8087 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8094 /* Even though we don't directly need a GOT entry for this symbol,
8095 a symbol must have a dynamic symbol table index greater that
8096 DT_MIPS_GOTSYM if there are dynamic relocations against it. */
8097 if (hmips
->global_got_area
> GGA_RELOC_ONLY
)
8098 hmips
->global_got_area
= GGA_RELOC_ONLY
;
8100 mips_elf_allocate_dynamic_relocations
8101 (dynobj
, info
, hmips
->possibly_dynamic_relocs
);
8102 if (hmips
->readonly_reloc
)
8103 /* We tell the dynamic linker that there are relocations
8104 against the text segment. */
8105 info
->flags
|= DF_TEXTREL
;
8112 /* Adjust a symbol defined by a dynamic object and referenced by a
8113 regular object. The current definition is in some section of the
8114 dynamic object, but we're not including those sections. We have to
8115 change the definition to something the rest of the link can
8119 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
8120 struct elf_link_hash_entry
*h
)
8123 struct mips_elf_link_hash_entry
*hmips
;
8124 struct mips_elf_link_hash_table
*htab
;
8126 htab
= mips_elf_hash_table (info
);
8127 dynobj
= elf_hash_table (info
)->dynobj
;
8128 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8130 /* Make sure we know what is going on here. */
8131 BFD_ASSERT (dynobj
!= NULL
8133 || h
->u
.weakdef
!= NULL
8136 && !h
->def_regular
)));
8138 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8140 /* If there are call relocations against an externally-defined symbol,
8141 see whether we can create a MIPS lazy-binding stub for it. We can
8142 only do this if all references to the function are through call
8143 relocations, and in that case, the traditional lazy-binding stubs
8144 are much more efficient than PLT entries.
8146 Traditional stubs are only available on SVR4 psABI-based systems;
8147 VxWorks always uses PLTs instead. */
8148 if (!htab
->is_vxworks
&& h
->needs_plt
&& !hmips
->no_fn_stub
)
8150 if (! elf_hash_table (info
)->dynamic_sections_created
)
8153 /* If this symbol is not defined in a regular file, then set
8154 the symbol to the stub location. This is required to make
8155 function pointers compare as equal between the normal
8156 executable and the shared library. */
8157 if (!h
->def_regular
)
8159 hmips
->needs_lazy_stub
= TRUE
;
8160 htab
->lazy_stub_count
++;
8164 /* As above, VxWorks requires PLT entries for externally-defined
8165 functions that are only accessed through call relocations.
8167 Both VxWorks and non-VxWorks targets also need PLT entries if there
8168 are static-only relocations against an externally-defined function.
8169 This can technically occur for shared libraries if there are
8170 branches to the symbol, although it is unlikely that this will be
8171 used in practice due to the short ranges involved. It can occur
8172 for any relative or absolute relocation in executables; in that
8173 case, the PLT entry becomes the function's canonical address. */
8174 else if (((h
->needs_plt
&& !hmips
->no_fn_stub
)
8175 || (h
->type
== STT_FUNC
&& hmips
->has_static_relocs
))
8176 && htab
->use_plts_and_copy_relocs
8177 && !SYMBOL_CALLS_LOCAL (info
, h
)
8178 && !(ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
8179 && h
->root
.type
== bfd_link_hash_undefweak
))
8181 /* If this is the first symbol to need a PLT entry, allocate room
8183 if (htab
->splt
->size
== 0)
8185 BFD_ASSERT (htab
->sgotplt
->size
== 0);
8187 /* If we're using the PLT additions to the psABI, each PLT
8188 entry is 16 bytes and the PLT0 entry is 32 bytes.
8189 Encourage better cache usage by aligning. We do this
8190 lazily to avoid pessimizing traditional objects. */
8191 if (!htab
->is_vxworks
8192 && !bfd_set_section_alignment (dynobj
, htab
->splt
, 5))
8195 /* Make sure that .got.plt is word-aligned. We do this lazily
8196 for the same reason as above. */
8197 if (!bfd_set_section_alignment (dynobj
, htab
->sgotplt
,
8198 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
8201 htab
->splt
->size
+= htab
->plt_header_size
;
8203 /* On non-VxWorks targets, the first two entries in .got.plt
8205 if (!htab
->is_vxworks
)
8206 htab
->sgotplt
->size
+= 2 * MIPS_ELF_GOT_SIZE (dynobj
);
8208 /* On VxWorks, also allocate room for the header's
8209 .rela.plt.unloaded entries. */
8210 if (htab
->is_vxworks
&& !info
->shared
)
8211 htab
->srelplt2
->size
+= 2 * sizeof (Elf32_External_Rela
);
8214 /* Assign the next .plt entry to this symbol. */
8215 h
->plt
.offset
= htab
->splt
->size
;
8216 htab
->splt
->size
+= htab
->plt_entry_size
;
8218 /* If the output file has no definition of the symbol, set the
8219 symbol's value to the address of the stub. */
8220 if (!info
->shared
&& !h
->def_regular
)
8222 h
->root
.u
.def
.section
= htab
->splt
;
8223 h
->root
.u
.def
.value
= h
->plt
.offset
;
8224 /* For VxWorks, point at the PLT load stub rather than the
8225 lazy resolution stub; this stub will become the canonical
8226 function address. */
8227 if (htab
->is_vxworks
)
8228 h
->root
.u
.def
.value
+= 8;
8231 /* Make room for the .got.plt entry and the R_MIPS_JUMP_SLOT
8233 htab
->sgotplt
->size
+= MIPS_ELF_GOT_SIZE (dynobj
);
8234 htab
->srelplt
->size
+= (htab
->is_vxworks
8235 ? MIPS_ELF_RELA_SIZE (dynobj
)
8236 : MIPS_ELF_REL_SIZE (dynobj
));
8238 /* Make room for the .rela.plt.unloaded relocations. */
8239 if (htab
->is_vxworks
&& !info
->shared
)
8240 htab
->srelplt2
->size
+= 3 * sizeof (Elf32_External_Rela
);
8242 /* All relocations against this symbol that could have been made
8243 dynamic will now refer to the PLT entry instead. */
8244 hmips
->possibly_dynamic_relocs
= 0;
8249 /* If this is a weak symbol, and there is a real definition, the
8250 processor independent code will have arranged for us to see the
8251 real definition first, and we can just use the same value. */
8252 if (h
->u
.weakdef
!= NULL
)
8254 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
8255 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
8256 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
8257 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
8261 /* Otherwise, there is nothing further to do for symbols defined
8262 in regular objects. */
8266 /* There's also nothing more to do if we'll convert all relocations
8267 against this symbol into dynamic relocations. */
8268 if (!hmips
->has_static_relocs
)
8271 /* We're now relying on copy relocations. Complain if we have
8272 some that we can't convert. */
8273 if (!htab
->use_plts_and_copy_relocs
|| info
->shared
)
8275 (*_bfd_error_handler
) (_("non-dynamic relocations refer to "
8276 "dynamic symbol %s"),
8277 h
->root
.root
.string
);
8278 bfd_set_error (bfd_error_bad_value
);
8282 /* We must allocate the symbol in our .dynbss section, which will
8283 become part of the .bss section of the executable. There will be
8284 an entry for this symbol in the .dynsym section. The dynamic
8285 object will contain position independent code, so all references
8286 from the dynamic object to this symbol will go through the global
8287 offset table. The dynamic linker will use the .dynsym entry to
8288 determine the address it must put in the global offset table, so
8289 both the dynamic object and the regular object will refer to the
8290 same memory location for the variable. */
8292 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
8294 if (htab
->is_vxworks
)
8295 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
8297 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
8301 /* All relocations against this symbol that could have been made
8302 dynamic will now refer to the local copy instead. */
8303 hmips
->possibly_dynamic_relocs
= 0;
8305 return _bfd_elf_adjust_dynamic_copy (h
, htab
->sdynbss
);
8308 /* This function is called after all the input files have been read,
8309 and the input sections have been assigned to output sections. We
8310 check for any mips16 stub sections that we can discard. */
8313 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
8314 struct bfd_link_info
*info
)
8317 struct mips_elf_link_hash_table
*htab
;
8318 struct mips_htab_traverse_info hti
;
8320 htab
= mips_elf_hash_table (info
);
8322 /* The .reginfo section has a fixed size. */
8323 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
8325 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
8328 hti
.output_bfd
= output_bfd
;
8330 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
8331 mips_elf_check_symbols
, &hti
);
8338 /* If the link uses a GOT, lay it out and work out its size. */
8341 mips_elf_lay_out_got (bfd
*output_bfd
, struct bfd_link_info
*info
)
8345 struct mips_got_info
*g
;
8346 bfd_size_type loadable_size
= 0;
8347 bfd_size_type page_gotno
;
8349 struct mips_elf_count_tls_arg count_tls_arg
;
8350 struct mips_elf_link_hash_table
*htab
;
8352 htab
= mips_elf_hash_table (info
);
8357 dynobj
= elf_hash_table (info
)->dynobj
;
8360 /* Allocate room for the reserved entries. VxWorks always reserves
8361 3 entries; other objects only reserve 2 entries. */
8362 BFD_ASSERT (g
->assigned_gotno
== 0);
8363 if (htab
->is_vxworks
)
8364 htab
->reserved_gotno
= 3;
8366 htab
->reserved_gotno
= 2;
8367 g
->local_gotno
+= htab
->reserved_gotno
;
8368 g
->assigned_gotno
= htab
->reserved_gotno
;
8370 /* Replace entries for indirect and warning symbols with entries for
8371 the target symbol. */
8372 if (!mips_elf_resolve_final_got_entries (g
))
8375 /* Count the number of GOT symbols. */
8376 mips_elf_link_hash_traverse (htab
, mips_elf_count_got_symbols
, g
);
8378 /* Calculate the total loadable size of the output. That
8379 will give us the maximum number of GOT_PAGE entries
8381 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
8383 asection
*subsection
;
8385 for (subsection
= sub
->sections
;
8387 subsection
= subsection
->next
)
8389 if ((subsection
->flags
& SEC_ALLOC
) == 0)
8391 loadable_size
+= ((subsection
->size
+ 0xf)
8392 &~ (bfd_size_type
) 0xf);
8396 if (htab
->is_vxworks
)
8397 /* There's no need to allocate page entries for VxWorks; R_MIPS*_GOT16
8398 relocations against local symbols evaluate to "G", and the EABI does
8399 not include R_MIPS_GOT_PAGE. */
8402 /* Assume there are two loadable segments consisting of contiguous
8403 sections. Is 5 enough? */
8404 page_gotno
= (loadable_size
>> 16) + 5;
8406 /* Choose the smaller of the two estimates; both are intended to be
8408 if (page_gotno
> g
->page_gotno
)
8409 page_gotno
= g
->page_gotno
;
8411 g
->local_gotno
+= page_gotno
;
8412 s
->size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
8413 s
->size
+= g
->global_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
8415 /* We need to calculate tls_gotno for global symbols at this point
8416 instead of building it up earlier, to avoid doublecounting
8417 entries for one global symbol from multiple input files. */
8418 count_tls_arg
.info
= info
;
8419 count_tls_arg
.needed
= 0;
8420 elf_link_hash_traverse (elf_hash_table (info
),
8421 mips_elf_count_global_tls_entries
,
8423 g
->tls_gotno
+= count_tls_arg
.needed
;
8424 s
->size
+= g
->tls_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
8426 /* VxWorks does not support multiple GOTs. It initializes $gp to
8427 __GOTT_BASE__[__GOTT_INDEX__], the value of which is set by the
8429 if (htab
->is_vxworks
)
8431 /* VxWorks executables do not need a GOT. */
8434 /* Each VxWorks GOT entry needs an explicit relocation. */
8437 count
= g
->global_gotno
+ g
->local_gotno
- htab
->reserved_gotno
;
8439 mips_elf_allocate_dynamic_relocations (dynobj
, info
, count
);
8442 else if (s
->size
> MIPS_ELF_GOT_MAX_SIZE (info
))
8444 if (!mips_elf_multi_got (output_bfd
, info
, s
, page_gotno
))
8449 struct mips_elf_count_tls_arg arg
;
8451 /* Set up TLS entries. */
8452 g
->tls_assigned_gotno
= g
->global_gotno
+ g
->local_gotno
;
8453 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
8455 /* Allocate room for the TLS relocations. */
8458 htab_traverse (g
->got_entries
, mips_elf_count_local_tls_relocs
, &arg
);
8459 elf_link_hash_traverse (elf_hash_table (info
),
8460 mips_elf_count_global_tls_relocs
,
8463 mips_elf_allocate_dynamic_relocations (dynobj
, info
, arg
.needed
);
8469 /* Estimate the size of the .MIPS.stubs section. */
8472 mips_elf_estimate_stub_size (bfd
*output_bfd
, struct bfd_link_info
*info
)
8474 struct mips_elf_link_hash_table
*htab
;
8475 bfd_size_type dynsymcount
;
8477 htab
= mips_elf_hash_table (info
);
8478 if (htab
->lazy_stub_count
== 0)
8481 /* IRIX rld assumes that a function stub isn't at the end of the .text
8482 section, so add a dummy entry to the end. */
8483 htab
->lazy_stub_count
++;
8485 /* Get a worst-case estimate of the number of dynamic symbols needed.
8486 At this point, dynsymcount does not account for section symbols
8487 and count_section_dynsyms may overestimate the number that will
8489 dynsymcount
= (elf_hash_table (info
)->dynsymcount
8490 + count_section_dynsyms (output_bfd
, info
));
8492 /* Determine the size of one stub entry. */
8493 htab
->function_stub_size
= (dynsymcount
> 0x10000
8494 ? MIPS_FUNCTION_STUB_BIG_SIZE
8495 : MIPS_FUNCTION_STUB_NORMAL_SIZE
);
8497 htab
->sstubs
->size
= htab
->lazy_stub_count
* htab
->function_stub_size
;
8500 /* A mips_elf_link_hash_traverse callback for which DATA points to the
8501 MIPS hash table. If H needs a traditional MIPS lazy-binding stub,
8502 allocate an entry in the stubs section. */
8505 mips_elf_allocate_lazy_stub (struct mips_elf_link_hash_entry
*h
, void **data
)
8507 struct mips_elf_link_hash_table
*htab
;
8509 htab
= (struct mips_elf_link_hash_table
*) data
;
8510 if (h
->needs_lazy_stub
)
8512 h
->root
.root
.u
.def
.section
= htab
->sstubs
;
8513 h
->root
.root
.u
.def
.value
= htab
->sstubs
->size
;
8514 h
->root
.plt
.offset
= htab
->sstubs
->size
;
8515 htab
->sstubs
->size
+= htab
->function_stub_size
;
8520 /* Allocate offsets in the stubs section to each symbol that needs one.
8521 Set the final size of the .MIPS.stub section. */
8524 mips_elf_lay_out_lazy_stubs (struct bfd_link_info
*info
)
8526 struct mips_elf_link_hash_table
*htab
;
8528 htab
= mips_elf_hash_table (info
);
8529 if (htab
->lazy_stub_count
== 0)
8532 htab
->sstubs
->size
= 0;
8533 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
8534 mips_elf_allocate_lazy_stub
, htab
);
8535 htab
->sstubs
->size
+= htab
->function_stub_size
;
8536 BFD_ASSERT (htab
->sstubs
->size
8537 == htab
->lazy_stub_count
* htab
->function_stub_size
);
8540 /* Set the sizes of the dynamic sections. */
8543 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
8544 struct bfd_link_info
*info
)
8547 asection
*s
, *sreldyn
;
8548 bfd_boolean reltext
;
8549 struct mips_elf_link_hash_table
*htab
;
8551 htab
= mips_elf_hash_table (info
);
8552 dynobj
= elf_hash_table (info
)->dynobj
;
8553 BFD_ASSERT (dynobj
!= NULL
);
8555 if (elf_hash_table (info
)->dynamic_sections_created
)
8557 /* Set the contents of the .interp section to the interpreter. */
8558 if (info
->executable
)
8560 s
= bfd_get_section_by_name (dynobj
, ".interp");
8561 BFD_ASSERT (s
!= NULL
);
8563 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
8565 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
8568 /* Create a symbol for the PLT, if we know that we are using it. */
8569 if (htab
->splt
&& htab
->splt
->size
> 0 && htab
->root
.hplt
== NULL
)
8571 struct elf_link_hash_entry
*h
;
8573 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
8575 h
= _bfd_elf_define_linkage_sym (dynobj
, info
, htab
->splt
,
8576 "_PROCEDURE_LINKAGE_TABLE_");
8577 htab
->root
.hplt
= h
;
8584 /* Allocate space for global sym dynamic relocs. */
8585 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
8587 mips_elf_estimate_stub_size (output_bfd
, info
);
8589 if (!mips_elf_lay_out_got (output_bfd
, info
))
8592 mips_elf_lay_out_lazy_stubs (info
);
8594 /* The check_relocs and adjust_dynamic_symbol entry points have
8595 determined the sizes of the various dynamic sections. Allocate
8598 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8602 /* It's OK to base decisions on the section name, because none
8603 of the dynobj section names depend upon the input files. */
8604 name
= bfd_get_section_name (dynobj
, s
);
8606 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8609 if (CONST_STRNEQ (name
, ".rel"))
8613 const char *outname
;
8616 /* If this relocation section applies to a read only
8617 section, then we probably need a DT_TEXTREL entry.
8618 If the relocation section is .rel(a).dyn, we always
8619 assert a DT_TEXTREL entry rather than testing whether
8620 there exists a relocation to a read only section or
8622 outname
= bfd_get_section_name (output_bfd
,
8624 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
8626 && (target
->flags
& SEC_READONLY
) != 0
8627 && (target
->flags
& SEC_ALLOC
) != 0)
8628 || strcmp (outname
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
8631 /* We use the reloc_count field as a counter if we need
8632 to copy relocs into the output file. */
8633 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) != 0)
8636 /* If combreloc is enabled, elf_link_sort_relocs() will
8637 sort relocations, but in a different way than we do,
8638 and before we're done creating relocations. Also, it
8639 will move them around between input sections'
8640 relocation's contents, so our sorting would be
8641 broken, so don't let it run. */
8642 info
->combreloc
= 0;
8645 else if (! info
->shared
8646 && ! mips_elf_hash_table (info
)->use_rld_obj_head
8647 && CONST_STRNEQ (name
, ".rld_map"))
8649 /* We add a room for __rld_map. It will be filled in by the
8650 rtld to contain a pointer to the _r_debug structure. */
8653 else if (SGI_COMPAT (output_bfd
)
8654 && CONST_STRNEQ (name
, ".compact_rel"))
8655 s
->size
+= mips_elf_hash_table (info
)->compact_rel_size
;
8656 else if (s
== htab
->splt
)
8658 /* If the last PLT entry has a branch delay slot, allocate
8659 room for an extra nop to fill the delay slot. This is
8660 for CPUs without load interlocking. */
8661 if (! LOAD_INTERLOCKS_P (output_bfd
)
8662 && ! htab
->is_vxworks
&& s
->size
> 0)
8665 else if (! CONST_STRNEQ (name
, ".init")
8667 && s
!= htab
->sgotplt
8668 && s
!= htab
->sstubs
8669 && s
!= htab
->sdynbss
)
8671 /* It's not one of our sections, so don't allocate space. */
8677 s
->flags
|= SEC_EXCLUDE
;
8681 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8684 /* Allocate memory for the section contents. */
8685 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
8686 if (s
->contents
== NULL
)
8688 bfd_set_error (bfd_error_no_memory
);
8693 if (elf_hash_table (info
)->dynamic_sections_created
)
8695 /* Add some entries to the .dynamic section. We fill in the
8696 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
8697 must add the entries now so that we get the correct size for
8698 the .dynamic section. */
8700 /* SGI object has the equivalence of DT_DEBUG in the
8701 DT_MIPS_RLD_MAP entry. This must come first because glibc
8702 only fills in DT_MIPS_RLD_MAP (not DT_DEBUG) and GDB only
8703 looks at the first one it sees. */
8705 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
8708 /* The DT_DEBUG entry may be filled in by the dynamic linker and
8709 used by the debugger. */
8710 if (info
->executable
8711 && !SGI_COMPAT (output_bfd
)
8712 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
8715 if (reltext
&& (SGI_COMPAT (output_bfd
) || htab
->is_vxworks
))
8716 info
->flags
|= DF_TEXTREL
;
8718 if ((info
->flags
& DF_TEXTREL
) != 0)
8720 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
8723 /* Clear the DF_TEXTREL flag. It will be set again if we
8724 write out an actual text relocation; we may not, because
8725 at this point we do not know whether e.g. any .eh_frame
8726 absolute relocations have been converted to PC-relative. */
8727 info
->flags
&= ~DF_TEXTREL
;
8730 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
8733 sreldyn
= mips_elf_rel_dyn_section (info
, FALSE
);
8734 if (htab
->is_vxworks
)
8736 /* VxWorks uses .rela.dyn instead of .rel.dyn. It does not
8737 use any of the DT_MIPS_* tags. */
8738 if (sreldyn
&& sreldyn
->size
> 0)
8740 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELA
, 0))
8743 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELASZ
, 0))
8746 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELAENT
, 0))
8752 if (sreldyn
&& sreldyn
->size
> 0)
8754 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
8757 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
8760 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
8764 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
8767 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
8770 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
8773 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
8776 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
8779 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
8782 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
8785 if (IRIX_COMPAT (dynobj
) == ict_irix5
8786 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
8789 if (IRIX_COMPAT (dynobj
) == ict_irix6
8790 && (bfd_get_section_by_name
8791 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
8792 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
8795 if (htab
->splt
->size
> 0)
8797 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTREL
, 0))
8800 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_JMPREL
, 0))
8803 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTRELSZ
, 0))
8806 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_PLTGOT
, 0))
8809 if (htab
->is_vxworks
8810 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
8817 /* REL is a relocation in INPUT_BFD that is being copied to OUTPUT_BFD.
8818 Adjust its R_ADDEND field so that it is correct for the output file.
8819 LOCAL_SYMS and LOCAL_SECTIONS are arrays of INPUT_BFD's local symbols
8820 and sections respectively; both use symbol indexes. */
8823 mips_elf_adjust_addend (bfd
*output_bfd
, struct bfd_link_info
*info
,
8824 bfd
*input_bfd
, Elf_Internal_Sym
*local_syms
,
8825 asection
**local_sections
, Elf_Internal_Rela
*rel
)
8827 unsigned int r_type
, r_symndx
;
8828 Elf_Internal_Sym
*sym
;
8831 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
, FALSE
))
8833 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8834 if (r_type
== R_MIPS16_GPREL
8835 || r_type
== R_MIPS_GPREL16
8836 || r_type
== R_MIPS_GPREL32
8837 || r_type
== R_MIPS_LITERAL
)
8839 rel
->r_addend
+= _bfd_get_gp_value (input_bfd
);
8840 rel
->r_addend
-= _bfd_get_gp_value (output_bfd
);
8843 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
8844 sym
= local_syms
+ r_symndx
;
8846 /* Adjust REL's addend to account for section merging. */
8847 if (!info
->relocatable
)
8849 sec
= local_sections
[r_symndx
];
8850 _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
8853 /* This would normally be done by the rela_normal code in elflink.c. */
8854 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8855 rel
->r_addend
+= local_sections
[r_symndx
]->output_offset
;
8859 /* Relocate a MIPS ELF section. */
8862 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
8863 bfd
*input_bfd
, asection
*input_section
,
8864 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
8865 Elf_Internal_Sym
*local_syms
,
8866 asection
**local_sections
)
8868 Elf_Internal_Rela
*rel
;
8869 const Elf_Internal_Rela
*relend
;
8871 bfd_boolean use_saved_addend_p
= FALSE
;
8872 const struct elf_backend_data
*bed
;
8874 bed
= get_elf_backend_data (output_bfd
);
8875 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
8876 for (rel
= relocs
; rel
< relend
; ++rel
)
8880 reloc_howto_type
*howto
;
8881 bfd_boolean require_jalx
;
8882 /* TRUE if the relocation is a RELA relocation, rather than a
8884 bfd_boolean rela_relocation_p
= TRUE
;
8885 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8887 unsigned long r_symndx
;
8889 Elf_Internal_Shdr
*symtab_hdr
;
8890 struct elf_link_hash_entry
*h
;
8892 /* Find the relocation howto for this relocation. */
8893 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
8894 NEWABI_P (input_bfd
)
8895 && (MIPS_RELOC_RELA_P
8896 (input_bfd
, input_section
,
8899 r_symndx
= ELF_R_SYM (input_bfd
, rel
->r_info
);
8900 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
8901 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
, FALSE
))
8903 sec
= local_sections
[r_symndx
];
8908 unsigned long extsymoff
;
8911 if (!elf_bad_symtab (input_bfd
))
8912 extsymoff
= symtab_hdr
->sh_info
;
8913 h
= elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
8914 while (h
->root
.type
== bfd_link_hash_indirect
8915 || h
->root
.type
== bfd_link_hash_warning
)
8916 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8919 if (h
->root
.type
== bfd_link_hash_defined
8920 || h
->root
.type
== bfd_link_hash_defweak
)
8921 sec
= h
->root
.u
.def
.section
;
8924 if (sec
!= NULL
&& elf_discarded_section (sec
))
8926 /* For relocs against symbols from removed linkonce sections,
8927 or sections discarded by a linker script, we just want the
8928 section contents zeroed. Avoid any special processing. */
8929 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
8935 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
8937 /* Some 32-bit code uses R_MIPS_64. In particular, people use
8938 64-bit code, but make sure all their addresses are in the
8939 lowermost or uppermost 32-bit section of the 64-bit address
8940 space. Thus, when they use an R_MIPS_64 they mean what is
8941 usually meant by R_MIPS_32, with the exception that the
8942 stored value is sign-extended to 64 bits. */
8943 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
8945 /* On big-endian systems, we need to lie about the position
8947 if (bfd_big_endian (input_bfd
))
8951 if (!use_saved_addend_p
)
8953 /* If these relocations were originally of the REL variety,
8954 we must pull the addend out of the field that will be
8955 relocated. Otherwise, we simply use the contents of the
8957 if (mips_elf_rel_relocation_p (input_bfd
, input_section
,
8960 rela_relocation_p
= FALSE
;
8961 addend
= mips_elf_read_rel_addend (input_bfd
, rel
,
8963 if (hi16_reloc_p (r_type
)
8964 || (got16_reloc_p (r_type
)
8965 && mips_elf_local_relocation_p (input_bfd
, rel
,
8966 local_sections
, FALSE
)))
8968 if (!mips_elf_add_lo16_rel_addend (input_bfd
, rel
, relend
,
8974 name
= h
->root
.root
.string
;
8976 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
8977 local_syms
+ r_symndx
,
8979 (*_bfd_error_handler
)
8980 (_("%B: Can't find matching LO16 reloc against `%s' for %s at 0x%lx in section `%A'"),
8981 input_bfd
, input_section
, name
, howto
->name
,
8986 addend
<<= howto
->rightshift
;
8989 addend
= rel
->r_addend
;
8990 mips_elf_adjust_addend (output_bfd
, info
, input_bfd
,
8991 local_syms
, local_sections
, rel
);
8994 if (info
->relocatable
)
8996 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
8997 && bfd_big_endian (input_bfd
))
9000 if (!rela_relocation_p
&& rel
->r_addend
)
9002 addend
+= rel
->r_addend
;
9003 if (hi16_reloc_p (r_type
) || got16_reloc_p (r_type
))
9004 addend
= mips_elf_high (addend
);
9005 else if (r_type
== R_MIPS_HIGHER
)
9006 addend
= mips_elf_higher (addend
);
9007 else if (r_type
== R_MIPS_HIGHEST
)
9008 addend
= mips_elf_highest (addend
);
9010 addend
>>= howto
->rightshift
;
9012 /* We use the source mask, rather than the destination
9013 mask because the place to which we are writing will be
9014 source of the addend in the final link. */
9015 addend
&= howto
->src_mask
;
9017 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
9018 /* See the comment above about using R_MIPS_64 in the 32-bit
9019 ABI. Here, we need to update the addend. It would be
9020 possible to get away with just using the R_MIPS_32 reloc
9021 but for endianness. */
9027 if (addend
& ((bfd_vma
) 1 << 31))
9029 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
9036 /* If we don't know that we have a 64-bit type,
9037 do two separate stores. */
9038 if (bfd_big_endian (input_bfd
))
9040 /* Store the sign-bits (which are most significant)
9042 low_bits
= sign_bits
;
9048 high_bits
= sign_bits
;
9050 bfd_put_32 (input_bfd
, low_bits
,
9051 contents
+ rel
->r_offset
);
9052 bfd_put_32 (input_bfd
, high_bits
,
9053 contents
+ rel
->r_offset
+ 4);
9057 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
9058 input_bfd
, input_section
,
9063 /* Go on to the next relocation. */
9067 /* In the N32 and 64-bit ABIs there may be multiple consecutive
9068 relocations for the same offset. In that case we are
9069 supposed to treat the output of each relocation as the addend
9071 if (rel
+ 1 < relend
9072 && rel
->r_offset
== rel
[1].r_offset
9073 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
9074 use_saved_addend_p
= TRUE
;
9076 use_saved_addend_p
= FALSE
;
9078 /* Figure out what value we are supposed to relocate. */
9079 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
9080 input_section
, info
, rel
,
9081 addend
, howto
, local_syms
,
9082 local_sections
, &value
,
9083 &name
, &require_jalx
,
9084 use_saved_addend_p
))
9086 case bfd_reloc_continue
:
9087 /* There's nothing to do. */
9090 case bfd_reloc_undefined
:
9091 /* mips_elf_calculate_relocation already called the
9092 undefined_symbol callback. There's no real point in
9093 trying to perform the relocation at this point, so we
9094 just skip ahead to the next relocation. */
9097 case bfd_reloc_notsupported
:
9098 msg
= _("internal error: unsupported relocation error");
9099 info
->callbacks
->warning
9100 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
9103 case bfd_reloc_overflow
:
9104 if (use_saved_addend_p
)
9105 /* Ignore overflow until we reach the last relocation for
9106 a given location. */
9110 struct mips_elf_link_hash_table
*htab
;
9112 htab
= mips_elf_hash_table (info
);
9113 BFD_ASSERT (name
!= NULL
);
9114 if (!htab
->small_data_overflow_reported
9115 && (howto
->type
== R_MIPS_GPREL16
9116 || howto
->type
== R_MIPS_LITERAL
))
9119 _("small-data section exceeds 64KB;"
9120 " lower small-data size limit (see option -G)");
9122 htab
->small_data_overflow_reported
= TRUE
;
9123 (*info
->callbacks
->einfo
) ("%P: %s\n", msg
);
9125 if (! ((*info
->callbacks
->reloc_overflow
)
9126 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
9127 input_bfd
, input_section
, rel
->r_offset
)))
9140 /* If we've got another relocation for the address, keep going
9141 until we reach the last one. */
9142 if (use_saved_addend_p
)
9148 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
9149 /* See the comment above about using R_MIPS_64 in the 32-bit
9150 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
9151 that calculated the right value. Now, however, we
9152 sign-extend the 32-bit result to 64-bits, and store it as a
9153 64-bit value. We are especially generous here in that we
9154 go to extreme lengths to support this usage on systems with
9155 only a 32-bit VMA. */
9161 if (value
& ((bfd_vma
) 1 << 31))
9163 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
9170 /* If we don't know that we have a 64-bit type,
9171 do two separate stores. */
9172 if (bfd_big_endian (input_bfd
))
9174 /* Undo what we did above. */
9176 /* Store the sign-bits (which are most significant)
9178 low_bits
= sign_bits
;
9184 high_bits
= sign_bits
;
9186 bfd_put_32 (input_bfd
, low_bits
,
9187 contents
+ rel
->r_offset
);
9188 bfd_put_32 (input_bfd
, high_bits
,
9189 contents
+ rel
->r_offset
+ 4);
9193 /* Actually perform the relocation. */
9194 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
9195 input_bfd
, input_section
,
9196 contents
, require_jalx
))
9203 /* A function that iterates over each entry in la25_stubs and fills
9204 in the code for each one. DATA points to a mips_htab_traverse_info. */
9207 mips_elf_create_la25_stub (void **slot
, void *data
)
9209 struct mips_htab_traverse_info
*hti
;
9210 struct mips_elf_link_hash_table
*htab
;
9211 struct mips_elf_la25_stub
*stub
;
9214 bfd_vma offset
, target
, target_high
, target_low
;
9216 stub
= (struct mips_elf_la25_stub
*) *slot
;
9217 hti
= (struct mips_htab_traverse_info
*) data
;
9218 htab
= mips_elf_hash_table (hti
->info
);
9220 /* Create the section contents, if we haven't already. */
9221 s
= stub
->stub_section
;
9225 loc
= bfd_malloc (s
->size
);
9234 /* Work out where in the section this stub should go. */
9235 offset
= stub
->offset
;
9237 /* Work out the target address. */
9238 target
= (stub
->h
->root
.root
.u
.def
.section
->output_section
->vma
9239 + stub
->h
->root
.root
.u
.def
.section
->output_offset
9240 + stub
->h
->root
.root
.u
.def
.value
);
9241 target_high
= ((target
+ 0x8000) >> 16) & 0xffff;
9242 target_low
= (target
& 0xffff);
9244 if (stub
->stub_section
!= htab
->strampoline
)
9246 /* This is a simple LUI/ADIDU stub. Zero out the beginning
9247 of the section and write the two instructions at the end. */
9248 memset (loc
, 0, offset
);
9250 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
9251 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 4);
9255 /* This is trampoline. */
9257 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
9258 bfd_put_32 (hti
->output_bfd
, LA25_J (target
), loc
+ 4);
9259 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 8);
9260 bfd_put_32 (hti
->output_bfd
, 0, loc
+ 12);
9265 /* If NAME is one of the special IRIX6 symbols defined by the linker,
9266 adjust it appropriately now. */
9269 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
9270 const char *name
, Elf_Internal_Sym
*sym
)
9272 /* The linker script takes care of providing names and values for
9273 these, but we must place them into the right sections. */
9274 static const char* const text_section_symbols
[] = {
9277 "__dso_displacement",
9279 "__program_header_table",
9283 static const char* const data_section_symbols
[] = {
9291 const char* const *p
;
9294 for (i
= 0; i
< 2; ++i
)
9295 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
9298 if (strcmp (*p
, name
) == 0)
9300 /* All of these symbols are given type STT_SECTION by the
9302 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9303 sym
->st_other
= STO_PROTECTED
;
9305 /* The IRIX linker puts these symbols in special sections. */
9307 sym
->st_shndx
= SHN_MIPS_TEXT
;
9309 sym
->st_shndx
= SHN_MIPS_DATA
;
9315 /* Finish up dynamic symbol handling. We set the contents of various
9316 dynamic sections here. */
9319 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
9320 struct bfd_link_info
*info
,
9321 struct elf_link_hash_entry
*h
,
9322 Elf_Internal_Sym
*sym
)
9326 struct mips_got_info
*g
, *gg
;
9329 struct mips_elf_link_hash_table
*htab
;
9330 struct mips_elf_link_hash_entry
*hmips
;
9332 htab
= mips_elf_hash_table (info
);
9333 dynobj
= elf_hash_table (info
)->dynobj
;
9334 hmips
= (struct mips_elf_link_hash_entry
*) h
;
9336 BFD_ASSERT (!htab
->is_vxworks
);
9338 if (h
->plt
.offset
!= MINUS_ONE
&& hmips
->no_fn_stub
)
9340 /* We've decided to create a PLT entry for this symbol. */
9342 bfd_vma header_address
, plt_index
, got_address
;
9343 bfd_vma got_address_high
, got_address_low
, load
;
9344 const bfd_vma
*plt_entry
;
9346 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
9347 BFD_ASSERT (h
->dynindx
!= -1);
9348 BFD_ASSERT (htab
->splt
!= NULL
);
9349 BFD_ASSERT (h
->plt
.offset
<= htab
->splt
->size
);
9350 BFD_ASSERT (!h
->def_regular
);
9352 /* Calculate the address of the PLT header. */
9353 header_address
= (htab
->splt
->output_section
->vma
9354 + htab
->splt
->output_offset
);
9356 /* Calculate the index of the entry. */
9357 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
9358 / htab
->plt_entry_size
);
9360 /* Calculate the address of the .got.plt entry. */
9361 got_address
= (htab
->sgotplt
->output_section
->vma
9362 + htab
->sgotplt
->output_offset
9363 + (2 + plt_index
) * MIPS_ELF_GOT_SIZE (dynobj
));
9364 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
9365 got_address_low
= got_address
& 0xffff;
9367 /* Initially point the .got.plt entry at the PLT header. */
9368 loc
= (htab
->sgotplt
->contents
9369 + (2 + plt_index
) * MIPS_ELF_GOT_SIZE (dynobj
));
9370 if (ABI_64_P (output_bfd
))
9371 bfd_put_64 (output_bfd
, header_address
, loc
);
9373 bfd_put_32 (output_bfd
, header_address
, loc
);
9375 /* Find out where the .plt entry should go. */
9376 loc
= htab
->splt
->contents
+ h
->plt
.offset
;
9378 /* Pick the load opcode. */
9379 load
= MIPS_ELF_LOAD_WORD (output_bfd
);
9381 /* Fill in the PLT entry itself. */
9382 plt_entry
= mips_exec_plt_entry
;
9383 bfd_put_32 (output_bfd
, plt_entry
[0] | got_address_high
, loc
);
9384 bfd_put_32 (output_bfd
, plt_entry
[1] | got_address_low
| load
, loc
+ 4);
9386 if (! LOAD_INTERLOCKS_P (output_bfd
))
9388 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_low
, loc
+ 8);
9389 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9393 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 8);
9394 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_low
, loc
+ 12);
9397 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
9398 mips_elf_output_dynamic_relocation (output_bfd
, htab
->srelplt
,
9399 plt_index
, h
->dynindx
,
9400 R_MIPS_JUMP_SLOT
, got_address
);
9402 /* We distinguish between PLT entries and lazy-binding stubs by
9403 giving the former an st_other value of STO_MIPS_PLT. Set the
9404 flag and leave the value if there are any relocations in the
9405 binary where pointer equality matters. */
9406 sym
->st_shndx
= SHN_UNDEF
;
9407 if (h
->pointer_equality_needed
)
9408 sym
->st_other
= STO_MIPS_PLT
;
9412 else if (h
->plt
.offset
!= MINUS_ONE
)
9414 /* We've decided to create a lazy-binding stub. */
9415 bfd_byte stub
[MIPS_FUNCTION_STUB_BIG_SIZE
];
9417 /* This symbol has a stub. Set it up. */
9419 BFD_ASSERT (h
->dynindx
!= -1);
9421 BFD_ASSERT ((htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
9422 || (h
->dynindx
<= 0xffff));
9424 /* Values up to 2^31 - 1 are allowed. Larger values would cause
9425 sign extension at runtime in the stub, resulting in a negative
9427 if (h
->dynindx
& ~0x7fffffff)
9430 /* Fill the stub. */
9432 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
+ idx
);
9434 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ idx
);
9436 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
9438 bfd_put_32 (output_bfd
, STUB_LUI ((h
->dynindx
>> 16) & 0x7fff),
9442 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ idx
);
9445 /* If a large stub is not required and sign extension is not a
9446 problem, then use legacy code in the stub. */
9447 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
9448 bfd_put_32 (output_bfd
, STUB_ORI (h
->dynindx
& 0xffff), stub
+ idx
);
9449 else if (h
->dynindx
& ~0x7fff)
9450 bfd_put_32 (output_bfd
, STUB_LI16U (h
->dynindx
& 0xffff), stub
+ idx
);
9452 bfd_put_32 (output_bfd
, STUB_LI16S (output_bfd
, h
->dynindx
),
9455 BFD_ASSERT (h
->plt
.offset
<= htab
->sstubs
->size
);
9456 memcpy (htab
->sstubs
->contents
+ h
->plt
.offset
,
9457 stub
, htab
->function_stub_size
);
9459 /* Mark the symbol as undefined. plt.offset != -1 occurs
9460 only for the referenced symbol. */
9461 sym
->st_shndx
= SHN_UNDEF
;
9463 /* The run-time linker uses the st_value field of the symbol
9464 to reset the global offset table entry for this external
9465 to its stub address when unlinking a shared object. */
9466 sym
->st_value
= (htab
->sstubs
->output_section
->vma
9467 + htab
->sstubs
->output_offset
9471 /* If we have a MIPS16 function with a stub, the dynamic symbol must
9472 refer to the stub, since only the stub uses the standard calling
9474 if (h
->dynindx
!= -1 && hmips
->fn_stub
!= NULL
)
9476 BFD_ASSERT (hmips
->need_fn_stub
);
9477 sym
->st_value
= (hmips
->fn_stub
->output_section
->vma
9478 + hmips
->fn_stub
->output_offset
);
9479 sym
->st_size
= hmips
->fn_stub
->size
;
9480 sym
->st_other
= ELF_ST_VISIBILITY (sym
->st_other
);
9483 BFD_ASSERT (h
->dynindx
!= -1
9484 || h
->forced_local
);
9488 BFD_ASSERT (g
!= NULL
);
9490 /* Run through the global symbol table, creating GOT entries for all
9491 the symbols that need them. */
9492 if (g
->global_gotsym
!= NULL
9493 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
9498 value
= sym
->st_value
;
9499 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
9500 R_MIPS_GOT16
, info
);
9501 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
9504 if (g
->next
&& h
->dynindx
!= -1 && h
->type
!= STT_TLS
)
9506 struct mips_got_entry e
, *p
;
9512 e
.abfd
= output_bfd
;
9517 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
9520 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
9525 || (elf_hash_table (info
)->dynamic_sections_created
9527 && p
->d
.h
->root
.def_dynamic
9528 && !p
->d
.h
->root
.def_regular
))
9530 /* Create an R_MIPS_REL32 relocation for this entry. Due to
9531 the various compatibility problems, it's easier to mock
9532 up an R_MIPS_32 or R_MIPS_64 relocation and leave
9533 mips_elf_create_dynamic_relocation to calculate the
9534 appropriate addend. */
9535 Elf_Internal_Rela rel
[3];
9537 memset (rel
, 0, sizeof (rel
));
9538 if (ABI_64_P (output_bfd
))
9539 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
9541 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
9542 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
9545 if (! (mips_elf_create_dynamic_relocation
9546 (output_bfd
, info
, rel
,
9547 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
9551 entry
= sym
->st_value
;
9552 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
9557 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
9558 name
= h
->root
.root
.string
;
9559 if (strcmp (name
, "_DYNAMIC") == 0
9560 || h
== elf_hash_table (info
)->hgot
)
9561 sym
->st_shndx
= SHN_ABS
;
9562 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
9563 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
9565 sym
->st_shndx
= SHN_ABS
;
9566 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9569 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
9571 sym
->st_shndx
= SHN_ABS
;
9572 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9573 sym
->st_value
= elf_gp (output_bfd
);
9575 else if (SGI_COMPAT (output_bfd
))
9577 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
9578 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
9580 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9581 sym
->st_other
= STO_PROTECTED
;
9583 sym
->st_shndx
= SHN_MIPS_DATA
;
9585 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
9587 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9588 sym
->st_other
= STO_PROTECTED
;
9589 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
9590 sym
->st_shndx
= SHN_ABS
;
9592 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
9594 if (h
->type
== STT_FUNC
)
9595 sym
->st_shndx
= SHN_MIPS_TEXT
;
9596 else if (h
->type
== STT_OBJECT
)
9597 sym
->st_shndx
= SHN_MIPS_DATA
;
9601 /* Emit a copy reloc, if needed. */
9607 BFD_ASSERT (h
->dynindx
!= -1);
9608 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
9610 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9611 symval
= (h
->root
.u
.def
.section
->output_section
->vma
9612 + h
->root
.u
.def
.section
->output_offset
9613 + h
->root
.u
.def
.value
);
9614 mips_elf_output_dynamic_relocation (output_bfd
, s
, s
->reloc_count
++,
9615 h
->dynindx
, R_MIPS_COPY
, symval
);
9618 /* Handle the IRIX6-specific symbols. */
9619 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
9620 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
9624 if (! mips_elf_hash_table (info
)->use_rld_obj_head
9625 && (strcmp (name
, "__rld_map") == 0
9626 || strcmp (name
, "__RLD_MAP") == 0))
9628 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
9629 BFD_ASSERT (s
!= NULL
);
9630 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
9631 bfd_put_32 (output_bfd
, 0, s
->contents
);
9632 if (mips_elf_hash_table (info
)->rld_value
== 0)
9633 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
9635 else if (mips_elf_hash_table (info
)->use_rld_obj_head
9636 && strcmp (name
, "__rld_obj_head") == 0)
9638 /* IRIX6 does not use a .rld_map section. */
9639 if (IRIX_COMPAT (output_bfd
) == ict_irix5
9640 || IRIX_COMPAT (output_bfd
) == ict_none
)
9641 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
9643 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
9647 /* Keep dynamic MIPS16 symbols odd. This allows the dynamic linker to
9648 treat MIPS16 symbols like any other. */
9649 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
9651 BFD_ASSERT (sym
->st_value
& 1);
9652 sym
->st_other
-= STO_MIPS16
;
9658 /* Likewise, for VxWorks. */
9661 _bfd_mips_vxworks_finish_dynamic_symbol (bfd
*output_bfd
,
9662 struct bfd_link_info
*info
,
9663 struct elf_link_hash_entry
*h
,
9664 Elf_Internal_Sym
*sym
)
9668 struct mips_got_info
*g
;
9669 struct mips_elf_link_hash_table
*htab
;
9671 htab
= mips_elf_hash_table (info
);
9672 dynobj
= elf_hash_table (info
)->dynobj
;
9674 if (h
->plt
.offset
!= (bfd_vma
) -1)
9677 bfd_vma plt_address
, plt_index
, got_address
, got_offset
, branch_offset
;
9678 Elf_Internal_Rela rel
;
9679 static const bfd_vma
*plt_entry
;
9681 BFD_ASSERT (h
->dynindx
!= -1);
9682 BFD_ASSERT (htab
->splt
!= NULL
);
9683 BFD_ASSERT (h
->plt
.offset
<= htab
->splt
->size
);
9685 /* Calculate the address of the .plt entry. */
9686 plt_address
= (htab
->splt
->output_section
->vma
9687 + htab
->splt
->output_offset
9690 /* Calculate the index of the entry. */
9691 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
9692 / htab
->plt_entry_size
);
9694 /* Calculate the address of the .got.plt entry. */
9695 got_address
= (htab
->sgotplt
->output_section
->vma
9696 + htab
->sgotplt
->output_offset
9699 /* Calculate the offset of the .got.plt entry from
9700 _GLOBAL_OFFSET_TABLE_. */
9701 got_offset
= mips_elf_gotplt_index (info
, h
);
9703 /* Calculate the offset for the branch at the start of the PLT
9704 entry. The branch jumps to the beginning of .plt. */
9705 branch_offset
= -(h
->plt
.offset
/ 4 + 1) & 0xffff;
9707 /* Fill in the initial value of the .got.plt entry. */
9708 bfd_put_32 (output_bfd
, plt_address
,
9709 htab
->sgotplt
->contents
+ plt_index
* 4);
9711 /* Find out where the .plt entry should go. */
9712 loc
= htab
->splt
->contents
+ h
->plt
.offset
;
9716 plt_entry
= mips_vxworks_shared_plt_entry
;
9717 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9718 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9722 bfd_vma got_address_high
, got_address_low
;
9724 plt_entry
= mips_vxworks_exec_plt_entry
;
9725 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
9726 got_address_low
= got_address
& 0xffff;
9728 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9729 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9730 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_high
, loc
+ 8);
9731 bfd_put_32 (output_bfd
, plt_entry
[3] | got_address_low
, loc
+ 12);
9732 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9733 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9734 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
9735 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
9737 loc
= (htab
->srelplt2
->contents
9738 + (plt_index
* 3 + 2) * sizeof (Elf32_External_Rela
));
9740 /* Emit a relocation for the .got.plt entry. */
9741 rel
.r_offset
= got_address
;
9742 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9743 rel
.r_addend
= h
->plt
.offset
;
9744 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9746 /* Emit a relocation for the lui of %hi(<.got.plt slot>). */
9747 loc
+= sizeof (Elf32_External_Rela
);
9748 rel
.r_offset
= plt_address
+ 8;
9749 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9750 rel
.r_addend
= got_offset
;
9751 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9753 /* Emit a relocation for the addiu of %lo(<.got.plt slot>). */
9754 loc
+= sizeof (Elf32_External_Rela
);
9756 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9757 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9760 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
9761 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
9762 rel
.r_offset
= got_address
;
9763 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_JUMP_SLOT
);
9765 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9767 if (!h
->def_regular
)
9768 sym
->st_shndx
= SHN_UNDEF
;
9771 BFD_ASSERT (h
->dynindx
!= -1 || h
->forced_local
);
9775 BFD_ASSERT (g
!= NULL
);
9777 /* See if this symbol has an entry in the GOT. */
9778 if (g
->global_gotsym
!= NULL
9779 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
9782 Elf_Internal_Rela outrel
;
9786 /* Install the symbol value in the GOT. */
9787 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
9788 R_MIPS_GOT16
, info
);
9789 MIPS_ELF_PUT_WORD (output_bfd
, sym
->st_value
, sgot
->contents
+ offset
);
9791 /* Add a dynamic relocation for it. */
9792 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9793 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
9794 outrel
.r_offset
= (sgot
->output_section
->vma
9795 + sgot
->output_offset
9797 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_32
);
9798 outrel
.r_addend
= 0;
9799 bfd_elf32_swap_reloca_out (dynobj
, &outrel
, loc
);
9802 /* Emit a copy reloc, if needed. */
9805 Elf_Internal_Rela rel
;
9807 BFD_ASSERT (h
->dynindx
!= -1);
9809 rel
.r_offset
= (h
->root
.u
.def
.section
->output_section
->vma
9810 + h
->root
.u
.def
.section
->output_offset
9811 + h
->root
.u
.def
.value
);
9812 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_COPY
);
9814 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
9815 htab
->srelbss
->contents
9816 + (htab
->srelbss
->reloc_count
9817 * sizeof (Elf32_External_Rela
)));
9818 ++htab
->srelbss
->reloc_count
;
9821 /* If this is a mips16 symbol, force the value to be even. */
9822 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
9823 sym
->st_value
&= ~1;
9828 /* Write out a plt0 entry to the beginning of .plt. */
9831 mips_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9834 bfd_vma gotplt_value
, gotplt_value_high
, gotplt_value_low
;
9835 static const bfd_vma
*plt_entry
;
9836 struct mips_elf_link_hash_table
*htab
;
9838 htab
= mips_elf_hash_table (info
);
9839 if (ABI_64_P (output_bfd
))
9840 plt_entry
= mips_n64_exec_plt0_entry
;
9841 else if (ABI_N32_P (output_bfd
))
9842 plt_entry
= mips_n32_exec_plt0_entry
;
9844 plt_entry
= mips_o32_exec_plt0_entry
;
9846 /* Calculate the value of .got.plt. */
9847 gotplt_value
= (htab
->sgotplt
->output_section
->vma
9848 + htab
->sgotplt
->output_offset
);
9849 gotplt_value_high
= ((gotplt_value
+ 0x8000) >> 16) & 0xffff;
9850 gotplt_value_low
= gotplt_value
& 0xffff;
9852 /* The PLT sequence is not safe for N64 if .got.plt's address can
9853 not be loaded in two instructions. */
9854 BFD_ASSERT ((gotplt_value
& ~(bfd_vma
) 0x7fffffff) == 0
9855 || ~(gotplt_value
| 0x7fffffff) == 0);
9857 /* Install the PLT header. */
9858 loc
= htab
->splt
->contents
;
9859 bfd_put_32 (output_bfd
, plt_entry
[0] | gotplt_value_high
, loc
);
9860 bfd_put_32 (output_bfd
, plt_entry
[1] | gotplt_value_low
, loc
+ 4);
9861 bfd_put_32 (output_bfd
, plt_entry
[2] | gotplt_value_low
, loc
+ 8);
9862 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9863 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9864 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9865 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
9866 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
9869 /* Install the PLT header for a VxWorks executable and finalize the
9870 contents of .rela.plt.unloaded. */
9873 mips_vxworks_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9875 Elf_Internal_Rela rela
;
9877 bfd_vma got_value
, got_value_high
, got_value_low
, plt_address
;
9878 static const bfd_vma
*plt_entry
;
9879 struct mips_elf_link_hash_table
*htab
;
9881 htab
= mips_elf_hash_table (info
);
9882 plt_entry
= mips_vxworks_exec_plt0_entry
;
9884 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
9885 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
9886 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
9887 + htab
->root
.hgot
->root
.u
.def
.value
);
9889 got_value_high
= ((got_value
+ 0x8000) >> 16) & 0xffff;
9890 got_value_low
= got_value
& 0xffff;
9892 /* Calculate the address of the PLT header. */
9893 plt_address
= htab
->splt
->output_section
->vma
+ htab
->splt
->output_offset
;
9895 /* Install the PLT header. */
9896 loc
= htab
->splt
->contents
;
9897 bfd_put_32 (output_bfd
, plt_entry
[0] | got_value_high
, loc
);
9898 bfd_put_32 (output_bfd
, plt_entry
[1] | got_value_low
, loc
+ 4);
9899 bfd_put_32 (output_bfd
, plt_entry
[2], loc
+ 8);
9900 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9901 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9902 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9904 /* Output the relocation for the lui of %hi(_GLOBAL_OFFSET_TABLE_). */
9905 loc
= htab
->srelplt2
->contents
;
9906 rela
.r_offset
= plt_address
;
9907 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9909 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9910 loc
+= sizeof (Elf32_External_Rela
);
9912 /* Output the relocation for the following addiu of
9913 %lo(_GLOBAL_OFFSET_TABLE_). */
9915 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9916 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9917 loc
+= sizeof (Elf32_External_Rela
);
9919 /* Fix up the remaining relocations. They may have the wrong
9920 symbol index for _G_O_T_ or _P_L_T_ depending on the order
9921 in which symbols were output. */
9922 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
9924 Elf_Internal_Rela rel
;
9926 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9927 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9928 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9929 loc
+= sizeof (Elf32_External_Rela
);
9931 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9932 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9933 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9934 loc
+= sizeof (Elf32_External_Rela
);
9936 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9937 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9938 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9939 loc
+= sizeof (Elf32_External_Rela
);
9943 /* Install the PLT header for a VxWorks shared library. */
9946 mips_vxworks_finish_shared_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9949 struct mips_elf_link_hash_table
*htab
;
9951 htab
= mips_elf_hash_table (info
);
9953 /* We just need to copy the entry byte-by-byte. */
9954 for (i
= 0; i
< ARRAY_SIZE (mips_vxworks_shared_plt0_entry
); i
++)
9955 bfd_put_32 (output_bfd
, mips_vxworks_shared_plt0_entry
[i
],
9956 htab
->splt
->contents
+ i
* 4);
9959 /* Finish up the dynamic sections. */
9962 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
9963 struct bfd_link_info
*info
)
9968 struct mips_got_info
*gg
, *g
;
9969 struct mips_elf_link_hash_table
*htab
;
9971 htab
= mips_elf_hash_table (info
);
9972 dynobj
= elf_hash_table (info
)->dynobj
;
9974 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
9977 gg
= htab
->got_info
;
9979 if (elf_hash_table (info
)->dynamic_sections_created
)
9982 int dyn_to_skip
= 0, dyn_skipped
= 0;
9984 BFD_ASSERT (sdyn
!= NULL
);
9985 BFD_ASSERT (gg
!= NULL
);
9987 g
= mips_elf_got_for_ibfd (gg
, output_bfd
);
9988 BFD_ASSERT (g
!= NULL
);
9990 for (b
= sdyn
->contents
;
9991 b
< sdyn
->contents
+ sdyn
->size
;
9992 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
9994 Elf_Internal_Dyn dyn
;
9998 bfd_boolean swap_out_p
;
10000 /* Read in the current dynamic entry. */
10001 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
10003 /* Assume that we're going to modify it and write it out. */
10009 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
10013 BFD_ASSERT (htab
->is_vxworks
);
10014 dyn
.d_un
.d_val
= MIPS_ELF_RELA_SIZE (dynobj
);
10018 /* Rewrite DT_STRSZ. */
10020 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
10025 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
10028 case DT_MIPS_PLTGOT
:
10030 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
10033 case DT_MIPS_RLD_VERSION
:
10034 dyn
.d_un
.d_val
= 1; /* XXX */
10037 case DT_MIPS_FLAGS
:
10038 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
10041 case DT_MIPS_TIME_STAMP
:
10045 dyn
.d_un
.d_val
= t
;
10049 case DT_MIPS_ICHECKSUM
:
10051 swap_out_p
= FALSE
;
10054 case DT_MIPS_IVERSION
:
10056 swap_out_p
= FALSE
;
10059 case DT_MIPS_BASE_ADDRESS
:
10060 s
= output_bfd
->sections
;
10061 BFD_ASSERT (s
!= NULL
);
10062 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
10065 case DT_MIPS_LOCAL_GOTNO
:
10066 dyn
.d_un
.d_val
= g
->local_gotno
;
10069 case DT_MIPS_UNREFEXTNO
:
10070 /* The index into the dynamic symbol table which is the
10071 entry of the first external symbol that is not
10072 referenced within the same object. */
10073 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
10076 case DT_MIPS_GOTSYM
:
10077 if (gg
->global_gotsym
)
10079 dyn
.d_un
.d_val
= gg
->global_gotsym
->dynindx
;
10082 /* In case if we don't have global got symbols we default
10083 to setting DT_MIPS_GOTSYM to the same value as
10084 DT_MIPS_SYMTABNO, so we just fall through. */
10086 case DT_MIPS_SYMTABNO
:
10088 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
10089 s
= bfd_get_section_by_name (output_bfd
, name
);
10090 BFD_ASSERT (s
!= NULL
);
10092 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
10095 case DT_MIPS_HIPAGENO
:
10096 dyn
.d_un
.d_val
= g
->local_gotno
- htab
->reserved_gotno
;
10099 case DT_MIPS_RLD_MAP
:
10100 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
10103 case DT_MIPS_OPTIONS
:
10104 s
= (bfd_get_section_by_name
10105 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
10106 dyn
.d_un
.d_ptr
= s
->vma
;
10110 BFD_ASSERT (htab
->is_vxworks
);
10111 /* The count does not include the JUMP_SLOT relocations. */
10113 dyn
.d_un
.d_val
-= htab
->srelplt
->size
;
10117 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10118 if (htab
->is_vxworks
)
10119 dyn
.d_un
.d_val
= DT_RELA
;
10121 dyn
.d_un
.d_val
= DT_REL
;
10125 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10126 dyn
.d_un
.d_val
= htab
->srelplt
->size
;
10130 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10131 dyn
.d_un
.d_ptr
= (htab
->srelplt
->output_section
->vma
10132 + htab
->srelplt
->output_offset
);
10136 /* If we didn't need any text relocations after all, delete
10137 the dynamic tag. */
10138 if (!(info
->flags
& DF_TEXTREL
))
10140 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
10141 swap_out_p
= FALSE
;
10146 /* If we didn't need any text relocations after all, clear
10147 DF_TEXTREL from DT_FLAGS. */
10148 if (!(info
->flags
& DF_TEXTREL
))
10149 dyn
.d_un
.d_val
&= ~DF_TEXTREL
;
10151 swap_out_p
= FALSE
;
10155 swap_out_p
= FALSE
;
10156 if (htab
->is_vxworks
10157 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
10162 if (swap_out_p
|| dyn_skipped
)
10163 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
10164 (dynobj
, &dyn
, b
- dyn_skipped
);
10168 dyn_skipped
+= dyn_to_skip
;
10173 /* Wipe out any trailing entries if we shifted down a dynamic tag. */
10174 if (dyn_skipped
> 0)
10175 memset (b
- dyn_skipped
, 0, dyn_skipped
);
10178 if (sgot
!= NULL
&& sgot
->size
> 0
10179 && !bfd_is_abs_section (sgot
->output_section
))
10181 if (htab
->is_vxworks
)
10183 /* The first entry of the global offset table points to the
10184 ".dynamic" section. The second is initialized by the
10185 loader and contains the shared library identifier.
10186 The third is also initialized by the loader and points
10187 to the lazy resolution stub. */
10188 MIPS_ELF_PUT_WORD (output_bfd
,
10189 sdyn
->output_offset
+ sdyn
->output_section
->vma
,
10191 MIPS_ELF_PUT_WORD (output_bfd
, 0,
10192 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
10193 MIPS_ELF_PUT_WORD (output_bfd
, 0,
10195 + 2 * MIPS_ELF_GOT_SIZE (output_bfd
));
10199 /* The first entry of the global offset table will be filled at
10200 runtime. The second entry will be used by some runtime loaders.
10201 This isn't the case of IRIX rld. */
10202 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
10203 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
10204 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
10207 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
10208 = MIPS_ELF_GOT_SIZE (output_bfd
);
10211 /* Generate dynamic relocations for the non-primary gots. */
10212 if (gg
!= NULL
&& gg
->next
)
10214 Elf_Internal_Rela rel
[3];
10215 bfd_vma addend
= 0;
10217 memset (rel
, 0, sizeof (rel
));
10218 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
10220 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
10222 bfd_vma index
= g
->next
->local_gotno
+ g
->next
->global_gotno
10223 + g
->next
->tls_gotno
;
10225 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
10226 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
10227 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
10229 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
10231 if (! info
->shared
)
10234 while (index
< g
->assigned_gotno
)
10236 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
10237 = index
++ * MIPS_ELF_GOT_SIZE (output_bfd
);
10238 if (!(mips_elf_create_dynamic_relocation
10239 (output_bfd
, info
, rel
, NULL
,
10240 bfd_abs_section_ptr
,
10241 0, &addend
, sgot
)))
10243 BFD_ASSERT (addend
== 0);
10248 /* The generation of dynamic relocations for the non-primary gots
10249 adds more dynamic relocations. We cannot count them until
10252 if (elf_hash_table (info
)->dynamic_sections_created
)
10255 bfd_boolean swap_out_p
;
10257 BFD_ASSERT (sdyn
!= NULL
);
10259 for (b
= sdyn
->contents
;
10260 b
< sdyn
->contents
+ sdyn
->size
;
10261 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
10263 Elf_Internal_Dyn dyn
;
10266 /* Read in the current dynamic entry. */
10267 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
10269 /* Assume that we're going to modify it and write it out. */
10275 /* Reduce DT_RELSZ to account for any relocations we
10276 decided not to make. This is for the n64 irix rld,
10277 which doesn't seem to apply any relocations if there
10278 are trailing null entries. */
10279 s
= mips_elf_rel_dyn_section (info
, FALSE
);
10280 dyn
.d_un
.d_val
= (s
->reloc_count
10281 * (ABI_64_P (output_bfd
)
10282 ? sizeof (Elf64_Mips_External_Rel
)
10283 : sizeof (Elf32_External_Rel
)));
10284 /* Adjust the section size too. Tools like the prelinker
10285 can reasonably expect the values to the same. */
10286 elf_section_data (s
->output_section
)->this_hdr
.sh_size
10291 swap_out_p
= FALSE
;
10296 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
10303 Elf32_compact_rel cpt
;
10305 if (SGI_COMPAT (output_bfd
))
10307 /* Write .compact_rel section out. */
10308 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
10312 cpt
.num
= s
->reloc_count
;
10314 cpt
.offset
= (s
->output_section
->filepos
10315 + sizeof (Elf32_External_compact_rel
));
10318 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
10319 ((Elf32_External_compact_rel
*)
10322 /* Clean up a dummy stub function entry in .text. */
10323 if (htab
->sstubs
!= NULL
)
10325 file_ptr dummy_offset
;
10327 BFD_ASSERT (htab
->sstubs
->size
>= htab
->function_stub_size
);
10328 dummy_offset
= htab
->sstubs
->size
- htab
->function_stub_size
;
10329 memset (htab
->sstubs
->contents
+ dummy_offset
, 0,
10330 htab
->function_stub_size
);
10335 /* The psABI says that the dynamic relocations must be sorted in
10336 increasing order of r_symndx. The VxWorks EABI doesn't require
10337 this, and because the code below handles REL rather than RELA
10338 relocations, using it for VxWorks would be outright harmful. */
10339 if (!htab
->is_vxworks
)
10341 s
= mips_elf_rel_dyn_section (info
, FALSE
);
10343 && s
->size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
10345 reldyn_sorting_bfd
= output_bfd
;
10347 if (ABI_64_P (output_bfd
))
10348 qsort ((Elf64_External_Rel
*) s
->contents
+ 1,
10349 s
->reloc_count
- 1, sizeof (Elf64_Mips_External_Rel
),
10350 sort_dynamic_relocs_64
);
10352 qsort ((Elf32_External_Rel
*) s
->contents
+ 1,
10353 s
->reloc_count
- 1, sizeof (Elf32_External_Rel
),
10354 sort_dynamic_relocs
);
10359 if (htab
->splt
&& htab
->splt
->size
> 0)
10361 if (htab
->is_vxworks
)
10364 mips_vxworks_finish_shared_plt (output_bfd
, info
);
10366 mips_vxworks_finish_exec_plt (output_bfd
, info
);
10370 BFD_ASSERT (!info
->shared
);
10371 mips_finish_exec_plt (output_bfd
, info
);
10378 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
10381 mips_set_isa_flags (bfd
*abfd
)
10385 switch (bfd_get_mach (abfd
))
10388 case bfd_mach_mips3000
:
10389 val
= E_MIPS_ARCH_1
;
10392 case bfd_mach_mips3900
:
10393 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
10396 case bfd_mach_mips6000
:
10397 val
= E_MIPS_ARCH_2
;
10400 case bfd_mach_mips4000
:
10401 case bfd_mach_mips4300
:
10402 case bfd_mach_mips4400
:
10403 case bfd_mach_mips4600
:
10404 val
= E_MIPS_ARCH_3
;
10407 case bfd_mach_mips4010
:
10408 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
10411 case bfd_mach_mips4100
:
10412 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
10415 case bfd_mach_mips4111
:
10416 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
10419 case bfd_mach_mips4120
:
10420 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
10423 case bfd_mach_mips4650
:
10424 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
10427 case bfd_mach_mips5400
:
10428 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
10431 case bfd_mach_mips5500
:
10432 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
10435 case bfd_mach_mips9000
:
10436 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_9000
;
10439 case bfd_mach_mips5000
:
10440 case bfd_mach_mips7000
:
10441 case bfd_mach_mips8000
:
10442 case bfd_mach_mips10000
:
10443 case bfd_mach_mips12000
:
10444 case bfd_mach_mips14000
:
10445 case bfd_mach_mips16000
:
10446 val
= E_MIPS_ARCH_4
;
10449 case bfd_mach_mips5
:
10450 val
= E_MIPS_ARCH_5
;
10453 case bfd_mach_mips_loongson_2e
:
10454 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2E
;
10457 case bfd_mach_mips_loongson_2f
:
10458 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2F
;
10461 case bfd_mach_mips_sb1
:
10462 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
10465 case bfd_mach_mips_octeon
:
10466 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON
;
10469 case bfd_mach_mips_xlr
:
10470 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_XLR
;
10473 case bfd_mach_mipsisa32
:
10474 val
= E_MIPS_ARCH_32
;
10477 case bfd_mach_mipsisa64
:
10478 val
= E_MIPS_ARCH_64
;
10481 case bfd_mach_mipsisa32r2
:
10482 val
= E_MIPS_ARCH_32R2
;
10485 case bfd_mach_mipsisa64r2
:
10486 val
= E_MIPS_ARCH_64R2
;
10489 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
10490 elf_elfheader (abfd
)->e_flags
|= val
;
10495 /* The final processing done just before writing out a MIPS ELF object
10496 file. This gets the MIPS architecture right based on the machine
10497 number. This is used by both the 32-bit and the 64-bit ABI. */
10500 _bfd_mips_elf_final_write_processing (bfd
*abfd
,
10501 bfd_boolean linker ATTRIBUTE_UNUSED
)
10504 Elf_Internal_Shdr
**hdrpp
;
10508 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
10509 is nonzero. This is for compatibility with old objects, which used
10510 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
10511 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
10512 mips_set_isa_flags (abfd
);
10514 /* Set the sh_info field for .gptab sections and other appropriate
10515 info for each special section. */
10516 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
10517 i
< elf_numsections (abfd
);
10520 switch ((*hdrpp
)->sh_type
)
10522 case SHT_MIPS_MSYM
:
10523 case SHT_MIPS_LIBLIST
:
10524 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
10526 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10529 case SHT_MIPS_GPTAB
:
10530 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
10531 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
10532 BFD_ASSERT (name
!= NULL
10533 && CONST_STRNEQ (name
, ".gptab."));
10534 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
10535 BFD_ASSERT (sec
!= NULL
);
10536 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
10539 case SHT_MIPS_CONTENT
:
10540 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
10541 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
10542 BFD_ASSERT (name
!= NULL
10543 && CONST_STRNEQ (name
, ".MIPS.content"));
10544 sec
= bfd_get_section_by_name (abfd
,
10545 name
+ sizeof ".MIPS.content" - 1);
10546 BFD_ASSERT (sec
!= NULL
);
10547 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10550 case SHT_MIPS_SYMBOL_LIB
:
10551 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
10553 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10554 sec
= bfd_get_section_by_name (abfd
, ".liblist");
10556 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
10559 case SHT_MIPS_EVENTS
:
10560 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
10561 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
10562 BFD_ASSERT (name
!= NULL
);
10563 if (CONST_STRNEQ (name
, ".MIPS.events"))
10564 sec
= bfd_get_section_by_name (abfd
,
10565 name
+ sizeof ".MIPS.events" - 1);
10568 BFD_ASSERT (CONST_STRNEQ (name
, ".MIPS.post_rel"));
10569 sec
= bfd_get_section_by_name (abfd
,
10571 + sizeof ".MIPS.post_rel" - 1));
10573 BFD_ASSERT (sec
!= NULL
);
10574 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10581 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
10585 _bfd_mips_elf_additional_program_headers (bfd
*abfd
,
10586 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
10591 /* See if we need a PT_MIPS_REGINFO segment. */
10592 s
= bfd_get_section_by_name (abfd
, ".reginfo");
10593 if (s
&& (s
->flags
& SEC_LOAD
))
10596 /* See if we need a PT_MIPS_OPTIONS segment. */
10597 if (IRIX_COMPAT (abfd
) == ict_irix6
10598 && bfd_get_section_by_name (abfd
,
10599 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
10602 /* See if we need a PT_MIPS_RTPROC segment. */
10603 if (IRIX_COMPAT (abfd
) == ict_irix5
10604 && bfd_get_section_by_name (abfd
, ".dynamic")
10605 && bfd_get_section_by_name (abfd
, ".mdebug"))
10608 /* Allocate a PT_NULL header in dynamic objects. See
10609 _bfd_mips_elf_modify_segment_map for details. */
10610 if (!SGI_COMPAT (abfd
)
10611 && bfd_get_section_by_name (abfd
, ".dynamic"))
10617 /* Modify the segment map for an IRIX5 executable. */
10620 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
10621 struct bfd_link_info
*info
)
10624 struct elf_segment_map
*m
, **pm
;
10627 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
10629 s
= bfd_get_section_by_name (abfd
, ".reginfo");
10630 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
10632 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
10633 if (m
->p_type
== PT_MIPS_REGINFO
)
10638 m
= bfd_zalloc (abfd
, amt
);
10642 m
->p_type
= PT_MIPS_REGINFO
;
10644 m
->sections
[0] = s
;
10646 /* We want to put it after the PHDR and INTERP segments. */
10647 pm
= &elf_tdata (abfd
)->segment_map
;
10649 && ((*pm
)->p_type
== PT_PHDR
10650 || (*pm
)->p_type
== PT_INTERP
))
10658 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
10659 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
10660 PT_MIPS_OPTIONS segment immediately following the program header
10662 if (NEWABI_P (abfd
)
10663 /* On non-IRIX6 new abi, we'll have already created a segment
10664 for this section, so don't create another. I'm not sure this
10665 is not also the case for IRIX 6, but I can't test it right
10667 && IRIX_COMPAT (abfd
) == ict_irix6
)
10669 for (s
= abfd
->sections
; s
; s
= s
->next
)
10670 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
10675 struct elf_segment_map
*options_segment
;
10677 pm
= &elf_tdata (abfd
)->segment_map
;
10679 && ((*pm
)->p_type
== PT_PHDR
10680 || (*pm
)->p_type
== PT_INTERP
))
10683 if (*pm
== NULL
|| (*pm
)->p_type
!= PT_MIPS_OPTIONS
)
10685 amt
= sizeof (struct elf_segment_map
);
10686 options_segment
= bfd_zalloc (abfd
, amt
);
10687 options_segment
->next
= *pm
;
10688 options_segment
->p_type
= PT_MIPS_OPTIONS
;
10689 options_segment
->p_flags
= PF_R
;
10690 options_segment
->p_flags_valid
= TRUE
;
10691 options_segment
->count
= 1;
10692 options_segment
->sections
[0] = s
;
10693 *pm
= options_segment
;
10699 if (IRIX_COMPAT (abfd
) == ict_irix5
)
10701 /* If there are .dynamic and .mdebug sections, we make a room
10702 for the RTPROC header. FIXME: Rewrite without section names. */
10703 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
10704 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
10705 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
10707 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
10708 if (m
->p_type
== PT_MIPS_RTPROC
)
10713 m
= bfd_zalloc (abfd
, amt
);
10717 m
->p_type
= PT_MIPS_RTPROC
;
10719 s
= bfd_get_section_by_name (abfd
, ".rtproc");
10724 m
->p_flags_valid
= 1;
10729 m
->sections
[0] = s
;
10732 /* We want to put it after the DYNAMIC segment. */
10733 pm
= &elf_tdata (abfd
)->segment_map
;
10734 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
10744 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
10745 .dynstr, .dynsym, and .hash sections, and everything in
10747 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
10749 if ((*pm
)->p_type
== PT_DYNAMIC
)
10752 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
10754 /* For a normal mips executable the permissions for the PT_DYNAMIC
10755 segment are read, write and execute. We do that here since
10756 the code in elf.c sets only the read permission. This matters
10757 sometimes for the dynamic linker. */
10758 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
10760 m
->p_flags
= PF_R
| PF_W
| PF_X
;
10761 m
->p_flags_valid
= 1;
10764 /* GNU/Linux binaries do not need the extended PT_DYNAMIC section.
10765 glibc's dynamic linker has traditionally derived the number of
10766 tags from the p_filesz field, and sometimes allocates stack
10767 arrays of that size. An overly-big PT_DYNAMIC segment can
10768 be actively harmful in such cases. Making PT_DYNAMIC contain
10769 other sections can also make life hard for the prelinker,
10770 which might move one of the other sections to a different
10771 PT_LOAD segment. */
10772 if (SGI_COMPAT (abfd
)
10775 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
10777 static const char *sec_names
[] =
10779 ".dynamic", ".dynstr", ".dynsym", ".hash"
10783 struct elf_segment_map
*n
;
10785 low
= ~(bfd_vma
) 0;
10787 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
10789 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
10790 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
10797 if (high
< s
->vma
+ sz
)
10798 high
= s
->vma
+ sz
;
10803 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10804 if ((s
->flags
& SEC_LOAD
) != 0
10806 && s
->vma
+ s
->size
<= high
)
10809 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
10810 n
= bfd_zalloc (abfd
, amt
);
10817 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10819 if ((s
->flags
& SEC_LOAD
) != 0
10821 && s
->vma
+ s
->size
<= high
)
10823 n
->sections
[i
] = s
;
10832 /* Allocate a spare program header in dynamic objects so that tools
10833 like the prelinker can add an extra PT_LOAD entry.
10835 If the prelinker needs to make room for a new PT_LOAD entry, its
10836 standard procedure is to move the first (read-only) sections into
10837 the new (writable) segment. However, the MIPS ABI requires
10838 .dynamic to be in a read-only segment, and the section will often
10839 start within sizeof (ElfNN_Phdr) bytes of the last program header.
10841 Although the prelinker could in principle move .dynamic to a
10842 writable segment, it seems better to allocate a spare program
10843 header instead, and avoid the need to move any sections.
10844 There is a long tradition of allocating spare dynamic tags,
10845 so allocating a spare program header seems like a natural
10848 If INFO is NULL, we may be copying an already prelinked binary
10849 with objcopy or strip, so do not add this header. */
10851 && !SGI_COMPAT (abfd
)
10852 && bfd_get_section_by_name (abfd
, ".dynamic"))
10854 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
10855 if ((*pm
)->p_type
== PT_NULL
)
10859 m
= bfd_zalloc (abfd
, sizeof (*m
));
10863 m
->p_type
= PT_NULL
;
10871 /* Return the section that should be marked against GC for a given
10875 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
10876 struct bfd_link_info
*info
,
10877 Elf_Internal_Rela
*rel
,
10878 struct elf_link_hash_entry
*h
,
10879 Elf_Internal_Sym
*sym
)
10881 /* ??? Do mips16 stub sections need to be handled special? */
10884 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
10886 case R_MIPS_GNU_VTINHERIT
:
10887 case R_MIPS_GNU_VTENTRY
:
10891 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
10894 /* Update the got entry reference counts for the section being removed. */
10897 _bfd_mips_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
10898 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
10899 asection
*sec ATTRIBUTE_UNUSED
,
10900 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
10903 Elf_Internal_Shdr
*symtab_hdr
;
10904 struct elf_link_hash_entry
**sym_hashes
;
10905 bfd_signed_vma
*local_got_refcounts
;
10906 const Elf_Internal_Rela
*rel
, *relend
;
10907 unsigned long r_symndx
;
10908 struct elf_link_hash_entry
*h
;
10910 if (info
->relocatable
)
10913 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
10914 sym_hashes
= elf_sym_hashes (abfd
);
10915 local_got_refcounts
= elf_local_got_refcounts (abfd
);
10917 relend
= relocs
+ sec
->reloc_count
;
10918 for (rel
= relocs
; rel
< relend
; rel
++)
10919 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
10921 case R_MIPS16_GOT16
:
10922 case R_MIPS16_CALL16
:
10924 case R_MIPS_CALL16
:
10925 case R_MIPS_CALL_HI16
:
10926 case R_MIPS_CALL_LO16
:
10927 case R_MIPS_GOT_HI16
:
10928 case R_MIPS_GOT_LO16
:
10929 case R_MIPS_GOT_DISP
:
10930 case R_MIPS_GOT_PAGE
:
10931 case R_MIPS_GOT_OFST
:
10932 /* ??? It would seem that the existing MIPS code does no sort
10933 of reference counting or whatnot on its GOT and PLT entries,
10934 so it is not possible to garbage collect them at this time. */
10945 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
10946 hiding the old indirect symbol. Process additional relocation
10947 information. Also called for weakdefs, in which case we just let
10948 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
10951 _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
10952 struct elf_link_hash_entry
*dir
,
10953 struct elf_link_hash_entry
*ind
)
10955 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
10957 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
10959 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
10960 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
10961 /* Any absolute non-dynamic relocations against an indirect or weak
10962 definition will be against the target symbol. */
10963 if (indmips
->has_static_relocs
)
10964 dirmips
->has_static_relocs
= TRUE
;
10966 if (ind
->root
.type
!= bfd_link_hash_indirect
)
10969 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
10970 if (indmips
->readonly_reloc
)
10971 dirmips
->readonly_reloc
= TRUE
;
10972 if (indmips
->no_fn_stub
)
10973 dirmips
->no_fn_stub
= TRUE
;
10974 if (indmips
->fn_stub
)
10976 dirmips
->fn_stub
= indmips
->fn_stub
;
10977 indmips
->fn_stub
= NULL
;
10979 if (indmips
->need_fn_stub
)
10981 dirmips
->need_fn_stub
= TRUE
;
10982 indmips
->need_fn_stub
= FALSE
;
10984 if (indmips
->call_stub
)
10986 dirmips
->call_stub
= indmips
->call_stub
;
10987 indmips
->call_stub
= NULL
;
10989 if (indmips
->call_fp_stub
)
10991 dirmips
->call_fp_stub
= indmips
->call_fp_stub
;
10992 indmips
->call_fp_stub
= NULL
;
10994 if (indmips
->global_got_area
< dirmips
->global_got_area
)
10995 dirmips
->global_got_area
= indmips
->global_got_area
;
10996 if (indmips
->global_got_area
< GGA_NONE
)
10997 indmips
->global_got_area
= GGA_NONE
;
10998 if (indmips
->has_nonpic_branches
)
10999 dirmips
->has_nonpic_branches
= TRUE
;
11001 if (dirmips
->tls_type
== 0)
11002 dirmips
->tls_type
= indmips
->tls_type
;
11005 #define PDR_SIZE 32
11008 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
11009 struct bfd_link_info
*info
)
11012 bfd_boolean ret
= FALSE
;
11013 unsigned char *tdata
;
11016 o
= bfd_get_section_by_name (abfd
, ".pdr");
11021 if (o
->size
% PDR_SIZE
!= 0)
11023 if (o
->output_section
!= NULL
11024 && bfd_is_abs_section (o
->output_section
))
11027 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
11031 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
11032 info
->keep_memory
);
11039 cookie
->rel
= cookie
->rels
;
11040 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
11042 for (i
= 0, skip
= 0; i
< o
->size
/ PDR_SIZE
; i
++)
11044 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
11053 mips_elf_section_data (o
)->u
.tdata
= tdata
;
11054 o
->size
-= skip
* PDR_SIZE
;
11060 if (! info
->keep_memory
)
11061 free (cookie
->rels
);
11067 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
11069 if (strcmp (sec
->name
, ".pdr") == 0)
11075 _bfd_mips_elf_write_section (bfd
*output_bfd
,
11076 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
11077 asection
*sec
, bfd_byte
*contents
)
11079 bfd_byte
*to
, *from
, *end
;
11082 if (strcmp (sec
->name
, ".pdr") != 0)
11085 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
11089 end
= contents
+ sec
->size
;
11090 for (from
= contents
, i
= 0;
11092 from
+= PDR_SIZE
, i
++)
11094 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
11097 memcpy (to
, from
, PDR_SIZE
);
11100 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
11101 sec
->output_offset
, sec
->size
);
11105 /* MIPS ELF uses a special find_nearest_line routine in order the
11106 handle the ECOFF debugging information. */
11108 struct mips_elf_find_line
11110 struct ecoff_debug_info d
;
11111 struct ecoff_find_line i
;
11115 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asection
*section
,
11116 asymbol
**symbols
, bfd_vma offset
,
11117 const char **filename_ptr
,
11118 const char **functionname_ptr
,
11119 unsigned int *line_ptr
)
11123 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
11124 filename_ptr
, functionname_ptr
,
11128 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
11129 filename_ptr
, functionname_ptr
,
11130 line_ptr
, ABI_64_P (abfd
) ? 8 : 0,
11131 &elf_tdata (abfd
)->dwarf2_find_line_info
))
11134 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
11137 flagword origflags
;
11138 struct mips_elf_find_line
*fi
;
11139 const struct ecoff_debug_swap
* const swap
=
11140 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
11142 /* If we are called during a link, mips_elf_final_link may have
11143 cleared the SEC_HAS_CONTENTS field. We force it back on here
11144 if appropriate (which it normally will be). */
11145 origflags
= msec
->flags
;
11146 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
11147 msec
->flags
|= SEC_HAS_CONTENTS
;
11149 fi
= elf_tdata (abfd
)->find_line_info
;
11152 bfd_size_type external_fdr_size
;
11155 struct fdr
*fdr_ptr
;
11156 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
11158 fi
= bfd_zalloc (abfd
, amt
);
11161 msec
->flags
= origflags
;
11165 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
11167 msec
->flags
= origflags
;
11171 /* Swap in the FDR information. */
11172 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
11173 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
11174 if (fi
->d
.fdr
== NULL
)
11176 msec
->flags
= origflags
;
11179 external_fdr_size
= swap
->external_fdr_size
;
11180 fdr_ptr
= fi
->d
.fdr
;
11181 fraw_src
= (char *) fi
->d
.external_fdr
;
11182 fraw_end
= (fraw_src
11183 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
11184 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
11185 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
11187 elf_tdata (abfd
)->find_line_info
= fi
;
11189 /* Note that we don't bother to ever free this information.
11190 find_nearest_line is either called all the time, as in
11191 objdump -l, so the information should be saved, or it is
11192 rarely called, as in ld error messages, so the memory
11193 wasted is unimportant. Still, it would probably be a
11194 good idea for free_cached_info to throw it away. */
11197 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
11198 &fi
->i
, filename_ptr
, functionname_ptr
,
11201 msec
->flags
= origflags
;
11205 msec
->flags
= origflags
;
11208 /* Fall back on the generic ELF find_nearest_line routine. */
11210 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
11211 filename_ptr
, functionname_ptr
,
11216 _bfd_mips_elf_find_inliner_info (bfd
*abfd
,
11217 const char **filename_ptr
,
11218 const char **functionname_ptr
,
11219 unsigned int *line_ptr
)
11222 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
11223 functionname_ptr
, line_ptr
,
11224 & elf_tdata (abfd
)->dwarf2_find_line_info
);
11229 /* When are writing out the .options or .MIPS.options section,
11230 remember the bytes we are writing out, so that we can install the
11231 GP value in the section_processing routine. */
11234 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
11235 const void *location
,
11236 file_ptr offset
, bfd_size_type count
)
11238 if (MIPS_ELF_OPTIONS_SECTION_NAME_P (section
->name
))
11242 if (elf_section_data (section
) == NULL
)
11244 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
11245 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
11246 if (elf_section_data (section
) == NULL
)
11249 c
= mips_elf_section_data (section
)->u
.tdata
;
11252 c
= bfd_zalloc (abfd
, section
->size
);
11255 mips_elf_section_data (section
)->u
.tdata
= c
;
11258 memcpy (c
+ offset
, location
, count
);
11261 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
11265 /* This is almost identical to bfd_generic_get_... except that some
11266 MIPS relocations need to be handled specially. Sigh. */
11269 _bfd_elf_mips_get_relocated_section_contents
11271 struct bfd_link_info
*link_info
,
11272 struct bfd_link_order
*link_order
,
11274 bfd_boolean relocatable
,
11277 /* Get enough memory to hold the stuff */
11278 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
11279 asection
*input_section
= link_order
->u
.indirect
.section
;
11282 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
11283 arelent
**reloc_vector
= NULL
;
11286 if (reloc_size
< 0)
11289 reloc_vector
= bfd_malloc (reloc_size
);
11290 if (reloc_vector
== NULL
&& reloc_size
!= 0)
11293 /* read in the section */
11294 sz
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
11295 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0, sz
))
11298 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
11302 if (reloc_count
< 0)
11305 if (reloc_count
> 0)
11310 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
11313 struct bfd_hash_entry
*h
;
11314 struct bfd_link_hash_entry
*lh
;
11315 /* Skip all this stuff if we aren't mixing formats. */
11316 if (abfd
&& input_bfd
11317 && abfd
->xvec
== input_bfd
->xvec
)
11321 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
11322 lh
= (struct bfd_link_hash_entry
*) h
;
11329 case bfd_link_hash_undefined
:
11330 case bfd_link_hash_undefweak
:
11331 case bfd_link_hash_common
:
11334 case bfd_link_hash_defined
:
11335 case bfd_link_hash_defweak
:
11337 gp
= lh
->u
.def
.value
;
11339 case bfd_link_hash_indirect
:
11340 case bfd_link_hash_warning
:
11342 /* @@FIXME ignoring warning for now */
11344 case bfd_link_hash_new
:
11353 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
11355 char *error_message
= NULL
;
11356 bfd_reloc_status_type r
;
11358 /* Specific to MIPS: Deal with relocation types that require
11359 knowing the gp of the output bfd. */
11360 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
11362 /* If we've managed to find the gp and have a special
11363 function for the relocation then go ahead, else default
11364 to the generic handling. */
11366 && (*parent
)->howto
->special_function
11367 == _bfd_mips_elf32_gprel16_reloc
)
11368 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
11369 input_section
, relocatable
,
11372 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
11374 relocatable
? abfd
: NULL
,
11379 asection
*os
= input_section
->output_section
;
11381 /* A partial link, so keep the relocs */
11382 os
->orelocation
[os
->reloc_count
] = *parent
;
11386 if (r
!= bfd_reloc_ok
)
11390 case bfd_reloc_undefined
:
11391 if (!((*link_info
->callbacks
->undefined_symbol
)
11392 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
11393 input_bfd
, input_section
, (*parent
)->address
, TRUE
)))
11396 case bfd_reloc_dangerous
:
11397 BFD_ASSERT (error_message
!= NULL
);
11398 if (!((*link_info
->callbacks
->reloc_dangerous
)
11399 (link_info
, error_message
, input_bfd
, input_section
,
11400 (*parent
)->address
)))
11403 case bfd_reloc_overflow
:
11404 if (!((*link_info
->callbacks
->reloc_overflow
)
11406 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
11407 (*parent
)->howto
->name
, (*parent
)->addend
,
11408 input_bfd
, input_section
, (*parent
)->address
)))
11411 case bfd_reloc_outofrange
:
11420 if (reloc_vector
!= NULL
)
11421 free (reloc_vector
);
11425 if (reloc_vector
!= NULL
)
11426 free (reloc_vector
);
11430 /* Allocate ABFD's target-dependent data. */
11433 _bfd_mips_elf_mkobject (bfd
*abfd
)
11435 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_obj_tdata
),
11439 /* Create a MIPS ELF linker hash table. */
11441 struct bfd_link_hash_table
*
11442 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
11444 struct mips_elf_link_hash_table
*ret
;
11445 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
11447 ret
= bfd_malloc (amt
);
11451 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
11452 mips_elf_link_hash_newfunc
,
11453 sizeof (struct mips_elf_link_hash_entry
)))
11460 /* We no longer use this. */
11461 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
11462 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
11464 ret
->procedure_count
= 0;
11465 ret
->compact_rel_size
= 0;
11466 ret
->use_rld_obj_head
= FALSE
;
11467 ret
->rld_value
= 0;
11468 ret
->mips16_stubs_seen
= FALSE
;
11469 ret
->use_plts_and_copy_relocs
= FALSE
;
11470 ret
->is_vxworks
= FALSE
;
11471 ret
->small_data_overflow_reported
= FALSE
;
11472 ret
->srelbss
= NULL
;
11473 ret
->sdynbss
= NULL
;
11474 ret
->srelplt
= NULL
;
11475 ret
->srelplt2
= NULL
;
11476 ret
->sgotplt
= NULL
;
11478 ret
->sstubs
= NULL
;
11480 ret
->got_info
= NULL
;
11481 ret
->plt_header_size
= 0;
11482 ret
->plt_entry_size
= 0;
11483 ret
->lazy_stub_count
= 0;
11484 ret
->function_stub_size
= 0;
11485 ret
->strampoline
= NULL
;
11486 ret
->la25_stubs
= NULL
;
11487 ret
->add_stub_section
= NULL
;
11489 return &ret
->root
.root
;
11492 /* Likewise, but indicate that the target is VxWorks. */
11494 struct bfd_link_hash_table
*
11495 _bfd_mips_vxworks_link_hash_table_create (bfd
*abfd
)
11497 struct bfd_link_hash_table
*ret
;
11499 ret
= _bfd_mips_elf_link_hash_table_create (abfd
);
11502 struct mips_elf_link_hash_table
*htab
;
11504 htab
= (struct mips_elf_link_hash_table
*) ret
;
11505 htab
->use_plts_and_copy_relocs
= TRUE
;
11506 htab
->is_vxworks
= TRUE
;
11511 /* A function that the linker calls if we are allowed to use PLTs
11512 and copy relocs. */
11515 _bfd_mips_elf_use_plts_and_copy_relocs (struct bfd_link_info
*info
)
11517 mips_elf_hash_table (info
)->use_plts_and_copy_relocs
= TRUE
;
11520 /* We need to use a special link routine to handle the .reginfo and
11521 the .mdebug sections. We need to merge all instances of these
11522 sections together, not write them all out sequentially. */
11525 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
11528 struct bfd_link_order
*p
;
11529 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
11530 asection
*rtproc_sec
;
11531 Elf32_RegInfo reginfo
;
11532 struct ecoff_debug_info debug
;
11533 struct mips_htab_traverse_info hti
;
11534 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
11535 const struct ecoff_debug_swap
*swap
= bed
->elf_backend_ecoff_debug_swap
;
11536 HDRR
*symhdr
= &debug
.symbolic_header
;
11537 void *mdebug_handle
= NULL
;
11542 struct mips_elf_link_hash_table
*htab
;
11544 static const char * const secname
[] =
11546 ".text", ".init", ".fini", ".data",
11547 ".rodata", ".sdata", ".sbss", ".bss"
11549 static const int sc
[] =
11551 scText
, scInit
, scFini
, scData
,
11552 scRData
, scSData
, scSBss
, scBss
11555 /* Sort the dynamic symbols so that those with GOT entries come after
11557 htab
= mips_elf_hash_table (info
);
11558 if (!mips_elf_sort_hash_table (abfd
, info
))
11561 /* Create any scheduled LA25 stubs. */
11563 hti
.output_bfd
= abfd
;
11565 htab_traverse (htab
->la25_stubs
, mips_elf_create_la25_stub
, &hti
);
11569 /* Get a value for the GP register. */
11570 if (elf_gp (abfd
) == 0)
11572 struct bfd_link_hash_entry
*h
;
11574 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
11575 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
11576 elf_gp (abfd
) = (h
->u
.def
.value
11577 + h
->u
.def
.section
->output_section
->vma
11578 + h
->u
.def
.section
->output_offset
);
11579 else if (htab
->is_vxworks
11580 && (h
= bfd_link_hash_lookup (info
->hash
,
11581 "_GLOBAL_OFFSET_TABLE_",
11582 FALSE
, FALSE
, TRUE
))
11583 && h
->type
== bfd_link_hash_defined
)
11584 elf_gp (abfd
) = (h
->u
.def
.section
->output_section
->vma
11585 + h
->u
.def
.section
->output_offset
11587 else if (info
->relocatable
)
11589 bfd_vma lo
= MINUS_ONE
;
11591 /* Find the GP-relative section with the lowest offset. */
11592 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
11594 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
11597 /* And calculate GP relative to that. */
11598 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (info
);
11602 /* If the relocate_section function needs to do a reloc
11603 involving the GP value, it should make a reloc_dangerous
11604 callback to warn that GP is not defined. */
11608 /* Go through the sections and collect the .reginfo and .mdebug
11610 reginfo_sec
= NULL
;
11612 gptab_data_sec
= NULL
;
11613 gptab_bss_sec
= NULL
;
11614 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
11616 if (strcmp (o
->name
, ".reginfo") == 0)
11618 memset (®info
, 0, sizeof reginfo
);
11620 /* We have found the .reginfo section in the output file.
11621 Look through all the link_orders comprising it and merge
11622 the information together. */
11623 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11625 asection
*input_section
;
11627 Elf32_External_RegInfo ext
;
11630 if (p
->type
!= bfd_indirect_link_order
)
11632 if (p
->type
== bfd_data_link_order
)
11637 input_section
= p
->u
.indirect
.section
;
11638 input_bfd
= input_section
->owner
;
11640 if (! bfd_get_section_contents (input_bfd
, input_section
,
11641 &ext
, 0, sizeof ext
))
11644 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
11646 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
11647 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
11648 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
11649 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
11650 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
11652 /* ri_gp_value is set by the function
11653 mips_elf32_section_processing when the section is
11654 finally written out. */
11656 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11657 elf_link_input_bfd ignores this section. */
11658 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11661 /* Size has been set in _bfd_mips_elf_always_size_sections. */
11662 BFD_ASSERT(o
->size
== sizeof (Elf32_External_RegInfo
));
11664 /* Skip this section later on (I don't think this currently
11665 matters, but someday it might). */
11666 o
->map_head
.link_order
= NULL
;
11671 if (strcmp (o
->name
, ".mdebug") == 0)
11673 struct extsym_info einfo
;
11676 /* We have found the .mdebug section in the output file.
11677 Look through all the link_orders comprising it and merge
11678 the information together. */
11679 symhdr
->magic
= swap
->sym_magic
;
11680 /* FIXME: What should the version stamp be? */
11681 symhdr
->vstamp
= 0;
11682 symhdr
->ilineMax
= 0;
11683 symhdr
->cbLine
= 0;
11684 symhdr
->idnMax
= 0;
11685 symhdr
->ipdMax
= 0;
11686 symhdr
->isymMax
= 0;
11687 symhdr
->ioptMax
= 0;
11688 symhdr
->iauxMax
= 0;
11689 symhdr
->issMax
= 0;
11690 symhdr
->issExtMax
= 0;
11691 symhdr
->ifdMax
= 0;
11693 symhdr
->iextMax
= 0;
11695 /* We accumulate the debugging information itself in the
11696 debug_info structure. */
11698 debug
.external_dnr
= NULL
;
11699 debug
.external_pdr
= NULL
;
11700 debug
.external_sym
= NULL
;
11701 debug
.external_opt
= NULL
;
11702 debug
.external_aux
= NULL
;
11704 debug
.ssext
= debug
.ssext_end
= NULL
;
11705 debug
.external_fdr
= NULL
;
11706 debug
.external_rfd
= NULL
;
11707 debug
.external_ext
= debug
.external_ext_end
= NULL
;
11709 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
11710 if (mdebug_handle
== NULL
)
11714 esym
.cobol_main
= 0;
11718 esym
.asym
.iss
= issNil
;
11719 esym
.asym
.st
= stLocal
;
11720 esym
.asym
.reserved
= 0;
11721 esym
.asym
.index
= indexNil
;
11723 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
11725 esym
.asym
.sc
= sc
[i
];
11726 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
11729 esym
.asym
.value
= s
->vma
;
11730 last
= s
->vma
+ s
->size
;
11733 esym
.asym
.value
= last
;
11734 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
11735 secname
[i
], &esym
))
11739 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11741 asection
*input_section
;
11743 const struct ecoff_debug_swap
*input_swap
;
11744 struct ecoff_debug_info input_debug
;
11748 if (p
->type
!= bfd_indirect_link_order
)
11750 if (p
->type
== bfd_data_link_order
)
11755 input_section
= p
->u
.indirect
.section
;
11756 input_bfd
= input_section
->owner
;
11758 if (!is_mips_elf (input_bfd
))
11760 /* I don't know what a non MIPS ELF bfd would be
11761 doing with a .mdebug section, but I don't really
11762 want to deal with it. */
11766 input_swap
= (get_elf_backend_data (input_bfd
)
11767 ->elf_backend_ecoff_debug_swap
);
11769 BFD_ASSERT (p
->size
== input_section
->size
);
11771 /* The ECOFF linking code expects that we have already
11772 read in the debugging information and set up an
11773 ecoff_debug_info structure, so we do that now. */
11774 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
11778 if (! (bfd_ecoff_debug_accumulate
11779 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
11780 &input_debug
, input_swap
, info
)))
11783 /* Loop through the external symbols. For each one with
11784 interesting information, try to find the symbol in
11785 the linker global hash table and save the information
11786 for the output external symbols. */
11787 eraw_src
= input_debug
.external_ext
;
11788 eraw_end
= (eraw_src
11789 + (input_debug
.symbolic_header
.iextMax
11790 * input_swap
->external_ext_size
));
11792 eraw_src
< eraw_end
;
11793 eraw_src
+= input_swap
->external_ext_size
)
11797 struct mips_elf_link_hash_entry
*h
;
11799 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
11800 if (ext
.asym
.sc
== scNil
11801 || ext
.asym
.sc
== scUndefined
11802 || ext
.asym
.sc
== scSUndefined
)
11805 name
= input_debug
.ssext
+ ext
.asym
.iss
;
11806 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
11807 name
, FALSE
, FALSE
, TRUE
);
11808 if (h
== NULL
|| h
->esym
.ifd
!= -2)
11813 BFD_ASSERT (ext
.ifd
11814 < input_debug
.symbolic_header
.ifdMax
);
11815 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
11821 /* Free up the information we just read. */
11822 free (input_debug
.line
);
11823 free (input_debug
.external_dnr
);
11824 free (input_debug
.external_pdr
);
11825 free (input_debug
.external_sym
);
11826 free (input_debug
.external_opt
);
11827 free (input_debug
.external_aux
);
11828 free (input_debug
.ss
);
11829 free (input_debug
.ssext
);
11830 free (input_debug
.external_fdr
);
11831 free (input_debug
.external_rfd
);
11832 free (input_debug
.external_ext
);
11834 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11835 elf_link_input_bfd ignores this section. */
11836 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11839 if (SGI_COMPAT (abfd
) && info
->shared
)
11841 /* Create .rtproc section. */
11842 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
11843 if (rtproc_sec
== NULL
)
11845 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
11846 | SEC_LINKER_CREATED
| SEC_READONLY
);
11848 rtproc_sec
= bfd_make_section_with_flags (abfd
,
11851 if (rtproc_sec
== NULL
11852 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
11856 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
11862 /* Build the external symbol information. */
11865 einfo
.debug
= &debug
;
11867 einfo
.failed
= FALSE
;
11868 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
11869 mips_elf_output_extsym
, &einfo
);
11873 /* Set the size of the .mdebug section. */
11874 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
11876 /* Skip this section later on (I don't think this currently
11877 matters, but someday it might). */
11878 o
->map_head
.link_order
= NULL
;
11883 if (CONST_STRNEQ (o
->name
, ".gptab."))
11885 const char *subname
;
11888 Elf32_External_gptab
*ext_tab
;
11891 /* The .gptab.sdata and .gptab.sbss sections hold
11892 information describing how the small data area would
11893 change depending upon the -G switch. These sections
11894 not used in executables files. */
11895 if (! info
->relocatable
)
11897 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11899 asection
*input_section
;
11901 if (p
->type
!= bfd_indirect_link_order
)
11903 if (p
->type
== bfd_data_link_order
)
11908 input_section
= p
->u
.indirect
.section
;
11910 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11911 elf_link_input_bfd ignores this section. */
11912 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11915 /* Skip this section later on (I don't think this
11916 currently matters, but someday it might). */
11917 o
->map_head
.link_order
= NULL
;
11919 /* Really remove the section. */
11920 bfd_section_list_remove (abfd
, o
);
11921 --abfd
->section_count
;
11926 /* There is one gptab for initialized data, and one for
11927 uninitialized data. */
11928 if (strcmp (o
->name
, ".gptab.sdata") == 0)
11929 gptab_data_sec
= o
;
11930 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
11934 (*_bfd_error_handler
)
11935 (_("%s: illegal section name `%s'"),
11936 bfd_get_filename (abfd
), o
->name
);
11937 bfd_set_error (bfd_error_nonrepresentable_section
);
11941 /* The linker script always combines .gptab.data and
11942 .gptab.sdata into .gptab.sdata, and likewise for
11943 .gptab.bss and .gptab.sbss. It is possible that there is
11944 no .sdata or .sbss section in the output file, in which
11945 case we must change the name of the output section. */
11946 subname
= o
->name
+ sizeof ".gptab" - 1;
11947 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
11949 if (o
== gptab_data_sec
)
11950 o
->name
= ".gptab.data";
11952 o
->name
= ".gptab.bss";
11953 subname
= o
->name
+ sizeof ".gptab" - 1;
11954 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
11957 /* Set up the first entry. */
11959 amt
= c
* sizeof (Elf32_gptab
);
11960 tab
= bfd_malloc (amt
);
11963 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
11964 tab
[0].gt_header
.gt_unused
= 0;
11966 /* Combine the input sections. */
11967 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11969 asection
*input_section
;
11971 bfd_size_type size
;
11972 unsigned long last
;
11973 bfd_size_type gpentry
;
11975 if (p
->type
!= bfd_indirect_link_order
)
11977 if (p
->type
== bfd_data_link_order
)
11982 input_section
= p
->u
.indirect
.section
;
11983 input_bfd
= input_section
->owner
;
11985 /* Combine the gptab entries for this input section one
11986 by one. We know that the input gptab entries are
11987 sorted by ascending -G value. */
11988 size
= input_section
->size
;
11990 for (gpentry
= sizeof (Elf32_External_gptab
);
11992 gpentry
+= sizeof (Elf32_External_gptab
))
11994 Elf32_External_gptab ext_gptab
;
11995 Elf32_gptab int_gptab
;
12001 if (! (bfd_get_section_contents
12002 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
12003 sizeof (Elf32_External_gptab
))))
12009 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
12011 val
= int_gptab
.gt_entry
.gt_g_value
;
12012 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
12015 for (look
= 1; look
< c
; look
++)
12017 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
12018 tab
[look
].gt_entry
.gt_bytes
+= add
;
12020 if (tab
[look
].gt_entry
.gt_g_value
== val
)
12026 Elf32_gptab
*new_tab
;
12029 /* We need a new table entry. */
12030 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
12031 new_tab
= bfd_realloc (tab
, amt
);
12032 if (new_tab
== NULL
)
12038 tab
[c
].gt_entry
.gt_g_value
= val
;
12039 tab
[c
].gt_entry
.gt_bytes
= add
;
12041 /* Merge in the size for the next smallest -G
12042 value, since that will be implied by this new
12045 for (look
= 1; look
< c
; look
++)
12047 if (tab
[look
].gt_entry
.gt_g_value
< val
12049 || (tab
[look
].gt_entry
.gt_g_value
12050 > tab
[max
].gt_entry
.gt_g_value
)))
12054 tab
[c
].gt_entry
.gt_bytes
+=
12055 tab
[max
].gt_entry
.gt_bytes
;
12060 last
= int_gptab
.gt_entry
.gt_bytes
;
12063 /* Hack: reset the SEC_HAS_CONTENTS flag so that
12064 elf_link_input_bfd ignores this section. */
12065 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
12068 /* The table must be sorted by -G value. */
12070 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
12072 /* Swap out the table. */
12073 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
12074 ext_tab
= bfd_alloc (abfd
, amt
);
12075 if (ext_tab
== NULL
)
12081 for (j
= 0; j
< c
; j
++)
12082 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
12085 o
->size
= c
* sizeof (Elf32_External_gptab
);
12086 o
->contents
= (bfd_byte
*) ext_tab
;
12088 /* Skip this section later on (I don't think this currently
12089 matters, but someday it might). */
12090 o
->map_head
.link_order
= NULL
;
12094 /* Invoke the regular ELF backend linker to do all the work. */
12095 if (!bfd_elf_final_link (abfd
, info
))
12098 /* Now write out the computed sections. */
12100 if (reginfo_sec
!= NULL
)
12102 Elf32_External_RegInfo ext
;
12104 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
12105 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
12109 if (mdebug_sec
!= NULL
)
12111 BFD_ASSERT (abfd
->output_has_begun
);
12112 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
12114 mdebug_sec
->filepos
))
12117 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
12120 if (gptab_data_sec
!= NULL
)
12122 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
12123 gptab_data_sec
->contents
,
12124 0, gptab_data_sec
->size
))
12128 if (gptab_bss_sec
!= NULL
)
12130 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
12131 gptab_bss_sec
->contents
,
12132 0, gptab_bss_sec
->size
))
12136 if (SGI_COMPAT (abfd
))
12138 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
12139 if (rtproc_sec
!= NULL
)
12141 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
12142 rtproc_sec
->contents
,
12143 0, rtproc_sec
->size
))
12151 /* Structure for saying that BFD machine EXTENSION extends BASE. */
12153 struct mips_mach_extension
{
12154 unsigned long extension
, base
;
12158 /* An array describing how BFD machines relate to one another. The entries
12159 are ordered topologically with MIPS I extensions listed last. */
12161 static const struct mips_mach_extension mips_mach_extensions
[] = {
12162 /* MIPS64r2 extensions. */
12163 { bfd_mach_mips_octeon
, bfd_mach_mipsisa64r2
},
12165 /* MIPS64 extensions. */
12166 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
12167 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
12168 { bfd_mach_mips_xlr
, bfd_mach_mipsisa64
},
12170 /* MIPS V extensions. */
12171 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
12173 /* R10000 extensions. */
12174 { bfd_mach_mips12000
, bfd_mach_mips10000
},
12175 { bfd_mach_mips14000
, bfd_mach_mips10000
},
12176 { bfd_mach_mips16000
, bfd_mach_mips10000
},
12178 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
12179 vr5400 ISA, but doesn't include the multimedia stuff. It seems
12180 better to allow vr5400 and vr5500 code to be merged anyway, since
12181 many libraries will just use the core ISA. Perhaps we could add
12182 some sort of ASE flag if this ever proves a problem. */
12183 { bfd_mach_mips5500
, bfd_mach_mips5400
},
12184 { bfd_mach_mips5400
, bfd_mach_mips5000
},
12186 /* MIPS IV extensions. */
12187 { bfd_mach_mips5
, bfd_mach_mips8000
},
12188 { bfd_mach_mips10000
, bfd_mach_mips8000
},
12189 { bfd_mach_mips5000
, bfd_mach_mips8000
},
12190 { bfd_mach_mips7000
, bfd_mach_mips8000
},
12191 { bfd_mach_mips9000
, bfd_mach_mips8000
},
12193 /* VR4100 extensions. */
12194 { bfd_mach_mips4120
, bfd_mach_mips4100
},
12195 { bfd_mach_mips4111
, bfd_mach_mips4100
},
12197 /* MIPS III extensions. */
12198 { bfd_mach_mips_loongson_2e
, bfd_mach_mips4000
},
12199 { bfd_mach_mips_loongson_2f
, bfd_mach_mips4000
},
12200 { bfd_mach_mips8000
, bfd_mach_mips4000
},
12201 { bfd_mach_mips4650
, bfd_mach_mips4000
},
12202 { bfd_mach_mips4600
, bfd_mach_mips4000
},
12203 { bfd_mach_mips4400
, bfd_mach_mips4000
},
12204 { bfd_mach_mips4300
, bfd_mach_mips4000
},
12205 { bfd_mach_mips4100
, bfd_mach_mips4000
},
12206 { bfd_mach_mips4010
, bfd_mach_mips4000
},
12208 /* MIPS32 extensions. */
12209 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
12211 /* MIPS II extensions. */
12212 { bfd_mach_mips4000
, bfd_mach_mips6000
},
12213 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
12215 /* MIPS I extensions. */
12216 { bfd_mach_mips6000
, bfd_mach_mips3000
},
12217 { bfd_mach_mips3900
, bfd_mach_mips3000
}
12221 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
12224 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
12228 if (extension
== base
)
12231 if (base
== bfd_mach_mipsisa32
12232 && mips_mach_extends_p (bfd_mach_mipsisa64
, extension
))
12235 if (base
== bfd_mach_mipsisa32r2
12236 && mips_mach_extends_p (bfd_mach_mipsisa64r2
, extension
))
12239 for (i
= 0; i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
12240 if (extension
== mips_mach_extensions
[i
].extension
)
12242 extension
= mips_mach_extensions
[i
].base
;
12243 if (extension
== base
)
12251 /* Return true if the given ELF header flags describe a 32-bit binary. */
12254 mips_32bit_flags_p (flagword flags
)
12256 return ((flags
& EF_MIPS_32BITMODE
) != 0
12257 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
12258 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
12259 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
12260 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
12261 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
12262 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
);
12266 /* Merge object attributes from IBFD into OBFD. Raise an error if
12267 there are conflicting attributes. */
12269 mips_elf_merge_obj_attributes (bfd
*ibfd
, bfd
*obfd
)
12271 obj_attribute
*in_attr
;
12272 obj_attribute
*out_attr
;
12274 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
12276 /* This is the first object. Copy the attributes. */
12277 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
12279 /* Use the Tag_null value to indicate the attributes have been
12281 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
12286 /* Check for conflicting Tag_GNU_MIPS_ABI_FP attributes and merge
12287 non-conflicting ones. */
12288 in_attr
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
12289 out_attr
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
12290 if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12292 out_attr
[Tag_GNU_MIPS_ABI_FP
].type
= 1;
12293 if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
12294 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
12295 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
12297 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
12299 (_("Warning: %B uses unknown floating point ABI %d"), ibfd
,
12300 in_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
12301 else if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
12303 (_("Warning: %B uses unknown floating point ABI %d"), obfd
,
12304 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
12306 switch (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12309 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12313 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
12319 (_("Warning: %B uses hard float, %B uses soft float"),
12325 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
12335 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12339 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
12345 (_("Warning: %B uses hard float, %B uses soft float"),
12351 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
12361 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12367 (_("Warning: %B uses hard float, %B uses soft float"),
12377 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12381 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
12387 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
12393 (_("Warning: %B uses hard float, %B uses soft float"),
12407 /* Merge Tag_compatibility attributes and any common GNU ones. */
12408 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
12413 /* Merge backend specific data from an object file to the output
12414 object file when linking. */
12417 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
12419 flagword old_flags
;
12420 flagword new_flags
;
12422 bfd_boolean null_input_bfd
= TRUE
;
12425 /* Check if we have the same endianess */
12426 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
12428 (*_bfd_error_handler
)
12429 (_("%B: endianness incompatible with that of the selected emulation"),
12434 if (!is_mips_elf (ibfd
) || !is_mips_elf (obfd
))
12437 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
12439 (*_bfd_error_handler
)
12440 (_("%B: ABI is incompatible with that of the selected emulation"),
12445 if (!mips_elf_merge_obj_attributes (ibfd
, obfd
))
12448 new_flags
= elf_elfheader (ibfd
)->e_flags
;
12449 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
12450 old_flags
= elf_elfheader (obfd
)->e_flags
;
12452 if (! elf_flags_init (obfd
))
12454 elf_flags_init (obfd
) = TRUE
;
12455 elf_elfheader (obfd
)->e_flags
= new_flags
;
12456 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
12457 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
12459 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
12460 && (bfd_get_arch_info (obfd
)->the_default
12461 || mips_mach_extends_p (bfd_get_mach (obfd
),
12462 bfd_get_mach (ibfd
))))
12464 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
12465 bfd_get_mach (ibfd
)))
12472 /* Check flag compatibility. */
12474 new_flags
&= ~EF_MIPS_NOREORDER
;
12475 old_flags
&= ~EF_MIPS_NOREORDER
;
12477 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
12478 doesn't seem to matter. */
12479 new_flags
&= ~EF_MIPS_XGOT
;
12480 old_flags
&= ~EF_MIPS_XGOT
;
12482 /* MIPSpro generates ucode info in n64 objects. Again, we should
12483 just be able to ignore this. */
12484 new_flags
&= ~EF_MIPS_UCODE
;
12485 old_flags
&= ~EF_MIPS_UCODE
;
12487 /* DSOs should only be linked with CPIC code. */
12488 if ((ibfd
->flags
& DYNAMIC
) != 0)
12489 new_flags
|= EF_MIPS_PIC
| EF_MIPS_CPIC
;
12491 if (new_flags
== old_flags
)
12494 /* Check to see if the input BFD actually contains any sections.
12495 If not, its flags may not have been initialised either, but it cannot
12496 actually cause any incompatibility. */
12497 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
12499 /* Ignore synthetic sections and empty .text, .data and .bss sections
12500 which are automatically generated by gas. */
12501 if (strcmp (sec
->name
, ".reginfo")
12502 && strcmp (sec
->name
, ".mdebug")
12504 || (strcmp (sec
->name
, ".text")
12505 && strcmp (sec
->name
, ".data")
12506 && strcmp (sec
->name
, ".bss"))))
12508 null_input_bfd
= FALSE
;
12512 if (null_input_bfd
)
12517 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
12518 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
12520 (*_bfd_error_handler
)
12521 (_("%B: warning: linking abicalls files with non-abicalls files"),
12526 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
12527 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
12528 if (! (new_flags
& EF_MIPS_PIC
))
12529 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
12531 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
12532 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
12534 /* Compare the ISAs. */
12535 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
12537 (*_bfd_error_handler
)
12538 (_("%B: linking 32-bit code with 64-bit code"),
12542 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
12544 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
12545 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
12547 /* Copy the architecture info from IBFD to OBFD. Also copy
12548 the 32-bit flag (if set) so that we continue to recognise
12549 OBFD as a 32-bit binary. */
12550 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
12551 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
12552 elf_elfheader (obfd
)->e_flags
12553 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
12555 /* Copy across the ABI flags if OBFD doesn't use them
12556 and if that was what caused us to treat IBFD as 32-bit. */
12557 if ((old_flags
& EF_MIPS_ABI
) == 0
12558 && mips_32bit_flags_p (new_flags
)
12559 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
12560 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
12564 /* The ISAs aren't compatible. */
12565 (*_bfd_error_handler
)
12566 (_("%B: linking %s module with previous %s modules"),
12568 bfd_printable_name (ibfd
),
12569 bfd_printable_name (obfd
));
12574 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
12575 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
12577 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
12578 does set EI_CLASS differently from any 32-bit ABI. */
12579 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
12580 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
12581 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
12583 /* Only error if both are set (to different values). */
12584 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
12585 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
12586 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
12588 (*_bfd_error_handler
)
12589 (_("%B: ABI mismatch: linking %s module with previous %s modules"),
12591 elf_mips_abi_name (ibfd
),
12592 elf_mips_abi_name (obfd
));
12595 new_flags
&= ~EF_MIPS_ABI
;
12596 old_flags
&= ~EF_MIPS_ABI
;
12599 /* For now, allow arbitrary mixing of ASEs (retain the union). */
12600 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
12602 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
12604 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
12605 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
12608 /* Warn about any other mismatches */
12609 if (new_flags
!= old_flags
)
12611 (*_bfd_error_handler
)
12612 (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
12613 ibfd
, (unsigned long) new_flags
,
12614 (unsigned long) old_flags
);
12620 bfd_set_error (bfd_error_bad_value
);
12627 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
12630 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
12632 BFD_ASSERT (!elf_flags_init (abfd
)
12633 || elf_elfheader (abfd
)->e_flags
== flags
);
12635 elf_elfheader (abfd
)->e_flags
= flags
;
12636 elf_flags_init (abfd
) = TRUE
;
12641 _bfd_mips_elf_get_target_dtag (bfd_vma dtag
)
12645 default: return "";
12646 case DT_MIPS_RLD_VERSION
:
12647 return "MIPS_RLD_VERSION";
12648 case DT_MIPS_TIME_STAMP
:
12649 return "MIPS_TIME_STAMP";
12650 case DT_MIPS_ICHECKSUM
:
12651 return "MIPS_ICHECKSUM";
12652 case DT_MIPS_IVERSION
:
12653 return "MIPS_IVERSION";
12654 case DT_MIPS_FLAGS
:
12655 return "MIPS_FLAGS";
12656 case DT_MIPS_BASE_ADDRESS
:
12657 return "MIPS_BASE_ADDRESS";
12659 return "MIPS_MSYM";
12660 case DT_MIPS_CONFLICT
:
12661 return "MIPS_CONFLICT";
12662 case DT_MIPS_LIBLIST
:
12663 return "MIPS_LIBLIST";
12664 case DT_MIPS_LOCAL_GOTNO
:
12665 return "MIPS_LOCAL_GOTNO";
12666 case DT_MIPS_CONFLICTNO
:
12667 return "MIPS_CONFLICTNO";
12668 case DT_MIPS_LIBLISTNO
:
12669 return "MIPS_LIBLISTNO";
12670 case DT_MIPS_SYMTABNO
:
12671 return "MIPS_SYMTABNO";
12672 case DT_MIPS_UNREFEXTNO
:
12673 return "MIPS_UNREFEXTNO";
12674 case DT_MIPS_GOTSYM
:
12675 return "MIPS_GOTSYM";
12676 case DT_MIPS_HIPAGENO
:
12677 return "MIPS_HIPAGENO";
12678 case DT_MIPS_RLD_MAP
:
12679 return "MIPS_RLD_MAP";
12680 case DT_MIPS_DELTA_CLASS
:
12681 return "MIPS_DELTA_CLASS";
12682 case DT_MIPS_DELTA_CLASS_NO
:
12683 return "MIPS_DELTA_CLASS_NO";
12684 case DT_MIPS_DELTA_INSTANCE
:
12685 return "MIPS_DELTA_INSTANCE";
12686 case DT_MIPS_DELTA_INSTANCE_NO
:
12687 return "MIPS_DELTA_INSTANCE_NO";
12688 case DT_MIPS_DELTA_RELOC
:
12689 return "MIPS_DELTA_RELOC";
12690 case DT_MIPS_DELTA_RELOC_NO
:
12691 return "MIPS_DELTA_RELOC_NO";
12692 case DT_MIPS_DELTA_SYM
:
12693 return "MIPS_DELTA_SYM";
12694 case DT_MIPS_DELTA_SYM_NO
:
12695 return "MIPS_DELTA_SYM_NO";
12696 case DT_MIPS_DELTA_CLASSSYM
:
12697 return "MIPS_DELTA_CLASSSYM";
12698 case DT_MIPS_DELTA_CLASSSYM_NO
:
12699 return "MIPS_DELTA_CLASSSYM_NO";
12700 case DT_MIPS_CXX_FLAGS
:
12701 return "MIPS_CXX_FLAGS";
12702 case DT_MIPS_PIXIE_INIT
:
12703 return "MIPS_PIXIE_INIT";
12704 case DT_MIPS_SYMBOL_LIB
:
12705 return "MIPS_SYMBOL_LIB";
12706 case DT_MIPS_LOCALPAGE_GOTIDX
:
12707 return "MIPS_LOCALPAGE_GOTIDX";
12708 case DT_MIPS_LOCAL_GOTIDX
:
12709 return "MIPS_LOCAL_GOTIDX";
12710 case DT_MIPS_HIDDEN_GOTIDX
:
12711 return "MIPS_HIDDEN_GOTIDX";
12712 case DT_MIPS_PROTECTED_GOTIDX
:
12713 return "MIPS_PROTECTED_GOT_IDX";
12714 case DT_MIPS_OPTIONS
:
12715 return "MIPS_OPTIONS";
12716 case DT_MIPS_INTERFACE
:
12717 return "MIPS_INTERFACE";
12718 case DT_MIPS_DYNSTR_ALIGN
:
12719 return "DT_MIPS_DYNSTR_ALIGN";
12720 case DT_MIPS_INTERFACE_SIZE
:
12721 return "DT_MIPS_INTERFACE_SIZE";
12722 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
:
12723 return "DT_MIPS_RLD_TEXT_RESOLVE_ADDR";
12724 case DT_MIPS_PERF_SUFFIX
:
12725 return "DT_MIPS_PERF_SUFFIX";
12726 case DT_MIPS_COMPACT_SIZE
:
12727 return "DT_MIPS_COMPACT_SIZE";
12728 case DT_MIPS_GP_VALUE
:
12729 return "DT_MIPS_GP_VALUE";
12730 case DT_MIPS_AUX_DYNAMIC
:
12731 return "DT_MIPS_AUX_DYNAMIC";
12732 case DT_MIPS_PLTGOT
:
12733 return "DT_MIPS_PLTGOT";
12734 case DT_MIPS_RWPLT
:
12735 return "DT_MIPS_RWPLT";
12740 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
12744 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
12746 /* Print normal ELF private data. */
12747 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
12749 /* xgettext:c-format */
12750 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
12752 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
12753 fprintf (file
, _(" [abi=O32]"));
12754 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
12755 fprintf (file
, _(" [abi=O64]"));
12756 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
12757 fprintf (file
, _(" [abi=EABI32]"));
12758 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
12759 fprintf (file
, _(" [abi=EABI64]"));
12760 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
12761 fprintf (file
, _(" [abi unknown]"));
12762 else if (ABI_N32_P (abfd
))
12763 fprintf (file
, _(" [abi=N32]"));
12764 else if (ABI_64_P (abfd
))
12765 fprintf (file
, _(" [abi=64]"));
12767 fprintf (file
, _(" [no abi set]"));
12769 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
12770 fprintf (file
, " [mips1]");
12771 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
12772 fprintf (file
, " [mips2]");
12773 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
12774 fprintf (file
, " [mips3]");
12775 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
12776 fprintf (file
, " [mips4]");
12777 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
12778 fprintf (file
, " [mips5]");
12779 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
12780 fprintf (file
, " [mips32]");
12781 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
12782 fprintf (file
, " [mips64]");
12783 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
12784 fprintf (file
, " [mips32r2]");
12785 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
12786 fprintf (file
, " [mips64r2]");
12788 fprintf (file
, _(" [unknown ISA]"));
12790 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
12791 fprintf (file
, " [mdmx]");
12793 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
12794 fprintf (file
, " [mips16]");
12796 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
12797 fprintf (file
, " [32bitmode]");
12799 fprintf (file
, _(" [not 32bitmode]"));
12801 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NOREORDER
)
12802 fprintf (file
, " [noreorder]");
12804 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
12805 fprintf (file
, " [PIC]");
12807 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_CPIC
)
12808 fprintf (file
, " [CPIC]");
12810 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_XGOT
)
12811 fprintf (file
, " [XGOT]");
12813 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_UCODE
)
12814 fprintf (file
, " [UCODE]");
12816 fputc ('\n', file
);
12821 const struct bfd_elf_special_section _bfd_mips_elf_special_sections
[] =
12823 { STRING_COMMA_LEN (".lit4"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12824 { STRING_COMMA_LEN (".lit8"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12825 { STRING_COMMA_LEN (".mdebug"), 0, SHT_MIPS_DEBUG
, 0 },
12826 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12827 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12828 { STRING_COMMA_LEN (".ucode"), 0, SHT_MIPS_UCODE
, 0 },
12829 { NULL
, 0, 0, 0, 0 }
12832 /* Merge non visibility st_other attributes. Ensure that the
12833 STO_OPTIONAL flag is copied into h->other, even if this is not a
12834 definiton of the symbol. */
12836 _bfd_mips_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
12837 const Elf_Internal_Sym
*isym
,
12838 bfd_boolean definition
,
12839 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
12841 if ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1)) != 0)
12843 unsigned char other
;
12845 other
= (definition
? isym
->st_other
: h
->other
);
12846 other
&= ~ELF_ST_VISIBILITY (-1);
12847 h
->other
= other
| ELF_ST_VISIBILITY (h
->other
);
12851 && ELF_MIPS_IS_OPTIONAL (isym
->st_other
))
12852 h
->other
|= STO_OPTIONAL
;
12855 /* Decide whether an undefined symbol is special and can be ignored.
12856 This is the case for OPTIONAL symbols on IRIX. */
12858 _bfd_mips_elf_ignore_undef_symbol (struct elf_link_hash_entry
*h
)
12860 return ELF_MIPS_IS_OPTIONAL (h
->other
) ? TRUE
: FALSE
;
12864 _bfd_mips_elf_common_definition (Elf_Internal_Sym
*sym
)
12866 return (sym
->st_shndx
== SHN_COMMON
12867 || sym
->st_shndx
== SHN_MIPS_ACOMMON
12868 || sym
->st_shndx
== SHN_MIPS_SCOMMON
);
12871 /* Return address for Ith PLT stub in section PLT, for relocation REL
12872 or (bfd_vma) -1 if it should not be included. */
12875 _bfd_mips_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
12876 const arelent
*rel ATTRIBUTE_UNUSED
)
12879 + 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
)
12880 + i
* 4 * ARRAY_SIZE (mips_exec_plt_entry
));
12884 _bfd_mips_post_process_headers (bfd
*abfd
, struct bfd_link_info
*link_info
)
12886 struct mips_elf_link_hash_table
*htab
;
12887 Elf_Internal_Ehdr
*i_ehdrp
;
12889 i_ehdrp
= elf_elfheader (abfd
);
12892 htab
= mips_elf_hash_table (link_info
);
12893 if (htab
->use_plts_and_copy_relocs
&& !htab
->is_vxworks
)
12894 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 1;