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 a PIC object. */
666 #define PIC_OBJECT_P(abfd) \
667 ((elf_elfheader (abfd)->e_flags & EF_MIPS_PIC) != 0)
669 /* Nonzero if ABFD is using the N32 ABI. */
670 #define ABI_N32_P(abfd) \
671 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0)
673 /* Nonzero if ABFD is using the N64 ABI. */
674 #define ABI_64_P(abfd) \
675 (get_elf_backend_data (abfd)->s->elfclass == ELFCLASS64)
677 /* Nonzero if ABFD is using NewABI conventions. */
678 #define NEWABI_P(abfd) (ABI_N32_P (abfd) || ABI_64_P (abfd))
680 /* The IRIX compatibility level we are striving for. */
681 #define IRIX_COMPAT(abfd) \
682 (get_elf_backend_data (abfd)->elf_backend_mips_irix_compat (abfd))
684 /* Whether we are trying to be compatible with IRIX at all. */
685 #define SGI_COMPAT(abfd) \
686 (IRIX_COMPAT (abfd) != ict_none)
688 /* The name of the options section. */
689 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \
690 (NEWABI_P (abfd) ? ".MIPS.options" : ".options")
692 /* True if NAME is the recognized name of any SHT_MIPS_OPTIONS section.
693 Some IRIX system files do not use MIPS_ELF_OPTIONS_SECTION_NAME. */
694 #define MIPS_ELF_OPTIONS_SECTION_NAME_P(NAME) \
695 (strcmp (NAME, ".MIPS.options") == 0 || strcmp (NAME, ".options") == 0)
697 /* Whether the section is readonly. */
698 #define MIPS_ELF_READONLY_SECTION(sec) \
699 ((sec->flags & (SEC_ALLOC | SEC_LOAD | SEC_READONLY)) \
700 == (SEC_ALLOC | SEC_LOAD | SEC_READONLY))
702 /* The name of the stub section. */
703 #define MIPS_ELF_STUB_SECTION_NAME(abfd) ".MIPS.stubs"
705 /* The size of an external REL relocation. */
706 #define MIPS_ELF_REL_SIZE(abfd) \
707 (get_elf_backend_data (abfd)->s->sizeof_rel)
709 /* The size of an external RELA relocation. */
710 #define MIPS_ELF_RELA_SIZE(abfd) \
711 (get_elf_backend_data (abfd)->s->sizeof_rela)
713 /* The size of an external dynamic table entry. */
714 #define MIPS_ELF_DYN_SIZE(abfd) \
715 (get_elf_backend_data (abfd)->s->sizeof_dyn)
717 /* The size of a GOT entry. */
718 #define MIPS_ELF_GOT_SIZE(abfd) \
719 (get_elf_backend_data (abfd)->s->arch_size / 8)
721 /* The size of a symbol-table entry. */
722 #define MIPS_ELF_SYM_SIZE(abfd) \
723 (get_elf_backend_data (abfd)->s->sizeof_sym)
725 /* The default alignment for sections, as a power of two. */
726 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \
727 (get_elf_backend_data (abfd)->s->log_file_align)
729 /* Get word-sized data. */
730 #define MIPS_ELF_GET_WORD(abfd, ptr) \
731 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr))
733 /* Put out word-sized data. */
734 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \
736 ? bfd_put_64 (abfd, val, ptr) \
737 : bfd_put_32 (abfd, val, ptr))
739 /* The opcode for word-sized loads (LW or LD). */
740 #define MIPS_ELF_LOAD_WORD(abfd) \
741 (ABI_64_P (abfd) ? 0xdc000000 : 0x8c000000)
743 /* Add a dynamic symbol table-entry. */
744 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \
745 _bfd_elf_add_dynamic_entry (info, tag, val)
747 #define MIPS_ELF_RTYPE_TO_HOWTO(abfd, rtype, rela) \
748 (get_elf_backend_data (abfd)->elf_backend_mips_rtype_to_howto (rtype, rela))
750 /* Determine whether the internal relocation of index REL_IDX is REL
751 (zero) or RELA (non-zero). The assumption is that, if there are
752 two relocation sections for this section, one of them is REL and
753 the other is RELA. If the index of the relocation we're testing is
754 in range for the first relocation section, check that the external
755 relocation size is that for RELA. It is also assumed that, if
756 rel_idx is not in range for the first section, and this first
757 section contains REL relocs, then the relocation is in the second
758 section, that is RELA. */
759 #define MIPS_RELOC_RELA_P(abfd, sec, rel_idx) \
760 ((NUM_SHDR_ENTRIES (&elf_section_data (sec)->rel_hdr) \
761 * get_elf_backend_data (abfd)->s->int_rels_per_ext_rel \
762 > (bfd_vma)(rel_idx)) \
763 == (elf_section_data (sec)->rel_hdr.sh_entsize \
764 == (ABI_64_P (abfd) ? sizeof (Elf64_External_Rela) \
765 : sizeof (Elf32_External_Rela))))
767 /* The name of the dynamic relocation section. */
768 #define MIPS_ELF_REL_DYN_NAME(INFO) \
769 (mips_elf_hash_table (INFO)->is_vxworks ? ".rela.dyn" : ".rel.dyn")
771 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value
772 from smaller values. Start with zero, widen, *then* decrement. */
773 #define MINUS_ONE (((bfd_vma)0) - 1)
774 #define MINUS_TWO (((bfd_vma)0) - 2)
776 /* The value to write into got[1] for SVR4 targets, to identify it is
777 a GNU object. The dynamic linker can then use got[1] to store the
779 #define MIPS_ELF_GNU_GOT1_MASK(abfd) \
780 ((bfd_vma) 1 << (ABI_64_P (abfd) ? 63 : 31))
782 /* The offset of $gp from the beginning of the .got section. */
783 #define ELF_MIPS_GP_OFFSET(INFO) \
784 (mips_elf_hash_table (INFO)->is_vxworks ? 0x0 : 0x7ff0)
786 /* The maximum size of the GOT for it to be addressable using 16-bit
788 #define MIPS_ELF_GOT_MAX_SIZE(INFO) (ELF_MIPS_GP_OFFSET (INFO) + 0x7fff)
790 /* Instructions which appear in a stub. */
791 #define STUB_LW(abfd) \
793 ? 0xdf998010 /* ld t9,0x8010(gp) */ \
794 : 0x8f998010)) /* lw t9,0x8010(gp) */
795 #define STUB_MOVE(abfd) \
797 ? 0x03e0782d /* daddu t7,ra */ \
798 : 0x03e07821)) /* addu t7,ra */
799 #define STUB_LUI(VAL) (0x3c180000 + (VAL)) /* lui t8,VAL */
800 #define STUB_JALR 0x0320f809 /* jalr t9,ra */
801 #define STUB_ORI(VAL) (0x37180000 + (VAL)) /* ori t8,t8,VAL */
802 #define STUB_LI16U(VAL) (0x34180000 + (VAL)) /* ori t8,zero,VAL unsigned */
803 #define STUB_LI16S(abfd, VAL) \
805 ? (0x64180000 + (VAL)) /* daddiu t8,zero,VAL sign extended */ \
806 : (0x24180000 + (VAL)))) /* addiu t8,zero,VAL sign extended */
808 #define MIPS_FUNCTION_STUB_NORMAL_SIZE 16
809 #define MIPS_FUNCTION_STUB_BIG_SIZE 20
811 /* The name of the dynamic interpreter. This is put in the .interp
814 #define ELF_DYNAMIC_INTERPRETER(abfd) \
815 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \
816 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \
817 : "/usr/lib/libc.so.1")
820 #define MNAME(bfd,pre,pos) \
821 (ABI_64_P (bfd) ? CONCAT4 (pre,64,_,pos) : CONCAT4 (pre,32,_,pos))
822 #define ELF_R_SYM(bfd, i) \
823 (ABI_64_P (bfd) ? ELF64_R_SYM (i) : ELF32_R_SYM (i))
824 #define ELF_R_TYPE(bfd, i) \
825 (ABI_64_P (bfd) ? ELF64_MIPS_R_TYPE (i) : ELF32_R_TYPE (i))
826 #define ELF_R_INFO(bfd, s, t) \
827 (ABI_64_P (bfd) ? ELF64_R_INFO (s, t) : ELF32_R_INFO (s, t))
829 #define MNAME(bfd,pre,pos) CONCAT4 (pre,32,_,pos)
830 #define ELF_R_SYM(bfd, i) \
832 #define ELF_R_TYPE(bfd, i) \
834 #define ELF_R_INFO(bfd, s, t) \
835 (ELF32_R_INFO (s, t))
838 /* The mips16 compiler uses a couple of special sections to handle
839 floating point arguments.
841 Section names that look like .mips16.fn.FNNAME contain stubs that
842 copy floating point arguments from the fp regs to the gp regs and
843 then jump to FNNAME. If any 32 bit function calls FNNAME, the
844 call should be redirected to the stub instead. If no 32 bit
845 function calls FNNAME, the stub should be discarded. We need to
846 consider any reference to the function, not just a call, because
847 if the address of the function is taken we will need the stub,
848 since the address might be passed to a 32 bit function.
850 Section names that look like .mips16.call.FNNAME contain stubs
851 that copy floating point arguments from the gp regs to the fp
852 regs and then jump to FNNAME. If FNNAME is a 32 bit function,
853 then any 16 bit function that calls FNNAME should be redirected
854 to the stub instead. If FNNAME is not a 32 bit function, the
855 stub should be discarded.
857 .mips16.call.fp.FNNAME sections are similar, but contain stubs
858 which call FNNAME and then copy the return value from the fp regs
859 to the gp regs. These stubs store the return value in $18 while
860 calling FNNAME; any function which might call one of these stubs
861 must arrange to save $18 around the call. (This case is not
862 needed for 32 bit functions that call 16 bit functions, because
863 16 bit functions always return floating point values in both
866 Note that in all cases FNNAME might be defined statically.
867 Therefore, FNNAME is not used literally. Instead, the relocation
868 information will indicate which symbol the section is for.
870 We record any stubs that we find in the symbol table. */
872 #define FN_STUB ".mips16.fn."
873 #define CALL_STUB ".mips16.call."
874 #define CALL_FP_STUB ".mips16.call.fp."
876 #define FN_STUB_P(name) CONST_STRNEQ (name, FN_STUB)
877 #define CALL_STUB_P(name) CONST_STRNEQ (name, CALL_STUB)
878 #define CALL_FP_STUB_P(name) CONST_STRNEQ (name, CALL_FP_STUB)
880 /* The format of the first PLT entry in an O32 executable. */
881 static const bfd_vma mips_o32_exec_plt0_entry
[] = {
882 0x3c1c0000, /* lui $28, %hi(&GOTPLT[0]) */
883 0x8f990000, /* lw $25, %lo(&GOTPLT[0])($28) */
884 0x279c0000, /* addiu $28, $28, %lo(&GOTPLT[0]) */
885 0x031cc023, /* subu $24, $24, $28 */
886 0x03e07821, /* move $15, $31 */
887 0x0018c082, /* srl $24, $24, 2 */
888 0x0320f809, /* jalr $25 */
889 0x2718fffe /* subu $24, $24, 2 */
892 /* The format of the first PLT entry in an N32 executable. Different
893 because gp ($28) is not available; we use t2 ($14) instead. */
894 static const bfd_vma mips_n32_exec_plt0_entry
[] = {
895 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
896 0x8dd90000, /* lw $25, %lo(&GOTPLT[0])($14) */
897 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
898 0x030ec023, /* subu $24, $24, $14 */
899 0x03e07821, /* move $15, $31 */
900 0x0018c082, /* srl $24, $24, 2 */
901 0x0320f809, /* jalr $25 */
902 0x2718fffe /* subu $24, $24, 2 */
905 /* The format of the first PLT entry in an N64 executable. Different
906 from N32 because of the increased size of GOT entries. */
907 static const bfd_vma mips_n64_exec_plt0_entry
[] = {
908 0x3c0e0000, /* lui $14, %hi(&GOTPLT[0]) */
909 0xddd90000, /* ld $25, %lo(&GOTPLT[0])($14) */
910 0x25ce0000, /* addiu $14, $14, %lo(&GOTPLT[0]) */
911 0x030ec023, /* subu $24, $24, $14 */
912 0x03e07821, /* move $15, $31 */
913 0x0018c0c2, /* srl $24, $24, 3 */
914 0x0320f809, /* jalr $25 */
915 0x2718fffe /* subu $24, $24, 2 */
918 /* The format of subsequent PLT entries. */
919 static const bfd_vma mips_exec_plt_entry
[] = {
920 0x3c0f0000, /* lui $15, %hi(.got.plt entry) */
921 0x01f90000, /* l[wd] $25, %lo(.got.plt entry)($15) */
922 0x25f80000, /* addiu $24, $15, %lo(.got.plt entry) */
923 0x03200008 /* jr $25 */
926 /* The format of the first PLT entry in a VxWorks executable. */
927 static const bfd_vma mips_vxworks_exec_plt0_entry
[] = {
928 0x3c190000, /* lui t9, %hi(_GLOBAL_OFFSET_TABLE_) */
929 0x27390000, /* addiu t9, t9, %lo(_GLOBAL_OFFSET_TABLE_) */
930 0x8f390008, /* lw t9, 8(t9) */
931 0x00000000, /* nop */
932 0x03200008, /* jr t9 */
936 /* The format of subsequent PLT entries. */
937 static const bfd_vma mips_vxworks_exec_plt_entry
[] = {
938 0x10000000, /* b .PLT_resolver */
939 0x24180000, /* li t8, <pltindex> */
940 0x3c190000, /* lui t9, %hi(<.got.plt slot>) */
941 0x27390000, /* addiu t9, t9, %lo(<.got.plt slot>) */
942 0x8f390000, /* lw t9, 0(t9) */
943 0x00000000, /* nop */
944 0x03200008, /* jr t9 */
948 /* The format of the first PLT entry in a VxWorks shared object. */
949 static const bfd_vma mips_vxworks_shared_plt0_entry
[] = {
950 0x8f990008, /* lw t9, 8(gp) */
951 0x00000000, /* nop */
952 0x03200008, /* jr t9 */
953 0x00000000, /* nop */
954 0x00000000, /* nop */
958 /* The format of subsequent PLT entries. */
959 static const bfd_vma mips_vxworks_shared_plt_entry
[] = {
960 0x10000000, /* b .PLT_resolver */
961 0x24180000 /* li t8, <pltindex> */
964 /* Look up an entry in a MIPS ELF linker hash table. */
966 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \
967 ((struct mips_elf_link_hash_entry *) \
968 elf_link_hash_lookup (&(table)->root, (string), (create), \
971 /* Traverse a MIPS ELF linker hash table. */
973 #define mips_elf_link_hash_traverse(table, func, info) \
974 (elf_link_hash_traverse \
976 (bfd_boolean (*) (struct elf_link_hash_entry *, void *)) (func), \
979 /* Get the MIPS ELF linker hash table from a link_info structure. */
981 #define mips_elf_hash_table(p) \
982 ((struct mips_elf_link_hash_table *) ((p)->hash))
984 /* Find the base offsets for thread-local storage in this object,
985 for GD/LD and IE/LE respectively. */
987 #define TP_OFFSET 0x7000
988 #define DTP_OFFSET 0x8000
991 dtprel_base (struct bfd_link_info
*info
)
993 /* If tls_sec is NULL, we should have signalled an error already. */
994 if (elf_hash_table (info
)->tls_sec
== NULL
)
996 return elf_hash_table (info
)->tls_sec
->vma
+ DTP_OFFSET
;
1000 tprel_base (struct bfd_link_info
*info
)
1002 /* If tls_sec is NULL, we should have signalled an error already. */
1003 if (elf_hash_table (info
)->tls_sec
== NULL
)
1005 return elf_hash_table (info
)->tls_sec
->vma
+ TP_OFFSET
;
1008 /* Create an entry in a MIPS ELF linker hash table. */
1010 static struct bfd_hash_entry
*
1011 mips_elf_link_hash_newfunc (struct bfd_hash_entry
*entry
,
1012 struct bfd_hash_table
*table
, const char *string
)
1014 struct mips_elf_link_hash_entry
*ret
=
1015 (struct mips_elf_link_hash_entry
*) entry
;
1017 /* Allocate the structure if it has not already been allocated by a
1020 ret
= bfd_hash_allocate (table
, sizeof (struct mips_elf_link_hash_entry
));
1022 return (struct bfd_hash_entry
*) ret
;
1024 /* Call the allocation method of the superclass. */
1025 ret
= ((struct mips_elf_link_hash_entry
*)
1026 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
1030 /* Set local fields. */
1031 memset (&ret
->esym
, 0, sizeof (EXTR
));
1032 /* We use -2 as a marker to indicate that the information has
1033 not been set. -1 means there is no associated ifd. */
1036 ret
->possibly_dynamic_relocs
= 0;
1037 ret
->fn_stub
= NULL
;
1038 ret
->call_stub
= NULL
;
1039 ret
->call_fp_stub
= NULL
;
1040 ret
->tls_type
= GOT_NORMAL
;
1041 ret
->global_got_area
= GGA_NONE
;
1042 ret
->readonly_reloc
= FALSE
;
1043 ret
->has_static_relocs
= FALSE
;
1044 ret
->no_fn_stub
= FALSE
;
1045 ret
->need_fn_stub
= FALSE
;
1046 ret
->has_nonpic_branches
= FALSE
;
1047 ret
->needs_lazy_stub
= FALSE
;
1050 return (struct bfd_hash_entry
*) ret
;
1054 _bfd_mips_elf_new_section_hook (bfd
*abfd
, asection
*sec
)
1056 if (!sec
->used_by_bfd
)
1058 struct _mips_elf_section_data
*sdata
;
1059 bfd_size_type amt
= sizeof (*sdata
);
1061 sdata
= bfd_zalloc (abfd
, amt
);
1064 sec
->used_by_bfd
= sdata
;
1067 return _bfd_elf_new_section_hook (abfd
, sec
);
1070 /* Read ECOFF debugging information from a .mdebug section into a
1071 ecoff_debug_info structure. */
1074 _bfd_mips_elf_read_ecoff_info (bfd
*abfd
, asection
*section
,
1075 struct ecoff_debug_info
*debug
)
1078 const struct ecoff_debug_swap
*swap
;
1081 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1082 memset (debug
, 0, sizeof (*debug
));
1084 ext_hdr
= bfd_malloc (swap
->external_hdr_size
);
1085 if (ext_hdr
== NULL
&& swap
->external_hdr_size
!= 0)
1088 if (! bfd_get_section_contents (abfd
, section
, ext_hdr
, 0,
1089 swap
->external_hdr_size
))
1092 symhdr
= &debug
->symbolic_header
;
1093 (*swap
->swap_hdr_in
) (abfd
, ext_hdr
, symhdr
);
1095 /* The symbolic header contains absolute file offsets and sizes to
1097 #define READ(ptr, offset, count, size, type) \
1098 if (symhdr->count == 0) \
1099 debug->ptr = NULL; \
1102 bfd_size_type amt = (bfd_size_type) size * symhdr->count; \
1103 debug->ptr = bfd_malloc (amt); \
1104 if (debug->ptr == NULL) \
1105 goto error_return; \
1106 if (bfd_seek (abfd, symhdr->offset, SEEK_SET) != 0 \
1107 || bfd_bread (debug->ptr, amt, abfd) != amt) \
1108 goto error_return; \
1111 READ (line
, cbLineOffset
, cbLine
, sizeof (unsigned char), unsigned char *);
1112 READ (external_dnr
, cbDnOffset
, idnMax
, swap
->external_dnr_size
, void *);
1113 READ (external_pdr
, cbPdOffset
, ipdMax
, swap
->external_pdr_size
, void *);
1114 READ (external_sym
, cbSymOffset
, isymMax
, swap
->external_sym_size
, void *);
1115 READ (external_opt
, cbOptOffset
, ioptMax
, swap
->external_opt_size
, void *);
1116 READ (external_aux
, cbAuxOffset
, iauxMax
, sizeof (union aux_ext
),
1118 READ (ss
, cbSsOffset
, issMax
, sizeof (char), char *);
1119 READ (ssext
, cbSsExtOffset
, issExtMax
, sizeof (char), char *);
1120 READ (external_fdr
, cbFdOffset
, ifdMax
, swap
->external_fdr_size
, void *);
1121 READ (external_rfd
, cbRfdOffset
, crfd
, swap
->external_rfd_size
, void *);
1122 READ (external_ext
, cbExtOffset
, iextMax
, swap
->external_ext_size
, void *);
1130 if (ext_hdr
!= NULL
)
1132 if (debug
->line
!= NULL
)
1134 if (debug
->external_dnr
!= NULL
)
1135 free (debug
->external_dnr
);
1136 if (debug
->external_pdr
!= NULL
)
1137 free (debug
->external_pdr
);
1138 if (debug
->external_sym
!= NULL
)
1139 free (debug
->external_sym
);
1140 if (debug
->external_opt
!= NULL
)
1141 free (debug
->external_opt
);
1142 if (debug
->external_aux
!= NULL
)
1143 free (debug
->external_aux
);
1144 if (debug
->ss
!= NULL
)
1146 if (debug
->ssext
!= NULL
)
1147 free (debug
->ssext
);
1148 if (debug
->external_fdr
!= NULL
)
1149 free (debug
->external_fdr
);
1150 if (debug
->external_rfd
!= NULL
)
1151 free (debug
->external_rfd
);
1152 if (debug
->external_ext
!= NULL
)
1153 free (debug
->external_ext
);
1157 /* Swap RPDR (runtime procedure table entry) for output. */
1160 ecoff_swap_rpdr_out (bfd
*abfd
, const RPDR
*in
, struct rpdr_ext
*ex
)
1162 H_PUT_S32 (abfd
, in
->adr
, ex
->p_adr
);
1163 H_PUT_32 (abfd
, in
->regmask
, ex
->p_regmask
);
1164 H_PUT_32 (abfd
, in
->regoffset
, ex
->p_regoffset
);
1165 H_PUT_32 (abfd
, in
->fregmask
, ex
->p_fregmask
);
1166 H_PUT_32 (abfd
, in
->fregoffset
, ex
->p_fregoffset
);
1167 H_PUT_32 (abfd
, in
->frameoffset
, ex
->p_frameoffset
);
1169 H_PUT_16 (abfd
, in
->framereg
, ex
->p_framereg
);
1170 H_PUT_16 (abfd
, in
->pcreg
, ex
->p_pcreg
);
1172 H_PUT_32 (abfd
, in
->irpss
, ex
->p_irpss
);
1175 /* Create a runtime procedure table from the .mdebug section. */
1178 mips_elf_create_procedure_table (void *handle
, bfd
*abfd
,
1179 struct bfd_link_info
*info
, asection
*s
,
1180 struct ecoff_debug_info
*debug
)
1182 const struct ecoff_debug_swap
*swap
;
1183 HDRR
*hdr
= &debug
->symbolic_header
;
1185 struct rpdr_ext
*erp
;
1187 struct pdr_ext
*epdr
;
1188 struct sym_ext
*esym
;
1192 bfd_size_type count
;
1193 unsigned long sindex
;
1197 const char *no_name_func
= _("static procedure (no name)");
1205 swap
= get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
1207 sindex
= strlen (no_name_func
) + 1;
1208 count
= hdr
->ipdMax
;
1211 size
= swap
->external_pdr_size
;
1213 epdr
= bfd_malloc (size
* count
);
1217 if (! _bfd_ecoff_get_accumulated_pdr (handle
, (bfd_byte
*) epdr
))
1220 size
= sizeof (RPDR
);
1221 rp
= rpdr
= bfd_malloc (size
* count
);
1225 size
= sizeof (char *);
1226 sv
= bfd_malloc (size
* count
);
1230 count
= hdr
->isymMax
;
1231 size
= swap
->external_sym_size
;
1232 esym
= bfd_malloc (size
* count
);
1236 if (! _bfd_ecoff_get_accumulated_sym (handle
, (bfd_byte
*) esym
))
1239 count
= hdr
->issMax
;
1240 ss
= bfd_malloc (count
);
1243 if (! _bfd_ecoff_get_accumulated_ss (handle
, (bfd_byte
*) ss
))
1246 count
= hdr
->ipdMax
;
1247 for (i
= 0; i
< (unsigned long) count
; i
++, rp
++)
1249 (*swap
->swap_pdr_in
) (abfd
, epdr
+ i
, &pdr
);
1250 (*swap
->swap_sym_in
) (abfd
, &esym
[pdr
.isym
], &sym
);
1251 rp
->adr
= sym
.value
;
1252 rp
->regmask
= pdr
.regmask
;
1253 rp
->regoffset
= pdr
.regoffset
;
1254 rp
->fregmask
= pdr
.fregmask
;
1255 rp
->fregoffset
= pdr
.fregoffset
;
1256 rp
->frameoffset
= pdr
.frameoffset
;
1257 rp
->framereg
= pdr
.framereg
;
1258 rp
->pcreg
= pdr
.pcreg
;
1260 sv
[i
] = ss
+ sym
.iss
;
1261 sindex
+= strlen (sv
[i
]) + 1;
1265 size
= sizeof (struct rpdr_ext
) * (count
+ 2) + sindex
;
1266 size
= BFD_ALIGN (size
, 16);
1267 rtproc
= bfd_alloc (abfd
, size
);
1270 mips_elf_hash_table (info
)->procedure_count
= 0;
1274 mips_elf_hash_table (info
)->procedure_count
= count
+ 2;
1277 memset (erp
, 0, sizeof (struct rpdr_ext
));
1279 str
= (char *) rtproc
+ sizeof (struct rpdr_ext
) * (count
+ 2);
1280 strcpy (str
, no_name_func
);
1281 str
+= strlen (no_name_func
) + 1;
1282 for (i
= 0; i
< count
; i
++)
1284 ecoff_swap_rpdr_out (abfd
, rpdr
+ i
, erp
+ i
);
1285 strcpy (str
, sv
[i
]);
1286 str
+= strlen (sv
[i
]) + 1;
1288 H_PUT_S32 (abfd
, -1, (erp
+ count
)->p_adr
);
1290 /* Set the size and contents of .rtproc section. */
1292 s
->contents
= rtproc
;
1294 /* Skip this section later on (I don't think this currently
1295 matters, but someday it might). */
1296 s
->map_head
.link_order
= NULL
;
1325 /* We're going to create a stub for H. Create a symbol for the stub's
1326 value and size, to help make the disassembly easier to read. */
1329 mips_elf_create_stub_symbol (struct bfd_link_info
*info
,
1330 struct mips_elf_link_hash_entry
*h
,
1331 const char *prefix
, asection
*s
, bfd_vma value
,
1334 struct bfd_link_hash_entry
*bh
;
1335 struct elf_link_hash_entry
*elfh
;
1338 /* Create a new symbol. */
1339 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1341 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1342 BSF_LOCAL
, s
, value
, NULL
,
1346 /* Make it a local function. */
1347 elfh
= (struct elf_link_hash_entry
*) bh
;
1348 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, STT_FUNC
);
1350 elfh
->forced_local
= 1;
1354 /* We're about to redefine H. Create a symbol to represent H's
1355 current value and size, to help make the disassembly easier
1359 mips_elf_create_shadow_symbol (struct bfd_link_info
*info
,
1360 struct mips_elf_link_hash_entry
*h
,
1363 struct bfd_link_hash_entry
*bh
;
1364 struct elf_link_hash_entry
*elfh
;
1369 /* Read the symbol's value. */
1370 BFD_ASSERT (h
->root
.root
.type
== bfd_link_hash_defined
1371 || h
->root
.root
.type
== bfd_link_hash_defweak
);
1372 s
= h
->root
.root
.u
.def
.section
;
1373 value
= h
->root
.root
.u
.def
.value
;
1375 /* Create a new symbol. */
1376 name
= ACONCAT ((prefix
, h
->root
.root
.root
.string
, NULL
));
1378 if (!_bfd_generic_link_add_one_symbol (info
, s
->owner
, name
,
1379 BSF_LOCAL
, s
, value
, NULL
,
1383 /* Make it local and copy the other attributes from H. */
1384 elfh
= (struct elf_link_hash_entry
*) bh
;
1385 elfh
->type
= ELF_ST_INFO (STB_LOCAL
, ELF_ST_TYPE (h
->root
.type
));
1386 elfh
->other
= h
->root
.other
;
1387 elfh
->size
= h
->root
.size
;
1388 elfh
->forced_local
= 1;
1392 /* Return TRUE if relocations in SECTION can refer directly to a MIPS16
1393 function rather than to a hard-float stub. */
1396 section_allows_mips16_refs_p (asection
*section
)
1400 name
= bfd_get_section_name (section
->owner
, section
);
1401 return (FN_STUB_P (name
)
1402 || CALL_STUB_P (name
)
1403 || CALL_FP_STUB_P (name
)
1404 || strcmp (name
, ".pdr") == 0);
1407 /* [RELOCS, RELEND) are the relocations against SEC, which is a MIPS16
1408 stub section of some kind. Return the R_SYMNDX of the target
1409 function, or 0 if we can't decide which function that is. */
1411 static unsigned long
1412 mips16_stub_symndx (asection
*sec ATTRIBUTE_UNUSED
,
1413 const Elf_Internal_Rela
*relocs
,
1414 const Elf_Internal_Rela
*relend
)
1416 const Elf_Internal_Rela
*rel
;
1418 /* Trust the first R_MIPS_NONE relocation, if any. */
1419 for (rel
= relocs
; rel
< relend
; rel
++)
1420 if (ELF_R_TYPE (sec
->owner
, rel
->r_info
) == R_MIPS_NONE
)
1421 return ELF_R_SYM (sec
->owner
, rel
->r_info
);
1423 /* Otherwise trust the first relocation, whatever its kind. This is
1424 the traditional behavior. */
1425 if (relocs
< relend
)
1426 return ELF_R_SYM (sec
->owner
, relocs
->r_info
);
1431 /* Check the mips16 stubs for a particular symbol, and see if we can
1435 mips_elf_check_mips16_stubs (struct bfd_link_info
*info
,
1436 struct mips_elf_link_hash_entry
*h
)
1438 /* Dynamic symbols must use the standard call interface, in case other
1439 objects try to call them. */
1440 if (h
->fn_stub
!= NULL
1441 && h
->root
.dynindx
!= -1)
1443 mips_elf_create_shadow_symbol (info
, h
, ".mips16.");
1444 h
->need_fn_stub
= TRUE
;
1447 if (h
->fn_stub
!= NULL
1448 && ! h
->need_fn_stub
)
1450 /* We don't need the fn_stub; the only references to this symbol
1451 are 16 bit calls. Clobber the size to 0 to prevent it from
1452 being included in the link. */
1453 h
->fn_stub
->size
= 0;
1454 h
->fn_stub
->flags
&= ~SEC_RELOC
;
1455 h
->fn_stub
->reloc_count
= 0;
1456 h
->fn_stub
->flags
|= SEC_EXCLUDE
;
1459 if (h
->call_stub
!= NULL
1460 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1462 /* We don't need the call_stub; this is a 16 bit function, so
1463 calls from other 16 bit functions are OK. Clobber the size
1464 to 0 to prevent it from being included in the link. */
1465 h
->call_stub
->size
= 0;
1466 h
->call_stub
->flags
&= ~SEC_RELOC
;
1467 h
->call_stub
->reloc_count
= 0;
1468 h
->call_stub
->flags
|= SEC_EXCLUDE
;
1471 if (h
->call_fp_stub
!= NULL
1472 && ELF_ST_IS_MIPS16 (h
->root
.other
))
1474 /* We don't need the call_stub; this is a 16 bit function, so
1475 calls from other 16 bit functions are OK. Clobber the size
1476 to 0 to prevent it from being included in the link. */
1477 h
->call_fp_stub
->size
= 0;
1478 h
->call_fp_stub
->flags
&= ~SEC_RELOC
;
1479 h
->call_fp_stub
->reloc_count
= 0;
1480 h
->call_fp_stub
->flags
|= SEC_EXCLUDE
;
1484 /* Hashtable callbacks for mips_elf_la25_stubs. */
1487 mips_elf_la25_stub_hash (const void *entry_
)
1489 const struct mips_elf_la25_stub
*entry
;
1491 entry
= (struct mips_elf_la25_stub
*) entry_
;
1492 return entry
->h
->root
.root
.u
.def
.section
->id
1493 + entry
->h
->root
.root
.u
.def
.value
;
1497 mips_elf_la25_stub_eq (const void *entry1_
, const void *entry2_
)
1499 const struct mips_elf_la25_stub
*entry1
, *entry2
;
1501 entry1
= (struct mips_elf_la25_stub
*) entry1_
;
1502 entry2
= (struct mips_elf_la25_stub
*) entry2_
;
1503 return ((entry1
->h
->root
.root
.u
.def
.section
1504 == entry2
->h
->root
.root
.u
.def
.section
)
1505 && (entry1
->h
->root
.root
.u
.def
.value
1506 == entry2
->h
->root
.root
.u
.def
.value
));
1509 /* Called by the linker to set up the la25 stub-creation code. FN is
1510 the linker's implementation of add_stub_function. Return true on
1514 _bfd_mips_elf_init_stubs (struct bfd_link_info
*info
,
1515 asection
*(*fn
) (const char *, asection
*,
1518 struct mips_elf_link_hash_table
*htab
;
1520 htab
= mips_elf_hash_table (info
);
1521 htab
->add_stub_section
= fn
;
1522 htab
->la25_stubs
= htab_try_create (1, mips_elf_la25_stub_hash
,
1523 mips_elf_la25_stub_eq
, NULL
);
1524 if (htab
->la25_stubs
== NULL
)
1530 /* Return true if H is a locally-defined PIC function, in the sense
1531 that it might need $25 to be valid on entry. Note that MIPS16
1532 functions never need $25 to be valid on entry; they set up $gp
1533 using PC-relative instructions instead. */
1536 mips_elf_local_pic_function_p (struct mips_elf_link_hash_entry
*h
)
1538 return ((h
->root
.root
.type
== bfd_link_hash_defined
1539 || h
->root
.root
.type
== bfd_link_hash_defweak
)
1540 && h
->root
.def_regular
1541 && !bfd_is_abs_section (h
->root
.root
.u
.def
.section
)
1542 && !ELF_ST_IS_MIPS16 (h
->root
.other
)
1543 && (PIC_OBJECT_P (h
->root
.root
.u
.def
.section
->owner
)
1544 || ELF_ST_IS_MIPS_PIC (h
->root
.other
)));
1547 /* STUB describes an la25 stub that we have decided to implement
1548 by inserting an LUI/ADDIU pair before the target function.
1549 Create the section and redirect the function symbol to it. */
1552 mips_elf_add_la25_intro (struct mips_elf_la25_stub
*stub
,
1553 struct bfd_link_info
*info
)
1555 struct mips_elf_link_hash_table
*htab
;
1557 asection
*s
, *input_section
;
1560 htab
= mips_elf_hash_table (info
);
1562 /* Create a unique name for the new section. */
1563 name
= bfd_malloc (11 + sizeof (".text.stub."));
1566 sprintf (name
, ".text.stub.%d", (int) htab_elements (htab
->la25_stubs
));
1568 /* Create the section. */
1569 input_section
= stub
->h
->root
.root
.u
.def
.section
;
1570 s
= htab
->add_stub_section (name
, input_section
,
1571 input_section
->output_section
);
1575 /* Make sure that any padding goes before the stub. */
1576 align
= input_section
->alignment_power
;
1577 if (!bfd_set_section_alignment (s
->owner
, s
, align
))
1580 s
->size
= (1 << align
) - 8;
1582 /* Create a symbol for the stub. */
1583 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 8);
1584 stub
->stub_section
= s
;
1585 stub
->offset
= s
->size
;
1587 /* Allocate room for it. */
1592 /* STUB describes an la25 stub that we have decided to implement
1593 with a separate trampoline. Allocate room for it and redirect
1594 the function symbol to it. */
1597 mips_elf_add_la25_trampoline (struct mips_elf_la25_stub
*stub
,
1598 struct bfd_link_info
*info
)
1600 struct mips_elf_link_hash_table
*htab
;
1603 htab
= mips_elf_hash_table (info
);
1605 /* Create a trampoline section, if we haven't already. */
1606 s
= htab
->strampoline
;
1609 asection
*input_section
= stub
->h
->root
.root
.u
.def
.section
;
1610 s
= htab
->add_stub_section (".text", NULL
,
1611 input_section
->output_section
);
1612 if (s
== NULL
|| !bfd_set_section_alignment (s
->owner
, s
, 4))
1614 htab
->strampoline
= s
;
1617 /* Create a symbol for the stub. */
1618 mips_elf_create_stub_symbol (info
, stub
->h
, ".pic.", s
, s
->size
, 16);
1619 stub
->stub_section
= s
;
1620 stub
->offset
= s
->size
;
1622 /* Allocate room for it. */
1627 /* H describes a symbol that needs an la25 stub. Make sure that an
1628 appropriate stub exists and point H at it. */
1631 mips_elf_add_la25_stub (struct bfd_link_info
*info
,
1632 struct mips_elf_link_hash_entry
*h
)
1634 struct mips_elf_link_hash_table
*htab
;
1635 struct mips_elf_la25_stub search
, *stub
;
1636 bfd_boolean use_trampoline_p
;
1641 /* Prefer to use LUI/ADDIU stubs if the function is at the beginning
1642 of the section and if we would need no more than 2 nops. */
1643 s
= h
->root
.root
.u
.def
.section
;
1644 value
= h
->root
.root
.u
.def
.value
;
1645 use_trampoline_p
= (value
!= 0 || s
->alignment_power
> 4);
1647 /* Describe the stub we want. */
1648 search
.stub_section
= NULL
;
1652 /* See if we've already created an equivalent stub. */
1653 htab
= mips_elf_hash_table (info
);
1654 slot
= htab_find_slot (htab
->la25_stubs
, &search
, INSERT
);
1658 stub
= (struct mips_elf_la25_stub
*) *slot
;
1661 /* We can reuse the existing stub. */
1662 h
->la25_stub
= stub
;
1666 /* Create a permanent copy of ENTRY and add it to the hash table. */
1667 stub
= bfd_malloc (sizeof (search
));
1673 h
->la25_stub
= stub
;
1674 return (use_trampoline_p
1675 ? mips_elf_add_la25_trampoline (stub
, info
)
1676 : mips_elf_add_la25_intro (stub
, info
));
1679 /* A mips_elf_link_hash_traverse callback that is called before sizing
1680 sections. DATA points to a mips_htab_traverse_info structure. */
1683 mips_elf_check_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
1685 struct mips_htab_traverse_info
*hti
;
1687 hti
= (struct mips_htab_traverse_info
*) data
;
1688 if (h
->root
.root
.type
== bfd_link_hash_warning
)
1689 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
1691 if (!hti
->info
->relocatable
)
1692 mips_elf_check_mips16_stubs (hti
->info
, h
);
1694 if (mips_elf_local_pic_function_p (h
))
1696 /* H is a function that might need $25 to be valid on entry.
1697 If we're creating a non-PIC relocatable object, mark H as
1698 being PIC. If we're creating a non-relocatable object with
1699 non-PIC branches and jumps to H, make sure that H has an la25
1701 if (hti
->info
->relocatable
)
1703 if (!PIC_OBJECT_P (hti
->output_bfd
))
1704 h
->root
.other
= ELF_ST_SET_MIPS_PIC (h
->root
.other
);
1706 else if (h
->has_nonpic_branches
&& !mips_elf_add_la25_stub (hti
->info
, h
))
1715 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions.
1716 Most mips16 instructions are 16 bits, but these instructions
1719 The format of these instructions is:
1721 +--------------+--------------------------------+
1722 | JALX | X| Imm 20:16 | Imm 25:21 |
1723 +--------------+--------------------------------+
1725 +-----------------------------------------------+
1727 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx.
1728 Note that the immediate value in the first word is swapped.
1730 When producing a relocatable object file, R_MIPS16_26 is
1731 handled mostly like R_MIPS_26. In particular, the addend is
1732 stored as a straight 26-bit value in a 32-bit instruction.
1733 (gas makes life simpler for itself by never adjusting a
1734 R_MIPS16_26 reloc to be against a section, so the addend is
1735 always zero). However, the 32 bit instruction is stored as 2
1736 16-bit values, rather than a single 32-bit value. In a
1737 big-endian file, the result is the same; in a little-endian
1738 file, the two 16-bit halves of the 32 bit value are swapped.
1739 This is so that a disassembler can recognize the jal
1742 When doing a final link, R_MIPS16_26 is treated as a 32 bit
1743 instruction stored as two 16-bit values. The addend A is the
1744 contents of the targ26 field. The calculation is the same as
1745 R_MIPS_26. When storing the calculated value, reorder the
1746 immediate value as shown above, and don't forget to store the
1747 value as two 16-bit values.
1749 To put it in MIPS ABI terms, the relocation field is T-targ26-16,
1753 +--------+----------------------+
1757 +--------+----------------------+
1760 +----------+------+-------------+
1764 +----------+--------------------+
1765 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is
1766 ((sub1 << 16) | sub2)).
1768 When producing a relocatable object file, the calculation is
1769 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1770 When producing a fully linked file, the calculation is
1771 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2)
1772 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff)
1774 The table below lists the other MIPS16 instruction relocations.
1775 Each one is calculated in the same way as the non-MIPS16 relocation
1776 given on the right, but using the extended MIPS16 layout of 16-bit
1779 R_MIPS16_GPREL R_MIPS_GPREL16
1780 R_MIPS16_GOT16 R_MIPS_GOT16
1781 R_MIPS16_CALL16 R_MIPS_CALL16
1782 R_MIPS16_HI16 R_MIPS_HI16
1783 R_MIPS16_LO16 R_MIPS_LO16
1785 A typical instruction will have a format like this:
1787 +--------------+--------------------------------+
1788 | EXTEND | Imm 10:5 | Imm 15:11 |
1789 +--------------+--------------------------------+
1790 | Major | rx | ry | Imm 4:0 |
1791 +--------------+--------------------------------+
1793 EXTEND is the five bit value 11110. Major is the instruction
1796 All we need to do here is shuffle the bits appropriately.
1797 As above, the two 16-bit halves must be swapped on a
1798 little-endian system. */
1800 static inline bfd_boolean
1801 mips16_reloc_p (int r_type
)
1806 case R_MIPS16_GPREL
:
1807 case R_MIPS16_GOT16
:
1808 case R_MIPS16_CALL16
:
1818 static inline bfd_boolean
1819 got16_reloc_p (int r_type
)
1821 return r_type
== R_MIPS_GOT16
|| r_type
== R_MIPS16_GOT16
;
1824 static inline bfd_boolean
1825 call16_reloc_p (int r_type
)
1827 return r_type
== R_MIPS_CALL16
|| r_type
== R_MIPS16_CALL16
;
1830 static inline bfd_boolean
1831 hi16_reloc_p (int r_type
)
1833 return r_type
== R_MIPS_HI16
|| r_type
== R_MIPS16_HI16
;
1836 static inline bfd_boolean
1837 lo16_reloc_p (int r_type
)
1839 return r_type
== R_MIPS_LO16
|| r_type
== R_MIPS16_LO16
;
1842 static inline bfd_boolean
1843 mips16_call_reloc_p (int r_type
)
1845 return r_type
== R_MIPS16_26
|| r_type
== R_MIPS16_CALL16
;
1849 _bfd_mips16_elf_reloc_unshuffle (bfd
*abfd
, int r_type
,
1850 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1852 bfd_vma extend
, insn
, val
;
1854 if (!mips16_reloc_p (r_type
))
1857 /* Pick up the mips16 extend instruction and the real instruction. */
1858 extend
= bfd_get_16 (abfd
, data
);
1859 insn
= bfd_get_16 (abfd
, data
+ 2);
1860 if (r_type
== R_MIPS16_26
)
1863 val
= ((extend
& 0xfc00) << 16) | ((extend
& 0x3e0) << 11)
1864 | ((extend
& 0x1f) << 21) | insn
;
1866 val
= extend
<< 16 | insn
;
1869 val
= ((extend
& 0xf800) << 16) | ((insn
& 0xffe0) << 11)
1870 | ((extend
& 0x1f) << 11) | (extend
& 0x7e0) | (insn
& 0x1f);
1871 bfd_put_32 (abfd
, val
, data
);
1875 _bfd_mips16_elf_reloc_shuffle (bfd
*abfd
, int r_type
,
1876 bfd_boolean jal_shuffle
, bfd_byte
*data
)
1878 bfd_vma extend
, insn
, val
;
1880 if (!mips16_reloc_p (r_type
))
1883 val
= bfd_get_32 (abfd
, data
);
1884 if (r_type
== R_MIPS16_26
)
1888 insn
= val
& 0xffff;
1889 extend
= ((val
>> 16) & 0xfc00) | ((val
>> 11) & 0x3e0)
1890 | ((val
>> 21) & 0x1f);
1894 insn
= val
& 0xffff;
1900 insn
= ((val
>> 11) & 0xffe0) | (val
& 0x1f);
1901 extend
= ((val
>> 16) & 0xf800) | ((val
>> 11) & 0x1f) | (val
& 0x7e0);
1903 bfd_put_16 (abfd
, insn
, data
+ 2);
1904 bfd_put_16 (abfd
, extend
, data
);
1907 bfd_reloc_status_type
1908 _bfd_mips_elf_gprel16_with_gp (bfd
*abfd
, asymbol
*symbol
,
1909 arelent
*reloc_entry
, asection
*input_section
,
1910 bfd_boolean relocatable
, void *data
, bfd_vma gp
)
1914 bfd_reloc_status_type status
;
1916 if (bfd_is_com_section (symbol
->section
))
1919 relocation
= symbol
->value
;
1921 relocation
+= symbol
->section
->output_section
->vma
;
1922 relocation
+= symbol
->section
->output_offset
;
1924 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1925 return bfd_reloc_outofrange
;
1927 /* Set val to the offset into the section or symbol. */
1928 val
= reloc_entry
->addend
;
1930 _bfd_mips_elf_sign_extend (val
, 16);
1932 /* Adjust val for the final section location and GP value. If we
1933 are producing relocatable output, we don't want to do this for
1934 an external symbol. */
1936 || (symbol
->flags
& BSF_SECTION_SYM
) != 0)
1937 val
+= relocation
- gp
;
1939 if (reloc_entry
->howto
->partial_inplace
)
1941 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
1943 + reloc_entry
->address
);
1944 if (status
!= bfd_reloc_ok
)
1948 reloc_entry
->addend
= val
;
1951 reloc_entry
->address
+= input_section
->output_offset
;
1953 return bfd_reloc_ok
;
1956 /* Used to store a REL high-part relocation such as R_MIPS_HI16 or
1957 R_MIPS_GOT16. REL is the relocation, INPUT_SECTION is the section
1958 that contains the relocation field and DATA points to the start of
1963 struct mips_hi16
*next
;
1965 asection
*input_section
;
1969 /* FIXME: This should not be a static variable. */
1971 static struct mips_hi16
*mips_hi16_list
;
1973 /* A howto special_function for REL *HI16 relocations. We can only
1974 calculate the correct value once we've seen the partnering
1975 *LO16 relocation, so just save the information for later.
1977 The ABI requires that the *LO16 immediately follow the *HI16.
1978 However, as a GNU extension, we permit an arbitrary number of
1979 *HI16s to be associated with a single *LO16. This significantly
1980 simplies the relocation handling in gcc. */
1982 bfd_reloc_status_type
1983 _bfd_mips_elf_hi16_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
1984 asymbol
*symbol ATTRIBUTE_UNUSED
, void *data
,
1985 asection
*input_section
, bfd
*output_bfd
,
1986 char **error_message ATTRIBUTE_UNUSED
)
1988 struct mips_hi16
*n
;
1990 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
1991 return bfd_reloc_outofrange
;
1993 n
= bfd_malloc (sizeof *n
);
1995 return bfd_reloc_outofrange
;
1997 n
->next
= mips_hi16_list
;
1999 n
->input_section
= input_section
;
2000 n
->rel
= *reloc_entry
;
2003 if (output_bfd
!= NULL
)
2004 reloc_entry
->address
+= input_section
->output_offset
;
2006 return bfd_reloc_ok
;
2009 /* A howto special_function for REL R_MIPS*_GOT16 relocations. This is just
2010 like any other 16-bit relocation when applied to global symbols, but is
2011 treated in the same as R_MIPS_HI16 when applied to local symbols. */
2013 bfd_reloc_status_type
2014 _bfd_mips_elf_got16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2015 void *data
, asection
*input_section
,
2016 bfd
*output_bfd
, char **error_message
)
2018 if ((symbol
->flags
& (BSF_GLOBAL
| BSF_WEAK
)) != 0
2019 || bfd_is_und_section (bfd_get_section (symbol
))
2020 || bfd_is_com_section (bfd_get_section (symbol
)))
2021 /* The relocation is against a global symbol. */
2022 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2023 input_section
, output_bfd
,
2026 return _bfd_mips_elf_hi16_reloc (abfd
, reloc_entry
, symbol
, data
,
2027 input_section
, output_bfd
, error_message
);
2030 /* A howto special_function for REL *LO16 relocations. The *LO16 itself
2031 is a straightforward 16 bit inplace relocation, but we must deal with
2032 any partnering high-part relocations as well. */
2034 bfd_reloc_status_type
2035 _bfd_mips_elf_lo16_reloc (bfd
*abfd
, arelent
*reloc_entry
, asymbol
*symbol
,
2036 void *data
, asection
*input_section
,
2037 bfd
*output_bfd
, char **error_message
)
2040 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2042 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2043 return bfd_reloc_outofrange
;
2045 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2047 vallo
= bfd_get_32 (abfd
, location
);
2048 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2051 while (mips_hi16_list
!= NULL
)
2053 bfd_reloc_status_type ret
;
2054 struct mips_hi16
*hi
;
2056 hi
= mips_hi16_list
;
2058 /* R_MIPS*_GOT16 relocations are something of a special case. We
2059 want to install the addend in the same way as for a R_MIPS*_HI16
2060 relocation (with a rightshift of 16). However, since GOT16
2061 relocations can also be used with global symbols, their howto
2062 has a rightshift of 0. */
2063 if (hi
->rel
.howto
->type
== R_MIPS_GOT16
)
2064 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS_HI16
, FALSE
);
2065 else if (hi
->rel
.howto
->type
== R_MIPS16_GOT16
)
2066 hi
->rel
.howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, R_MIPS16_HI16
, FALSE
);
2068 /* VALLO is a signed 16-bit number. Bias it by 0x8000 so that any
2069 carry or borrow will induce a change of +1 or -1 in the high part. */
2070 hi
->rel
.addend
+= (vallo
+ 0x8000) & 0xffff;
2072 ret
= _bfd_mips_elf_generic_reloc (abfd
, &hi
->rel
, symbol
, hi
->data
,
2073 hi
->input_section
, output_bfd
,
2075 if (ret
!= bfd_reloc_ok
)
2078 mips_hi16_list
= hi
->next
;
2082 return _bfd_mips_elf_generic_reloc (abfd
, reloc_entry
, symbol
, data
,
2083 input_section
, output_bfd
,
2087 /* A generic howto special_function. This calculates and installs the
2088 relocation itself, thus avoiding the oft-discussed problems in
2089 bfd_perform_relocation and bfd_install_relocation. */
2091 bfd_reloc_status_type
2092 _bfd_mips_elf_generic_reloc (bfd
*abfd ATTRIBUTE_UNUSED
, arelent
*reloc_entry
,
2093 asymbol
*symbol
, void *data ATTRIBUTE_UNUSED
,
2094 asection
*input_section
, bfd
*output_bfd
,
2095 char **error_message ATTRIBUTE_UNUSED
)
2098 bfd_reloc_status_type status
;
2099 bfd_boolean relocatable
;
2101 relocatable
= (output_bfd
!= NULL
);
2103 if (reloc_entry
->address
> bfd_get_section_limit (abfd
, input_section
))
2104 return bfd_reloc_outofrange
;
2106 /* Build up the field adjustment in VAL. */
2108 if (!relocatable
|| (symbol
->flags
& BSF_SECTION_SYM
) != 0)
2110 /* Either we're calculating the final field value or we have a
2111 relocation against a section symbol. Add in the section's
2112 offset or address. */
2113 val
+= symbol
->section
->output_section
->vma
;
2114 val
+= symbol
->section
->output_offset
;
2119 /* We're calculating the final field value. Add in the symbol's value
2120 and, if pc-relative, subtract the address of the field itself. */
2121 val
+= symbol
->value
;
2122 if (reloc_entry
->howto
->pc_relative
)
2124 val
-= input_section
->output_section
->vma
;
2125 val
-= input_section
->output_offset
;
2126 val
-= reloc_entry
->address
;
2130 /* VAL is now the final adjustment. If we're keeping this relocation
2131 in the output file, and if the relocation uses a separate addend,
2132 we just need to add VAL to that addend. Otherwise we need to add
2133 VAL to the relocation field itself. */
2134 if (relocatable
&& !reloc_entry
->howto
->partial_inplace
)
2135 reloc_entry
->addend
+= val
;
2138 bfd_byte
*location
= (bfd_byte
*) data
+ reloc_entry
->address
;
2140 /* Add in the separate addend, if any. */
2141 val
+= reloc_entry
->addend
;
2143 /* Add VAL to the relocation field. */
2144 _bfd_mips16_elf_reloc_unshuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2146 status
= _bfd_relocate_contents (reloc_entry
->howto
, abfd
, val
,
2148 _bfd_mips16_elf_reloc_shuffle (abfd
, reloc_entry
->howto
->type
, FALSE
,
2151 if (status
!= bfd_reloc_ok
)
2156 reloc_entry
->address
+= input_section
->output_offset
;
2158 return bfd_reloc_ok
;
2161 /* Swap an entry in a .gptab section. Note that these routines rely
2162 on the equivalence of the two elements of the union. */
2165 bfd_mips_elf32_swap_gptab_in (bfd
*abfd
, const Elf32_External_gptab
*ex
,
2168 in
->gt_entry
.gt_g_value
= H_GET_32 (abfd
, ex
->gt_entry
.gt_g_value
);
2169 in
->gt_entry
.gt_bytes
= H_GET_32 (abfd
, ex
->gt_entry
.gt_bytes
);
2173 bfd_mips_elf32_swap_gptab_out (bfd
*abfd
, const Elf32_gptab
*in
,
2174 Elf32_External_gptab
*ex
)
2176 H_PUT_32 (abfd
, in
->gt_entry
.gt_g_value
, ex
->gt_entry
.gt_g_value
);
2177 H_PUT_32 (abfd
, in
->gt_entry
.gt_bytes
, ex
->gt_entry
.gt_bytes
);
2181 bfd_elf32_swap_compact_rel_out (bfd
*abfd
, const Elf32_compact_rel
*in
,
2182 Elf32_External_compact_rel
*ex
)
2184 H_PUT_32 (abfd
, in
->id1
, ex
->id1
);
2185 H_PUT_32 (abfd
, in
->num
, ex
->num
);
2186 H_PUT_32 (abfd
, in
->id2
, ex
->id2
);
2187 H_PUT_32 (abfd
, in
->offset
, ex
->offset
);
2188 H_PUT_32 (abfd
, in
->reserved0
, ex
->reserved0
);
2189 H_PUT_32 (abfd
, in
->reserved1
, ex
->reserved1
);
2193 bfd_elf32_swap_crinfo_out (bfd
*abfd
, const Elf32_crinfo
*in
,
2194 Elf32_External_crinfo
*ex
)
2198 l
= (((in
->ctype
& CRINFO_CTYPE
) << CRINFO_CTYPE_SH
)
2199 | ((in
->rtype
& CRINFO_RTYPE
) << CRINFO_RTYPE_SH
)
2200 | ((in
->dist2to
& CRINFO_DIST2TO
) << CRINFO_DIST2TO_SH
)
2201 | ((in
->relvaddr
& CRINFO_RELVADDR
) << CRINFO_RELVADDR_SH
));
2202 H_PUT_32 (abfd
, l
, ex
->info
);
2203 H_PUT_32 (abfd
, in
->konst
, ex
->konst
);
2204 H_PUT_32 (abfd
, in
->vaddr
, ex
->vaddr
);
2207 /* A .reginfo section holds a single Elf32_RegInfo structure. These
2208 routines swap this structure in and out. They are used outside of
2209 BFD, so they are globally visible. */
2212 bfd_mips_elf32_swap_reginfo_in (bfd
*abfd
, const Elf32_External_RegInfo
*ex
,
2215 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2216 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2217 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2218 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2219 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2220 in
->ri_gp_value
= H_GET_32 (abfd
, ex
->ri_gp_value
);
2224 bfd_mips_elf32_swap_reginfo_out (bfd
*abfd
, const Elf32_RegInfo
*in
,
2225 Elf32_External_RegInfo
*ex
)
2227 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2228 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2229 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2230 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2231 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2232 H_PUT_32 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2235 /* In the 64 bit ABI, the .MIPS.options section holds register
2236 information in an Elf64_Reginfo structure. These routines swap
2237 them in and out. They are globally visible because they are used
2238 outside of BFD. These routines are here so that gas can call them
2239 without worrying about whether the 64 bit ABI has been included. */
2242 bfd_mips_elf64_swap_reginfo_in (bfd
*abfd
, const Elf64_External_RegInfo
*ex
,
2243 Elf64_Internal_RegInfo
*in
)
2245 in
->ri_gprmask
= H_GET_32 (abfd
, ex
->ri_gprmask
);
2246 in
->ri_pad
= H_GET_32 (abfd
, ex
->ri_pad
);
2247 in
->ri_cprmask
[0] = H_GET_32 (abfd
, ex
->ri_cprmask
[0]);
2248 in
->ri_cprmask
[1] = H_GET_32 (abfd
, ex
->ri_cprmask
[1]);
2249 in
->ri_cprmask
[2] = H_GET_32 (abfd
, ex
->ri_cprmask
[2]);
2250 in
->ri_cprmask
[3] = H_GET_32 (abfd
, ex
->ri_cprmask
[3]);
2251 in
->ri_gp_value
= H_GET_64 (abfd
, ex
->ri_gp_value
);
2255 bfd_mips_elf64_swap_reginfo_out (bfd
*abfd
, const Elf64_Internal_RegInfo
*in
,
2256 Elf64_External_RegInfo
*ex
)
2258 H_PUT_32 (abfd
, in
->ri_gprmask
, ex
->ri_gprmask
);
2259 H_PUT_32 (abfd
, in
->ri_pad
, ex
->ri_pad
);
2260 H_PUT_32 (abfd
, in
->ri_cprmask
[0], ex
->ri_cprmask
[0]);
2261 H_PUT_32 (abfd
, in
->ri_cprmask
[1], ex
->ri_cprmask
[1]);
2262 H_PUT_32 (abfd
, in
->ri_cprmask
[2], ex
->ri_cprmask
[2]);
2263 H_PUT_32 (abfd
, in
->ri_cprmask
[3], ex
->ri_cprmask
[3]);
2264 H_PUT_64 (abfd
, in
->ri_gp_value
, ex
->ri_gp_value
);
2267 /* Swap in an options header. */
2270 bfd_mips_elf_swap_options_in (bfd
*abfd
, const Elf_External_Options
*ex
,
2271 Elf_Internal_Options
*in
)
2273 in
->kind
= H_GET_8 (abfd
, ex
->kind
);
2274 in
->size
= H_GET_8 (abfd
, ex
->size
);
2275 in
->section
= H_GET_16 (abfd
, ex
->section
);
2276 in
->info
= H_GET_32 (abfd
, ex
->info
);
2279 /* Swap out an options header. */
2282 bfd_mips_elf_swap_options_out (bfd
*abfd
, const Elf_Internal_Options
*in
,
2283 Elf_External_Options
*ex
)
2285 H_PUT_8 (abfd
, in
->kind
, ex
->kind
);
2286 H_PUT_8 (abfd
, in
->size
, ex
->size
);
2287 H_PUT_16 (abfd
, in
->section
, ex
->section
);
2288 H_PUT_32 (abfd
, in
->info
, ex
->info
);
2291 /* This function is called via qsort() to sort the dynamic relocation
2292 entries by increasing r_symndx value. */
2295 sort_dynamic_relocs (const void *arg1
, const void *arg2
)
2297 Elf_Internal_Rela int_reloc1
;
2298 Elf_Internal_Rela int_reloc2
;
2301 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg1
, &int_reloc1
);
2302 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd
, arg2
, &int_reloc2
);
2304 diff
= ELF32_R_SYM (int_reloc1
.r_info
) - ELF32_R_SYM (int_reloc2
.r_info
);
2308 if (int_reloc1
.r_offset
< int_reloc2
.r_offset
)
2310 if (int_reloc1
.r_offset
> int_reloc2
.r_offset
)
2315 /* Like sort_dynamic_relocs, but used for elf64 relocations. */
2318 sort_dynamic_relocs_64 (const void *arg1 ATTRIBUTE_UNUSED
,
2319 const void *arg2 ATTRIBUTE_UNUSED
)
2322 Elf_Internal_Rela int_reloc1
[3];
2323 Elf_Internal_Rela int_reloc2
[3];
2325 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2326 (reldyn_sorting_bfd
, arg1
, int_reloc1
);
2327 (*get_elf_backend_data (reldyn_sorting_bfd
)->s
->swap_reloc_in
)
2328 (reldyn_sorting_bfd
, arg2
, int_reloc2
);
2330 if (ELF64_R_SYM (int_reloc1
[0].r_info
) < ELF64_R_SYM (int_reloc2
[0].r_info
))
2332 if (ELF64_R_SYM (int_reloc1
[0].r_info
) > ELF64_R_SYM (int_reloc2
[0].r_info
))
2335 if (int_reloc1
[0].r_offset
< int_reloc2
[0].r_offset
)
2337 if (int_reloc1
[0].r_offset
> int_reloc2
[0].r_offset
)
2346 /* This routine is used to write out ECOFF debugging external symbol
2347 information. It is called via mips_elf_link_hash_traverse. The
2348 ECOFF external symbol information must match the ELF external
2349 symbol information. Unfortunately, at this point we don't know
2350 whether a symbol is required by reloc information, so the two
2351 tables may wind up being different. We must sort out the external
2352 symbol information before we can set the final size of the .mdebug
2353 section, and we must set the size of the .mdebug section before we
2354 can relocate any sections, and we can't know which symbols are
2355 required by relocation until we relocate the sections.
2356 Fortunately, it is relatively unlikely that any symbol will be
2357 stripped but required by a reloc. In particular, it can not happen
2358 when generating a final executable. */
2361 mips_elf_output_extsym (struct mips_elf_link_hash_entry
*h
, void *data
)
2363 struct extsym_info
*einfo
= data
;
2365 asection
*sec
, *output_section
;
2367 if (h
->root
.root
.type
== bfd_link_hash_warning
)
2368 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
2370 if (h
->root
.indx
== -2)
2372 else if ((h
->root
.def_dynamic
2373 || h
->root
.ref_dynamic
2374 || h
->root
.type
== bfd_link_hash_new
)
2375 && !h
->root
.def_regular
2376 && !h
->root
.ref_regular
)
2378 else if (einfo
->info
->strip
== strip_all
2379 || (einfo
->info
->strip
== strip_some
2380 && bfd_hash_lookup (einfo
->info
->keep_hash
,
2381 h
->root
.root
.root
.string
,
2382 FALSE
, FALSE
) == NULL
))
2390 if (h
->esym
.ifd
== -2)
2393 h
->esym
.cobol_main
= 0;
2394 h
->esym
.weakext
= 0;
2395 h
->esym
.reserved
= 0;
2396 h
->esym
.ifd
= ifdNil
;
2397 h
->esym
.asym
.value
= 0;
2398 h
->esym
.asym
.st
= stGlobal
;
2400 if (h
->root
.root
.type
== bfd_link_hash_undefined
2401 || h
->root
.root
.type
== bfd_link_hash_undefweak
)
2405 /* Use undefined class. Also, set class and type for some
2407 name
= h
->root
.root
.root
.string
;
2408 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
2409 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
2411 h
->esym
.asym
.sc
= scData
;
2412 h
->esym
.asym
.st
= stLabel
;
2413 h
->esym
.asym
.value
= 0;
2415 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
2417 h
->esym
.asym
.sc
= scAbs
;
2418 h
->esym
.asym
.st
= stLabel
;
2419 h
->esym
.asym
.value
=
2420 mips_elf_hash_table (einfo
->info
)->procedure_count
;
2422 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (einfo
->abfd
))
2424 h
->esym
.asym
.sc
= scAbs
;
2425 h
->esym
.asym
.st
= stLabel
;
2426 h
->esym
.asym
.value
= elf_gp (einfo
->abfd
);
2429 h
->esym
.asym
.sc
= scUndefined
;
2431 else if (h
->root
.root
.type
!= bfd_link_hash_defined
2432 && h
->root
.root
.type
!= bfd_link_hash_defweak
)
2433 h
->esym
.asym
.sc
= scAbs
;
2438 sec
= h
->root
.root
.u
.def
.section
;
2439 output_section
= sec
->output_section
;
2441 /* When making a shared library and symbol h is the one from
2442 the another shared library, OUTPUT_SECTION may be null. */
2443 if (output_section
== NULL
)
2444 h
->esym
.asym
.sc
= scUndefined
;
2447 name
= bfd_section_name (output_section
->owner
, output_section
);
2449 if (strcmp (name
, ".text") == 0)
2450 h
->esym
.asym
.sc
= scText
;
2451 else if (strcmp (name
, ".data") == 0)
2452 h
->esym
.asym
.sc
= scData
;
2453 else if (strcmp (name
, ".sdata") == 0)
2454 h
->esym
.asym
.sc
= scSData
;
2455 else if (strcmp (name
, ".rodata") == 0
2456 || strcmp (name
, ".rdata") == 0)
2457 h
->esym
.asym
.sc
= scRData
;
2458 else if (strcmp (name
, ".bss") == 0)
2459 h
->esym
.asym
.sc
= scBss
;
2460 else if (strcmp (name
, ".sbss") == 0)
2461 h
->esym
.asym
.sc
= scSBss
;
2462 else if (strcmp (name
, ".init") == 0)
2463 h
->esym
.asym
.sc
= scInit
;
2464 else if (strcmp (name
, ".fini") == 0)
2465 h
->esym
.asym
.sc
= scFini
;
2467 h
->esym
.asym
.sc
= scAbs
;
2471 h
->esym
.asym
.reserved
= 0;
2472 h
->esym
.asym
.index
= indexNil
;
2475 if (h
->root
.root
.type
== bfd_link_hash_common
)
2476 h
->esym
.asym
.value
= h
->root
.root
.u
.c
.size
;
2477 else if (h
->root
.root
.type
== bfd_link_hash_defined
2478 || h
->root
.root
.type
== bfd_link_hash_defweak
)
2480 if (h
->esym
.asym
.sc
== scCommon
)
2481 h
->esym
.asym
.sc
= scBss
;
2482 else if (h
->esym
.asym
.sc
== scSCommon
)
2483 h
->esym
.asym
.sc
= scSBss
;
2485 sec
= h
->root
.root
.u
.def
.section
;
2486 output_section
= sec
->output_section
;
2487 if (output_section
!= NULL
)
2488 h
->esym
.asym
.value
= (h
->root
.root
.u
.def
.value
2489 + sec
->output_offset
2490 + output_section
->vma
);
2492 h
->esym
.asym
.value
= 0;
2496 struct mips_elf_link_hash_entry
*hd
= h
;
2498 while (hd
->root
.root
.type
== bfd_link_hash_indirect
)
2499 hd
= (struct mips_elf_link_hash_entry
*)h
->root
.root
.u
.i
.link
;
2501 if (hd
->needs_lazy_stub
)
2503 /* Set type and value for a symbol with a function stub. */
2504 h
->esym
.asym
.st
= stProc
;
2505 sec
= hd
->root
.root
.u
.def
.section
;
2507 h
->esym
.asym
.value
= 0;
2510 output_section
= sec
->output_section
;
2511 if (output_section
!= NULL
)
2512 h
->esym
.asym
.value
= (hd
->root
.plt
.offset
2513 + sec
->output_offset
2514 + output_section
->vma
);
2516 h
->esym
.asym
.value
= 0;
2521 if (! bfd_ecoff_debug_one_external (einfo
->abfd
, einfo
->debug
, einfo
->swap
,
2522 h
->root
.root
.root
.string
,
2525 einfo
->failed
= TRUE
;
2532 /* A comparison routine used to sort .gptab entries. */
2535 gptab_compare (const void *p1
, const void *p2
)
2537 const Elf32_gptab
*a1
= p1
;
2538 const Elf32_gptab
*a2
= p2
;
2540 return a1
->gt_entry
.gt_g_value
- a2
->gt_entry
.gt_g_value
;
2543 /* Functions to manage the got entry hash table. */
2545 /* Use all 64 bits of a bfd_vma for the computation of a 32-bit
2548 static INLINE hashval_t
2549 mips_elf_hash_bfd_vma (bfd_vma addr
)
2552 return addr
+ (addr
>> 32);
2558 /* got_entries only match if they're identical, except for gotidx, so
2559 use all fields to compute the hash, and compare the appropriate
2563 mips_elf_got_entry_hash (const void *entry_
)
2565 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2567 return entry
->symndx
2568 + ((entry
->tls_type
& GOT_TLS_LDM
) << 17)
2569 + (! entry
->abfd
? mips_elf_hash_bfd_vma (entry
->d
.address
)
2571 + (entry
->symndx
>= 0 ? mips_elf_hash_bfd_vma (entry
->d
.addend
)
2572 : entry
->d
.h
->root
.root
.root
.hash
));
2576 mips_elf_got_entry_eq (const void *entry1
, const void *entry2
)
2578 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2579 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2581 /* An LDM entry can only match another LDM entry. */
2582 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2585 return e1
->abfd
== e2
->abfd
&& e1
->symndx
== e2
->symndx
2586 && (! e1
->abfd
? e1
->d
.address
== e2
->d
.address
2587 : e1
->symndx
>= 0 ? e1
->d
.addend
== e2
->d
.addend
2588 : e1
->d
.h
== e2
->d
.h
);
2591 /* multi_got_entries are still a match in the case of global objects,
2592 even if the input bfd in which they're referenced differs, so the
2593 hash computation and compare functions are adjusted
2597 mips_elf_multi_got_entry_hash (const void *entry_
)
2599 const struct mips_got_entry
*entry
= (struct mips_got_entry
*)entry_
;
2601 return entry
->symndx
2603 ? mips_elf_hash_bfd_vma (entry
->d
.address
)
2604 : entry
->symndx
>= 0
2605 ? ((entry
->tls_type
& GOT_TLS_LDM
)
2606 ? (GOT_TLS_LDM
<< 17)
2608 + mips_elf_hash_bfd_vma (entry
->d
.addend
)))
2609 : entry
->d
.h
->root
.root
.root
.hash
);
2613 mips_elf_multi_got_entry_eq (const void *entry1
, const void *entry2
)
2615 const struct mips_got_entry
*e1
= (struct mips_got_entry
*)entry1
;
2616 const struct mips_got_entry
*e2
= (struct mips_got_entry
*)entry2
;
2618 /* Any two LDM entries match. */
2619 if (e1
->tls_type
& e2
->tls_type
& GOT_TLS_LDM
)
2622 /* Nothing else matches an LDM entry. */
2623 if ((e1
->tls_type
^ e2
->tls_type
) & GOT_TLS_LDM
)
2626 return e1
->symndx
== e2
->symndx
2627 && (e1
->symndx
>= 0 ? e1
->abfd
== e2
->abfd
&& e1
->d
.addend
== e2
->d
.addend
2628 : e1
->abfd
== NULL
|| e2
->abfd
== NULL
2629 ? e1
->abfd
== e2
->abfd
&& e1
->d
.address
== e2
->d
.address
2630 : e1
->d
.h
== e2
->d
.h
);
2634 mips_got_page_entry_hash (const void *entry_
)
2636 const struct mips_got_page_entry
*entry
;
2638 entry
= (const struct mips_got_page_entry
*) entry_
;
2639 return entry
->abfd
->id
+ entry
->symndx
;
2643 mips_got_page_entry_eq (const void *entry1_
, const void *entry2_
)
2645 const struct mips_got_page_entry
*entry1
, *entry2
;
2647 entry1
= (const struct mips_got_page_entry
*) entry1_
;
2648 entry2
= (const struct mips_got_page_entry
*) entry2_
;
2649 return entry1
->abfd
== entry2
->abfd
&& entry1
->symndx
== entry2
->symndx
;
2652 /* Return the dynamic relocation section. If it doesn't exist, try to
2653 create a new it if CREATE_P, otherwise return NULL. Also return NULL
2654 if creation fails. */
2657 mips_elf_rel_dyn_section (struct bfd_link_info
*info
, bfd_boolean create_p
)
2663 dname
= MIPS_ELF_REL_DYN_NAME (info
);
2664 dynobj
= elf_hash_table (info
)->dynobj
;
2665 sreloc
= bfd_get_section_by_name (dynobj
, dname
);
2666 if (sreloc
== NULL
&& create_p
)
2668 sreloc
= bfd_make_section_with_flags (dynobj
, dname
,
2673 | SEC_LINKER_CREATED
2676 || ! bfd_set_section_alignment (dynobj
, sreloc
,
2677 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
2683 /* Count the number of relocations needed for a TLS GOT entry, with
2684 access types from TLS_TYPE, and symbol H (or a local symbol if H
2688 mips_tls_got_relocs (struct bfd_link_info
*info
, unsigned char tls_type
,
2689 struct elf_link_hash_entry
*h
)
2693 bfd_boolean need_relocs
= FALSE
;
2694 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2696 if (h
&& WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, h
)
2697 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, h
)))
2700 if ((info
->shared
|| indx
!= 0)
2702 || ELF_ST_VISIBILITY (h
->other
) == STV_DEFAULT
2703 || h
->root
.type
!= bfd_link_hash_undefweak
))
2709 if (tls_type
& GOT_TLS_GD
)
2716 if (tls_type
& GOT_TLS_IE
)
2719 if ((tls_type
& GOT_TLS_LDM
) && info
->shared
)
2725 /* Count the number of TLS relocations required for the GOT entry in
2726 ARG1, if it describes a local symbol. */
2729 mips_elf_count_local_tls_relocs (void **arg1
, void *arg2
)
2731 struct mips_got_entry
*entry
= * (struct mips_got_entry
**) arg1
;
2732 struct mips_elf_count_tls_arg
*arg
= arg2
;
2734 if (entry
->abfd
!= NULL
&& entry
->symndx
!= -1)
2735 arg
->needed
+= mips_tls_got_relocs (arg
->info
, entry
->tls_type
, NULL
);
2740 /* Count the number of TLS GOT entries required for the global (or
2741 forced-local) symbol in ARG1. */
2744 mips_elf_count_global_tls_entries (void *arg1
, void *arg2
)
2746 struct mips_elf_link_hash_entry
*hm
2747 = (struct mips_elf_link_hash_entry
*) arg1
;
2748 struct mips_elf_count_tls_arg
*arg
= arg2
;
2750 if (hm
->tls_type
& GOT_TLS_GD
)
2752 if (hm
->tls_type
& GOT_TLS_IE
)
2758 /* Count the number of TLS relocations required for the global (or
2759 forced-local) symbol in ARG1. */
2762 mips_elf_count_global_tls_relocs (void *arg1
, void *arg2
)
2764 struct mips_elf_link_hash_entry
*hm
2765 = (struct mips_elf_link_hash_entry
*) arg1
;
2766 struct mips_elf_count_tls_arg
*arg
= arg2
;
2768 arg
->needed
+= mips_tls_got_relocs (arg
->info
, hm
->tls_type
, &hm
->root
);
2773 /* Output a simple dynamic relocation into SRELOC. */
2776 mips_elf_output_dynamic_relocation (bfd
*output_bfd
,
2778 unsigned long reloc_index
,
2783 Elf_Internal_Rela rel
[3];
2785 memset (rel
, 0, sizeof (rel
));
2787 rel
[0].r_info
= ELF_R_INFO (output_bfd
, indx
, r_type
);
2788 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
2790 if (ABI_64_P (output_bfd
))
2792 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
2793 (output_bfd
, &rel
[0],
2795 + reloc_index
* sizeof (Elf64_Mips_External_Rel
)));
2798 bfd_elf32_swap_reloc_out
2799 (output_bfd
, &rel
[0],
2801 + reloc_index
* sizeof (Elf32_External_Rel
)));
2804 /* Initialize a set of TLS GOT entries for one symbol. */
2807 mips_elf_initialize_tls_slots (bfd
*abfd
, bfd_vma got_offset
,
2808 unsigned char *tls_type_p
,
2809 struct bfd_link_info
*info
,
2810 struct mips_elf_link_hash_entry
*h
,
2813 struct mips_elf_link_hash_table
*htab
;
2815 asection
*sreloc
, *sgot
;
2816 bfd_vma offset
, offset2
;
2817 bfd_boolean need_relocs
= FALSE
;
2819 htab
= mips_elf_hash_table (info
);
2825 bfd_boolean dyn
= elf_hash_table (info
)->dynamic_sections_created
;
2827 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn
, info
->shared
, &h
->root
)
2828 && (!info
->shared
|| !SYMBOL_REFERENCES_LOCAL (info
, &h
->root
)))
2829 indx
= h
->root
.dynindx
;
2832 if (*tls_type_p
& GOT_TLS_DONE
)
2835 if ((info
->shared
|| indx
!= 0)
2837 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
2838 || h
->root
.type
!= bfd_link_hash_undefweak
))
2841 /* MINUS_ONE means the symbol is not defined in this object. It may not
2842 be defined at all; assume that the value doesn't matter in that
2843 case. Otherwise complain if we would use the value. */
2844 BFD_ASSERT (value
!= MINUS_ONE
|| (indx
!= 0 && need_relocs
)
2845 || h
->root
.root
.type
== bfd_link_hash_undefweak
);
2847 /* Emit necessary relocations. */
2848 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
2850 /* General Dynamic. */
2851 if (*tls_type_p
& GOT_TLS_GD
)
2853 offset
= got_offset
;
2854 offset2
= offset
+ MIPS_ELF_GOT_SIZE (abfd
);
2858 mips_elf_output_dynamic_relocation
2859 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2860 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2861 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2864 mips_elf_output_dynamic_relocation
2865 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2866 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPREL64
: R_MIPS_TLS_DTPREL32
,
2867 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset2
);
2869 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2870 sgot
->contents
+ offset2
);
2874 MIPS_ELF_PUT_WORD (abfd
, 1,
2875 sgot
->contents
+ offset
);
2876 MIPS_ELF_PUT_WORD (abfd
, value
- dtprel_base (info
),
2877 sgot
->contents
+ offset2
);
2880 got_offset
+= 2 * MIPS_ELF_GOT_SIZE (abfd
);
2883 /* Initial Exec model. */
2884 if (*tls_type_p
& GOT_TLS_IE
)
2886 offset
= got_offset
;
2891 MIPS_ELF_PUT_WORD (abfd
, value
- elf_hash_table (info
)->tls_sec
->vma
,
2892 sgot
->contents
+ offset
);
2894 MIPS_ELF_PUT_WORD (abfd
, 0,
2895 sgot
->contents
+ offset
);
2897 mips_elf_output_dynamic_relocation
2898 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2899 ABI_64_P (abfd
) ? R_MIPS_TLS_TPREL64
: R_MIPS_TLS_TPREL32
,
2900 sgot
->output_offset
+ sgot
->output_section
->vma
+ offset
);
2903 MIPS_ELF_PUT_WORD (abfd
, value
- tprel_base (info
),
2904 sgot
->contents
+ offset
);
2907 if (*tls_type_p
& GOT_TLS_LDM
)
2909 /* The initial offset is zero, and the LD offsets will include the
2910 bias by DTP_OFFSET. */
2911 MIPS_ELF_PUT_WORD (abfd
, 0,
2912 sgot
->contents
+ got_offset
2913 + MIPS_ELF_GOT_SIZE (abfd
));
2916 MIPS_ELF_PUT_WORD (abfd
, 1,
2917 sgot
->contents
+ got_offset
);
2919 mips_elf_output_dynamic_relocation
2920 (abfd
, sreloc
, sreloc
->reloc_count
++, indx
,
2921 ABI_64_P (abfd
) ? R_MIPS_TLS_DTPMOD64
: R_MIPS_TLS_DTPMOD32
,
2922 sgot
->output_offset
+ sgot
->output_section
->vma
+ got_offset
);
2925 *tls_type_p
|= GOT_TLS_DONE
;
2928 /* Return the GOT index to use for a relocation of type R_TYPE against
2929 a symbol accessed using TLS_TYPE models. The GOT entries for this
2930 symbol in this GOT start at GOT_INDEX. This function initializes the
2931 GOT entries and corresponding relocations. */
2934 mips_tls_got_index (bfd
*abfd
, bfd_vma got_index
, unsigned char *tls_type
,
2935 int r_type
, struct bfd_link_info
*info
,
2936 struct mips_elf_link_hash_entry
*h
, bfd_vma symbol
)
2938 BFD_ASSERT (r_type
== R_MIPS_TLS_GOTTPREL
|| r_type
== R_MIPS_TLS_GD
2939 || r_type
== R_MIPS_TLS_LDM
);
2941 mips_elf_initialize_tls_slots (abfd
, got_index
, tls_type
, info
, h
, symbol
);
2943 if (r_type
== R_MIPS_TLS_GOTTPREL
)
2945 BFD_ASSERT (*tls_type
& GOT_TLS_IE
);
2946 if (*tls_type
& GOT_TLS_GD
)
2947 return got_index
+ 2 * MIPS_ELF_GOT_SIZE (abfd
);
2952 if (r_type
== R_MIPS_TLS_GD
)
2954 BFD_ASSERT (*tls_type
& GOT_TLS_GD
);
2958 if (r_type
== R_MIPS_TLS_LDM
)
2960 BFD_ASSERT (*tls_type
& GOT_TLS_LDM
);
2967 /* Return the offset from _GLOBAL_OFFSET_TABLE_ of the .got.plt entry
2968 for global symbol H. .got.plt comes before the GOT, so the offset
2969 will be negative. */
2972 mips_elf_gotplt_index (struct bfd_link_info
*info
,
2973 struct elf_link_hash_entry
*h
)
2975 bfd_vma plt_index
, got_address
, got_value
;
2976 struct mips_elf_link_hash_table
*htab
;
2978 htab
= mips_elf_hash_table (info
);
2979 BFD_ASSERT (h
->plt
.offset
!= (bfd_vma
) -1);
2981 /* This function only works for VxWorks, because a non-VxWorks .got.plt
2982 section starts with reserved entries. */
2983 BFD_ASSERT (htab
->is_vxworks
);
2985 /* Calculate the index of the symbol's PLT entry. */
2986 plt_index
= (h
->plt
.offset
- htab
->plt_header_size
) / htab
->plt_entry_size
;
2988 /* Calculate the address of the associated .got.plt entry. */
2989 got_address
= (htab
->sgotplt
->output_section
->vma
2990 + htab
->sgotplt
->output_offset
2993 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
2994 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
2995 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
2996 + htab
->root
.hgot
->root
.u
.def
.value
);
2998 return got_address
- got_value
;
3001 /* Return the GOT offset for address VALUE. If there is not yet a GOT
3002 entry for this value, create one. If R_SYMNDX refers to a TLS symbol,
3003 create a TLS GOT entry instead. Return -1 if no satisfactory GOT
3004 offset can be found. */
3007 mips_elf_local_got_index (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3008 bfd_vma value
, unsigned long r_symndx
,
3009 struct mips_elf_link_hash_entry
*h
, int r_type
)
3011 struct mips_elf_link_hash_table
*htab
;
3012 struct mips_got_entry
*entry
;
3014 htab
= mips_elf_hash_table (info
);
3015 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
,
3016 r_symndx
, h
, r_type
);
3020 if (TLS_RELOC_P (r_type
))
3022 if (entry
->symndx
== -1 && htab
->got_info
->next
== NULL
)
3023 /* A type (3) entry in the single-GOT case. We use the symbol's
3024 hash table entry to track the index. */
3025 return mips_tls_got_index (abfd
, h
->tls_got_offset
, &h
->tls_type
,
3026 r_type
, info
, h
, value
);
3028 return mips_tls_got_index (abfd
, entry
->gotidx
, &entry
->tls_type
,
3029 r_type
, info
, h
, value
);
3032 return entry
->gotidx
;
3035 /* Returns the GOT index for the global symbol indicated by H. */
3038 mips_elf_global_got_index (bfd
*abfd
, bfd
*ibfd
, struct elf_link_hash_entry
*h
,
3039 int r_type
, struct bfd_link_info
*info
)
3041 struct mips_elf_link_hash_table
*htab
;
3043 struct mips_got_info
*g
, *gg
;
3044 long global_got_dynindx
= 0;
3046 htab
= mips_elf_hash_table (info
);
3047 gg
= g
= htab
->got_info
;
3048 if (g
->bfd2got
&& ibfd
)
3050 struct mips_got_entry e
, *p
;
3052 BFD_ASSERT (h
->dynindx
>= 0);
3054 g
= mips_elf_got_for_ibfd (g
, ibfd
);
3055 if (g
->next
!= gg
|| TLS_RELOC_P (r_type
))
3059 e
.d
.h
= (struct mips_elf_link_hash_entry
*)h
;
3062 p
= htab_find (g
->got_entries
, &e
);
3064 BFD_ASSERT (p
->gotidx
> 0);
3066 if (TLS_RELOC_P (r_type
))
3068 bfd_vma value
= MINUS_ONE
;
3069 if ((h
->root
.type
== bfd_link_hash_defined
3070 || h
->root
.type
== bfd_link_hash_defweak
)
3071 && h
->root
.u
.def
.section
->output_section
)
3072 value
= (h
->root
.u
.def
.value
3073 + h
->root
.u
.def
.section
->output_offset
3074 + h
->root
.u
.def
.section
->output_section
->vma
);
3076 return mips_tls_got_index (abfd
, p
->gotidx
, &p
->tls_type
, r_type
,
3077 info
, e
.d
.h
, value
);
3084 if (gg
->global_gotsym
!= NULL
)
3085 global_got_dynindx
= gg
->global_gotsym
->dynindx
;
3087 if (TLS_RELOC_P (r_type
))
3089 struct mips_elf_link_hash_entry
*hm
3090 = (struct mips_elf_link_hash_entry
*) h
;
3091 bfd_vma value
= MINUS_ONE
;
3093 if ((h
->root
.type
== bfd_link_hash_defined
3094 || h
->root
.type
== bfd_link_hash_defweak
)
3095 && h
->root
.u
.def
.section
->output_section
)
3096 value
= (h
->root
.u
.def
.value
3097 + h
->root
.u
.def
.section
->output_offset
3098 + h
->root
.u
.def
.section
->output_section
->vma
);
3100 index
= mips_tls_got_index (abfd
, hm
->tls_got_offset
, &hm
->tls_type
,
3101 r_type
, info
, hm
, value
);
3105 /* Once we determine the global GOT entry with the lowest dynamic
3106 symbol table index, we must put all dynamic symbols with greater
3107 indices into the GOT. That makes it easy to calculate the GOT
3109 BFD_ASSERT (h
->dynindx
>= global_got_dynindx
);
3110 index
= ((h
->dynindx
- global_got_dynindx
+ g
->local_gotno
)
3111 * MIPS_ELF_GOT_SIZE (abfd
));
3113 BFD_ASSERT (index
< htab
->sgot
->size
);
3118 /* Find a GOT page entry that points to within 32KB of VALUE. These
3119 entries are supposed to be placed at small offsets in the GOT, i.e.,
3120 within 32KB of GP. Return the index of the GOT entry, or -1 if no
3121 entry could be created. If OFFSETP is nonnull, use it to return the
3122 offset of the GOT entry from VALUE. */
3125 mips_elf_got_page (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3126 bfd_vma value
, bfd_vma
*offsetp
)
3128 bfd_vma page
, index
;
3129 struct mips_got_entry
*entry
;
3131 page
= (value
+ 0x8000) & ~(bfd_vma
) 0xffff;
3132 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, page
, 0,
3133 NULL
, R_MIPS_GOT_PAGE
);
3138 index
= entry
->gotidx
;
3141 *offsetp
= value
- entry
->d
.address
;
3146 /* Find a local GOT entry for an R_MIPS*_GOT16 relocation against VALUE.
3147 EXTERNAL is true if the relocation was against a global symbol
3148 that has been forced local. */
3151 mips_elf_got16_entry (bfd
*abfd
, bfd
*ibfd
, struct bfd_link_info
*info
,
3152 bfd_vma value
, bfd_boolean external
)
3154 struct mips_got_entry
*entry
;
3156 /* GOT16 relocations against local symbols are followed by a LO16
3157 relocation; those against global symbols are not. Thus if the
3158 symbol was originally local, the GOT16 relocation should load the
3159 equivalent of %hi(VALUE), otherwise it should load VALUE itself. */
3161 value
= mips_elf_high (value
) << 16;
3163 /* It doesn't matter whether the original relocation was R_MIPS_GOT16,
3164 R_MIPS16_GOT16, R_MIPS_CALL16, etc. The format of the entry is the
3165 same in all cases. */
3166 entry
= mips_elf_create_local_got_entry (abfd
, info
, ibfd
, value
, 0,
3167 NULL
, R_MIPS_GOT16
);
3169 return entry
->gotidx
;
3174 /* Returns the offset for the entry at the INDEXth position
3178 mips_elf_got_offset_from_index (struct bfd_link_info
*info
, bfd
*output_bfd
,
3179 bfd
*input_bfd
, bfd_vma index
)
3181 struct mips_elf_link_hash_table
*htab
;
3185 htab
= mips_elf_hash_table (info
);
3187 gp
= _bfd_get_gp_value (output_bfd
)
3188 + mips_elf_adjust_gp (output_bfd
, htab
->got_info
, input_bfd
);
3190 return sgot
->output_section
->vma
+ sgot
->output_offset
+ index
- gp
;
3193 /* Create and return a local GOT entry for VALUE, which was calculated
3194 from a symbol belonging to INPUT_SECTON. Return NULL if it could not
3195 be created. If R_SYMNDX refers to a TLS symbol, create a TLS entry
3198 static struct mips_got_entry
*
3199 mips_elf_create_local_got_entry (bfd
*abfd
, struct bfd_link_info
*info
,
3200 bfd
*ibfd
, bfd_vma value
,
3201 unsigned long r_symndx
,
3202 struct mips_elf_link_hash_entry
*h
,
3205 struct mips_got_entry entry
, **loc
;
3206 struct mips_got_info
*g
;
3207 struct mips_elf_link_hash_table
*htab
;
3209 htab
= mips_elf_hash_table (info
);
3213 entry
.d
.address
= value
;
3216 g
= mips_elf_got_for_ibfd (htab
->got_info
, ibfd
);
3219 g
= mips_elf_got_for_ibfd (htab
->got_info
, abfd
);
3220 BFD_ASSERT (g
!= NULL
);
3223 /* We might have a symbol, H, if it has been forced local. Use the
3224 global entry then. It doesn't matter whether an entry is local
3225 or global for TLS, since the dynamic linker does not
3226 automatically relocate TLS GOT entries. */
3227 BFD_ASSERT (h
== NULL
|| h
->root
.forced_local
);
3228 if (TLS_RELOC_P (r_type
))
3230 struct mips_got_entry
*p
;
3233 if (r_type
== R_MIPS_TLS_LDM
)
3235 entry
.tls_type
= GOT_TLS_LDM
;
3241 entry
.symndx
= r_symndx
;
3247 p
= (struct mips_got_entry
*)
3248 htab_find (g
->got_entries
, &entry
);
3254 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
3259 entry
.gotidx
= MIPS_ELF_GOT_SIZE (abfd
) * g
->assigned_gotno
++;
3262 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3267 memcpy (*loc
, &entry
, sizeof entry
);
3269 if (g
->assigned_gotno
> g
->local_gotno
)
3271 (*loc
)->gotidx
= -1;
3272 /* We didn't allocate enough space in the GOT. */
3273 (*_bfd_error_handler
)
3274 (_("not enough GOT space for local GOT entries"));
3275 bfd_set_error (bfd_error_bad_value
);
3279 MIPS_ELF_PUT_WORD (abfd
, value
,
3280 (htab
->sgot
->contents
+ entry
.gotidx
));
3282 /* These GOT entries need a dynamic relocation on VxWorks. */
3283 if (htab
->is_vxworks
)
3285 Elf_Internal_Rela outrel
;
3288 bfd_vma got_address
;
3290 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3291 got_address
= (htab
->sgot
->output_section
->vma
3292 + htab
->sgot
->output_offset
3295 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
3296 outrel
.r_offset
= got_address
;
3297 outrel
.r_info
= ELF32_R_INFO (STN_UNDEF
, R_MIPS_32
);
3298 outrel
.r_addend
= value
;
3299 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
3305 /* Return the number of dynamic section symbols required by OUTPUT_BFD.
3306 The number might be exact or a worst-case estimate, depending on how
3307 much information is available to elf_backend_omit_section_dynsym at
3308 the current linking stage. */
3310 static bfd_size_type
3311 count_section_dynsyms (bfd
*output_bfd
, struct bfd_link_info
*info
)
3313 bfd_size_type count
;
3316 if (info
->shared
|| elf_hash_table (info
)->is_relocatable_executable
)
3319 const struct elf_backend_data
*bed
;
3321 bed
= get_elf_backend_data (output_bfd
);
3322 for (p
= output_bfd
->sections
; p
; p
= p
->next
)
3323 if ((p
->flags
& SEC_EXCLUDE
) == 0
3324 && (p
->flags
& SEC_ALLOC
) != 0
3325 && !(*bed
->elf_backend_omit_section_dynsym
) (output_bfd
, info
, p
))
3331 /* Sort the dynamic symbol table so that symbols that need GOT entries
3332 appear towards the end. */
3335 mips_elf_sort_hash_table (bfd
*abfd
, struct bfd_link_info
*info
)
3337 struct mips_elf_link_hash_table
*htab
;
3338 struct mips_elf_hash_sort_data hsd
;
3339 struct mips_got_info
*g
;
3341 if (elf_hash_table (info
)->dynsymcount
== 0)
3344 htab
= mips_elf_hash_table (info
);
3350 hsd
.max_unref_got_dynindx
3351 = hsd
.min_got_dynindx
3352 = (elf_hash_table (info
)->dynsymcount
- g
->reloc_only_gotno
);
3353 hsd
.max_non_got_dynindx
= count_section_dynsyms (abfd
, info
) + 1;
3354 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table
*)
3355 elf_hash_table (info
)),
3356 mips_elf_sort_hash_table_f
,
3359 /* There should have been enough room in the symbol table to
3360 accommodate both the GOT and non-GOT symbols. */
3361 BFD_ASSERT (hsd
.max_non_got_dynindx
<= hsd
.min_got_dynindx
);
3362 BFD_ASSERT ((unsigned long) hsd
.max_unref_got_dynindx
3363 == elf_hash_table (info
)->dynsymcount
);
3364 BFD_ASSERT (elf_hash_table (info
)->dynsymcount
- hsd
.min_got_dynindx
3365 == g
->global_gotno
);
3367 /* Now we know which dynamic symbol has the lowest dynamic symbol
3368 table index in the GOT. */
3369 g
->global_gotsym
= hsd
.low
;
3374 /* If H needs a GOT entry, assign it the highest available dynamic
3375 index. Otherwise, assign it the lowest available dynamic
3379 mips_elf_sort_hash_table_f (struct mips_elf_link_hash_entry
*h
, void *data
)
3381 struct mips_elf_hash_sort_data
*hsd
= data
;
3383 if (h
->root
.root
.type
== bfd_link_hash_warning
)
3384 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3386 /* Symbols without dynamic symbol table entries aren't interesting
3388 if (h
->root
.dynindx
== -1)
3391 switch (h
->global_got_area
)
3394 h
->root
.dynindx
= hsd
->max_non_got_dynindx
++;
3398 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
3400 h
->root
.dynindx
= --hsd
->min_got_dynindx
;
3401 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3404 case GGA_RELOC_ONLY
:
3405 BFD_ASSERT (h
->tls_type
== GOT_NORMAL
);
3407 if (hsd
->max_unref_got_dynindx
== hsd
->min_got_dynindx
)
3408 hsd
->low
= (struct elf_link_hash_entry
*) h
;
3409 h
->root
.dynindx
= hsd
->max_unref_got_dynindx
++;
3416 /* If H is a symbol that needs a global GOT entry, but has a dynamic
3417 symbol table index lower than any we've seen to date, record it for
3421 mips_elf_record_global_got_symbol (struct elf_link_hash_entry
*h
,
3422 bfd
*abfd
, struct bfd_link_info
*info
,
3423 unsigned char tls_flag
)
3425 struct mips_elf_link_hash_table
*htab
;
3426 struct mips_elf_link_hash_entry
*hmips
;
3427 struct mips_got_entry entry
, **loc
;
3428 struct mips_got_info
*g
;
3430 htab
= mips_elf_hash_table (info
);
3431 hmips
= (struct mips_elf_link_hash_entry
*) h
;
3433 /* A global symbol in the GOT must also be in the dynamic symbol
3435 if (h
->dynindx
== -1)
3437 switch (ELF_ST_VISIBILITY (h
->other
))
3441 _bfd_elf_link_hash_hide_symbol (info
, h
, TRUE
);
3444 if (!bfd_elf_link_record_dynamic_symbol (info
, h
))
3448 /* Make sure we have a GOT to put this entry into. */
3450 BFD_ASSERT (g
!= NULL
);
3454 entry
.d
.h
= (struct mips_elf_link_hash_entry
*) h
;
3457 loc
= (struct mips_got_entry
**) htab_find_slot (g
->got_entries
, &entry
,
3460 /* If we've already marked this entry as needing GOT space, we don't
3461 need to do it again. */
3464 (*loc
)->tls_type
|= tls_flag
;
3468 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3474 entry
.tls_type
= tls_flag
;
3476 memcpy (*loc
, &entry
, sizeof entry
);
3479 hmips
->global_got_area
= GGA_NORMAL
;
3484 /* Reserve space in G for a GOT entry containing the value of symbol
3485 SYMNDX in input bfd ABDF, plus ADDEND. */
3488 mips_elf_record_local_got_symbol (bfd
*abfd
, long symndx
, bfd_vma addend
,
3489 struct bfd_link_info
*info
,
3490 unsigned char tls_flag
)
3492 struct mips_elf_link_hash_table
*htab
;
3493 struct mips_got_info
*g
;
3494 struct mips_got_entry entry
, **loc
;
3496 htab
= mips_elf_hash_table (info
);
3498 BFD_ASSERT (g
!= NULL
);
3501 entry
.symndx
= symndx
;
3502 entry
.d
.addend
= addend
;
3503 entry
.tls_type
= tls_flag
;
3504 loc
= (struct mips_got_entry
**)
3505 htab_find_slot (g
->got_entries
, &entry
, INSERT
);
3509 if (tls_flag
== GOT_TLS_GD
&& !((*loc
)->tls_type
& GOT_TLS_GD
))
3512 (*loc
)->tls_type
|= tls_flag
;
3514 else if (tls_flag
== GOT_TLS_IE
&& !((*loc
)->tls_type
& GOT_TLS_IE
))
3517 (*loc
)->tls_type
|= tls_flag
;
3525 entry
.tls_type
= tls_flag
;
3526 if (tls_flag
== GOT_TLS_IE
)
3528 else if (tls_flag
== GOT_TLS_GD
)
3530 else if (g
->tls_ldm_offset
== MINUS_ONE
)
3532 g
->tls_ldm_offset
= MINUS_TWO
;
3538 entry
.gotidx
= g
->local_gotno
++;
3542 *loc
= (struct mips_got_entry
*)bfd_alloc (abfd
, sizeof entry
);
3547 memcpy (*loc
, &entry
, sizeof entry
);
3552 /* Return the maximum number of GOT page entries required for RANGE. */
3555 mips_elf_pages_for_range (const struct mips_got_page_range
*range
)
3557 return (range
->max_addend
- range
->min_addend
+ 0x1ffff) >> 16;
3560 /* Record that ABFD has a page relocation against symbol SYMNDX and
3561 that ADDEND is the addend for that relocation.
3563 This function creates an upper bound on the number of GOT slots
3564 required; no attempt is made to combine references to non-overridable
3565 global symbols across multiple input files. */
3568 mips_elf_record_got_page_entry (struct bfd_link_info
*info
, bfd
*abfd
,
3569 long symndx
, bfd_signed_vma addend
)
3571 struct mips_elf_link_hash_table
*htab
;
3572 struct mips_got_info
*g
;
3573 struct mips_got_page_entry lookup
, *entry
;
3574 struct mips_got_page_range
**range_ptr
, *range
;
3575 bfd_vma old_pages
, new_pages
;
3578 htab
= mips_elf_hash_table (info
);
3580 BFD_ASSERT (g
!= NULL
);
3582 /* Find the mips_got_page_entry hash table entry for this symbol. */
3584 lookup
.symndx
= symndx
;
3585 loc
= htab_find_slot (g
->got_page_entries
, &lookup
, INSERT
);
3589 /* Create a mips_got_page_entry if this is the first time we've
3591 entry
= (struct mips_got_page_entry
*) *loc
;
3594 entry
= bfd_alloc (abfd
, sizeof (*entry
));
3599 entry
->symndx
= symndx
;
3600 entry
->ranges
= NULL
;
3601 entry
->num_pages
= 0;
3605 /* Skip over ranges whose maximum extent cannot share a page entry
3607 range_ptr
= &entry
->ranges
;
3608 while (*range_ptr
&& addend
> (*range_ptr
)->max_addend
+ 0xffff)
3609 range_ptr
= &(*range_ptr
)->next
;
3611 /* If we scanned to the end of the list, or found a range whose
3612 minimum extent cannot share a page entry with ADDEND, create
3613 a new singleton range. */
3615 if (!range
|| addend
< range
->min_addend
- 0xffff)
3617 range
= bfd_alloc (abfd
, sizeof (*range
));
3621 range
->next
= *range_ptr
;
3622 range
->min_addend
= addend
;
3623 range
->max_addend
= addend
;
3631 /* Remember how many pages the old range contributed. */
3632 old_pages
= mips_elf_pages_for_range (range
);
3634 /* Update the ranges. */
3635 if (addend
< range
->min_addend
)
3636 range
->min_addend
= addend
;
3637 else if (addend
> range
->max_addend
)
3639 if (range
->next
&& addend
>= range
->next
->min_addend
- 0xffff)
3641 old_pages
+= mips_elf_pages_for_range (range
->next
);
3642 range
->max_addend
= range
->next
->max_addend
;
3643 range
->next
= range
->next
->next
;
3646 range
->max_addend
= addend
;
3649 /* Record any change in the total estimate. */
3650 new_pages
= mips_elf_pages_for_range (range
);
3651 if (old_pages
!= new_pages
)
3653 entry
->num_pages
+= new_pages
- old_pages
;
3654 g
->page_gotno
+= new_pages
- old_pages
;
3660 /* Add room for N relocations to the .rel(a).dyn section in ABFD. */
3663 mips_elf_allocate_dynamic_relocations (bfd
*abfd
, struct bfd_link_info
*info
,
3667 struct mips_elf_link_hash_table
*htab
;
3669 htab
= mips_elf_hash_table (info
);
3670 s
= mips_elf_rel_dyn_section (info
, FALSE
);
3671 BFD_ASSERT (s
!= NULL
);
3673 if (htab
->is_vxworks
)
3674 s
->size
+= n
* MIPS_ELF_RELA_SIZE (abfd
);
3679 /* Make room for a null element. */
3680 s
->size
+= MIPS_ELF_REL_SIZE (abfd
);
3683 s
->size
+= n
* MIPS_ELF_REL_SIZE (abfd
);
3687 /* A htab_traverse callback for GOT entries. Set boolean *DATA to true
3688 if the GOT entry is for an indirect or warning symbol. */
3691 mips_elf_check_recreate_got (void **entryp
, void *data
)
3693 struct mips_got_entry
*entry
;
3694 bfd_boolean
*must_recreate
;
3696 entry
= (struct mips_got_entry
*) *entryp
;
3697 must_recreate
= (bfd_boolean
*) data
;
3698 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3700 struct mips_elf_link_hash_entry
*h
;
3703 if (h
->root
.root
.type
== bfd_link_hash_indirect
3704 || h
->root
.root
.type
== bfd_link_hash_warning
)
3706 *must_recreate
= TRUE
;
3713 /* A htab_traverse callback for GOT entries. Add all entries to
3714 hash table *DATA, converting entries for indirect and warning
3715 symbols into entries for the target symbol. Set *DATA to null
3719 mips_elf_recreate_got (void **entryp
, void *data
)
3722 struct mips_got_entry
*entry
;
3725 new_got
= (htab_t
*) data
;
3726 entry
= (struct mips_got_entry
*) *entryp
;
3727 if (entry
->abfd
!= NULL
&& entry
->symndx
== -1)
3729 struct mips_elf_link_hash_entry
*h
;
3732 while (h
->root
.root
.type
== bfd_link_hash_indirect
3733 || h
->root
.root
.type
== bfd_link_hash_warning
)
3735 BFD_ASSERT (h
->global_got_area
== GGA_NONE
);
3736 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
3740 slot
= htab_find_slot (*new_got
, entry
, INSERT
);
3753 /* If any entries in G->got_entries are for indirect or warning symbols,
3754 replace them with entries for the target symbol. */
3757 mips_elf_resolve_final_got_entries (struct mips_got_info
*g
)
3759 bfd_boolean must_recreate
;
3762 must_recreate
= FALSE
;
3763 htab_traverse (g
->got_entries
, mips_elf_check_recreate_got
, &must_recreate
);
3766 new_got
= htab_create (htab_size (g
->got_entries
),
3767 mips_elf_got_entry_hash
,
3768 mips_elf_got_entry_eq
, NULL
);
3769 htab_traverse (g
->got_entries
, mips_elf_recreate_got
, &new_got
);
3770 if (new_got
== NULL
)
3773 /* Each entry in g->got_entries has either been copied to new_got
3774 or freed. Now delete the hash table itself. */
3775 htab_delete (g
->got_entries
);
3776 g
->got_entries
= new_got
;
3781 /* A mips_elf_link_hash_traverse callback for which DATA points
3782 to a mips_got_info. Count the number of type (3) entries. */
3785 mips_elf_count_got_symbols (struct mips_elf_link_hash_entry
*h
, void *data
)
3787 struct mips_got_info
*g
;
3789 g
= (struct mips_got_info
*) data
;
3790 if (h
->global_got_area
!= GGA_NONE
)
3792 if (h
->root
.forced_local
|| h
->root
.dynindx
== -1)
3794 /* We no longer need this entry if it was only used for
3795 relocations; those relocations will be against the
3796 null or section symbol instead of H. */
3797 if (h
->global_got_area
!= GGA_RELOC_ONLY
)
3799 h
->global_got_area
= GGA_NONE
;
3804 if (h
->global_got_area
== GGA_RELOC_ONLY
)
3805 g
->reloc_only_gotno
++;
3811 /* Compute the hash value of the bfd in a bfd2got hash entry. */
3814 mips_elf_bfd2got_entry_hash (const void *entry_
)
3816 const struct mips_elf_bfd2got_hash
*entry
3817 = (struct mips_elf_bfd2got_hash
*)entry_
;
3819 return entry
->bfd
->id
;
3822 /* Check whether two hash entries have the same bfd. */
3825 mips_elf_bfd2got_entry_eq (const void *entry1
, const void *entry2
)
3827 const struct mips_elf_bfd2got_hash
*e1
3828 = (const struct mips_elf_bfd2got_hash
*)entry1
;
3829 const struct mips_elf_bfd2got_hash
*e2
3830 = (const struct mips_elf_bfd2got_hash
*)entry2
;
3832 return e1
->bfd
== e2
->bfd
;
3835 /* In a multi-got link, determine the GOT to be used for IBFD. G must
3836 be the master GOT data. */
3838 static struct mips_got_info
*
3839 mips_elf_got_for_ibfd (struct mips_got_info
*g
, bfd
*ibfd
)
3841 struct mips_elf_bfd2got_hash e
, *p
;
3847 p
= htab_find (g
->bfd2got
, &e
);
3848 return p
? p
->g
: NULL
;
3851 /* Use BFD2GOT to find ABFD's got entry, creating one if none exists.
3852 Return NULL if an error occured. */
3854 static struct mips_got_info
*
3855 mips_elf_get_got_for_bfd (struct htab
*bfd2got
, bfd
*output_bfd
,
3858 struct mips_elf_bfd2got_hash bfdgot_entry
, *bfdgot
;
3859 struct mips_got_info
*g
;
3862 bfdgot_entry
.bfd
= input_bfd
;
3863 bfdgotp
= htab_find_slot (bfd2got
, &bfdgot_entry
, INSERT
);
3864 bfdgot
= (struct mips_elf_bfd2got_hash
*) *bfdgotp
;
3868 bfdgot
= ((struct mips_elf_bfd2got_hash
*)
3869 bfd_alloc (output_bfd
, sizeof (struct mips_elf_bfd2got_hash
)));
3875 g
= ((struct mips_got_info
*)
3876 bfd_alloc (output_bfd
, sizeof (struct mips_got_info
)));
3880 bfdgot
->bfd
= input_bfd
;
3883 g
->global_gotsym
= NULL
;
3884 g
->global_gotno
= 0;
3885 g
->reloc_only_gotno
= 0;
3888 g
->assigned_gotno
= -1;
3890 g
->tls_assigned_gotno
= 0;
3891 g
->tls_ldm_offset
= MINUS_ONE
;
3892 g
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
3893 mips_elf_multi_got_entry_eq
, NULL
);
3894 if (g
->got_entries
== NULL
)
3897 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
3898 mips_got_page_entry_eq
, NULL
);
3899 if (g
->got_page_entries
== NULL
)
3909 /* A htab_traverse callback for the entries in the master got.
3910 Create one separate got for each bfd that has entries in the global
3911 got, such that we can tell how many local and global entries each
3915 mips_elf_make_got_per_bfd (void **entryp
, void *p
)
3917 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
3918 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
3919 struct mips_got_info
*g
;
3921 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
3928 /* Insert the GOT entry in the bfd's got entry hash table. */
3929 entryp
= htab_find_slot (g
->got_entries
, entry
, INSERT
);
3930 if (*entryp
!= NULL
)
3935 if (entry
->tls_type
)
3937 if (entry
->tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
3939 if (entry
->tls_type
& GOT_TLS_IE
)
3942 else if (entry
->symndx
>= 0 || entry
->d
.h
->root
.forced_local
)
3950 /* A htab_traverse callback for the page entries in the master got.
3951 Associate each page entry with the bfd's got. */
3954 mips_elf_make_got_pages_per_bfd (void **entryp
, void *p
)
3956 struct mips_got_page_entry
*entry
= (struct mips_got_page_entry
*) *entryp
;
3957 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*) p
;
3958 struct mips_got_info
*g
;
3960 g
= mips_elf_get_got_for_bfd (arg
->bfd2got
, arg
->obfd
, entry
->abfd
);
3967 /* Insert the GOT entry in the bfd's got entry hash table. */
3968 entryp
= htab_find_slot (g
->got_page_entries
, entry
, INSERT
);
3969 if (*entryp
!= NULL
)
3973 g
->page_gotno
+= entry
->num_pages
;
3977 /* Consider merging the got described by BFD2GOT with TO, using the
3978 information given by ARG. Return -1 if this would lead to overflow,
3979 1 if they were merged successfully, and 0 if a merge failed due to
3980 lack of memory. (These values are chosen so that nonnegative return
3981 values can be returned by a htab_traverse callback.) */
3984 mips_elf_merge_got_with (struct mips_elf_bfd2got_hash
*bfd2got
,
3985 struct mips_got_info
*to
,
3986 struct mips_elf_got_per_bfd_arg
*arg
)
3988 struct mips_got_info
*from
= bfd2got
->g
;
3989 unsigned int estimate
;
3991 /* Work out how many page entries we would need for the combined GOT. */
3992 estimate
= arg
->max_pages
;
3993 if (estimate
>= from
->page_gotno
+ to
->page_gotno
)
3994 estimate
= from
->page_gotno
+ to
->page_gotno
;
3996 /* And conservatively estimate how many local, global and TLS entries
3998 estimate
+= (from
->local_gotno
3999 + from
->global_gotno
4005 /* Bail out if the combined GOT might be too big. */
4006 if (estimate
> arg
->max_count
)
4009 /* Commit to the merge. Record that TO is now the bfd for this got. */
4012 /* Transfer the bfd's got information from FROM to TO. */
4013 htab_traverse (from
->got_entries
, mips_elf_make_got_per_bfd
, arg
);
4014 if (arg
->obfd
== NULL
)
4017 htab_traverse (from
->got_page_entries
, mips_elf_make_got_pages_per_bfd
, arg
);
4018 if (arg
->obfd
== NULL
)
4021 /* We don't have to worry about releasing memory of the actual
4022 got entries, since they're all in the master got_entries hash
4024 htab_delete (from
->got_entries
);
4025 htab_delete (from
->got_page_entries
);
4029 /* Attempt to merge gots of different input bfds. Try to use as much
4030 as possible of the primary got, since it doesn't require explicit
4031 dynamic relocations, but don't use bfds that would reference global
4032 symbols out of the addressable range. Failing the primary got,
4033 attempt to merge with the current got, or finish the current got
4034 and then make make the new got current. */
4037 mips_elf_merge_gots (void **bfd2got_
, void *p
)
4039 struct mips_elf_bfd2got_hash
*bfd2got
4040 = (struct mips_elf_bfd2got_hash
*)*bfd2got_
;
4041 struct mips_elf_got_per_bfd_arg
*arg
= (struct mips_elf_got_per_bfd_arg
*)p
;
4042 struct mips_got_info
*g
;
4043 unsigned int estimate
;
4048 /* Work out the number of page, local and TLS entries. */
4049 estimate
= arg
->max_pages
;
4050 if (estimate
> g
->page_gotno
)
4051 estimate
= g
->page_gotno
;
4052 estimate
+= g
->local_gotno
+ g
->tls_gotno
;
4054 /* We place TLS GOT entries after both locals and globals. The globals
4055 for the primary GOT may overflow the normal GOT size limit, so be
4056 sure not to merge a GOT which requires TLS with the primary GOT in that
4057 case. This doesn't affect non-primary GOTs. */
4058 estimate
+= (g
->tls_gotno
> 0 ? arg
->global_count
: g
->global_gotno
);
4060 if (estimate
<= arg
->max_count
)
4062 /* If we don't have a primary GOT, use it as
4063 a starting point for the primary GOT. */
4066 arg
->primary
= bfd2got
->g
;
4070 /* Try merging with the primary GOT. */
4071 result
= mips_elf_merge_got_with (bfd2got
, arg
->primary
, arg
);
4076 /* If we can merge with the last-created got, do it. */
4079 result
= mips_elf_merge_got_with (bfd2got
, arg
->current
, arg
);
4084 /* Well, we couldn't merge, so create a new GOT. Don't check if it
4085 fits; if it turns out that it doesn't, we'll get relocation
4086 overflows anyway. */
4087 g
->next
= arg
->current
;
4093 /* Set the TLS GOT index for the GOT entry in ENTRYP. ENTRYP's NEXT field
4094 is null iff there is just a single GOT. */
4097 mips_elf_initialize_tls_index (void **entryp
, void *p
)
4099 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
4100 struct mips_got_info
*g
= p
;
4102 unsigned char tls_type
;
4104 /* We're only interested in TLS symbols. */
4105 if (entry
->tls_type
== 0)
4108 next_index
= MIPS_ELF_GOT_SIZE (entry
->abfd
) * (long) g
->tls_assigned_gotno
;
4110 if (entry
->symndx
== -1 && g
->next
== NULL
)
4112 /* A type (3) got entry in the single-GOT case. We use the symbol's
4113 hash table entry to track its index. */
4114 if (entry
->d
.h
->tls_type
& GOT_TLS_OFFSET_DONE
)
4116 entry
->d
.h
->tls_type
|= GOT_TLS_OFFSET_DONE
;
4117 entry
->d
.h
->tls_got_offset
= next_index
;
4118 tls_type
= entry
->d
.h
->tls_type
;
4122 if (entry
->tls_type
& GOT_TLS_LDM
)
4124 /* There are separate mips_got_entry objects for each input bfd
4125 that requires an LDM entry. Make sure that all LDM entries in
4126 a GOT resolve to the same index. */
4127 if (g
->tls_ldm_offset
!= MINUS_TWO
&& g
->tls_ldm_offset
!= MINUS_ONE
)
4129 entry
->gotidx
= g
->tls_ldm_offset
;
4132 g
->tls_ldm_offset
= next_index
;
4134 entry
->gotidx
= next_index
;
4135 tls_type
= entry
->tls_type
;
4138 /* Account for the entries we've just allocated. */
4139 if (tls_type
& (GOT_TLS_GD
| GOT_TLS_LDM
))
4140 g
->tls_assigned_gotno
+= 2;
4141 if (tls_type
& GOT_TLS_IE
)
4142 g
->tls_assigned_gotno
+= 1;
4147 /* If passed a NULL mips_got_info in the argument, set the marker used
4148 to tell whether a global symbol needs a got entry (in the primary
4149 got) to the given VALUE.
4151 If passed a pointer G to a mips_got_info in the argument (it must
4152 not be the primary GOT), compute the offset from the beginning of
4153 the (primary) GOT section to the entry in G corresponding to the
4154 global symbol. G's assigned_gotno must contain the index of the
4155 first available global GOT entry in G. VALUE must contain the size
4156 of a GOT entry in bytes. For each global GOT entry that requires a
4157 dynamic relocation, NEEDED_RELOCS is incremented, and the symbol is
4158 marked as not eligible for lazy resolution through a function
4161 mips_elf_set_global_got_offset (void **entryp
, void *p
)
4163 struct mips_got_entry
*entry
= (struct mips_got_entry
*)*entryp
;
4164 struct mips_elf_set_global_got_offset_arg
*arg
4165 = (struct mips_elf_set_global_got_offset_arg
*)p
;
4166 struct mips_got_info
*g
= arg
->g
;
4168 if (g
&& entry
->tls_type
!= GOT_NORMAL
)
4169 arg
->needed_relocs
+=
4170 mips_tls_got_relocs (arg
->info
, entry
->tls_type
,
4171 entry
->symndx
== -1 ? &entry
->d
.h
->root
: NULL
);
4173 if (entry
->abfd
!= NULL
4174 && entry
->symndx
== -1
4175 && entry
->d
.h
->global_got_area
!= GGA_NONE
)
4179 BFD_ASSERT (g
->global_gotsym
== NULL
);
4181 entry
->gotidx
= arg
->value
* (long) g
->assigned_gotno
++;
4182 if (arg
->info
->shared
4183 || (elf_hash_table (arg
->info
)->dynamic_sections_created
4184 && entry
->d
.h
->root
.def_dynamic
4185 && !entry
->d
.h
->root
.def_regular
))
4186 ++arg
->needed_relocs
;
4189 entry
->d
.h
->global_got_area
= arg
->value
;
4195 /* A htab_traverse callback for GOT entries for which DATA is the
4196 bfd_link_info. Forbid any global symbols from having traditional
4197 lazy-binding stubs. */
4200 mips_elf_forbid_lazy_stubs (void **entryp
, void *data
)
4202 struct bfd_link_info
*info
;
4203 struct mips_elf_link_hash_table
*htab
;
4204 struct mips_got_entry
*entry
;
4206 entry
= (struct mips_got_entry
*) *entryp
;
4207 info
= (struct bfd_link_info
*) data
;
4208 htab
= mips_elf_hash_table (info
);
4209 if (entry
->abfd
!= NULL
4210 && entry
->symndx
== -1
4211 && entry
->d
.h
->needs_lazy_stub
)
4213 entry
->d
.h
->needs_lazy_stub
= FALSE
;
4214 htab
->lazy_stub_count
--;
4220 /* Return the offset of an input bfd IBFD's GOT from the beginning of
4223 mips_elf_adjust_gp (bfd
*abfd
, struct mips_got_info
*g
, bfd
*ibfd
)
4225 if (g
->bfd2got
== NULL
)
4228 g
= mips_elf_got_for_ibfd (g
, ibfd
);
4232 BFD_ASSERT (g
->next
);
4236 return (g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
)
4237 * MIPS_ELF_GOT_SIZE (abfd
);
4240 /* Turn a single GOT that is too big for 16-bit addressing into
4241 a sequence of GOTs, each one 16-bit addressable. */
4244 mips_elf_multi_got (bfd
*abfd
, struct bfd_link_info
*info
,
4245 asection
*got
, bfd_size_type pages
)
4247 struct mips_elf_link_hash_table
*htab
;
4248 struct mips_elf_got_per_bfd_arg got_per_bfd_arg
;
4249 struct mips_elf_set_global_got_offset_arg set_got_offset_arg
;
4250 struct mips_got_info
*g
, *gg
;
4251 unsigned int assign
, needed_relocs
;
4254 dynobj
= elf_hash_table (info
)->dynobj
;
4255 htab
= mips_elf_hash_table (info
);
4257 g
->bfd2got
= htab_try_create (1, mips_elf_bfd2got_entry_hash
,
4258 mips_elf_bfd2got_entry_eq
, NULL
);
4259 if (g
->bfd2got
== NULL
)
4262 got_per_bfd_arg
.bfd2got
= g
->bfd2got
;
4263 got_per_bfd_arg
.obfd
= abfd
;
4264 got_per_bfd_arg
.info
= info
;
4266 /* Count how many GOT entries each input bfd requires, creating a
4267 map from bfd to got info while at that. */
4268 htab_traverse (g
->got_entries
, mips_elf_make_got_per_bfd
, &got_per_bfd_arg
);
4269 if (got_per_bfd_arg
.obfd
== NULL
)
4272 /* Also count how many page entries each input bfd requires. */
4273 htab_traverse (g
->got_page_entries
, mips_elf_make_got_pages_per_bfd
,
4275 if (got_per_bfd_arg
.obfd
== NULL
)
4278 got_per_bfd_arg
.current
= NULL
;
4279 got_per_bfd_arg
.primary
= NULL
;
4280 got_per_bfd_arg
.max_count
= ((MIPS_ELF_GOT_MAX_SIZE (info
)
4281 / MIPS_ELF_GOT_SIZE (abfd
))
4282 - htab
->reserved_gotno
);
4283 got_per_bfd_arg
.max_pages
= pages
;
4284 /* The number of globals that will be included in the primary GOT.
4285 See the calls to mips_elf_set_global_got_offset below for more
4287 got_per_bfd_arg
.global_count
= g
->global_gotno
;
4289 /* Try to merge the GOTs of input bfds together, as long as they
4290 don't seem to exceed the maximum GOT size, choosing one of them
4291 to be the primary GOT. */
4292 htab_traverse (g
->bfd2got
, mips_elf_merge_gots
, &got_per_bfd_arg
);
4293 if (got_per_bfd_arg
.obfd
== NULL
)
4296 /* If we do not find any suitable primary GOT, create an empty one. */
4297 if (got_per_bfd_arg
.primary
== NULL
)
4299 g
->next
= (struct mips_got_info
*)
4300 bfd_alloc (abfd
, sizeof (struct mips_got_info
));
4301 if (g
->next
== NULL
)
4304 g
->next
->global_gotsym
= NULL
;
4305 g
->next
->global_gotno
= 0;
4306 g
->next
->reloc_only_gotno
= 0;
4307 g
->next
->local_gotno
= 0;
4308 g
->next
->page_gotno
= 0;
4309 g
->next
->tls_gotno
= 0;
4310 g
->next
->assigned_gotno
= 0;
4311 g
->next
->tls_assigned_gotno
= 0;
4312 g
->next
->tls_ldm_offset
= MINUS_ONE
;
4313 g
->next
->got_entries
= htab_try_create (1, mips_elf_multi_got_entry_hash
,
4314 mips_elf_multi_got_entry_eq
,
4316 if (g
->next
->got_entries
== NULL
)
4318 g
->next
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4319 mips_got_page_entry_eq
,
4321 if (g
->next
->got_page_entries
== NULL
)
4323 g
->next
->bfd2got
= NULL
;
4326 g
->next
= got_per_bfd_arg
.primary
;
4327 g
->next
->next
= got_per_bfd_arg
.current
;
4329 /* GG is now the master GOT, and G is the primary GOT. */
4333 /* Map the output bfd to the primary got. That's what we're going
4334 to use for bfds that use GOT16 or GOT_PAGE relocations that we
4335 didn't mark in check_relocs, and we want a quick way to find it.
4336 We can't just use gg->next because we're going to reverse the
4339 struct mips_elf_bfd2got_hash
*bfdgot
;
4342 bfdgot
= (struct mips_elf_bfd2got_hash
*)bfd_alloc
4343 (abfd
, sizeof (struct mips_elf_bfd2got_hash
));
4350 bfdgotp
= htab_find_slot (gg
->bfd2got
, bfdgot
, INSERT
);
4352 BFD_ASSERT (*bfdgotp
== NULL
);
4356 /* Every symbol that is referenced in a dynamic relocation must be
4357 present in the primary GOT, so arrange for them to appear after
4358 those that are actually referenced. */
4359 gg
->reloc_only_gotno
= gg
->global_gotno
- g
->global_gotno
;
4360 g
->global_gotno
= gg
->global_gotno
;
4362 set_got_offset_arg
.g
= NULL
;
4363 set_got_offset_arg
.value
= GGA_RELOC_ONLY
;
4364 htab_traverse (gg
->got_entries
, mips_elf_set_global_got_offset
,
4365 &set_got_offset_arg
);
4366 set_got_offset_arg
.value
= GGA_NORMAL
;
4367 htab_traverse (g
->got_entries
, mips_elf_set_global_got_offset
,
4368 &set_got_offset_arg
);
4370 /* Now go through the GOTs assigning them offset ranges.
4371 [assigned_gotno, local_gotno[ will be set to the range of local
4372 entries in each GOT. We can then compute the end of a GOT by
4373 adding local_gotno to global_gotno. We reverse the list and make
4374 it circular since then we'll be able to quickly compute the
4375 beginning of a GOT, by computing the end of its predecessor. To
4376 avoid special cases for the primary GOT, while still preserving
4377 assertions that are valid for both single- and multi-got links,
4378 we arrange for the main got struct to have the right number of
4379 global entries, but set its local_gotno such that the initial
4380 offset of the primary GOT is zero. Remember that the primary GOT
4381 will become the last item in the circular linked list, so it
4382 points back to the master GOT. */
4383 gg
->local_gotno
= -g
->global_gotno
;
4384 gg
->global_gotno
= g
->global_gotno
;
4391 struct mips_got_info
*gn
;
4393 assign
+= htab
->reserved_gotno
;
4394 g
->assigned_gotno
= assign
;
4395 g
->local_gotno
+= assign
;
4396 g
->local_gotno
+= (pages
< g
->page_gotno
? pages
: g
->page_gotno
);
4397 assign
= g
->local_gotno
+ g
->global_gotno
+ g
->tls_gotno
;
4399 /* Take g out of the direct list, and push it onto the reversed
4400 list that gg points to. g->next is guaranteed to be nonnull after
4401 this operation, as required by mips_elf_initialize_tls_index. */
4406 /* Set up any TLS entries. We always place the TLS entries after
4407 all non-TLS entries. */
4408 g
->tls_assigned_gotno
= g
->local_gotno
+ g
->global_gotno
;
4409 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
4411 /* Move onto the next GOT. It will be a secondary GOT if nonull. */
4414 /* Forbid global symbols in every non-primary GOT from having
4415 lazy-binding stubs. */
4417 htab_traverse (g
->got_entries
, mips_elf_forbid_lazy_stubs
, info
);
4421 got
->size
= (gg
->next
->local_gotno
4422 + gg
->next
->global_gotno
4423 + gg
->next
->tls_gotno
) * MIPS_ELF_GOT_SIZE (abfd
);
4426 set_got_offset_arg
.value
= MIPS_ELF_GOT_SIZE (abfd
);
4427 set_got_offset_arg
.info
= info
;
4428 for (g
= gg
->next
; g
&& g
->next
!= gg
; g
= g
->next
)
4430 unsigned int save_assign
;
4432 /* Assign offsets to global GOT entries. */
4433 save_assign
= g
->assigned_gotno
;
4434 g
->assigned_gotno
= g
->local_gotno
;
4435 set_got_offset_arg
.g
= g
;
4436 set_got_offset_arg
.needed_relocs
= 0;
4437 htab_traverse (g
->got_entries
,
4438 mips_elf_set_global_got_offset
,
4439 &set_got_offset_arg
);
4440 needed_relocs
+= set_got_offset_arg
.needed_relocs
;
4441 BFD_ASSERT (g
->assigned_gotno
- g
->local_gotno
<= g
->global_gotno
);
4443 g
->assigned_gotno
= save_assign
;
4446 needed_relocs
+= g
->local_gotno
- g
->assigned_gotno
;
4447 BFD_ASSERT (g
->assigned_gotno
== g
->next
->local_gotno
4448 + g
->next
->global_gotno
4449 + g
->next
->tls_gotno
4450 + htab
->reserved_gotno
);
4455 mips_elf_allocate_dynamic_relocations (dynobj
, info
,
4462 /* Returns the first relocation of type r_type found, beginning with
4463 RELOCATION. RELEND is one-past-the-end of the relocation table. */
4465 static const Elf_Internal_Rela
*
4466 mips_elf_next_relocation (bfd
*abfd ATTRIBUTE_UNUSED
, unsigned int r_type
,
4467 const Elf_Internal_Rela
*relocation
,
4468 const Elf_Internal_Rela
*relend
)
4470 unsigned long r_symndx
= ELF_R_SYM (abfd
, relocation
->r_info
);
4472 while (relocation
< relend
)
4474 if (ELF_R_TYPE (abfd
, relocation
->r_info
) == r_type
4475 && ELF_R_SYM (abfd
, relocation
->r_info
) == r_symndx
)
4481 /* We didn't find it. */
4485 /* Return whether a relocation is against a local symbol. */
4488 mips_elf_local_relocation_p (bfd
*input_bfd
,
4489 const Elf_Internal_Rela
*relocation
,
4490 asection
**local_sections
,
4491 bfd_boolean check_forced
)
4493 unsigned long r_symndx
;
4494 Elf_Internal_Shdr
*symtab_hdr
;
4495 struct mips_elf_link_hash_entry
*h
;
4498 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4499 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4500 extsymoff
= (elf_bad_symtab (input_bfd
)) ? 0 : symtab_hdr
->sh_info
;
4502 if (r_symndx
< extsymoff
)
4504 if (elf_bad_symtab (input_bfd
) && local_sections
[r_symndx
] != NULL
)
4509 /* Look up the hash table to check whether the symbol
4510 was forced local. */
4511 h
= (struct mips_elf_link_hash_entry
*)
4512 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
4513 /* Find the real hash-table entry for this symbol. */
4514 while (h
->root
.root
.type
== bfd_link_hash_indirect
4515 || h
->root
.root
.type
== bfd_link_hash_warning
)
4516 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4517 if (h
->root
.forced_local
)
4524 /* Sign-extend VALUE, which has the indicated number of BITS. */
4527 _bfd_mips_elf_sign_extend (bfd_vma value
, int bits
)
4529 if (value
& ((bfd_vma
) 1 << (bits
- 1)))
4530 /* VALUE is negative. */
4531 value
|= ((bfd_vma
) - 1) << bits
;
4536 /* Return non-zero if the indicated VALUE has overflowed the maximum
4537 range expressible by a signed number with the indicated number of
4541 mips_elf_overflow_p (bfd_vma value
, int bits
)
4543 bfd_signed_vma svalue
= (bfd_signed_vma
) value
;
4545 if (svalue
> (1 << (bits
- 1)) - 1)
4546 /* The value is too big. */
4548 else if (svalue
< -(1 << (bits
- 1)))
4549 /* The value is too small. */
4556 /* Calculate the %high function. */
4559 mips_elf_high (bfd_vma value
)
4561 return ((value
+ (bfd_vma
) 0x8000) >> 16) & 0xffff;
4564 /* Calculate the %higher function. */
4567 mips_elf_higher (bfd_vma value ATTRIBUTE_UNUSED
)
4570 return ((value
+ (bfd_vma
) 0x80008000) >> 32) & 0xffff;
4577 /* Calculate the %highest function. */
4580 mips_elf_highest (bfd_vma value ATTRIBUTE_UNUSED
)
4583 return ((value
+ (((bfd_vma
) 0x8000 << 32) | 0x80008000)) >> 48) & 0xffff;
4590 /* Create the .compact_rel section. */
4593 mips_elf_create_compact_rel_section
4594 (bfd
*abfd
, struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
4597 register asection
*s
;
4599 if (bfd_get_section_by_name (abfd
, ".compact_rel") == NULL
)
4601 flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
| SEC_LINKER_CREATED
4604 s
= bfd_make_section_with_flags (abfd
, ".compact_rel", flags
);
4606 || ! bfd_set_section_alignment (abfd
, s
,
4607 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
4610 s
->size
= sizeof (Elf32_External_compact_rel
);
4616 /* Create the .got section to hold the global offset table. */
4619 mips_elf_create_got_section (bfd
*abfd
, struct bfd_link_info
*info
)
4622 register asection
*s
;
4623 struct elf_link_hash_entry
*h
;
4624 struct bfd_link_hash_entry
*bh
;
4625 struct mips_got_info
*g
;
4627 struct mips_elf_link_hash_table
*htab
;
4629 htab
= mips_elf_hash_table (info
);
4631 /* This function may be called more than once. */
4635 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
4636 | SEC_LINKER_CREATED
);
4638 /* We have to use an alignment of 2**4 here because this is hardcoded
4639 in the function stub generation and in the linker script. */
4640 s
= bfd_make_section_with_flags (abfd
, ".got", flags
);
4642 || ! bfd_set_section_alignment (abfd
, s
, 4))
4646 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the
4647 linker script because we don't want to define the symbol if we
4648 are not creating a global offset table. */
4650 if (! (_bfd_generic_link_add_one_symbol
4651 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
,
4652 0, NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
4655 h
= (struct elf_link_hash_entry
*) bh
;
4658 h
->type
= STT_OBJECT
;
4659 elf_hash_table (info
)->hgot
= h
;
4662 && ! bfd_elf_link_record_dynamic_symbol (info
, h
))
4665 amt
= sizeof (struct mips_got_info
);
4666 g
= bfd_alloc (abfd
, amt
);
4669 g
->global_gotsym
= NULL
;
4670 g
->global_gotno
= 0;
4671 g
->reloc_only_gotno
= 0;
4675 g
->assigned_gotno
= 0;
4678 g
->tls_ldm_offset
= MINUS_ONE
;
4679 g
->got_entries
= htab_try_create (1, mips_elf_got_entry_hash
,
4680 mips_elf_got_entry_eq
, NULL
);
4681 if (g
->got_entries
== NULL
)
4683 g
->got_page_entries
= htab_try_create (1, mips_got_page_entry_hash
,
4684 mips_got_page_entry_eq
, NULL
);
4685 if (g
->got_page_entries
== NULL
)
4688 mips_elf_section_data (s
)->elf
.this_hdr
.sh_flags
4689 |= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
4691 /* We also need a .got.plt section when generating PLTs. */
4692 s
= bfd_make_section_with_flags (abfd
, ".got.plt",
4693 SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
4694 | SEC_IN_MEMORY
| SEC_LINKER_CREATED
);
4702 /* Return true if H refers to the special VxWorks __GOTT_BASE__ or
4703 __GOTT_INDEX__ symbols. These symbols are only special for
4704 shared objects; they are not used in executables. */
4707 is_gott_symbol (struct bfd_link_info
*info
, struct elf_link_hash_entry
*h
)
4709 return (mips_elf_hash_table (info
)->is_vxworks
4711 && (strcmp (h
->root
.root
.string
, "__GOTT_BASE__") == 0
4712 || strcmp (h
->root
.root
.string
, "__GOTT_INDEX__") == 0));
4715 /* Return TRUE if a relocation of type R_TYPE from INPUT_BFD might
4716 require an la25 stub. See also mips_elf_local_pic_function_p,
4717 which determines whether the destination function ever requires a
4721 mips_elf_relocation_needs_la25_stub (bfd
*input_bfd
, int r_type
)
4723 /* We specifically ignore branches and jumps from EF_PIC objects,
4724 where the onus is on the compiler or programmer to perform any
4725 necessary initialization of $25. Sometimes such initialization
4726 is unnecessary; for example, -mno-shared functions do not use
4727 the incoming value of $25, and may therefore be called directly. */
4728 if (PIC_OBJECT_P (input_bfd
))
4743 /* Calculate the value produced by the RELOCATION (which comes from
4744 the INPUT_BFD). The ADDEND is the addend to use for this
4745 RELOCATION; RELOCATION->R_ADDEND is ignored.
4747 The result of the relocation calculation is stored in VALUEP.
4748 REQUIRE_JALXP indicates whether or not the opcode used with this
4749 relocation must be JALX.
4751 This function returns bfd_reloc_continue if the caller need take no
4752 further action regarding this relocation, bfd_reloc_notsupported if
4753 something goes dramatically wrong, bfd_reloc_overflow if an
4754 overflow occurs, and bfd_reloc_ok to indicate success. */
4756 static bfd_reloc_status_type
4757 mips_elf_calculate_relocation (bfd
*abfd
, bfd
*input_bfd
,
4758 asection
*input_section
,
4759 struct bfd_link_info
*info
,
4760 const Elf_Internal_Rela
*relocation
,
4761 bfd_vma addend
, reloc_howto_type
*howto
,
4762 Elf_Internal_Sym
*local_syms
,
4763 asection
**local_sections
, bfd_vma
*valuep
,
4764 const char **namep
, bfd_boolean
*require_jalxp
,
4765 bfd_boolean save_addend
)
4767 /* The eventual value we will return. */
4769 /* The address of the symbol against which the relocation is
4772 /* The final GP value to be used for the relocatable, executable, or
4773 shared object file being produced. */
4775 /* The place (section offset or address) of the storage unit being
4778 /* The value of GP used to create the relocatable object. */
4780 /* The offset into the global offset table at which the address of
4781 the relocation entry symbol, adjusted by the addend, resides
4782 during execution. */
4783 bfd_vma g
= MINUS_ONE
;
4784 /* The section in which the symbol referenced by the relocation is
4786 asection
*sec
= NULL
;
4787 struct mips_elf_link_hash_entry
*h
= NULL
;
4788 /* TRUE if the symbol referred to by this relocation is a local
4790 bfd_boolean local_p
, was_local_p
;
4791 /* TRUE if the symbol referred to by this relocation is "_gp_disp". */
4792 bfd_boolean gp_disp_p
= FALSE
;
4793 /* TRUE if the symbol referred to by this relocation is
4794 "__gnu_local_gp". */
4795 bfd_boolean gnu_local_gp_p
= FALSE
;
4796 Elf_Internal_Shdr
*symtab_hdr
;
4798 unsigned long r_symndx
;
4800 /* TRUE if overflow occurred during the calculation of the
4801 relocation value. */
4802 bfd_boolean overflowed_p
;
4803 /* TRUE if this relocation refers to a MIPS16 function. */
4804 bfd_boolean target_is_16_bit_code_p
= FALSE
;
4805 struct mips_elf_link_hash_table
*htab
;
4808 dynobj
= elf_hash_table (info
)->dynobj
;
4809 htab
= mips_elf_hash_table (info
);
4811 /* Parse the relocation. */
4812 r_symndx
= ELF_R_SYM (input_bfd
, relocation
->r_info
);
4813 r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
4814 p
= (input_section
->output_section
->vma
4815 + input_section
->output_offset
4816 + relocation
->r_offset
);
4818 /* Assume that there will be no overflow. */
4819 overflowed_p
= FALSE
;
4821 /* Figure out whether or not the symbol is local, and get the offset
4822 used in the array of hash table entries. */
4823 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
4824 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
4825 local_sections
, FALSE
);
4826 was_local_p
= local_p
;
4827 if (! elf_bad_symtab (input_bfd
))
4828 extsymoff
= symtab_hdr
->sh_info
;
4831 /* The symbol table does not follow the rule that local symbols
4832 must come before globals. */
4836 /* Figure out the value of the symbol. */
4839 Elf_Internal_Sym
*sym
;
4841 sym
= local_syms
+ r_symndx
;
4842 sec
= local_sections
[r_symndx
];
4844 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4845 if (ELF_ST_TYPE (sym
->st_info
) != STT_SECTION
4846 || (sec
->flags
& SEC_MERGE
))
4847 symbol
+= sym
->st_value
;
4848 if ((sec
->flags
& SEC_MERGE
)
4849 && ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
4851 addend
= _bfd_elf_rel_local_sym (abfd
, sym
, &sec
, addend
);
4853 addend
+= sec
->output_section
->vma
+ sec
->output_offset
;
4856 /* MIPS16 text labels should be treated as odd. */
4857 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
4860 /* Record the name of this symbol, for our caller. */
4861 *namep
= bfd_elf_string_from_elf_section (input_bfd
,
4862 symtab_hdr
->sh_link
,
4865 *namep
= bfd_section_name (input_bfd
, sec
);
4867 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (sym
->st_other
);
4871 /* ??? Could we use RELOC_FOR_GLOBAL_SYMBOL here ? */
4873 /* For global symbols we look up the symbol in the hash-table. */
4874 h
= ((struct mips_elf_link_hash_entry
*)
4875 elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
]);
4876 /* Find the real hash-table entry for this symbol. */
4877 while (h
->root
.root
.type
== bfd_link_hash_indirect
4878 || h
->root
.root
.type
== bfd_link_hash_warning
)
4879 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
4881 /* Record the name of this symbol, for our caller. */
4882 *namep
= h
->root
.root
.root
.string
;
4884 /* See if this is the special _gp_disp symbol. Note that such a
4885 symbol must always be a global symbol. */
4886 if (strcmp (*namep
, "_gp_disp") == 0
4887 && ! NEWABI_P (input_bfd
))
4889 /* Relocations against _gp_disp are permitted only with
4890 R_MIPS_HI16 and R_MIPS_LO16 relocations. */
4891 if (!hi16_reloc_p (r_type
) && !lo16_reloc_p (r_type
))
4892 return bfd_reloc_notsupported
;
4896 /* See if this is the special _gp symbol. Note that such a
4897 symbol must always be a global symbol. */
4898 else if (strcmp (*namep
, "__gnu_local_gp") == 0)
4899 gnu_local_gp_p
= TRUE
;
4902 /* If this symbol is defined, calculate its address. Note that
4903 _gp_disp is a magic symbol, always implicitly defined by the
4904 linker, so it's inappropriate to check to see whether or not
4906 else if ((h
->root
.root
.type
== bfd_link_hash_defined
4907 || h
->root
.root
.type
== bfd_link_hash_defweak
)
4908 && h
->root
.root
.u
.def
.section
)
4910 sec
= h
->root
.root
.u
.def
.section
;
4911 if (sec
->output_section
)
4912 symbol
= (h
->root
.root
.u
.def
.value
4913 + sec
->output_section
->vma
4914 + sec
->output_offset
);
4916 symbol
= h
->root
.root
.u
.def
.value
;
4918 else if (h
->root
.root
.type
== bfd_link_hash_undefweak
)
4919 /* We allow relocations against undefined weak symbols, giving
4920 it the value zero, so that you can undefined weak functions
4921 and check to see if they exist by looking at their
4924 else if (info
->unresolved_syms_in_objects
== RM_IGNORE
4925 && ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
4927 else if (strcmp (*namep
, SGI_COMPAT (input_bfd
)
4928 ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING") == 0)
4930 /* If this is a dynamic link, we should have created a
4931 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol
4932 in in _bfd_mips_elf_create_dynamic_sections.
4933 Otherwise, we should define the symbol with a value of 0.
4934 FIXME: It should probably get into the symbol table
4936 BFD_ASSERT (! info
->shared
);
4937 BFD_ASSERT (bfd_get_section_by_name (abfd
, ".dynamic") == NULL
);
4940 else if (ELF_MIPS_IS_OPTIONAL (h
->root
.other
))
4942 /* This is an optional symbol - an Irix specific extension to the
4943 ELF spec. Ignore it for now.
4944 XXX - FIXME - there is more to the spec for OPTIONAL symbols
4945 than simply ignoring them, but we do not handle this for now.
4946 For information see the "64-bit ELF Object File Specification"
4947 which is available from here:
4948 http://techpubs.sgi.com/library/manuals/4000/007-4658-001/pdf/007-4658-001.pdf */
4953 if (! ((*info
->callbacks
->undefined_symbol
)
4954 (info
, h
->root
.root
.root
.string
, input_bfd
,
4955 input_section
, relocation
->r_offset
,
4956 (info
->unresolved_syms_in_objects
== RM_GENERATE_ERROR
)
4957 || ELF_ST_VISIBILITY (h
->root
.other
))))
4958 return bfd_reloc_undefined
;
4962 target_is_16_bit_code_p
= ELF_ST_IS_MIPS16 (h
->root
.other
);
4965 /* If this is a reference to a 16-bit function with a stub, we need
4966 to redirect the relocation to the stub unless:
4968 (a) the relocation is for a MIPS16 JAL;
4970 (b) the relocation is for a MIPS16 PIC call, and there are no
4971 non-MIPS16 uses of the GOT slot; or
4973 (c) the section allows direct references to MIPS16 functions. */
4974 if (r_type
!= R_MIPS16_26
4975 && !info
->relocatable
4977 && h
->fn_stub
!= NULL
4978 && (r_type
!= R_MIPS16_CALL16
|| h
->need_fn_stub
))
4980 && elf_tdata (input_bfd
)->local_stubs
!= NULL
4981 && elf_tdata (input_bfd
)->local_stubs
[r_symndx
] != NULL
))
4982 && !section_allows_mips16_refs_p (input_section
))
4984 /* This is a 32- or 64-bit call to a 16-bit function. We should
4985 have already noticed that we were going to need the
4988 sec
= elf_tdata (input_bfd
)->local_stubs
[r_symndx
];
4991 BFD_ASSERT (h
->need_fn_stub
);
4995 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
4996 /* The target is 16-bit, but the stub isn't. */
4997 target_is_16_bit_code_p
= FALSE
;
4999 /* If this is a 16-bit call to a 32- or 64-bit function with a stub, we
5000 need to redirect the call to the stub. Note that we specifically
5001 exclude R_MIPS16_CALL16 from this behavior; indirect calls should
5002 use an indirect stub instead. */
5003 else if (r_type
== R_MIPS16_26
&& !info
->relocatable
5004 && ((h
!= NULL
&& (h
->call_stub
!= NULL
|| h
->call_fp_stub
!= NULL
))
5006 && elf_tdata (input_bfd
)->local_call_stubs
!= NULL
5007 && elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
] != NULL
))
5008 && !target_is_16_bit_code_p
)
5011 sec
= elf_tdata (input_bfd
)->local_call_stubs
[r_symndx
];
5014 /* If both call_stub and call_fp_stub are defined, we can figure
5015 out which one to use by checking which one appears in the input
5017 if (h
->call_stub
!= NULL
&& h
->call_fp_stub
!= NULL
)
5022 for (o
= input_bfd
->sections
; o
!= NULL
; o
= o
->next
)
5024 if (CALL_FP_STUB_P (bfd_get_section_name (input_bfd
, o
)))
5026 sec
= h
->call_fp_stub
;
5033 else if (h
->call_stub
!= NULL
)
5036 sec
= h
->call_fp_stub
;
5039 BFD_ASSERT (sec
->size
> 0);
5040 symbol
= sec
->output_section
->vma
+ sec
->output_offset
;
5042 /* If this is a direct call to a PIC function, redirect to the
5044 else if (h
!= NULL
&& h
->la25_stub
5045 && mips_elf_relocation_needs_la25_stub (input_bfd
, r_type
))
5046 symbol
= (h
->la25_stub
->stub_section
->output_section
->vma
5047 + h
->la25_stub
->stub_section
->output_offset
5048 + h
->la25_stub
->offset
);
5050 /* Calls from 16-bit code to 32-bit code and vice versa require the
5051 special jalx instruction. */
5052 *require_jalxp
= (!info
->relocatable
5053 && (((r_type
== R_MIPS16_26
) && !target_is_16_bit_code_p
)
5054 || ((r_type
== R_MIPS_26
) && target_is_16_bit_code_p
)));
5056 local_p
= mips_elf_local_relocation_p (input_bfd
, relocation
,
5057 local_sections
, TRUE
);
5059 gp0
= _bfd_get_gp_value (input_bfd
);
5060 gp
= _bfd_get_gp_value (abfd
);
5062 gp
+= mips_elf_adjust_gp (abfd
, htab
->got_info
, input_bfd
);
5067 /* If we haven't already determined the GOT offset, oand we're going
5068 to need it, get it now. */
5071 case R_MIPS_GOT_PAGE
:
5072 case R_MIPS_GOT_OFST
:
5073 /* We need to decay to GOT_DISP/addend if the symbol doesn't
5075 local_p
= local_p
|| _bfd_elf_symbol_refs_local_p (&h
->root
, info
, 1);
5076 if (local_p
|| r_type
== R_MIPS_GOT_OFST
)
5080 case R_MIPS16_CALL16
:
5081 case R_MIPS16_GOT16
:
5084 case R_MIPS_GOT_DISP
:
5085 case R_MIPS_GOT_HI16
:
5086 case R_MIPS_CALL_HI16
:
5087 case R_MIPS_GOT_LO16
:
5088 case R_MIPS_CALL_LO16
:
5090 case R_MIPS_TLS_GOTTPREL
:
5091 case R_MIPS_TLS_LDM
:
5092 /* Find the index into the GOT where this value is located. */
5093 if (r_type
== R_MIPS_TLS_LDM
)
5095 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5096 0, 0, NULL
, r_type
);
5098 return bfd_reloc_outofrange
;
5102 /* On VxWorks, CALL relocations should refer to the .got.plt
5103 entry, which is initialized to point at the PLT stub. */
5104 if (htab
->is_vxworks
5105 && (r_type
== R_MIPS_CALL_HI16
5106 || r_type
== R_MIPS_CALL_LO16
5107 || call16_reloc_p (r_type
)))
5109 BFD_ASSERT (addend
== 0);
5110 BFD_ASSERT (h
->root
.needs_plt
);
5111 g
= mips_elf_gotplt_index (info
, &h
->root
);
5115 /* GOT_PAGE may take a non-zero addend, that is ignored in a
5116 GOT_PAGE relocation that decays to GOT_DISP because the
5117 symbol turns out to be global. The addend is then added
5119 BFD_ASSERT (addend
== 0 || r_type
== R_MIPS_GOT_PAGE
);
5120 g
= mips_elf_global_got_index (dynobj
, input_bfd
,
5121 &h
->root
, r_type
, info
);
5122 if (h
->tls_type
== GOT_NORMAL
5123 && (! elf_hash_table(info
)->dynamic_sections_created
5125 && (info
->symbolic
|| h
->root
.forced_local
)
5126 && h
->root
.def_regular
)))
5127 /* This is a static link or a -Bsymbolic link. The
5128 symbol is defined locally, or was forced to be local.
5129 We must initialize this entry in the GOT. */
5130 MIPS_ELF_PUT_WORD (dynobj
, symbol
, htab
->sgot
->contents
+ g
);
5133 else if (!htab
->is_vxworks
5134 && (call16_reloc_p (r_type
) || got16_reloc_p (r_type
)))
5135 /* The calculation below does not involve "g". */
5139 g
= mips_elf_local_got_index (abfd
, input_bfd
, info
,
5140 symbol
+ addend
, r_symndx
, h
, r_type
);
5142 return bfd_reloc_outofrange
;
5145 /* Convert GOT indices to actual offsets. */
5146 g
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, g
);
5150 /* Relocations against the VxWorks __GOTT_BASE__ and __GOTT_INDEX__
5151 symbols are resolved by the loader. Add them to .rela.dyn. */
5152 if (h
!= NULL
&& is_gott_symbol (info
, &h
->root
))
5154 Elf_Internal_Rela outrel
;
5158 s
= mips_elf_rel_dyn_section (info
, FALSE
);
5159 loc
= s
->contents
+ s
->reloc_count
++ * sizeof (Elf32_External_Rela
);
5161 outrel
.r_offset
= (input_section
->output_section
->vma
5162 + input_section
->output_offset
5163 + relocation
->r_offset
);
5164 outrel
.r_info
= ELF32_R_INFO (h
->root
.dynindx
, r_type
);
5165 outrel
.r_addend
= addend
;
5166 bfd_elf32_swap_reloca_out (abfd
, &outrel
, loc
);
5168 /* If we've written this relocation for a readonly section,
5169 we need to set DF_TEXTREL again, so that we do not delete the
5171 if (MIPS_ELF_READONLY_SECTION (input_section
))
5172 info
->flags
|= DF_TEXTREL
;
5175 return bfd_reloc_ok
;
5178 /* Figure out what kind of relocation is being performed. */
5182 return bfd_reloc_continue
;
5185 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 16);
5186 overflowed_p
= mips_elf_overflow_p (value
, 16);
5193 || (htab
->root
.dynamic_sections_created
5195 && h
->root
.def_dynamic
5196 && !h
->root
.def_regular
5197 && !h
->has_static_relocs
))
5200 || h
->root
.root
.type
!= bfd_link_hash_undefweak
5201 || ELF_ST_VISIBILITY (h
->root
.other
) == STV_DEFAULT
)
5202 && (input_section
->flags
& SEC_ALLOC
) != 0)
5204 /* If we're creating a shared library, then we can't know
5205 where the symbol will end up. So, we create a relocation
5206 record in the output, and leave the job up to the dynamic
5207 linker. We must do the same for executable references to
5208 shared library symbols, unless we've decided to use copy
5209 relocs or PLTs instead. */
5211 if (!mips_elf_create_dynamic_relocation (abfd
,
5219 return bfd_reloc_undefined
;
5223 if (r_type
!= R_MIPS_REL32
)
5224 value
= symbol
+ addend
;
5228 value
&= howto
->dst_mask
;
5232 value
= symbol
+ addend
- p
;
5233 value
&= howto
->dst_mask
;
5237 /* The calculation for R_MIPS16_26 is just the same as for an
5238 R_MIPS_26. It's only the storage of the relocated field into
5239 the output file that's different. That's handled in
5240 mips_elf_perform_relocation. So, we just fall through to the
5241 R_MIPS_26 case here. */
5244 value
= ((addend
| ((p
+ 4) & 0xf0000000)) + symbol
) >> 2;
5247 value
= (_bfd_mips_elf_sign_extend (addend
, 28) + symbol
) >> 2;
5248 if (h
->root
.root
.type
!= bfd_link_hash_undefweak
)
5249 overflowed_p
= (value
>> 26) != ((p
+ 4) >> 28);
5251 value
&= howto
->dst_mask
;
5254 case R_MIPS_TLS_DTPREL_HI16
:
5255 value
= (mips_elf_high (addend
+ symbol
- dtprel_base (info
))
5259 case R_MIPS_TLS_DTPREL_LO16
:
5260 case R_MIPS_TLS_DTPREL32
:
5261 case R_MIPS_TLS_DTPREL64
:
5262 value
= (symbol
+ addend
- dtprel_base (info
)) & howto
->dst_mask
;
5265 case R_MIPS_TLS_TPREL_HI16
:
5266 value
= (mips_elf_high (addend
+ symbol
- tprel_base (info
))
5270 case R_MIPS_TLS_TPREL_LO16
:
5271 value
= (symbol
+ addend
- tprel_base (info
)) & howto
->dst_mask
;
5278 value
= mips_elf_high (addend
+ symbol
);
5279 value
&= howto
->dst_mask
;
5283 /* For MIPS16 ABI code we generate this sequence
5284 0: li $v0,%hi(_gp_disp)
5285 4: addiupc $v1,%lo(_gp_disp)
5289 So the offsets of hi and lo relocs are the same, but the
5290 $pc is four higher than $t9 would be, so reduce
5291 both reloc addends by 4. */
5292 if (r_type
== R_MIPS16_HI16
)
5293 value
= mips_elf_high (addend
+ gp
- p
- 4);
5295 value
= mips_elf_high (addend
+ gp
- p
);
5296 overflowed_p
= mips_elf_overflow_p (value
, 16);
5303 value
= (symbol
+ addend
) & howto
->dst_mask
;
5306 /* See the comment for R_MIPS16_HI16 above for the reason
5307 for this conditional. */
5308 if (r_type
== R_MIPS16_LO16
)
5309 value
= addend
+ gp
- p
;
5311 value
= addend
+ gp
- p
+ 4;
5312 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation
5313 for overflow. But, on, say, IRIX5, relocations against
5314 _gp_disp are normally generated from the .cpload
5315 pseudo-op. It generates code that normally looks like
5318 lui $gp,%hi(_gp_disp)
5319 addiu $gp,$gp,%lo(_gp_disp)
5322 Here $t9 holds the address of the function being called,
5323 as required by the MIPS ELF ABI. The R_MIPS_LO16
5324 relocation can easily overflow in this situation, but the
5325 R_MIPS_HI16 relocation will handle the overflow.
5326 Therefore, we consider this a bug in the MIPS ABI, and do
5327 not check for overflow here. */
5331 case R_MIPS_LITERAL
:
5332 /* Because we don't merge literal sections, we can handle this
5333 just like R_MIPS_GPREL16. In the long run, we should merge
5334 shared literals, and then we will need to additional work
5339 case R_MIPS16_GPREL
:
5340 /* The R_MIPS16_GPREL performs the same calculation as
5341 R_MIPS_GPREL16, but stores the relocated bits in a different
5342 order. We don't need to do anything special here; the
5343 differences are handled in mips_elf_perform_relocation. */
5344 case R_MIPS_GPREL16
:
5345 /* Only sign-extend the addend if it was extracted from the
5346 instruction. If the addend was separate, leave it alone,
5347 otherwise we may lose significant bits. */
5348 if (howto
->partial_inplace
)
5349 addend
= _bfd_mips_elf_sign_extend (addend
, 16);
5350 value
= symbol
+ addend
- gp
;
5351 /* If the symbol was local, any earlier relocatable links will
5352 have adjusted its addend with the gp offset, so compensate
5353 for that now. Don't do it for symbols forced local in this
5354 link, though, since they won't have had the gp offset applied
5358 overflowed_p
= mips_elf_overflow_p (value
, 16);
5361 case R_MIPS16_GOT16
:
5362 case R_MIPS16_CALL16
:
5365 /* VxWorks does not have separate local and global semantics for
5366 R_MIPS*_GOT16; every relocation evaluates to "G". */
5367 if (!htab
->is_vxworks
&& local_p
)
5371 forced
= ! mips_elf_local_relocation_p (input_bfd
, relocation
,
5372 local_sections
, FALSE
);
5373 value
= mips_elf_got16_entry (abfd
, input_bfd
, info
,
5374 symbol
+ addend
, forced
);
5375 if (value
== MINUS_ONE
)
5376 return bfd_reloc_outofrange
;
5378 = mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
5379 overflowed_p
= mips_elf_overflow_p (value
, 16);
5386 case R_MIPS_TLS_GOTTPREL
:
5387 case R_MIPS_TLS_LDM
:
5388 case R_MIPS_GOT_DISP
:
5391 overflowed_p
= mips_elf_overflow_p (value
, 16);
5394 case R_MIPS_GPREL32
:
5395 value
= (addend
+ symbol
+ gp0
- gp
);
5397 value
&= howto
->dst_mask
;
5401 case R_MIPS_GNU_REL16_S2
:
5402 value
= symbol
+ _bfd_mips_elf_sign_extend (addend
, 18) - p
;
5403 overflowed_p
= mips_elf_overflow_p (value
, 18);
5404 value
>>= howto
->rightshift
;
5405 value
&= howto
->dst_mask
;
5408 case R_MIPS_GOT_HI16
:
5409 case R_MIPS_CALL_HI16
:
5410 /* We're allowed to handle these two relocations identically.
5411 The dynamic linker is allowed to handle the CALL relocations
5412 differently by creating a lazy evaluation stub. */
5414 value
= mips_elf_high (value
);
5415 value
&= howto
->dst_mask
;
5418 case R_MIPS_GOT_LO16
:
5419 case R_MIPS_CALL_LO16
:
5420 value
= g
& howto
->dst_mask
;
5423 case R_MIPS_GOT_PAGE
:
5424 /* GOT_PAGE relocations that reference non-local symbols decay
5425 to GOT_DISP. The corresponding GOT_OFST relocation decays to
5429 value
= mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, NULL
);
5430 if (value
== MINUS_ONE
)
5431 return bfd_reloc_outofrange
;
5432 value
= mips_elf_got_offset_from_index (info
, abfd
, input_bfd
, value
);
5433 overflowed_p
= mips_elf_overflow_p (value
, 16);
5436 case R_MIPS_GOT_OFST
:
5438 mips_elf_got_page (abfd
, input_bfd
, info
, symbol
+ addend
, &value
);
5441 overflowed_p
= mips_elf_overflow_p (value
, 16);
5445 value
= symbol
- addend
;
5446 value
&= howto
->dst_mask
;
5450 value
= mips_elf_higher (addend
+ symbol
);
5451 value
&= howto
->dst_mask
;
5454 case R_MIPS_HIGHEST
:
5455 value
= mips_elf_highest (addend
+ symbol
);
5456 value
&= howto
->dst_mask
;
5459 case R_MIPS_SCN_DISP
:
5460 value
= symbol
+ addend
- sec
->output_offset
;
5461 value
&= howto
->dst_mask
;
5465 /* This relocation is only a hint. In some cases, we optimize
5466 it into a bal instruction. But we don't try to optimize
5467 branches to the PLT; that will wind up wasting time. */
5468 if (h
!= NULL
&& h
->root
.plt
.offset
!= (bfd_vma
) -1)
5469 return bfd_reloc_continue
;
5470 value
= symbol
+ addend
;
5474 case R_MIPS_GNU_VTINHERIT
:
5475 case R_MIPS_GNU_VTENTRY
:
5476 /* We don't do anything with these at present. */
5477 return bfd_reloc_continue
;
5480 /* An unrecognized relocation type. */
5481 return bfd_reloc_notsupported
;
5484 /* Store the VALUE for our caller. */
5486 return overflowed_p
? bfd_reloc_overflow
: bfd_reloc_ok
;
5489 /* Obtain the field relocated by RELOCATION. */
5492 mips_elf_obtain_contents (reloc_howto_type
*howto
,
5493 const Elf_Internal_Rela
*relocation
,
5494 bfd
*input_bfd
, bfd_byte
*contents
)
5497 bfd_byte
*location
= contents
+ relocation
->r_offset
;
5499 /* Obtain the bytes. */
5500 x
= bfd_get ((8 * bfd_get_reloc_size (howto
)), input_bfd
, location
);
5505 /* It has been determined that the result of the RELOCATION is the
5506 VALUE. Use HOWTO to place VALUE into the output file at the
5507 appropriate position. The SECTION is the section to which the
5508 relocation applies. If REQUIRE_JALX is TRUE, then the opcode used
5509 for the relocation must be either JAL or JALX, and it is
5510 unconditionally converted to JALX.
5512 Returns FALSE if anything goes wrong. */
5515 mips_elf_perform_relocation (struct bfd_link_info
*info
,
5516 reloc_howto_type
*howto
,
5517 const Elf_Internal_Rela
*relocation
,
5518 bfd_vma value
, bfd
*input_bfd
,
5519 asection
*input_section
, bfd_byte
*contents
,
5520 bfd_boolean require_jalx
)
5524 int r_type
= ELF_R_TYPE (input_bfd
, relocation
->r_info
);
5526 /* Figure out where the relocation is occurring. */
5527 location
= contents
+ relocation
->r_offset
;
5529 _bfd_mips16_elf_reloc_unshuffle (input_bfd
, r_type
, FALSE
, location
);
5531 /* Obtain the current value. */
5532 x
= mips_elf_obtain_contents (howto
, relocation
, input_bfd
, contents
);
5534 /* Clear the field we are setting. */
5535 x
&= ~howto
->dst_mask
;
5537 /* Set the field. */
5538 x
|= (value
& howto
->dst_mask
);
5540 /* If required, turn JAL into JALX. */
5544 bfd_vma opcode
= x
>> 26;
5545 bfd_vma jalx_opcode
;
5547 /* Check to see if the opcode is already JAL or JALX. */
5548 if (r_type
== R_MIPS16_26
)
5550 ok
= ((opcode
== 0x6) || (opcode
== 0x7));
5555 ok
= ((opcode
== 0x3) || (opcode
== 0x1d));
5559 /* If the opcode is not JAL or JALX, there's a problem. */
5562 (*_bfd_error_handler
)
5563 (_("%B: %A+0x%lx: jump to stub routine which is not jal"),
5566 (unsigned long) relocation
->r_offset
);
5567 bfd_set_error (bfd_error_bad_value
);
5571 /* Make this the JALX opcode. */
5572 x
= (x
& ~(0x3f << 26)) | (jalx_opcode
<< 26);
5575 /* On the RM9000, bal is faster than jal, because bal uses branch
5576 prediction hardware. If we are linking for the RM9000, and we
5577 see jal, and bal fits, use it instead. Note that this
5578 transformation should be safe for all architectures. */
5579 if (bfd_get_mach (input_bfd
) == bfd_mach_mips9000
5580 && !info
->relocatable
5582 && ((r_type
== R_MIPS_26
&& (x
>> 26) == 0x3) /* jal addr */
5583 || (r_type
== R_MIPS_JALR
&& x
== 0x0320f809))) /* jalr t9 */
5589 addr
= (input_section
->output_section
->vma
5590 + input_section
->output_offset
5591 + relocation
->r_offset
5593 if (r_type
== R_MIPS_26
)
5594 dest
= (value
<< 2) | ((addr
>> 28) << 28);
5598 if (off
<= 0x1ffff && off
>= -0x20000)
5599 x
= 0x04110000 | (((bfd_vma
) off
>> 2) & 0xffff); /* bal addr */
5602 /* Put the value into the output. */
5603 bfd_put (8 * bfd_get_reloc_size (howto
), input_bfd
, x
, location
);
5605 _bfd_mips16_elf_reloc_shuffle(input_bfd
, r_type
, !info
->relocatable
,
5611 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL
5612 is the original relocation, which is now being transformed into a
5613 dynamic relocation. The ADDENDP is adjusted if necessary; the
5614 caller should store the result in place of the original addend. */
5617 mips_elf_create_dynamic_relocation (bfd
*output_bfd
,
5618 struct bfd_link_info
*info
,
5619 const Elf_Internal_Rela
*rel
,
5620 struct mips_elf_link_hash_entry
*h
,
5621 asection
*sec
, bfd_vma symbol
,
5622 bfd_vma
*addendp
, asection
*input_section
)
5624 Elf_Internal_Rela outrel
[3];
5629 bfd_boolean defined_p
;
5630 struct mips_elf_link_hash_table
*htab
;
5632 htab
= mips_elf_hash_table (info
);
5633 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
5634 dynobj
= elf_hash_table (info
)->dynobj
;
5635 sreloc
= mips_elf_rel_dyn_section (info
, FALSE
);
5636 BFD_ASSERT (sreloc
!= NULL
);
5637 BFD_ASSERT (sreloc
->contents
!= NULL
);
5638 BFD_ASSERT (sreloc
->reloc_count
* MIPS_ELF_REL_SIZE (output_bfd
)
5641 outrel
[0].r_offset
=
5642 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[0].r_offset
);
5643 if (ABI_64_P (output_bfd
))
5645 outrel
[1].r_offset
=
5646 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[1].r_offset
);
5647 outrel
[2].r_offset
=
5648 _bfd_elf_section_offset (output_bfd
, info
, input_section
, rel
[2].r_offset
);
5651 if (outrel
[0].r_offset
== MINUS_ONE
)
5652 /* The relocation field has been deleted. */
5655 if (outrel
[0].r_offset
== MINUS_TWO
)
5657 /* The relocation field has been converted into a relative value of
5658 some sort. Functions like _bfd_elf_write_section_eh_frame expect
5659 the field to be fully relocated, so add in the symbol's value. */
5664 /* We must now calculate the dynamic symbol table index to use
5665 in the relocation. */
5667 && (!h
->root
.def_regular
5668 || (info
->shared
&& !info
->symbolic
&& !h
->root
.forced_local
)))
5670 indx
= h
->root
.dynindx
;
5671 if (SGI_COMPAT (output_bfd
))
5672 defined_p
= h
->root
.def_regular
;
5674 /* ??? glibc's ld.so just adds the final GOT entry to the
5675 relocation field. It therefore treats relocs against
5676 defined symbols in the same way as relocs against
5677 undefined symbols. */
5682 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
5684 else if (sec
== NULL
|| sec
->owner
== NULL
)
5686 bfd_set_error (bfd_error_bad_value
);
5691 indx
= elf_section_data (sec
->output_section
)->dynindx
;
5694 asection
*osec
= htab
->root
.text_index_section
;
5695 indx
= elf_section_data (osec
)->dynindx
;
5701 /* Instead of generating a relocation using the section
5702 symbol, we may as well make it a fully relative
5703 relocation. We want to avoid generating relocations to
5704 local symbols because we used to generate them
5705 incorrectly, without adding the original symbol value,
5706 which is mandated by the ABI for section symbols. In
5707 order to give dynamic loaders and applications time to
5708 phase out the incorrect use, we refrain from emitting
5709 section-relative relocations. It's not like they're
5710 useful, after all. This should be a bit more efficient
5712 /* ??? Although this behavior is compatible with glibc's ld.so,
5713 the ABI says that relocations against STN_UNDEF should have
5714 a symbol value of 0. Irix rld honors this, so relocations
5715 against STN_UNDEF have no effect. */
5716 if (!SGI_COMPAT (output_bfd
))
5721 /* If the relocation was previously an absolute relocation and
5722 this symbol will not be referred to by the relocation, we must
5723 adjust it by the value we give it in the dynamic symbol table.
5724 Otherwise leave the job up to the dynamic linker. */
5725 if (defined_p
&& r_type
!= R_MIPS_REL32
)
5728 if (htab
->is_vxworks
)
5729 /* VxWorks uses non-relative relocations for this. */
5730 outrel
[0].r_info
= ELF32_R_INFO (indx
, R_MIPS_32
);
5732 /* The relocation is always an REL32 relocation because we don't
5733 know where the shared library will wind up at load-time. */
5734 outrel
[0].r_info
= ELF_R_INFO (output_bfd
, (unsigned long) indx
,
5737 /* For strict adherence to the ABI specification, we should
5738 generate a R_MIPS_64 relocation record by itself before the
5739 _REL32/_64 record as well, such that the addend is read in as
5740 a 64-bit value (REL32 is a 32-bit relocation, after all).
5741 However, since none of the existing ELF64 MIPS dynamic
5742 loaders seems to care, we don't waste space with these
5743 artificial relocations. If this turns out to not be true,
5744 mips_elf_allocate_dynamic_relocation() should be tweaked so
5745 as to make room for a pair of dynamic relocations per
5746 invocation if ABI_64_P, and here we should generate an
5747 additional relocation record with R_MIPS_64 by itself for a
5748 NULL symbol before this relocation record. */
5749 outrel
[1].r_info
= ELF_R_INFO (output_bfd
, 0,
5750 ABI_64_P (output_bfd
)
5753 outrel
[2].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_NONE
);
5755 /* Adjust the output offset of the relocation to reference the
5756 correct location in the output file. */
5757 outrel
[0].r_offset
+= (input_section
->output_section
->vma
5758 + input_section
->output_offset
);
5759 outrel
[1].r_offset
+= (input_section
->output_section
->vma
5760 + input_section
->output_offset
);
5761 outrel
[2].r_offset
+= (input_section
->output_section
->vma
5762 + input_section
->output_offset
);
5764 /* Put the relocation back out. We have to use the special
5765 relocation outputter in the 64-bit case since the 64-bit
5766 relocation format is non-standard. */
5767 if (ABI_64_P (output_bfd
))
5769 (*get_elf_backend_data (output_bfd
)->s
->swap_reloc_out
)
5770 (output_bfd
, &outrel
[0],
5772 + sreloc
->reloc_count
* sizeof (Elf64_Mips_External_Rel
)));
5774 else if (htab
->is_vxworks
)
5776 /* VxWorks uses RELA rather than REL dynamic relocations. */
5777 outrel
[0].r_addend
= *addendp
;
5778 bfd_elf32_swap_reloca_out
5779 (output_bfd
, &outrel
[0],
5781 + sreloc
->reloc_count
* sizeof (Elf32_External_Rela
)));
5784 bfd_elf32_swap_reloc_out
5785 (output_bfd
, &outrel
[0],
5786 (sreloc
->contents
+ sreloc
->reloc_count
* sizeof (Elf32_External_Rel
)));
5788 /* We've now added another relocation. */
5789 ++sreloc
->reloc_count
;
5791 /* Make sure the output section is writable. The dynamic linker
5792 will be writing to it. */
5793 elf_section_data (input_section
->output_section
)->this_hdr
.sh_flags
5796 /* On IRIX5, make an entry of compact relocation info. */
5797 if (IRIX_COMPAT (output_bfd
) == ict_irix5
)
5799 asection
*scpt
= bfd_get_section_by_name (dynobj
, ".compact_rel");
5804 Elf32_crinfo cptrel
;
5806 mips_elf_set_cr_format (cptrel
, CRF_MIPS_LONG
);
5807 cptrel
.vaddr
= (rel
->r_offset
5808 + input_section
->output_section
->vma
5809 + input_section
->output_offset
);
5810 if (r_type
== R_MIPS_REL32
)
5811 mips_elf_set_cr_type (cptrel
, CRT_MIPS_REL32
);
5813 mips_elf_set_cr_type (cptrel
, CRT_MIPS_WORD
);
5814 mips_elf_set_cr_dist2to (cptrel
, 0);
5815 cptrel
.konst
= *addendp
;
5817 cr
= (scpt
->contents
5818 + sizeof (Elf32_External_compact_rel
));
5819 mips_elf_set_cr_relvaddr (cptrel
, 0);
5820 bfd_elf32_swap_crinfo_out (output_bfd
, &cptrel
,
5821 ((Elf32_External_crinfo
*) cr
5822 + scpt
->reloc_count
));
5823 ++scpt
->reloc_count
;
5827 /* If we've written this relocation for a readonly section,
5828 we need to set DF_TEXTREL again, so that we do not delete the
5830 if (MIPS_ELF_READONLY_SECTION (input_section
))
5831 info
->flags
|= DF_TEXTREL
;
5836 /* Return the MACH for a MIPS e_flags value. */
5839 _bfd_elf_mips_mach (flagword flags
)
5841 switch (flags
& EF_MIPS_MACH
)
5843 case E_MIPS_MACH_3900
:
5844 return bfd_mach_mips3900
;
5846 case E_MIPS_MACH_4010
:
5847 return bfd_mach_mips4010
;
5849 case E_MIPS_MACH_4100
:
5850 return bfd_mach_mips4100
;
5852 case E_MIPS_MACH_4111
:
5853 return bfd_mach_mips4111
;
5855 case E_MIPS_MACH_4120
:
5856 return bfd_mach_mips4120
;
5858 case E_MIPS_MACH_4650
:
5859 return bfd_mach_mips4650
;
5861 case E_MIPS_MACH_5400
:
5862 return bfd_mach_mips5400
;
5864 case E_MIPS_MACH_5500
:
5865 return bfd_mach_mips5500
;
5867 case E_MIPS_MACH_9000
:
5868 return bfd_mach_mips9000
;
5870 case E_MIPS_MACH_SB1
:
5871 return bfd_mach_mips_sb1
;
5873 case E_MIPS_MACH_LS2E
:
5874 return bfd_mach_mips_loongson_2e
;
5876 case E_MIPS_MACH_LS2F
:
5877 return bfd_mach_mips_loongson_2f
;
5879 case E_MIPS_MACH_OCTEON
:
5880 return bfd_mach_mips_octeon
;
5883 switch (flags
& EF_MIPS_ARCH
)
5887 return bfd_mach_mips3000
;
5890 return bfd_mach_mips6000
;
5893 return bfd_mach_mips4000
;
5896 return bfd_mach_mips8000
;
5899 return bfd_mach_mips5
;
5901 case E_MIPS_ARCH_32
:
5902 return bfd_mach_mipsisa32
;
5904 case E_MIPS_ARCH_64
:
5905 return bfd_mach_mipsisa64
;
5907 case E_MIPS_ARCH_32R2
:
5908 return bfd_mach_mipsisa32r2
;
5910 case E_MIPS_ARCH_64R2
:
5911 return bfd_mach_mipsisa64r2
;
5918 /* Return printable name for ABI. */
5920 static INLINE
char *
5921 elf_mips_abi_name (bfd
*abfd
)
5925 flags
= elf_elfheader (abfd
)->e_flags
;
5926 switch (flags
& EF_MIPS_ABI
)
5929 if (ABI_N32_P (abfd
))
5931 else if (ABI_64_P (abfd
))
5935 case E_MIPS_ABI_O32
:
5937 case E_MIPS_ABI_O64
:
5939 case E_MIPS_ABI_EABI32
:
5941 case E_MIPS_ABI_EABI64
:
5944 return "unknown abi";
5948 /* MIPS ELF uses two common sections. One is the usual one, and the
5949 other is for small objects. All the small objects are kept
5950 together, and then referenced via the gp pointer, which yields
5951 faster assembler code. This is what we use for the small common
5952 section. This approach is copied from ecoff.c. */
5953 static asection mips_elf_scom_section
;
5954 static asymbol mips_elf_scom_symbol
;
5955 static asymbol
*mips_elf_scom_symbol_ptr
;
5957 /* MIPS ELF also uses an acommon section, which represents an
5958 allocated common symbol which may be overridden by a
5959 definition in a shared library. */
5960 static asection mips_elf_acom_section
;
5961 static asymbol mips_elf_acom_symbol
;
5962 static asymbol
*mips_elf_acom_symbol_ptr
;
5964 /* This is used for both the 32-bit and the 64-bit ABI. */
5967 _bfd_mips_elf_symbol_processing (bfd
*abfd
, asymbol
*asym
)
5969 elf_symbol_type
*elfsym
;
5971 /* Handle the special MIPS section numbers that a symbol may use. */
5972 elfsym
= (elf_symbol_type
*) asym
;
5973 switch (elfsym
->internal_elf_sym
.st_shndx
)
5975 case SHN_MIPS_ACOMMON
:
5976 /* This section is used in a dynamically linked executable file.
5977 It is an allocated common section. The dynamic linker can
5978 either resolve these symbols to something in a shared
5979 library, or it can just leave them here. For our purposes,
5980 we can consider these symbols to be in a new section. */
5981 if (mips_elf_acom_section
.name
== NULL
)
5983 /* Initialize the acommon section. */
5984 mips_elf_acom_section
.name
= ".acommon";
5985 mips_elf_acom_section
.flags
= SEC_ALLOC
;
5986 mips_elf_acom_section
.output_section
= &mips_elf_acom_section
;
5987 mips_elf_acom_section
.symbol
= &mips_elf_acom_symbol
;
5988 mips_elf_acom_section
.symbol_ptr_ptr
= &mips_elf_acom_symbol_ptr
;
5989 mips_elf_acom_symbol
.name
= ".acommon";
5990 mips_elf_acom_symbol
.flags
= BSF_SECTION_SYM
;
5991 mips_elf_acom_symbol
.section
= &mips_elf_acom_section
;
5992 mips_elf_acom_symbol_ptr
= &mips_elf_acom_symbol
;
5994 asym
->section
= &mips_elf_acom_section
;
5998 /* Common symbols less than the GP size are automatically
5999 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */
6000 if (asym
->value
> elf_gp_size (abfd
)
6001 || ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_TLS
6002 || IRIX_COMPAT (abfd
) == ict_irix6
)
6005 case SHN_MIPS_SCOMMON
:
6006 if (mips_elf_scom_section
.name
== NULL
)
6008 /* Initialize the small common section. */
6009 mips_elf_scom_section
.name
= ".scommon";
6010 mips_elf_scom_section
.flags
= SEC_IS_COMMON
;
6011 mips_elf_scom_section
.output_section
= &mips_elf_scom_section
;
6012 mips_elf_scom_section
.symbol
= &mips_elf_scom_symbol
;
6013 mips_elf_scom_section
.symbol_ptr_ptr
= &mips_elf_scom_symbol_ptr
;
6014 mips_elf_scom_symbol
.name
= ".scommon";
6015 mips_elf_scom_symbol
.flags
= BSF_SECTION_SYM
;
6016 mips_elf_scom_symbol
.section
= &mips_elf_scom_section
;
6017 mips_elf_scom_symbol_ptr
= &mips_elf_scom_symbol
;
6019 asym
->section
= &mips_elf_scom_section
;
6020 asym
->value
= elfsym
->internal_elf_sym
.st_size
;
6023 case SHN_MIPS_SUNDEFINED
:
6024 asym
->section
= bfd_und_section_ptr
;
6029 asection
*section
= bfd_get_section_by_name (abfd
, ".text");
6031 BFD_ASSERT (SGI_COMPAT (abfd
));
6032 if (section
!= NULL
)
6034 asym
->section
= section
;
6035 /* MIPS_TEXT is a bit special, the address is not an offset
6036 to the base of the .text section. So substract the section
6037 base address to make it an offset. */
6038 asym
->value
-= section
->vma
;
6045 asection
*section
= bfd_get_section_by_name (abfd
, ".data");
6047 BFD_ASSERT (SGI_COMPAT (abfd
));
6048 if (section
!= NULL
)
6050 asym
->section
= section
;
6051 /* MIPS_DATA is a bit special, the address is not an offset
6052 to the base of the .data section. So substract the section
6053 base address to make it an offset. */
6054 asym
->value
-= section
->vma
;
6060 /* If this is an odd-valued function symbol, assume it's a MIPS16 one. */
6061 if (ELF_ST_TYPE (elfsym
->internal_elf_sym
.st_info
) == STT_FUNC
6062 && (asym
->value
& 1) != 0)
6065 elfsym
->internal_elf_sym
.st_other
6066 = ELF_ST_SET_MIPS16 (elfsym
->internal_elf_sym
.st_other
);
6070 /* Implement elf_backend_eh_frame_address_size. This differs from
6071 the default in the way it handles EABI64.
6073 EABI64 was originally specified as an LP64 ABI, and that is what
6074 -mabi=eabi normally gives on a 64-bit target. However, gcc has
6075 historically accepted the combination of -mabi=eabi and -mlong32,
6076 and this ILP32 variation has become semi-official over time.
6077 Both forms use elf32 and have pointer-sized FDE addresses.
6079 If an EABI object was generated by GCC 4.0 or above, it will have
6080 an empty .gcc_compiled_longXX section, where XX is the size of longs
6081 in bits. Unfortunately, ILP32 objects generated by earlier compilers
6082 have no special marking to distinguish them from LP64 objects.
6084 We don't want users of the official LP64 ABI to be punished for the
6085 existence of the ILP32 variant, but at the same time, we don't want
6086 to mistakenly interpret pre-4.0 ILP32 objects as being LP64 objects.
6087 We therefore take the following approach:
6089 - If ABFD contains a .gcc_compiled_longXX section, use it to
6090 determine the pointer size.
6092 - Otherwise check the type of the first relocation. Assume that
6093 the LP64 ABI is being used if the relocation is of type R_MIPS_64.
6097 The second check is enough to detect LP64 objects generated by pre-4.0
6098 compilers because, in the kind of output generated by those compilers,
6099 the first relocation will be associated with either a CIE personality
6100 routine or an FDE start address. Furthermore, the compilers never
6101 used a special (non-pointer) encoding for this ABI.
6103 Checking the relocation type should also be safe because there is no
6104 reason to use R_MIPS_64 in an ILP32 object. Pre-4.0 compilers never
6108 _bfd_mips_elf_eh_frame_address_size (bfd
*abfd
, asection
*sec
)
6110 if (elf_elfheader (abfd
)->e_ident
[EI_CLASS
] == ELFCLASS64
)
6112 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
6114 bfd_boolean long32_p
, long64_p
;
6116 long32_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long32") != 0;
6117 long64_p
= bfd_get_section_by_name (abfd
, ".gcc_compiled_long64") != 0;
6118 if (long32_p
&& long64_p
)
6125 if (sec
->reloc_count
> 0
6126 && elf_section_data (sec
)->relocs
!= NULL
6127 && (ELF32_R_TYPE (elf_section_data (sec
)->relocs
[0].r_info
)
6136 /* There appears to be a bug in the MIPSpro linker that causes GOT_DISP
6137 relocations against two unnamed section symbols to resolve to the
6138 same address. For example, if we have code like:
6140 lw $4,%got_disp(.data)($gp)
6141 lw $25,%got_disp(.text)($gp)
6144 then the linker will resolve both relocations to .data and the program
6145 will jump there rather than to .text.
6147 We can work around this problem by giving names to local section symbols.
6148 This is also what the MIPSpro tools do. */
6151 _bfd_mips_elf_name_local_section_symbols (bfd
*abfd
)
6153 return SGI_COMPAT (abfd
);
6156 /* Work over a section just before writing it out. This routine is
6157 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize
6158 sections that need the SHF_MIPS_GPREL flag by name; there has to be
6162 _bfd_mips_elf_section_processing (bfd
*abfd
, Elf_Internal_Shdr
*hdr
)
6164 if (hdr
->sh_type
== SHT_MIPS_REGINFO
6165 && hdr
->sh_size
> 0)
6169 BFD_ASSERT (hdr
->sh_size
== sizeof (Elf32_External_RegInfo
));
6170 BFD_ASSERT (hdr
->contents
== NULL
);
6173 hdr
->sh_offset
+ sizeof (Elf32_External_RegInfo
) - 4,
6176 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
6177 if (bfd_bwrite (buf
, 4, abfd
) != 4)
6181 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
6182 && hdr
->bfd_section
!= NULL
6183 && mips_elf_section_data (hdr
->bfd_section
) != NULL
6184 && mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
!= NULL
)
6186 bfd_byte
*contents
, *l
, *lend
;
6188 /* We stored the section contents in the tdata field in the
6189 set_section_contents routine. We save the section contents
6190 so that we don't have to read them again.
6191 At this point we know that elf_gp is set, so we can look
6192 through the section contents to see if there is an
6193 ODK_REGINFO structure. */
6195 contents
= mips_elf_section_data (hdr
->bfd_section
)->u
.tdata
;
6197 lend
= contents
+ hdr
->sh_size
;
6198 while (l
+ sizeof (Elf_External_Options
) <= lend
)
6200 Elf_Internal_Options intopt
;
6202 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
6204 if (intopt
.size
< sizeof (Elf_External_Options
))
6206 (*_bfd_error_handler
)
6207 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
6208 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
6211 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
6218 + sizeof (Elf_External_Options
)
6219 + (sizeof (Elf64_External_RegInfo
) - 8)),
6222 H_PUT_64 (abfd
, elf_gp (abfd
), buf
);
6223 if (bfd_bwrite (buf
, 8, abfd
) != 8)
6226 else if (intopt
.kind
== ODK_REGINFO
)
6233 + sizeof (Elf_External_Options
)
6234 + (sizeof (Elf32_External_RegInfo
) - 4)),
6237 H_PUT_32 (abfd
, elf_gp (abfd
), buf
);
6238 if (bfd_bwrite (buf
, 4, abfd
) != 4)
6245 if (hdr
->bfd_section
!= NULL
)
6247 const char *name
= bfd_get_section_name (abfd
, hdr
->bfd_section
);
6249 if (strcmp (name
, ".sdata") == 0
6250 || strcmp (name
, ".lit8") == 0
6251 || strcmp (name
, ".lit4") == 0)
6253 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
6254 hdr
->sh_type
= SHT_PROGBITS
;
6256 else if (strcmp (name
, ".sbss") == 0)
6258 hdr
->sh_flags
|= SHF_ALLOC
| SHF_WRITE
| SHF_MIPS_GPREL
;
6259 hdr
->sh_type
= SHT_NOBITS
;
6261 else if (strcmp (name
, ".srdata") == 0)
6263 hdr
->sh_flags
|= SHF_ALLOC
| SHF_MIPS_GPREL
;
6264 hdr
->sh_type
= SHT_PROGBITS
;
6266 else if (strcmp (name
, ".compact_rel") == 0)
6269 hdr
->sh_type
= SHT_PROGBITS
;
6271 else if (strcmp (name
, ".rtproc") == 0)
6273 if (hdr
->sh_addralign
!= 0 && hdr
->sh_entsize
== 0)
6275 unsigned int adjust
;
6277 adjust
= hdr
->sh_size
% hdr
->sh_addralign
;
6279 hdr
->sh_size
+= hdr
->sh_addralign
- adjust
;
6287 /* Handle a MIPS specific section when reading an object file. This
6288 is called when elfcode.h finds a section with an unknown type.
6289 This routine supports both the 32-bit and 64-bit ELF ABI.
6291 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure
6295 _bfd_mips_elf_section_from_shdr (bfd
*abfd
,
6296 Elf_Internal_Shdr
*hdr
,
6302 /* There ought to be a place to keep ELF backend specific flags, but
6303 at the moment there isn't one. We just keep track of the
6304 sections by their name, instead. Fortunately, the ABI gives
6305 suggested names for all the MIPS specific sections, so we will
6306 probably get away with this. */
6307 switch (hdr
->sh_type
)
6309 case SHT_MIPS_LIBLIST
:
6310 if (strcmp (name
, ".liblist") != 0)
6314 if (strcmp (name
, ".msym") != 0)
6317 case SHT_MIPS_CONFLICT
:
6318 if (strcmp (name
, ".conflict") != 0)
6321 case SHT_MIPS_GPTAB
:
6322 if (! CONST_STRNEQ (name
, ".gptab."))
6325 case SHT_MIPS_UCODE
:
6326 if (strcmp (name
, ".ucode") != 0)
6329 case SHT_MIPS_DEBUG
:
6330 if (strcmp (name
, ".mdebug") != 0)
6332 flags
= SEC_DEBUGGING
;
6334 case SHT_MIPS_REGINFO
:
6335 if (strcmp (name
, ".reginfo") != 0
6336 || hdr
->sh_size
!= sizeof (Elf32_External_RegInfo
))
6338 flags
= (SEC_LINK_ONCE
| SEC_LINK_DUPLICATES_SAME_SIZE
);
6340 case SHT_MIPS_IFACE
:
6341 if (strcmp (name
, ".MIPS.interfaces") != 0)
6344 case SHT_MIPS_CONTENT
:
6345 if (! CONST_STRNEQ (name
, ".MIPS.content"))
6348 case SHT_MIPS_OPTIONS
:
6349 if (!MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
6352 case SHT_MIPS_DWARF
:
6353 if (! CONST_STRNEQ (name
, ".debug_")
6354 && ! CONST_STRNEQ (name
, ".zdebug_"))
6357 case SHT_MIPS_SYMBOL_LIB
:
6358 if (strcmp (name
, ".MIPS.symlib") != 0)
6361 case SHT_MIPS_EVENTS
:
6362 if (! CONST_STRNEQ (name
, ".MIPS.events")
6363 && ! CONST_STRNEQ (name
, ".MIPS.post_rel"))
6370 if (! _bfd_elf_make_section_from_shdr (abfd
, hdr
, name
, shindex
))
6375 if (! bfd_set_section_flags (abfd
, hdr
->bfd_section
,
6376 (bfd_get_section_flags (abfd
,
6382 /* FIXME: We should record sh_info for a .gptab section. */
6384 /* For a .reginfo section, set the gp value in the tdata information
6385 from the contents of this section. We need the gp value while
6386 processing relocs, so we just get it now. The .reginfo section
6387 is not used in the 64-bit MIPS ELF ABI. */
6388 if (hdr
->sh_type
== SHT_MIPS_REGINFO
)
6390 Elf32_External_RegInfo ext
;
6393 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
,
6394 &ext
, 0, sizeof ext
))
6396 bfd_mips_elf32_swap_reginfo_in (abfd
, &ext
, &s
);
6397 elf_gp (abfd
) = s
.ri_gp_value
;
6400 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and
6401 set the gp value based on what we find. We may see both
6402 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case,
6403 they should agree. */
6404 if (hdr
->sh_type
== SHT_MIPS_OPTIONS
)
6406 bfd_byte
*contents
, *l
, *lend
;
6408 contents
= bfd_malloc (hdr
->sh_size
);
6409 if (contents
== NULL
)
6411 if (! bfd_get_section_contents (abfd
, hdr
->bfd_section
, contents
,
6418 lend
= contents
+ hdr
->sh_size
;
6419 while (l
+ sizeof (Elf_External_Options
) <= lend
)
6421 Elf_Internal_Options intopt
;
6423 bfd_mips_elf_swap_options_in (abfd
, (Elf_External_Options
*) l
,
6425 if (intopt
.size
< sizeof (Elf_External_Options
))
6427 (*_bfd_error_handler
)
6428 (_("%B: Warning: bad `%s' option size %u smaller than its header"),
6429 abfd
, MIPS_ELF_OPTIONS_SECTION_NAME (abfd
), intopt
.size
);
6432 if (ABI_64_P (abfd
) && intopt
.kind
== ODK_REGINFO
)
6434 Elf64_Internal_RegInfo intreg
;
6436 bfd_mips_elf64_swap_reginfo_in
6438 ((Elf64_External_RegInfo
*)
6439 (l
+ sizeof (Elf_External_Options
))),
6441 elf_gp (abfd
) = intreg
.ri_gp_value
;
6443 else if (intopt
.kind
== ODK_REGINFO
)
6445 Elf32_RegInfo intreg
;
6447 bfd_mips_elf32_swap_reginfo_in
6449 ((Elf32_External_RegInfo
*)
6450 (l
+ sizeof (Elf_External_Options
))),
6452 elf_gp (abfd
) = intreg
.ri_gp_value
;
6462 /* Set the correct type for a MIPS ELF section. We do this by the
6463 section name, which is a hack, but ought to work. This routine is
6464 used by both the 32-bit and the 64-bit ABI. */
6467 _bfd_mips_elf_fake_sections (bfd
*abfd
, Elf_Internal_Shdr
*hdr
, asection
*sec
)
6469 const char *name
= bfd_get_section_name (abfd
, sec
);
6471 if (strcmp (name
, ".liblist") == 0)
6473 hdr
->sh_type
= SHT_MIPS_LIBLIST
;
6474 hdr
->sh_info
= sec
->size
/ sizeof (Elf32_Lib
);
6475 /* The sh_link field is set in final_write_processing. */
6477 else if (strcmp (name
, ".conflict") == 0)
6478 hdr
->sh_type
= SHT_MIPS_CONFLICT
;
6479 else if (CONST_STRNEQ (name
, ".gptab."))
6481 hdr
->sh_type
= SHT_MIPS_GPTAB
;
6482 hdr
->sh_entsize
= sizeof (Elf32_External_gptab
);
6483 /* The sh_info field is set in final_write_processing. */
6485 else if (strcmp (name
, ".ucode") == 0)
6486 hdr
->sh_type
= SHT_MIPS_UCODE
;
6487 else if (strcmp (name
, ".mdebug") == 0)
6489 hdr
->sh_type
= SHT_MIPS_DEBUG
;
6490 /* In a shared object on IRIX 5.3, the .mdebug section has an
6491 entsize of 0. FIXME: Does this matter? */
6492 if (SGI_COMPAT (abfd
) && (abfd
->flags
& DYNAMIC
) != 0)
6493 hdr
->sh_entsize
= 0;
6495 hdr
->sh_entsize
= 1;
6497 else if (strcmp (name
, ".reginfo") == 0)
6499 hdr
->sh_type
= SHT_MIPS_REGINFO
;
6500 /* In a shared object on IRIX 5.3, the .reginfo section has an
6501 entsize of 0x18. FIXME: Does this matter? */
6502 if (SGI_COMPAT (abfd
))
6504 if ((abfd
->flags
& DYNAMIC
) != 0)
6505 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6507 hdr
->sh_entsize
= 1;
6510 hdr
->sh_entsize
= sizeof (Elf32_External_RegInfo
);
6512 else if (SGI_COMPAT (abfd
)
6513 && (strcmp (name
, ".hash") == 0
6514 || strcmp (name
, ".dynamic") == 0
6515 || strcmp (name
, ".dynstr") == 0))
6517 if (SGI_COMPAT (abfd
))
6518 hdr
->sh_entsize
= 0;
6520 /* This isn't how the IRIX6 linker behaves. */
6521 hdr
->sh_info
= SIZEOF_MIPS_DYNSYM_SECNAMES
;
6524 else if (strcmp (name
, ".got") == 0
6525 || strcmp (name
, ".srdata") == 0
6526 || strcmp (name
, ".sdata") == 0
6527 || strcmp (name
, ".sbss") == 0
6528 || strcmp (name
, ".lit4") == 0
6529 || strcmp (name
, ".lit8") == 0)
6530 hdr
->sh_flags
|= SHF_MIPS_GPREL
;
6531 else if (strcmp (name
, ".MIPS.interfaces") == 0)
6533 hdr
->sh_type
= SHT_MIPS_IFACE
;
6534 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6536 else if (CONST_STRNEQ (name
, ".MIPS.content"))
6538 hdr
->sh_type
= SHT_MIPS_CONTENT
;
6539 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6540 /* The sh_info field is set in final_write_processing. */
6542 else if (MIPS_ELF_OPTIONS_SECTION_NAME_P (name
))
6544 hdr
->sh_type
= SHT_MIPS_OPTIONS
;
6545 hdr
->sh_entsize
= 1;
6546 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6548 else if (CONST_STRNEQ (name
, ".debug_")
6549 || CONST_STRNEQ (name
, ".zdebug_"))
6551 hdr
->sh_type
= SHT_MIPS_DWARF
;
6553 /* Irix facilities such as libexc expect a single .debug_frame
6554 per executable, the system ones have NOSTRIP set and the linker
6555 doesn't merge sections with different flags so ... */
6556 if (SGI_COMPAT (abfd
) && CONST_STRNEQ (name
, ".debug_frame"))
6557 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6559 else if (strcmp (name
, ".MIPS.symlib") == 0)
6561 hdr
->sh_type
= SHT_MIPS_SYMBOL_LIB
;
6562 /* The sh_link and sh_info fields are set in
6563 final_write_processing. */
6565 else if (CONST_STRNEQ (name
, ".MIPS.events")
6566 || CONST_STRNEQ (name
, ".MIPS.post_rel"))
6568 hdr
->sh_type
= SHT_MIPS_EVENTS
;
6569 hdr
->sh_flags
|= SHF_MIPS_NOSTRIP
;
6570 /* The sh_link field is set in final_write_processing. */
6572 else if (strcmp (name
, ".msym") == 0)
6574 hdr
->sh_type
= SHT_MIPS_MSYM
;
6575 hdr
->sh_flags
|= SHF_ALLOC
;
6576 hdr
->sh_entsize
= 8;
6579 /* The generic elf_fake_sections will set up REL_HDR using the default
6580 kind of relocations. We used to set up a second header for the
6581 non-default kind of relocations here, but only NewABI would use
6582 these, and the IRIX ld doesn't like resulting empty RELA sections.
6583 Thus we create those header only on demand now. */
6588 /* Given a BFD section, try to locate the corresponding ELF section
6589 index. This is used by both the 32-bit and the 64-bit ABI.
6590 Actually, it's not clear to me that the 64-bit ABI supports these,
6591 but for non-PIC objects we will certainly want support for at least
6592 the .scommon section. */
6595 _bfd_mips_elf_section_from_bfd_section (bfd
*abfd ATTRIBUTE_UNUSED
,
6596 asection
*sec
, int *retval
)
6598 if (strcmp (bfd_get_section_name (abfd
, sec
), ".scommon") == 0)
6600 *retval
= SHN_MIPS_SCOMMON
;
6603 if (strcmp (bfd_get_section_name (abfd
, sec
), ".acommon") == 0)
6605 *retval
= SHN_MIPS_ACOMMON
;
6611 /* Hook called by the linker routine which adds symbols from an object
6612 file. We must handle the special MIPS section numbers here. */
6615 _bfd_mips_elf_add_symbol_hook (bfd
*abfd
, struct bfd_link_info
*info
,
6616 Elf_Internal_Sym
*sym
, const char **namep
,
6617 flagword
*flagsp ATTRIBUTE_UNUSED
,
6618 asection
**secp
, bfd_vma
*valp
)
6620 if (SGI_COMPAT (abfd
)
6621 && (abfd
->flags
& DYNAMIC
) != 0
6622 && strcmp (*namep
, "_rld_new_interface") == 0)
6624 /* Skip IRIX5 rld entry name. */
6629 /* Shared objects may have a dynamic symbol '_gp_disp' defined as
6630 a SECTION *ABS*. This causes ld to think it can resolve _gp_disp
6631 by setting a DT_NEEDED for the shared object. Since _gp_disp is
6632 a magic symbol resolved by the linker, we ignore this bogus definition
6633 of _gp_disp. New ABI objects do not suffer from this problem so this
6634 is not done for them. */
6636 && (sym
->st_shndx
== SHN_ABS
)
6637 && (strcmp (*namep
, "_gp_disp") == 0))
6643 switch (sym
->st_shndx
)
6646 /* Common symbols less than the GP size are automatically
6647 treated as SHN_MIPS_SCOMMON symbols. */
6648 if (sym
->st_size
> elf_gp_size (abfd
)
6649 || ELF_ST_TYPE (sym
->st_info
) == STT_TLS
6650 || IRIX_COMPAT (abfd
) == ict_irix6
)
6653 case SHN_MIPS_SCOMMON
:
6654 *secp
= bfd_make_section_old_way (abfd
, ".scommon");
6655 (*secp
)->flags
|= SEC_IS_COMMON
;
6656 *valp
= sym
->st_size
;
6660 /* This section is used in a shared object. */
6661 if (elf_tdata (abfd
)->elf_text_section
== NULL
)
6663 asymbol
*elf_text_symbol
;
6664 asection
*elf_text_section
;
6665 bfd_size_type amt
= sizeof (asection
);
6667 elf_text_section
= bfd_zalloc (abfd
, amt
);
6668 if (elf_text_section
== NULL
)
6671 amt
= sizeof (asymbol
);
6672 elf_text_symbol
= bfd_zalloc (abfd
, amt
);
6673 if (elf_text_symbol
== NULL
)
6676 /* Initialize the section. */
6678 elf_tdata (abfd
)->elf_text_section
= elf_text_section
;
6679 elf_tdata (abfd
)->elf_text_symbol
= elf_text_symbol
;
6681 elf_text_section
->symbol
= elf_text_symbol
;
6682 elf_text_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_text_symbol
;
6684 elf_text_section
->name
= ".text";
6685 elf_text_section
->flags
= SEC_NO_FLAGS
;
6686 elf_text_section
->output_section
= NULL
;
6687 elf_text_section
->owner
= abfd
;
6688 elf_text_symbol
->name
= ".text";
6689 elf_text_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6690 elf_text_symbol
->section
= elf_text_section
;
6692 /* This code used to do *secp = bfd_und_section_ptr if
6693 info->shared. I don't know why, and that doesn't make sense,
6694 so I took it out. */
6695 *secp
= elf_tdata (abfd
)->elf_text_section
;
6698 case SHN_MIPS_ACOMMON
:
6699 /* Fall through. XXX Can we treat this as allocated data? */
6701 /* This section is used in a shared object. */
6702 if (elf_tdata (abfd
)->elf_data_section
== NULL
)
6704 asymbol
*elf_data_symbol
;
6705 asection
*elf_data_section
;
6706 bfd_size_type amt
= sizeof (asection
);
6708 elf_data_section
= bfd_zalloc (abfd
, amt
);
6709 if (elf_data_section
== NULL
)
6712 amt
= sizeof (asymbol
);
6713 elf_data_symbol
= bfd_zalloc (abfd
, amt
);
6714 if (elf_data_symbol
== NULL
)
6717 /* Initialize the section. */
6719 elf_tdata (abfd
)->elf_data_section
= elf_data_section
;
6720 elf_tdata (abfd
)->elf_data_symbol
= elf_data_symbol
;
6722 elf_data_section
->symbol
= elf_data_symbol
;
6723 elf_data_section
->symbol_ptr_ptr
= &elf_tdata (abfd
)->elf_data_symbol
;
6725 elf_data_section
->name
= ".data";
6726 elf_data_section
->flags
= SEC_NO_FLAGS
;
6727 elf_data_section
->output_section
= NULL
;
6728 elf_data_section
->owner
= abfd
;
6729 elf_data_symbol
->name
= ".data";
6730 elf_data_symbol
->flags
= BSF_SECTION_SYM
| BSF_DYNAMIC
;
6731 elf_data_symbol
->section
= elf_data_section
;
6733 /* This code used to do *secp = bfd_und_section_ptr if
6734 info->shared. I don't know why, and that doesn't make sense,
6735 so I took it out. */
6736 *secp
= elf_tdata (abfd
)->elf_data_section
;
6739 case SHN_MIPS_SUNDEFINED
:
6740 *secp
= bfd_und_section_ptr
;
6744 if (SGI_COMPAT (abfd
)
6746 && info
->output_bfd
->xvec
== abfd
->xvec
6747 && strcmp (*namep
, "__rld_obj_head") == 0)
6749 struct elf_link_hash_entry
*h
;
6750 struct bfd_link_hash_entry
*bh
;
6752 /* Mark __rld_obj_head as dynamic. */
6754 if (! (_bfd_generic_link_add_one_symbol
6755 (info
, abfd
, *namep
, BSF_GLOBAL
, *secp
, *valp
, NULL
, FALSE
,
6756 get_elf_backend_data (abfd
)->collect
, &bh
)))
6759 h
= (struct elf_link_hash_entry
*) bh
;
6762 h
->type
= STT_OBJECT
;
6764 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6767 mips_elf_hash_table (info
)->use_rld_obj_head
= TRUE
;
6770 /* If this is a mips16 text symbol, add 1 to the value to make it
6771 odd. This will cause something like .word SYM to come up with
6772 the right value when it is loaded into the PC. */
6773 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6779 /* This hook function is called before the linker writes out a global
6780 symbol. We mark symbols as small common if appropriate. This is
6781 also where we undo the increment of the value for a mips16 symbol. */
6784 _bfd_mips_elf_link_output_symbol_hook
6785 (struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
6786 const char *name ATTRIBUTE_UNUSED
, Elf_Internal_Sym
*sym
,
6787 asection
*input_sec
, struct elf_link_hash_entry
*h ATTRIBUTE_UNUSED
)
6789 /* If we see a common symbol, which implies a relocatable link, then
6790 if a symbol was small common in an input file, mark it as small
6791 common in the output file. */
6792 if (sym
->st_shndx
== SHN_COMMON
6793 && strcmp (input_sec
->name
, ".scommon") == 0)
6794 sym
->st_shndx
= SHN_MIPS_SCOMMON
;
6796 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
6797 sym
->st_value
&= ~1;
6802 /* Functions for the dynamic linker. */
6804 /* Create dynamic sections when linking against a dynamic object. */
6807 _bfd_mips_elf_create_dynamic_sections (bfd
*abfd
, struct bfd_link_info
*info
)
6809 struct elf_link_hash_entry
*h
;
6810 struct bfd_link_hash_entry
*bh
;
6812 register asection
*s
;
6813 const char * const *namep
;
6814 struct mips_elf_link_hash_table
*htab
;
6816 htab
= mips_elf_hash_table (info
);
6817 flags
= (SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
6818 | SEC_LINKER_CREATED
| SEC_READONLY
);
6820 /* The psABI requires a read-only .dynamic section, but the VxWorks
6822 if (!htab
->is_vxworks
)
6824 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6827 if (! bfd_set_section_flags (abfd
, s
, flags
))
6832 /* We need to create .got section. */
6833 if (!mips_elf_create_got_section (abfd
, info
))
6836 if (! mips_elf_rel_dyn_section (info
, TRUE
))
6839 /* Create .stub section. */
6840 s
= bfd_make_section_with_flags (abfd
,
6841 MIPS_ELF_STUB_SECTION_NAME (abfd
),
6844 || ! bfd_set_section_alignment (abfd
, s
,
6845 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6849 if ((IRIX_COMPAT (abfd
) == ict_irix5
|| IRIX_COMPAT (abfd
) == ict_none
)
6851 && bfd_get_section_by_name (abfd
, ".rld_map") == NULL
)
6853 s
= bfd_make_section_with_flags (abfd
, ".rld_map",
6854 flags
&~ (flagword
) SEC_READONLY
);
6856 || ! bfd_set_section_alignment (abfd
, s
,
6857 MIPS_ELF_LOG_FILE_ALIGN (abfd
)))
6861 /* On IRIX5, we adjust add some additional symbols and change the
6862 alignments of several sections. There is no ABI documentation
6863 indicating that this is necessary on IRIX6, nor any evidence that
6864 the linker takes such action. */
6865 if (IRIX_COMPAT (abfd
) == ict_irix5
)
6867 for (namep
= mips_elf_dynsym_rtproc_names
; *namep
!= NULL
; namep
++)
6870 if (! (_bfd_generic_link_add_one_symbol
6871 (info
, abfd
, *namep
, BSF_GLOBAL
, bfd_und_section_ptr
, 0,
6872 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6875 h
= (struct elf_link_hash_entry
*) bh
;
6878 h
->type
= STT_SECTION
;
6880 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6884 /* We need to create a .compact_rel section. */
6885 if (SGI_COMPAT (abfd
))
6887 if (!mips_elf_create_compact_rel_section (abfd
, info
))
6891 /* Change alignments of some sections. */
6892 s
= bfd_get_section_by_name (abfd
, ".hash");
6894 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6895 s
= bfd_get_section_by_name (abfd
, ".dynsym");
6897 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6898 s
= bfd_get_section_by_name (abfd
, ".dynstr");
6900 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6901 s
= bfd_get_section_by_name (abfd
, ".reginfo");
6903 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6904 s
= bfd_get_section_by_name (abfd
, ".dynamic");
6906 bfd_set_section_alignment (abfd
, s
, MIPS_ELF_LOG_FILE_ALIGN (abfd
));
6913 name
= SGI_COMPAT (abfd
) ? "_DYNAMIC_LINK" : "_DYNAMIC_LINKING";
6915 if (!(_bfd_generic_link_add_one_symbol
6916 (info
, abfd
, name
, BSF_GLOBAL
, bfd_abs_section_ptr
, 0,
6917 NULL
, FALSE
, get_elf_backend_data (abfd
)->collect
, &bh
)))
6920 h
= (struct elf_link_hash_entry
*) bh
;
6923 h
->type
= STT_SECTION
;
6925 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6928 if (! mips_elf_hash_table (info
)->use_rld_obj_head
)
6930 /* __rld_map is a four byte word located in the .data section
6931 and is filled in by the rtld to contain a pointer to
6932 the _r_debug structure. Its symbol value will be set in
6933 _bfd_mips_elf_finish_dynamic_symbol. */
6934 s
= bfd_get_section_by_name (abfd
, ".rld_map");
6935 BFD_ASSERT (s
!= NULL
);
6937 name
= SGI_COMPAT (abfd
) ? "__rld_map" : "__RLD_MAP";
6939 if (!(_bfd_generic_link_add_one_symbol
6940 (info
, abfd
, name
, BSF_GLOBAL
, s
, 0, NULL
, FALSE
,
6941 get_elf_backend_data (abfd
)->collect
, &bh
)))
6944 h
= (struct elf_link_hash_entry
*) bh
;
6947 h
->type
= STT_OBJECT
;
6949 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
6954 /* Create the .plt, .rel(a).plt, .dynbss and .rel(a).bss sections.
6955 Also create the _PROCEDURE_LINKAGE_TABLE symbol. */
6956 if (!_bfd_elf_create_dynamic_sections (abfd
, info
))
6959 /* Cache the sections created above. */
6960 htab
->splt
= bfd_get_section_by_name (abfd
, ".plt");
6961 htab
->sdynbss
= bfd_get_section_by_name (abfd
, ".dynbss");
6962 if (htab
->is_vxworks
)
6964 htab
->srelbss
= bfd_get_section_by_name (abfd
, ".rela.bss");
6965 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rela.plt");
6968 htab
->srelplt
= bfd_get_section_by_name (abfd
, ".rel.plt");
6970 || (htab
->is_vxworks
&& !htab
->srelbss
&& !info
->shared
)
6975 if (htab
->is_vxworks
)
6977 /* Do the usual VxWorks handling. */
6978 if (!elf_vxworks_create_dynamic_sections (abfd
, info
, &htab
->srelplt2
))
6981 /* Work out the PLT sizes. */
6984 htab
->plt_header_size
6985 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt0_entry
);
6986 htab
->plt_entry_size
6987 = 4 * ARRAY_SIZE (mips_vxworks_shared_plt_entry
);
6991 htab
->plt_header_size
6992 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt0_entry
);
6993 htab
->plt_entry_size
6994 = 4 * ARRAY_SIZE (mips_vxworks_exec_plt_entry
);
6997 else if (!info
->shared
)
6999 /* All variants of the plt0 entry are the same size. */
7000 htab
->plt_header_size
= 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
);
7001 htab
->plt_entry_size
= 4 * ARRAY_SIZE (mips_exec_plt_entry
);
7007 /* Return true if relocation REL against section SEC is a REL rather than
7008 RELA relocation. RELOCS is the first relocation in the section and
7009 ABFD is the bfd that contains SEC. */
7012 mips_elf_rel_relocation_p (bfd
*abfd
, asection
*sec
,
7013 const Elf_Internal_Rela
*relocs
,
7014 const Elf_Internal_Rela
*rel
)
7016 Elf_Internal_Shdr
*rel_hdr
;
7017 const struct elf_backend_data
*bed
;
7019 /* To determine which flavor or relocation this is, we depend on the
7020 fact that the INPUT_SECTION's REL_HDR is read before its REL_HDR2. */
7021 rel_hdr
= &elf_section_data (sec
)->rel_hdr
;
7022 bed
= get_elf_backend_data (abfd
);
7023 if ((size_t) (rel
- relocs
)
7024 >= (NUM_SHDR_ENTRIES (rel_hdr
) * bed
->s
->int_rels_per_ext_rel
))
7025 rel_hdr
= elf_section_data (sec
)->rel_hdr2
;
7026 return rel_hdr
->sh_entsize
== MIPS_ELF_REL_SIZE (abfd
);
7029 /* Read the addend for REL relocation REL, which belongs to bfd ABFD.
7030 HOWTO is the relocation's howto and CONTENTS points to the contents
7031 of the section that REL is against. */
7034 mips_elf_read_rel_addend (bfd
*abfd
, const Elf_Internal_Rela
*rel
,
7035 reloc_howto_type
*howto
, bfd_byte
*contents
)
7038 unsigned int r_type
;
7041 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7042 location
= contents
+ rel
->r_offset
;
7044 /* Get the addend, which is stored in the input file. */
7045 _bfd_mips16_elf_reloc_unshuffle (abfd
, r_type
, FALSE
, location
);
7046 addend
= mips_elf_obtain_contents (howto
, rel
, abfd
, contents
);
7047 _bfd_mips16_elf_reloc_shuffle (abfd
, r_type
, FALSE
, location
);
7049 return addend
& howto
->src_mask
;
7052 /* REL is a relocation in ABFD that needs a partnering LO16 relocation
7053 and *ADDEND is the addend for REL itself. Look for the LO16 relocation
7054 and update *ADDEND with the final addend. Return true on success
7055 or false if the LO16 could not be found. RELEND is the exclusive
7056 upper bound on the relocations for REL's section. */
7059 mips_elf_add_lo16_rel_addend (bfd
*abfd
,
7060 const Elf_Internal_Rela
*rel
,
7061 const Elf_Internal_Rela
*relend
,
7062 bfd_byte
*contents
, bfd_vma
*addend
)
7064 unsigned int r_type
, lo16_type
;
7065 const Elf_Internal_Rela
*lo16_relocation
;
7066 reloc_howto_type
*lo16_howto
;
7069 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7070 if (mips16_reloc_p (r_type
))
7071 lo16_type
= R_MIPS16_LO16
;
7073 lo16_type
= R_MIPS_LO16
;
7075 /* The combined value is the sum of the HI16 addend, left-shifted by
7076 sixteen bits, and the LO16 addend, sign extended. (Usually, the
7077 code does a `lui' of the HI16 value, and then an `addiu' of the
7080 Scan ahead to find a matching LO16 relocation.
7082 According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must
7083 be immediately following. However, for the IRIX6 ABI, the next
7084 relocation may be a composed relocation consisting of several
7085 relocations for the same address. In that case, the R_MIPS_LO16
7086 relocation may occur as one of these. We permit a similar
7087 extension in general, as that is useful for GCC.
7089 In some cases GCC dead code elimination removes the LO16 but keeps
7090 the corresponding HI16. This is strictly speaking a violation of
7091 the ABI but not immediately harmful. */
7092 lo16_relocation
= mips_elf_next_relocation (abfd
, lo16_type
, rel
, relend
);
7093 if (lo16_relocation
== NULL
)
7096 /* Obtain the addend kept there. */
7097 lo16_howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, lo16_type
, FALSE
);
7098 l
= mips_elf_read_rel_addend (abfd
, lo16_relocation
, lo16_howto
, contents
);
7100 l
<<= lo16_howto
->rightshift
;
7101 l
= _bfd_mips_elf_sign_extend (l
, 16);
7108 /* Try to read the contents of section SEC in bfd ABFD. Return true and
7109 store the contents in *CONTENTS on success. Assume that *CONTENTS
7110 already holds the contents if it is nonull on entry. */
7113 mips_elf_get_section_contents (bfd
*abfd
, asection
*sec
, bfd_byte
**contents
)
7118 /* Get cached copy if it exists. */
7119 if (elf_section_data (sec
)->this_hdr
.contents
!= NULL
)
7121 *contents
= elf_section_data (sec
)->this_hdr
.contents
;
7125 return bfd_malloc_and_get_section (abfd
, sec
, contents
);
7128 /* Look through the relocs for a section during the first phase, and
7129 allocate space in the global offset table. */
7132 _bfd_mips_elf_check_relocs (bfd
*abfd
, struct bfd_link_info
*info
,
7133 asection
*sec
, const Elf_Internal_Rela
*relocs
)
7137 Elf_Internal_Shdr
*symtab_hdr
;
7138 struct elf_link_hash_entry
**sym_hashes
;
7140 const Elf_Internal_Rela
*rel
;
7141 const Elf_Internal_Rela
*rel_end
;
7143 const struct elf_backend_data
*bed
;
7144 struct mips_elf_link_hash_table
*htab
;
7147 reloc_howto_type
*howto
;
7149 if (info
->relocatable
)
7152 htab
= mips_elf_hash_table (info
);
7153 dynobj
= elf_hash_table (info
)->dynobj
;
7154 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7155 sym_hashes
= elf_sym_hashes (abfd
);
7156 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7158 bed
= get_elf_backend_data (abfd
);
7159 rel_end
= relocs
+ sec
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
7161 /* Check for the mips16 stub sections. */
7163 name
= bfd_get_section_name (abfd
, sec
);
7164 if (FN_STUB_P (name
))
7166 unsigned long r_symndx
;
7168 /* Look at the relocation information to figure out which symbol
7171 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
7174 (*_bfd_error_handler
)
7175 (_("%B: Warning: cannot determine the target function for"
7176 " stub section `%s'"),
7178 bfd_set_error (bfd_error_bad_value
);
7182 if (r_symndx
< extsymoff
7183 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7187 /* This stub is for a local symbol. This stub will only be
7188 needed if there is some relocation in this BFD, other
7189 than a 16 bit function call, which refers to this symbol. */
7190 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
7192 Elf_Internal_Rela
*sec_relocs
;
7193 const Elf_Internal_Rela
*r
, *rend
;
7195 /* We can ignore stub sections when looking for relocs. */
7196 if ((o
->flags
& SEC_RELOC
) == 0
7197 || o
->reloc_count
== 0
7198 || section_allows_mips16_refs_p (o
))
7202 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
7204 if (sec_relocs
== NULL
)
7207 rend
= sec_relocs
+ o
->reloc_count
;
7208 for (r
= sec_relocs
; r
< rend
; r
++)
7209 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
7210 && !mips16_call_reloc_p (ELF_R_TYPE (abfd
, r
->r_info
)))
7213 if (elf_section_data (o
)->relocs
!= sec_relocs
)
7222 /* There is no non-call reloc for this stub, so we do
7223 not need it. Since this function is called before
7224 the linker maps input sections to output sections, we
7225 can easily discard it by setting the SEC_EXCLUDE
7227 sec
->flags
|= SEC_EXCLUDE
;
7231 /* Record this stub in an array of local symbol stubs for
7233 if (elf_tdata (abfd
)->local_stubs
== NULL
)
7235 unsigned long symcount
;
7239 if (elf_bad_symtab (abfd
))
7240 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
7242 symcount
= symtab_hdr
->sh_info
;
7243 amt
= symcount
* sizeof (asection
*);
7244 n
= bfd_zalloc (abfd
, amt
);
7247 elf_tdata (abfd
)->local_stubs
= n
;
7250 sec
->flags
|= SEC_KEEP
;
7251 elf_tdata (abfd
)->local_stubs
[r_symndx
] = sec
;
7253 /* We don't need to set mips16_stubs_seen in this case.
7254 That flag is used to see whether we need to look through
7255 the global symbol table for stubs. We don't need to set
7256 it here, because we just have a local stub. */
7260 struct mips_elf_link_hash_entry
*h
;
7262 h
= ((struct mips_elf_link_hash_entry
*)
7263 sym_hashes
[r_symndx
- extsymoff
]);
7265 while (h
->root
.root
.type
== bfd_link_hash_indirect
7266 || h
->root
.root
.type
== bfd_link_hash_warning
)
7267 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
7269 /* H is the symbol this stub is for. */
7271 /* If we already have an appropriate stub for this function, we
7272 don't need another one, so we can discard this one. Since
7273 this function is called before the linker maps input sections
7274 to output sections, we can easily discard it by setting the
7275 SEC_EXCLUDE flag. */
7276 if (h
->fn_stub
!= NULL
)
7278 sec
->flags
|= SEC_EXCLUDE
;
7282 sec
->flags
|= SEC_KEEP
;
7284 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
7287 else if (CALL_STUB_P (name
) || CALL_FP_STUB_P (name
))
7289 unsigned long r_symndx
;
7290 struct mips_elf_link_hash_entry
*h
;
7293 /* Look at the relocation information to figure out which symbol
7296 r_symndx
= mips16_stub_symndx (sec
, relocs
, rel_end
);
7299 (*_bfd_error_handler
)
7300 (_("%B: Warning: cannot determine the target function for"
7301 " stub section `%s'"),
7303 bfd_set_error (bfd_error_bad_value
);
7307 if (r_symndx
< extsymoff
7308 || sym_hashes
[r_symndx
- extsymoff
] == NULL
)
7312 /* This stub is for a local symbol. This stub will only be
7313 needed if there is some relocation (R_MIPS16_26) in this BFD
7314 that refers to this symbol. */
7315 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
7317 Elf_Internal_Rela
*sec_relocs
;
7318 const Elf_Internal_Rela
*r
, *rend
;
7320 /* We can ignore stub sections when looking for relocs. */
7321 if ((o
->flags
& SEC_RELOC
) == 0
7322 || o
->reloc_count
== 0
7323 || section_allows_mips16_refs_p (o
))
7327 = _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
7329 if (sec_relocs
== NULL
)
7332 rend
= sec_relocs
+ o
->reloc_count
;
7333 for (r
= sec_relocs
; r
< rend
; r
++)
7334 if (ELF_R_SYM (abfd
, r
->r_info
) == r_symndx
7335 && ELF_R_TYPE (abfd
, r
->r_info
) == R_MIPS16_26
)
7338 if (elf_section_data (o
)->relocs
!= sec_relocs
)
7347 /* There is no non-call reloc for this stub, so we do
7348 not need it. Since this function is called before
7349 the linker maps input sections to output sections, we
7350 can easily discard it by setting the SEC_EXCLUDE
7352 sec
->flags
|= SEC_EXCLUDE
;
7356 /* Record this stub in an array of local symbol call_stubs for
7358 if (elf_tdata (abfd
)->local_call_stubs
== NULL
)
7360 unsigned long symcount
;
7364 if (elf_bad_symtab (abfd
))
7365 symcount
= NUM_SHDR_ENTRIES (symtab_hdr
);
7367 symcount
= symtab_hdr
->sh_info
;
7368 amt
= symcount
* sizeof (asection
*);
7369 n
= bfd_zalloc (abfd
, amt
);
7372 elf_tdata (abfd
)->local_call_stubs
= n
;
7375 sec
->flags
|= SEC_KEEP
;
7376 elf_tdata (abfd
)->local_call_stubs
[r_symndx
] = sec
;
7378 /* We don't need to set mips16_stubs_seen in this case.
7379 That flag is used to see whether we need to look through
7380 the global symbol table for stubs. We don't need to set
7381 it here, because we just have a local stub. */
7385 h
= ((struct mips_elf_link_hash_entry
*)
7386 sym_hashes
[r_symndx
- extsymoff
]);
7388 /* H is the symbol this stub is for. */
7390 if (CALL_FP_STUB_P (name
))
7391 loc
= &h
->call_fp_stub
;
7393 loc
= &h
->call_stub
;
7395 /* If we already have an appropriate stub for this function, we
7396 don't need another one, so we can discard this one. Since
7397 this function is called before the linker maps input sections
7398 to output sections, we can easily discard it by setting the
7399 SEC_EXCLUDE flag. */
7402 sec
->flags
|= SEC_EXCLUDE
;
7406 sec
->flags
|= SEC_KEEP
;
7408 mips_elf_hash_table (info
)->mips16_stubs_seen
= TRUE
;
7414 for (rel
= relocs
; rel
< rel_end
; ++rel
)
7416 unsigned long r_symndx
;
7417 unsigned int r_type
;
7418 struct elf_link_hash_entry
*h
;
7419 bfd_boolean can_make_dynamic_p
;
7421 r_symndx
= ELF_R_SYM (abfd
, rel
->r_info
);
7422 r_type
= ELF_R_TYPE (abfd
, rel
->r_info
);
7424 if (r_symndx
< extsymoff
)
7426 else if (r_symndx
>= extsymoff
+ NUM_SHDR_ENTRIES (symtab_hdr
))
7428 (*_bfd_error_handler
)
7429 (_("%B: Malformed reloc detected for section %s"),
7431 bfd_set_error (bfd_error_bad_value
);
7436 h
= sym_hashes
[r_symndx
- extsymoff
];
7438 && (h
->root
.type
== bfd_link_hash_indirect
7439 || h
->root
.type
== bfd_link_hash_warning
))
7440 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
7443 /* Set CAN_MAKE_DYNAMIC_P to true if we can convert this
7444 relocation into a dynamic one. */
7445 can_make_dynamic_p
= FALSE
;
7448 case R_MIPS16_GOT16
:
7449 case R_MIPS16_CALL16
:
7452 case R_MIPS_CALL_HI16
:
7453 case R_MIPS_CALL_LO16
:
7454 case R_MIPS_GOT_HI16
:
7455 case R_MIPS_GOT_LO16
:
7456 case R_MIPS_GOT_PAGE
:
7457 case R_MIPS_GOT_OFST
:
7458 case R_MIPS_GOT_DISP
:
7459 case R_MIPS_TLS_GOTTPREL
:
7461 case R_MIPS_TLS_LDM
:
7463 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7464 if (!mips_elf_create_got_section (dynobj
, info
))
7466 if (htab
->is_vxworks
&& !info
->shared
)
7468 (*_bfd_error_handler
)
7469 (_("%B: GOT reloc at 0x%lx not expected in executables"),
7470 abfd
, (unsigned long) rel
->r_offset
);
7471 bfd_set_error (bfd_error_bad_value
);
7479 /* In VxWorks executables, references to external symbols
7480 must be handled using copy relocs or PLT entries; it is not
7481 possible to convert this relocation into a dynamic one.
7483 For executables that use PLTs and copy-relocs, we have a
7484 choice between converting the relocation into a dynamic
7485 one or using copy relocations or PLT entries. It is
7486 usually better to do the former, unless the relocation is
7487 against a read-only section. */
7490 && !htab
->is_vxworks
7491 && strcmp (h
->root
.root
.string
, "__gnu_local_gp") != 0
7492 && !(!info
->nocopyreloc
7493 && !PIC_OBJECT_P (abfd
)
7494 && MIPS_ELF_READONLY_SECTION (sec
))))
7495 && (sec
->flags
& SEC_ALLOC
) != 0)
7497 can_make_dynamic_p
= TRUE
;
7499 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
7505 /* Most static relocations require pointer equality, except
7508 h
->pointer_equality_needed
= TRUE
;
7515 ((struct mips_elf_link_hash_entry
*) h
)->has_static_relocs
= TRUE
;
7521 /* Relocations against the special VxWorks __GOTT_BASE__ and
7522 __GOTT_INDEX__ symbols must be left to the loader. Allocate
7523 room for them in .rela.dyn. */
7524 if (is_gott_symbol (info
, h
))
7528 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7532 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7533 if (MIPS_ELF_READONLY_SECTION (sec
))
7534 /* We tell the dynamic linker that there are
7535 relocations against the text segment. */
7536 info
->flags
|= DF_TEXTREL
;
7539 else if (r_type
== R_MIPS_CALL_LO16
7540 || r_type
== R_MIPS_GOT_LO16
7541 || r_type
== R_MIPS_GOT_DISP
7542 || (got16_reloc_p (r_type
) && htab
->is_vxworks
))
7544 /* We may need a local GOT entry for this relocation. We
7545 don't count R_MIPS_GOT_PAGE because we can estimate the
7546 maximum number of pages needed by looking at the size of
7547 the segment. Similar comments apply to R_MIPS*_GOT16 and
7548 R_MIPS*_CALL16, except on VxWorks, where GOT relocations
7549 always evaluate to "G". We don't count R_MIPS_GOT_HI16, or
7550 R_MIPS_CALL_HI16 because these are always followed by an
7551 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. */
7552 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7553 rel
->r_addend
, info
, 0))
7557 if (h
!= NULL
&& mips_elf_relocation_needs_la25_stub (abfd
, r_type
))
7558 ((struct mips_elf_link_hash_entry
*) h
)->has_nonpic_branches
= TRUE
;
7563 case R_MIPS16_CALL16
:
7566 (*_bfd_error_handler
)
7567 (_("%B: CALL16 reloc at 0x%lx not against global symbol"),
7568 abfd
, (unsigned long) rel
->r_offset
);
7569 bfd_set_error (bfd_error_bad_value
);
7574 case R_MIPS_CALL_HI16
:
7575 case R_MIPS_CALL_LO16
:
7578 /* VxWorks call relocations point the function's .got.plt
7579 entry, which will be allocated by adjust_dynamic_symbol.
7580 Otherwise, this symbol requires a global GOT entry. */
7581 if ((!htab
->is_vxworks
|| h
->forced_local
)
7582 && !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7585 /* We need a stub, not a plt entry for the undefined
7586 function. But we record it as if it needs plt. See
7587 _bfd_elf_adjust_dynamic_symbol. */
7593 case R_MIPS_GOT_PAGE
:
7594 /* If this is a global, overridable symbol, GOT_PAGE will
7595 decay to GOT_DISP, so we'll need a GOT entry for it. */
7598 struct mips_elf_link_hash_entry
*hmips
=
7599 (struct mips_elf_link_hash_entry
*) h
;
7601 /* This symbol is definitely not overridable. */
7602 if (hmips
->root
.def_regular
7603 && ! (info
->shared
&& ! info
->symbolic
7604 && ! hmips
->root
.forced_local
))
7609 case R_MIPS16_GOT16
:
7611 case R_MIPS_GOT_HI16
:
7612 case R_MIPS_GOT_LO16
:
7613 if (!h
|| r_type
== R_MIPS_GOT_PAGE
)
7615 /* This relocation needs (or may need, if h != NULL) a
7616 page entry in the GOT. For R_MIPS_GOT_PAGE we do not
7617 know for sure until we know whether the symbol is
7619 if (mips_elf_rel_relocation_p (abfd
, sec
, relocs
, rel
))
7621 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
7623 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
7624 addend
= mips_elf_read_rel_addend (abfd
, rel
,
7626 if (r_type
== R_MIPS_GOT16
)
7627 mips_elf_add_lo16_rel_addend (abfd
, rel
, rel_end
,
7630 addend
<<= howto
->rightshift
;
7633 addend
= rel
->r_addend
;
7634 if (!mips_elf_record_got_page_entry (info
, abfd
, r_symndx
,
7641 case R_MIPS_GOT_DISP
:
7642 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
, info
, 0))
7646 case R_MIPS_TLS_GOTTPREL
:
7648 info
->flags
|= DF_STATIC_TLS
;
7651 case R_MIPS_TLS_LDM
:
7652 if (r_type
== R_MIPS_TLS_LDM
)
7660 /* This symbol requires a global offset table entry, or two
7661 for TLS GD relocations. */
7663 unsigned char flag
= (r_type
== R_MIPS_TLS_GD
7665 : r_type
== R_MIPS_TLS_LDM
7670 struct mips_elf_link_hash_entry
*hmips
=
7671 (struct mips_elf_link_hash_entry
*) h
;
7672 hmips
->tls_type
|= flag
;
7674 if (h
&& !mips_elf_record_global_got_symbol (h
, abfd
,
7680 BFD_ASSERT (flag
== GOT_TLS_LDM
|| r_symndx
!= 0);
7682 if (!mips_elf_record_local_got_symbol (abfd
, r_symndx
,
7693 /* In VxWorks executables, references to external symbols
7694 are handled using copy relocs or PLT stubs, so there's
7695 no need to add a .rela.dyn entry for this relocation. */
7696 if (can_make_dynamic_p
)
7700 sreloc
= mips_elf_rel_dyn_section (info
, TRUE
);
7704 if (info
->shared
&& h
== NULL
)
7706 /* When creating a shared object, we must copy these
7707 reloc types into the output file as R_MIPS_REL32
7708 relocs. Make room for this reloc in .rel(a).dyn. */
7709 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
7710 if (MIPS_ELF_READONLY_SECTION (sec
))
7711 /* We tell the dynamic linker that there are
7712 relocations against the text segment. */
7713 info
->flags
|= DF_TEXTREL
;
7717 struct mips_elf_link_hash_entry
*hmips
;
7719 /* For a shared object, we must copy this relocation
7720 unless the symbol turns out to be undefined and
7721 weak with non-default visibility, in which case
7722 it will be left as zero.
7724 We could elide R_MIPS_REL32 for locally binding symbols
7725 in shared libraries, but do not yet do so.
7727 For an executable, we only need to copy this
7728 reloc if the symbol is defined in a dynamic
7730 hmips
= (struct mips_elf_link_hash_entry
*) h
;
7731 ++hmips
->possibly_dynamic_relocs
;
7732 if (MIPS_ELF_READONLY_SECTION (sec
))
7733 /* We need it to tell the dynamic linker if there
7734 are relocations against the text segment. */
7735 hmips
->readonly_reloc
= TRUE
;
7739 if (SGI_COMPAT (abfd
))
7740 mips_elf_hash_table (info
)->compact_rel_size
+=
7741 sizeof (Elf32_External_crinfo
);
7745 case R_MIPS_GPREL16
:
7746 case R_MIPS_LITERAL
:
7747 case R_MIPS_GPREL32
:
7748 if (SGI_COMPAT (abfd
))
7749 mips_elf_hash_table (info
)->compact_rel_size
+=
7750 sizeof (Elf32_External_crinfo
);
7753 /* This relocation describes the C++ object vtable hierarchy.
7754 Reconstruct it for later use during GC. */
7755 case R_MIPS_GNU_VTINHERIT
:
7756 if (!bfd_elf_gc_record_vtinherit (abfd
, sec
, h
, rel
->r_offset
))
7760 /* This relocation describes which C++ vtable entries are actually
7761 used. Record for later use during GC. */
7762 case R_MIPS_GNU_VTENTRY
:
7763 BFD_ASSERT (h
!= NULL
);
7765 && !bfd_elf_gc_record_vtentry (abfd
, sec
, h
, rel
->r_offset
))
7773 /* We must not create a stub for a symbol that has relocations
7774 related to taking the function's address. This doesn't apply to
7775 VxWorks, where CALL relocs refer to a .got.plt entry instead of
7776 a normal .got entry. */
7777 if (!htab
->is_vxworks
&& h
!= NULL
)
7781 ((struct mips_elf_link_hash_entry
*) h
)->no_fn_stub
= TRUE
;
7783 case R_MIPS16_CALL16
:
7785 case R_MIPS_CALL_HI16
:
7786 case R_MIPS_CALL_LO16
:
7791 /* See if this reloc would need to refer to a MIPS16 hard-float stub,
7792 if there is one. We only need to handle global symbols here;
7793 we decide whether to keep or delete stubs for local symbols
7794 when processing the stub's relocations. */
7796 && !mips16_call_reloc_p (r_type
)
7797 && !section_allows_mips16_refs_p (sec
))
7799 struct mips_elf_link_hash_entry
*mh
;
7801 mh
= (struct mips_elf_link_hash_entry
*) h
;
7802 mh
->need_fn_stub
= TRUE
;
7805 /* Refuse some position-dependent relocations when creating a
7806 shared library. Do not refuse R_MIPS_32 / R_MIPS_64; they're
7807 not PIC, but we can create dynamic relocations and the result
7808 will be fine. Also do not refuse R_MIPS_LO16, which can be
7809 combined with R_MIPS_GOT16. */
7817 case R_MIPS_HIGHEST
:
7818 /* Don't refuse a high part relocation if it's against
7819 no symbol (e.g. part of a compound relocation). */
7823 /* R_MIPS_HI16 against _gp_disp is used for $gp setup,
7824 and has a special meaning. */
7825 if (!NEWABI_P (abfd
) && h
!= NULL
7826 && strcmp (h
->root
.root
.string
, "_gp_disp") == 0)
7833 howto
= MIPS_ELF_RTYPE_TO_HOWTO (abfd
, r_type
, FALSE
);
7834 (*_bfd_error_handler
)
7835 (_("%B: relocation %s against `%s' can not be used when making a shared object; recompile with -fPIC"),
7837 (h
) ? h
->root
.root
.string
: "a local symbol");
7838 bfd_set_error (bfd_error_bad_value
);
7850 _bfd_mips_relax_section (bfd
*abfd
, asection
*sec
,
7851 struct bfd_link_info
*link_info
,
7854 Elf_Internal_Rela
*internal_relocs
;
7855 Elf_Internal_Rela
*irel
, *irelend
;
7856 Elf_Internal_Shdr
*symtab_hdr
;
7857 bfd_byte
*contents
= NULL
;
7859 bfd_boolean changed_contents
= FALSE
;
7860 bfd_vma sec_start
= sec
->output_section
->vma
+ sec
->output_offset
;
7861 Elf_Internal_Sym
*isymbuf
= NULL
;
7863 /* We are not currently changing any sizes, so only one pass. */
7866 if (link_info
->relocatable
)
7869 internal_relocs
= _bfd_elf_link_read_relocs (abfd
, sec
, NULL
, NULL
,
7870 link_info
->keep_memory
);
7871 if (internal_relocs
== NULL
)
7874 irelend
= internal_relocs
+ sec
->reloc_count
7875 * get_elf_backend_data (abfd
)->s
->int_rels_per_ext_rel
;
7876 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
7877 extsymoff
= (elf_bad_symtab (abfd
)) ? 0 : symtab_hdr
->sh_info
;
7879 for (irel
= internal_relocs
; irel
< irelend
; irel
++)
7882 bfd_signed_vma sym_offset
;
7883 unsigned int r_type
;
7884 unsigned long r_symndx
;
7886 unsigned long instruction
;
7888 /* Turn jalr into bgezal, and jr into beq, if they're marked
7889 with a JALR relocation, that indicate where they jump to.
7890 This saves some pipeline bubbles. */
7891 r_type
= ELF_R_TYPE (abfd
, irel
->r_info
);
7892 if (r_type
!= R_MIPS_JALR
)
7895 r_symndx
= ELF_R_SYM (abfd
, irel
->r_info
);
7896 /* Compute the address of the jump target. */
7897 if (r_symndx
>= extsymoff
)
7899 struct mips_elf_link_hash_entry
*h
7900 = ((struct mips_elf_link_hash_entry
*)
7901 elf_sym_hashes (abfd
) [r_symndx
- extsymoff
]);
7903 while (h
->root
.root
.type
== bfd_link_hash_indirect
7904 || h
->root
.root
.type
== bfd_link_hash_warning
)
7905 h
= (struct mips_elf_link_hash_entry
*) h
->root
.root
.u
.i
.link
;
7907 /* If a symbol is undefined, or if it may be overridden,
7909 if (! ((h
->root
.root
.type
== bfd_link_hash_defined
7910 || h
->root
.root
.type
== bfd_link_hash_defweak
)
7911 && h
->root
.root
.u
.def
.section
)
7912 || (link_info
->shared
&& ! link_info
->symbolic
7913 && !h
->root
.forced_local
))
7916 sym_sec
= h
->root
.root
.u
.def
.section
;
7917 if (sym_sec
->output_section
)
7918 symval
= (h
->root
.root
.u
.def
.value
7919 + sym_sec
->output_section
->vma
7920 + sym_sec
->output_offset
);
7922 symval
= h
->root
.root
.u
.def
.value
;
7926 Elf_Internal_Sym
*isym
;
7928 /* Read this BFD's symbols if we haven't done so already. */
7929 if (isymbuf
== NULL
&& symtab_hdr
->sh_info
!= 0)
7931 isymbuf
= (Elf_Internal_Sym
*) symtab_hdr
->contents
;
7932 if (isymbuf
== NULL
)
7933 isymbuf
= bfd_elf_get_elf_syms (abfd
, symtab_hdr
,
7934 symtab_hdr
->sh_info
, 0,
7936 if (isymbuf
== NULL
)
7940 isym
= isymbuf
+ r_symndx
;
7941 if (isym
->st_shndx
== SHN_UNDEF
)
7943 else if (isym
->st_shndx
== SHN_ABS
)
7944 sym_sec
= bfd_abs_section_ptr
;
7945 else if (isym
->st_shndx
== SHN_COMMON
)
7946 sym_sec
= bfd_com_section_ptr
;
7949 = bfd_section_from_elf_index (abfd
, isym
->st_shndx
);
7950 symval
= isym
->st_value
7951 + sym_sec
->output_section
->vma
7952 + sym_sec
->output_offset
;
7955 /* Compute branch offset, from delay slot of the jump to the
7957 sym_offset
= (symval
+ irel
->r_addend
)
7958 - (sec_start
+ irel
->r_offset
+ 4);
7960 /* Branch offset must be properly aligned. */
7961 if ((sym_offset
& 3) != 0)
7966 /* Check that it's in range. */
7967 if (sym_offset
< -0x8000 || sym_offset
>= 0x8000)
7970 /* Get the section contents if we haven't done so already. */
7971 if (!mips_elf_get_section_contents (abfd
, sec
, &contents
))
7974 instruction
= bfd_get_32 (abfd
, contents
+ irel
->r_offset
);
7976 /* If it was jalr <reg>, turn it into bgezal $zero, <target>. */
7977 if ((instruction
& 0xfc1fffff) == 0x0000f809)
7978 instruction
= 0x04110000;
7979 /* If it was jr <reg>, turn it into b <target>. */
7980 else if ((instruction
& 0xfc1fffff) == 0x00000008)
7981 instruction
= 0x10000000;
7985 instruction
|= (sym_offset
& 0xffff);
7986 bfd_put_32 (abfd
, instruction
, contents
+ irel
->r_offset
);
7987 changed_contents
= TRUE
;
7990 if (contents
!= NULL
7991 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
7993 if (!changed_contents
&& !link_info
->keep_memory
)
7997 /* Cache the section contents for elf_link_input_bfd. */
7998 elf_section_data (sec
)->this_hdr
.contents
= contents
;
8004 if (contents
!= NULL
8005 && elf_section_data (sec
)->this_hdr
.contents
!= contents
)
8010 /* Allocate space for global sym dynamic relocs. */
8013 allocate_dynrelocs (struct elf_link_hash_entry
*h
, void *inf
)
8015 struct bfd_link_info
*info
= inf
;
8017 struct mips_elf_link_hash_entry
*hmips
;
8018 struct mips_elf_link_hash_table
*htab
;
8020 htab
= mips_elf_hash_table (info
);
8021 dynobj
= elf_hash_table (info
)->dynobj
;
8022 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8024 /* VxWorks executables are handled elsewhere; we only need to
8025 allocate relocations in shared objects. */
8026 if (htab
->is_vxworks
&& !info
->shared
)
8029 /* Ignore indirect and warning symbols. All relocations against
8030 such symbols will be redirected to the target symbol. */
8031 if (h
->root
.type
== bfd_link_hash_indirect
8032 || h
->root
.type
== bfd_link_hash_warning
)
8035 /* If this symbol is defined in a dynamic object, or we are creating
8036 a shared library, we will need to copy any R_MIPS_32 or
8037 R_MIPS_REL32 relocs against it into the output file. */
8038 if (! info
->relocatable
8039 && hmips
->possibly_dynamic_relocs
!= 0
8040 && (h
->root
.type
== bfd_link_hash_defweak
8044 bfd_boolean do_copy
= TRUE
;
8046 if (h
->root
.type
== bfd_link_hash_undefweak
)
8048 /* Do not copy relocations for undefined weak symbols with
8049 non-default visibility. */
8050 if (ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
)
8053 /* Make sure undefined weak symbols are output as a dynamic
8055 else if (h
->dynindx
== -1 && !h
->forced_local
)
8057 if (! bfd_elf_link_record_dynamic_symbol (info
, h
))
8064 /* Even though we don't directly need a GOT entry for this symbol,
8065 a symbol must have a dynamic symbol table index greater that
8066 DT_MIPS_GOTSYM if there are dynamic relocations against it. */
8067 if (hmips
->global_got_area
> GGA_RELOC_ONLY
)
8068 hmips
->global_got_area
= GGA_RELOC_ONLY
;
8070 mips_elf_allocate_dynamic_relocations
8071 (dynobj
, info
, hmips
->possibly_dynamic_relocs
);
8072 if (hmips
->readonly_reloc
)
8073 /* We tell the dynamic linker that there are relocations
8074 against the text segment. */
8075 info
->flags
|= DF_TEXTREL
;
8082 /* Adjust a symbol defined by a dynamic object and referenced by a
8083 regular object. The current definition is in some section of the
8084 dynamic object, but we're not including those sections. We have to
8085 change the definition to something the rest of the link can
8089 _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info
*info
,
8090 struct elf_link_hash_entry
*h
)
8093 struct mips_elf_link_hash_entry
*hmips
;
8094 struct mips_elf_link_hash_table
*htab
;
8096 htab
= mips_elf_hash_table (info
);
8097 dynobj
= elf_hash_table (info
)->dynobj
;
8098 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8100 /* Make sure we know what is going on here. */
8101 BFD_ASSERT (dynobj
!= NULL
8103 || h
->u
.weakdef
!= NULL
8106 && !h
->def_regular
)));
8108 hmips
= (struct mips_elf_link_hash_entry
*) h
;
8110 /* If there are call relocations against an externally-defined symbol,
8111 see whether we can create a MIPS lazy-binding stub for it. We can
8112 only do this if all references to the function are through call
8113 relocations, and in that case, the traditional lazy-binding stubs
8114 are much more efficient than PLT entries.
8116 Traditional stubs are only available on SVR4 psABI-based systems;
8117 VxWorks always uses PLTs instead. */
8118 if (!htab
->is_vxworks
&& h
->needs_plt
&& !hmips
->no_fn_stub
)
8120 if (! elf_hash_table (info
)->dynamic_sections_created
)
8123 /* If this symbol is not defined in a regular file, then set
8124 the symbol to the stub location. This is required to make
8125 function pointers compare as equal between the normal
8126 executable and the shared library. */
8127 if (!h
->def_regular
)
8129 hmips
->needs_lazy_stub
= TRUE
;
8130 htab
->lazy_stub_count
++;
8134 /* As above, VxWorks requires PLT entries for externally-defined
8135 functions that are only accessed through call relocations.
8137 Both VxWorks and non-VxWorks targets also need PLT entries if there
8138 are static-only relocations against an externally-defined function.
8139 This can technically occur for shared libraries if there are
8140 branches to the symbol, although it is unlikely that this will be
8141 used in practice due to the short ranges involved. It can occur
8142 for any relative or absolute relocation in executables; in that
8143 case, the PLT entry becomes the function's canonical address. */
8144 else if (((h
->needs_plt
&& !hmips
->no_fn_stub
)
8145 || (h
->type
== STT_FUNC
&& hmips
->has_static_relocs
))
8146 && htab
->use_plts_and_copy_relocs
8147 && !SYMBOL_CALLS_LOCAL (info
, h
)
8148 && !(ELF_ST_VISIBILITY (h
->other
) != STV_DEFAULT
8149 && h
->root
.type
== bfd_link_hash_undefweak
))
8151 /* If this is the first symbol to need a PLT entry, allocate room
8153 if (htab
->splt
->size
== 0)
8155 BFD_ASSERT (htab
->sgotplt
->size
== 0);
8157 /* If we're using the PLT additions to the psABI, each PLT
8158 entry is 16 bytes and the PLT0 entry is 32 bytes.
8159 Encourage better cache usage by aligning. We do this
8160 lazily to avoid pessimizing traditional objects. */
8161 if (!htab
->is_vxworks
8162 && !bfd_set_section_alignment (dynobj
, htab
->splt
, 5))
8165 /* Make sure that .got.plt is word-aligned. We do this lazily
8166 for the same reason as above. */
8167 if (!bfd_set_section_alignment (dynobj
, htab
->sgotplt
,
8168 MIPS_ELF_LOG_FILE_ALIGN (dynobj
)))
8171 htab
->splt
->size
+= htab
->plt_header_size
;
8173 /* On non-VxWorks targets, the first two entries in .got.plt
8175 if (!htab
->is_vxworks
)
8176 htab
->sgotplt
->size
+= 2 * MIPS_ELF_GOT_SIZE (dynobj
);
8178 /* On VxWorks, also allocate room for the header's
8179 .rela.plt.unloaded entries. */
8180 if (htab
->is_vxworks
&& !info
->shared
)
8181 htab
->srelplt2
->size
+= 2 * sizeof (Elf32_External_Rela
);
8184 /* Assign the next .plt entry to this symbol. */
8185 h
->plt
.offset
= htab
->splt
->size
;
8186 htab
->splt
->size
+= htab
->plt_entry_size
;
8188 /* If the output file has no definition of the symbol, set the
8189 symbol's value to the address of the stub. */
8190 if (!info
->shared
&& !h
->def_regular
)
8192 h
->root
.u
.def
.section
= htab
->splt
;
8193 h
->root
.u
.def
.value
= h
->plt
.offset
;
8194 /* For VxWorks, point at the PLT load stub rather than the
8195 lazy resolution stub; this stub will become the canonical
8196 function address. */
8197 if (htab
->is_vxworks
)
8198 h
->root
.u
.def
.value
+= 8;
8201 /* Make room for the .got.plt entry and the R_MIPS_JUMP_SLOT
8203 htab
->sgotplt
->size
+= MIPS_ELF_GOT_SIZE (dynobj
);
8204 htab
->srelplt
->size
+= (htab
->is_vxworks
8205 ? MIPS_ELF_RELA_SIZE (dynobj
)
8206 : MIPS_ELF_REL_SIZE (dynobj
));
8208 /* Make room for the .rela.plt.unloaded relocations. */
8209 if (htab
->is_vxworks
&& !info
->shared
)
8210 htab
->srelplt2
->size
+= 3 * sizeof (Elf32_External_Rela
);
8212 /* All relocations against this symbol that could have been made
8213 dynamic will now refer to the PLT entry instead. */
8214 hmips
->possibly_dynamic_relocs
= 0;
8219 /* If this is a weak symbol, and there is a real definition, the
8220 processor independent code will have arranged for us to see the
8221 real definition first, and we can just use the same value. */
8222 if (h
->u
.weakdef
!= NULL
)
8224 BFD_ASSERT (h
->u
.weakdef
->root
.type
== bfd_link_hash_defined
8225 || h
->u
.weakdef
->root
.type
== bfd_link_hash_defweak
);
8226 h
->root
.u
.def
.section
= h
->u
.weakdef
->root
.u
.def
.section
;
8227 h
->root
.u
.def
.value
= h
->u
.weakdef
->root
.u
.def
.value
;
8231 /* Otherwise, there is nothing further to do for symbols defined
8232 in regular objects. */
8236 /* There's also nothing more to do if we'll convert all relocations
8237 against this symbol into dynamic relocations. */
8238 if (!hmips
->has_static_relocs
)
8241 /* We're now relying on copy relocations. Complain if we have
8242 some that we can't convert. */
8243 if (!htab
->use_plts_and_copy_relocs
|| info
->shared
)
8245 (*_bfd_error_handler
) (_("non-dynamic relocations refer to "
8246 "dynamic symbol %s"),
8247 h
->root
.root
.string
);
8248 bfd_set_error (bfd_error_bad_value
);
8252 /* We must allocate the symbol in our .dynbss section, which will
8253 become part of the .bss section of the executable. There will be
8254 an entry for this symbol in the .dynsym section. The dynamic
8255 object will contain position independent code, so all references
8256 from the dynamic object to this symbol will go through the global
8257 offset table. The dynamic linker will use the .dynsym entry to
8258 determine the address it must put in the global offset table, so
8259 both the dynamic object and the regular object will refer to the
8260 same memory location for the variable. */
8262 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
8264 if (htab
->is_vxworks
)
8265 htab
->srelbss
->size
+= sizeof (Elf32_External_Rela
);
8267 mips_elf_allocate_dynamic_relocations (dynobj
, info
, 1);
8271 /* All relocations against this symbol that could have been made
8272 dynamic will now refer to the local copy instead. */
8273 hmips
->possibly_dynamic_relocs
= 0;
8275 return _bfd_elf_adjust_dynamic_copy (h
, htab
->sdynbss
);
8278 /* This function is called after all the input files have been read,
8279 and the input sections have been assigned to output sections. We
8280 check for any mips16 stub sections that we can discard. */
8283 _bfd_mips_elf_always_size_sections (bfd
*output_bfd
,
8284 struct bfd_link_info
*info
)
8287 struct mips_elf_link_hash_table
*htab
;
8288 struct mips_htab_traverse_info hti
;
8290 htab
= mips_elf_hash_table (info
);
8292 /* The .reginfo section has a fixed size. */
8293 ri
= bfd_get_section_by_name (output_bfd
, ".reginfo");
8295 bfd_set_section_size (output_bfd
, ri
, sizeof (Elf32_External_RegInfo
));
8298 hti
.output_bfd
= output_bfd
;
8300 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
8301 mips_elf_check_symbols
, &hti
);
8308 /* If the link uses a GOT, lay it out and work out its size. */
8311 mips_elf_lay_out_got (bfd
*output_bfd
, struct bfd_link_info
*info
)
8315 struct mips_got_info
*g
;
8316 bfd_size_type loadable_size
= 0;
8317 bfd_size_type page_gotno
;
8319 struct mips_elf_count_tls_arg count_tls_arg
;
8320 struct mips_elf_link_hash_table
*htab
;
8322 htab
= mips_elf_hash_table (info
);
8327 dynobj
= elf_hash_table (info
)->dynobj
;
8330 /* Allocate room for the reserved entries. VxWorks always reserves
8331 3 entries; other objects only reserve 2 entries. */
8332 BFD_ASSERT (g
->assigned_gotno
== 0);
8333 if (htab
->is_vxworks
)
8334 htab
->reserved_gotno
= 3;
8336 htab
->reserved_gotno
= 2;
8337 g
->local_gotno
+= htab
->reserved_gotno
;
8338 g
->assigned_gotno
= htab
->reserved_gotno
;
8340 /* Replace entries for indirect and warning symbols with entries for
8341 the target symbol. */
8342 if (!mips_elf_resolve_final_got_entries (g
))
8345 /* Count the number of GOT symbols. */
8346 mips_elf_link_hash_traverse (htab
, mips_elf_count_got_symbols
, g
);
8348 /* Calculate the total loadable size of the output. That
8349 will give us the maximum number of GOT_PAGE entries
8351 for (sub
= info
->input_bfds
; sub
; sub
= sub
->link_next
)
8353 asection
*subsection
;
8355 for (subsection
= sub
->sections
;
8357 subsection
= subsection
->next
)
8359 if ((subsection
->flags
& SEC_ALLOC
) == 0)
8361 loadable_size
+= ((subsection
->size
+ 0xf)
8362 &~ (bfd_size_type
) 0xf);
8366 if (htab
->is_vxworks
)
8367 /* There's no need to allocate page entries for VxWorks; R_MIPS*_GOT16
8368 relocations against local symbols evaluate to "G", and the EABI does
8369 not include R_MIPS_GOT_PAGE. */
8372 /* Assume there are two loadable segments consisting of contiguous
8373 sections. Is 5 enough? */
8374 page_gotno
= (loadable_size
>> 16) + 5;
8376 /* Choose the smaller of the two estimates; both are intended to be
8378 if (page_gotno
> g
->page_gotno
)
8379 page_gotno
= g
->page_gotno
;
8381 g
->local_gotno
+= page_gotno
;
8382 s
->size
+= g
->local_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
8383 s
->size
+= g
->global_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
8385 /* We need to calculate tls_gotno for global symbols at this point
8386 instead of building it up earlier, to avoid doublecounting
8387 entries for one global symbol from multiple input files. */
8388 count_tls_arg
.info
= info
;
8389 count_tls_arg
.needed
= 0;
8390 elf_link_hash_traverse (elf_hash_table (info
),
8391 mips_elf_count_global_tls_entries
,
8393 g
->tls_gotno
+= count_tls_arg
.needed
;
8394 s
->size
+= g
->tls_gotno
* MIPS_ELF_GOT_SIZE (output_bfd
);
8396 /* VxWorks does not support multiple GOTs. It initializes $gp to
8397 __GOTT_BASE__[__GOTT_INDEX__], the value of which is set by the
8399 if (htab
->is_vxworks
)
8401 /* VxWorks executables do not need a GOT. */
8404 /* Each VxWorks GOT entry needs an explicit relocation. */
8407 count
= g
->global_gotno
+ g
->local_gotno
- htab
->reserved_gotno
;
8409 mips_elf_allocate_dynamic_relocations (dynobj
, info
, count
);
8412 else if (s
->size
> MIPS_ELF_GOT_MAX_SIZE (info
))
8414 if (!mips_elf_multi_got (output_bfd
, info
, s
, page_gotno
))
8419 struct mips_elf_count_tls_arg arg
;
8421 /* Set up TLS entries. */
8422 g
->tls_assigned_gotno
= g
->global_gotno
+ g
->local_gotno
;
8423 htab_traverse (g
->got_entries
, mips_elf_initialize_tls_index
, g
);
8425 /* Allocate room for the TLS relocations. */
8428 htab_traverse (g
->got_entries
, mips_elf_count_local_tls_relocs
, &arg
);
8429 elf_link_hash_traverse (elf_hash_table (info
),
8430 mips_elf_count_global_tls_relocs
,
8433 mips_elf_allocate_dynamic_relocations (dynobj
, info
, arg
.needed
);
8439 /* Estimate the size of the .MIPS.stubs section. */
8442 mips_elf_estimate_stub_size (bfd
*output_bfd
, struct bfd_link_info
*info
)
8444 struct mips_elf_link_hash_table
*htab
;
8445 bfd_size_type dynsymcount
;
8447 htab
= mips_elf_hash_table (info
);
8448 if (htab
->lazy_stub_count
== 0)
8451 /* IRIX rld assumes that a function stub isn't at the end of the .text
8452 section, so add a dummy entry to the end. */
8453 htab
->lazy_stub_count
++;
8455 /* Get a worst-case estimate of the number of dynamic symbols needed.
8456 At this point, dynsymcount does not account for section symbols
8457 and count_section_dynsyms may overestimate the number that will
8459 dynsymcount
= (elf_hash_table (info
)->dynsymcount
8460 + count_section_dynsyms (output_bfd
, info
));
8462 /* Determine the size of one stub entry. */
8463 htab
->function_stub_size
= (dynsymcount
> 0x10000
8464 ? MIPS_FUNCTION_STUB_BIG_SIZE
8465 : MIPS_FUNCTION_STUB_NORMAL_SIZE
);
8467 htab
->sstubs
->size
= htab
->lazy_stub_count
* htab
->function_stub_size
;
8470 /* A mips_elf_link_hash_traverse callback for which DATA points to the
8471 MIPS hash table. If H needs a traditional MIPS lazy-binding stub,
8472 allocate an entry in the stubs section. */
8475 mips_elf_allocate_lazy_stub (struct mips_elf_link_hash_entry
*h
, void **data
)
8477 struct mips_elf_link_hash_table
*htab
;
8479 htab
= (struct mips_elf_link_hash_table
*) data
;
8480 if (h
->needs_lazy_stub
)
8482 h
->root
.root
.u
.def
.section
= htab
->sstubs
;
8483 h
->root
.root
.u
.def
.value
= htab
->sstubs
->size
;
8484 h
->root
.plt
.offset
= htab
->sstubs
->size
;
8485 htab
->sstubs
->size
+= htab
->function_stub_size
;
8490 /* Allocate offsets in the stubs section to each symbol that needs one.
8491 Set the final size of the .MIPS.stub section. */
8494 mips_elf_lay_out_lazy_stubs (struct bfd_link_info
*info
)
8496 struct mips_elf_link_hash_table
*htab
;
8498 htab
= mips_elf_hash_table (info
);
8499 if (htab
->lazy_stub_count
== 0)
8502 htab
->sstubs
->size
= 0;
8503 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
8504 mips_elf_allocate_lazy_stub
, htab
);
8505 htab
->sstubs
->size
+= htab
->function_stub_size
;
8506 BFD_ASSERT (htab
->sstubs
->size
8507 == htab
->lazy_stub_count
* htab
->function_stub_size
);
8510 /* Set the sizes of the dynamic sections. */
8513 _bfd_mips_elf_size_dynamic_sections (bfd
*output_bfd
,
8514 struct bfd_link_info
*info
)
8517 asection
*s
, *sreldyn
;
8518 bfd_boolean reltext
;
8519 struct mips_elf_link_hash_table
*htab
;
8521 htab
= mips_elf_hash_table (info
);
8522 dynobj
= elf_hash_table (info
)->dynobj
;
8523 BFD_ASSERT (dynobj
!= NULL
);
8525 if (elf_hash_table (info
)->dynamic_sections_created
)
8527 /* Set the contents of the .interp section to the interpreter. */
8528 if (info
->executable
)
8530 s
= bfd_get_section_by_name (dynobj
, ".interp");
8531 BFD_ASSERT (s
!= NULL
);
8533 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd
)) + 1;
8535 = (bfd_byte
*) ELF_DYNAMIC_INTERPRETER (output_bfd
);
8538 /* Create a symbol for the PLT, if we know that we are using it. */
8539 if (htab
->splt
&& htab
->splt
->size
> 0 && htab
->root
.hplt
== NULL
)
8541 struct elf_link_hash_entry
*h
;
8543 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
8545 h
= _bfd_elf_define_linkage_sym (dynobj
, info
, htab
->splt
,
8546 "_PROCEDURE_LINKAGE_TABLE_");
8547 htab
->root
.hplt
= h
;
8554 /* Allocate space for global sym dynamic relocs. */
8555 elf_link_hash_traverse (&htab
->root
, allocate_dynrelocs
, (PTR
) info
);
8557 mips_elf_estimate_stub_size (output_bfd
, info
);
8559 if (!mips_elf_lay_out_got (output_bfd
, info
))
8562 mips_elf_lay_out_lazy_stubs (info
);
8564 /* The check_relocs and adjust_dynamic_symbol entry points have
8565 determined the sizes of the various dynamic sections. Allocate
8568 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
8572 /* It's OK to base decisions on the section name, because none
8573 of the dynobj section names depend upon the input files. */
8574 name
= bfd_get_section_name (dynobj
, s
);
8576 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
8579 if (CONST_STRNEQ (name
, ".rel"))
8583 const char *outname
;
8586 /* If this relocation section applies to a read only
8587 section, then we probably need a DT_TEXTREL entry.
8588 If the relocation section is .rel(a).dyn, we always
8589 assert a DT_TEXTREL entry rather than testing whether
8590 there exists a relocation to a read only section or
8592 outname
= bfd_get_section_name (output_bfd
,
8594 target
= bfd_get_section_by_name (output_bfd
, outname
+ 4);
8596 && (target
->flags
& SEC_READONLY
) != 0
8597 && (target
->flags
& SEC_ALLOC
) != 0)
8598 || strcmp (outname
, MIPS_ELF_REL_DYN_NAME (info
)) == 0)
8601 /* We use the reloc_count field as a counter if we need
8602 to copy relocs into the output file. */
8603 if (strcmp (name
, MIPS_ELF_REL_DYN_NAME (info
)) != 0)
8606 /* If combreloc is enabled, elf_link_sort_relocs() will
8607 sort relocations, but in a different way than we do,
8608 and before we're done creating relocations. Also, it
8609 will move them around between input sections'
8610 relocation's contents, so our sorting would be
8611 broken, so don't let it run. */
8612 info
->combreloc
= 0;
8615 else if (! info
->shared
8616 && ! mips_elf_hash_table (info
)->use_rld_obj_head
8617 && CONST_STRNEQ (name
, ".rld_map"))
8619 /* We add a room for __rld_map. It will be filled in by the
8620 rtld to contain a pointer to the _r_debug structure. */
8623 else if (SGI_COMPAT (output_bfd
)
8624 && CONST_STRNEQ (name
, ".compact_rel"))
8625 s
->size
+= mips_elf_hash_table (info
)->compact_rel_size
;
8626 else if (s
== htab
->splt
)
8628 /* If the last PLT entry has a branch delay slot, allocate
8629 room for an extra nop to fill the delay slot. */
8630 if (!htab
->is_vxworks
&& s
->size
> 0)
8633 else if (! CONST_STRNEQ (name
, ".init")
8635 && s
!= htab
->sgotplt
8636 && s
!= htab
->sstubs
8637 && s
!= htab
->sdynbss
)
8639 /* It's not one of our sections, so don't allocate space. */
8645 s
->flags
|= SEC_EXCLUDE
;
8649 if ((s
->flags
& SEC_HAS_CONTENTS
) == 0)
8652 /* Allocate memory for the section contents. */
8653 s
->contents
= bfd_zalloc (dynobj
, s
->size
);
8654 if (s
->contents
== NULL
)
8656 bfd_set_error (bfd_error_no_memory
);
8661 if (elf_hash_table (info
)->dynamic_sections_created
)
8663 /* Add some entries to the .dynamic section. We fill in the
8664 values later, in _bfd_mips_elf_finish_dynamic_sections, but we
8665 must add the entries now so that we get the correct size for
8666 the .dynamic section. */
8668 /* SGI object has the equivalence of DT_DEBUG in the
8669 DT_MIPS_RLD_MAP entry. This must come first because glibc
8670 only fills in DT_MIPS_RLD_MAP (not DT_DEBUG) and GDB only
8671 looks at the first one it sees. */
8673 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_MAP
, 0))
8676 /* The DT_DEBUG entry may be filled in by the dynamic linker and
8677 used by the debugger. */
8678 if (info
->executable
8679 && !SGI_COMPAT (output_bfd
)
8680 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_DEBUG
, 0))
8683 if (reltext
&& (SGI_COMPAT (output_bfd
) || htab
->is_vxworks
))
8684 info
->flags
|= DF_TEXTREL
;
8686 if ((info
->flags
& DF_TEXTREL
) != 0)
8688 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_TEXTREL
, 0))
8691 /* Clear the DF_TEXTREL flag. It will be set again if we
8692 write out an actual text relocation; we may not, because
8693 at this point we do not know whether e.g. any .eh_frame
8694 absolute relocations have been converted to PC-relative. */
8695 info
->flags
&= ~DF_TEXTREL
;
8698 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTGOT
, 0))
8701 sreldyn
= mips_elf_rel_dyn_section (info
, FALSE
);
8702 if (htab
->is_vxworks
)
8704 /* VxWorks uses .rela.dyn instead of .rel.dyn. It does not
8705 use any of the DT_MIPS_* tags. */
8706 if (sreldyn
&& sreldyn
->size
> 0)
8708 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELA
, 0))
8711 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELASZ
, 0))
8714 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELAENT
, 0))
8720 if (sreldyn
&& sreldyn
->size
> 0)
8722 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_REL
, 0))
8725 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELSZ
, 0))
8728 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_RELENT
, 0))
8732 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_RLD_VERSION
, 0))
8735 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_FLAGS
, 0))
8738 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_BASE_ADDRESS
, 0))
8741 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_LOCAL_GOTNO
, 0))
8744 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_SYMTABNO
, 0))
8747 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_UNREFEXTNO
, 0))
8750 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_GOTSYM
, 0))
8753 if (IRIX_COMPAT (dynobj
) == ict_irix5
8754 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_HIPAGENO
, 0))
8757 if (IRIX_COMPAT (dynobj
) == ict_irix6
8758 && (bfd_get_section_by_name
8759 (dynobj
, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj
)))
8760 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_OPTIONS
, 0))
8763 if (htab
->splt
->size
> 0)
8765 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTREL
, 0))
8768 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_JMPREL
, 0))
8771 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_PLTRELSZ
, 0))
8774 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info
, DT_MIPS_PLTGOT
, 0))
8777 if (htab
->is_vxworks
8778 && !elf_vxworks_add_dynamic_entries (output_bfd
, info
))
8785 /* REL is a relocation in INPUT_BFD that is being copied to OUTPUT_BFD.
8786 Adjust its R_ADDEND field so that it is correct for the output file.
8787 LOCAL_SYMS and LOCAL_SECTIONS are arrays of INPUT_BFD's local symbols
8788 and sections respectively; both use symbol indexes. */
8791 mips_elf_adjust_addend (bfd
*output_bfd
, struct bfd_link_info
*info
,
8792 bfd
*input_bfd
, Elf_Internal_Sym
*local_syms
,
8793 asection
**local_sections
, Elf_Internal_Rela
*rel
)
8795 unsigned int r_type
, r_symndx
;
8796 Elf_Internal_Sym
*sym
;
8799 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
, FALSE
))
8801 r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8802 if (r_type
== R_MIPS16_GPREL
8803 || r_type
== R_MIPS_GPREL16
8804 || r_type
== R_MIPS_GPREL32
8805 || r_type
== R_MIPS_LITERAL
)
8807 rel
->r_addend
+= _bfd_get_gp_value (input_bfd
);
8808 rel
->r_addend
-= _bfd_get_gp_value (output_bfd
);
8811 r_symndx
= ELF_R_SYM (output_bfd
, rel
->r_info
);
8812 sym
= local_syms
+ r_symndx
;
8814 /* Adjust REL's addend to account for section merging. */
8815 if (!info
->relocatable
)
8817 sec
= local_sections
[r_symndx
];
8818 _bfd_elf_rela_local_sym (output_bfd
, sym
, &sec
, rel
);
8821 /* This would normally be done by the rela_normal code in elflink.c. */
8822 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
8823 rel
->r_addend
+= local_sections
[r_symndx
]->output_offset
;
8827 /* Relocate a MIPS ELF section. */
8830 _bfd_mips_elf_relocate_section (bfd
*output_bfd
, struct bfd_link_info
*info
,
8831 bfd
*input_bfd
, asection
*input_section
,
8832 bfd_byte
*contents
, Elf_Internal_Rela
*relocs
,
8833 Elf_Internal_Sym
*local_syms
,
8834 asection
**local_sections
)
8836 Elf_Internal_Rela
*rel
;
8837 const Elf_Internal_Rela
*relend
;
8839 bfd_boolean use_saved_addend_p
= FALSE
;
8840 const struct elf_backend_data
*bed
;
8842 bed
= get_elf_backend_data (output_bfd
);
8843 relend
= relocs
+ input_section
->reloc_count
* bed
->s
->int_rels_per_ext_rel
;
8844 for (rel
= relocs
; rel
< relend
; ++rel
)
8848 reloc_howto_type
*howto
;
8849 bfd_boolean require_jalx
;
8850 /* TRUE if the relocation is a RELA relocation, rather than a
8852 bfd_boolean rela_relocation_p
= TRUE
;
8853 unsigned int r_type
= ELF_R_TYPE (output_bfd
, rel
->r_info
);
8855 unsigned long r_symndx
;
8857 Elf_Internal_Shdr
*symtab_hdr
;
8858 struct elf_link_hash_entry
*h
;
8860 /* Find the relocation howto for this relocation. */
8861 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, r_type
,
8862 NEWABI_P (input_bfd
)
8863 && (MIPS_RELOC_RELA_P
8864 (input_bfd
, input_section
,
8867 r_symndx
= ELF_R_SYM (input_bfd
, rel
->r_info
);
8868 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
8869 if (mips_elf_local_relocation_p (input_bfd
, rel
, local_sections
, FALSE
))
8871 sec
= local_sections
[r_symndx
];
8876 unsigned long extsymoff
;
8879 if (!elf_bad_symtab (input_bfd
))
8880 extsymoff
= symtab_hdr
->sh_info
;
8881 h
= elf_sym_hashes (input_bfd
) [r_symndx
- extsymoff
];
8882 while (h
->root
.type
== bfd_link_hash_indirect
8883 || h
->root
.type
== bfd_link_hash_warning
)
8884 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
8887 if (h
->root
.type
== bfd_link_hash_defined
8888 || h
->root
.type
== bfd_link_hash_defweak
)
8889 sec
= h
->root
.u
.def
.section
;
8892 if (sec
!= NULL
&& elf_discarded_section (sec
))
8894 /* For relocs against symbols from removed linkonce sections,
8895 or sections discarded by a linker script, we just want the
8896 section contents zeroed. Avoid any special processing. */
8897 _bfd_clear_contents (howto
, input_bfd
, contents
+ rel
->r_offset
);
8903 if (r_type
== R_MIPS_64
&& ! NEWABI_P (input_bfd
))
8905 /* Some 32-bit code uses R_MIPS_64. In particular, people use
8906 64-bit code, but make sure all their addresses are in the
8907 lowermost or uppermost 32-bit section of the 64-bit address
8908 space. Thus, when they use an R_MIPS_64 they mean what is
8909 usually meant by R_MIPS_32, with the exception that the
8910 stored value is sign-extended to 64 bits. */
8911 howto
= MIPS_ELF_RTYPE_TO_HOWTO (input_bfd
, R_MIPS_32
, FALSE
);
8913 /* On big-endian systems, we need to lie about the position
8915 if (bfd_big_endian (input_bfd
))
8919 if (!use_saved_addend_p
)
8921 /* If these relocations were originally of the REL variety,
8922 we must pull the addend out of the field that will be
8923 relocated. Otherwise, we simply use the contents of the
8925 if (mips_elf_rel_relocation_p (input_bfd
, input_section
,
8928 rela_relocation_p
= FALSE
;
8929 addend
= mips_elf_read_rel_addend (input_bfd
, rel
,
8931 if (hi16_reloc_p (r_type
)
8932 || (got16_reloc_p (r_type
)
8933 && mips_elf_local_relocation_p (input_bfd
, rel
,
8934 local_sections
, FALSE
)))
8936 if (!mips_elf_add_lo16_rel_addend (input_bfd
, rel
, relend
,
8942 name
= h
->root
.root
.string
;
8944 name
= bfd_elf_sym_name (input_bfd
, symtab_hdr
,
8945 local_syms
+ r_symndx
,
8947 (*_bfd_error_handler
)
8948 (_("%B: Can't find matching LO16 reloc against `%s' for %s at 0x%lx in section `%A'"),
8949 input_bfd
, input_section
, name
, howto
->name
,
8954 addend
<<= howto
->rightshift
;
8957 addend
= rel
->r_addend
;
8958 mips_elf_adjust_addend (output_bfd
, info
, input_bfd
,
8959 local_syms
, local_sections
, rel
);
8962 if (info
->relocatable
)
8964 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
)
8965 && bfd_big_endian (input_bfd
))
8968 if (!rela_relocation_p
&& rel
->r_addend
)
8970 addend
+= rel
->r_addend
;
8971 if (hi16_reloc_p (r_type
) || got16_reloc_p (r_type
))
8972 addend
= mips_elf_high (addend
);
8973 else if (r_type
== R_MIPS_HIGHER
)
8974 addend
= mips_elf_higher (addend
);
8975 else if (r_type
== R_MIPS_HIGHEST
)
8976 addend
= mips_elf_highest (addend
);
8978 addend
>>= howto
->rightshift
;
8980 /* We use the source mask, rather than the destination
8981 mask because the place to which we are writing will be
8982 source of the addend in the final link. */
8983 addend
&= howto
->src_mask
;
8985 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
8986 /* See the comment above about using R_MIPS_64 in the 32-bit
8987 ABI. Here, we need to update the addend. It would be
8988 possible to get away with just using the R_MIPS_32 reloc
8989 but for endianness. */
8995 if (addend
& ((bfd_vma
) 1 << 31))
8997 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
9004 /* If we don't know that we have a 64-bit type,
9005 do two separate stores. */
9006 if (bfd_big_endian (input_bfd
))
9008 /* Store the sign-bits (which are most significant)
9010 low_bits
= sign_bits
;
9016 high_bits
= sign_bits
;
9018 bfd_put_32 (input_bfd
, low_bits
,
9019 contents
+ rel
->r_offset
);
9020 bfd_put_32 (input_bfd
, high_bits
,
9021 contents
+ rel
->r_offset
+ 4);
9025 if (! mips_elf_perform_relocation (info
, howto
, rel
, addend
,
9026 input_bfd
, input_section
,
9031 /* Go on to the next relocation. */
9035 /* In the N32 and 64-bit ABIs there may be multiple consecutive
9036 relocations for the same offset. In that case we are
9037 supposed to treat the output of each relocation as the addend
9039 if (rel
+ 1 < relend
9040 && rel
->r_offset
== rel
[1].r_offset
9041 && ELF_R_TYPE (input_bfd
, rel
[1].r_info
) != R_MIPS_NONE
)
9042 use_saved_addend_p
= TRUE
;
9044 use_saved_addend_p
= FALSE
;
9046 /* Figure out what value we are supposed to relocate. */
9047 switch (mips_elf_calculate_relocation (output_bfd
, input_bfd
,
9048 input_section
, info
, rel
,
9049 addend
, howto
, local_syms
,
9050 local_sections
, &value
,
9051 &name
, &require_jalx
,
9052 use_saved_addend_p
))
9054 case bfd_reloc_continue
:
9055 /* There's nothing to do. */
9058 case bfd_reloc_undefined
:
9059 /* mips_elf_calculate_relocation already called the
9060 undefined_symbol callback. There's no real point in
9061 trying to perform the relocation at this point, so we
9062 just skip ahead to the next relocation. */
9065 case bfd_reloc_notsupported
:
9066 msg
= _("internal error: unsupported relocation error");
9067 info
->callbacks
->warning
9068 (info
, msg
, name
, input_bfd
, input_section
, rel
->r_offset
);
9071 case bfd_reloc_overflow
:
9072 if (use_saved_addend_p
)
9073 /* Ignore overflow until we reach the last relocation for
9074 a given location. */
9078 struct mips_elf_link_hash_table
*htab
;
9080 htab
= mips_elf_hash_table (info
);
9081 BFD_ASSERT (name
!= NULL
);
9082 if (!htab
->small_data_overflow_reported
9083 && (howto
->type
== R_MIPS_GPREL16
9084 || howto
->type
== R_MIPS_LITERAL
))
9087 _("small-data section exceeds 64KB;"
9088 " lower small-data size limit (see option -G)");
9090 htab
->small_data_overflow_reported
= TRUE
;
9091 (*info
->callbacks
->einfo
) ("%P: %s\n", msg
);
9093 if (! ((*info
->callbacks
->reloc_overflow
)
9094 (info
, NULL
, name
, howto
->name
, (bfd_vma
) 0,
9095 input_bfd
, input_section
, rel
->r_offset
)))
9108 /* If we've got another relocation for the address, keep going
9109 until we reach the last one. */
9110 if (use_saved_addend_p
)
9116 if (r_type
== R_MIPS_64
&& ! NEWABI_P (output_bfd
))
9117 /* See the comment above about using R_MIPS_64 in the 32-bit
9118 ABI. Until now, we've been using the HOWTO for R_MIPS_32;
9119 that calculated the right value. Now, however, we
9120 sign-extend the 32-bit result to 64-bits, and store it as a
9121 64-bit value. We are especially generous here in that we
9122 go to extreme lengths to support this usage on systems with
9123 only a 32-bit VMA. */
9129 if (value
& ((bfd_vma
) 1 << 31))
9131 sign_bits
= ((bfd_vma
) 1 << 32) - 1;
9138 /* If we don't know that we have a 64-bit type,
9139 do two separate stores. */
9140 if (bfd_big_endian (input_bfd
))
9142 /* Undo what we did above. */
9144 /* Store the sign-bits (which are most significant)
9146 low_bits
= sign_bits
;
9152 high_bits
= sign_bits
;
9154 bfd_put_32 (input_bfd
, low_bits
,
9155 contents
+ rel
->r_offset
);
9156 bfd_put_32 (input_bfd
, high_bits
,
9157 contents
+ rel
->r_offset
+ 4);
9161 /* Actually perform the relocation. */
9162 if (! mips_elf_perform_relocation (info
, howto
, rel
, value
,
9163 input_bfd
, input_section
,
9164 contents
, require_jalx
))
9171 /* A function that iterates over each entry in la25_stubs and fills
9172 in the code for each one. DATA points to a mips_htab_traverse_info. */
9175 mips_elf_create_la25_stub (void **slot
, void *data
)
9177 struct mips_htab_traverse_info
*hti
;
9178 struct mips_elf_link_hash_table
*htab
;
9179 struct mips_elf_la25_stub
*stub
;
9182 bfd_vma offset
, target
, target_high
, target_low
;
9184 stub
= (struct mips_elf_la25_stub
*) *slot
;
9185 hti
= (struct mips_htab_traverse_info
*) data
;
9186 htab
= mips_elf_hash_table (hti
->info
);
9188 /* Create the section contents, if we haven't already. */
9189 s
= stub
->stub_section
;
9193 loc
= bfd_malloc (s
->size
);
9202 /* Work out where in the section this stub should go. */
9203 offset
= stub
->offset
;
9205 /* Work out the target address. */
9206 target
= (stub
->h
->root
.root
.u
.def
.section
->output_section
->vma
9207 + stub
->h
->root
.root
.u
.def
.section
->output_offset
9208 + stub
->h
->root
.root
.u
.def
.value
);
9209 target_high
= ((target
+ 0x8000) >> 16) & 0xffff;
9210 target_low
= (target
& 0xffff);
9212 if (stub
->stub_section
!= htab
->strampoline
)
9214 /* This is a simple LUI/ADIDU stub. Zero out the beginning
9215 of the section and write the two instructions at the end. */
9216 memset (loc
, 0, offset
);
9218 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
9219 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 4);
9223 /* This is trampoline. */
9225 bfd_put_32 (hti
->output_bfd
, LA25_LUI (target_high
), loc
);
9226 bfd_put_32 (hti
->output_bfd
, LA25_J (target
), loc
+ 4);
9227 bfd_put_32 (hti
->output_bfd
, LA25_ADDIU (target_low
), loc
+ 8);
9228 bfd_put_32 (hti
->output_bfd
, 0, loc
+ 12);
9233 /* If NAME is one of the special IRIX6 symbols defined by the linker,
9234 adjust it appropriately now. */
9237 mips_elf_irix6_finish_dynamic_symbol (bfd
*abfd ATTRIBUTE_UNUSED
,
9238 const char *name
, Elf_Internal_Sym
*sym
)
9240 /* The linker script takes care of providing names and values for
9241 these, but we must place them into the right sections. */
9242 static const char* const text_section_symbols
[] = {
9245 "__dso_displacement",
9247 "__program_header_table",
9251 static const char* const data_section_symbols
[] = {
9259 const char* const *p
;
9262 for (i
= 0; i
< 2; ++i
)
9263 for (p
= (i
== 0) ? text_section_symbols
: data_section_symbols
;
9266 if (strcmp (*p
, name
) == 0)
9268 /* All of these symbols are given type STT_SECTION by the
9270 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9271 sym
->st_other
= STO_PROTECTED
;
9273 /* The IRIX linker puts these symbols in special sections. */
9275 sym
->st_shndx
= SHN_MIPS_TEXT
;
9277 sym
->st_shndx
= SHN_MIPS_DATA
;
9283 /* Finish up dynamic symbol handling. We set the contents of various
9284 dynamic sections here. */
9287 _bfd_mips_elf_finish_dynamic_symbol (bfd
*output_bfd
,
9288 struct bfd_link_info
*info
,
9289 struct elf_link_hash_entry
*h
,
9290 Elf_Internal_Sym
*sym
)
9294 struct mips_got_info
*g
, *gg
;
9297 struct mips_elf_link_hash_table
*htab
;
9298 struct mips_elf_link_hash_entry
*hmips
;
9300 htab
= mips_elf_hash_table (info
);
9301 dynobj
= elf_hash_table (info
)->dynobj
;
9302 hmips
= (struct mips_elf_link_hash_entry
*) h
;
9304 BFD_ASSERT (!htab
->is_vxworks
);
9306 if (h
->plt
.offset
!= MINUS_ONE
&& hmips
->no_fn_stub
)
9308 /* We've decided to create a PLT entry for this symbol. */
9310 bfd_vma header_address
, plt_index
, got_address
;
9311 bfd_vma got_address_high
, got_address_low
, load
;
9312 const bfd_vma
*plt_entry
;
9314 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
9315 BFD_ASSERT (h
->dynindx
!= -1);
9316 BFD_ASSERT (htab
->splt
!= NULL
);
9317 BFD_ASSERT (h
->plt
.offset
<= htab
->splt
->size
);
9318 BFD_ASSERT (!h
->def_regular
);
9320 /* Calculate the address of the PLT header. */
9321 header_address
= (htab
->splt
->output_section
->vma
9322 + htab
->splt
->output_offset
);
9324 /* Calculate the index of the entry. */
9325 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
9326 / htab
->plt_entry_size
);
9328 /* Calculate the address of the .got.plt entry. */
9329 got_address
= (htab
->sgotplt
->output_section
->vma
9330 + htab
->sgotplt
->output_offset
9331 + (2 + plt_index
) * MIPS_ELF_GOT_SIZE (dynobj
));
9332 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
9333 got_address_low
= got_address
& 0xffff;
9335 /* Initially point the .got.plt entry at the PLT header. */
9336 loc
= (htab
->sgotplt
->contents
9337 + (2 + plt_index
) * MIPS_ELF_GOT_SIZE (dynobj
));
9338 if (ABI_64_P (output_bfd
))
9339 bfd_put_64 (output_bfd
, header_address
, loc
);
9341 bfd_put_32 (output_bfd
, header_address
, loc
);
9343 /* Find out where the .plt entry should go. */
9344 loc
= htab
->splt
->contents
+ h
->plt
.offset
;
9346 /* Pick the load opcode. */
9347 load
= MIPS_ELF_LOAD_WORD (output_bfd
);
9349 /* Fill in the PLT entry itself. */
9350 plt_entry
= mips_exec_plt_entry
;
9351 bfd_put_32 (output_bfd
, plt_entry
[0] | got_address_high
, loc
);
9352 bfd_put_32 (output_bfd
, plt_entry
[1] | got_address_low
| load
, loc
+ 4);
9353 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_low
, loc
+ 8);
9354 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9356 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
9357 mips_elf_output_dynamic_relocation (output_bfd
, htab
->srelplt
,
9358 plt_index
, h
->dynindx
,
9359 R_MIPS_JUMP_SLOT
, got_address
);
9361 /* We distinguish between PLT entries and lazy-binding stubs by
9362 giving the former an st_other value of STO_MIPS_PLT. Set the
9363 flag and leave the value if there are any relocations in the
9364 binary where pointer equality matters. */
9365 sym
->st_shndx
= SHN_UNDEF
;
9366 if (h
->pointer_equality_needed
)
9367 sym
->st_other
= STO_MIPS_PLT
;
9371 else if (h
->plt
.offset
!= MINUS_ONE
)
9373 /* We've decided to create a lazy-binding stub. */
9374 bfd_byte stub
[MIPS_FUNCTION_STUB_BIG_SIZE
];
9376 /* This symbol has a stub. Set it up. */
9378 BFD_ASSERT (h
->dynindx
!= -1);
9380 BFD_ASSERT ((htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
9381 || (h
->dynindx
<= 0xffff));
9383 /* Values up to 2^31 - 1 are allowed. Larger values would cause
9384 sign extension at runtime in the stub, resulting in a negative
9386 if (h
->dynindx
& ~0x7fffffff)
9389 /* Fill the stub. */
9391 bfd_put_32 (output_bfd
, STUB_LW (output_bfd
), stub
+ idx
);
9393 bfd_put_32 (output_bfd
, STUB_MOVE (output_bfd
), stub
+ idx
);
9395 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
9397 bfd_put_32 (output_bfd
, STUB_LUI ((h
->dynindx
>> 16) & 0x7fff),
9401 bfd_put_32 (output_bfd
, STUB_JALR
, stub
+ idx
);
9404 /* If a large stub is not required and sign extension is not a
9405 problem, then use legacy code in the stub. */
9406 if (htab
->function_stub_size
== MIPS_FUNCTION_STUB_BIG_SIZE
)
9407 bfd_put_32 (output_bfd
, STUB_ORI (h
->dynindx
& 0xffff), stub
+ idx
);
9408 else if (h
->dynindx
& ~0x7fff)
9409 bfd_put_32 (output_bfd
, STUB_LI16U (h
->dynindx
& 0xffff), stub
+ idx
);
9411 bfd_put_32 (output_bfd
, STUB_LI16S (output_bfd
, h
->dynindx
),
9414 BFD_ASSERT (h
->plt
.offset
<= htab
->sstubs
->size
);
9415 memcpy (htab
->sstubs
->contents
+ h
->plt
.offset
,
9416 stub
, htab
->function_stub_size
);
9418 /* Mark the symbol as undefined. plt.offset != -1 occurs
9419 only for the referenced symbol. */
9420 sym
->st_shndx
= SHN_UNDEF
;
9422 /* The run-time linker uses the st_value field of the symbol
9423 to reset the global offset table entry for this external
9424 to its stub address when unlinking a shared object. */
9425 sym
->st_value
= (htab
->sstubs
->output_section
->vma
9426 + htab
->sstubs
->output_offset
9430 /* If we have a MIPS16 function with a stub, the dynamic symbol must
9431 refer to the stub, since only the stub uses the standard calling
9433 if (h
->dynindx
!= -1 && hmips
->fn_stub
!= NULL
)
9435 BFD_ASSERT (hmips
->need_fn_stub
);
9436 sym
->st_value
= (hmips
->fn_stub
->output_section
->vma
9437 + hmips
->fn_stub
->output_offset
);
9438 sym
->st_size
= hmips
->fn_stub
->size
;
9439 sym
->st_other
= ELF_ST_VISIBILITY (sym
->st_other
);
9442 BFD_ASSERT (h
->dynindx
!= -1
9443 || h
->forced_local
);
9447 BFD_ASSERT (g
!= NULL
);
9449 /* Run through the global symbol table, creating GOT entries for all
9450 the symbols that need them. */
9451 if (g
->global_gotsym
!= NULL
9452 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
9457 value
= sym
->st_value
;
9458 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
9459 R_MIPS_GOT16
, info
);
9460 MIPS_ELF_PUT_WORD (output_bfd
, value
, sgot
->contents
+ offset
);
9463 if (g
->next
&& h
->dynindx
!= -1 && h
->type
!= STT_TLS
)
9465 struct mips_got_entry e
, *p
;
9471 e
.abfd
= output_bfd
;
9476 for (g
= g
->next
; g
->next
!= gg
; g
= g
->next
)
9479 && (p
= (struct mips_got_entry
*) htab_find (g
->got_entries
,
9484 || (elf_hash_table (info
)->dynamic_sections_created
9486 && p
->d
.h
->root
.def_dynamic
9487 && !p
->d
.h
->root
.def_regular
))
9489 /* Create an R_MIPS_REL32 relocation for this entry. Due to
9490 the various compatibility problems, it's easier to mock
9491 up an R_MIPS_32 or R_MIPS_64 relocation and leave
9492 mips_elf_create_dynamic_relocation to calculate the
9493 appropriate addend. */
9494 Elf_Internal_Rela rel
[3];
9496 memset (rel
, 0, sizeof (rel
));
9497 if (ABI_64_P (output_bfd
))
9498 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_64
);
9500 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_32
);
9501 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
= offset
;
9504 if (! (mips_elf_create_dynamic_relocation
9505 (output_bfd
, info
, rel
,
9506 e
.d
.h
, NULL
, sym
->st_value
, &entry
, sgot
)))
9510 entry
= sym
->st_value
;
9511 MIPS_ELF_PUT_WORD (output_bfd
, entry
, sgot
->contents
+ offset
);
9516 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
9517 name
= h
->root
.root
.string
;
9518 if (strcmp (name
, "_DYNAMIC") == 0
9519 || h
== elf_hash_table (info
)->hgot
)
9520 sym
->st_shndx
= SHN_ABS
;
9521 else if (strcmp (name
, "_DYNAMIC_LINK") == 0
9522 || strcmp (name
, "_DYNAMIC_LINKING") == 0)
9524 sym
->st_shndx
= SHN_ABS
;
9525 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9528 else if (strcmp (name
, "_gp_disp") == 0 && ! NEWABI_P (output_bfd
))
9530 sym
->st_shndx
= SHN_ABS
;
9531 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9532 sym
->st_value
= elf_gp (output_bfd
);
9534 else if (SGI_COMPAT (output_bfd
))
9536 if (strcmp (name
, mips_elf_dynsym_rtproc_names
[0]) == 0
9537 || strcmp (name
, mips_elf_dynsym_rtproc_names
[1]) == 0)
9539 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9540 sym
->st_other
= STO_PROTECTED
;
9542 sym
->st_shndx
= SHN_MIPS_DATA
;
9544 else if (strcmp (name
, mips_elf_dynsym_rtproc_names
[2]) == 0)
9546 sym
->st_info
= ELF_ST_INFO (STB_GLOBAL
, STT_SECTION
);
9547 sym
->st_other
= STO_PROTECTED
;
9548 sym
->st_value
= mips_elf_hash_table (info
)->procedure_count
;
9549 sym
->st_shndx
= SHN_ABS
;
9551 else if (sym
->st_shndx
!= SHN_UNDEF
&& sym
->st_shndx
!= SHN_ABS
)
9553 if (h
->type
== STT_FUNC
)
9554 sym
->st_shndx
= SHN_MIPS_TEXT
;
9555 else if (h
->type
== STT_OBJECT
)
9556 sym
->st_shndx
= SHN_MIPS_DATA
;
9560 /* Emit a copy reloc, if needed. */
9566 BFD_ASSERT (h
->dynindx
!= -1);
9567 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
9569 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9570 symval
= (h
->root
.u
.def
.section
->output_section
->vma
9571 + h
->root
.u
.def
.section
->output_offset
9572 + h
->root
.u
.def
.value
);
9573 mips_elf_output_dynamic_relocation (output_bfd
, s
, s
->reloc_count
++,
9574 h
->dynindx
, R_MIPS_COPY
, symval
);
9577 /* Handle the IRIX6-specific symbols. */
9578 if (IRIX_COMPAT (output_bfd
) == ict_irix6
)
9579 mips_elf_irix6_finish_dynamic_symbol (output_bfd
, name
, sym
);
9583 if (! mips_elf_hash_table (info
)->use_rld_obj_head
9584 && (strcmp (name
, "__rld_map") == 0
9585 || strcmp (name
, "__RLD_MAP") == 0))
9587 asection
*s
= bfd_get_section_by_name (dynobj
, ".rld_map");
9588 BFD_ASSERT (s
!= NULL
);
9589 sym
->st_value
= s
->output_section
->vma
+ s
->output_offset
;
9590 bfd_put_32 (output_bfd
, 0, s
->contents
);
9591 if (mips_elf_hash_table (info
)->rld_value
== 0)
9592 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
9594 else if (mips_elf_hash_table (info
)->use_rld_obj_head
9595 && strcmp (name
, "__rld_obj_head") == 0)
9597 /* IRIX6 does not use a .rld_map section. */
9598 if (IRIX_COMPAT (output_bfd
) == ict_irix5
9599 || IRIX_COMPAT (output_bfd
) == ict_none
)
9600 BFD_ASSERT (bfd_get_section_by_name (dynobj
, ".rld_map")
9602 mips_elf_hash_table (info
)->rld_value
= sym
->st_value
;
9606 /* Keep dynamic MIPS16 symbols odd. This allows the dynamic linker to
9607 treat MIPS16 symbols like any other. */
9608 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
9610 BFD_ASSERT (sym
->st_value
& 1);
9611 sym
->st_other
-= STO_MIPS16
;
9617 /* Likewise, for VxWorks. */
9620 _bfd_mips_vxworks_finish_dynamic_symbol (bfd
*output_bfd
,
9621 struct bfd_link_info
*info
,
9622 struct elf_link_hash_entry
*h
,
9623 Elf_Internal_Sym
*sym
)
9627 struct mips_got_info
*g
;
9628 struct mips_elf_link_hash_table
*htab
;
9630 htab
= mips_elf_hash_table (info
);
9631 dynobj
= elf_hash_table (info
)->dynobj
;
9633 if (h
->plt
.offset
!= (bfd_vma
) -1)
9636 bfd_vma plt_address
, plt_index
, got_address
, got_offset
, branch_offset
;
9637 Elf_Internal_Rela rel
;
9638 static const bfd_vma
*plt_entry
;
9640 BFD_ASSERT (h
->dynindx
!= -1);
9641 BFD_ASSERT (htab
->splt
!= NULL
);
9642 BFD_ASSERT (h
->plt
.offset
<= htab
->splt
->size
);
9644 /* Calculate the address of the .plt entry. */
9645 plt_address
= (htab
->splt
->output_section
->vma
9646 + htab
->splt
->output_offset
9649 /* Calculate the index of the entry. */
9650 plt_index
= ((h
->plt
.offset
- htab
->plt_header_size
)
9651 / htab
->plt_entry_size
);
9653 /* Calculate the address of the .got.plt entry. */
9654 got_address
= (htab
->sgotplt
->output_section
->vma
9655 + htab
->sgotplt
->output_offset
9658 /* Calculate the offset of the .got.plt entry from
9659 _GLOBAL_OFFSET_TABLE_. */
9660 got_offset
= mips_elf_gotplt_index (info
, h
);
9662 /* Calculate the offset for the branch at the start of the PLT
9663 entry. The branch jumps to the beginning of .plt. */
9664 branch_offset
= -(h
->plt
.offset
/ 4 + 1) & 0xffff;
9666 /* Fill in the initial value of the .got.plt entry. */
9667 bfd_put_32 (output_bfd
, plt_address
,
9668 htab
->sgotplt
->contents
+ plt_index
* 4);
9670 /* Find out where the .plt entry should go. */
9671 loc
= htab
->splt
->contents
+ h
->plt
.offset
;
9675 plt_entry
= mips_vxworks_shared_plt_entry
;
9676 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9677 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9681 bfd_vma got_address_high
, got_address_low
;
9683 plt_entry
= mips_vxworks_exec_plt_entry
;
9684 got_address_high
= ((got_address
+ 0x8000) >> 16) & 0xffff;
9685 got_address_low
= got_address
& 0xffff;
9687 bfd_put_32 (output_bfd
, plt_entry
[0] | branch_offset
, loc
);
9688 bfd_put_32 (output_bfd
, plt_entry
[1] | plt_index
, loc
+ 4);
9689 bfd_put_32 (output_bfd
, plt_entry
[2] | got_address_high
, loc
+ 8);
9690 bfd_put_32 (output_bfd
, plt_entry
[3] | got_address_low
, loc
+ 12);
9691 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9692 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9693 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
9694 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
9696 loc
= (htab
->srelplt2
->contents
9697 + (plt_index
* 3 + 2) * sizeof (Elf32_External_Rela
));
9699 /* Emit a relocation for the .got.plt entry. */
9700 rel
.r_offset
= got_address
;
9701 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9702 rel
.r_addend
= h
->plt
.offset
;
9703 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9705 /* Emit a relocation for the lui of %hi(<.got.plt slot>). */
9706 loc
+= sizeof (Elf32_External_Rela
);
9707 rel
.r_offset
= plt_address
+ 8;
9708 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9709 rel
.r_addend
= got_offset
;
9710 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9712 /* Emit a relocation for the addiu of %lo(<.got.plt slot>). */
9713 loc
+= sizeof (Elf32_External_Rela
);
9715 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9716 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9719 /* Emit an R_MIPS_JUMP_SLOT relocation against the .got.plt entry. */
9720 loc
= htab
->srelplt
->contents
+ plt_index
* sizeof (Elf32_External_Rela
);
9721 rel
.r_offset
= got_address
;
9722 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_JUMP_SLOT
);
9724 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9726 if (!h
->def_regular
)
9727 sym
->st_shndx
= SHN_UNDEF
;
9730 BFD_ASSERT (h
->dynindx
!= -1 || h
->forced_local
);
9734 BFD_ASSERT (g
!= NULL
);
9736 /* See if this symbol has an entry in the GOT. */
9737 if (g
->global_gotsym
!= NULL
9738 && h
->dynindx
>= g
->global_gotsym
->dynindx
)
9741 Elf_Internal_Rela outrel
;
9745 /* Install the symbol value in the GOT. */
9746 offset
= mips_elf_global_got_index (dynobj
, output_bfd
, h
,
9747 R_MIPS_GOT16
, info
);
9748 MIPS_ELF_PUT_WORD (output_bfd
, sym
->st_value
, sgot
->contents
+ offset
);
9750 /* Add a dynamic relocation for it. */
9751 s
= mips_elf_rel_dyn_section (info
, FALSE
);
9752 loc
= s
->contents
+ (s
->reloc_count
++ * sizeof (Elf32_External_Rela
));
9753 outrel
.r_offset
= (sgot
->output_section
->vma
9754 + sgot
->output_offset
9756 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_32
);
9757 outrel
.r_addend
= 0;
9758 bfd_elf32_swap_reloca_out (dynobj
, &outrel
, loc
);
9761 /* Emit a copy reloc, if needed. */
9764 Elf_Internal_Rela rel
;
9766 BFD_ASSERT (h
->dynindx
!= -1);
9768 rel
.r_offset
= (h
->root
.u
.def
.section
->output_section
->vma
9769 + h
->root
.u
.def
.section
->output_offset
9770 + h
->root
.u
.def
.value
);
9771 rel
.r_info
= ELF32_R_INFO (h
->dynindx
, R_MIPS_COPY
);
9773 bfd_elf32_swap_reloca_out (output_bfd
, &rel
,
9774 htab
->srelbss
->contents
9775 + (htab
->srelbss
->reloc_count
9776 * sizeof (Elf32_External_Rela
)));
9777 ++htab
->srelbss
->reloc_count
;
9780 /* If this is a mips16 symbol, force the value to be even. */
9781 if (ELF_ST_IS_MIPS16 (sym
->st_other
))
9782 sym
->st_value
&= ~1;
9787 /* Write out a plt0 entry to the beginning of .plt. */
9790 mips_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9793 bfd_vma gotplt_value
, gotplt_value_high
, gotplt_value_low
;
9794 static const bfd_vma
*plt_entry
;
9795 struct mips_elf_link_hash_table
*htab
;
9797 htab
= mips_elf_hash_table (info
);
9798 if (ABI_64_P (output_bfd
))
9799 plt_entry
= mips_n64_exec_plt0_entry
;
9800 else if (ABI_N32_P (output_bfd
))
9801 plt_entry
= mips_n32_exec_plt0_entry
;
9803 plt_entry
= mips_o32_exec_plt0_entry
;
9805 /* Calculate the value of .got.plt. */
9806 gotplt_value
= (htab
->sgotplt
->output_section
->vma
9807 + htab
->sgotplt
->output_offset
);
9808 gotplt_value_high
= ((gotplt_value
+ 0x8000) >> 16) & 0xffff;
9809 gotplt_value_low
= gotplt_value
& 0xffff;
9811 /* The PLT sequence is not safe for N64 if .got.plt's address can
9812 not be loaded in two instructions. */
9813 BFD_ASSERT ((gotplt_value
& ~(bfd_vma
) 0x7fffffff) == 0
9814 || ~(gotplt_value
| 0x7fffffff) == 0);
9816 /* Install the PLT header. */
9817 loc
= htab
->splt
->contents
;
9818 bfd_put_32 (output_bfd
, plt_entry
[0] | gotplt_value_high
, loc
);
9819 bfd_put_32 (output_bfd
, plt_entry
[1] | gotplt_value_low
, loc
+ 4);
9820 bfd_put_32 (output_bfd
, plt_entry
[2] | gotplt_value_low
, loc
+ 8);
9821 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9822 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9823 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9824 bfd_put_32 (output_bfd
, plt_entry
[6], loc
+ 24);
9825 bfd_put_32 (output_bfd
, plt_entry
[7], loc
+ 28);
9828 /* Install the PLT header for a VxWorks executable and finalize the
9829 contents of .rela.plt.unloaded. */
9832 mips_vxworks_finish_exec_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9834 Elf_Internal_Rela rela
;
9836 bfd_vma got_value
, got_value_high
, got_value_low
, plt_address
;
9837 static const bfd_vma
*plt_entry
;
9838 struct mips_elf_link_hash_table
*htab
;
9840 htab
= mips_elf_hash_table (info
);
9841 plt_entry
= mips_vxworks_exec_plt0_entry
;
9843 /* Calculate the value of _GLOBAL_OFFSET_TABLE_. */
9844 got_value
= (htab
->root
.hgot
->root
.u
.def
.section
->output_section
->vma
9845 + htab
->root
.hgot
->root
.u
.def
.section
->output_offset
9846 + htab
->root
.hgot
->root
.u
.def
.value
);
9848 got_value_high
= ((got_value
+ 0x8000) >> 16) & 0xffff;
9849 got_value_low
= got_value
& 0xffff;
9851 /* Calculate the address of the PLT header. */
9852 plt_address
= htab
->splt
->output_section
->vma
+ htab
->splt
->output_offset
;
9854 /* Install the PLT header. */
9855 loc
= htab
->splt
->contents
;
9856 bfd_put_32 (output_bfd
, plt_entry
[0] | got_value_high
, loc
);
9857 bfd_put_32 (output_bfd
, plt_entry
[1] | got_value_low
, loc
+ 4);
9858 bfd_put_32 (output_bfd
, plt_entry
[2], loc
+ 8);
9859 bfd_put_32 (output_bfd
, plt_entry
[3], loc
+ 12);
9860 bfd_put_32 (output_bfd
, plt_entry
[4], loc
+ 16);
9861 bfd_put_32 (output_bfd
, plt_entry
[5], loc
+ 20);
9863 /* Output the relocation for the lui of %hi(_GLOBAL_OFFSET_TABLE_). */
9864 loc
= htab
->srelplt2
->contents
;
9865 rela
.r_offset
= plt_address
;
9866 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9868 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9869 loc
+= sizeof (Elf32_External_Rela
);
9871 /* Output the relocation for the following addiu of
9872 %lo(_GLOBAL_OFFSET_TABLE_). */
9874 rela
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9875 bfd_elf32_swap_reloca_out (output_bfd
, &rela
, loc
);
9876 loc
+= sizeof (Elf32_External_Rela
);
9878 /* Fix up the remaining relocations. They may have the wrong
9879 symbol index for _G_O_T_ or _P_L_T_ depending on the order
9880 in which symbols were output. */
9881 while (loc
< htab
->srelplt2
->contents
+ htab
->srelplt2
->size
)
9883 Elf_Internal_Rela rel
;
9885 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9886 rel
.r_info
= ELF32_R_INFO (htab
->root
.hplt
->indx
, R_MIPS_32
);
9887 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9888 loc
+= sizeof (Elf32_External_Rela
);
9890 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9891 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_HI16
);
9892 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9893 loc
+= sizeof (Elf32_External_Rela
);
9895 bfd_elf32_swap_reloca_in (output_bfd
, loc
, &rel
);
9896 rel
.r_info
= ELF32_R_INFO (htab
->root
.hgot
->indx
, R_MIPS_LO16
);
9897 bfd_elf32_swap_reloca_out (output_bfd
, &rel
, loc
);
9898 loc
+= sizeof (Elf32_External_Rela
);
9902 /* Install the PLT header for a VxWorks shared library. */
9905 mips_vxworks_finish_shared_plt (bfd
*output_bfd
, struct bfd_link_info
*info
)
9908 struct mips_elf_link_hash_table
*htab
;
9910 htab
= mips_elf_hash_table (info
);
9912 /* We just need to copy the entry byte-by-byte. */
9913 for (i
= 0; i
< ARRAY_SIZE (mips_vxworks_shared_plt0_entry
); i
++)
9914 bfd_put_32 (output_bfd
, mips_vxworks_shared_plt0_entry
[i
],
9915 htab
->splt
->contents
+ i
* 4);
9918 /* Finish up the dynamic sections. */
9921 _bfd_mips_elf_finish_dynamic_sections (bfd
*output_bfd
,
9922 struct bfd_link_info
*info
)
9927 struct mips_got_info
*gg
, *g
;
9928 struct mips_elf_link_hash_table
*htab
;
9930 htab
= mips_elf_hash_table (info
);
9931 dynobj
= elf_hash_table (info
)->dynobj
;
9933 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
9936 gg
= htab
->got_info
;
9938 if (elf_hash_table (info
)->dynamic_sections_created
)
9941 int dyn_to_skip
= 0, dyn_skipped
= 0;
9943 BFD_ASSERT (sdyn
!= NULL
);
9944 BFD_ASSERT (gg
!= NULL
);
9946 g
= mips_elf_got_for_ibfd (gg
, output_bfd
);
9947 BFD_ASSERT (g
!= NULL
);
9949 for (b
= sdyn
->contents
;
9950 b
< sdyn
->contents
+ sdyn
->size
;
9951 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
9953 Elf_Internal_Dyn dyn
;
9957 bfd_boolean swap_out_p
;
9959 /* Read in the current dynamic entry. */
9960 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
9962 /* Assume that we're going to modify it and write it out. */
9968 dyn
.d_un
.d_val
= MIPS_ELF_REL_SIZE (dynobj
);
9972 BFD_ASSERT (htab
->is_vxworks
);
9973 dyn
.d_un
.d_val
= MIPS_ELF_RELA_SIZE (dynobj
);
9977 /* Rewrite DT_STRSZ. */
9979 _bfd_elf_strtab_size (elf_hash_table (info
)->dynstr
);
9984 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9987 case DT_MIPS_PLTGOT
:
9989 dyn
.d_un
.d_ptr
= s
->output_section
->vma
+ s
->output_offset
;
9992 case DT_MIPS_RLD_VERSION
:
9993 dyn
.d_un
.d_val
= 1; /* XXX */
9997 dyn
.d_un
.d_val
= RHF_NOTPOT
; /* XXX */
10000 case DT_MIPS_TIME_STAMP
:
10004 dyn
.d_un
.d_val
= t
;
10008 case DT_MIPS_ICHECKSUM
:
10010 swap_out_p
= FALSE
;
10013 case DT_MIPS_IVERSION
:
10015 swap_out_p
= FALSE
;
10018 case DT_MIPS_BASE_ADDRESS
:
10019 s
= output_bfd
->sections
;
10020 BFD_ASSERT (s
!= NULL
);
10021 dyn
.d_un
.d_ptr
= s
->vma
& ~(bfd_vma
) 0xffff;
10024 case DT_MIPS_LOCAL_GOTNO
:
10025 dyn
.d_un
.d_val
= g
->local_gotno
;
10028 case DT_MIPS_UNREFEXTNO
:
10029 /* The index into the dynamic symbol table which is the
10030 entry of the first external symbol that is not
10031 referenced within the same object. */
10032 dyn
.d_un
.d_val
= bfd_count_sections (output_bfd
) + 1;
10035 case DT_MIPS_GOTSYM
:
10036 if (gg
->global_gotsym
)
10038 dyn
.d_un
.d_val
= gg
->global_gotsym
->dynindx
;
10041 /* In case if we don't have global got symbols we default
10042 to setting DT_MIPS_GOTSYM to the same value as
10043 DT_MIPS_SYMTABNO, so we just fall through. */
10045 case DT_MIPS_SYMTABNO
:
10047 elemsize
= MIPS_ELF_SYM_SIZE (output_bfd
);
10048 s
= bfd_get_section_by_name (output_bfd
, name
);
10049 BFD_ASSERT (s
!= NULL
);
10051 dyn
.d_un
.d_val
= s
->size
/ elemsize
;
10054 case DT_MIPS_HIPAGENO
:
10055 dyn
.d_un
.d_val
= g
->local_gotno
- htab
->reserved_gotno
;
10058 case DT_MIPS_RLD_MAP
:
10059 dyn
.d_un
.d_ptr
= mips_elf_hash_table (info
)->rld_value
;
10062 case DT_MIPS_OPTIONS
:
10063 s
= (bfd_get_section_by_name
10064 (output_bfd
, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd
)));
10065 dyn
.d_un
.d_ptr
= s
->vma
;
10069 BFD_ASSERT (htab
->is_vxworks
);
10070 /* The count does not include the JUMP_SLOT relocations. */
10072 dyn
.d_un
.d_val
-= htab
->srelplt
->size
;
10076 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10077 if (htab
->is_vxworks
)
10078 dyn
.d_un
.d_val
= DT_RELA
;
10080 dyn
.d_un
.d_val
= DT_REL
;
10084 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10085 dyn
.d_un
.d_val
= htab
->srelplt
->size
;
10089 BFD_ASSERT (htab
->use_plts_and_copy_relocs
);
10090 dyn
.d_un
.d_ptr
= (htab
->srelplt
->output_section
->vma
10091 + htab
->srelplt
->output_offset
);
10095 /* If we didn't need any text relocations after all, delete
10096 the dynamic tag. */
10097 if (!(info
->flags
& DF_TEXTREL
))
10099 dyn_to_skip
= MIPS_ELF_DYN_SIZE (dynobj
);
10100 swap_out_p
= FALSE
;
10105 /* If we didn't need any text relocations after all, clear
10106 DF_TEXTREL from DT_FLAGS. */
10107 if (!(info
->flags
& DF_TEXTREL
))
10108 dyn
.d_un
.d_val
&= ~DF_TEXTREL
;
10110 swap_out_p
= FALSE
;
10114 swap_out_p
= FALSE
;
10115 if (htab
->is_vxworks
10116 && elf_vxworks_finish_dynamic_entry (output_bfd
, &dyn
))
10121 if (swap_out_p
|| dyn_skipped
)
10122 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
10123 (dynobj
, &dyn
, b
- dyn_skipped
);
10127 dyn_skipped
+= dyn_to_skip
;
10132 /* Wipe out any trailing entries if we shifted down a dynamic tag. */
10133 if (dyn_skipped
> 0)
10134 memset (b
- dyn_skipped
, 0, dyn_skipped
);
10137 if (sgot
!= NULL
&& sgot
->size
> 0
10138 && !bfd_is_abs_section (sgot
->output_section
))
10140 if (htab
->is_vxworks
)
10142 /* The first entry of the global offset table points to the
10143 ".dynamic" section. The second is initialized by the
10144 loader and contains the shared library identifier.
10145 The third is also initialized by the loader and points
10146 to the lazy resolution stub. */
10147 MIPS_ELF_PUT_WORD (output_bfd
,
10148 sdyn
->output_offset
+ sdyn
->output_section
->vma
,
10150 MIPS_ELF_PUT_WORD (output_bfd
, 0,
10151 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
10152 MIPS_ELF_PUT_WORD (output_bfd
, 0,
10154 + 2 * MIPS_ELF_GOT_SIZE (output_bfd
));
10158 /* The first entry of the global offset table will be filled at
10159 runtime. The second entry will be used by some runtime loaders.
10160 This isn't the case of IRIX rld. */
10161 MIPS_ELF_PUT_WORD (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
10162 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
10163 sgot
->contents
+ MIPS_ELF_GOT_SIZE (output_bfd
));
10166 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
10167 = MIPS_ELF_GOT_SIZE (output_bfd
);
10170 /* Generate dynamic relocations for the non-primary gots. */
10171 if (gg
!= NULL
&& gg
->next
)
10173 Elf_Internal_Rela rel
[3];
10174 bfd_vma addend
= 0;
10176 memset (rel
, 0, sizeof (rel
));
10177 rel
[0].r_info
= ELF_R_INFO (output_bfd
, 0, R_MIPS_REL32
);
10179 for (g
= gg
->next
; g
->next
!= gg
; g
= g
->next
)
10181 bfd_vma index
= g
->next
->local_gotno
+ g
->next
->global_gotno
10182 + g
->next
->tls_gotno
;
10184 MIPS_ELF_PUT_WORD (output_bfd
, 0, sgot
->contents
10185 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
10186 MIPS_ELF_PUT_WORD (output_bfd
, MIPS_ELF_GNU_GOT1_MASK (output_bfd
),
10188 + index
++ * MIPS_ELF_GOT_SIZE (output_bfd
));
10190 if (! info
->shared
)
10193 while (index
< g
->assigned_gotno
)
10195 rel
[0].r_offset
= rel
[1].r_offset
= rel
[2].r_offset
10196 = index
++ * MIPS_ELF_GOT_SIZE (output_bfd
);
10197 if (!(mips_elf_create_dynamic_relocation
10198 (output_bfd
, info
, rel
, NULL
,
10199 bfd_abs_section_ptr
,
10200 0, &addend
, sgot
)))
10202 BFD_ASSERT (addend
== 0);
10207 /* The generation of dynamic relocations for the non-primary gots
10208 adds more dynamic relocations. We cannot count them until
10211 if (elf_hash_table (info
)->dynamic_sections_created
)
10214 bfd_boolean swap_out_p
;
10216 BFD_ASSERT (sdyn
!= NULL
);
10218 for (b
= sdyn
->contents
;
10219 b
< sdyn
->contents
+ sdyn
->size
;
10220 b
+= MIPS_ELF_DYN_SIZE (dynobj
))
10222 Elf_Internal_Dyn dyn
;
10225 /* Read in the current dynamic entry. */
10226 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_in
) (dynobj
, b
, &dyn
);
10228 /* Assume that we're going to modify it and write it out. */
10234 /* Reduce DT_RELSZ to account for any relocations we
10235 decided not to make. This is for the n64 irix rld,
10236 which doesn't seem to apply any relocations if there
10237 are trailing null entries. */
10238 s
= mips_elf_rel_dyn_section (info
, FALSE
);
10239 dyn
.d_un
.d_val
= (s
->reloc_count
10240 * (ABI_64_P (output_bfd
)
10241 ? sizeof (Elf64_Mips_External_Rel
)
10242 : sizeof (Elf32_External_Rel
)));
10243 /* Adjust the section size too. Tools like the prelinker
10244 can reasonably expect the values to the same. */
10245 elf_section_data (s
->output_section
)->this_hdr
.sh_size
10250 swap_out_p
= FALSE
;
10255 (*get_elf_backend_data (dynobj
)->s
->swap_dyn_out
)
10262 Elf32_compact_rel cpt
;
10264 if (SGI_COMPAT (output_bfd
))
10266 /* Write .compact_rel section out. */
10267 s
= bfd_get_section_by_name (dynobj
, ".compact_rel");
10271 cpt
.num
= s
->reloc_count
;
10273 cpt
.offset
= (s
->output_section
->filepos
10274 + sizeof (Elf32_External_compact_rel
));
10277 bfd_elf32_swap_compact_rel_out (output_bfd
, &cpt
,
10278 ((Elf32_External_compact_rel
*)
10281 /* Clean up a dummy stub function entry in .text. */
10282 if (htab
->sstubs
!= NULL
)
10284 file_ptr dummy_offset
;
10286 BFD_ASSERT (htab
->sstubs
->size
>= htab
->function_stub_size
);
10287 dummy_offset
= htab
->sstubs
->size
- htab
->function_stub_size
;
10288 memset (htab
->sstubs
->contents
+ dummy_offset
, 0,
10289 htab
->function_stub_size
);
10294 /* The psABI says that the dynamic relocations must be sorted in
10295 increasing order of r_symndx. The VxWorks EABI doesn't require
10296 this, and because the code below handles REL rather than RELA
10297 relocations, using it for VxWorks would be outright harmful. */
10298 if (!htab
->is_vxworks
)
10300 s
= mips_elf_rel_dyn_section (info
, FALSE
);
10302 && s
->size
> (bfd_vma
)2 * MIPS_ELF_REL_SIZE (output_bfd
))
10304 reldyn_sorting_bfd
= output_bfd
;
10306 if (ABI_64_P (output_bfd
))
10307 qsort ((Elf64_External_Rel
*) s
->contents
+ 1,
10308 s
->reloc_count
- 1, sizeof (Elf64_Mips_External_Rel
),
10309 sort_dynamic_relocs_64
);
10311 qsort ((Elf32_External_Rel
*) s
->contents
+ 1,
10312 s
->reloc_count
- 1, sizeof (Elf32_External_Rel
),
10313 sort_dynamic_relocs
);
10318 if (htab
->splt
&& htab
->splt
->size
> 0)
10320 if (htab
->is_vxworks
)
10323 mips_vxworks_finish_shared_plt (output_bfd
, info
);
10325 mips_vxworks_finish_exec_plt (output_bfd
, info
);
10329 BFD_ASSERT (!info
->shared
);
10330 mips_finish_exec_plt (output_bfd
, info
);
10337 /* Set ABFD's EF_MIPS_ARCH and EF_MIPS_MACH flags. */
10340 mips_set_isa_flags (bfd
*abfd
)
10344 switch (bfd_get_mach (abfd
))
10347 case bfd_mach_mips3000
:
10348 val
= E_MIPS_ARCH_1
;
10351 case bfd_mach_mips3900
:
10352 val
= E_MIPS_ARCH_1
| E_MIPS_MACH_3900
;
10355 case bfd_mach_mips6000
:
10356 val
= E_MIPS_ARCH_2
;
10359 case bfd_mach_mips4000
:
10360 case bfd_mach_mips4300
:
10361 case bfd_mach_mips4400
:
10362 case bfd_mach_mips4600
:
10363 val
= E_MIPS_ARCH_3
;
10366 case bfd_mach_mips4010
:
10367 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4010
;
10370 case bfd_mach_mips4100
:
10371 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4100
;
10374 case bfd_mach_mips4111
:
10375 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4111
;
10378 case bfd_mach_mips4120
:
10379 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4120
;
10382 case bfd_mach_mips4650
:
10383 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_4650
;
10386 case bfd_mach_mips5400
:
10387 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5400
;
10390 case bfd_mach_mips5500
:
10391 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_5500
;
10394 case bfd_mach_mips9000
:
10395 val
= E_MIPS_ARCH_4
| E_MIPS_MACH_9000
;
10398 case bfd_mach_mips5000
:
10399 case bfd_mach_mips7000
:
10400 case bfd_mach_mips8000
:
10401 case bfd_mach_mips10000
:
10402 case bfd_mach_mips12000
:
10403 val
= E_MIPS_ARCH_4
;
10406 case bfd_mach_mips5
:
10407 val
= E_MIPS_ARCH_5
;
10410 case bfd_mach_mips_loongson_2e
:
10411 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2E
;
10414 case bfd_mach_mips_loongson_2f
:
10415 val
= E_MIPS_ARCH_3
| E_MIPS_MACH_LS2F
;
10418 case bfd_mach_mips_sb1
:
10419 val
= E_MIPS_ARCH_64
| E_MIPS_MACH_SB1
;
10422 case bfd_mach_mips_octeon
:
10423 val
= E_MIPS_ARCH_64R2
| E_MIPS_MACH_OCTEON
;
10426 case bfd_mach_mipsisa32
:
10427 val
= E_MIPS_ARCH_32
;
10430 case bfd_mach_mipsisa64
:
10431 val
= E_MIPS_ARCH_64
;
10434 case bfd_mach_mipsisa32r2
:
10435 val
= E_MIPS_ARCH_32R2
;
10438 case bfd_mach_mipsisa64r2
:
10439 val
= E_MIPS_ARCH_64R2
;
10442 elf_elfheader (abfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
10443 elf_elfheader (abfd
)->e_flags
|= val
;
10448 /* The final processing done just before writing out a MIPS ELF object
10449 file. This gets the MIPS architecture right based on the machine
10450 number. This is used by both the 32-bit and the 64-bit ABI. */
10453 _bfd_mips_elf_final_write_processing (bfd
*abfd
,
10454 bfd_boolean linker ATTRIBUTE_UNUSED
)
10457 Elf_Internal_Shdr
**hdrpp
;
10461 /* Keep the existing EF_MIPS_MACH and EF_MIPS_ARCH flags if the former
10462 is nonzero. This is for compatibility with old objects, which used
10463 a combination of a 32-bit EF_MIPS_ARCH and a 64-bit EF_MIPS_MACH. */
10464 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_MACH
) == 0)
10465 mips_set_isa_flags (abfd
);
10467 /* Set the sh_info field for .gptab sections and other appropriate
10468 info for each special section. */
10469 for (i
= 1, hdrpp
= elf_elfsections (abfd
) + 1;
10470 i
< elf_numsections (abfd
);
10473 switch ((*hdrpp
)->sh_type
)
10475 case SHT_MIPS_MSYM
:
10476 case SHT_MIPS_LIBLIST
:
10477 sec
= bfd_get_section_by_name (abfd
, ".dynstr");
10479 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10482 case SHT_MIPS_GPTAB
:
10483 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
10484 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
10485 BFD_ASSERT (name
!= NULL
10486 && CONST_STRNEQ (name
, ".gptab."));
10487 sec
= bfd_get_section_by_name (abfd
, name
+ sizeof ".gptab" - 1);
10488 BFD_ASSERT (sec
!= NULL
);
10489 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
10492 case SHT_MIPS_CONTENT
:
10493 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
10494 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
10495 BFD_ASSERT (name
!= NULL
10496 && CONST_STRNEQ (name
, ".MIPS.content"));
10497 sec
= bfd_get_section_by_name (abfd
,
10498 name
+ sizeof ".MIPS.content" - 1);
10499 BFD_ASSERT (sec
!= NULL
);
10500 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10503 case SHT_MIPS_SYMBOL_LIB
:
10504 sec
= bfd_get_section_by_name (abfd
, ".dynsym");
10506 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10507 sec
= bfd_get_section_by_name (abfd
, ".liblist");
10509 (*hdrpp
)->sh_info
= elf_section_data (sec
)->this_idx
;
10512 case SHT_MIPS_EVENTS
:
10513 BFD_ASSERT ((*hdrpp
)->bfd_section
!= NULL
);
10514 name
= bfd_get_section_name (abfd
, (*hdrpp
)->bfd_section
);
10515 BFD_ASSERT (name
!= NULL
);
10516 if (CONST_STRNEQ (name
, ".MIPS.events"))
10517 sec
= bfd_get_section_by_name (abfd
,
10518 name
+ sizeof ".MIPS.events" - 1);
10521 BFD_ASSERT (CONST_STRNEQ (name
, ".MIPS.post_rel"));
10522 sec
= bfd_get_section_by_name (abfd
,
10524 + sizeof ".MIPS.post_rel" - 1));
10526 BFD_ASSERT (sec
!= NULL
);
10527 (*hdrpp
)->sh_link
= elf_section_data (sec
)->this_idx
;
10534 /* When creating an IRIX5 executable, we need REGINFO and RTPROC
10538 _bfd_mips_elf_additional_program_headers (bfd
*abfd
,
10539 struct bfd_link_info
*info ATTRIBUTE_UNUSED
)
10544 /* See if we need a PT_MIPS_REGINFO segment. */
10545 s
= bfd_get_section_by_name (abfd
, ".reginfo");
10546 if (s
&& (s
->flags
& SEC_LOAD
))
10549 /* See if we need a PT_MIPS_OPTIONS segment. */
10550 if (IRIX_COMPAT (abfd
) == ict_irix6
10551 && bfd_get_section_by_name (abfd
,
10552 MIPS_ELF_OPTIONS_SECTION_NAME (abfd
)))
10555 /* See if we need a PT_MIPS_RTPROC segment. */
10556 if (IRIX_COMPAT (abfd
) == ict_irix5
10557 && bfd_get_section_by_name (abfd
, ".dynamic")
10558 && bfd_get_section_by_name (abfd
, ".mdebug"))
10561 /* Allocate a PT_NULL header in dynamic objects. See
10562 _bfd_mips_elf_modify_segment_map for details. */
10563 if (!SGI_COMPAT (abfd
)
10564 && bfd_get_section_by_name (abfd
, ".dynamic"))
10570 /* Modify the segment map for an IRIX5 executable. */
10573 _bfd_mips_elf_modify_segment_map (bfd
*abfd
,
10574 struct bfd_link_info
*info
)
10577 struct elf_segment_map
*m
, **pm
;
10580 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO
10582 s
= bfd_get_section_by_name (abfd
, ".reginfo");
10583 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
10585 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
10586 if (m
->p_type
== PT_MIPS_REGINFO
)
10591 m
= bfd_zalloc (abfd
, amt
);
10595 m
->p_type
= PT_MIPS_REGINFO
;
10597 m
->sections
[0] = s
;
10599 /* We want to put it after the PHDR and INTERP segments. */
10600 pm
= &elf_tdata (abfd
)->segment_map
;
10602 && ((*pm
)->p_type
== PT_PHDR
10603 || (*pm
)->p_type
== PT_INTERP
))
10611 /* For IRIX 6, we don't have .mdebug sections, nor does anything but
10612 .dynamic end up in PT_DYNAMIC. However, we do have to insert a
10613 PT_MIPS_OPTIONS segment immediately following the program header
10615 if (NEWABI_P (abfd
)
10616 /* On non-IRIX6 new abi, we'll have already created a segment
10617 for this section, so don't create another. I'm not sure this
10618 is not also the case for IRIX 6, but I can't test it right
10620 && IRIX_COMPAT (abfd
) == ict_irix6
)
10622 for (s
= abfd
->sections
; s
; s
= s
->next
)
10623 if (elf_section_data (s
)->this_hdr
.sh_type
== SHT_MIPS_OPTIONS
)
10628 struct elf_segment_map
*options_segment
;
10630 pm
= &elf_tdata (abfd
)->segment_map
;
10632 && ((*pm
)->p_type
== PT_PHDR
10633 || (*pm
)->p_type
== PT_INTERP
))
10636 if (*pm
== NULL
|| (*pm
)->p_type
!= PT_MIPS_OPTIONS
)
10638 amt
= sizeof (struct elf_segment_map
);
10639 options_segment
= bfd_zalloc (abfd
, amt
);
10640 options_segment
->next
= *pm
;
10641 options_segment
->p_type
= PT_MIPS_OPTIONS
;
10642 options_segment
->p_flags
= PF_R
;
10643 options_segment
->p_flags_valid
= TRUE
;
10644 options_segment
->count
= 1;
10645 options_segment
->sections
[0] = s
;
10646 *pm
= options_segment
;
10652 if (IRIX_COMPAT (abfd
) == ict_irix5
)
10654 /* If there are .dynamic and .mdebug sections, we make a room
10655 for the RTPROC header. FIXME: Rewrite without section names. */
10656 if (bfd_get_section_by_name (abfd
, ".interp") == NULL
10657 && bfd_get_section_by_name (abfd
, ".dynamic") != NULL
10658 && bfd_get_section_by_name (abfd
, ".mdebug") != NULL
)
10660 for (m
= elf_tdata (abfd
)->segment_map
; m
!= NULL
; m
= m
->next
)
10661 if (m
->p_type
== PT_MIPS_RTPROC
)
10666 m
= bfd_zalloc (abfd
, amt
);
10670 m
->p_type
= PT_MIPS_RTPROC
;
10672 s
= bfd_get_section_by_name (abfd
, ".rtproc");
10677 m
->p_flags_valid
= 1;
10682 m
->sections
[0] = s
;
10685 /* We want to put it after the DYNAMIC segment. */
10686 pm
= &elf_tdata (abfd
)->segment_map
;
10687 while (*pm
!= NULL
&& (*pm
)->p_type
!= PT_DYNAMIC
)
10697 /* On IRIX5, the PT_DYNAMIC segment includes the .dynamic,
10698 .dynstr, .dynsym, and .hash sections, and everything in
10700 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
;
10702 if ((*pm
)->p_type
== PT_DYNAMIC
)
10705 if (m
!= NULL
&& IRIX_COMPAT (abfd
) == ict_none
)
10707 /* For a normal mips executable the permissions for the PT_DYNAMIC
10708 segment are read, write and execute. We do that here since
10709 the code in elf.c sets only the read permission. This matters
10710 sometimes for the dynamic linker. */
10711 if (bfd_get_section_by_name (abfd
, ".dynamic") != NULL
)
10713 m
->p_flags
= PF_R
| PF_W
| PF_X
;
10714 m
->p_flags_valid
= 1;
10717 /* GNU/Linux binaries do not need the extended PT_DYNAMIC section.
10718 glibc's dynamic linker has traditionally derived the number of
10719 tags from the p_filesz field, and sometimes allocates stack
10720 arrays of that size. An overly-big PT_DYNAMIC segment can
10721 be actively harmful in such cases. Making PT_DYNAMIC contain
10722 other sections can also make life hard for the prelinker,
10723 which might move one of the other sections to a different
10724 PT_LOAD segment. */
10725 if (SGI_COMPAT (abfd
)
10728 && strcmp (m
->sections
[0]->name
, ".dynamic") == 0)
10730 static const char *sec_names
[] =
10732 ".dynamic", ".dynstr", ".dynsym", ".hash"
10736 struct elf_segment_map
*n
;
10738 low
= ~(bfd_vma
) 0;
10740 for (i
= 0; i
< sizeof sec_names
/ sizeof sec_names
[0]; i
++)
10742 s
= bfd_get_section_by_name (abfd
, sec_names
[i
]);
10743 if (s
!= NULL
&& (s
->flags
& SEC_LOAD
) != 0)
10750 if (high
< s
->vma
+ sz
)
10751 high
= s
->vma
+ sz
;
10756 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10757 if ((s
->flags
& SEC_LOAD
) != 0
10759 && s
->vma
+ s
->size
<= high
)
10762 amt
= sizeof *n
+ (bfd_size_type
) (c
- 1) * sizeof (asection
*);
10763 n
= bfd_zalloc (abfd
, amt
);
10770 for (s
= abfd
->sections
; s
!= NULL
; s
= s
->next
)
10772 if ((s
->flags
& SEC_LOAD
) != 0
10774 && s
->vma
+ s
->size
<= high
)
10776 n
->sections
[i
] = s
;
10785 /* Allocate a spare program header in dynamic objects so that tools
10786 like the prelinker can add an extra PT_LOAD entry.
10788 If the prelinker needs to make room for a new PT_LOAD entry, its
10789 standard procedure is to move the first (read-only) sections into
10790 the new (writable) segment. However, the MIPS ABI requires
10791 .dynamic to be in a read-only segment, and the section will often
10792 start within sizeof (ElfNN_Phdr) bytes of the last program header.
10794 Although the prelinker could in principle move .dynamic to a
10795 writable segment, it seems better to allocate a spare program
10796 header instead, and avoid the need to move any sections.
10797 There is a long tradition of allocating spare dynamic tags,
10798 so allocating a spare program header seems like a natural
10801 If INFO is NULL, we may be copying an already prelinked binary
10802 with objcopy or strip, so do not add this header. */
10804 && !SGI_COMPAT (abfd
)
10805 && bfd_get_section_by_name (abfd
, ".dynamic"))
10807 for (pm
= &elf_tdata (abfd
)->segment_map
; *pm
!= NULL
; pm
= &(*pm
)->next
)
10808 if ((*pm
)->p_type
== PT_NULL
)
10812 m
= bfd_zalloc (abfd
, sizeof (*m
));
10816 m
->p_type
= PT_NULL
;
10824 /* Return the section that should be marked against GC for a given
10828 _bfd_mips_elf_gc_mark_hook (asection
*sec
,
10829 struct bfd_link_info
*info
,
10830 Elf_Internal_Rela
*rel
,
10831 struct elf_link_hash_entry
*h
,
10832 Elf_Internal_Sym
*sym
)
10834 /* ??? Do mips16 stub sections need to be handled special? */
10837 switch (ELF_R_TYPE (sec
->owner
, rel
->r_info
))
10839 case R_MIPS_GNU_VTINHERIT
:
10840 case R_MIPS_GNU_VTENTRY
:
10844 return _bfd_elf_gc_mark_hook (sec
, info
, rel
, h
, sym
);
10847 /* Update the got entry reference counts for the section being removed. */
10850 _bfd_mips_elf_gc_sweep_hook (bfd
*abfd ATTRIBUTE_UNUSED
,
10851 struct bfd_link_info
*info ATTRIBUTE_UNUSED
,
10852 asection
*sec ATTRIBUTE_UNUSED
,
10853 const Elf_Internal_Rela
*relocs ATTRIBUTE_UNUSED
)
10856 Elf_Internal_Shdr
*symtab_hdr
;
10857 struct elf_link_hash_entry
**sym_hashes
;
10858 bfd_signed_vma
*local_got_refcounts
;
10859 const Elf_Internal_Rela
*rel
, *relend
;
10860 unsigned long r_symndx
;
10861 struct elf_link_hash_entry
*h
;
10863 if (info
->relocatable
)
10866 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
10867 sym_hashes
= elf_sym_hashes (abfd
);
10868 local_got_refcounts
= elf_local_got_refcounts (abfd
);
10870 relend
= relocs
+ sec
->reloc_count
;
10871 for (rel
= relocs
; rel
< relend
; rel
++)
10872 switch (ELF_R_TYPE (abfd
, rel
->r_info
))
10874 case R_MIPS16_GOT16
:
10875 case R_MIPS16_CALL16
:
10877 case R_MIPS_CALL16
:
10878 case R_MIPS_CALL_HI16
:
10879 case R_MIPS_CALL_LO16
:
10880 case R_MIPS_GOT_HI16
:
10881 case R_MIPS_GOT_LO16
:
10882 case R_MIPS_GOT_DISP
:
10883 case R_MIPS_GOT_PAGE
:
10884 case R_MIPS_GOT_OFST
:
10885 /* ??? It would seem that the existing MIPS code does no sort
10886 of reference counting or whatnot on its GOT and PLT entries,
10887 so it is not possible to garbage collect them at this time. */
10898 /* Copy data from a MIPS ELF indirect symbol to its direct symbol,
10899 hiding the old indirect symbol. Process additional relocation
10900 information. Also called for weakdefs, in which case we just let
10901 _bfd_elf_link_hash_copy_indirect copy the flags for us. */
10904 _bfd_mips_elf_copy_indirect_symbol (struct bfd_link_info
*info
,
10905 struct elf_link_hash_entry
*dir
,
10906 struct elf_link_hash_entry
*ind
)
10908 struct mips_elf_link_hash_entry
*dirmips
, *indmips
;
10910 _bfd_elf_link_hash_copy_indirect (info
, dir
, ind
);
10912 dirmips
= (struct mips_elf_link_hash_entry
*) dir
;
10913 indmips
= (struct mips_elf_link_hash_entry
*) ind
;
10914 /* Any absolute non-dynamic relocations against an indirect or weak
10915 definition will be against the target symbol. */
10916 if (indmips
->has_static_relocs
)
10917 dirmips
->has_static_relocs
= TRUE
;
10919 if (ind
->root
.type
!= bfd_link_hash_indirect
)
10922 dirmips
->possibly_dynamic_relocs
+= indmips
->possibly_dynamic_relocs
;
10923 if (indmips
->readonly_reloc
)
10924 dirmips
->readonly_reloc
= TRUE
;
10925 if (indmips
->no_fn_stub
)
10926 dirmips
->no_fn_stub
= TRUE
;
10927 if (indmips
->fn_stub
)
10929 dirmips
->fn_stub
= indmips
->fn_stub
;
10930 indmips
->fn_stub
= NULL
;
10932 if (indmips
->need_fn_stub
)
10934 dirmips
->need_fn_stub
= TRUE
;
10935 indmips
->need_fn_stub
= FALSE
;
10937 if (indmips
->call_stub
)
10939 dirmips
->call_stub
= indmips
->call_stub
;
10940 indmips
->call_stub
= NULL
;
10942 if (indmips
->call_fp_stub
)
10944 dirmips
->call_fp_stub
= indmips
->call_fp_stub
;
10945 indmips
->call_fp_stub
= NULL
;
10947 if (indmips
->global_got_area
< dirmips
->global_got_area
)
10948 dirmips
->global_got_area
= indmips
->global_got_area
;
10949 if (indmips
->global_got_area
< GGA_NONE
)
10950 indmips
->global_got_area
= GGA_NONE
;
10951 if (indmips
->has_nonpic_branches
)
10952 dirmips
->has_nonpic_branches
= TRUE
;
10954 if (dirmips
->tls_type
== 0)
10955 dirmips
->tls_type
= indmips
->tls_type
;
10958 #define PDR_SIZE 32
10961 _bfd_mips_elf_discard_info (bfd
*abfd
, struct elf_reloc_cookie
*cookie
,
10962 struct bfd_link_info
*info
)
10965 bfd_boolean ret
= FALSE
;
10966 unsigned char *tdata
;
10969 o
= bfd_get_section_by_name (abfd
, ".pdr");
10974 if (o
->size
% PDR_SIZE
!= 0)
10976 if (o
->output_section
!= NULL
10977 && bfd_is_abs_section (o
->output_section
))
10980 tdata
= bfd_zmalloc (o
->size
/ PDR_SIZE
);
10984 cookie
->rels
= _bfd_elf_link_read_relocs (abfd
, o
, NULL
, NULL
,
10985 info
->keep_memory
);
10992 cookie
->rel
= cookie
->rels
;
10993 cookie
->relend
= cookie
->rels
+ o
->reloc_count
;
10995 for (i
= 0, skip
= 0; i
< o
->size
/ PDR_SIZE
; i
++)
10997 if (bfd_elf_reloc_symbol_deleted_p (i
* PDR_SIZE
, cookie
))
11006 mips_elf_section_data (o
)->u
.tdata
= tdata
;
11007 o
->size
-= skip
* PDR_SIZE
;
11013 if (! info
->keep_memory
)
11014 free (cookie
->rels
);
11020 _bfd_mips_elf_ignore_discarded_relocs (asection
*sec
)
11022 if (strcmp (sec
->name
, ".pdr") == 0)
11028 _bfd_mips_elf_write_section (bfd
*output_bfd
,
11029 struct bfd_link_info
*link_info ATTRIBUTE_UNUSED
,
11030 asection
*sec
, bfd_byte
*contents
)
11032 bfd_byte
*to
, *from
, *end
;
11035 if (strcmp (sec
->name
, ".pdr") != 0)
11038 if (mips_elf_section_data (sec
)->u
.tdata
== NULL
)
11042 end
= contents
+ sec
->size
;
11043 for (from
= contents
, i
= 0;
11045 from
+= PDR_SIZE
, i
++)
11047 if ((mips_elf_section_data (sec
)->u
.tdata
)[i
] == 1)
11050 memcpy (to
, from
, PDR_SIZE
);
11053 bfd_set_section_contents (output_bfd
, sec
->output_section
, contents
,
11054 sec
->output_offset
, sec
->size
);
11058 /* MIPS ELF uses a special find_nearest_line routine in order the
11059 handle the ECOFF debugging information. */
11061 struct mips_elf_find_line
11063 struct ecoff_debug_info d
;
11064 struct ecoff_find_line i
;
11068 _bfd_mips_elf_find_nearest_line (bfd
*abfd
, asection
*section
,
11069 asymbol
**symbols
, bfd_vma offset
,
11070 const char **filename_ptr
,
11071 const char **functionname_ptr
,
11072 unsigned int *line_ptr
)
11076 if (_bfd_dwarf1_find_nearest_line (abfd
, section
, symbols
, offset
,
11077 filename_ptr
, functionname_ptr
,
11081 if (_bfd_dwarf2_find_nearest_line (abfd
, section
, symbols
, offset
,
11082 filename_ptr
, functionname_ptr
,
11083 line_ptr
, ABI_64_P (abfd
) ? 8 : 0,
11084 &elf_tdata (abfd
)->dwarf2_find_line_info
))
11087 msec
= bfd_get_section_by_name (abfd
, ".mdebug");
11090 flagword origflags
;
11091 struct mips_elf_find_line
*fi
;
11092 const struct ecoff_debug_swap
* const swap
=
11093 get_elf_backend_data (abfd
)->elf_backend_ecoff_debug_swap
;
11095 /* If we are called during a link, mips_elf_final_link may have
11096 cleared the SEC_HAS_CONTENTS field. We force it back on here
11097 if appropriate (which it normally will be). */
11098 origflags
= msec
->flags
;
11099 if (elf_section_data (msec
)->this_hdr
.sh_type
!= SHT_NOBITS
)
11100 msec
->flags
|= SEC_HAS_CONTENTS
;
11102 fi
= elf_tdata (abfd
)->find_line_info
;
11105 bfd_size_type external_fdr_size
;
11108 struct fdr
*fdr_ptr
;
11109 bfd_size_type amt
= sizeof (struct mips_elf_find_line
);
11111 fi
= bfd_zalloc (abfd
, amt
);
11114 msec
->flags
= origflags
;
11118 if (! _bfd_mips_elf_read_ecoff_info (abfd
, msec
, &fi
->d
))
11120 msec
->flags
= origflags
;
11124 /* Swap in the FDR information. */
11125 amt
= fi
->d
.symbolic_header
.ifdMax
* sizeof (struct fdr
);
11126 fi
->d
.fdr
= bfd_alloc (abfd
, amt
);
11127 if (fi
->d
.fdr
== NULL
)
11129 msec
->flags
= origflags
;
11132 external_fdr_size
= swap
->external_fdr_size
;
11133 fdr_ptr
= fi
->d
.fdr
;
11134 fraw_src
= (char *) fi
->d
.external_fdr
;
11135 fraw_end
= (fraw_src
11136 + fi
->d
.symbolic_header
.ifdMax
* external_fdr_size
);
11137 for (; fraw_src
< fraw_end
; fraw_src
+= external_fdr_size
, fdr_ptr
++)
11138 (*swap
->swap_fdr_in
) (abfd
, fraw_src
, fdr_ptr
);
11140 elf_tdata (abfd
)->find_line_info
= fi
;
11142 /* Note that we don't bother to ever free this information.
11143 find_nearest_line is either called all the time, as in
11144 objdump -l, so the information should be saved, or it is
11145 rarely called, as in ld error messages, so the memory
11146 wasted is unimportant. Still, it would probably be a
11147 good idea for free_cached_info to throw it away. */
11150 if (_bfd_ecoff_locate_line (abfd
, section
, offset
, &fi
->d
, swap
,
11151 &fi
->i
, filename_ptr
, functionname_ptr
,
11154 msec
->flags
= origflags
;
11158 msec
->flags
= origflags
;
11161 /* Fall back on the generic ELF find_nearest_line routine. */
11163 return _bfd_elf_find_nearest_line (abfd
, section
, symbols
, offset
,
11164 filename_ptr
, functionname_ptr
,
11169 _bfd_mips_elf_find_inliner_info (bfd
*abfd
,
11170 const char **filename_ptr
,
11171 const char **functionname_ptr
,
11172 unsigned int *line_ptr
)
11175 found
= _bfd_dwarf2_find_inliner_info (abfd
, filename_ptr
,
11176 functionname_ptr
, line_ptr
,
11177 & elf_tdata (abfd
)->dwarf2_find_line_info
);
11182 /* When are writing out the .options or .MIPS.options section,
11183 remember the bytes we are writing out, so that we can install the
11184 GP value in the section_processing routine. */
11187 _bfd_mips_elf_set_section_contents (bfd
*abfd
, sec_ptr section
,
11188 const void *location
,
11189 file_ptr offset
, bfd_size_type count
)
11191 if (MIPS_ELF_OPTIONS_SECTION_NAME_P (section
->name
))
11195 if (elf_section_data (section
) == NULL
)
11197 bfd_size_type amt
= sizeof (struct bfd_elf_section_data
);
11198 section
->used_by_bfd
= bfd_zalloc (abfd
, amt
);
11199 if (elf_section_data (section
) == NULL
)
11202 c
= mips_elf_section_data (section
)->u
.tdata
;
11205 c
= bfd_zalloc (abfd
, section
->size
);
11208 mips_elf_section_data (section
)->u
.tdata
= c
;
11211 memcpy (c
+ offset
, location
, count
);
11214 return _bfd_elf_set_section_contents (abfd
, section
, location
, offset
,
11218 /* This is almost identical to bfd_generic_get_... except that some
11219 MIPS relocations need to be handled specially. Sigh. */
11222 _bfd_elf_mips_get_relocated_section_contents
11224 struct bfd_link_info
*link_info
,
11225 struct bfd_link_order
*link_order
,
11227 bfd_boolean relocatable
,
11230 /* Get enough memory to hold the stuff */
11231 bfd
*input_bfd
= link_order
->u
.indirect
.section
->owner
;
11232 asection
*input_section
= link_order
->u
.indirect
.section
;
11235 long reloc_size
= bfd_get_reloc_upper_bound (input_bfd
, input_section
);
11236 arelent
**reloc_vector
= NULL
;
11239 if (reloc_size
< 0)
11242 reloc_vector
= bfd_malloc (reloc_size
);
11243 if (reloc_vector
== NULL
&& reloc_size
!= 0)
11246 /* read in the section */
11247 sz
= input_section
->rawsize
? input_section
->rawsize
: input_section
->size
;
11248 if (!bfd_get_section_contents (input_bfd
, input_section
, data
, 0, sz
))
11251 reloc_count
= bfd_canonicalize_reloc (input_bfd
,
11255 if (reloc_count
< 0)
11258 if (reloc_count
> 0)
11263 bfd_vma gp
= 0x12345678; /* initialize just to shut gcc up */
11266 struct bfd_hash_entry
*h
;
11267 struct bfd_link_hash_entry
*lh
;
11268 /* Skip all this stuff if we aren't mixing formats. */
11269 if (abfd
&& input_bfd
11270 && abfd
->xvec
== input_bfd
->xvec
)
11274 h
= bfd_hash_lookup (&link_info
->hash
->table
, "_gp", FALSE
, FALSE
);
11275 lh
= (struct bfd_link_hash_entry
*) h
;
11282 case bfd_link_hash_undefined
:
11283 case bfd_link_hash_undefweak
:
11284 case bfd_link_hash_common
:
11287 case bfd_link_hash_defined
:
11288 case bfd_link_hash_defweak
:
11290 gp
= lh
->u
.def
.value
;
11292 case bfd_link_hash_indirect
:
11293 case bfd_link_hash_warning
:
11295 /* @@FIXME ignoring warning for now */
11297 case bfd_link_hash_new
:
11306 for (parent
= reloc_vector
; *parent
!= NULL
; parent
++)
11308 char *error_message
= NULL
;
11309 bfd_reloc_status_type r
;
11311 /* Specific to MIPS: Deal with relocation types that require
11312 knowing the gp of the output bfd. */
11313 asymbol
*sym
= *(*parent
)->sym_ptr_ptr
;
11315 /* If we've managed to find the gp and have a special
11316 function for the relocation then go ahead, else default
11317 to the generic handling. */
11319 && (*parent
)->howto
->special_function
11320 == _bfd_mips_elf32_gprel16_reloc
)
11321 r
= _bfd_mips_elf_gprel16_with_gp (input_bfd
, sym
, *parent
,
11322 input_section
, relocatable
,
11325 r
= bfd_perform_relocation (input_bfd
, *parent
, data
,
11327 relocatable
? abfd
: NULL
,
11332 asection
*os
= input_section
->output_section
;
11334 /* A partial link, so keep the relocs */
11335 os
->orelocation
[os
->reloc_count
] = *parent
;
11339 if (r
!= bfd_reloc_ok
)
11343 case bfd_reloc_undefined
:
11344 if (!((*link_info
->callbacks
->undefined_symbol
)
11345 (link_info
, bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
11346 input_bfd
, input_section
, (*parent
)->address
, TRUE
)))
11349 case bfd_reloc_dangerous
:
11350 BFD_ASSERT (error_message
!= NULL
);
11351 if (!((*link_info
->callbacks
->reloc_dangerous
)
11352 (link_info
, error_message
, input_bfd
, input_section
,
11353 (*parent
)->address
)))
11356 case bfd_reloc_overflow
:
11357 if (!((*link_info
->callbacks
->reloc_overflow
)
11359 bfd_asymbol_name (*(*parent
)->sym_ptr_ptr
),
11360 (*parent
)->howto
->name
, (*parent
)->addend
,
11361 input_bfd
, input_section
, (*parent
)->address
)))
11364 case bfd_reloc_outofrange
:
11373 if (reloc_vector
!= NULL
)
11374 free (reloc_vector
);
11378 if (reloc_vector
!= NULL
)
11379 free (reloc_vector
);
11383 /* Allocate ABFD's target-dependent data. */
11386 _bfd_mips_elf_mkobject (bfd
*abfd
)
11388 return bfd_elf_allocate_object (abfd
, sizeof (struct elf_obj_tdata
),
11392 /* Create a MIPS ELF linker hash table. */
11394 struct bfd_link_hash_table
*
11395 _bfd_mips_elf_link_hash_table_create (bfd
*abfd
)
11397 struct mips_elf_link_hash_table
*ret
;
11398 bfd_size_type amt
= sizeof (struct mips_elf_link_hash_table
);
11400 ret
= bfd_malloc (amt
);
11404 if (!_bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
11405 mips_elf_link_hash_newfunc
,
11406 sizeof (struct mips_elf_link_hash_entry
)))
11413 /* We no longer use this. */
11414 for (i
= 0; i
< SIZEOF_MIPS_DYNSYM_SECNAMES
; i
++)
11415 ret
->dynsym_sec_strindex
[i
] = (bfd_size_type
) -1;
11417 ret
->procedure_count
= 0;
11418 ret
->compact_rel_size
= 0;
11419 ret
->use_rld_obj_head
= FALSE
;
11420 ret
->rld_value
= 0;
11421 ret
->mips16_stubs_seen
= FALSE
;
11422 ret
->use_plts_and_copy_relocs
= FALSE
;
11423 ret
->is_vxworks
= FALSE
;
11424 ret
->small_data_overflow_reported
= FALSE
;
11425 ret
->srelbss
= NULL
;
11426 ret
->sdynbss
= NULL
;
11427 ret
->srelplt
= NULL
;
11428 ret
->srelplt2
= NULL
;
11429 ret
->sgotplt
= NULL
;
11431 ret
->sstubs
= NULL
;
11433 ret
->got_info
= NULL
;
11434 ret
->plt_header_size
= 0;
11435 ret
->plt_entry_size
= 0;
11436 ret
->lazy_stub_count
= 0;
11437 ret
->function_stub_size
= 0;
11438 ret
->strampoline
= NULL
;
11439 ret
->la25_stubs
= NULL
;
11440 ret
->add_stub_section
= NULL
;
11442 return &ret
->root
.root
;
11445 /* Likewise, but indicate that the target is VxWorks. */
11447 struct bfd_link_hash_table
*
11448 _bfd_mips_vxworks_link_hash_table_create (bfd
*abfd
)
11450 struct bfd_link_hash_table
*ret
;
11452 ret
= _bfd_mips_elf_link_hash_table_create (abfd
);
11455 struct mips_elf_link_hash_table
*htab
;
11457 htab
= (struct mips_elf_link_hash_table
*) ret
;
11458 htab
->use_plts_and_copy_relocs
= TRUE
;
11459 htab
->is_vxworks
= TRUE
;
11464 /* A function that the linker calls if we are allowed to use PLTs
11465 and copy relocs. */
11468 _bfd_mips_elf_use_plts_and_copy_relocs (struct bfd_link_info
*info
)
11470 mips_elf_hash_table (info
)->use_plts_and_copy_relocs
= TRUE
;
11473 /* We need to use a special link routine to handle the .reginfo and
11474 the .mdebug sections. We need to merge all instances of these
11475 sections together, not write them all out sequentially. */
11478 _bfd_mips_elf_final_link (bfd
*abfd
, struct bfd_link_info
*info
)
11481 struct bfd_link_order
*p
;
11482 asection
*reginfo_sec
, *mdebug_sec
, *gptab_data_sec
, *gptab_bss_sec
;
11483 asection
*rtproc_sec
;
11484 Elf32_RegInfo reginfo
;
11485 struct ecoff_debug_info debug
;
11486 struct mips_htab_traverse_info hti
;
11487 const struct elf_backend_data
*bed
= get_elf_backend_data (abfd
);
11488 const struct ecoff_debug_swap
*swap
= bed
->elf_backend_ecoff_debug_swap
;
11489 HDRR
*symhdr
= &debug
.symbolic_header
;
11490 void *mdebug_handle
= NULL
;
11495 struct mips_elf_link_hash_table
*htab
;
11497 static const char * const secname
[] =
11499 ".text", ".init", ".fini", ".data",
11500 ".rodata", ".sdata", ".sbss", ".bss"
11502 static const int sc
[] =
11504 scText
, scInit
, scFini
, scData
,
11505 scRData
, scSData
, scSBss
, scBss
11508 /* Sort the dynamic symbols so that those with GOT entries come after
11510 htab
= mips_elf_hash_table (info
);
11511 if (!mips_elf_sort_hash_table (abfd
, info
))
11514 /* Create any scheduled LA25 stubs. */
11516 hti
.output_bfd
= abfd
;
11518 htab_traverse (htab
->la25_stubs
, mips_elf_create_la25_stub
, &hti
);
11522 /* Get a value for the GP register. */
11523 if (elf_gp (abfd
) == 0)
11525 struct bfd_link_hash_entry
*h
;
11527 h
= bfd_link_hash_lookup (info
->hash
, "_gp", FALSE
, FALSE
, TRUE
);
11528 if (h
!= NULL
&& h
->type
== bfd_link_hash_defined
)
11529 elf_gp (abfd
) = (h
->u
.def
.value
11530 + h
->u
.def
.section
->output_section
->vma
11531 + h
->u
.def
.section
->output_offset
);
11532 else if (htab
->is_vxworks
11533 && (h
= bfd_link_hash_lookup (info
->hash
,
11534 "_GLOBAL_OFFSET_TABLE_",
11535 FALSE
, FALSE
, TRUE
))
11536 && h
->type
== bfd_link_hash_defined
)
11537 elf_gp (abfd
) = (h
->u
.def
.section
->output_section
->vma
11538 + h
->u
.def
.section
->output_offset
11540 else if (info
->relocatable
)
11542 bfd_vma lo
= MINUS_ONE
;
11544 /* Find the GP-relative section with the lowest offset. */
11545 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
11547 && (elf_section_data (o
)->this_hdr
.sh_flags
& SHF_MIPS_GPREL
))
11550 /* And calculate GP relative to that. */
11551 elf_gp (abfd
) = lo
+ ELF_MIPS_GP_OFFSET (info
);
11555 /* If the relocate_section function needs to do a reloc
11556 involving the GP value, it should make a reloc_dangerous
11557 callback to warn that GP is not defined. */
11561 /* Go through the sections and collect the .reginfo and .mdebug
11563 reginfo_sec
= NULL
;
11565 gptab_data_sec
= NULL
;
11566 gptab_bss_sec
= NULL
;
11567 for (o
= abfd
->sections
; o
!= NULL
; o
= o
->next
)
11569 if (strcmp (o
->name
, ".reginfo") == 0)
11571 memset (®info
, 0, sizeof reginfo
);
11573 /* We have found the .reginfo section in the output file.
11574 Look through all the link_orders comprising it and merge
11575 the information together. */
11576 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11578 asection
*input_section
;
11580 Elf32_External_RegInfo ext
;
11583 if (p
->type
!= bfd_indirect_link_order
)
11585 if (p
->type
== bfd_data_link_order
)
11590 input_section
= p
->u
.indirect
.section
;
11591 input_bfd
= input_section
->owner
;
11593 if (! bfd_get_section_contents (input_bfd
, input_section
,
11594 &ext
, 0, sizeof ext
))
11597 bfd_mips_elf32_swap_reginfo_in (input_bfd
, &ext
, &sub
);
11599 reginfo
.ri_gprmask
|= sub
.ri_gprmask
;
11600 reginfo
.ri_cprmask
[0] |= sub
.ri_cprmask
[0];
11601 reginfo
.ri_cprmask
[1] |= sub
.ri_cprmask
[1];
11602 reginfo
.ri_cprmask
[2] |= sub
.ri_cprmask
[2];
11603 reginfo
.ri_cprmask
[3] |= sub
.ri_cprmask
[3];
11605 /* ri_gp_value is set by the function
11606 mips_elf32_section_processing when the section is
11607 finally written out. */
11609 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11610 elf_link_input_bfd ignores this section. */
11611 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11614 /* Size has been set in _bfd_mips_elf_always_size_sections. */
11615 BFD_ASSERT(o
->size
== sizeof (Elf32_External_RegInfo
));
11617 /* Skip this section later on (I don't think this currently
11618 matters, but someday it might). */
11619 o
->map_head
.link_order
= NULL
;
11624 if (strcmp (o
->name
, ".mdebug") == 0)
11626 struct extsym_info einfo
;
11629 /* We have found the .mdebug section in the output file.
11630 Look through all the link_orders comprising it and merge
11631 the information together. */
11632 symhdr
->magic
= swap
->sym_magic
;
11633 /* FIXME: What should the version stamp be? */
11634 symhdr
->vstamp
= 0;
11635 symhdr
->ilineMax
= 0;
11636 symhdr
->cbLine
= 0;
11637 symhdr
->idnMax
= 0;
11638 symhdr
->ipdMax
= 0;
11639 symhdr
->isymMax
= 0;
11640 symhdr
->ioptMax
= 0;
11641 symhdr
->iauxMax
= 0;
11642 symhdr
->issMax
= 0;
11643 symhdr
->issExtMax
= 0;
11644 symhdr
->ifdMax
= 0;
11646 symhdr
->iextMax
= 0;
11648 /* We accumulate the debugging information itself in the
11649 debug_info structure. */
11651 debug
.external_dnr
= NULL
;
11652 debug
.external_pdr
= NULL
;
11653 debug
.external_sym
= NULL
;
11654 debug
.external_opt
= NULL
;
11655 debug
.external_aux
= NULL
;
11657 debug
.ssext
= debug
.ssext_end
= NULL
;
11658 debug
.external_fdr
= NULL
;
11659 debug
.external_rfd
= NULL
;
11660 debug
.external_ext
= debug
.external_ext_end
= NULL
;
11662 mdebug_handle
= bfd_ecoff_debug_init (abfd
, &debug
, swap
, info
);
11663 if (mdebug_handle
== NULL
)
11667 esym
.cobol_main
= 0;
11671 esym
.asym
.iss
= issNil
;
11672 esym
.asym
.st
= stLocal
;
11673 esym
.asym
.reserved
= 0;
11674 esym
.asym
.index
= indexNil
;
11676 for (i
= 0; i
< sizeof (secname
) / sizeof (secname
[0]); i
++)
11678 esym
.asym
.sc
= sc
[i
];
11679 s
= bfd_get_section_by_name (abfd
, secname
[i
]);
11682 esym
.asym
.value
= s
->vma
;
11683 last
= s
->vma
+ s
->size
;
11686 esym
.asym
.value
= last
;
11687 if (!bfd_ecoff_debug_one_external (abfd
, &debug
, swap
,
11688 secname
[i
], &esym
))
11692 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11694 asection
*input_section
;
11696 const struct ecoff_debug_swap
*input_swap
;
11697 struct ecoff_debug_info input_debug
;
11701 if (p
->type
!= bfd_indirect_link_order
)
11703 if (p
->type
== bfd_data_link_order
)
11708 input_section
= p
->u
.indirect
.section
;
11709 input_bfd
= input_section
->owner
;
11711 if (!is_mips_elf (input_bfd
))
11713 /* I don't know what a non MIPS ELF bfd would be
11714 doing with a .mdebug section, but I don't really
11715 want to deal with it. */
11719 input_swap
= (get_elf_backend_data (input_bfd
)
11720 ->elf_backend_ecoff_debug_swap
);
11722 BFD_ASSERT (p
->size
== input_section
->size
);
11724 /* The ECOFF linking code expects that we have already
11725 read in the debugging information and set up an
11726 ecoff_debug_info structure, so we do that now. */
11727 if (! _bfd_mips_elf_read_ecoff_info (input_bfd
, input_section
,
11731 if (! (bfd_ecoff_debug_accumulate
11732 (mdebug_handle
, abfd
, &debug
, swap
, input_bfd
,
11733 &input_debug
, input_swap
, info
)))
11736 /* Loop through the external symbols. For each one with
11737 interesting information, try to find the symbol in
11738 the linker global hash table and save the information
11739 for the output external symbols. */
11740 eraw_src
= input_debug
.external_ext
;
11741 eraw_end
= (eraw_src
11742 + (input_debug
.symbolic_header
.iextMax
11743 * input_swap
->external_ext_size
));
11745 eraw_src
< eraw_end
;
11746 eraw_src
+= input_swap
->external_ext_size
)
11750 struct mips_elf_link_hash_entry
*h
;
11752 (*input_swap
->swap_ext_in
) (input_bfd
, eraw_src
, &ext
);
11753 if (ext
.asym
.sc
== scNil
11754 || ext
.asym
.sc
== scUndefined
11755 || ext
.asym
.sc
== scSUndefined
)
11758 name
= input_debug
.ssext
+ ext
.asym
.iss
;
11759 h
= mips_elf_link_hash_lookup (mips_elf_hash_table (info
),
11760 name
, FALSE
, FALSE
, TRUE
);
11761 if (h
== NULL
|| h
->esym
.ifd
!= -2)
11766 BFD_ASSERT (ext
.ifd
11767 < input_debug
.symbolic_header
.ifdMax
);
11768 ext
.ifd
= input_debug
.ifdmap
[ext
.ifd
];
11774 /* Free up the information we just read. */
11775 free (input_debug
.line
);
11776 free (input_debug
.external_dnr
);
11777 free (input_debug
.external_pdr
);
11778 free (input_debug
.external_sym
);
11779 free (input_debug
.external_opt
);
11780 free (input_debug
.external_aux
);
11781 free (input_debug
.ss
);
11782 free (input_debug
.ssext
);
11783 free (input_debug
.external_fdr
);
11784 free (input_debug
.external_rfd
);
11785 free (input_debug
.external_ext
);
11787 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11788 elf_link_input_bfd ignores this section. */
11789 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11792 if (SGI_COMPAT (abfd
) && info
->shared
)
11794 /* Create .rtproc section. */
11795 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
11796 if (rtproc_sec
== NULL
)
11798 flagword flags
= (SEC_HAS_CONTENTS
| SEC_IN_MEMORY
11799 | SEC_LINKER_CREATED
| SEC_READONLY
);
11801 rtproc_sec
= bfd_make_section_with_flags (abfd
,
11804 if (rtproc_sec
== NULL
11805 || ! bfd_set_section_alignment (abfd
, rtproc_sec
, 4))
11809 if (! mips_elf_create_procedure_table (mdebug_handle
, abfd
,
11815 /* Build the external symbol information. */
11818 einfo
.debug
= &debug
;
11820 einfo
.failed
= FALSE
;
11821 mips_elf_link_hash_traverse (mips_elf_hash_table (info
),
11822 mips_elf_output_extsym
, &einfo
);
11826 /* Set the size of the .mdebug section. */
11827 o
->size
= bfd_ecoff_debug_size (abfd
, &debug
, swap
);
11829 /* Skip this section later on (I don't think this currently
11830 matters, but someday it might). */
11831 o
->map_head
.link_order
= NULL
;
11836 if (CONST_STRNEQ (o
->name
, ".gptab."))
11838 const char *subname
;
11841 Elf32_External_gptab
*ext_tab
;
11844 /* The .gptab.sdata and .gptab.sbss sections hold
11845 information describing how the small data area would
11846 change depending upon the -G switch. These sections
11847 not used in executables files. */
11848 if (! info
->relocatable
)
11850 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11852 asection
*input_section
;
11854 if (p
->type
!= bfd_indirect_link_order
)
11856 if (p
->type
== bfd_data_link_order
)
11861 input_section
= p
->u
.indirect
.section
;
11863 /* Hack: reset the SEC_HAS_CONTENTS flag so that
11864 elf_link_input_bfd ignores this section. */
11865 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
11868 /* Skip this section later on (I don't think this
11869 currently matters, but someday it might). */
11870 o
->map_head
.link_order
= NULL
;
11872 /* Really remove the section. */
11873 bfd_section_list_remove (abfd
, o
);
11874 --abfd
->section_count
;
11879 /* There is one gptab for initialized data, and one for
11880 uninitialized data. */
11881 if (strcmp (o
->name
, ".gptab.sdata") == 0)
11882 gptab_data_sec
= o
;
11883 else if (strcmp (o
->name
, ".gptab.sbss") == 0)
11887 (*_bfd_error_handler
)
11888 (_("%s: illegal section name `%s'"),
11889 bfd_get_filename (abfd
), o
->name
);
11890 bfd_set_error (bfd_error_nonrepresentable_section
);
11894 /* The linker script always combines .gptab.data and
11895 .gptab.sdata into .gptab.sdata, and likewise for
11896 .gptab.bss and .gptab.sbss. It is possible that there is
11897 no .sdata or .sbss section in the output file, in which
11898 case we must change the name of the output section. */
11899 subname
= o
->name
+ sizeof ".gptab" - 1;
11900 if (bfd_get_section_by_name (abfd
, subname
) == NULL
)
11902 if (o
== gptab_data_sec
)
11903 o
->name
= ".gptab.data";
11905 o
->name
= ".gptab.bss";
11906 subname
= o
->name
+ sizeof ".gptab" - 1;
11907 BFD_ASSERT (bfd_get_section_by_name (abfd
, subname
) != NULL
);
11910 /* Set up the first entry. */
11912 amt
= c
* sizeof (Elf32_gptab
);
11913 tab
= bfd_malloc (amt
);
11916 tab
[0].gt_header
.gt_current_g_value
= elf_gp_size (abfd
);
11917 tab
[0].gt_header
.gt_unused
= 0;
11919 /* Combine the input sections. */
11920 for (p
= o
->map_head
.link_order
; p
!= NULL
; p
= p
->next
)
11922 asection
*input_section
;
11924 bfd_size_type size
;
11925 unsigned long last
;
11926 bfd_size_type gpentry
;
11928 if (p
->type
!= bfd_indirect_link_order
)
11930 if (p
->type
== bfd_data_link_order
)
11935 input_section
= p
->u
.indirect
.section
;
11936 input_bfd
= input_section
->owner
;
11938 /* Combine the gptab entries for this input section one
11939 by one. We know that the input gptab entries are
11940 sorted by ascending -G value. */
11941 size
= input_section
->size
;
11943 for (gpentry
= sizeof (Elf32_External_gptab
);
11945 gpentry
+= sizeof (Elf32_External_gptab
))
11947 Elf32_External_gptab ext_gptab
;
11948 Elf32_gptab int_gptab
;
11954 if (! (bfd_get_section_contents
11955 (input_bfd
, input_section
, &ext_gptab
, gpentry
,
11956 sizeof (Elf32_External_gptab
))))
11962 bfd_mips_elf32_swap_gptab_in (input_bfd
, &ext_gptab
,
11964 val
= int_gptab
.gt_entry
.gt_g_value
;
11965 add
= int_gptab
.gt_entry
.gt_bytes
- last
;
11968 for (look
= 1; look
< c
; look
++)
11970 if (tab
[look
].gt_entry
.gt_g_value
>= val
)
11971 tab
[look
].gt_entry
.gt_bytes
+= add
;
11973 if (tab
[look
].gt_entry
.gt_g_value
== val
)
11979 Elf32_gptab
*new_tab
;
11982 /* We need a new table entry. */
11983 amt
= (bfd_size_type
) (c
+ 1) * sizeof (Elf32_gptab
);
11984 new_tab
= bfd_realloc (tab
, amt
);
11985 if (new_tab
== NULL
)
11991 tab
[c
].gt_entry
.gt_g_value
= val
;
11992 tab
[c
].gt_entry
.gt_bytes
= add
;
11994 /* Merge in the size for the next smallest -G
11995 value, since that will be implied by this new
11998 for (look
= 1; look
< c
; look
++)
12000 if (tab
[look
].gt_entry
.gt_g_value
< val
12002 || (tab
[look
].gt_entry
.gt_g_value
12003 > tab
[max
].gt_entry
.gt_g_value
)))
12007 tab
[c
].gt_entry
.gt_bytes
+=
12008 tab
[max
].gt_entry
.gt_bytes
;
12013 last
= int_gptab
.gt_entry
.gt_bytes
;
12016 /* Hack: reset the SEC_HAS_CONTENTS flag so that
12017 elf_link_input_bfd ignores this section. */
12018 input_section
->flags
&= ~SEC_HAS_CONTENTS
;
12021 /* The table must be sorted by -G value. */
12023 qsort (tab
+ 1, c
- 1, sizeof (tab
[0]), gptab_compare
);
12025 /* Swap out the table. */
12026 amt
= (bfd_size_type
) c
* sizeof (Elf32_External_gptab
);
12027 ext_tab
= bfd_alloc (abfd
, amt
);
12028 if (ext_tab
== NULL
)
12034 for (j
= 0; j
< c
; j
++)
12035 bfd_mips_elf32_swap_gptab_out (abfd
, tab
+ j
, ext_tab
+ j
);
12038 o
->size
= c
* sizeof (Elf32_External_gptab
);
12039 o
->contents
= (bfd_byte
*) ext_tab
;
12041 /* Skip this section later on (I don't think this currently
12042 matters, but someday it might). */
12043 o
->map_head
.link_order
= NULL
;
12047 /* Invoke the regular ELF backend linker to do all the work. */
12048 if (!bfd_elf_final_link (abfd
, info
))
12051 /* Now write out the computed sections. */
12053 if (reginfo_sec
!= NULL
)
12055 Elf32_External_RegInfo ext
;
12057 bfd_mips_elf32_swap_reginfo_out (abfd
, ®info
, &ext
);
12058 if (! bfd_set_section_contents (abfd
, reginfo_sec
, &ext
, 0, sizeof ext
))
12062 if (mdebug_sec
!= NULL
)
12064 BFD_ASSERT (abfd
->output_has_begun
);
12065 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle
, abfd
, &debug
,
12067 mdebug_sec
->filepos
))
12070 bfd_ecoff_debug_free (mdebug_handle
, abfd
, &debug
, swap
, info
);
12073 if (gptab_data_sec
!= NULL
)
12075 if (! bfd_set_section_contents (abfd
, gptab_data_sec
,
12076 gptab_data_sec
->contents
,
12077 0, gptab_data_sec
->size
))
12081 if (gptab_bss_sec
!= NULL
)
12083 if (! bfd_set_section_contents (abfd
, gptab_bss_sec
,
12084 gptab_bss_sec
->contents
,
12085 0, gptab_bss_sec
->size
))
12089 if (SGI_COMPAT (abfd
))
12091 rtproc_sec
= bfd_get_section_by_name (abfd
, ".rtproc");
12092 if (rtproc_sec
!= NULL
)
12094 if (! bfd_set_section_contents (abfd
, rtproc_sec
,
12095 rtproc_sec
->contents
,
12096 0, rtproc_sec
->size
))
12104 /* Structure for saying that BFD machine EXTENSION extends BASE. */
12106 struct mips_mach_extension
{
12107 unsigned long extension
, base
;
12111 /* An array describing how BFD machines relate to one another. The entries
12112 are ordered topologically with MIPS I extensions listed last. */
12114 static const struct mips_mach_extension mips_mach_extensions
[] = {
12115 /* MIPS64r2 extensions. */
12116 { bfd_mach_mips_octeon
, bfd_mach_mipsisa64r2
},
12118 /* MIPS64 extensions. */
12119 { bfd_mach_mipsisa64r2
, bfd_mach_mipsisa64
},
12120 { bfd_mach_mips_sb1
, bfd_mach_mipsisa64
},
12122 /* MIPS V extensions. */
12123 { bfd_mach_mipsisa64
, bfd_mach_mips5
},
12125 /* R10000 extensions. */
12126 { bfd_mach_mips12000
, bfd_mach_mips10000
},
12128 /* R5000 extensions. Note: the vr5500 ISA is an extension of the core
12129 vr5400 ISA, but doesn't include the multimedia stuff. It seems
12130 better to allow vr5400 and vr5500 code to be merged anyway, since
12131 many libraries will just use the core ISA. Perhaps we could add
12132 some sort of ASE flag if this ever proves a problem. */
12133 { bfd_mach_mips5500
, bfd_mach_mips5400
},
12134 { bfd_mach_mips5400
, bfd_mach_mips5000
},
12136 /* MIPS IV extensions. */
12137 { bfd_mach_mips5
, bfd_mach_mips8000
},
12138 { bfd_mach_mips10000
, bfd_mach_mips8000
},
12139 { bfd_mach_mips5000
, bfd_mach_mips8000
},
12140 { bfd_mach_mips7000
, bfd_mach_mips8000
},
12141 { bfd_mach_mips9000
, bfd_mach_mips8000
},
12143 /* VR4100 extensions. */
12144 { bfd_mach_mips4120
, bfd_mach_mips4100
},
12145 { bfd_mach_mips4111
, bfd_mach_mips4100
},
12147 /* MIPS III extensions. */
12148 { bfd_mach_mips_loongson_2e
, bfd_mach_mips4000
},
12149 { bfd_mach_mips_loongson_2f
, bfd_mach_mips4000
},
12150 { bfd_mach_mips8000
, bfd_mach_mips4000
},
12151 { bfd_mach_mips4650
, bfd_mach_mips4000
},
12152 { bfd_mach_mips4600
, bfd_mach_mips4000
},
12153 { bfd_mach_mips4400
, bfd_mach_mips4000
},
12154 { bfd_mach_mips4300
, bfd_mach_mips4000
},
12155 { bfd_mach_mips4100
, bfd_mach_mips4000
},
12156 { bfd_mach_mips4010
, bfd_mach_mips4000
},
12158 /* MIPS32 extensions. */
12159 { bfd_mach_mipsisa32r2
, bfd_mach_mipsisa32
},
12161 /* MIPS II extensions. */
12162 { bfd_mach_mips4000
, bfd_mach_mips6000
},
12163 { bfd_mach_mipsisa32
, bfd_mach_mips6000
},
12165 /* MIPS I extensions. */
12166 { bfd_mach_mips6000
, bfd_mach_mips3000
},
12167 { bfd_mach_mips3900
, bfd_mach_mips3000
}
12171 /* Return true if bfd machine EXTENSION is an extension of machine BASE. */
12174 mips_mach_extends_p (unsigned long base
, unsigned long extension
)
12178 if (extension
== base
)
12181 if (base
== bfd_mach_mipsisa32
12182 && mips_mach_extends_p (bfd_mach_mipsisa64
, extension
))
12185 if (base
== bfd_mach_mipsisa32r2
12186 && mips_mach_extends_p (bfd_mach_mipsisa64r2
, extension
))
12189 for (i
= 0; i
< ARRAY_SIZE (mips_mach_extensions
); i
++)
12190 if (extension
== mips_mach_extensions
[i
].extension
)
12192 extension
= mips_mach_extensions
[i
].base
;
12193 if (extension
== base
)
12201 /* Return true if the given ELF header flags describe a 32-bit binary. */
12204 mips_32bit_flags_p (flagword flags
)
12206 return ((flags
& EF_MIPS_32BITMODE
) != 0
12207 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
12208 || (flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
12209 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
12210 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
12211 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
12212 || (flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
);
12216 /* Merge object attributes from IBFD into OBFD. Raise an error if
12217 there are conflicting attributes. */
12219 mips_elf_merge_obj_attributes (bfd
*ibfd
, bfd
*obfd
)
12221 obj_attribute
*in_attr
;
12222 obj_attribute
*out_attr
;
12224 if (!elf_known_obj_attributes_proc (obfd
)[0].i
)
12226 /* This is the first object. Copy the attributes. */
12227 _bfd_elf_copy_obj_attributes (ibfd
, obfd
);
12229 /* Use the Tag_null value to indicate the attributes have been
12231 elf_known_obj_attributes_proc (obfd
)[0].i
= 1;
12236 /* Check for conflicting Tag_GNU_MIPS_ABI_FP attributes and merge
12237 non-conflicting ones. */
12238 in_attr
= elf_known_obj_attributes (ibfd
)[OBJ_ATTR_GNU
];
12239 out_attr
= elf_known_obj_attributes (obfd
)[OBJ_ATTR_GNU
];
12240 if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
!= out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12242 out_attr
[Tag_GNU_MIPS_ABI_FP
].type
= 1;
12243 if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
12244 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
= in_attr
[Tag_GNU_MIPS_ABI_FP
].i
;
12245 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
== 0)
12247 else if (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
12249 (_("Warning: %B uses unknown floating point ABI %d"), ibfd
,
12250 in_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
12251 else if (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
> 4)
12253 (_("Warning: %B uses unknown floating point ABI %d"), obfd
,
12254 out_attr
[Tag_GNU_MIPS_ABI_FP
].i
);
12256 switch (out_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12259 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12263 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
12269 (_("Warning: %B uses hard float, %B uses soft float"),
12275 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
12285 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12289 (_("Warning: %B uses -msingle-float, %B uses -mdouble-float"),
12295 (_("Warning: %B uses hard float, %B uses soft float"),
12301 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
12311 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12317 (_("Warning: %B uses hard float, %B uses soft float"),
12327 switch (in_attr
[Tag_GNU_MIPS_ABI_FP
].i
)
12331 (_("Warning: %B uses -msingle-float, %B uses -mips32r2 -mfp64"),
12337 (_("Warning: %B uses -mdouble-float, %B uses -mips32r2 -mfp64"),
12343 (_("Warning: %B uses hard float, %B uses soft float"),
12357 /* Merge Tag_compatibility attributes and any common GNU ones. */
12358 _bfd_elf_merge_object_attributes (ibfd
, obfd
);
12363 /* Merge backend specific data from an object file to the output
12364 object file when linking. */
12367 _bfd_mips_elf_merge_private_bfd_data (bfd
*ibfd
, bfd
*obfd
)
12369 flagword old_flags
;
12370 flagword new_flags
;
12372 bfd_boolean null_input_bfd
= TRUE
;
12375 /* Check if we have the same endianess */
12376 if (! _bfd_generic_verify_endian_match (ibfd
, obfd
))
12378 (*_bfd_error_handler
)
12379 (_("%B: endianness incompatible with that of the selected emulation"),
12384 if (!is_mips_elf (ibfd
) || !is_mips_elf (obfd
))
12387 if (strcmp (bfd_get_target (ibfd
), bfd_get_target (obfd
)) != 0)
12389 (*_bfd_error_handler
)
12390 (_("%B: ABI is incompatible with that of the selected emulation"),
12395 if (!mips_elf_merge_obj_attributes (ibfd
, obfd
))
12398 new_flags
= elf_elfheader (ibfd
)->e_flags
;
12399 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_NOREORDER
;
12400 old_flags
= elf_elfheader (obfd
)->e_flags
;
12402 if (! elf_flags_init (obfd
))
12404 elf_flags_init (obfd
) = TRUE
;
12405 elf_elfheader (obfd
)->e_flags
= new_flags
;
12406 elf_elfheader (obfd
)->e_ident
[EI_CLASS
]
12407 = elf_elfheader (ibfd
)->e_ident
[EI_CLASS
];
12409 if (bfd_get_arch (obfd
) == bfd_get_arch (ibfd
)
12410 && (bfd_get_arch_info (obfd
)->the_default
12411 || mips_mach_extends_p (bfd_get_mach (obfd
),
12412 bfd_get_mach (ibfd
))))
12414 if (! bfd_set_arch_mach (obfd
, bfd_get_arch (ibfd
),
12415 bfd_get_mach (ibfd
)))
12422 /* Check flag compatibility. */
12424 new_flags
&= ~EF_MIPS_NOREORDER
;
12425 old_flags
&= ~EF_MIPS_NOREORDER
;
12427 /* Some IRIX 6 BSD-compatibility objects have this bit set. It
12428 doesn't seem to matter. */
12429 new_flags
&= ~EF_MIPS_XGOT
;
12430 old_flags
&= ~EF_MIPS_XGOT
;
12432 /* MIPSpro generates ucode info in n64 objects. Again, we should
12433 just be able to ignore this. */
12434 new_flags
&= ~EF_MIPS_UCODE
;
12435 old_flags
&= ~EF_MIPS_UCODE
;
12437 /* DSOs should only be linked with CPIC code. */
12438 if ((ibfd
->flags
& DYNAMIC
) != 0)
12439 new_flags
|= EF_MIPS_PIC
| EF_MIPS_CPIC
;
12441 if (new_flags
== old_flags
)
12444 /* Check to see if the input BFD actually contains any sections.
12445 If not, its flags may not have been initialised either, but it cannot
12446 actually cause any incompatibility. */
12447 for (sec
= ibfd
->sections
; sec
!= NULL
; sec
= sec
->next
)
12449 /* Ignore synthetic sections and empty .text, .data and .bss sections
12450 which are automatically generated by gas. */
12451 if (strcmp (sec
->name
, ".reginfo")
12452 && strcmp (sec
->name
, ".mdebug")
12454 || (strcmp (sec
->name
, ".text")
12455 && strcmp (sec
->name
, ".data")
12456 && strcmp (sec
->name
, ".bss"))))
12458 null_input_bfd
= FALSE
;
12462 if (null_input_bfd
)
12467 if (((new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0)
12468 != ((old_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
)) != 0))
12470 (*_bfd_error_handler
)
12471 (_("%B: warning: linking abicalls files with non-abicalls files"),
12476 if (new_flags
& (EF_MIPS_PIC
| EF_MIPS_CPIC
))
12477 elf_elfheader (obfd
)->e_flags
|= EF_MIPS_CPIC
;
12478 if (! (new_flags
& EF_MIPS_PIC
))
12479 elf_elfheader (obfd
)->e_flags
&= ~EF_MIPS_PIC
;
12481 new_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
12482 old_flags
&= ~ (EF_MIPS_PIC
| EF_MIPS_CPIC
);
12484 /* Compare the ISAs. */
12485 if (mips_32bit_flags_p (old_flags
) != mips_32bit_flags_p (new_flags
))
12487 (*_bfd_error_handler
)
12488 (_("%B: linking 32-bit code with 64-bit code"),
12492 else if (!mips_mach_extends_p (bfd_get_mach (ibfd
), bfd_get_mach (obfd
)))
12494 /* OBFD's ISA isn't the same as, or an extension of, IBFD's. */
12495 if (mips_mach_extends_p (bfd_get_mach (obfd
), bfd_get_mach (ibfd
)))
12497 /* Copy the architecture info from IBFD to OBFD. Also copy
12498 the 32-bit flag (if set) so that we continue to recognise
12499 OBFD as a 32-bit binary. */
12500 bfd_set_arch_info (obfd
, bfd_get_arch_info (ibfd
));
12501 elf_elfheader (obfd
)->e_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
);
12502 elf_elfheader (obfd
)->e_flags
12503 |= new_flags
& (EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
12505 /* Copy across the ABI flags if OBFD doesn't use them
12506 and if that was what caused us to treat IBFD as 32-bit. */
12507 if ((old_flags
& EF_MIPS_ABI
) == 0
12508 && mips_32bit_flags_p (new_flags
)
12509 && !mips_32bit_flags_p (new_flags
& ~EF_MIPS_ABI
))
12510 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ABI
;
12514 /* The ISAs aren't compatible. */
12515 (*_bfd_error_handler
)
12516 (_("%B: linking %s module with previous %s modules"),
12518 bfd_printable_name (ibfd
),
12519 bfd_printable_name (obfd
));
12524 new_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
12525 old_flags
&= ~(EF_MIPS_ARCH
| EF_MIPS_MACH
| EF_MIPS_32BITMODE
);
12527 /* Compare ABIs. The 64-bit ABI does not use EF_MIPS_ABI. But, it
12528 does set EI_CLASS differently from any 32-bit ABI. */
12529 if ((new_flags
& EF_MIPS_ABI
) != (old_flags
& EF_MIPS_ABI
)
12530 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
12531 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
12533 /* Only error if both are set (to different values). */
12534 if (((new_flags
& EF_MIPS_ABI
) && (old_flags
& EF_MIPS_ABI
))
12535 || (elf_elfheader (ibfd
)->e_ident
[EI_CLASS
]
12536 != elf_elfheader (obfd
)->e_ident
[EI_CLASS
]))
12538 (*_bfd_error_handler
)
12539 (_("%B: ABI mismatch: linking %s module with previous %s modules"),
12541 elf_mips_abi_name (ibfd
),
12542 elf_mips_abi_name (obfd
));
12545 new_flags
&= ~EF_MIPS_ABI
;
12546 old_flags
&= ~EF_MIPS_ABI
;
12549 /* For now, allow arbitrary mixing of ASEs (retain the union). */
12550 if ((new_flags
& EF_MIPS_ARCH_ASE
) != (old_flags
& EF_MIPS_ARCH_ASE
))
12552 elf_elfheader (obfd
)->e_flags
|= new_flags
& EF_MIPS_ARCH_ASE
;
12554 new_flags
&= ~ EF_MIPS_ARCH_ASE
;
12555 old_flags
&= ~ EF_MIPS_ARCH_ASE
;
12558 /* Warn about any other mismatches */
12559 if (new_flags
!= old_flags
)
12561 (*_bfd_error_handler
)
12562 (_("%B: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"),
12563 ibfd
, (unsigned long) new_flags
,
12564 (unsigned long) old_flags
);
12570 bfd_set_error (bfd_error_bad_value
);
12577 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */
12580 _bfd_mips_elf_set_private_flags (bfd
*abfd
, flagword flags
)
12582 BFD_ASSERT (!elf_flags_init (abfd
)
12583 || elf_elfheader (abfd
)->e_flags
== flags
);
12585 elf_elfheader (abfd
)->e_flags
= flags
;
12586 elf_flags_init (abfd
) = TRUE
;
12591 _bfd_mips_elf_get_target_dtag (bfd_vma dtag
)
12595 default: return "";
12596 case DT_MIPS_RLD_VERSION
:
12597 return "MIPS_RLD_VERSION";
12598 case DT_MIPS_TIME_STAMP
:
12599 return "MIPS_TIME_STAMP";
12600 case DT_MIPS_ICHECKSUM
:
12601 return "MIPS_ICHECKSUM";
12602 case DT_MIPS_IVERSION
:
12603 return "MIPS_IVERSION";
12604 case DT_MIPS_FLAGS
:
12605 return "MIPS_FLAGS";
12606 case DT_MIPS_BASE_ADDRESS
:
12607 return "MIPS_BASE_ADDRESS";
12609 return "MIPS_MSYM";
12610 case DT_MIPS_CONFLICT
:
12611 return "MIPS_CONFLICT";
12612 case DT_MIPS_LIBLIST
:
12613 return "MIPS_LIBLIST";
12614 case DT_MIPS_LOCAL_GOTNO
:
12615 return "MIPS_LOCAL_GOTNO";
12616 case DT_MIPS_CONFLICTNO
:
12617 return "MIPS_CONFLICTNO";
12618 case DT_MIPS_LIBLISTNO
:
12619 return "MIPS_LIBLISTNO";
12620 case DT_MIPS_SYMTABNO
:
12621 return "MIPS_SYMTABNO";
12622 case DT_MIPS_UNREFEXTNO
:
12623 return "MIPS_UNREFEXTNO";
12624 case DT_MIPS_GOTSYM
:
12625 return "MIPS_GOTSYM";
12626 case DT_MIPS_HIPAGENO
:
12627 return "MIPS_HIPAGENO";
12628 case DT_MIPS_RLD_MAP
:
12629 return "MIPS_RLD_MAP";
12630 case DT_MIPS_DELTA_CLASS
:
12631 return "MIPS_DELTA_CLASS";
12632 case DT_MIPS_DELTA_CLASS_NO
:
12633 return "MIPS_DELTA_CLASS_NO";
12634 case DT_MIPS_DELTA_INSTANCE
:
12635 return "MIPS_DELTA_INSTANCE";
12636 case DT_MIPS_DELTA_INSTANCE_NO
:
12637 return "MIPS_DELTA_INSTANCE_NO";
12638 case DT_MIPS_DELTA_RELOC
:
12639 return "MIPS_DELTA_RELOC";
12640 case DT_MIPS_DELTA_RELOC_NO
:
12641 return "MIPS_DELTA_RELOC_NO";
12642 case DT_MIPS_DELTA_SYM
:
12643 return "MIPS_DELTA_SYM";
12644 case DT_MIPS_DELTA_SYM_NO
:
12645 return "MIPS_DELTA_SYM_NO";
12646 case DT_MIPS_DELTA_CLASSSYM
:
12647 return "MIPS_DELTA_CLASSSYM";
12648 case DT_MIPS_DELTA_CLASSSYM_NO
:
12649 return "MIPS_DELTA_CLASSSYM_NO";
12650 case DT_MIPS_CXX_FLAGS
:
12651 return "MIPS_CXX_FLAGS";
12652 case DT_MIPS_PIXIE_INIT
:
12653 return "MIPS_PIXIE_INIT";
12654 case DT_MIPS_SYMBOL_LIB
:
12655 return "MIPS_SYMBOL_LIB";
12656 case DT_MIPS_LOCALPAGE_GOTIDX
:
12657 return "MIPS_LOCALPAGE_GOTIDX";
12658 case DT_MIPS_LOCAL_GOTIDX
:
12659 return "MIPS_LOCAL_GOTIDX";
12660 case DT_MIPS_HIDDEN_GOTIDX
:
12661 return "MIPS_HIDDEN_GOTIDX";
12662 case DT_MIPS_PROTECTED_GOTIDX
:
12663 return "MIPS_PROTECTED_GOT_IDX";
12664 case DT_MIPS_OPTIONS
:
12665 return "MIPS_OPTIONS";
12666 case DT_MIPS_INTERFACE
:
12667 return "MIPS_INTERFACE";
12668 case DT_MIPS_DYNSTR_ALIGN
:
12669 return "DT_MIPS_DYNSTR_ALIGN";
12670 case DT_MIPS_INTERFACE_SIZE
:
12671 return "DT_MIPS_INTERFACE_SIZE";
12672 case DT_MIPS_RLD_TEXT_RESOLVE_ADDR
:
12673 return "DT_MIPS_RLD_TEXT_RESOLVE_ADDR";
12674 case DT_MIPS_PERF_SUFFIX
:
12675 return "DT_MIPS_PERF_SUFFIX";
12676 case DT_MIPS_COMPACT_SIZE
:
12677 return "DT_MIPS_COMPACT_SIZE";
12678 case DT_MIPS_GP_VALUE
:
12679 return "DT_MIPS_GP_VALUE";
12680 case DT_MIPS_AUX_DYNAMIC
:
12681 return "DT_MIPS_AUX_DYNAMIC";
12682 case DT_MIPS_PLTGOT
:
12683 return "DT_MIPS_PLTGOT";
12684 case DT_MIPS_RWPLT
:
12685 return "DT_MIPS_RWPLT";
12690 _bfd_mips_elf_print_private_bfd_data (bfd
*abfd
, void *ptr
)
12694 BFD_ASSERT (abfd
!= NULL
&& ptr
!= NULL
);
12696 /* Print normal ELF private data. */
12697 _bfd_elf_print_private_bfd_data (abfd
, ptr
);
12699 /* xgettext:c-format */
12700 fprintf (file
, _("private flags = %lx:"), elf_elfheader (abfd
)->e_flags
);
12702 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O32
)
12703 fprintf (file
, _(" [abi=O32]"));
12704 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_O64
)
12705 fprintf (file
, _(" [abi=O64]"));
12706 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI32
)
12707 fprintf (file
, _(" [abi=EABI32]"));
12708 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
) == E_MIPS_ABI_EABI64
)
12709 fprintf (file
, _(" [abi=EABI64]"));
12710 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ABI
))
12711 fprintf (file
, _(" [abi unknown]"));
12712 else if (ABI_N32_P (abfd
))
12713 fprintf (file
, _(" [abi=N32]"));
12714 else if (ABI_64_P (abfd
))
12715 fprintf (file
, _(" [abi=64]"));
12717 fprintf (file
, _(" [no abi set]"));
12719 if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_1
)
12720 fprintf (file
, " [mips1]");
12721 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_2
)
12722 fprintf (file
, " [mips2]");
12723 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_3
)
12724 fprintf (file
, " [mips3]");
12725 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_4
)
12726 fprintf (file
, " [mips4]");
12727 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_5
)
12728 fprintf (file
, " [mips5]");
12729 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32
)
12730 fprintf (file
, " [mips32]");
12731 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64
)
12732 fprintf (file
, " [mips64]");
12733 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_32R2
)
12734 fprintf (file
, " [mips32r2]");
12735 else if ((elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH
) == E_MIPS_ARCH_64R2
)
12736 fprintf (file
, " [mips64r2]");
12738 fprintf (file
, _(" [unknown ISA]"));
12740 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_MDMX
)
12741 fprintf (file
, " [mdmx]");
12743 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_ARCH_ASE_M16
)
12744 fprintf (file
, " [mips16]");
12746 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_32BITMODE
)
12747 fprintf (file
, " [32bitmode]");
12749 fprintf (file
, _(" [not 32bitmode]"));
12751 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_NOREORDER
)
12752 fprintf (file
, " [noreorder]");
12754 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_PIC
)
12755 fprintf (file
, " [PIC]");
12757 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_CPIC
)
12758 fprintf (file
, " [CPIC]");
12760 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_XGOT
)
12761 fprintf (file
, " [XGOT]");
12763 if (elf_elfheader (abfd
)->e_flags
& EF_MIPS_UCODE
)
12764 fprintf (file
, " [UCODE]");
12766 fputc ('\n', file
);
12771 const struct bfd_elf_special_section _bfd_mips_elf_special_sections
[] =
12773 { STRING_COMMA_LEN (".lit4"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12774 { STRING_COMMA_LEN (".lit8"), 0, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12775 { STRING_COMMA_LEN (".mdebug"), 0, SHT_MIPS_DEBUG
, 0 },
12776 { STRING_COMMA_LEN (".sbss"), -2, SHT_NOBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12777 { STRING_COMMA_LEN (".sdata"), -2, SHT_PROGBITS
, SHF_ALLOC
+ SHF_WRITE
+ SHF_MIPS_GPREL
},
12778 { STRING_COMMA_LEN (".ucode"), 0, SHT_MIPS_UCODE
, 0 },
12779 { NULL
, 0, 0, 0, 0 }
12782 /* Merge non visibility st_other attributes. Ensure that the
12783 STO_OPTIONAL flag is copied into h->other, even if this is not a
12784 definiton of the symbol. */
12786 _bfd_mips_elf_merge_symbol_attribute (struct elf_link_hash_entry
*h
,
12787 const Elf_Internal_Sym
*isym
,
12788 bfd_boolean definition
,
12789 bfd_boolean dynamic ATTRIBUTE_UNUSED
)
12791 if ((isym
->st_other
& ~ELF_ST_VISIBILITY (-1)) != 0)
12793 unsigned char other
;
12795 other
= (definition
? isym
->st_other
: h
->other
);
12796 other
&= ~ELF_ST_VISIBILITY (-1);
12797 h
->other
= other
| ELF_ST_VISIBILITY (h
->other
);
12801 && ELF_MIPS_IS_OPTIONAL (isym
->st_other
))
12802 h
->other
|= STO_OPTIONAL
;
12805 /* Decide whether an undefined symbol is special and can be ignored.
12806 This is the case for OPTIONAL symbols on IRIX. */
12808 _bfd_mips_elf_ignore_undef_symbol (struct elf_link_hash_entry
*h
)
12810 return ELF_MIPS_IS_OPTIONAL (h
->other
) ? TRUE
: FALSE
;
12814 _bfd_mips_elf_common_definition (Elf_Internal_Sym
*sym
)
12816 return (sym
->st_shndx
== SHN_COMMON
12817 || sym
->st_shndx
== SHN_MIPS_ACOMMON
12818 || sym
->st_shndx
== SHN_MIPS_SCOMMON
);
12821 /* Return address for Ith PLT stub in section PLT, for relocation REL
12822 or (bfd_vma) -1 if it should not be included. */
12825 _bfd_mips_elf_plt_sym_val (bfd_vma i
, const asection
*plt
,
12826 const arelent
*rel ATTRIBUTE_UNUSED
)
12829 + 4 * ARRAY_SIZE (mips_o32_exec_plt0_entry
)
12830 + i
* 4 * ARRAY_SIZE (mips_exec_plt_entry
));
12834 _bfd_mips_post_process_headers (bfd
*abfd
, struct bfd_link_info
*link_info
)
12836 struct mips_elf_link_hash_table
*htab
;
12837 Elf_Internal_Ehdr
*i_ehdrp
;
12839 i_ehdrp
= elf_elfheader (abfd
);
12842 htab
= mips_elf_hash_table (link_info
);
12843 if (htab
->use_plts_and_copy_relocs
&& !htab
->is_vxworks
)
12844 i_ehdrp
->e_ident
[EI_ABIVERSION
] = 1;