Changeset 609 for branches/GNU/src/binutils/bfd/elf32-mips.c
- Timestamp:
- Aug 16, 2003, 6:59:22 PM (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/binutils/bfd/elf32-mips.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* MIPS-specific support for 32-bit ELF 2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 3 Free Software Foundation, Inc.2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 3 2003 Free Software Foundation, Inc. 4 4 5 5 Most of the information added by Ian Lance Taylor, Cygnus Support, … … 36 36 #include "genlink.h" 37 37 #include "elf-bfd.h" 38 #include "elfxx-mips.h" 38 39 #include "elf/mips.h" 39 40 … … 47 48 #include "ecoffswap.h" 48 49 49 /* This structure is used to hold .got information when linking. It 50 is stored in the tdata field of the bfd_elf_section_data structure. */ 51 52 struct mips_got_info 53 { 54 /* The global symbol in the GOT with the lowest index in the dynamic 55 symbol table. */ 56 struct elf_link_hash_entry *global_gotsym; 57 /* The number of global .got entries. */ 58 unsigned int global_gotno; 59 /* The number of local .got entries. */ 60 unsigned int local_gotno; 61 /* The number of local .got entries we have used. */ 62 unsigned int assigned_gotno; 63 }; 64 65 /* The MIPS ELF linker needs additional information for each symbol in 66 the global hash table. */ 67 68 struct mips_elf_link_hash_entry 69 { 70 struct elf_link_hash_entry root; 71 72 /* External symbol information. */ 73 EXTR esym; 74 75 /* Number of R_MIPS_32, R_MIPS_REL32, or R_MIPS_64 relocs against 76 this symbol. */ 77 unsigned int possibly_dynamic_relocs; 78 79 /* The index of the first dynamic relocation (in the .rel.dyn 80 section) against this symbol. */ 81 unsigned int min_dyn_reloc_index; 82 83 /* We must not create a stub for a symbol that has relocations 84 related to taking the function's address, i.e. any but 85 R_MIPS_CALL*16 ones -- see "MIPS ABI Supplement, 3rd Edition", 86 p. 4-20. */ 87 boolean no_fn_stub; 88 89 /* If there is a stub that 32 bit functions should use to call this 90 16 bit function, this points to the section containing the stub. */ 91 asection *fn_stub; 92 93 /* Whether we need the fn_stub; this is set if this symbol appears 94 in any relocs other than a 16 bit call. */ 95 boolean need_fn_stub; 96 97 /* If there is a stub that 16 bit functions should use to call this 98 32 bit function, this points to the section containing the stub. */ 99 asection *call_stub; 100 101 /* This is like the call_stub field, but it is used if the function 102 being called returns a floating point value. */ 103 asection *call_fp_stub; 104 }; 105 50 static bfd_reloc_status_type mips_elf_hi16_reloc 51 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); 52 static bfd_reloc_status_type mips_elf_lo16_reloc 53 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); 54 static bfd_reloc_status_type mips_elf_got16_reloc 55 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); 56 static bfd_reloc_status_type mips_elf_gprel32_reloc 57 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); 106 58 static bfd_reloc_status_type mips32_64bit_reloc 107 59 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); 108 60 static reloc_howto_type *bfd_elf32_bfd_reloc_type_lookup 109 61 PARAMS ((bfd *, bfd_reloc_code_real_type)); 110 static reloc_howto_type *mips_ rtype_to_howto111 PARAMS ((unsigned int ));62 static reloc_howto_type *mips_elf32_rtype_to_howto 63 PARAMS ((unsigned int, bfd_boolean)); 112 64 static void mips_info_to_howto_rel 113 PARAMS ((bfd *, arelent *, Elf 32_Internal_Rel*));65 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); 114 66 static void mips_info_to_howto_rela 115 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *)); 116 static void bfd_mips_elf32_swap_gptab_in 117 PARAMS ((bfd *, const Elf32_External_gptab *, Elf32_gptab *)); 118 static void bfd_mips_elf32_swap_gptab_out 119 PARAMS ((bfd *, const Elf32_gptab *, Elf32_External_gptab *)); 120 #if 0 121 static void bfd_mips_elf_swap_msym_in 122 PARAMS ((bfd *, const Elf32_External_Msym *, Elf32_Internal_Msym *)); 123 #endif 124 static void bfd_mips_elf_swap_msym_out 125 PARAMS ((bfd *, const Elf32_Internal_Msym *, Elf32_External_Msym *)); 126 static boolean mips_elf_sym_is_global PARAMS ((bfd *, asymbol *)); 127 static boolean mips_elf_create_procedure_table 128 PARAMS ((PTR, bfd *, struct bfd_link_info *, asection *, 129 struct ecoff_debug_info *)); 130 static INLINE int elf_mips_isa PARAMS ((flagword)); 131 static INLINE int elf_mips_mach PARAMS ((flagword)); 132 static INLINE char* elf_mips_abi_name PARAMS ((bfd *)); 133 static boolean mips_elf_is_local_label_name 67 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); 68 static bfd_boolean mips_elf_sym_is_global 69 PARAMS ((bfd *, asymbol *)); 70 static bfd_boolean mips_elf32_object_p 71 PARAMS ((bfd *)); 72 static bfd_boolean mips_elf_is_local_label_name 134 73 PARAMS ((bfd *, const char *)); 135 static struct bfd_hash_entry *mips_elf_link_hash_newfunc136 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *));137 static int gptab_compare PARAMS ((const void *, const void *));138 74 static bfd_reloc_status_type mips16_jump_reloc 139 75 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); 140 76 static bfd_reloc_status_type mips16_gprel_reloc 141 77 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); 142 static boolean mips_elf_create_compact_rel_section143 PARAMS ((bfd *, struct bfd_link_info *));144 static boolean mips_elf_create_got_section145 PARAMS ((bfd *, struct bfd_link_info *));146 78 static bfd_reloc_status_type mips_elf_final_gp 147 PARAMS ((bfd *, asymbol *, boolean, char **, bfd_vma *)); 148 static bfd_byte *elf32_mips_get_relocated_section_contents 149 PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *, 150 bfd_byte *, boolean, asymbol **)); 151 static asection *mips_elf_create_msym_section 79 PARAMS ((bfd *, asymbol *, bfd_boolean, char **, bfd_vma *)); 80 static bfd_boolean mips_elf_assign_gp 81 PARAMS ((bfd *, bfd_vma *)); 82 static bfd_boolean elf32_mips_grok_prstatus 83 PARAMS ((bfd *, Elf_Internal_Note *)); 84 static bfd_boolean elf32_mips_grok_psinfo 85 PARAMS ((bfd *, Elf_Internal_Note *)); 86 static irix_compat_t elf32_mips_irix_compat 152 87 PARAMS ((bfd *)); 153 static void mips_elf_irix6_finish_dynamic_symbol 154 PARAMS ((bfd *, const char *, Elf_Internal_Sym *)); 155 static bfd_vma mips_elf_sign_extend PARAMS ((bfd_vma, int)); 156 static boolean mips_elf_overflow_p PARAMS ((bfd_vma, int)); 157 static bfd_vma mips_elf_high PARAMS ((bfd_vma)); 158 static bfd_vma mips_elf_higher PARAMS ((bfd_vma)); 159 static bfd_vma mips_elf_highest PARAMS ((bfd_vma)); 160 static bfd_vma mips_elf_global_got_index 161 PARAMS ((bfd *, struct elf_link_hash_entry *)); 162 static bfd_vma mips_elf_local_got_index 163 PARAMS ((bfd *, struct bfd_link_info *, bfd_vma)); 164 static bfd_vma mips_elf_got_offset_from_index 165 PARAMS ((bfd *, bfd *, bfd_vma)); 166 static boolean mips_elf_record_global_got_symbol 167 PARAMS ((struct elf_link_hash_entry *, struct bfd_link_info *, 168 struct mips_got_info *)); 169 static bfd_vma mips_elf_got_page 170 PARAMS ((bfd *, struct bfd_link_info *, bfd_vma, bfd_vma *)); 171 static const Elf_Internal_Rela *mips_elf_next_relocation 172 PARAMS ((unsigned int, const Elf_Internal_Rela *, 173 const Elf_Internal_Rela *)); 174 static bfd_reloc_status_type mips_elf_calculate_relocation 175 PARAMS ((bfd *, bfd *, asection *, struct bfd_link_info *, 176 const Elf_Internal_Rela *, bfd_vma, reloc_howto_type *, 177 Elf_Internal_Sym *, asection **, bfd_vma *, const char **, 178 boolean *)); 179 static bfd_vma mips_elf_obtain_contents 180 PARAMS ((reloc_howto_type *, const Elf_Internal_Rela *, bfd *, bfd_byte *)); 181 static boolean mips_elf_perform_relocation 182 PARAMS ((struct bfd_link_info *, reloc_howto_type *, 183 const Elf_Internal_Rela *, bfd_vma, 184 bfd *, asection *, bfd_byte *, boolean)); 185 static boolean mips_elf_assign_gp PARAMS ((bfd *, bfd_vma *)); 186 static boolean mips_elf_sort_hash_table_f 187 PARAMS ((struct mips_elf_link_hash_entry *, PTR)); 188 static boolean mips_elf_sort_hash_table 189 PARAMS ((struct bfd_link_info *, unsigned long)); 190 static asection * mips_elf_got_section PARAMS ((bfd *)); 191 static struct mips_got_info *mips_elf_got_info 192 PARAMS ((bfd *, asection **)); 193 static boolean mips_elf_local_relocation_p 194 PARAMS ((bfd *, const Elf_Internal_Rela *, asection **, boolean)); 195 static bfd_vma mips_elf_create_local_got_entry 196 PARAMS ((bfd *, struct mips_got_info *, asection *, bfd_vma)); 197 static bfd_vma mips_elf_got16_entry 198 PARAMS ((bfd *, struct bfd_link_info *, bfd_vma, boolean)); 199 static boolean mips_elf_create_dynamic_relocation 200 PARAMS ((bfd *, struct bfd_link_info *, const Elf_Internal_Rela *, 201 struct mips_elf_link_hash_entry *, asection *, 202 bfd_vma, bfd_vma *, asection *)); 203 static void mips_elf_allocate_dynamic_relocations 204 PARAMS ((bfd *, unsigned int)); 205 static boolean mips_elf_stub_section_p 206 PARAMS ((bfd *, asection *)); 207 static int sort_dynamic_relocs 208 PARAMS ((const void *, const void *)); 209 210 extern const bfd_target bfd_elf32_tradbigmips_vec; 211 extern const bfd_target bfd_elf32_tradlittlemips_vec; 212 #ifdef BFD64 213 extern const bfd_target bfd_elf64_tradbigmips_vec; 214 extern const bfd_target bfd_elf64_tradlittlemips_vec; 215 #endif 216 217 /* The level of IRIX compatibility we're striving for. */ 218 219 typedef enum { 220 ict_none, 221 ict_irix5, 222 ict_irix6 223 } irix_compat_t; 224 225 /* This will be used when we sort the dynamic relocation records. */ 226 static bfd *reldyn_sorting_bfd; 88 89 extern const bfd_target bfd_elf32_bigmips_vec; 90 extern const bfd_target bfd_elf32_littlemips_vec; 227 91 228 92 /* Nonzero if ABFD is using the N32 ABI. */ 229 230 93 #define ABI_N32_P(abfd) \ 231 94 ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI2) != 0) 232 95 233 /* Nonzero if ABFD is using the 64-bit ABI. */234 #define ABI_64_P(abfd) \235 ((elf_elfheader (abfd)->e_ident[EI_CLASS] == ELFCLASS64) != 0)236 237 /* Depending on the target vector we generate some version of Irix238 executables or "normal" MIPS ELF ABI executables. */239 #ifdef BFD64240 #define IRIX_COMPAT(abfd) \241 (((abfd->xvec == &bfd_elf64_tradbigmips_vec) || \242 (abfd->xvec == &bfd_elf64_tradlittlemips_vec) || \243 (abfd->xvec == &bfd_elf32_tradbigmips_vec) || \244 (abfd->xvec == &bfd_elf32_tradlittlemips_vec)) ? ict_none : \245 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5))246 #else247 #define IRIX_COMPAT(abfd) \248 (((abfd->xvec == &bfd_elf32_tradbigmips_vec) || \249 (abfd->xvec == &bfd_elf32_tradlittlemips_vec)) ? ict_none : \250 ((ABI_N32_P (abfd) || ABI_64_P (abfd)) ? ict_irix6 : ict_irix5))251 #endif252 253 96 /* Whether we are trying to be compatible with IRIX at all. */ 254 97 #define SGI_COMPAT(abfd) \ 255 (IRIX_COMPAT (abfd) != ict_none) 256 257 /* The name of the msym section. */ 258 #define MIPS_ELF_MSYM_SECTION_NAME(abfd) ".msym" 259 260 /* The name of the srdata section. */ 261 #define MIPS_ELF_SRDATA_SECTION_NAME(abfd) ".srdata" 262 263 /* The name of the options section. */ 264 #define MIPS_ELF_OPTIONS_SECTION_NAME(abfd) \ 265 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.options" : ".options") 266 267 /* The name of the stub section. */ 268 #define MIPS_ELF_STUB_SECTION_NAME(abfd) \ 269 (IRIX_COMPAT (abfd) == ict_irix6 ? ".MIPS.stubs" : ".stub") 270 271 /* The name of the dynamic relocation section. */ 272 #define MIPS_ELF_REL_DYN_SECTION_NAME(abfd) ".rel.dyn" 273 274 /* The size of an external REL relocation. */ 275 #define MIPS_ELF_REL_SIZE(abfd) \ 276 (get_elf_backend_data (abfd)->s->sizeof_rel) 277 278 /* The size of an external dynamic table entry. */ 279 #define MIPS_ELF_DYN_SIZE(abfd) \ 280 (get_elf_backend_data (abfd)->s->sizeof_dyn) 281 282 /* The size of a GOT entry. */ 283 #define MIPS_ELF_GOT_SIZE(abfd) \ 284 (get_elf_backend_data (abfd)->s->arch_size / 8) 285 286 /* The size of a symbol-table entry. */ 287 #define MIPS_ELF_SYM_SIZE(abfd) \ 288 (get_elf_backend_data (abfd)->s->sizeof_sym) 289 290 /* The default alignment for sections, as a power of two. */ 291 #define MIPS_ELF_LOG_FILE_ALIGN(abfd) \ 292 (get_elf_backend_data (abfd)->s->file_align == 8 ? 3 : 2) 293 294 /* Get word-sized data. */ 295 #define MIPS_ELF_GET_WORD(abfd, ptr) \ 296 (ABI_64_P (abfd) ? bfd_get_64 (abfd, ptr) : bfd_get_32 (abfd, ptr)) 297 298 /* Put out word-sized data. */ 299 #define MIPS_ELF_PUT_WORD(abfd, val, ptr) \ 300 (ABI_64_P (abfd) \ 301 ? bfd_put_64 (abfd, val, ptr) \ 302 : bfd_put_32 (abfd, val, ptr)) 303 304 /* Add a dynamic symbol table-entry. */ 305 #ifdef BFD64 306 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \ 307 (ABI_64_P (elf_hash_table (info)->dynobj) \ 308 ? bfd_elf64_add_dynamic_entry (info, tag, val) \ 309 : bfd_elf32_add_dynamic_entry (info, tag, val)) 310 #else 311 #define MIPS_ELF_ADD_DYNAMIC_ENTRY(info, tag, val) \ 312 (ABI_64_P (elf_hash_table (info)->dynobj) \ 313 ? (abort (), false) \ 314 : bfd_elf32_add_dynamic_entry (info, tag, val)) 315 #endif 98 (elf32_mips_irix_compat (abfd) != ict_none) 316 99 317 100 /* The number of local .got entries we reserve. */ 318 101 #define MIPS_RESERVED_GOTNO (2) 319 320 /* Instructions which appear in a stub. For some reason the stub is321 slightly different on an SGI system. */322 #define ELF_MIPS_GP_OFFSET(abfd) (SGI_COMPAT (abfd) ? 0x7ff0 : 0x8000)323 #define STUB_LW(abfd) \324 (SGI_COMPAT (abfd) \325 ? (ABI_64_P (abfd) \326 ? 0xdf998010 /* ld t9,0x8010(gp) */ \327 : 0x8f998010) /* lw t9,0x8010(gp) */ \328 : 0x8f998010) /* lw t9,0x8000(gp) */329 #define STUB_MOVE(abfd) \330 (SGI_COMPAT (abfd) ? 0x03e07825 : 0x03e07821) /* move t7,ra */331 #define STUB_JALR 0x0320f809 /* jal t9 */332 #define STUB_LI16(abfd) \333 (SGI_COMPAT (abfd) ? 0x34180000 : 0x24180000) /* ori t8,zero,0 */334 #define MIPS_FUNCTION_STUB_SIZE (16)335 336 #if 0337 /* We no longer try to identify particular sections for the .dynsym338 section. When we do, we wind up crashing if there are other random339 sections with relocations. */340 341 /* Names of sections which appear in the .dynsym section in an Irix 5342 executable. */343 344 static const char * const mips_elf_dynsym_sec_names[] =345 {346 ".text",347 ".init",348 ".fini",349 ".data",350 ".rodata",351 ".sdata",352 ".sbss",353 ".bss",354 NULL355 };356 357 #define SIZEOF_MIPS_DYNSYM_SECNAMES \358 (sizeof mips_elf_dynsym_sec_names / sizeof mips_elf_dynsym_sec_names[0])359 360 /* The number of entries in mips_elf_dynsym_sec_names which go in the361 text segment. */362 363 #define MIPS_TEXT_DYNSYM_SECNO (3)364 365 #endif /* 0 */366 367 /* The names of the runtime procedure table symbols used on Irix 5. */368 369 static const char * const mips_elf_dynsym_rtproc_names[] =370 {371 "_procedure_table",372 "_procedure_string_table",373 "_procedure_table_size",374 NULL375 };376 377 /* These structures are used to generate the .compact_rel section on378 Irix 5. */379 380 typedef struct381 {382 unsigned long id1; /* Always one? */383 unsigned long num; /* Number of compact relocation entries. */384 unsigned long id2; /* Always two? */385 unsigned long offset; /* The file offset of the first relocation. */386 unsigned long reserved0; /* Zero? */387 unsigned long reserved1; /* Zero? */388 } Elf32_compact_rel;389 390 typedef struct391 {392 bfd_byte id1[4];393 bfd_byte num[4];394 bfd_byte id2[4];395 bfd_byte offset[4];396 bfd_byte reserved0[4];397 bfd_byte reserved1[4];398 } Elf32_External_compact_rel;399 400 typedef struct401 {402 unsigned int ctype : 1; /* 1: long 0: short format. See below. */403 unsigned int rtype : 4; /* Relocation types. See below. */404 unsigned int dist2to : 8;405 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */406 unsigned long konst; /* KONST field. See below. */407 unsigned long vaddr; /* VADDR to be relocated. */408 } Elf32_crinfo;409 410 typedef struct411 {412 unsigned int ctype : 1; /* 1: long 0: short format. See below. */413 unsigned int rtype : 4; /* Relocation types. See below. */414 unsigned int dist2to : 8;415 unsigned int relvaddr : 19; /* (VADDR - vaddr of the previous entry)/ 4 */416 unsigned long konst; /* KONST field. See below. */417 } Elf32_crinfo2;418 419 typedef struct420 {421 bfd_byte info[4];422 bfd_byte konst[4];423 bfd_byte vaddr[4];424 } Elf32_External_crinfo;425 426 typedef struct427 {428 bfd_byte info[4];429 bfd_byte konst[4];430 } Elf32_External_crinfo2;431 432 /* These are the constants used to swap the bitfields in a crinfo. */433 434 #define CRINFO_CTYPE (0x1)435 #define CRINFO_CTYPE_SH (31)436 #define CRINFO_RTYPE (0xf)437 #define CRINFO_RTYPE_SH (27)438 #define CRINFO_DIST2TO (0xff)439 #define CRINFO_DIST2TO_SH (19)440 #define CRINFO_RELVADDR (0x7ffff)441 #define CRINFO_RELVADDR_SH (0)442 443 /* A compact relocation info has long (3 words) or short (2 words)444 formats. A short format doesn't have VADDR field and relvaddr445 fields contains ((VADDR - vaddr of the previous entry) >> 2). */446 #define CRF_MIPS_LONG 1447 #define CRF_MIPS_SHORT 0448 449 /* There are 4 types of compact relocation at least. The value KONST450 has different meaning for each type:451 452 (type) (konst)453 CT_MIPS_REL32 Address in data454 CT_MIPS_WORD Address in word (XXX)455 CT_MIPS_GPHI_LO GP - vaddr456 CT_MIPS_JMPAD Address to jump457 */458 459 #define CRT_MIPS_REL32 0xa460 #define CRT_MIPS_WORD 0xb461 #define CRT_MIPS_GPHI_LO 0xc462 #define CRT_MIPS_JMPAD 0xd463 464 #define mips_elf_set_cr_format(x,format) ((x).ctype = (format))465 #define mips_elf_set_cr_type(x,type) ((x).rtype = (type))466 #define mips_elf_set_cr_dist2to(x,v) ((x).dist2to = (v))467 #define mips_elf_set_cr_relvaddr(x,d) ((x).relvaddr = (d)<<2)468 469 static void bfd_elf32_swap_compact_rel_out470 PARAMS ((bfd *, const Elf32_compact_rel *, Elf32_External_compact_rel *));471 static void bfd_elf32_swap_crinfo_out472 PARAMS ((bfd *, const Elf32_crinfo *, Elf32_External_crinfo *));473 474 #define USE_REL 1 /* MIPS uses REL relocations instead of RELA */475 102 476 103 /* In case we're on a 32-bit machine, construct a 64-bit "-1" value … … 478 105 #define MINUS_ONE (((bfd_vma)0) - 1) 479 106 480 static reloc_howto_type elf_mips_howto_table[] = 107 /* The relocation table used for SHT_REL sections. */ 108 109 static reloc_howto_type elf_mips_howto_table_rel[] = 481 110 { 482 111 /* No relocation. */ … … 485 114 0, /* size (0 = byte, 1 = short, 2 = long) */ 486 115 0, /* bitsize */ 487 false, /* pc_relative */116 FALSE, /* pc_relative */ 488 117 0, /* bitpos */ 489 118 complain_overflow_dont, /* complain_on_overflow */ 490 119 bfd_elf_generic_reloc, /* special_function */ 491 120 "R_MIPS_NONE", /* name */ 492 false, /* partial_inplace */121 FALSE, /* partial_inplace */ 493 122 0, /* src_mask */ 494 123 0, /* dst_mask */ 495 false), /* pcrel_offset */124 FALSE), /* pcrel_offset */ 496 125 497 126 /* 16 bit relocation. */ 498 127 HOWTO (R_MIPS_16, /* type */ 499 128 0, /* rightshift */ 500 1, /* size (0 = byte, 1 = short, 2 = long) */501 16, /* bitsize */ 502 false, /* pc_relative */503 0, /* bitpos */ 504 complain_overflow_ bitfield, /* complain_on_overflow */129 2, /* size (0 = byte, 1 = short, 2 = long) */ 130 16, /* bitsize */ 131 FALSE, /* pc_relative */ 132 0, /* bitpos */ 133 complain_overflow_signed, /* complain_on_overflow */ 505 134 bfd_elf_generic_reloc, /* special_function */ 506 135 "R_MIPS_16", /* name */ 507 true, /* partial_inplace */508 0x ffff, /* src_mask */509 0x ffff, /* dst_mask */510 false), /* pcrel_offset */136 TRUE, /* partial_inplace */ 137 0x0000ffff, /* src_mask */ 138 0x0000ffff, /* dst_mask */ 139 FALSE), /* pcrel_offset */ 511 140 512 141 /* 32 bit relocation. */ … … 515 144 2, /* size (0 = byte, 1 = short, 2 = long) */ 516 145 32, /* bitsize */ 517 false, /* pc_relative */518 0, /* bitpos */ 519 complain_overflow_ bitfield, /* complain_on_overflow */146 FALSE, /* pc_relative */ 147 0, /* bitpos */ 148 complain_overflow_dont, /* complain_on_overflow */ 520 149 bfd_elf_generic_reloc, /* special_function */ 521 150 "R_MIPS_32", /* name */ 522 true, /* partial_inplace */151 TRUE, /* partial_inplace */ 523 152 0xffffffff, /* src_mask */ 524 153 0xffffffff, /* dst_mask */ 525 false), /* pcrel_offset */154 FALSE), /* pcrel_offset */ 526 155 527 156 /* 32 bit symbol relative relocation. */ … … 530 159 2, /* size (0 = byte, 1 = short, 2 = long) */ 531 160 32, /* bitsize */ 532 false, /* pc_relative */533 0, /* bitpos */ 534 complain_overflow_ bitfield, /* complain_on_overflow */161 FALSE, /* pc_relative */ 162 0, /* bitpos */ 163 complain_overflow_dont, /* complain_on_overflow */ 535 164 bfd_elf_generic_reloc, /* special_function */ 536 165 "R_MIPS_REL32", /* name */ 537 true, /* partial_inplace */166 TRUE, /* partial_inplace */ 538 167 0xffffffff, /* src_mask */ 539 168 0xffffffff, /* dst_mask */ 540 false), /* pcrel_offset */169 FALSE), /* pcrel_offset */ 541 170 542 171 /* 26 bit jump address. */ … … 545 174 2, /* size (0 = byte, 1 = short, 2 = long) */ 546 175 26, /* bitsize */ 547 false, /* pc_relative */176 FALSE, /* pc_relative */ 548 177 0, /* bitpos */ 549 178 complain_overflow_dont, /* complain_on_overflow */ … … 553 182 bfd_elf_generic_reloc, /* special_function */ 554 183 "R_MIPS_26", /* name */ 555 true, /* partial_inplace */556 0x 3ffffff, /* src_mask */557 0x 3ffffff, /* dst_mask */558 false), /* pcrel_offset */184 TRUE, /* partial_inplace */ 185 0x03ffffff, /* src_mask */ 186 0x03ffffff, /* dst_mask */ 187 FALSE), /* pcrel_offset */ 559 188 560 189 /* High 16 bits of symbol value. */ … … 563 192 2, /* size (0 = byte, 1 = short, 2 = long) */ 564 193 16, /* bitsize */ 565 false, /* pc_relative */566 0, /* bitpos */ 567 complain_overflow_dont, /* complain_on_overflow */ 568 _bfd_mips_elf_hi16_reloc, /* special_function */194 FALSE, /* pc_relative */ 195 0, /* bitpos */ 196 complain_overflow_dont, /* complain_on_overflow */ 197 mips_elf_hi16_reloc, /* special_function */ 569 198 "R_MIPS_HI16", /* name */ 570 true, /* partial_inplace */571 0x ffff, /* src_mask */572 0x ffff, /* dst_mask */573 false), /* pcrel_offset */199 TRUE, /* partial_inplace */ 200 0x0000ffff, /* src_mask */ 201 0x0000ffff, /* dst_mask */ 202 FALSE), /* pcrel_offset */ 574 203 575 204 /* Low 16 bits of symbol value. */ … … 578 207 2, /* size (0 = byte, 1 = short, 2 = long) */ 579 208 16, /* bitsize */ 580 false, /* pc_relative */581 0, /* bitpos */ 582 complain_overflow_dont, /* complain_on_overflow */ 583 _bfd_mips_elf_lo16_reloc, /* special_function */209 FALSE, /* pc_relative */ 210 0, /* bitpos */ 211 complain_overflow_dont, /* complain_on_overflow */ 212 mips_elf_lo16_reloc, /* special_function */ 584 213 "R_MIPS_LO16", /* name */ 585 true, /* partial_inplace */586 0x ffff, /* src_mask */587 0x ffff, /* dst_mask */588 false), /* pcrel_offset */214 TRUE, /* partial_inplace */ 215 0x0000ffff, /* src_mask */ 216 0x0000ffff, /* dst_mask */ 217 FALSE), /* pcrel_offset */ 589 218 590 219 /* GP relative reference. */ … … 593 222 2, /* size (0 = byte, 1 = short, 2 = long) */ 594 223 16, /* bitsize */ 595 false, /* pc_relative */224 FALSE, /* pc_relative */ 596 225 0, /* bitpos */ 597 226 complain_overflow_signed, /* complain_on_overflow */ 598 _bfd_mips_elf _gprel16_reloc, /* special_function */227 _bfd_mips_elf32_gprel16_reloc, /* special_function */ 599 228 "R_MIPS_GPREL16", /* name */ 600 true, /* partial_inplace */601 0x ffff, /* src_mask */602 0x ffff, /* dst_mask */603 false), /* pcrel_offset */229 TRUE, /* partial_inplace */ 230 0x0000ffff, /* src_mask */ 231 0x0000ffff, /* dst_mask */ 232 FALSE), /* pcrel_offset */ 604 233 605 234 /* Reference to literal section. */ … … 608 237 2, /* size (0 = byte, 1 = short, 2 = long) */ 609 238 16, /* bitsize */ 610 false, /* pc_relative */239 FALSE, /* pc_relative */ 611 240 0, /* bitpos */ 612 241 complain_overflow_signed, /* complain_on_overflow */ 613 _bfd_mips_elf _gprel16_reloc, /* special_function */242 _bfd_mips_elf32_gprel16_reloc, /* special_function */ 614 243 "R_MIPS_LITERAL", /* name */ 615 true, /* partial_inplace */616 0x ffff, /* src_mask */617 0x ffff, /* dst_mask */618 false), /* pcrel_offset */244 TRUE, /* partial_inplace */ 245 0x0000ffff, /* src_mask */ 246 0x0000ffff, /* dst_mask */ 247 FALSE), /* pcrel_offset */ 619 248 620 249 /* Reference to global offset table. */ … … 623 252 2, /* size (0 = byte, 1 = short, 2 = long) */ 624 253 16, /* bitsize */ 625 false, /* pc_relative */254 FALSE, /* pc_relative */ 626 255 0, /* bitpos */ 627 256 complain_overflow_signed, /* complain_on_overflow */ 628 _bfd_mips_elf_got16_reloc, /* special_function */257 mips_elf_got16_reloc, /* special_function */ 629 258 "R_MIPS_GOT16", /* name */ 630 false, /* partial_inplace */631 0x ffff, /* src_mask */632 0x ffff, /* dst_mask */633 false), /* pcrel_offset */259 TRUE, /* partial_inplace */ 260 0x0000ffff, /* src_mask */ 261 0x0000ffff, /* dst_mask */ 262 FALSE), /* pcrel_offset */ 634 263 635 264 /* 16 bit PC relative reference. */ … … 638 267 2, /* size (0 = byte, 1 = short, 2 = long) */ 639 268 16, /* bitsize */ 640 true, /* pc_relative */269 TRUE, /* pc_relative */ 641 270 0, /* bitpos */ 642 271 complain_overflow_signed, /* complain_on_overflow */ 643 272 bfd_elf_generic_reloc, /* special_function */ 644 273 "R_MIPS_PC16", /* name */ 645 true, /* partial_inplace */646 0x ffff, /* src_mask */647 0x ffff, /* dst_mask */648 true), /* pcrel_offset */274 TRUE, /* partial_inplace */ 275 0x0000ffff, /* src_mask */ 276 0x0000ffff, /* dst_mask */ 277 TRUE), /* pcrel_offset */ 649 278 650 279 /* 16 bit call through global offset table. */ … … 653 282 2, /* size (0 = byte, 1 = short, 2 = long) */ 654 283 16, /* bitsize */ 655 false, /* pc_relative */284 FALSE, /* pc_relative */ 656 285 0, /* bitpos */ 657 286 complain_overflow_signed, /* complain_on_overflow */ 658 287 bfd_elf_generic_reloc, /* special_function */ 659 288 "R_MIPS_CALL16", /* name */ 660 false, /* partial_inplace */661 0x ffff, /* src_mask */662 0x ffff, /* dst_mask */663 false), /* pcrel_offset */289 TRUE, /* partial_inplace */ 290 0x0000ffff, /* src_mask */ 291 0x0000ffff, /* dst_mask */ 292 FALSE), /* pcrel_offset */ 664 293 665 294 /* 32 bit GP relative reference. */ … … 668 297 2, /* size (0 = byte, 1 = short, 2 = long) */ 669 298 32, /* bitsize */ 670 false, /* pc_relative */671 0, /* bitpos */ 672 complain_overflow_ bitfield, /* complain_on_overflow */673 _bfd_mips_elf_gprel32_reloc, /* special_function */299 FALSE, /* pc_relative */ 300 0, /* bitpos */ 301 complain_overflow_dont, /* complain_on_overflow */ 302 mips_elf_gprel32_reloc, /* special_function */ 674 303 "R_MIPS_GPREL32", /* name */ 675 true, /* partial_inplace */304 TRUE, /* partial_inplace */ 676 305 0xffffffff, /* src_mask */ 677 306 0xffffffff, /* dst_mask */ 678 false), /* pcrel_offset */679 680 681 682 683 684 307 FALSE), /* pcrel_offset */ 308 309 /* The remaining relocs are defined on Irix 5, although they are 310 not defined by the ABI. */ 311 EMPTY_HOWTO (13), 312 EMPTY_HOWTO (14), 313 EMPTY_HOWTO (15), 685 314 686 315 /* A 5 bit shift field. */ … … 689 318 2, /* size (0 = byte, 1 = short, 2 = long) */ 690 319 5, /* bitsize */ 691 false, /* pc_relative */320 FALSE, /* pc_relative */ 692 321 6, /* bitpos */ 693 322 complain_overflow_bitfield, /* complain_on_overflow */ 694 323 bfd_elf_generic_reloc, /* special_function */ 695 324 "R_MIPS_SHIFT5", /* name */ 696 true, /* partial_inplace */325 TRUE, /* partial_inplace */ 697 326 0x000007c0, /* src_mask */ 698 327 0x000007c0, /* dst_mask */ 699 false), /* pcrel_offset */328 FALSE), /* pcrel_offset */ 700 329 701 330 /* A 6 bit shift field. */ … … 706 335 2, /* size (0 = byte, 1 = short, 2 = long) */ 707 336 6, /* bitsize */ 708 false, /* pc_relative */337 FALSE, /* pc_relative */ 709 338 6, /* bitpos */ 710 339 complain_overflow_bitfield, /* complain_on_overflow */ 711 340 bfd_elf_generic_reloc, /* special_function */ 712 341 "R_MIPS_SHIFT6", /* name */ 713 true, /* partial_inplace */342 TRUE, /* partial_inplace */ 714 343 0x000007c4, /* src_mask */ 715 344 0x000007c4, /* dst_mask */ 716 false), /* pcrel_offset */345 FALSE), /* pcrel_offset */ 717 346 718 347 /* A 64 bit relocation. */ … … 721 350 4, /* size (0 = byte, 1 = short, 2 = long) */ 722 351 64, /* bitsize */ 723 false, /* pc_relative */724 0, /* bitpos */ 725 complain_overflow_ bitfield, /* complain_on_overflow */352 FALSE, /* pc_relative */ 353 0, /* bitpos */ 354 complain_overflow_dont, /* complain_on_overflow */ 726 355 mips32_64bit_reloc, /* special_function */ 727 356 "R_MIPS_64", /* name */ 728 true, /* partial_inplace */357 TRUE, /* partial_inplace */ 729 358 MINUS_ONE, /* src_mask */ 730 359 MINUS_ONE, /* dst_mask */ 731 false), /* pcrel_offset */360 FALSE), /* pcrel_offset */ 732 361 733 362 /* Displacement in the global offset table. */ … … 736 365 2, /* size (0 = byte, 1 = short, 2 = long) */ 737 366 16, /* bitsize */ 738 false, /* pc_relative */739 0, /* bitpos */ 740 complain_overflow_ bitfield, /* complain_on_overflow */367 FALSE, /* pc_relative */ 368 0, /* bitpos */ 369 complain_overflow_signed, /* complain_on_overflow */ 741 370 bfd_elf_generic_reloc, /* special_function */ 742 371 "R_MIPS_GOT_DISP", /* name */ 743 true, /* partial_inplace */372 TRUE, /* partial_inplace */ 744 373 0x0000ffff, /* src_mask */ 745 374 0x0000ffff, /* dst_mask */ 746 false), /* pcrel_offset */375 FALSE), /* pcrel_offset */ 747 376 748 377 /* Displacement to page pointer in the global offset table. */ … … 751 380 2, /* size (0 = byte, 1 = short, 2 = long) */ 752 381 16, /* bitsize */ 753 false, /* pc_relative */754 0, /* bitpos */ 755 complain_overflow_ bitfield, /* complain_on_overflow */382 FALSE, /* pc_relative */ 383 0, /* bitpos */ 384 complain_overflow_signed, /* complain_on_overflow */ 756 385 bfd_elf_generic_reloc, /* special_function */ 757 386 "R_MIPS_GOT_PAGE", /* name */ 758 true, /* partial_inplace */387 TRUE, /* partial_inplace */ 759 388 0x0000ffff, /* src_mask */ 760 389 0x0000ffff, /* dst_mask */ 761 false), /* pcrel_offset */390 FALSE), /* pcrel_offset */ 762 391 763 392 /* Offset from page pointer in the global offset table. */ … … 766 395 2, /* size (0 = byte, 1 = short, 2 = long) */ 767 396 16, /* bitsize */ 768 false, /* pc_relative */769 0, /* bitpos */ 770 complain_overflow_ bitfield, /* complain_on_overflow */397 FALSE, /* pc_relative */ 398 0, /* bitpos */ 399 complain_overflow_signed, /* complain_on_overflow */ 771 400 bfd_elf_generic_reloc, /* special_function */ 772 401 "R_MIPS_GOT_OFST", /* name */ 773 true, /* partial_inplace */402 TRUE, /* partial_inplace */ 774 403 0x0000ffff, /* src_mask */ 775 404 0x0000ffff, /* dst_mask */ 776 false), /* pcrel_offset */405 FALSE), /* pcrel_offset */ 777 406 778 407 /* High 16 bits of displacement in global offset table. */ … … 781 410 2, /* size (0 = byte, 1 = short, 2 = long) */ 782 411 16, /* bitsize */ 783 false, /* pc_relative */412 FALSE, /* pc_relative */ 784 413 0, /* bitpos */ 785 414 complain_overflow_dont, /* complain_on_overflow */ 786 415 bfd_elf_generic_reloc, /* special_function */ 787 416 "R_MIPS_GOT_HI16", /* name */ 788 true, /* partial_inplace */417 TRUE, /* partial_inplace */ 789 418 0x0000ffff, /* src_mask */ 790 419 0x0000ffff, /* dst_mask */ 791 false), /* pcrel_offset */420 FALSE), /* pcrel_offset */ 792 421 793 422 /* Low 16 bits of displacement in global offset table. */ … … 796 425 2, /* size (0 = byte, 1 = short, 2 = long) */ 797 426 16, /* bitsize */ 798 false, /* pc_relative */427 FALSE, /* pc_relative */ 799 428 0, /* bitpos */ 800 429 complain_overflow_dont, /* complain_on_overflow */ 801 430 bfd_elf_generic_reloc, /* special_function */ 802 431 "R_MIPS_GOT_LO16", /* name */ 803 true, /* partial_inplace */432 TRUE, /* partial_inplace */ 804 433 0x0000ffff, /* src_mask */ 805 434 0x0000ffff, /* dst_mask */ 806 false), /* pcrel_offset */435 FALSE), /* pcrel_offset */ 807 436 808 437 /* 64 bit subtraction. Used in the N32 ABI. */ … … 811 440 4, /* size (0 = byte, 1 = short, 2 = long) */ 812 441 64, /* bitsize */ 813 false, /* pc_relative */814 0, /* bitpos */ 815 complain_overflow_ bitfield, /* complain_on_overflow */442 FALSE, /* pc_relative */ 443 0, /* bitpos */ 444 complain_overflow_dont, /* complain_on_overflow */ 816 445 bfd_elf_generic_reloc, /* special_function */ 817 446 "R_MIPS_SUB", /* name */ 818 true, /* partial_inplace */447 TRUE, /* partial_inplace */ 819 448 MINUS_ONE, /* src_mask */ 820 449 MINUS_ONE, /* dst_mask */ 821 false), /* pcrel_offset */450 FALSE), /* pcrel_offset */ 822 451 823 452 /* Used to cause the linker to insert and delete instructions? */ … … 831 460 2, /* size (0 = byte, 1 = short, 2 = long) */ 832 461 16, /* bitsize */ 833 false, /* pc_relative */462 FALSE, /* pc_relative */ 834 463 0, /* bitpos */ 835 464 complain_overflow_dont, /* complain_on_overflow */ 836 465 bfd_elf_generic_reloc, /* special_function */ 837 466 "R_MIPS_HIGHER", /* name */ 838 true, /* partial_inplace */839 0 ,/* src_mask */840 0x ffff, /* dst_mask */841 false), /* pcrel_offset */467 TRUE, /* partial_inplace */ 468 0x0000ffff, /* src_mask */ 469 0x0000ffff, /* dst_mask */ 470 FALSE), /* pcrel_offset */ 842 471 843 472 /* Get the highest value of a 64 bit addend. */ … … 846 475 2, /* size (0 = byte, 1 = short, 2 = long) */ 847 476 16, /* bitsize */ 848 false, /* pc_relative */477 FALSE, /* pc_relative */ 849 478 0, /* bitpos */ 850 479 complain_overflow_dont, /* complain_on_overflow */ 851 480 bfd_elf_generic_reloc, /* special_function */ 852 481 "R_MIPS_HIGHEST", /* name */ 853 true, /* partial_inplace */854 0 ,/* src_mask */855 0x ffff, /* dst_mask */856 false), /* pcrel_offset */482 TRUE, /* partial_inplace */ 483 0x0000ffff, /* src_mask */ 484 0x0000ffff, /* dst_mask */ 485 FALSE), /* pcrel_offset */ 857 486 858 487 /* High 16 bits of displacement in global offset table. */ … … 861 490 2, /* size (0 = byte, 1 = short, 2 = long) */ 862 491 16, /* bitsize */ 863 false, /* pc_relative */492 FALSE, /* pc_relative */ 864 493 0, /* bitpos */ 865 494 complain_overflow_dont, /* complain_on_overflow */ 866 495 bfd_elf_generic_reloc, /* special_function */ 867 496 "R_MIPS_CALL_HI16", /* name */ 868 true, /* partial_inplace */497 TRUE, /* partial_inplace */ 869 498 0x0000ffff, /* src_mask */ 870 499 0x0000ffff, /* dst_mask */ 871 false), /* pcrel_offset */500 FALSE), /* pcrel_offset */ 872 501 873 502 /* Low 16 bits of displacement in global offset table. */ … … 876 505 2, /* size (0 = byte, 1 = short, 2 = long) */ 877 506 16, /* bitsize */ 878 false, /* pc_relative */507 FALSE, /* pc_relative */ 879 508 0, /* bitpos */ 880 509 complain_overflow_dont, /* complain_on_overflow */ 881 510 bfd_elf_generic_reloc, /* special_function */ 882 511 "R_MIPS_CALL_LO16", /* name */ 883 true, /* partial_inplace */512 TRUE, /* partial_inplace */ 884 513 0x0000ffff, /* src_mask */ 885 514 0x0000ffff, /* dst_mask */ 886 false), /* pcrel_offset */515 FALSE), /* pcrel_offset */ 887 516 888 517 /* Section displacement. */ … … 891 520 2, /* size (0 = byte, 1 = short, 2 = long) */ 892 521 32, /* bitsize */ 893 false, /* pc_relative */522 FALSE, /* pc_relative */ 894 523 0, /* bitpos */ 895 524 complain_overflow_dont, /* complain_on_overflow */ 896 525 bfd_elf_generic_reloc, /* special_function */ 897 526 "R_MIPS_SCN_DISP", /* name */ 898 false, /* partial_inplace */527 TRUE, /* partial_inplace */ 899 528 0xffffffff, /* src_mask */ 900 529 0xffffffff, /* dst_mask */ 901 false), /* pcrel_offset */530 FALSE), /* pcrel_offset */ 902 531 903 532 EMPTY_HOWTO (R_MIPS_REL16), … … 910 539 HOWTO (R_MIPS_JALR, /* type */ 911 540 0, /* rightshift */ 912 0, /* size (0 = byte, 1 = short, 2 = long) */913 0, /* bitsize */914 false, /* pc_relative */541 2, /* size (0 = byte, 1 = short, 2 = long) */ 542 32, /* bitsize */ 543 FALSE, /* pc_relative */ 915 544 0, /* bitpos */ 916 545 complain_overflow_dont, /* complain_on_overflow */ 917 546 bfd_elf_generic_reloc, /* special_function */ 918 547 "R_MIPS_JALR", /* name */ 919 false, /* partial_inplace */548 FALSE, /* partial_inplace */ 920 549 0x00000000, /* src_mask */ 921 550 0x00000000, /* dst_mask */ 922 false), /* pcrel_offset */551 FALSE), /* pcrel_offset */ 923 552 }; 924 553 … … 930 559 4, /* size (0 = byte, 1 = short, 2 = long) */ 931 560 32, /* bitsize */ 932 false, /* pc_relative */561 FALSE, /* pc_relative */ 933 562 0, /* bitpos */ 934 563 complain_overflow_signed, /* complain_on_overflow */ 935 564 mips32_64bit_reloc, /* special_function */ 936 565 "R_MIPS_64", /* name */ 937 true, /* partial_inplace */566 TRUE, /* partial_inplace */ 938 567 0xffffffff, /* src_mask */ 939 568 0xffffffff, /* dst_mask */ 940 false); /* pcrel_offset */569 FALSE); /* pcrel_offset */ 941 570 942 571 /* The reloc used for the mips16 jump instruction. */ … … 946 575 2, /* size (0 = byte, 1 = short, 2 = long) */ 947 576 26, /* bitsize */ 948 false, /* pc_relative */577 FALSE, /* pc_relative */ 949 578 0, /* bitpos */ 950 579 complain_overflow_dont, /* complain_on_overflow */ … … 954 583 mips16_jump_reloc, /* special_function */ 955 584 "R_MIPS16_26", /* name */ 956 true, /* partial_inplace */585 TRUE, /* partial_inplace */ 957 586 0x3ffffff, /* src_mask */ 958 587 0x3ffffff, /* dst_mask */ 959 false); /* pcrel_offset */588 FALSE); /* pcrel_offset */ 960 589 961 590 /* The reloc used for the mips16 gprel instruction. */ … … 965 594 2, /* size (0 = byte, 1 = short, 2 = long) */ 966 595 16, /* bitsize */ 967 false, /* pc_relative */596 FALSE, /* pc_relative */ 968 597 0, /* bitpos */ 969 598 complain_overflow_signed, /* complain_on_overflow */ 970 599 mips16_gprel_reloc, /* special_function */ 971 600 "R_MIPS16_GPREL", /* name */ 972 true, /* partial_inplace */601 TRUE, /* partial_inplace */ 973 602 0x07ff001f, /* src_mask */ 974 603 0x07ff001f, /* dst_mask */ 975 false); /* pcrel_offset */604 FALSE); /* pcrel_offset */ 976 605 977 606 /* GNU extensions for embedded-pic. */ … … 982 611 2, /* size (0 = byte, 1 = short, 2 = long) */ 983 612 16, /* bitsize */ 984 true, /* pc_relative */985 0, /* bitpos */ 986 complain_overflow_dont, /* complain_on_overflow */ 987 _bfd_mips_elf_hi16_reloc, /* special_function */613 TRUE, /* pc_relative */ 614 0, /* bitpos */ 615 complain_overflow_dont, /* complain_on_overflow */ 616 mips_elf_hi16_reloc, /* special_function */ 988 617 "R_MIPS_GNU_REL_HI16", /* name */ 989 true, /* partial_inplace */618 TRUE, /* partial_inplace */ 990 619 0xffff, /* src_mask */ 991 620 0xffff, /* dst_mask */ 992 true); /* pcrel_offset */621 TRUE); /* pcrel_offset */ 993 622 994 623 /* Low 16 bits of symbol value, pc-relative. */ … … 998 627 2, /* size (0 = byte, 1 = short, 2 = long) */ 999 628 16, /* bitsize */ 1000 true, /* pc_relative */1001 0, /* bitpos */ 1002 complain_overflow_dont, /* complain_on_overflow */ 1003 _bfd_mips_elf_lo16_reloc, /* special_function */629 TRUE, /* pc_relative */ 630 0, /* bitpos */ 631 complain_overflow_dont, /* complain_on_overflow */ 632 mips_elf_lo16_reloc, /* special_function */ 1004 633 "R_MIPS_GNU_REL_LO16", /* name */ 1005 true, /* partial_inplace */634 TRUE, /* partial_inplace */ 1006 635 0xffff, /* src_mask */ 1007 636 0xffff, /* dst_mask */ 1008 true); /* pcrel_offset */637 TRUE); /* pcrel_offset */ 1009 638 1010 639 /* 16 bit offset for pc-relative branches. */ … … 1014 643 2, /* size (0 = byte, 1 = short, 2 = long) */ 1015 644 16, /* bitsize */ 1016 true, /* pc_relative */645 TRUE, /* pc_relative */ 1017 646 0, /* bitpos */ 1018 647 complain_overflow_signed, /* complain_on_overflow */ 1019 648 bfd_elf_generic_reloc, /* special_function */ 1020 649 "R_MIPS_GNU_REL16_S2", /* name */ 1021 true, /* partial_inplace */650 TRUE, /* partial_inplace */ 1022 651 0xffff, /* src_mask */ 1023 652 0xffff, /* dst_mask */ 1024 true); /* pcrel_offset */653 TRUE); /* pcrel_offset */ 1025 654 1026 655 /* 64 bit pc-relative. */ … … 1030 659 4, /* size (0 = byte, 1 = short, 2 = long) */ 1031 660 64, /* bitsize */ 1032 true, /* pc_relative */661 TRUE, /* pc_relative */ 1033 662 0, /* bitpos */ 1034 663 complain_overflow_signed, /* complain_on_overflow */ 1035 664 bfd_elf_generic_reloc, /* special_function */ 1036 665 "R_MIPS_PC64", /* name */ 1037 true, /* partial_inplace */666 TRUE, /* partial_inplace */ 1038 667 MINUS_ONE, /* src_mask */ 1039 668 MINUS_ONE, /* dst_mask */ 1040 true); /* pcrel_offset */669 TRUE); /* pcrel_offset */ 1041 670 1042 671 /* 32 bit pc-relative. */ … … 1046 675 2, /* size (0 = byte, 1 = short, 2 = long) */ 1047 676 32, /* bitsize */ 1048 true, /* pc_relative */677 TRUE, /* pc_relative */ 1049 678 0, /* bitpos */ 1050 679 complain_overflow_signed, /* complain_on_overflow */ 1051 680 bfd_elf_generic_reloc, /* special_function */ 1052 681 "R_MIPS_PC32", /* name */ 1053 true, /* partial_inplace */682 TRUE, /* partial_inplace */ 1054 683 0xffffffff, /* src_mask */ 1055 684 0xffffffff, /* dst_mask */ 1056 true); /* pcrel_offset */685 TRUE); /* pcrel_offset */ 1057 686 1058 687 /* GNU extension to record C++ vtable hierarchy */ … … 1062 691 2, /* size (0 = byte, 1 = short, 2 = long) */ 1063 692 0, /* bitsize */ 1064 false, /* pc_relative */693 FALSE, /* pc_relative */ 1065 694 0, /* bitpos */ 1066 695 complain_overflow_dont, /* complain_on_overflow */ 1067 696 NULL, /* special_function */ 1068 697 "R_MIPS_GNU_VTINHERIT", /* name */ 1069 false, /* partial_inplace */698 FALSE, /* partial_inplace */ 1070 699 0, /* src_mask */ 1071 700 0, /* dst_mask */ 1072 false); /* pcrel_offset */701 FALSE); /* pcrel_offset */ 1073 702 1074 703 /* GNU extension to record C++ vtable member usage */ … … 1078 707 2, /* size (0 = byte, 1 = short, 2 = long) */ 1079 708 0, /* bitsize */ 1080 false, /* pc_relative */709 FALSE, /* pc_relative */ 1081 710 0, /* bitpos */ 1082 711 complain_overflow_dont, /* complain_on_overflow */ 1083 712 _bfd_elf_rel_vtable_reloc_fn, /* special_function */ 1084 713 "R_MIPS_GNU_VTENTRY", /* name */ 1085 false, /* partial_inplace */714 FALSE, /* partial_inplace */ 1086 715 0, /* src_mask */ 1087 716 0, /* dst_mask */ 1088 false); /* pcrel_offset */717 FALSE); /* pcrel_offset */ 1089 718 1090 719 /* Do a R_MIPS_HI16 relocation. This has to be done in combination 1091 720 with a R_MIPS_LO16 reloc, because there is a carry from the LO16 to 1092 721 the HI16. Here we just save the information we need; we do the 1093 actual relocation when we see the LO16. MIPS ELF requires that the 1094 LO16 immediately follow the HI16. As a GNU extension, we permit an 722 actual relocation when we see the LO16. 723 724 MIPS ELF requires that the LO16 immediately follow the HI16. As a 725 GNU extension, for non-pc-relative relocations, we permit an 1095 726 arbitrary number of HI16 relocs to be associated with a single LO16 1096 727 reloc. This extension permits gcc to output the HI and LO relocs 1097 itself. */ 728 itself. 729 730 This cannot be done for PC-relative relocations because both the HI16 731 and LO16 parts of the relocations must be done relative to the LO16 732 part, and there can be carry to or borrow from the HI16 part. */ 1098 733 1099 734 struct mips_hi16 … … 1108 743 static struct mips_hi16 *mips_hi16_list; 1109 744 1110 bfd_reloc_status_type 1111 _bfd_mips_elf_hi16_reloc (abfd, 1112 reloc_entry, 1113 symbol, 1114 data, 1115 input_section, 1116 output_bfd, 1117 error_message) 745 static bfd_reloc_status_type 746 mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data, input_section, 747 output_bfd, error_message) 1118 748 bfd *abfd ATTRIBUTE_UNUSED; 1119 749 arelent *reloc_entry; … … 1128 758 struct mips_hi16 *n; 1129 759 1130 /* If we're relocating, and this an external symbol, we don't want760 /* If we're relocating, and this is an external symbol, we don't want 1131 761 to change anything. */ 1132 762 if (output_bfd != (bfd *) NULL … … 1142 772 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0) 1143 773 { 1144 b oolean relocateable;774 bfd_boolean relocateable; 1145 775 bfd_vma gp; 1146 776 … … 1149 779 1150 780 if (output_bfd != NULL) 1151 relocateable = true;781 relocateable = TRUE; 1152 782 else 1153 783 { 1154 relocateable = false;784 relocateable = FALSE; 1155 785 output_bfd = symbol->section->output_section->owner; 1156 786 } … … 1183 813 1184 814 /* Save the information, and let LO16 do the actual relocation. */ 1185 n = (struct mips_hi16 *) bfd_malloc ( sizeof *n);815 n = (struct mips_hi16 *) bfd_malloc ((bfd_size_type) sizeof *n); 1186 816 if (n == NULL) 1187 817 return bfd_reloc_outofrange; … … 1201 831 R_MIPS_HI16 relocation described above. */ 1202 832 1203 bfd_reloc_status_type 1204 _bfd_mips_elf_lo16_reloc (abfd, 1205 reloc_entry, 1206 symbol, 1207 data, 1208 input_section, 1209 output_bfd, 1210 error_message) 833 static bfd_reloc_status_type 834 mips_elf_lo16_reloc (abfd, reloc_entry, symbol, data, input_section, 835 output_bfd, error_message) 1211 836 bfd *abfd; 1212 837 arelent *reloc_entry; … … 1235 860 find the low 16 bits of the addend needed by the LO16. */ 1236 861 insn = bfd_get_32 (abfd, l->addr); 1237 vallo = (bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address) 1238 & 0xffff); 862 vallo = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address); 863 864 /* The low order 16 bits are always treated as a signed 865 value. */ 866 vallo = ((vallo & 0xffff) ^ 0x8000) - 0x8000; 1239 867 val = ((insn & 0xffff) << 16) + vallo; 1240 868 val += l->addend; 1241 869 1242 /* The low order 16 bits are always treated as a signed 1243 value. Therefore, a negative value in the low order bits 1244 requires an adjustment in the high order bits. We need 1245 to make this adjustment in two ways: once for the bits we 1246 took from the data, and once for the bits we are putting 1247 back in to the data. */ 1248 if ((vallo & 0x8000) != 0) 1249 val -= 0x10000; 1250 if ((val & 0x8000) != 0) 1251 val += 0x10000; 1252 1253 insn = (insn & ~0xffff) | ((val >> 16) & 0xffff); 1254 bfd_put_32 (abfd, insn, l->addr); 870 /* If PC-relative, we need to subtract out the address of the LO 871 half of the HI/LO. (The actual relocation is relative 872 to that instruction.) */ 873 if (reloc_entry->howto->pc_relative) 874 val -= reloc_entry->address; 875 876 /* At this point, "val" has the value of the combined HI/LO 877 pair. If the low order 16 bits (which will be used for 878 the LO16 insn) are negative, then we will need an 879 adjustment for the high order 16 bits. */ 880 val += 0x8000; 881 val = (val >> 16) & 0xffff; 882 883 insn &= ~ (bfd_vma) 0xffff; 884 insn |= val; 885 bfd_put_32 (abfd, (bfd_vma) insn, l->addr); 1255 886 1256 887 if (strcmp (bfd_asymbol_name (symbol), "_gp_disp") == 0) … … 1275 906 /* FIXME: Does this case ever occur? */ 1276 907 1277 ret = mips_elf_final_gp (output_bfd, symbol, true, error_message, &gp);908 ret = mips_elf_final_gp (output_bfd, symbol, TRUE, error_message, &gp); 1278 909 if (ret != bfd_reloc_ok) 1279 910 return ret; … … 1311 942 not yet know how to create global offset tables. */ 1312 943 1313 bfd_reloc_status_type 1314 _bfd_mips_elf_got16_reloc (abfd, 1315 reloc_entry, 1316 symbol, 1317 data, 1318 input_section, 1319 output_bfd, 1320 error_message) 944 static bfd_reloc_status_type 945 mips_elf_got16_reloc (abfd, reloc_entry, symbol, data, input_section, 946 output_bfd, error_message) 1321 947 bfd *abfd; 1322 948 arelent *reloc_entry; … … 1327 953 char **error_message; 1328 954 { 1329 /* If we're relocating, and this an external symbol, we don't want955 /* If we're relocating, and this is an external symbol, we don't want 1330 956 to change anything. */ 1331 957 if (output_bfd != (bfd *) NULL … … 1341 967 if (output_bfd != (bfd *) NULL 1342 968 && (symbol->flags & BSF_SECTION_SYM) != 0) 1343 return _bfd_mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data,1344 969 return mips_elf_hi16_reloc (abfd, reloc_entry, symbol, data, 970 input_section, output_bfd, error_message); 1345 971 1346 972 abort (); 1347 973 } 1348 974 1349 /* Set the GP value for OUTPUT_BFD. Returns falseif this is a975 /* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a 1350 976 dangerous relocation. */ 1351 977 1352 static b oolean978 static bfd_boolean 1353 979 mips_elf_assign_gp (output_bfd, pgp) 1354 980 bfd *output_bfd; … … 1362 988 *pgp = _bfd_get_gp_value (output_bfd); 1363 989 if (*pgp) 1364 return true;990 return TRUE; 1365 991 1366 992 count = bfd_get_symcount (output_bfd); … … 1375 1001 for (i = 0; i < count; i++, sym++) 1376 1002 { 1377 register CONSTchar *name;1003 register const char *name; 1378 1004 1379 1005 name = bfd_asymbol_name (*sym); … … 1392 1018 *pgp = 4; 1393 1019 _bfd_set_gp_value (output_bfd, *pgp); 1394 return false;1395 } 1396 1397 return true;1020 return FALSE; 1021 } 1022 1023 return TRUE; 1398 1024 } 1399 1025 … … 1408 1034 bfd *output_bfd; 1409 1035 asymbol *symbol; 1410 b oolean relocateable;1036 bfd_boolean relocateable; 1411 1037 char **error_message; 1412 1038 bfd_vma *pgp; … … 1447 1073 merged. */ 1448 1074 1449 static bfd_reloc_status_type gprel16_with_gp PARAMS ((bfd *, asymbol *,1450 arelent *, asection *,1451 boolean, PTR, bfd_vma));1452 1453 1075 bfd_reloc_status_type 1454 _bfd_mips_elf _gprel16_reloc (abfd, reloc_entry, symbol, data, input_section,1455 output_bfd, error_message)1076 _bfd_mips_elf32_gprel16_reloc (abfd, reloc_entry, symbol, data, input_section, 1077 output_bfd, error_message) 1456 1078 bfd *abfd; 1457 1079 arelent *reloc_entry; … … 1462 1084 char **error_message; 1463 1085 { 1464 b oolean relocateable;1086 bfd_boolean relocateable; 1465 1087 bfd_reloc_status_type ret; 1466 1088 bfd_vma gp; … … 1479 1101 1480 1102 if (output_bfd != (bfd *) NULL) 1481 relocateable = true;1103 relocateable = TRUE; 1482 1104 else 1483 1105 { 1484 relocateable = false;1106 relocateable = FALSE; 1485 1107 output_bfd = symbol->section->output_section->owner; 1486 1108 } … … 1491 1113 return ret; 1492 1114 1493 return gprel16_with_gp (abfd, symbol, reloc_entry, input_section, 1494 relocateable, data, gp); 1495 } 1115 return _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry, 1116 input_section, relocateable, 1117 data, gp); 1118 } 1119 1120 /* Do a R_MIPS_GPREL32 relocation. This is a 32 bit value which must 1121 become the offset from the gp register. */ 1122 1123 static bfd_reloc_status_type gprel32_with_gp 1124 PARAMS ((bfd *, asymbol *, arelent *, asection *, bfd_boolean, PTR, 1125 bfd_vma)); 1496 1126 1497 1127 static bfd_reloc_status_type 1498 gprel16_with_gp (abfd, symbol, reloc_entry, input_section, relocateable, data, 1499 gp) 1500 bfd *abfd; 1501 asymbol *symbol; 1502 arelent *reloc_entry; 1503 asection *input_section; 1504 boolean relocateable; 1505 PTR data; 1506 bfd_vma gp; 1507 { 1508 bfd_vma relocation; 1509 unsigned long insn; 1510 unsigned long val; 1511 1512 if (bfd_is_com_section (symbol->section)) 1513 relocation = 0; 1514 else 1515 relocation = symbol->value; 1516 1517 relocation += symbol->section->output_section->vma; 1518 relocation += symbol->section->output_offset; 1519 1520 if (reloc_entry->address > input_section->_cooked_size) 1521 return bfd_reloc_outofrange; 1522 1523 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address); 1524 1525 /* Set val to the offset into the section or symbol. */ 1526 if (reloc_entry->howto->src_mask == 0) 1527 { 1528 /* This case occurs with the 64-bit MIPS ELF ABI. */ 1529 val = reloc_entry->addend; 1530 } 1531 else 1532 { 1533 val = ((insn & 0xffff) + reloc_entry->addend) & 0xffff; 1534 if (val & 0x8000) 1535 val -= 0x10000; 1536 } 1537 1538 /* Adjust val for the final section location and GP value. If we 1539 are producing relocateable output, we don't want to do this for 1540 an external symbol. */ 1541 if (! relocateable 1542 || (symbol->flags & BSF_SECTION_SYM) != 0) 1543 val += relocation - gp; 1544 1545 insn = (insn & ~0xffff) | (val & 0xffff); 1546 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address); 1547 1548 if (relocateable) 1549 reloc_entry->address += input_section->output_offset; 1550 1551 /* Make sure it fit in 16 bits. */ 1552 if ((long) val >= 0x8000 || (long) val < -0x8000) 1553 return bfd_reloc_overflow; 1554 1555 return bfd_reloc_ok; 1556 } 1557 1558 /* Do a R_MIPS_GPREL32 relocation. Is this 32 bit value the offset 1559 from the gp register? XXX */ 1560 1561 static bfd_reloc_status_type gprel32_with_gp PARAMS ((bfd *, asymbol *, 1562 arelent *, asection *, 1563 boolean, PTR, bfd_vma)); 1564 1565 bfd_reloc_status_type 1566 _bfd_mips_elf_gprel32_reloc (abfd, 1567 reloc_entry, 1568 symbol, 1569 data, 1570 input_section, 1571 output_bfd, 1572 error_message) 1128 mips_elf_gprel32_reloc (abfd, reloc_entry, symbol, data, input_section, 1129 output_bfd, error_message) 1573 1130 bfd *abfd; 1574 1131 arelent *reloc_entry; … … 1579 1136 char **error_message; 1580 1137 { 1581 b oolean relocateable;1138 bfd_boolean relocateable; 1582 1139 bfd_reloc_status_type ret; 1583 1140 bfd_vma gp; … … 1598 1155 if (output_bfd != (bfd *) NULL) 1599 1156 { 1600 relocateable = true;1157 relocateable = TRUE; 1601 1158 gp = _bfd_get_gp_value (output_bfd); 1602 1159 } 1603 1160 else 1604 1161 { 1605 relocateable = false;1162 relocateable = FALSE; 1606 1163 output_bfd = symbol->section->output_section->owner; 1607 1164 … … 1623 1180 arelent *reloc_entry; 1624 1181 asection *input_section; 1625 b oolean relocateable;1182 bfd_boolean relocateable; 1626 1183 PTR data; 1627 1184 bfd_vma gp; … … 1659 1216 val += relocation - gp; 1660 1217 1661 bfd_put_32 (abfd, val, (bfd_byte *) data + reloc_entry->address);1218 bfd_put_32 (abfd, (bfd_vma) val, (bfd_byte *) data + reloc_entry->address); 1662 1219 1663 1220 if (relocateable) … … 1696 1253 if (bfd_big_endian (abfd)) 1697 1254 reloc32.address += 4; 1698 reloc32.howto = &elf_mips_howto_table [R_MIPS_32];1255 reloc32.howto = &elf_mips_howto_table_rel[R_MIPS_32]; 1699 1256 r = bfd_perform_relocation (abfd, &reloc32, data, input_section, 1700 1257 output_bfd, error_message); … … 1709 1266 if (bfd_little_endian (abfd)) 1710 1267 addr += 4; 1711 bfd_put_32 (abfd, val, (bfd_byte *) data + addr);1268 bfd_put_32 (abfd, (bfd_vma) val, (bfd_byte *) data + addr); 1712 1269 1713 1270 return r; … … 1737 1294 /* FIXME. */ 1738 1295 { 1739 static b oolean warned;1296 static bfd_boolean warned; 1740 1297 1741 1298 if (! warned) … … 1743 1300 (_("Linking mips16 objects into %s format is not supported"), 1744 1301 bfd_get_target (input_section->output_section->owner)); 1745 warned = true;1302 warned = TRUE; 1746 1303 } 1747 1304 … … 1762 1319 char **error_message; 1763 1320 { 1764 b oolean relocateable;1321 bfd_boolean relocateable; 1765 1322 bfd_reloc_status_type ret; 1766 1323 bfd_vma gp; … … 1781 1338 1782 1339 if (output_bfd != NULL) 1783 relocateable = true;1340 relocateable = TRUE; 1784 1341 else 1785 1342 { 1786 relocateable = false;1343 relocateable = FALSE; 1787 1344 output_bfd = symbol->section->output_section->owner; 1788 1345 } … … 1803 1360 relocation, and then clean up. */ 1804 1361 bfd_put_32 (abfd, 1805 ( ((extend & 0x1f) << 11)1806 1807 1362 (bfd_vma) (((extend & 0x1f) << 11) 1363 | (extend & 0x7e0) 1364 | (insn & 0x1f)), 1808 1365 (bfd_byte *) data + reloc_entry->address); 1809 1366 1810 ret = gprel16_with_gp (abfd, symbol, reloc_entry, input_section,1811 relocateable, data, gp);1367 ret = _bfd_mips_elf_gprel16_with_gp (abfd, symbol, reloc_entry, 1368 input_section, relocateable, data, gp); 1812 1369 1813 1370 final = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address); 1814 1371 bfd_put_16 (abfd, 1815 ( (extend & 0xf800)1816 1817 1372 (bfd_vma) ((extend & 0xf800) 1373 | ((final >> 11) & 0x1f) 1374 | (final & 0x7e0)), 1818 1375 (bfd_byte *) data + reloc_entry->address); 1819 1376 bfd_put_16 (abfd, 1820 ( (insn & 0xffe0)1821 1377 (bfd_vma) ((insn & 0xffe0) 1378 | (final & 0x1f)), 1822 1379 (bfd_byte *) data + reloc_entry->address + 2); 1823 1380 … … 1825 1382 } 1826 1383 1827 /* Return the ISA for a MIPS e_flags value. */1828 1829 static INLINE int1830 elf_mips_isa (flags)1831 flagword flags;1832 {1833 switch (flags & EF_MIPS_ARCH)1834 {1835 case E_MIPS_ARCH_1:1836 return 1;1837 case E_MIPS_ARCH_2:1838 return 2;1839 case E_MIPS_ARCH_3:1840 return 3;1841 case E_MIPS_ARCH_4:1842 return 4;1843 case E_MIPS_ARCH_5:1844 return 5;1845 case E_MIPS_ARCH_32:1846 return 32;1847 case E_MIPS_ARCH_64:1848 return 64;1849 }1850 return 4;1851 }1852 1853 /* Return the MACH for a MIPS e_flags value. */1854 1855 static INLINE int1856 elf_mips_mach (flags)1857 flagword flags;1858 {1859 switch (flags & EF_MIPS_MACH)1860 {1861 case E_MIPS_MACH_3900:1862 return bfd_mach_mips3900;1863 1864 case E_MIPS_MACH_4010:1865 return bfd_mach_mips4010;1866 1867 case E_MIPS_MACH_4100:1868 return bfd_mach_mips4100;1869 1870 case E_MIPS_MACH_4111:1871 return bfd_mach_mips4111;1872 1873 case E_MIPS_MACH_4650:1874 return bfd_mach_mips4650;1875 1876 case E_MIPS_MACH_MIPS32_4K:1877 return bfd_mach_mips32_4k;1878 1879 case E_MIPS_MACH_SB1:1880 return bfd_mach_mips_sb1;1881 1882 default:1883 switch (flags & EF_MIPS_ARCH)1884 {1885 default:1886 case E_MIPS_ARCH_1:1887 return bfd_mach_mips3000;1888 break;1889 1890 case E_MIPS_ARCH_2:1891 return bfd_mach_mips6000;1892 break;1893 1894 case E_MIPS_ARCH_3:1895 return bfd_mach_mips4000;1896 break;1897 1898 case E_MIPS_ARCH_4:1899 return bfd_mach_mips8000;1900 break;1901 1902 case E_MIPS_ARCH_5:1903 return bfd_mach_mips5;1904 break;1905 1906 case E_MIPS_ARCH_32:1907 return bfd_mach_mips32;1908 break;1909 1910 case E_MIPS_ARCH_64:1911 return bfd_mach_mips64;1912 break;1913 }1914 }1915 1916 return 0;1917 }1918 1919 /* Return printable name for ABI. */1920 1921 static INLINE char *1922 elf_mips_abi_name (abfd)1923 bfd *abfd;1924 {1925 flagword flags;1926 1927 if (ABI_N32_P (abfd))1928 return "N32";1929 else if (ABI_64_P (abfd))1930 return "64";1931 1932 flags = elf_elfheader (abfd)->e_flags;1933 switch (flags & EF_MIPS_ABI)1934 {1935 case 0:1936 return "none";1937 case E_MIPS_ABI_O32:1938 return "O32";1939 case E_MIPS_ABI_O64:1940 return "O64";1941 case E_MIPS_ABI_EABI32:1942 return "EABI32";1943 case E_MIPS_ABI_EABI64:1944 return "EABI64";1945 default:1946 return "unknown abi";1947 }1948 }1949 1950 1384 /* A mapping from BFD reloc types to MIPS ELF reloc types. */ 1951 1385 1952 1386 struct elf_reloc_map { 1953 bfd_reloc_code_real_type bfd_ reloc_val;1954 enum elf_mips_reloc_type elf_ reloc_val;1387 bfd_reloc_code_real_type bfd_val; 1388 enum elf_mips_reloc_type elf_val; 1955 1389 }; 1956 1390 1957 static CONSTstruct elf_reloc_map mips_reloc_map[] =1958 { 1959 { BFD_RELOC_NONE, R_MIPS_NONE ,},1391 static const struct elf_reloc_map mips_reloc_map[] = 1392 { 1393 { BFD_RELOC_NONE, R_MIPS_NONE }, 1960 1394 { BFD_RELOC_16, R_MIPS_16 }, 1961 1395 { BFD_RELOC_32, R_MIPS_32 }, 1396 /* There is no BFD reloc for R_MIPS_REL32. */ 1962 1397 { BFD_RELOC_64, R_MIPS_64 }, 1963 1398 { BFD_RELOC_MIPS_JMP, R_MIPS_26 }, 1964 1399 { BFD_RELOC_HI16_S, R_MIPS_HI16 }, 1965 1400 { BFD_RELOC_LO16, R_MIPS_LO16 }, 1966 { BFD_RELOC_ MIPS_GPREL, R_MIPS_GPREL16 },1401 { BFD_RELOC_GPREL16, R_MIPS_GPREL16 }, 1967 1402 { BFD_RELOC_MIPS_LITERAL, R_MIPS_LITERAL }, 1968 1403 { BFD_RELOC_MIPS_GOT16, R_MIPS_GOT16 }, 1969 1404 { BFD_RELOC_16_PCREL, R_MIPS_PC16 }, 1970 1405 { BFD_RELOC_MIPS_CALL16, R_MIPS_CALL16 }, 1971 { BFD_RELOC_ MIPS_GPREL32, R_MIPS_GPREL32 },1406 { BFD_RELOC_GPREL32, R_MIPS_GPREL32 }, 1972 1407 { BFD_RELOC_MIPS_GOT_HI16, R_MIPS_GOT_HI16 }, 1973 1408 { BFD_RELOC_MIPS_GOT_LO16, R_MIPS_GOT_LO16 }, … … 1988 1423 { 1989 1424 unsigned int i; 1990 1991 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); i++) 1992 { 1993 if (mips_reloc_map[i].bfd_reloc_val == code) 1994 return &elf_mips_howto_table[(int) mips_reloc_map[i].elf_reloc_val]; 1425 reloc_howto_type *howto_table = elf_mips_howto_table_rel; 1426 1427 for (i = 0; i < sizeof (mips_reloc_map) / sizeof (struct elf_reloc_map); 1428 i++) 1429 { 1430 if (mips_reloc_map[i].bfd_val == code) 1431 return &howto_table[(int) mips_reloc_map[i].elf_val]; 1995 1432 } 1996 1433 … … 2004 1441 /* We need to handle BFD_RELOC_CTOR specially. 2005 1442 Select the right relocation (R_MIPS_32 or R_MIPS_64) based on the 2006 size of addresses on this architecture. */ 2007 if (bfd_arch_bits_per_address (abfd) == 32) 2008 return &elf_mips_howto_table[(int) R_MIPS_32]; 1443 size of addresses of the ABI. */ 1444 if ((elf_elfheader (abfd)->e_flags & (E_MIPS_ABI_O64 1445 | E_MIPS_ABI_EABI64)) != 0) 1446 return &elf_mips_ctor64_howto; 2009 1447 else 2010 return & elf_mips_ctor64_howto;1448 return &howto_table[(int) R_MIPS_32]; 2011 1449 2012 1450 case BFD_RELOC_MIPS16_JMP: … … 2031 1469 } 2032 1470 2033 /* Given a MIPS Elf 32_Internal_Rel, fill in an arelent structure. */1471 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */ 2034 1472 2035 1473 static reloc_howto_type * 2036 mips_ rtype_to_howto (r_type)1474 mips_elf32_rtype_to_howto (r_type, rela_p) 2037 1475 unsigned int r_type; 1476 bfd_boolean rela_p ATTRIBUTE_UNUSED; 2038 1477 { 2039 1478 switch (r_type) … … 2041 1480 case R_MIPS16_26: 2042 1481 return &elf_mips16_jump_howto; 2043 break;2044 1482 case R_MIPS16_GPREL: 2045 1483 return &elf_mips16_gprel_howto; 2046 break;2047 1484 case R_MIPS_GNU_VTINHERIT: 2048 1485 return &elf_mips_gnu_vtinherit_howto; 2049 break;2050 1486 case R_MIPS_GNU_VTENTRY: 2051 1487 return &elf_mips_gnu_vtentry_howto; 2052 break;2053 1488 case R_MIPS_GNU_REL_HI16: 2054 1489 return &elf_mips_gnu_rel_hi16; 2055 break;2056 1490 case R_MIPS_GNU_REL_LO16: 2057 1491 return &elf_mips_gnu_rel_lo16; 2058 break;2059 1492 case R_MIPS_GNU_REL16_S2: 2060 1493 return &elf_mips_gnu_rel16_s2; 2061 break;2062 1494 case R_MIPS_PC64: 2063 1495 return &elf_mips_gnu_pcrel64; 2064 break;2065 1496 case R_MIPS_PC32: 2066 1497 return &elf_mips_gnu_pcrel32; 2067 break;2068 2069 1498 default: 2070 1499 BFD_ASSERT (r_type < (unsigned int) R_MIPS_max); 2071 return &elf_mips_howto_table[r_type]; 2072 break; 2073 } 2074 } 2075 2076 /* Given a MIPS Elf32_Internal_Rel, fill in an arelent structure. */ 1500 return &elf_mips_howto_table_rel[r_type]; 1501 } 1502 } 1503 1504 /* Given a MIPS Elf_Internal_Rel, fill in an arelent structure. */ 2077 1505 2078 1506 static void … … 2080 1508 bfd *abfd; 2081 1509 arelent *cache_ptr; 2082 Elf 32_Internal_Rel*dst;1510 Elf_Internal_Rela *dst; 2083 1511 { 2084 1512 unsigned int r_type; 2085 1513 2086 1514 r_type = ELF32_R_TYPE (dst->r_info); 2087 cache_ptr->howto = mips_ rtype_to_howto (r_type);1515 cache_ptr->howto = mips_elf32_rtype_to_howto (r_type, FALSE); 2088 1516 2089 1517 /* The addend for a GPREL16 or LITERAL relocation comes from the GP … … 2097 1525 } 2098 1526 2099 /* Given a MIPS Elf 32_Internal_Rela, fill in an arelent structure. */1527 /* Given a MIPS Elf_Internal_Rela, fill in an arelent structure. */ 2100 1528 2101 1529 static void … … 2103 1531 bfd *abfd; 2104 1532 arelent *cache_ptr; 2105 Elf32_Internal_Rela *dst; 2106 { 2107 /* Since an Elf32_Internal_Rel is an initial prefix of an 2108 Elf32_Internal_Rela, we can just use mips_info_to_howto_rel 2109 above. */ 2110 mips_info_to_howto_rel (abfd, cache_ptr, (Elf32_Internal_Rel *) dst); 1533 Elf_Internal_Rela *dst; 1534 { 1535 mips_info_to_howto_rel (abfd, cache_ptr, dst); 2111 1536 2112 1537 /* If we ever need to do any extra processing with dst->r_addend 2113 (the field omitted in an Elf32_Internal_Rel) we can do it here. */ 2114 } 2115 2116 2117 /* A .reginfo section holds a single Elf32_RegInfo structure. These 2118 routines swap this structure in and out. They are used outside of 2119 BFD, so they are globally visible. */ 2120 2121 void 2122 bfd_mips_elf32_swap_reginfo_in (abfd, ex, in) 2123 bfd *abfd; 2124 const Elf32_External_RegInfo *ex; 2125 Elf32_RegInfo *in; 2126 { 2127 in->ri_gprmask = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gprmask); 2128 in->ri_cprmask[0] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[0]); 2129 in->ri_cprmask[1] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[1]); 2130 in->ri_cprmask[2] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[2]); 2131 in->ri_cprmask[3] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[3]); 2132 in->ri_gp_value = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gp_value); 2133 } 2134 2135 void 2136 bfd_mips_elf32_swap_reginfo_out (abfd, in, ex) 2137 bfd *abfd; 2138 const Elf32_RegInfo *in; 2139 Elf32_External_RegInfo *ex; 2140 { 2141 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gprmask, 2142 (bfd_byte *) ex->ri_gprmask); 2143 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[0], 2144 (bfd_byte *) ex->ri_cprmask[0]); 2145 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[1], 2146 (bfd_byte *) ex->ri_cprmask[1]); 2147 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[2], 2148 (bfd_byte *) ex->ri_cprmask[2]); 2149 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[3], 2150 (bfd_byte *) ex->ri_cprmask[3]); 2151 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gp_value, 2152 (bfd_byte *) ex->ri_gp_value); 2153 } 2154 2155 /* In the 64 bit ABI, the .MIPS.options section holds register 2156 information in an Elf64_Reginfo structure. These routines swap 2157 them in and out. They are globally visible because they are used 2158 outside of BFD. These routines are here so that gas can call them 2159 without worrying about whether the 64 bit ABI has been included. */ 2160 2161 void 2162 bfd_mips_elf64_swap_reginfo_in (abfd, ex, in) 2163 bfd *abfd; 2164 const Elf64_External_RegInfo *ex; 2165 Elf64_Internal_RegInfo *in; 2166 { 2167 in->ri_gprmask = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_gprmask); 2168 in->ri_pad = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_pad); 2169 in->ri_cprmask[0] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[0]); 2170 in->ri_cprmask[1] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[1]); 2171 in->ri_cprmask[2] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[2]); 2172 in->ri_cprmask[3] = bfd_h_get_32 (abfd, (bfd_byte *) ex->ri_cprmask[3]); 2173 in->ri_gp_value = bfd_h_get_64 (abfd, (bfd_byte *) ex->ri_gp_value); 2174 } 2175 2176 void 2177 bfd_mips_elf64_swap_reginfo_out (abfd, in, ex) 2178 bfd *abfd; 2179 const Elf64_Internal_RegInfo *in; 2180 Elf64_External_RegInfo *ex; 2181 { 2182 bfd_h_put_32 (abfd, (bfd_vma) in->ri_gprmask, 2183 (bfd_byte *) ex->ri_gprmask); 2184 bfd_h_put_32 (abfd, (bfd_vma) in->ri_pad, 2185 (bfd_byte *) ex->ri_pad); 2186 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[0], 2187 (bfd_byte *) ex->ri_cprmask[0]); 2188 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[1], 2189 (bfd_byte *) ex->ri_cprmask[1]); 2190 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[2], 2191 (bfd_byte *) ex->ri_cprmask[2]); 2192 bfd_h_put_32 (abfd, (bfd_vma) in->ri_cprmask[3], 2193 (bfd_byte *) ex->ri_cprmask[3]); 2194 bfd_h_put_64 (abfd, (bfd_vma) in->ri_gp_value, 2195 (bfd_byte *) ex->ri_gp_value); 2196 } 2197 2198 /* Swap an entry in a .gptab section. Note that these routines rely 2199 on the equivalence of the two elements of the union. */ 2200 2201 static void 2202 bfd_mips_elf32_swap_gptab_in (abfd, ex, in) 2203 bfd *abfd; 2204 const Elf32_External_gptab *ex; 2205 Elf32_gptab *in; 2206 { 2207 in->gt_entry.gt_g_value = bfd_h_get_32 (abfd, ex->gt_entry.gt_g_value); 2208 in->gt_entry.gt_bytes = bfd_h_get_32 (abfd, ex->gt_entry.gt_bytes); 2209 } 2210 2211 static void 2212 bfd_mips_elf32_swap_gptab_out (abfd, in, ex) 2213 bfd *abfd; 2214 const Elf32_gptab *in; 2215 Elf32_External_gptab *ex; 2216 { 2217 bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_g_value, 2218 ex->gt_entry.gt_g_value); 2219 bfd_h_put_32 (abfd, (bfd_vma) in->gt_entry.gt_bytes, 2220 ex->gt_entry.gt_bytes); 2221 } 2222 2223 static void 2224 bfd_elf32_swap_compact_rel_out (abfd, in, ex) 2225 bfd *abfd; 2226 const Elf32_compact_rel *in; 2227 Elf32_External_compact_rel *ex; 2228 { 2229 bfd_h_put_32 (abfd, (bfd_vma) in->id1, ex->id1); 2230 bfd_h_put_32 (abfd, (bfd_vma) in->num, ex->num); 2231 bfd_h_put_32 (abfd, (bfd_vma) in->id2, ex->id2); 2232 bfd_h_put_32 (abfd, (bfd_vma) in->offset, ex->offset); 2233 bfd_h_put_32 (abfd, (bfd_vma) in->reserved0, ex->reserved0); 2234 bfd_h_put_32 (abfd, (bfd_vma) in->reserved1, ex->reserved1); 2235 } 2236 2237 static void 2238 bfd_elf32_swap_crinfo_out (abfd, in, ex) 2239 bfd *abfd; 2240 const Elf32_crinfo *in; 2241 Elf32_External_crinfo *ex; 2242 { 2243 unsigned long l; 2244 2245 l = (((in->ctype & CRINFO_CTYPE) << CRINFO_CTYPE_SH) 2246 | ((in->rtype & CRINFO_RTYPE) << CRINFO_RTYPE_SH) 2247 | ((in->dist2to & CRINFO_DIST2TO) << CRINFO_DIST2TO_SH) 2248 | ((in->relvaddr & CRINFO_RELVADDR) << CRINFO_RELVADDR_SH)); 2249 bfd_h_put_32 (abfd, (bfd_vma) l, ex->info); 2250 bfd_h_put_32 (abfd, (bfd_vma) in->konst, ex->konst); 2251 bfd_h_put_32 (abfd, (bfd_vma) in->vaddr, ex->vaddr); 2252 } 2253 2254 /* Swap in an options header. */ 2255 2256 void 2257 bfd_mips_elf_swap_options_in (abfd, ex, in) 2258 bfd *abfd; 2259 const Elf_External_Options *ex; 2260 Elf_Internal_Options *in; 2261 { 2262 in->kind = bfd_h_get_8 (abfd, ex->kind); 2263 in->size = bfd_h_get_8 (abfd, ex->size); 2264 in->section = bfd_h_get_16 (abfd, ex->section); 2265 in->info = bfd_h_get_32 (abfd, ex->info); 2266 } 2267 2268 /* Swap out an options header. */ 2269 2270 void 2271 bfd_mips_elf_swap_options_out (abfd, in, ex) 2272 bfd *abfd; 2273 const Elf_Internal_Options *in; 2274 Elf_External_Options *ex; 2275 { 2276 bfd_h_put_8 (abfd, in->kind, ex->kind); 2277 bfd_h_put_8 (abfd, in->size, ex->size); 2278 bfd_h_put_16 (abfd, in->section, ex->section); 2279 bfd_h_put_32 (abfd, in->info, ex->info); 2280 } 2281 #if 0 2282 /* Swap in an MSYM entry. */ 2283 2284 static void 2285 bfd_mips_elf_swap_msym_in (abfd, ex, in) 2286 bfd *abfd; 2287 const Elf32_External_Msym *ex; 2288 Elf32_Internal_Msym *in; 2289 { 2290 in->ms_hash_value = bfd_h_get_32 (abfd, ex->ms_hash_value); 2291 in->ms_info = bfd_h_get_32 (abfd, ex->ms_info); 2292 } 2293 #endif 2294 /* Swap out an MSYM entry. */ 2295 2296 static void 2297 bfd_mips_elf_swap_msym_out (abfd, in, ex) 2298 bfd *abfd; 2299 const Elf32_Internal_Msym *in; 2300 Elf32_External_Msym *ex; 2301 { 2302 bfd_h_put_32 (abfd, in->ms_hash_value, ex->ms_hash_value); 2303 bfd_h_put_32 (abfd, in->ms_info, ex->ms_info); 1538 (the field omitted in an Elf_Internal_Rel) we can do it here. */ 2304 1539 } 2305 1540 … … 2311 1546 and externally visible symbols. */ 2312 1547 2313 static b oolean1548 static bfd_boolean 2314 1549 mips_elf_sym_is_global (abfd, sym) 2315 1550 bfd *abfd ATTRIBUTE_UNUSED; 2316 1551 asymbol *sym; 2317 1552 { 2318 if (SGI_COMPAT (abfd))2319 return (sym->flags & BSF_SECTION_SYM) == 0 ? true : false;1553 if (SGI_COMPAT (abfd)) 1554 return (sym->flags & BSF_SECTION_SYM) == 0; 2320 1555 else 2321 1556 return ((sym->flags & (BSF_GLOBAL | BSF_WEAK)) != 0 2322 || bfd_is_und_section (bfd_get_section (sym)) 2323 || bfd_is_com_section (bfd_get_section (sym))); 2324 } 2325 2326 2327 /* Set the right machine number for a MIPS ELF file. This is used for 2328 both the 32-bit and the 64-bit ABI. */ 2329 2330 boolean 2331 _bfd_mips_elf_object_p (abfd) 1557 || bfd_is_und_section (bfd_get_section (sym)) 1558 || bfd_is_com_section (bfd_get_section (sym))); 1559 } 1560 1561 1562 /* Set the right machine number for a MIPS ELF file. */ 1563 1564 static bfd_boolean 1565 mips_elf32_object_p (abfd) 2332 1566 bfd *abfd; 2333 1567 { 2334 /* Irix 5 and 6 is broken. Object file symbol tables are not always 1568 unsigned long mach; 1569 1570 /* Irix 5 and 6 are broken. Object file symbol tables are not always 2335 1571 sorted correctly such that local symbols precede global symbols, 2336 1572 and the sh_info field in the symbol table is not always right. */ 2337 elf_bad_symtab (abfd) = true; 2338 2339 bfd_default_set_arch_mach (abfd, bfd_arch_mips, 2340 elf_mips_mach (elf_elfheader (abfd)->e_flags)); 2341 return true; 2342 } 2343 2344 /* The final processing done just before writing out a MIPS ELF object 2345 file. This gets the MIPS architecture right based on the machine 2346 number. This is used by both the 32-bit and the 64-bit ABI. */ 2347 2348 void 2349 _bfd_mips_elf_final_write_processing (abfd, linker) 2350 bfd *abfd; 2351 boolean linker ATTRIBUTE_UNUSED; 2352 { 2353 unsigned long val; 2354 unsigned int i; 2355 Elf_Internal_Shdr **hdrpp; 2356 const char *name; 2357 asection *sec; 2358 2359 switch (bfd_get_mach (abfd)) 2360 { 2361 default: 2362 case bfd_mach_mips3000: 2363 val = E_MIPS_ARCH_1; 2364 break; 2365 2366 case bfd_mach_mips3900: 2367 val = E_MIPS_ARCH_1 | E_MIPS_MACH_3900; 2368 break; 2369 2370 case bfd_mach_mips6000: 2371 val = E_MIPS_ARCH_2; 2372 break; 2373 2374 case bfd_mach_mips4000: 2375 case bfd_mach_mips4300: 2376 val = E_MIPS_ARCH_3; 2377 break; 2378 2379 case bfd_mach_mips4010: 2380 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4010; 2381 break; 2382 2383 case bfd_mach_mips4100: 2384 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4100; 2385 break; 2386 2387 case bfd_mach_mips4111: 2388 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4111; 2389 break; 2390 2391 case bfd_mach_mips4650: 2392 val = E_MIPS_ARCH_3 | E_MIPS_MACH_4650; 2393 break; 2394 2395 case bfd_mach_mips8000: 2396 case bfd_mach_mips10000: 2397 case bfd_mach_mips12000: 2398 val = E_MIPS_ARCH_4; 2399 break; 2400 2401 case bfd_mach_mips32: 2402 val = E_MIPS_ARCH_32; 2403 break; 2404 2405 case bfd_mach_mips32_4k: 2406 val = E_MIPS_ARCH_32 | E_MIPS_MACH_MIPS32_4K; 2407 break; 2408 2409 case bfd_mach_mips5: 2410 val = E_MIPS_ARCH_5; 2411 break; 2412 2413 case bfd_mach_mips64: 2414 val = E_MIPS_ARCH_64; 2415 break; 2416 2417 case bfd_mach_mips_sb1: 2418 val = E_MIPS_ARCH_64 | E_MIPS_MACH_SB1; 2419 break; 2420 } 2421 2422 elf_elfheader (abfd)->e_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH); 2423 elf_elfheader (abfd)->e_flags |= val; 2424 2425 /* Set the sh_info field for .gptab sections and other appropriate 2426 info for each special section. */ 2427 for (i = 1, hdrpp = elf_elfsections (abfd) + 1; 2428 i < elf_elfheader (abfd)->e_shnum; 2429 i++, hdrpp++) 2430 { 2431 switch ((*hdrpp)->sh_type) 2432 { 2433 case SHT_MIPS_MSYM: 2434 case SHT_MIPS_LIBLIST: 2435 sec = bfd_get_section_by_name (abfd, ".dynstr"); 2436 if (sec != NULL) 2437 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx; 2438 break; 2439 2440 case SHT_MIPS_GPTAB: 2441 BFD_ASSERT ((*hdrpp)->bfd_section != NULL); 2442 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section); 2443 BFD_ASSERT (name != NULL 2444 && strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0); 2445 sec = bfd_get_section_by_name (abfd, name + sizeof ".gptab" - 1); 2446 BFD_ASSERT (sec != NULL); 2447 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx; 2448 break; 2449 2450 case SHT_MIPS_CONTENT: 2451 BFD_ASSERT ((*hdrpp)->bfd_section != NULL); 2452 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section); 2453 BFD_ASSERT (name != NULL 2454 && strncmp (name, ".MIPS.content", 2455 sizeof ".MIPS.content" - 1) == 0); 2456 sec = bfd_get_section_by_name (abfd, 2457 name + sizeof ".MIPS.content" - 1); 2458 BFD_ASSERT (sec != NULL); 2459 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx; 2460 break; 2461 2462 case SHT_MIPS_SYMBOL_LIB: 2463 sec = bfd_get_section_by_name (abfd, ".dynsym"); 2464 if (sec != NULL) 2465 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx; 2466 sec = bfd_get_section_by_name (abfd, ".liblist"); 2467 if (sec != NULL) 2468 (*hdrpp)->sh_info = elf_section_data (sec)->this_idx; 2469 break; 2470 2471 case SHT_MIPS_EVENTS: 2472 BFD_ASSERT ((*hdrpp)->bfd_section != NULL); 2473 name = bfd_get_section_name (abfd, (*hdrpp)->bfd_section); 2474 BFD_ASSERT (name != NULL); 2475 if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0) 2476 sec = bfd_get_section_by_name (abfd, 2477 name + sizeof ".MIPS.events" - 1); 2478 else 2479 { 2480 BFD_ASSERT (strncmp (name, ".MIPS.post_rel", 2481 sizeof ".MIPS.post_rel" - 1) == 0); 2482 sec = bfd_get_section_by_name (abfd, 2483 (name 2484 + sizeof ".MIPS.post_rel" - 1)); 2485 } 2486 BFD_ASSERT (sec != NULL); 2487 (*hdrpp)->sh_link = elf_section_data (sec)->this_idx; 2488 break; 2489 2490 } 2491 } 2492 } 2493 2494 2495 /* Function to keep MIPS specific file flags like as EF_MIPS_PIC. */ 2496 2497 boolean 2498 _bfd_mips_elf_set_private_flags (abfd, flags) 2499 bfd *abfd; 2500 flagword flags; 2501 { 2502 BFD_ASSERT (!elf_flags_init (abfd) 2503 || elf_elfheader (abfd)->e_flags == flags); 2504 2505 elf_elfheader (abfd)->e_flags = flags; 2506 elf_flags_init (abfd) = true; 2507 return true; 2508 } 2509 2510 /* Copy backend specific data from one object module to another */ 2511 2512 boolean 2513 _bfd_mips_elf_copy_private_bfd_data (ibfd, obfd) 2514 bfd *ibfd; 2515 bfd *obfd; 2516 { 2517 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour 2518 || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 2519 return true; 2520 2521 BFD_ASSERT (!elf_flags_init (obfd) 2522 || (elf_elfheader (obfd)->e_flags 2523 == elf_elfheader (ibfd)->e_flags)); 2524 2525 elf_gp (obfd) = elf_gp (ibfd); 2526 elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags; 2527 elf_flags_init (obfd) = true; 2528 return true; 2529 } 2530 2531 /* Merge backend specific data from an object file to the output 2532 object file when linking. */ 2533 2534 boolean 2535 _bfd_mips_elf_merge_private_bfd_data (ibfd, obfd) 2536 bfd *ibfd; 2537 bfd *obfd; 2538 { 2539 flagword old_flags; 2540 flagword new_flags; 2541 boolean ok; 2542 boolean null_input_bfd = true; 2543 asection *sec; 2544 2545 /* Check if we have the same endianess */ 2546 if (_bfd_generic_verify_endian_match (ibfd, obfd) == false) 2547 return false; 2548 2549 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour 2550 || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 2551 return true; 2552 2553 new_flags = elf_elfheader (ibfd)->e_flags; 2554 elf_elfheader (obfd)->e_flags |= new_flags & EF_MIPS_NOREORDER; 2555 old_flags = elf_elfheader (obfd)->e_flags; 2556 2557 if (! elf_flags_init (obfd)) 2558 { 2559 elf_flags_init (obfd) = true; 2560 elf_elfheader (obfd)->e_flags = new_flags; 2561 elf_elfheader (obfd)->e_ident[EI_CLASS] 2562 = elf_elfheader (ibfd)->e_ident[EI_CLASS]; 2563 2564 if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) 2565 && bfd_get_arch_info (obfd)->the_default) 2566 { 2567 if (! bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), 2568 bfd_get_mach (ibfd))) 2569 return false; 2570 } 2571 2572 return true; 2573 } 2574 2575 /* Check flag compatibility. */ 2576 2577 new_flags &= ~EF_MIPS_NOREORDER; 2578 old_flags &= ~EF_MIPS_NOREORDER; 2579 2580 if (new_flags == old_flags) 2581 return true; 2582 2583 /* Check to see if the input BFD actually contains any sections. 2584 If not, its flags may not have been initialised either, but it cannot 2585 actually cause any incompatibility. */ 2586 for (sec = ibfd->sections; sec != NULL; sec = sec->next) 2587 { 2588 /* Ignore synthetic sections and empty .text, .data and .bss sections 2589 which are automatically generated by gas. */ 2590 if (strcmp (sec->name, ".reginfo") 2591 && strcmp (sec->name, ".mdebug") 2592 && ((!strcmp (sec->name, ".text") 2593 || !strcmp (sec->name, ".data") 2594 || !strcmp (sec->name, ".bss")) 2595 && sec->_raw_size != 0)) 2596 { 2597 null_input_bfd = false; 2598 break; 2599 } 2600 } 2601 if (null_input_bfd) 2602 return true; 2603 2604 ok = true; 2605 2606 if ((new_flags & EF_MIPS_PIC) != (old_flags & EF_MIPS_PIC)) 2607 { 2608 new_flags &= ~EF_MIPS_PIC; 2609 old_flags &= ~EF_MIPS_PIC; 2610 (*_bfd_error_handler) 2611 (_("%s: linking PIC files with non-PIC files"), 2612 bfd_get_filename (ibfd)); 2613 ok = false; 2614 } 2615 2616 if ((new_flags & EF_MIPS_CPIC) != (old_flags & EF_MIPS_CPIC)) 2617 { 2618 new_flags &= ~EF_MIPS_CPIC; 2619 old_flags &= ~EF_MIPS_CPIC; 2620 (*_bfd_error_handler) 2621 (_("%s: linking abicalls files with non-abicalls files"), 2622 bfd_get_filename (ibfd)); 2623 ok = false; 2624 } 2625 2626 /* Compare the ISA's. */ 2627 if ((new_flags & (EF_MIPS_ARCH | EF_MIPS_MACH)) 2628 != (old_flags & (EF_MIPS_ARCH | EF_MIPS_MACH))) 2629 { 2630 int new_mach = new_flags & EF_MIPS_MACH; 2631 int old_mach = old_flags & EF_MIPS_MACH; 2632 int new_isa = elf_mips_isa (new_flags); 2633 int old_isa = elf_mips_isa (old_flags); 2634 2635 /* If either has no machine specified, just compare the general isa's. 2636 Some combinations of machines are ok, if the isa's match. */ 2637 if (! new_mach 2638 || ! old_mach 2639 || new_mach == old_mach 2640 ) 2641 { 2642 /* Don't warn about mixing code using 32-bit ISAs, or mixing code 2643 using 64-bit ISAs. They will normally use the same data sizes 2644 and calling conventions. */ 2645 2646 if (( (new_isa == 1 || new_isa == 2 || new_isa == 32) 2647 ^ (old_isa == 1 || old_isa == 2 || old_isa == 32)) != 0) 2648 { 2649 (*_bfd_error_handler) 2650 (_("%s: ISA mismatch (-mips%d) with previous modules (-mips%d)"), 2651 bfd_get_filename (ibfd), new_isa, old_isa); 2652 ok = false; 2653 } 2654 } 2655 2656 else 2657 { 2658 (*_bfd_error_handler) 2659 (_("%s: ISA mismatch (%d) with previous modules (%d)"), 2660 bfd_get_filename (ibfd), 2661 elf_mips_mach (new_flags), 2662 elf_mips_mach (old_flags)); 2663 ok = false; 2664 } 2665 2666 new_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH); 2667 old_flags &= ~(EF_MIPS_ARCH | EF_MIPS_MACH); 2668 } 2669 2670 /* Compare ABI's. The 64-bit ABI does not use EF_MIPS_ABI. But, it 2671 does set EI_CLASS differently from any 32-bit ABI. */ 2672 if ((new_flags & EF_MIPS_ABI) != (old_flags & EF_MIPS_ABI) 2673 || (elf_elfheader (ibfd)->e_ident[EI_CLASS] 2674 != elf_elfheader (obfd)->e_ident[EI_CLASS])) 2675 { 2676 /* Only error if both are set (to different values). */ 2677 if (((new_flags & EF_MIPS_ABI) && (old_flags & EF_MIPS_ABI)) 2678 || (elf_elfheader (ibfd)->e_ident[EI_CLASS] 2679 != elf_elfheader (obfd)->e_ident[EI_CLASS])) 2680 { 2681 (*_bfd_error_handler) 2682 (_("%s: ABI mismatch: linking %s module with previous %s modules"), 2683 bfd_get_filename (ibfd), 2684 elf_mips_abi_name (ibfd), 2685 elf_mips_abi_name (obfd)); 2686 ok = false; 2687 } 2688 new_flags &= ~EF_MIPS_ABI; 2689 old_flags &= ~EF_MIPS_ABI; 2690 } 2691 2692 /* Warn about any other mismatches */ 2693 if (new_flags != old_flags) 2694 { 2695 (*_bfd_error_handler) 2696 (_("%s: uses different e_flags (0x%lx) fields than previous modules (0x%lx)"), 2697 bfd_get_filename (ibfd), (unsigned long) new_flags, 2698 (unsigned long) old_flags); 2699 ok = false; 2700 } 2701 2702 if (! ok) 2703 { 2704 bfd_set_error (bfd_error_bad_value); 2705 return false; 2706 } 2707 2708 return true; 2709 } 2710 2711 2712 boolean 2713 _bfd_mips_elf_print_private_bfd_data (abfd, ptr) 2714 bfd *abfd; 2715 PTR ptr; 2716 { 2717 FILE *file = (FILE *) ptr; 2718 2719 BFD_ASSERT (abfd != NULL && ptr != NULL); 2720 2721 /* Print normal ELF private data. */ 2722 _bfd_elf_print_private_bfd_data (abfd, ptr); 2723 2724 /* xgettext:c-format */ 2725 fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); 2726 2727 if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_O32) 2728 fprintf (file, _(" [abi=O32]")); 2729 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_O64) 2730 fprintf (file, _(" [abi=O64]")); 2731 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI32) 2732 fprintf (file, _(" [abi=EABI32]")); 2733 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI) == E_MIPS_ABI_EABI64) 2734 fprintf (file, _(" [abi=EABI64]")); 2735 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ABI)) 2736 fprintf (file, _(" [abi unknown]")); 2737 else if (ABI_N32_P (abfd)) 2738 fprintf (file, _(" [abi=N32]")); 2739 else if (ABI_64_P (abfd)) 2740 fprintf (file, _(" [abi=64]")); 2741 else 2742 fprintf (file, _(" [no abi set]")); 2743 2744 if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_1) 2745 fprintf (file, _(" [mips1]")); 2746 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_2) 2747 fprintf (file, _(" [mips2]")); 2748 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_3) 2749 fprintf (file, _(" [mips3]")); 2750 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_4) 2751 fprintf (file, _(" [mips4]")); 2752 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_5) 2753 fprintf (file, _ (" [mips5]")); 2754 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_32) 2755 fprintf (file, _ (" [mips32]")); 2756 else if ((elf_elfheader (abfd)->e_flags & EF_MIPS_ARCH) == E_MIPS_ARCH_64) 2757 fprintf (file, _ (" [mips64]")); 2758 else 2759 fprintf (file, _(" [unknown ISA]")); 2760 2761 if (elf_elfheader (abfd)->e_flags & EF_MIPS_32BITMODE) 2762 fprintf (file, _(" [32bitmode]")); 2763 else 2764 fprintf (file, _(" [not 32bitmode]")); 2765 2766 fputc ('\n', file); 2767 2768 return true; 2769 } 2770 2771 2772 /* Handle a MIPS specific section when reading an object file. This 2773 is called when elfcode.h finds a section with an unknown type. 2774 This routine supports both the 32-bit and 64-bit ELF ABI. 2775 2776 FIXME: We need to handle the SHF_MIPS_GPREL flag, but I'm not sure 2777 how to. */ 2778 2779 boolean 2780 _bfd_mips_elf_section_from_shdr (abfd, hdr, name) 2781 bfd *abfd; 2782 Elf_Internal_Shdr *hdr; 2783 char *name; 2784 { 2785 flagword flags = 0; 2786 2787 /* There ought to be a place to keep ELF backend specific flags, but 2788 at the moment there isn't one. We just keep track of the 2789 sections by their name, instead. Fortunately, the ABI gives 2790 suggested names for all the MIPS specific sections, so we will 2791 probably get away with this. */ 2792 switch (hdr->sh_type) 2793 { 2794 case SHT_MIPS_LIBLIST: 2795 if (strcmp (name, ".liblist") != 0) 2796 return false; 2797 break; 2798 case SHT_MIPS_MSYM: 2799 if (strcmp (name, MIPS_ELF_MSYM_SECTION_NAME (abfd)) != 0) 2800 return false; 2801 break; 2802 case SHT_MIPS_CONFLICT: 2803 if (strcmp (name, ".conflict") != 0) 2804 return false; 2805 break; 2806 case SHT_MIPS_GPTAB: 2807 if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) != 0) 2808 return false; 2809 break; 2810 case SHT_MIPS_UCODE: 2811 if (strcmp (name, ".ucode") != 0) 2812 return false; 2813 break; 2814 case SHT_MIPS_DEBUG: 2815 if (strcmp (name, ".mdebug") != 0) 2816 return false; 2817 flags = SEC_DEBUGGING; 2818 break; 2819 case SHT_MIPS_REGINFO: 2820 if (strcmp (name, ".reginfo") != 0 2821 || hdr->sh_size != sizeof (Elf32_External_RegInfo)) 2822 return false; 2823 flags = (SEC_LINK_ONCE | SEC_LINK_DUPLICATES_SAME_SIZE); 2824 break; 2825 case SHT_MIPS_IFACE: 2826 if (strcmp (name, ".MIPS.interfaces") != 0) 2827 return false; 2828 break; 2829 case SHT_MIPS_CONTENT: 2830 if (strncmp (name, ".MIPS.content", sizeof ".MIPS.content" - 1) != 0) 2831 return false; 2832 break; 2833 case SHT_MIPS_OPTIONS: 2834 if (strcmp (name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) != 0) 2835 return false; 2836 break; 2837 case SHT_MIPS_DWARF: 2838 if (strncmp (name, ".debug_", sizeof ".debug_" - 1) != 0) 2839 return false; 2840 break; 2841 case SHT_MIPS_SYMBOL_LIB: 2842 if (strcmp (name, ".MIPS.symlib") != 0) 2843 return false; 2844 break; 2845 case SHT_MIPS_EVENTS: 2846 if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) != 0 2847 && strncmp (name, ".MIPS.post_rel", 2848 sizeof ".MIPS.post_rel" - 1) != 0) 2849 return false; 2850 break; 2851 default: 2852 return false; 2853 } 2854 2855 if (! _bfd_elf_make_section_from_shdr (abfd, hdr, name)) 2856 return false; 2857 2858 if (flags) 2859 { 2860 if (! bfd_set_section_flags (abfd, hdr->bfd_section, 2861 (bfd_get_section_flags (abfd, 2862 hdr->bfd_section) 2863 | flags))) 2864 return false; 2865 } 2866 2867 /* FIXME: We should record sh_info for a .gptab section. */ 2868 2869 /* For a .reginfo section, set the gp value in the tdata information 2870 from the contents of this section. We need the gp value while 2871 processing relocs, so we just get it now. The .reginfo section 2872 is not used in the 64-bit MIPS ELF ABI. */ 2873 if (hdr->sh_type == SHT_MIPS_REGINFO) 2874 { 2875 Elf32_External_RegInfo ext; 2876 Elf32_RegInfo s; 2877 2878 if (! bfd_get_section_contents (abfd, hdr->bfd_section, (PTR) &ext, 2879 (file_ptr) 0, sizeof ext)) 2880 return false; 2881 bfd_mips_elf32_swap_reginfo_in (abfd, &ext, &s); 2882 elf_gp (abfd) = s.ri_gp_value; 2883 } 2884 2885 /* For a SHT_MIPS_OPTIONS section, look for a ODK_REGINFO entry, and 2886 set the gp value based on what we find. We may see both 2887 SHT_MIPS_REGINFO and SHT_MIPS_OPTIONS/ODK_REGINFO; in that case, 2888 they should agree. */ 2889 if (hdr->sh_type == SHT_MIPS_OPTIONS) 2890 { 2891 bfd_byte *contents, *l, *lend; 2892 2893 contents = (bfd_byte *) bfd_malloc (hdr->sh_size); 2894 if (contents == NULL) 2895 return false; 2896 if (! bfd_get_section_contents (abfd, hdr->bfd_section, contents, 2897 (file_ptr) 0, hdr->sh_size)) 2898 { 2899 free (contents); 2900 return false; 2901 } 2902 l = contents; 2903 lend = contents + hdr->sh_size; 2904 while (l + sizeof (Elf_External_Options) <= lend) 2905 { 2906 Elf_Internal_Options intopt; 2907 2908 bfd_mips_elf_swap_options_in (abfd, (Elf_External_Options *) l, 2909 &intopt); 2910 if (ABI_64_P (abfd) && intopt.kind == ODK_REGINFO) 2911 { 2912 Elf64_Internal_RegInfo intreg; 2913 2914 bfd_mips_elf64_swap_reginfo_in 2915 (abfd, 2916 ((Elf64_External_RegInfo *) 2917 (l + sizeof (Elf_External_Options))), 2918 &intreg); 2919 elf_gp (abfd) = intreg.ri_gp_value; 2920 } 2921 else if (intopt.kind == ODK_REGINFO) 2922 { 2923 Elf32_RegInfo intreg; 2924 2925 bfd_mips_elf32_swap_reginfo_in 2926 (abfd, 2927 ((Elf32_External_RegInfo *) 2928 (l + sizeof (Elf_External_Options))), 2929 &intreg); 2930 elf_gp (abfd) = intreg.ri_gp_value; 2931 } 2932 l += intopt.size; 2933 } 2934 free (contents); 2935 } 2936 2937 return true; 2938 } 2939 2940 /* Set the correct type for a MIPS ELF section. We do this by the 2941 section name, which is a hack, but ought to work. This routine is 2942 used by both the 32-bit and the 64-bit ABI. */ 2943 2944 boolean 2945 _bfd_mips_elf_fake_sections (abfd, hdr, sec) 2946 bfd *abfd; 2947 Elf32_Internal_Shdr *hdr; 2948 asection *sec; 2949 { 2950 register const char *name; 2951 2952 name = bfd_get_section_name (abfd, sec); 2953 2954 if (strcmp (name, ".liblist") == 0) 2955 { 2956 hdr->sh_type = SHT_MIPS_LIBLIST; 2957 hdr->sh_info = sec->_raw_size / sizeof (Elf32_Lib); 2958 /* The sh_link field is set in final_write_processing. */ 2959 } 2960 else if (strcmp (name, ".conflict") == 0) 2961 hdr->sh_type = SHT_MIPS_CONFLICT; 2962 else if (strncmp (name, ".gptab.", sizeof ".gptab." - 1) == 0) 2963 { 2964 hdr->sh_type = SHT_MIPS_GPTAB; 2965 hdr->sh_entsize = sizeof (Elf32_External_gptab); 2966 /* The sh_info field is set in final_write_processing. */ 2967 } 2968 else if (strcmp (name, ".ucode") == 0) 2969 hdr->sh_type = SHT_MIPS_UCODE; 2970 else if (strcmp (name, ".mdebug") == 0) 2971 { 2972 hdr->sh_type = SHT_MIPS_DEBUG; 2973 /* In a shared object on Irix 5.3, the .mdebug section has an 2974 entsize of 0. FIXME: Does this matter? */ 2975 if (SGI_COMPAT (abfd) && (abfd->flags & DYNAMIC) != 0) 2976 hdr->sh_entsize = 0; 2977 else 2978 hdr->sh_entsize = 1; 2979 } 2980 else if (strcmp (name, ".reginfo") == 0) 2981 { 2982 hdr->sh_type = SHT_MIPS_REGINFO; 2983 /* In a shared object on Irix 5.3, the .reginfo section has an 2984 entsize of 0x18. FIXME: Does this matter? */ 2985 if (SGI_COMPAT (abfd)) 2986 { 2987 if ((abfd->flags & DYNAMIC) != 0) 2988 hdr->sh_entsize = sizeof (Elf32_External_RegInfo); 2989 else 2990 hdr->sh_entsize = 1; 2991 } 2992 else 2993 hdr->sh_entsize = sizeof (Elf32_External_RegInfo); 2994 } 2995 else if (SGI_COMPAT (abfd) 2996 && (strcmp (name, ".hash") == 0 2997 || strcmp (name, ".dynamic") == 0 2998 || strcmp (name, ".dynstr") == 0)) 2999 { 3000 if (SGI_COMPAT (abfd)) 3001 hdr->sh_entsize = 0; 3002 #if 0 3003 /* This isn't how the Irix 6 linker behaves. */ 3004 hdr->sh_info = SIZEOF_MIPS_DYNSYM_SECNAMES; 3005 #endif 3006 } 3007 else if (strcmp (name, ".got") == 0 3008 || strcmp (name, MIPS_ELF_SRDATA_SECTION_NAME (abfd)) == 0 3009 || strcmp (name, ".sdata") == 0 3010 || strcmp (name, ".sbss") == 0 3011 || strcmp (name, ".lit4") == 0 3012 || strcmp (name, ".lit8") == 0) 3013 hdr->sh_flags |= SHF_MIPS_GPREL; 3014 else if (strcmp (name, ".MIPS.interfaces") == 0) 3015 { 3016 hdr->sh_type = SHT_MIPS_IFACE; 3017 hdr->sh_flags |= SHF_MIPS_NOSTRIP; 3018 } 3019 else if (strncmp (name, ".MIPS.content", strlen (".MIPS.content")) == 0) 3020 { 3021 hdr->sh_type = SHT_MIPS_CONTENT; 3022 hdr->sh_flags |= SHF_MIPS_NOSTRIP; 3023 /* The sh_info field is set in final_write_processing. */ 3024 } 3025 else if (strcmp (name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) == 0) 3026 { 3027 hdr->sh_type = SHT_MIPS_OPTIONS; 3028 hdr->sh_entsize = 1; 3029 hdr->sh_flags |= SHF_MIPS_NOSTRIP; 3030 } 3031 else if (strncmp (name, ".debug_", sizeof ".debug_" - 1) == 0) 3032 hdr->sh_type = SHT_MIPS_DWARF; 3033 else if (strcmp (name, ".MIPS.symlib") == 0) 3034 { 3035 hdr->sh_type = SHT_MIPS_SYMBOL_LIB; 3036 /* The sh_link and sh_info fields are set in 3037 final_write_processing. */ 3038 } 3039 else if (strncmp (name, ".MIPS.events", sizeof ".MIPS.events" - 1) == 0 3040 || strncmp (name, ".MIPS.post_rel", 3041 sizeof ".MIPS.post_rel" - 1) == 0) 3042 { 3043 hdr->sh_type = SHT_MIPS_EVENTS; 3044 hdr->sh_flags |= SHF_MIPS_NOSTRIP; 3045 /* The sh_link field is set in final_write_processing. */ 3046 } 3047 else if (strcmp (name, MIPS_ELF_MSYM_SECTION_NAME (abfd)) == 0) 3048 { 3049 hdr->sh_type = SHT_MIPS_MSYM; 3050 hdr->sh_flags |= SHF_ALLOC; 3051 hdr->sh_entsize = 8; 3052 } 3053 3054 /* The generic elf_fake_sections will set up REL_HDR using the 3055 default kind of relocations. But, we may actually need both 3056 kinds of relocations, so we set up the second header here. */ 3057 if ((sec->flags & SEC_RELOC) != 0) 3058 { 3059 struct bfd_elf_section_data *esd; 3060 3061 esd = elf_section_data (sec); 3062 BFD_ASSERT (esd->rel_hdr2 == NULL); 3063 esd->rel_hdr2 3064 = (Elf_Internal_Shdr *) bfd_zalloc (abfd, sizeof (Elf_Internal_Shdr)); 3065 if (!esd->rel_hdr2) 3066 return false; 3067 _bfd_elf_init_reloc_shdr (abfd, esd->rel_hdr2, sec, 3068 !elf_section_data (sec)->use_rela_p); 3069 } 3070 3071 return true; 3072 } 3073 3074 /* Given a BFD section, try to locate the corresponding ELF section 3075 index. This is used by both the 32-bit and the 64-bit ABI. 3076 Actually, it's not clear to me that the 64-bit ABI supports these, 3077 but for non-PIC objects we will certainly want support for at least 3078 the .scommon section. */ 3079 3080 boolean 3081 _bfd_mips_elf_section_from_bfd_section (abfd, hdr, sec, retval) 3082 bfd *abfd ATTRIBUTE_UNUSED; 3083 Elf_Internal_Shdr *hdr ATTRIBUTE_UNUSED; 3084 asection *sec; 3085 int *retval; 3086 { 3087 if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0) 3088 { 3089 *retval = SHN_MIPS_SCOMMON; 3090 return true; 3091 } 3092 if (strcmp (bfd_get_section_name (abfd, sec), ".acommon") == 0) 3093 { 3094 *retval = SHN_MIPS_ACOMMON; 3095 return true; 3096 } 3097 return false; 3098 } 3099 3100 /* When are writing out the .options or .MIPS.options section, 3101 remember the bytes we are writing out, so that we can install the 3102 GP value in the section_processing routine. */ 3103 3104 boolean 3105 _bfd_mips_elf_set_section_contents (abfd, section, location, offset, count) 3106 bfd *abfd; 3107 sec_ptr section; 3108 PTR location; 3109 file_ptr offset; 3110 bfd_size_type count; 3111 { 3112 if (strcmp (section->name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) == 0) 3113 { 3114 bfd_byte *c; 3115 3116 if (elf_section_data (section) == NULL) 3117 { 3118 section->used_by_bfd = 3119 (PTR) bfd_zalloc (abfd, sizeof (struct bfd_elf_section_data)); 3120 if (elf_section_data (section) == NULL) 3121 return false; 3122 } 3123 c = (bfd_byte *) elf_section_data (section)->tdata; 3124 if (c == NULL) 3125 { 3126 bfd_size_type size; 3127 3128 if (section->_cooked_size != 0) 3129 size = section->_cooked_size; 3130 else 3131 size = section->_raw_size; 3132 c = (bfd_byte *) bfd_zalloc (abfd, size); 3133 if (c == NULL) 3134 return false; 3135 elf_section_data (section)->tdata = (PTR) c; 3136 } 3137 3138 memcpy (c + offset, location, count); 3139 } 3140 3141 return _bfd_elf_set_section_contents (abfd, section, location, offset, 3142 count); 3143 } 3144 3145 /* Work over a section just before writing it out. This routine is 3146 used by both the 32-bit and the 64-bit ABI. FIXME: We recognize 3147 sections that need the SHF_MIPS_GPREL flag by name; there has to be 3148 a better way. */ 3149 3150 boolean 3151 _bfd_mips_elf_section_processing (abfd, hdr) 3152 bfd *abfd; 3153 Elf_Internal_Shdr *hdr; 3154 { 3155 if (hdr->sh_type == SHT_MIPS_REGINFO 3156 && hdr->sh_size > 0) 3157 { 3158 bfd_byte buf[4]; 3159 3160 BFD_ASSERT (hdr->sh_size == sizeof (Elf32_External_RegInfo)); 3161 BFD_ASSERT (hdr->contents == NULL); 3162 3163 if (bfd_seek (abfd, 3164 hdr->sh_offset + sizeof (Elf32_External_RegInfo) - 4, 3165 SEEK_SET) == -1) 3166 return false; 3167 bfd_h_put_32 (abfd, (bfd_vma) elf_gp (abfd), buf); 3168 if (bfd_write (buf, (bfd_size_type) 1, (bfd_size_type) 4, abfd) != 4) 3169 return false; 3170 } 3171 3172 if (hdr->sh_type == SHT_MIPS_OPTIONS 3173 && hdr->bfd_section != NULL 3174 && elf_section_data (hdr->bfd_section) != NULL 3175 && elf_section_data (hdr->bfd_section)->tdata != NULL) 3176 { 3177 bfd_byte *contents, *l, *lend; 3178 3179 /* We stored the section contents in the elf_section_data tdata 3180 field in the set_section_contents routine. We save the 3181 section contents so that we don't have to read them again. 3182 At this point we know that elf_gp is set, so we can look 3183 through the section contents to see if there is an 3184 ODK_REGINFO structure. */ 3185 3186 contents = (bfd_byte *) elf_section_data (hdr->bfd_section)->tdata; 3187 l = contents; 3188 lend = contents + hdr->sh_size; 3189 while (l + sizeof (Elf_External_Options) <= lend) 3190 { 3191 Elf_Internal_Options intopt; 3192 3193 bfd_mips_elf_swap_options_in (abfd, (Elf_External_Options *) l, 3194 &intopt); 3195 if (ABI_64_P (abfd) && intopt.kind == ODK_REGINFO) 3196 { 3197 bfd_byte buf[8]; 3198 3199 if (bfd_seek (abfd, 3200 (hdr->sh_offset 3201 + (l - contents) 3202 + sizeof (Elf_External_Options) 3203 + (sizeof (Elf64_External_RegInfo) - 8)), 3204 SEEK_SET) == -1) 3205 return false; 3206 bfd_h_put_64 (abfd, elf_gp (abfd), buf); 3207 if (bfd_write (buf, 1, 8, abfd) != 8) 3208 return false; 3209 } 3210 else if (intopt.kind == ODK_REGINFO) 3211 { 3212 bfd_byte buf[4]; 3213 3214 if (bfd_seek (abfd, 3215 (hdr->sh_offset 3216 + (l - contents) 3217 + sizeof (Elf_External_Options) 3218 + (sizeof (Elf32_External_RegInfo) - 4)), 3219 SEEK_SET) == -1) 3220 return false; 3221 bfd_h_put_32 (abfd, elf_gp (abfd), buf); 3222 if (bfd_write (buf, 1, 4, abfd) != 4) 3223 return false; 3224 } 3225 l += intopt.size; 3226 } 3227 } 3228 3229 if (hdr->bfd_section != NULL) 3230 { 3231 const char *name = bfd_get_section_name (abfd, hdr->bfd_section); 3232 3233 if (strcmp (name, ".sdata") == 0 3234 || strcmp (name, ".lit8") == 0 3235 || strcmp (name, ".lit4") == 0) 3236 { 3237 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL; 3238 hdr->sh_type = SHT_PROGBITS; 3239 } 3240 else if (strcmp (name, ".sbss") == 0) 3241 { 3242 hdr->sh_flags |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL; 3243 hdr->sh_type = SHT_NOBITS; 3244 } 3245 else if (strcmp (name, MIPS_ELF_SRDATA_SECTION_NAME (abfd)) == 0) 3246 { 3247 hdr->sh_flags |= SHF_ALLOC | SHF_MIPS_GPREL; 3248 hdr->sh_type = SHT_PROGBITS; 3249 } 3250 else if (strcmp (name, ".compact_rel") == 0) 3251 { 3252 hdr->sh_flags = 0; 3253 hdr->sh_type = SHT_PROGBITS; 3254 } 3255 else if (strcmp (name, ".rtproc") == 0) 3256 { 3257 if (hdr->sh_addralign != 0 && hdr->sh_entsize == 0) 3258 { 3259 unsigned int adjust; 3260 3261 adjust = hdr->sh_size % hdr->sh_addralign; 3262 if (adjust != 0) 3263 hdr->sh_size += hdr->sh_addralign - adjust; 3264 } 3265 } 3266 } 3267 3268 return true; 3269 } 3270 3271 3272 /* MIPS ELF uses two common sections. One is the usual one, and the 3273 other is for small objects. All the small objects are kept 3274 together, and then referenced via the gp pointer, which yields 3275 faster assembler code. This is what we use for the small common 3276 section. This approach is copied from ecoff.c. */ 3277 static asection mips_elf_scom_section; 3278 static asymbol mips_elf_scom_symbol; 3279 static asymbol *mips_elf_scom_symbol_ptr; 3280 3281 /* MIPS ELF also uses an acommon section, which represents an 3282 allocated common symbol which may be overridden by a 3283 definition in a shared library. */ 3284 static asection mips_elf_acom_section; 3285 static asymbol mips_elf_acom_symbol; 3286 static asymbol *mips_elf_acom_symbol_ptr; 3287 3288 /* Handle the special MIPS section numbers that a symbol may use. 3289 This is used for both the 32-bit and the 64-bit ABI. */ 3290 3291 void 3292 _bfd_mips_elf_symbol_processing (abfd, asym) 3293 bfd *abfd; 3294 asymbol *asym; 3295 { 3296 elf_symbol_type *elfsym; 3297 3298 elfsym = (elf_symbol_type *) asym; 3299 switch (elfsym->internal_elf_sym.st_shndx) 3300 { 3301 case SHN_MIPS_ACOMMON: 3302 /* This section is used in a dynamically linked executable file. 3303 It is an allocated common section. The dynamic linker can 3304 either resolve these symbols to something in a shared 3305 library, or it can just leave them here. For our purposes, 3306 we can consider these symbols to be in a new section. */ 3307 if (mips_elf_acom_section.name == NULL) 3308 { 3309 /* Initialize the acommon section. */ 3310 mips_elf_acom_section.name = ".acommon"; 3311 mips_elf_acom_section.flags = SEC_ALLOC; 3312 mips_elf_acom_section.output_section = &mips_elf_acom_section; 3313 mips_elf_acom_section.symbol = &mips_elf_acom_symbol; 3314 mips_elf_acom_section.symbol_ptr_ptr = &mips_elf_acom_symbol_ptr; 3315 mips_elf_acom_symbol.name = ".acommon"; 3316 mips_elf_acom_symbol.flags = BSF_SECTION_SYM; 3317 mips_elf_acom_symbol.section = &mips_elf_acom_section; 3318 mips_elf_acom_symbol_ptr = &mips_elf_acom_symbol; 3319 } 3320 asym->section = &mips_elf_acom_section; 3321 break; 3322 3323 case SHN_COMMON: 3324 /* Common symbols less than the GP size are automatically 3325 treated as SHN_MIPS_SCOMMON symbols on IRIX5. */ 3326 if (asym->value > elf_gp_size (abfd) 3327 || IRIX_COMPAT (abfd) == ict_irix6) 3328 break; 3329 /* Fall through. */ 3330 case SHN_MIPS_SCOMMON: 3331 if (mips_elf_scom_section.name == NULL) 3332 { 3333 /* Initialize the small common section. */ 3334 mips_elf_scom_section.name = ".scommon"; 3335 mips_elf_scom_section.flags = SEC_IS_COMMON; 3336 mips_elf_scom_section.output_section = &mips_elf_scom_section; 3337 mips_elf_scom_section.symbol = &mips_elf_scom_symbol; 3338 mips_elf_scom_section.symbol_ptr_ptr = &mips_elf_scom_symbol_ptr; 3339 mips_elf_scom_symbol.name = ".scommon"; 3340 mips_elf_scom_symbol.flags = BSF_SECTION_SYM; 3341 mips_elf_scom_symbol.section = &mips_elf_scom_section; 3342 mips_elf_scom_symbol_ptr = &mips_elf_scom_symbol; 3343 } 3344 asym->section = &mips_elf_scom_section; 3345 asym->value = elfsym->internal_elf_sym.st_size; 3346 break; 3347 3348 case SHN_MIPS_SUNDEFINED: 3349 asym->section = bfd_und_section_ptr; 3350 break; 3351 3352 #if 0 /* for SGI_COMPAT */ 3353 case SHN_MIPS_TEXT: 3354 asym->section = mips_elf_text_section_ptr; 3355 break; 3356 3357 case SHN_MIPS_DATA: 3358 asym->section = mips_elf_data_section_ptr; 3359 break; 3360 #endif 3361 } 3362 } 3363 3364 3365 /* When creating an Irix 5 executable, we need REGINFO and RTPROC 3366 segments. */ 3367 3368 int 3369 _bfd_mips_elf_additional_program_headers (abfd) 3370 bfd *abfd; 3371 { 3372 asection *s; 3373 int ret = 0; 3374 3375 /* See if we need a PT_MIPS_REGINFO segment. */ 3376 s = bfd_get_section_by_name (abfd, ".reginfo"); 3377 if (s && (s->flags & SEC_LOAD)) 3378 ++ret; 3379 3380 /* See if we need a PT_MIPS_OPTIONS segment. */ 3381 if (IRIX_COMPAT (abfd) == ict_irix6 3382 && bfd_get_section_by_name (abfd, 3383 MIPS_ELF_OPTIONS_SECTION_NAME (abfd))) 3384 ++ret; 3385 3386 /* See if we need a PT_MIPS_RTPROC segment. */ 3387 if (IRIX_COMPAT (abfd) == ict_irix5 3388 && bfd_get_section_by_name (abfd, ".dynamic") 3389 && bfd_get_section_by_name (abfd, ".mdebug")) 3390 ++ret; 3391 3392 return ret; 3393 } 3394 3395 /* Modify the segment map for an Irix 5 executable. */ 3396 3397 boolean 3398 _bfd_mips_elf_modify_segment_map (abfd) 3399 bfd *abfd; 3400 { 3401 asection *s; 3402 struct elf_segment_map *m, **pm; 3403 3404 /* If there is a .reginfo section, we need a PT_MIPS_REGINFO 3405 segment. */ 3406 s = bfd_get_section_by_name (abfd, ".reginfo"); 3407 if (s != NULL && (s->flags & SEC_LOAD) != 0) 3408 { 3409 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) 3410 if (m->p_type == PT_MIPS_REGINFO) 3411 break; 3412 if (m == NULL) 3413 { 3414 m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m); 3415 if (m == NULL) 3416 return false; 3417 3418 m->p_type = PT_MIPS_REGINFO; 3419 m->count = 1; 3420 m->sections[0] = s; 3421 3422 /* We want to put it after the PHDR and INTERP segments. */ 3423 pm = &elf_tdata (abfd)->segment_map; 3424 while (*pm != NULL 3425 && ((*pm)->p_type == PT_PHDR 3426 || (*pm)->p_type == PT_INTERP)) 3427 pm = &(*pm)->next; 3428 3429 m->next = *pm; 3430 *pm = m; 3431 } 3432 } 3433 3434 /* For IRIX 6, we don't have .mdebug sections, nor does anything but 3435 .dynamic end up in PT_DYNAMIC. However, we do have to insert a 3436 PT_OPTIONS segement immediately following the program header 3437 table. */ 3438 if (IRIX_COMPAT (abfd) == ict_irix6) 3439 { 3440 asection *s; 3441 3442 for (s = abfd->sections; s; s = s->next) 3443 if (elf_section_data (s)->this_hdr.sh_type == SHT_MIPS_OPTIONS) 3444 break; 3445 3446 if (s) 3447 { 3448 struct elf_segment_map *options_segment; 3449 3450 /* Usually, there's a program header table. But, sometimes 3451 there's not (like when running the `ld' testsuite). So, 3452 if there's no program header table, we just put the 3453 options segement at the end. */ 3454 for (pm = &elf_tdata (abfd)->segment_map; 3455 *pm != NULL; 3456 pm = &(*pm)->next) 3457 if ((*pm)->p_type == PT_PHDR) 3458 break; 3459 3460 options_segment = bfd_zalloc (abfd, 3461 sizeof (struct elf_segment_map)); 3462 options_segment->next = *pm; 3463 options_segment->p_type = PT_MIPS_OPTIONS; 3464 options_segment->p_flags = PF_R; 3465 options_segment->p_flags_valid = true; 3466 options_segment->count = 1; 3467 options_segment->sections[0] = s; 3468 *pm = options_segment; 3469 } 3470 } 3471 else 3472 { 3473 if (IRIX_COMPAT (abfd) == ict_irix5) 3474 { 3475 /* If there are .dynamic and .mdebug sections, we make a room 3476 for the RTPROC header. FIXME: Rewrite without section names. */ 3477 if (bfd_get_section_by_name (abfd, ".interp") == NULL 3478 && bfd_get_section_by_name (abfd, ".dynamic") != NULL 3479 && bfd_get_section_by_name (abfd, ".mdebug") != NULL) 3480 { 3481 for (m = elf_tdata (abfd)->segment_map; m != NULL; m = m->next) 3482 if (m->p_type == PT_MIPS_RTPROC) 3483 break; 3484 if (m == NULL) 3485 { 3486 m = (struct elf_segment_map *) bfd_zalloc (abfd, sizeof *m); 3487 if (m == NULL) 3488 return false; 3489 3490 m->p_type = PT_MIPS_RTPROC; 3491 3492 s = bfd_get_section_by_name (abfd, ".rtproc"); 3493 if (s == NULL) 3494 { 3495 m->count = 0; 3496 m->p_flags = 0; 3497 m->p_flags_valid = 1; 3498 } 3499 else 3500 { 3501 m->count = 1; 3502 m->sections[0] = s; 3503 } 3504 3505 /* We want to put it after the DYNAMIC segment. */ 3506 pm = &elf_tdata (abfd)->segment_map; 3507 while (*pm != NULL && (*pm)->p_type != PT_DYNAMIC) 3508 pm = &(*pm)->next; 3509 if (*pm != NULL) 3510 pm = &(*pm)->next; 3511 3512 m->next = *pm; 3513 *pm = m; 3514 } 3515 } 3516 } 3517 /* On Irix 5, the PT_DYNAMIC segment includes the .dynamic, 3518 .dynstr, .dynsym, and .hash sections, and everything in 3519 between. */ 3520 for (pm = &elf_tdata (abfd)->segment_map; *pm != NULL; 3521 pm = &(*pm)->next) 3522 if ((*pm)->p_type == PT_DYNAMIC) 3523 break; 3524 m = *pm; 3525 if (IRIX_COMPAT (abfd) == ict_none) 3526 { 3527 /* For a normal mips executable the permissions for the PT_DYNAMIC 3528 segment are read, write and execute. We do that here since 3529 the code in elf.c sets only the read permission. This matters 3530 sometimes for the dynamic linker. */ 3531 if (bfd_get_section_by_name (abfd, ".dynamic") != NULL) 3532 { 3533 m->p_flags = PF_R | PF_W | PF_X; 3534 m->p_flags_valid = 1; 3535 } 3536 } 3537 if (m != NULL 3538 && m->count == 1 && strcmp (m->sections[0]->name, ".dynamic") == 0) 3539 { 3540 static const char *sec_names[] = 3541 { 3542 ".dynamic", ".dynstr", ".dynsym", ".hash" 3543 }; 3544 bfd_vma low, high; 3545 unsigned int i, c; 3546 struct elf_segment_map *n; 3547 3548 low = 0xffffffff; 3549 high = 0; 3550 for (i = 0; i < sizeof sec_names / sizeof sec_names[0]; i++) 3551 { 3552 s = bfd_get_section_by_name (abfd, sec_names[i]); 3553 if (s != NULL && (s->flags & SEC_LOAD) != 0) 3554 { 3555 bfd_size_type sz; 3556 3557 if (low > s->vma) 3558 low = s->vma; 3559 sz = s->_cooked_size; 3560 if (sz == 0) 3561 sz = s->_raw_size; 3562 if (high < s->vma + sz) 3563 high = s->vma + sz; 3564 } 3565 } 3566 3567 c = 0; 3568 for (s = abfd->sections; s != NULL; s = s->next) 3569 if ((s->flags & SEC_LOAD) != 0 3570 && s->vma >= low 3571 && ((s->vma 3572 + (s->_cooked_size != 3573 0 ? s->_cooked_size : s->_raw_size)) <= high)) 3574 ++c; 3575 3576 n = ((struct elf_segment_map *) 3577 bfd_zalloc (abfd, sizeof *n + (c - 1) * sizeof (asection *))); 3578 if (n == NULL) 3579 return false; 3580 *n = *m; 3581 n->count = c; 3582 3583 i = 0; 3584 for (s = abfd->sections; s != NULL; s = s->next) 3585 { 3586 if ((s->flags & SEC_LOAD) != 0 3587 && s->vma >= low 3588 && ((s->vma 3589 + (s->_cooked_size != 0 ? 3590 s->_cooked_size : s->_raw_size)) <= high)) 3591 { 3592 n->sections[i] = s; 3593 ++i; 3594 } 3595 } 3596 3597 *pm = n; 3598 } 3599 } 3600 3601 return true; 3602 } 3603 3604 3605 /* The structure of the runtime procedure descriptor created by the 3606 loader for use by the static exception system. */ 3607 3608 typedef struct runtime_pdr { 3609 bfd_vma adr; /* memory address of start of procedure */ 3610 long regmask; /* save register mask */ 3611 long regoffset; /* save register offset */ 3612 long fregmask; /* save floating point register mask */ 3613 long fregoffset; /* save floating point register offset */ 3614 long frameoffset; /* frame size */ 3615 short framereg; /* frame pointer register */ 3616 short pcreg; /* offset or reg of return pc */ 3617 long irpss; /* index into the runtime string table */ 3618 long reserved; 3619 struct exception_info *exception_info;/* pointer to exception array */ 3620 } RPDR, *pRPDR; 3621 #define cbRPDR sizeof (RPDR) 3622 #define rpdNil ((pRPDR) 0) 3623 3624 /* Swap RPDR (runtime procedure table entry) for output. */ 3625 3626 static void ecoff_swap_rpdr_out 3627 PARAMS ((bfd *, const RPDR *, struct rpdr_ext *)); 3628 3629 static void 3630 ecoff_swap_rpdr_out (abfd, in, ex) 3631 bfd *abfd; 3632 const RPDR *in; 3633 struct rpdr_ext *ex; 3634 { 3635 /* ecoff_put_off was defined in ecoffswap.h. */ 3636 ecoff_put_off (abfd, in->adr, (bfd_byte *) ex->p_adr); 3637 bfd_h_put_32 (abfd, in->regmask, (bfd_byte *) ex->p_regmask); 3638 bfd_h_put_32 (abfd, in->regoffset, (bfd_byte *) ex->p_regoffset); 3639 bfd_h_put_32 (abfd, in->fregmask, (bfd_byte *) ex->p_fregmask); 3640 bfd_h_put_32 (abfd, in->fregoffset, (bfd_byte *) ex->p_fregoffset); 3641 bfd_h_put_32 (abfd, in->frameoffset, (bfd_byte *) ex->p_frameoffset); 3642 3643 bfd_h_put_16 (abfd, in->framereg, (bfd_byte *) ex->p_framereg); 3644 bfd_h_put_16 (abfd, in->pcreg, (bfd_byte *) ex->p_pcreg); 3645 3646 bfd_h_put_32 (abfd, in->irpss, (bfd_byte *) ex->p_irpss); 3647 #if 0 /* FIXME */ 3648 ecoff_put_off (abfd, in->exception_info, (bfd_byte *) ex->p_exception_info); 3649 #endif 3650 } 3651 3652 3653 /* Read ECOFF debugging information from a .mdebug section into a 3654 ecoff_debug_info structure. */ 3655 3656 boolean 3657 _bfd_mips_elf_read_ecoff_info (abfd, section, debug) 3658 bfd *abfd; 3659 asection *section; 3660 struct ecoff_debug_info *debug; 3661 { 3662 HDRR *symhdr; 3663 const struct ecoff_debug_swap *swap; 3664 char *ext_hdr = NULL; 3665 3666 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; 3667 memset (debug, 0, sizeof (*debug)); 3668 3669 ext_hdr = (char *) bfd_malloc ((size_t) swap->external_hdr_size); 3670 if (ext_hdr == NULL && swap->external_hdr_size != 0) 3671 goto error_return; 3672 3673 if (bfd_get_section_contents (abfd, section, ext_hdr, (file_ptr) 0, 3674 swap->external_hdr_size) 3675 == false) 3676 goto error_return; 3677 3678 symhdr = &debug->symbolic_header; 3679 (*swap->swap_hdr_in) (abfd, ext_hdr, symhdr); 3680 3681 /* The symbolic header contains absolute file offsets and sizes to 3682 read. */ 3683 #define READ(ptr, offset, count, size, type) \ 3684 if (symhdr->count == 0) \ 3685 debug->ptr = NULL; \ 3686 else \ 3687 { \ 3688 debug->ptr = (type) bfd_malloc ((size_t) (size * symhdr->count)); \ 3689 if (debug->ptr == NULL) \ 3690 goto error_return; \ 3691 if (bfd_seek (abfd, (file_ptr) symhdr->offset, SEEK_SET) != 0 \ 3692 || (bfd_read (debug->ptr, size, symhdr->count, \ 3693 abfd) != size * symhdr->count)) \ 3694 goto error_return; \ 3695 } 3696 3697 READ (line, cbLineOffset, cbLine, sizeof (unsigned char), unsigned char *); 3698 READ (external_dnr, cbDnOffset, idnMax, swap->external_dnr_size, PTR); 3699 READ (external_pdr, cbPdOffset, ipdMax, swap->external_pdr_size, PTR); 3700 READ (external_sym, cbSymOffset, isymMax, swap->external_sym_size, PTR); 3701 READ (external_opt, cbOptOffset, ioptMax, swap->external_opt_size, PTR); 3702 READ (external_aux, cbAuxOffset, iauxMax, sizeof (union aux_ext), 3703 union aux_ext *); 3704 READ (ss, cbSsOffset, issMax, sizeof (char), char *); 3705 READ (ssext, cbSsExtOffset, issExtMax, sizeof (char), char *); 3706 READ (external_fdr, cbFdOffset, ifdMax, swap->external_fdr_size, PTR); 3707 READ (external_rfd, cbRfdOffset, crfd, swap->external_rfd_size, PTR); 3708 READ (external_ext, cbExtOffset, iextMax, swap->external_ext_size, PTR); 3709 #undef READ 3710 3711 debug->fdr = NULL; 3712 debug->adjust = NULL; 3713 3714 return true; 3715 3716 error_return: 3717 if (ext_hdr != NULL) 3718 free (ext_hdr); 3719 if (debug->line != NULL) 3720 free (debug->line); 3721 if (debug->external_dnr != NULL) 3722 free (debug->external_dnr); 3723 if (debug->external_pdr != NULL) 3724 free (debug->external_pdr); 3725 if (debug->external_sym != NULL) 3726 free (debug->external_sym); 3727 if (debug->external_opt != NULL) 3728 free (debug->external_opt); 3729 if (debug->external_aux != NULL) 3730 free (debug->external_aux); 3731 if (debug->ss != NULL) 3732 free (debug->ss); 3733 if (debug->ssext != NULL) 3734 free (debug->ssext); 3735 if (debug->external_fdr != NULL) 3736 free (debug->external_fdr); 3737 if (debug->external_rfd != NULL) 3738 free (debug->external_rfd); 3739 if (debug->external_ext != NULL) 3740 free (debug->external_ext); 3741 return false; 1573 if (SGI_COMPAT (abfd)) 1574 elf_bad_symtab (abfd) = TRUE; 1575 1576 if (ABI_N32_P (abfd)) 1577 return FALSE; 1578 1579 mach = _bfd_elf_mips_mach (elf_elfheader (abfd)->e_flags); 1580 bfd_default_set_arch_mach (abfd, bfd_arch_mips, mach); 1581 1582 return TRUE; 3742 1583 } 3743 1584 … … 3745 1586 /* MIPS ELF local labels start with '$', not 'L'. */ 3746 1587 3747 static b oolean1588 static bfd_boolean 3748 1589 mips_elf_is_local_label_name (abfd, name) 3749 1590 bfd *abfd; … … 3751 1592 { 3752 1593 if (name[0] == '$') 3753 return true;1594 return TRUE; 3754 1595 3755 1596 /* On Irix 6, the labels go back to starting with '.', so we accept … … 3758 1599 } 3759 1600 3760 /* MIPS ELF uses a special find_nearest_line routine in order the 3761 handle the ECOFF debugging information. */ 3762 3763 struct mips_elf_find_line 3764 { 3765 struct ecoff_debug_info d; 3766 struct ecoff_find_line i; 3767 }; 3768 3769 boolean 3770 _bfd_mips_elf_find_nearest_line (abfd, section, symbols, offset, filename_ptr, 3771 functionname_ptr, line_ptr) 1601 1602 /* Support for core dump NOTE sections. */ 1603 static bfd_boolean 1604 elf32_mips_grok_prstatus (abfd, note) 3772 1605 bfd *abfd; 3773 asection *section; 3774 asymbol **symbols; 3775 bfd_vma offset; 3776 const char **filename_ptr; 3777 const char **functionname_ptr; 3778 unsigned int *line_ptr; 3779 { 3780 asection *msec; 3781 3782 if (_bfd_dwarf1_find_nearest_line (abfd, section, symbols, offset, 3783 filename_ptr, functionname_ptr, 3784 line_ptr)) 3785 return true; 3786 3787 if (_bfd_dwarf2_find_nearest_line (abfd, section, symbols, offset, 3788 filename_ptr, functionname_ptr, 3789 line_ptr, 3790 ABI_64_P (abfd) ? 8 : 0, 3791 &elf_tdata (abfd)->dwarf2_find_line_info)) 3792 return true; 3793 3794 msec = bfd_get_section_by_name (abfd, ".mdebug"); 3795 if (msec != NULL) 3796 { 3797 flagword origflags; 3798 struct mips_elf_find_line *fi; 3799 const struct ecoff_debug_swap * const swap = 3800 get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; 3801 3802 /* If we are called during a link, mips_elf_final_link may have 3803 cleared the SEC_HAS_CONTENTS field. We force it back on here 3804 if appropriate (which it normally will be). */ 3805 origflags = msec->flags; 3806 if (elf_section_data (msec)->this_hdr.sh_type != SHT_NOBITS) 3807 msec->flags |= SEC_HAS_CONTENTS; 3808 3809 fi = elf_tdata (abfd)->find_line_info; 3810 if (fi == NULL) 3811 { 3812 bfd_size_type external_fdr_size; 3813 char *fraw_src; 3814 char *fraw_end; 3815 struct fdr *fdr_ptr; 3816 3817 fi = ((struct mips_elf_find_line *) 3818 bfd_zalloc (abfd, sizeof (struct mips_elf_find_line))); 3819 if (fi == NULL) 3820 { 3821 msec->flags = origflags; 3822 return false; 3823 } 3824 3825 if (! _bfd_mips_elf_read_ecoff_info (abfd, msec, &fi->d)) 3826 { 3827 msec->flags = origflags; 3828 return false; 3829 } 3830 3831 /* Swap in the FDR information. */ 3832 fi->d.fdr = ((struct fdr *) 3833 bfd_alloc (abfd, 3834 (fi->d.symbolic_header.ifdMax * 3835 sizeof (struct fdr)))); 3836 if (fi->d.fdr == NULL) 3837 { 3838 msec->flags = origflags; 3839 return false; 3840 } 3841 external_fdr_size = swap->external_fdr_size; 3842 fdr_ptr = fi->d.fdr; 3843 fraw_src = (char *) fi->d.external_fdr; 3844 fraw_end = (fraw_src 3845 + fi->d.symbolic_header.ifdMax * external_fdr_size); 3846 for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++) 3847 (*swap->swap_fdr_in) (abfd, (PTR) fraw_src, fdr_ptr); 3848 3849 elf_tdata (abfd)->find_line_info = fi; 3850 3851 /* Note that we don't bother to ever free this information. 3852 find_nearest_line is either called all the time, as in 3853 objdump -l, so the information should be saved, or it is 3854 rarely called, as in ld error messages, so the memory 3855 wasted is unimportant. Still, it would probably be a 3856 good idea for free_cached_info to throw it away. */ 3857 } 3858 3859 if (_bfd_ecoff_locate_line (abfd, section, offset, &fi->d, swap, 3860 &fi->i, filename_ptr, functionname_ptr, 3861 line_ptr)) 3862 { 3863 msec->flags = origflags; 3864 return true; 3865 } 3866 3867 msec->flags = origflags; 3868 } 3869 3870 /* Fall back on the generic ELF find_nearest_line routine. */ 3871 3872 return _bfd_elf_find_nearest_line (abfd, section, symbols, offset, 3873 filename_ptr, functionname_ptr, 3874 line_ptr); 3875 } 3876 3877 3878 /* The mips16 compiler uses a couple of special sections to handle 3879 floating point arguments. 3880 3881 Section names that look like .mips16.fn.FNNAME contain stubs that 3882 copy floating point arguments from the fp regs to the gp regs and 3883 then jump to FNNAME. If any 32 bit function calls FNNAME, the 3884 call should be redirected to the stub instead. If no 32 bit 3885 function calls FNNAME, the stub should be discarded. We need to 3886 consider any reference to the function, not just a call, because 3887 if the address of the function is taken we will need the stub, 3888 since the address might be passed to a 32 bit function. 3889 3890 Section names that look like .mips16.call.FNNAME contain stubs 3891 that copy floating point arguments from the gp regs to the fp 3892 regs and then jump to FNNAME. If FNNAME is a 32 bit function, 3893 then any 16 bit function that calls FNNAME should be redirected 3894 to the stub instead. If FNNAME is not a 32 bit function, the 3895 stub should be discarded. 3896 3897 .mips16.call.fp.FNNAME sections are similar, but contain stubs 3898 which call FNNAME and then copy the return value from the fp regs 3899 to the gp regs. These stubs store the return value in $18 while 3900 calling FNNAME; any function which might call one of these stubs 3901 must arrange to save $18 around the call. (This case is not 3902 needed for 32 bit functions that call 16 bit functions, because 3903 16 bit functions always return floating point values in both 3904 $f0/$f1 and $2/$3.) 3905 3906 Note that in all cases FNNAME might be defined statically. 3907 Therefore, FNNAME is not used literally. Instead, the relocation 3908 information will indicate which symbol the section is for. 3909 3910 We record any stubs that we find in the symbol table. */ 3911 3912 #define FN_STUB ".mips16.fn." 3913 #define CALL_STUB ".mips16.call." 3914 #define CALL_FP_STUB ".mips16.call.fp." 3915 3916 /* MIPS ELF linker hash table. */ 3917 3918 struct mips_elf_link_hash_table 3919 { 3920 struct elf_link_hash_table root; 3921 #if 0 3922 /* We no longer use this. */ 3923 /* String section indices for the dynamic section symbols. */ 3924 bfd_size_type dynsym_sec_strindex[SIZEOF_MIPS_DYNSYM_SECNAMES]; 3925 #endif 3926 /* The number of .rtproc entries. */ 3927 bfd_size_type procedure_count; 3928 /* The size of the .compact_rel section (if SGI_COMPAT). */ 3929 bfd_size_type compact_rel_size; 3930 /* This flag indicates that the value of DT_MIPS_RLD_MAP dynamic 3931 entry is set to the address of __rld_obj_head as in Irix 5. */ 3932 boolean use_rld_obj_head; 3933 /* This is the value of the __rld_map or __rld_obj_head symbol. */ 3934 bfd_vma rld_value; 3935 /* This is set if we see any mips16 stub sections. */ 3936 boolean mips16_stubs_seen; 3937 }; 3938 3939 /* Look up an entry in a MIPS ELF linker hash table. */ 3940 3941 #define mips_elf_link_hash_lookup(table, string, create, copy, follow) \ 3942 ((struct mips_elf_link_hash_entry *) \ 3943 elf_link_hash_lookup (&(table)->root, (string), (create), \ 3944 (copy), (follow))) 3945 3946 /* Traverse a MIPS ELF linker hash table. */ 3947 3948 #define mips_elf_link_hash_traverse(table, func, info) \ 3949 (elf_link_hash_traverse \ 3950 (&(table)->root, \ 3951 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \ 3952 (info))) 3953 3954 /* Get the MIPS ELF linker hash table from a link_info structure. */ 3955 3956 #define mips_elf_hash_table(p) \ 3957 ((struct mips_elf_link_hash_table *) ((p)->hash)) 3958 3959 static boolean mips_elf_output_extsym 3960 PARAMS ((struct mips_elf_link_hash_entry *, PTR)); 3961 3962 /* Create an entry in a MIPS ELF linker hash table. */ 3963 3964 static struct bfd_hash_entry * 3965 mips_elf_link_hash_newfunc (entry, table, string) 3966 struct bfd_hash_entry *entry; 3967 struct bfd_hash_table *table; 3968 const char *string; 3969 { 3970 struct mips_elf_link_hash_entry *ret = 3971 (struct mips_elf_link_hash_entry *) entry; 3972 3973 /* Allocate the structure if it has not already been allocated by a 3974 subclass. */ 3975 if (ret == (struct mips_elf_link_hash_entry *) NULL) 3976 ret = ((struct mips_elf_link_hash_entry *) 3977 bfd_hash_allocate (table, 3978 sizeof (struct mips_elf_link_hash_entry))); 3979 if (ret == (struct mips_elf_link_hash_entry *) NULL) 3980 return (struct bfd_hash_entry *) ret; 3981 3982 /* Call the allocation method of the superclass. */ 3983 ret = ((struct mips_elf_link_hash_entry *) 3984 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, 3985 table, string)); 3986 if (ret != (struct mips_elf_link_hash_entry *) NULL) 3987 { 3988 /* Set local fields. */ 3989 memset (&ret->esym, 0, sizeof (EXTR)); 3990 /* We use -2 as a marker to indicate that the information has 3991 not been set. -1 means there is no associated ifd. */ 3992 ret->esym.ifd = -2; 3993 ret->possibly_dynamic_relocs = 0; 3994 ret->min_dyn_reloc_index = 0; 3995 ret->no_fn_stub = false; 3996 ret->fn_stub = NULL; 3997 ret->need_fn_stub = false; 3998 ret->call_stub = NULL; 3999 ret->call_fp_stub = NULL; 4000 } 4001 4002 return (struct bfd_hash_entry *) ret; 4003 } 4004 4005 void 4006 _bfd_mips_elf_hide_symbol (info, h) 4007 struct bfd_link_info *info; 4008 struct mips_elf_link_hash_entry *h; 4009 { 4010 bfd *dynobj; 4011 asection *got; 4012 struct mips_got_info *g; 4013 dynobj = elf_hash_table (info)->dynobj; 4014 got = bfd_get_section_by_name (dynobj, ".got"); 4015 g = (struct mips_got_info *) elf_section_data (got)->tdata; 4016 4017 h->root.elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 4018 h->root.plt.offset = (bfd_vma) -1; 4019 if ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0) 4020 h->root.dynindx = -1; 4021 4022 /* FIXME: Do we allocate too much GOT space here? */ 4023 g->local_gotno++; 4024 got->_raw_size += MIPS_ELF_GOT_SIZE (dynobj); 4025 } 4026 4027 /* Create a MIPS ELF linker hash table. */ 4028 4029 struct bfd_link_hash_table * 4030 _bfd_mips_elf_link_hash_table_create (abfd) 1606 Elf_Internal_Note *note; 1607 { 1608 int offset; 1609 unsigned int raw_size; 1610 1611 switch (note->descsz) 1612 { 1613 default: 1614 return FALSE; 1615 1616 case 256: /* Linux/MIPS */ 1617 /* pr_cursig */ 1618 elf_tdata (abfd)->core_signal = bfd_get_16 (abfd, note->descdata + 12); 1619 1620 /* pr_pid */ 1621 elf_tdata (abfd)->core_pid = bfd_get_32 (abfd, note->descdata + 24); 1622 1623 /* pr_reg */ 1624 offset = 72; 1625 raw_size = 180; 1626 1627 break; 1628 } 1629 1630 /* Make a ".reg/999" section. */ 1631 return _bfd_elfcore_make_pseudosection (abfd, ".reg", 1632 raw_size, note->descpos + offset); 1633 } 1634 1635 static bfd_boolean 1636 elf32_mips_grok_psinfo (abfd, note) 4031 1637 bfd *abfd; 4032 { 4033 struct mips_elf_link_hash_table *ret; 4034 4035 ret = ((struct mips_elf_link_hash_table *) 4036 bfd_alloc (abfd, sizeof (struct mips_elf_link_hash_table))); 4037 if (ret == (struct mips_elf_link_hash_table *) NULL) 4038 return NULL; 4039 4040 if (! _bfd_elf_link_hash_table_init (&ret->root, abfd, 4041 mips_elf_link_hash_newfunc)) 4042 { 4043 bfd_release (abfd, ret); 4044 return NULL; 4045 } 4046 4047 #if 0 4048 /* We no longer use this. */ 4049 for (i = 0; i < SIZEOF_MIPS_DYNSYM_SECNAMES; i++) 4050 ret->dynsym_sec_strindex[i] = (bfd_size_type) -1; 4051 #endif 4052 ret->procedure_count = 0; 4053 ret->compact_rel_size = 0; 4054 ret->use_rld_obj_head = false; 4055 ret->rld_value = 0; 4056 ret->mips16_stubs_seen = false; 4057 4058 return &ret->root.root; 4059 } 4060 4061 /* Hook called by the linker routine which adds symbols from an object 4062 file. We must handle the special MIPS section numbers here. */ 4063 4064 boolean 4065 _bfd_mips_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) 1638 Elf_Internal_Note *note; 1639 { 1640 switch (note->descsz) 1641 { 1642 default: 1643 return FALSE; 1644 1645 case 128: /* Linux/MIPS elf_prpsinfo */ 1646 elf_tdata (abfd)->core_program 1647 = _bfd_elfcore_strndup (abfd, note->descdata + 32, 16); 1648 elf_tdata (abfd)->core_command 1649 = _bfd_elfcore_strndup (abfd, note->descdata + 48, 80); 1650 } 1651 1652 /* Note that for some reason, a spurious space is tacked 1653 onto the end of the args in some (at least one anyway) 1654 implementations, so strip it off if it exists. */ 1655 1656 { 1657 char *command = elf_tdata (abfd)->core_command; 1658 int n = strlen (command); 1659 1660 if (0 < n && command[n - 1] == ' ') 1661 command[n - 1] = '\0'; 1662 } 1663 1664 return TRUE; 1665 } 1666 1667 1668 /* Depending on the target vector we generate some version of Irix 1669 executables or "normal" MIPS ELF ABI executables. */ 1670 static irix_compat_t 1671 elf32_mips_irix_compat (abfd) 1672 bfd *abfd; 1673 { 1674 if ((abfd->xvec == &bfd_elf32_bigmips_vec) 1675 || (abfd->xvec == &bfd_elf32_littlemips_vec)) 1676 return ict_irix5; 1677 else 1678 return ict_none; 1679 } 1680 1681 1682 /* Given a data section and an in-memory embedded reloc section, store 1683 relocation information into the embedded reloc section which can be 1684 used at runtime to relocate the data section. This is called by the 1685 linker when the --embedded-relocs switch is used. This is called 1686 after the add_symbols entry point has been called for all the 1687 objects, and before the final_link entry point is called. */ 1688 1689 bfd_boolean 1690 bfd_mips_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg) 4066 1691 bfd *abfd; 4067 1692 struct bfd_link_info *info; 4068 const Elf_Internal_Sym *sym; 4069 const char **namep; 4070 flagword *flagsp ATTRIBUTE_UNUSED; 4071 asection **secp; 4072 bfd_vma *valp; 4073 { 4074 if (SGI_COMPAT (abfd) 4075 && (abfd->flags & DYNAMIC) != 0 4076 && strcmp (*namep, "_rld_new_interface") == 0) 4077 { 4078 /* Skip Irix 5 rld entry name. */ 4079 *namep = NULL; 4080 return true; 4081 } 4082 4083 switch (sym->st_shndx) 4084 { 4085 case SHN_COMMON: 4086 /* Common symbols less than the GP size are automatically 4087 treated as SHN_MIPS_SCOMMON symbols. */ 4088 if (sym->st_size > elf_gp_size (abfd) 4089 || IRIX_COMPAT (abfd) == ict_irix6) 4090 break; 4091 /* Fall through. */ 4092 case SHN_MIPS_SCOMMON: 4093 *secp = bfd_make_section_old_way (abfd, ".scommon"); 4094 (*secp)->flags |= SEC_IS_COMMON; 4095 *valp = sym->st_size; 4096 break; 4097 4098 case SHN_MIPS_TEXT: 4099 /* This section is used in a shared object. */ 4100 if (elf_tdata (abfd)->elf_text_section == NULL) 1693 asection *datasec; 1694 asection *relsec; 1695 char **errmsg; 1696 { 1697 Elf_Internal_Shdr *symtab_hdr; 1698 Elf_Internal_Sym *isymbuf = NULL; 1699 Elf_Internal_Rela *internal_relocs = NULL; 1700 Elf_Internal_Rela *irel, *irelend; 1701 bfd_byte *p; 1702 1703 BFD_ASSERT (! info->relocateable); 1704 1705 *errmsg = NULL; 1706 1707 if (datasec->reloc_count == 0) 1708 return TRUE; 1709 1710 /* Read this BFD's symbols if we haven't done so already, or get the cached 1711 copy if it exists. */ 1712 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 1713 if (symtab_hdr->sh_info != 0) 1714 { 1715 isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; 1716 if (isymbuf == NULL) 1717 isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, 1718 symtab_hdr->sh_info, 0, 1719 NULL, NULL, NULL); 1720 if (isymbuf == NULL) 1721 goto error_return; 1722 } 1723 1724 /* Get a copy of the native relocations. */ 1725 internal_relocs = (_bfd_elf32_link_read_relocs 1726 (abfd, datasec, (PTR) NULL, (Elf_Internal_Rela *) NULL, 1727 info->keep_memory)); 1728 if (internal_relocs == NULL) 1729 goto error_return; 1730 1731 relsec->contents = (bfd_byte *) bfd_alloc (abfd, datasec->reloc_count * 12); 1732 if (relsec->contents == NULL) 1733 goto error_return; 1734 1735 p = relsec->contents; 1736 1737 irelend = internal_relocs + datasec->reloc_count; 1738 1739 for (irel = internal_relocs; irel < irelend; irel++, p += 12) 1740 { 1741 asection *targetsec; 1742 1743 /* We are going to write a four byte longword into the runtime 1744 reloc section. The longword will be the address in the data 1745 section which must be relocated. It is followed by the name 1746 of the target section NUL-padded or truncated to 8 1747 characters. */ 1748 1749 /* We can only relocate absolute longword relocs at run time. */ 1750 if ((ELF32_R_TYPE (irel->r_info) != (int) R_MIPS_32) && 1751 (ELF32_R_TYPE (irel->r_info) != (int) R_MIPS_64)) 4101 1752 { 4102 asymbol *elf_text_symbol; 4103 asection *elf_text_section; 4104 4105 elf_text_section = bfd_zalloc (abfd, sizeof (asection)); 4106 if (elf_text_section == NULL) 4107 return false; 4108 4109 elf_text_symbol = bfd_zalloc (abfd, sizeof (asymbol)); 4110 if (elf_text_symbol == NULL) 4111 return false; 4112 4113 /* Initialize the section. */ 4114 4115 elf_tdata (abfd)->elf_text_section = elf_text_section; 4116 elf_tdata (abfd)->elf_text_symbol = elf_text_symbol; 4117 4118 elf_text_section->symbol = elf_text_symbol; 4119 elf_text_section->symbol_ptr_ptr = &elf_tdata (abfd)->elf_text_symbol; 4120 4121 elf_text_section->name = ".text"; 4122 elf_text_section->flags = SEC_NO_FLAGS; 4123 elf_text_section->output_section = NULL; 4124 elf_text_section->owner = abfd; 4125 elf_text_symbol->name = ".text"; 4126 elf_text_symbol->flags = BSF_SECTION_SYM | BSF_DYNAMIC; 4127 elf_text_symbol->section = elf_text_section; 1753 *errmsg = _("unsupported reloc type"); 1754 bfd_set_error (bfd_error_bad_value); 1755 goto error_return; 4128 1756 } 4129 /* This code used to do *secp = bfd_und_section_ptr if 4130 info->shared. I don't know why, and that doesn't make sense, 4131 so I took it out. */ 4132 *secp = elf_tdata (abfd)->elf_text_section; 4133 break; 4134 4135 case SHN_MIPS_ACOMMON: 4136 /* Fall through. XXX Can we treat this as allocated data? */ 4137 case SHN_MIPS_DATA: 4138 /* This section is used in a shared object. */ 4139 if (elf_tdata (abfd)->elf_data_section == NULL) 1757 /* Get the target section referred to by the reloc. */ 1758 if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) 4140 1759 { 4141 asymbol *elf_data_symbol; 4142 asection *elf_data_section; 4143 4144 elf_data_section = bfd_zalloc (abfd, sizeof (asection)); 4145 if (elf_data_section == NULL) 4146 return false; 4147 4148 elf_data_symbol = bfd_zalloc (abfd, sizeof (asymbol)); 4149 if (elf_data_symbol == NULL) 4150 return false; 4151 4152 /* Initialize the section. */ 4153 4154 elf_tdata (abfd)->elf_data_section = elf_data_section; 4155 elf_tdata (abfd)->elf_data_symbol = elf_data_symbol; 4156 4157 elf_data_section->symbol = elf_data_symbol; 4158 elf_data_section->symbol_ptr_ptr = &elf_tdata (abfd)->elf_data_symbol; 4159 4160 elf_data_section->name = ".data"; 4161 elf_data_section->flags = SEC_NO_FLAGS; 4162 elf_data_section->output_section = NULL; 4163 elf_data_section->owner = abfd; 4164 elf_data_symbol->name = ".data"; 4165 elf_data_symbol->flags = BSF_SECTION_SYM | BSF_DYNAMIC; 4166 elf_data_symbol->section = elf_data_section; 4167 } 4168 /* This code used to do *secp = bfd_und_section_ptr if 4169 info->shared. I don't know why, and that doesn't make sense, 4170 so I took it out. */ 4171 *secp = elf_tdata (abfd)->elf_data_section; 4172 break; 4173 4174 case SHN_MIPS_SUNDEFINED: 4175 *secp = bfd_und_section_ptr; 4176 break; 4177 } 4178 4179 if (SGI_COMPAT (abfd) 4180 && ! info->shared 4181 && info->hash->creator == abfd->xvec 4182 && strcmp (*namep, "__rld_obj_head") == 0) 4183 { 4184 struct elf_link_hash_entry *h; 4185 4186 /* Mark __rld_obj_head as dynamic. */ 4187 h = NULL; 4188 if (! (_bfd_generic_link_add_one_symbol 4189 (info, abfd, *namep, BSF_GLOBAL, *secp, 4190 (bfd_vma) *valp, (const char *) NULL, false, 4191 get_elf_backend_data (abfd)->collect, 4192 (struct bfd_link_hash_entry **) &h))) 4193 return false; 4194 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF; 4195 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; 4196 h->type = STT_OBJECT; 4197 4198 if (! bfd_elf32_link_record_dynamic_symbol (info, h)) 4199 return false; 4200 4201 mips_elf_hash_table (info)->use_rld_obj_head = true; 4202 } 4203 4204 /* If this is a mips16 text symbol, add 1 to the value to make it 4205 odd. This will cause something like .word SYM to come up with 4206 the right value when it is loaded into the PC. */ 4207 if (sym->st_other == STO_MIPS16) 4208 ++*valp; 4209 4210 return true; 4211 } 4212 4213 /* Structure used to pass information to mips_elf_output_extsym. */ 4214 4215 struct extsym_info 4216 { 4217 bfd *abfd; 4218 struct bfd_link_info *info; 4219 struct ecoff_debug_info *debug; 4220 const struct ecoff_debug_swap *swap; 4221 boolean failed; 4222 }; 4223 4224 /* This routine is used to write out ECOFF debugging external symbol 4225 information. It is called via mips_elf_link_hash_traverse. The 4226 ECOFF external symbol information must match the ELF external 4227 symbol information. Unfortunately, at this point we don't know 4228 whether a symbol is required by reloc information, so the two 4229 tables may wind up being different. We must sort out the external 4230 symbol information before we can set the final size of the .mdebug 4231 section, and we must set the size of the .mdebug section before we 4232 can relocate any sections, and we can't know which symbols are 4233 required by relocation until we relocate the sections. 4234 Fortunately, it is relatively unlikely that any symbol will be 4235 stripped but required by a reloc. In particular, it can not happen 4236 when generating a final executable. */ 4237 4238 static boolean 4239 mips_elf_output_extsym (h, data) 4240 struct mips_elf_link_hash_entry *h; 4241 PTR data; 4242 { 4243 struct extsym_info *einfo = (struct extsym_info *) data; 4244 boolean strip; 4245 asection *sec, *output_section; 4246 4247 if (h->root.indx == -2) 4248 strip = false; 4249 else if (((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 4250 || (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0) 4251 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0 4252 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0) 4253 strip = true; 4254 else if (einfo->info->strip == strip_all 4255 || (einfo->info->strip == strip_some 4256 && bfd_hash_lookup (einfo->info->keep_hash, 4257 h->root.root.root.string, 4258 false, false) == NULL)) 4259 strip = true; 4260 else 4261 strip = false; 4262 4263 if (strip) 4264 return true; 4265 4266 if (h->esym.ifd == -2) 4267 { 4268 h->esym.jmptbl = 0; 4269 h->esym.cobol_main = 0; 4270 h->esym.weakext = 0; 4271 h->esym.reserved = 0; 4272 h->esym.ifd = ifdNil; 4273 h->esym.asym.value = 0; 4274 h->esym.asym.st = stGlobal; 4275 4276 if (h->root.root.type == bfd_link_hash_undefined 4277 || h->root.root.type == bfd_link_hash_undefweak) 4278 { 4279 const char *name; 4280 4281 /* Use undefined class. Also, set class and type for some 4282 special symbols. */ 4283 name = h->root.root.root.string; 4284 if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0 4285 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0) 4286 { 4287 h->esym.asym.sc = scData; 4288 h->esym.asym.st = stLabel; 4289 h->esym.asym.value = 0; 4290 } 4291 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0) 4292 { 4293 h->esym.asym.sc = scAbs; 4294 h->esym.asym.st = stLabel; 4295 h->esym.asym.value = 4296 mips_elf_hash_table (einfo->info)->procedure_count; 4297 } 4298 else if (strcmp (name, "_gp_disp") == 0) 4299 { 4300 h->esym.asym.sc = scAbs; 4301 h->esym.asym.st = stLabel; 4302 h->esym.asym.value = elf_gp (einfo->abfd); 4303 } 4304 else 4305 h->esym.asym.sc = scUndefined; 4306 } 4307 else if (h->root.root.type != bfd_link_hash_defined 4308 && h->root.root.type != bfd_link_hash_defweak) 4309 h->esym.asym.sc = scAbs; 4310 else 4311 { 4312 const char *name; 4313 4314 sec = h->root.root.u.def.section; 4315 output_section = sec->output_section; 4316 4317 /* When making a shared library and symbol h is the one from 4318 the another shared library, OUTPUT_SECTION may be null. */ 4319 if (output_section == NULL) 4320 h->esym.asym.sc = scUndefined; 4321 else 4322 { 4323 name = bfd_section_name (output_section->owner, output_section); 4324 4325 if (strcmp (name, ".text") == 0) 4326 h->esym.asym.sc = scText; 4327 else if (strcmp (name, ".data") == 0) 4328 h->esym.asym.sc = scData; 4329 else if (strcmp (name, ".sdata") == 0) 4330 h->esym.asym.sc = scSData; 4331 else if (strcmp (name, ".rodata") == 0 4332 || strcmp (name, ".rdata") == 0) 4333 h->esym.asym.sc = scRData; 4334 else if (strcmp (name, ".bss") == 0) 4335 h->esym.asym.sc = scBss; 4336 else if (strcmp (name, ".sbss") == 0) 4337 h->esym.asym.sc = scSBss; 4338 else if (strcmp (name, ".init") == 0) 4339 h->esym.asym.sc = scInit; 4340 else if (strcmp (name, ".fini") == 0) 4341 h->esym.asym.sc = scFini; 4342 else 4343 h->esym.asym.sc = scAbs; 4344 } 4345 } 4346 4347 h->esym.asym.reserved = 0; 4348 h->esym.asym.index = indexNil; 4349 } 4350 4351 if (h->root.root.type == bfd_link_hash_common) 4352 h->esym.asym.value = h->root.root.u.c.size; 4353 else if (h->root.root.type == bfd_link_hash_defined 4354 || h->root.root.type == bfd_link_hash_defweak) 4355 { 4356 if (h->esym.asym.sc == scCommon) 4357 h->esym.asym.sc = scBss; 4358 else if (h->esym.asym.sc == scSCommon) 4359 h->esym.asym.sc = scSBss; 4360 4361 sec = h->root.root.u.def.section; 4362 output_section = sec->output_section; 4363 if (output_section != NULL) 4364 h->esym.asym.value = (h->root.root.u.def.value 4365 + sec->output_offset 4366 + output_section->vma); 4367 else 4368 h->esym.asym.value = 0; 4369 } 4370 else if ((h->root.elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) 4371 { 4372 struct mips_elf_link_hash_entry *hd = h; 4373 boolean no_fn_stub = h->no_fn_stub; 4374 4375 while (hd->root.root.type == bfd_link_hash_indirect) 4376 { 4377 hd = (struct mips_elf_link_hash_entry *)h->root.root.u.i.link; 4378 no_fn_stub = no_fn_stub || hd->no_fn_stub; 4379 } 4380 4381 if (!no_fn_stub) 4382 { 4383 /* Set type and value for a symbol with a function stub. */ 4384 h->esym.asym.st = stProc; 4385 sec = hd->root.root.u.def.section; 4386 if (sec == NULL) 4387 h->esym.asym.value = 0; 4388 else 4389 { 4390 output_section = sec->output_section; 4391 if (output_section != NULL) 4392 h->esym.asym.value = (hd->root.plt.offset 4393 + sec->output_offset 4394 + output_section->vma); 4395 else 4396 h->esym.asym.value = 0; 4397 } 4398 #if 0 /* FIXME? */ 4399 h->esym.ifd = 0; 4400 #endif 4401 } 4402 } 4403 4404 if (! bfd_ecoff_debug_one_external (einfo->abfd, einfo->debug, einfo->swap, 4405 h->root.root.root.string, 4406 &h->esym)) 4407 { 4408 einfo->failed = true; 4409 return false; 4410 } 4411 4412 return true; 4413 } 4414 4415 /* Create a runtime procedure table from the .mdebug section. */ 4416 4417 static boolean 4418 mips_elf_create_procedure_table (handle, abfd, info, s, debug) 4419 PTR handle; 4420 bfd *abfd; 4421 struct bfd_link_info *info; 4422 asection *s; 4423 struct ecoff_debug_info *debug; 4424 { 4425 const struct ecoff_debug_swap *swap; 4426 HDRR *hdr = &debug->symbolic_header; 4427 RPDR *rpdr, *rp; 4428 struct rpdr_ext *erp; 4429 PTR rtproc; 4430 struct pdr_ext *epdr; 4431 struct sym_ext *esym; 4432 char *ss, **sv; 4433 char *str; 4434 unsigned long size, count; 4435 unsigned long sindex; 4436 unsigned long i; 4437 PDR pdr; 4438 SYMR sym; 4439 const char *no_name_func = _("static procedure (no name)"); 4440 4441 epdr = NULL; 4442 rpdr = NULL; 4443 esym = NULL; 4444 ss = NULL; 4445 sv = NULL; 4446 4447 swap = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; 4448 4449 sindex = strlen (no_name_func) + 1; 4450 count = hdr->ipdMax; 4451 if (count > 0) 4452 { 4453 size = swap->external_pdr_size; 4454 4455 epdr = (struct pdr_ext *) bfd_malloc (size * count); 4456 if (epdr == NULL) 4457 goto error_return; 4458 4459 if (! _bfd_ecoff_get_accumulated_pdr (handle, (PTR) epdr)) 4460 goto error_return; 4461 4462 size = sizeof (RPDR); 4463 rp = rpdr = (RPDR *) bfd_malloc (size * count); 4464 if (rpdr == NULL) 4465 goto error_return; 4466 4467 sv = (char **) bfd_malloc (sizeof (char *) * count); 4468 if (sv == NULL) 4469 goto error_return; 4470 4471 count = hdr->isymMax; 4472 size = swap->external_sym_size; 4473 esym = (struct sym_ext *) bfd_malloc (size * count); 4474 if (esym == NULL) 4475 goto error_return; 4476 4477 if (! _bfd_ecoff_get_accumulated_sym (handle, (PTR) esym)) 4478 goto error_return; 4479 4480 count = hdr->issMax; 4481 ss = (char *) bfd_malloc (count); 4482 if (ss == NULL) 4483 goto error_return; 4484 if (! _bfd_ecoff_get_accumulated_ss (handle, (PTR) ss)) 4485 goto error_return; 4486 4487 count = hdr->ipdMax; 4488 for (i = 0; i < count; i++, rp++) 4489 { 4490 (*swap->swap_pdr_in) (abfd, (PTR) (epdr + i), &pdr); 4491 (*swap->swap_sym_in) (abfd, (PTR) &esym[pdr.isym], &sym); 4492 rp->adr = sym.value; 4493 rp->regmask = pdr.regmask; 4494 rp->regoffset = pdr.regoffset; 4495 rp->fregmask = pdr.fregmask; 4496 rp->fregoffset = pdr.fregoffset; 4497 rp->frameoffset = pdr.frameoffset; 4498 rp->framereg = pdr.framereg; 4499 rp->pcreg = pdr.pcreg; 4500 rp->irpss = sindex; 4501 sv[i] = ss + sym.iss; 4502 sindex += strlen (sv[i]) + 1; 4503 } 4504 } 4505 4506 size = sizeof (struct rpdr_ext) * (count + 2) + sindex; 4507 size = BFD_ALIGN (size, 16); 4508 rtproc = (PTR) bfd_alloc (abfd, size); 4509 if (rtproc == NULL) 4510 { 4511 mips_elf_hash_table (info)->procedure_count = 0; 4512 goto error_return; 4513 } 4514 4515 mips_elf_hash_table (info)->procedure_count = count + 2; 4516 4517 erp = (struct rpdr_ext *) rtproc; 4518 memset (erp, 0, sizeof (struct rpdr_ext)); 4519 erp++; 4520 str = (char *) rtproc + sizeof (struct rpdr_ext) * (count + 2); 4521 strcpy (str, no_name_func); 4522 str += strlen (no_name_func) + 1; 4523 for (i = 0; i < count; i++) 4524 { 4525 ecoff_swap_rpdr_out (abfd, rpdr + i, erp + i); 4526 strcpy (str, sv[i]); 4527 str += strlen (sv[i]) + 1; 4528 } 4529 ecoff_put_off (abfd, (bfd_vma) -1, (bfd_byte *) (erp + count)->p_adr); 4530 4531 /* Set the size and contents of .rtproc section. */ 4532 s->_raw_size = size; 4533 s->contents = (bfd_byte *) rtproc; 4534 4535 /* Skip this section later on (I don't think this currently 4536 matters, but someday it might). */ 4537 s->link_order_head = (struct bfd_link_order *) NULL; 4538 4539 if (epdr != NULL) 4540 free (epdr); 4541 if (rpdr != NULL) 4542 free (rpdr); 4543 if (esym != NULL) 4544 free (esym); 4545 if (ss != NULL) 4546 free (ss); 4547 if (sv != NULL) 4548 free (sv); 4549 4550 return true; 4551 4552 error_return: 4553 if (epdr != NULL) 4554 free (epdr); 4555 if (rpdr != NULL) 4556 free (rpdr); 4557 if (esym != NULL) 4558 free (esym); 4559 if (ss != NULL) 4560 free (ss); 4561 if (sv != NULL) 4562 free (sv); 4563 return false; 4564 } 4565 4566 /* A comparison routine used to sort .gptab entries. */ 4567 4568 static int 4569 gptab_compare (p1, p2) 4570 const PTR p1; 4571 const PTR p2; 4572 { 4573 const Elf32_gptab *a1 = (const Elf32_gptab *) p1; 4574 const Elf32_gptab *a2 = (const Elf32_gptab *) p2; 4575 4576 return a1->gt_entry.gt_g_value - a2->gt_entry.gt_g_value; 4577 } 4578 4579 /* We need to use a special link routine to handle the .reginfo and 4580 the .mdebug sections. We need to merge all instances of these 4581 sections together, not write them all out sequentially. */ 4582 4583 boolean 4584 _bfd_mips_elf_final_link (abfd, info) 4585 bfd *abfd; 4586 struct bfd_link_info *info; 4587 { 4588 asection **secpp; 4589 asection *o; 4590 struct bfd_link_order *p; 4591 asection *reginfo_sec, *mdebug_sec, *gptab_data_sec, *gptab_bss_sec; 4592 asection *rtproc_sec; 4593 Elf32_RegInfo reginfo; 4594 struct ecoff_debug_info debug; 4595 const struct ecoff_debug_swap *swap 4596 = get_elf_backend_data (abfd)->elf_backend_ecoff_debug_swap; 4597 HDRR *symhdr = &debug.symbolic_header; 4598 PTR mdebug_handle = NULL; 4599 asection *s; 4600 EXTR esym; 4601 bfd_vma last; 4602 unsigned int i; 4603 static const char * const name[] = 4604 { 4605 ".text", ".init", ".fini", ".data", 4606 ".rodata", ".sdata", ".sbss", ".bss" 4607 }; 4608 static const int sc[] = 4609 { 4610 scText, scInit, scFini, scData, 4611 scRData, scSData, scSBss, scBss 4612 }; 4613 4614 /* If all the things we linked together were PIC, but we're 4615 producing an executable (rather than a shared object), then the 4616 resulting file is CPIC (i.e., it calls PIC code.) */ 4617 if (!info->shared 4618 && !info->relocateable 4619 && elf_elfheader (abfd)->e_flags & EF_MIPS_PIC) 4620 { 4621 elf_elfheader (abfd)->e_flags &= ~EF_MIPS_PIC; 4622 elf_elfheader (abfd)->e_flags |= EF_MIPS_CPIC; 4623 } 4624 4625 /* We'd carefully arranged the dynamic symbol indices, and then the 4626 generic size_dynamic_sections renumbered them out from under us. 4627 Rather than trying somehow to prevent the renumbering, just do 4628 the sort again. */ 4629 if (elf_hash_table (info)->dynamic_sections_created) 4630 { 4631 bfd *dynobj; 4632 asection *got; 4633 struct mips_got_info *g; 4634 4635 /* When we resort, we must tell mips_elf_sort_hash_table what 4636 the lowest index it may use is. That's the number of section 4637 symbols we're going to add. The generic ELF linker only 4638 adds these symbols when building a shared object. Note that 4639 we count the sections after (possibly) removing the .options 4640 section above. */ 4641 if (!mips_elf_sort_hash_table (info, (info->shared 4642 ? bfd_count_sections (abfd) + 1 4643 : 1))) 4644 return false; 4645 4646 /* Make sure we didn't grow the global .got region. */ 4647 dynobj = elf_hash_table (info)->dynobj; 4648 got = bfd_get_section_by_name (dynobj, ".got"); 4649 g = (struct mips_got_info *) elf_section_data (got)->tdata; 4650 4651 if (g->global_gotsym != NULL) 4652 BFD_ASSERT ((elf_hash_table (info)->dynsymcount 4653 - g->global_gotsym->dynindx) 4654 <= g->global_gotno); 4655 } 4656 4657 /* On IRIX5, we omit the .options section. On IRIX6, however, we 4658 include it, even though we don't process it quite right. (Some 4659 entries are supposed to be merged.) Empirically, we seem to be 4660 better off including it then not. */ 4661 if (IRIX_COMPAT (abfd) == ict_irix5 || IRIX_COMPAT (abfd) == ict_none) 4662 for (secpp = &abfd->sections; *secpp != NULL; secpp = &(*secpp)->next) 4663 { 4664 if (strcmp ((*secpp)->name, MIPS_ELF_OPTIONS_SECTION_NAME (abfd)) == 0) 4665 { 4666 for (p = (*secpp)->link_order_head; p != NULL; p = p->next) 4667 if (p->type == bfd_indirect_link_order) 4668 p->u.indirect.section->flags &= ~SEC_HAS_CONTENTS; 4669 (*secpp)->link_order_head = NULL; 4670 *secpp = (*secpp)->next; 4671 --abfd->section_count; 4672 4673 break; 4674 } 4675 } 4676 4677 /* Get a value for the GP register. */ 4678 if (elf_gp (abfd) == 0) 4679 { 4680 struct bfd_link_hash_entry *h; 4681 4682 h = bfd_link_hash_lookup (info->hash, "_gp", false, false, true); 4683 if (h != (struct bfd_link_hash_entry *) NULL 4684 && h->type == bfd_link_hash_defined) 4685 elf_gp (abfd) = (h->u.def.value 4686 + h->u.def.section->output_section->vma 4687 + h->u.def.section->output_offset); 4688 else if (info->relocateable) 4689 { 4690 bfd_vma lo; 4691 4692 /* Find the GP-relative section with the lowest offset. */ 4693 lo = (bfd_vma) -1; 4694 for (o = abfd->sections; o != (asection *) NULL; o = o->next) 4695 if (o->vma < lo 4696 && (elf_section_data (o)->this_hdr.sh_flags & SHF_MIPS_GPREL)) 4697 lo = o->vma; 4698 4699 /* And calculate GP relative to that. */ 4700 elf_gp (abfd) = lo + ELF_MIPS_GP_OFFSET (abfd); 1760 Elf_Internal_Sym *isym; 1761 1762 /* A local symbol. */ 1763 isym = isymbuf + ELF32_R_SYM (irel->r_info); 1764 targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx); 4701 1765 } 4702 1766 else 4703 1767 { 4704 /* If the relocate_section function needs to do a reloc 4705 involving the GP value, it should make a reloc_dangerous 4706 callback to warn that GP is not defined. */ 1768 unsigned long indx; 1769 struct elf_link_hash_entry *h; 1770 1771 /* An external symbol. */ 1772 indx = ELF32_R_SYM (irel->r_info); 1773 h = elf_sym_hashes (abfd)[indx]; 1774 targetsec = NULL; 1775 /* 1776 For some reason, in certain programs, the symbol will 1777 not be in the hash table. It seems to happen when you 1778 declare a static table of pointers to const external structures. 1779 In this case, the relocs are relative to data, not 1780 text, so just treating it like an undefined link 1781 should be sufficient. */ 1782 BFD_ASSERT(h != NULL); 1783 if (h->root.type == bfd_link_hash_defined 1784 || h->root.type == bfd_link_hash_defweak) 1785 targetsec = h->root.u.def.section; 4707 1786 } 4708 } 4709 4710 /* Go through the sections and collect the .reginfo and .mdebug 4711 information. */ 4712 reginfo_sec = NULL; 4713 mdebug_sec = NULL; 4714 gptab_data_sec = NULL; 4715 gptab_bss_sec = NULL; 4716 for (o = abfd->sections; o != (asection *) NULL; o = o->next) 4717 { 4718 if (strcmp (o->name, ".reginfo") == 0) 4719 { 4720 memset (®info, 0, sizeof reginfo); 4721 4722 /* We have found the .reginfo section in the output file. 4723 Look through all the link_orders comprising it and merge 4724 the information together. */ 4725 for (p = o->link_order_head; 4726 p != (struct bfd_link_order *) NULL; 4727 p = p->next) 4728 { 4729 asection *input_section; 4730 bfd *input_bfd; 4731 Elf32_External_RegInfo ext; 4732 Elf32_RegInfo sub; 4733 4734 if (p->type != bfd_indirect_link_order) 4735 { 4736 if (p->type == bfd_fill_link_order) 4737 continue; 4738 abort (); 4739 } 4740 4741 input_section = p->u.indirect.section; 4742 input_bfd = input_section->owner; 4743 4744 /* The linker emulation code has probably clobbered the 4745 size to be zero bytes. */ 4746 if (input_section->_raw_size == 0) 4747 input_section->_raw_size = sizeof (Elf32_External_RegInfo); 4748 4749 if (! bfd_get_section_contents (input_bfd, input_section, 4750 (PTR) &ext, 4751 (file_ptr) 0, 4752 sizeof ext)) 4753 return false; 4754 4755 bfd_mips_elf32_swap_reginfo_in (input_bfd, &ext, &sub); 4756 4757 reginfo.ri_gprmask |= sub.ri_gprmask; 4758 reginfo.ri_cprmask[0] |= sub.ri_cprmask[0]; 4759 reginfo.ri_cprmask[1] |= sub.ri_cprmask[1]; 4760 reginfo.ri_cprmask[2] |= sub.ri_cprmask[2]; 4761 reginfo.ri_cprmask[3] |= sub.ri_cprmask[3]; 4762 4763 /* ri_gp_value is set by the function 4764 mips_elf32_section_processing when the section is 4765 finally written out. */ 4766 4767 /* Hack: reset the SEC_HAS_CONTENTS flag so that 4768 elf_link_input_bfd ignores this section. */ 4769 input_section->flags &= ~SEC_HAS_CONTENTS; 4770 } 4771 4772 /* Size has been set in mips_elf_always_size_sections */ 4773 BFD_ASSERT(o->_raw_size == sizeof (Elf32_External_RegInfo)); 4774 4775 /* Skip this section later on (I don't think this currently 4776 matters, but someday it might). */ 4777 o->link_order_head = (struct bfd_link_order *) NULL; 4778 4779 reginfo_sec = o; 4780 } 4781 4782 if (strcmp (o->name, ".mdebug") == 0) 4783 { 4784 struct extsym_info einfo; 4785 4786 /* We have found the .mdebug section in the output file. 4787 Look through all the link_orders comprising it and merge 4788 the information together. */ 4789 symhdr->magic = swap->sym_magic; 4790 /* FIXME: What should the version stamp be? */ 4791 symhdr->vstamp = 0; 4792 symhdr->ilineMax = 0; 4793 symhdr->cbLine = 0; 4794 symhdr->idnMax = 0; 4795 symhdr->ipdMax = 0; 4796 symhdr->isymMax = 0; 4797 symhdr->ioptMax = 0; 4798 symhdr->iauxMax = 0; 4799 symhdr->issMax = 0; 4800 symhdr->issExtMax = 0; 4801 symhdr->ifdMax = 0; 4802 symhdr->crfd = 0; 4803 symhdr->iextMax = 0; 4804 4805 /* We accumulate the debugging information itself in the 4806 debug_info structure. */ 4807 debug.line = NULL; 4808 debug.external_dnr = NULL; 4809 debug.external_pdr = NULL; 4810 debug.external_sym = NULL; 4811 debug.external_opt = NULL; 4812 debug.external_aux = NULL; 4813 debug.ss = NULL; 4814 debug.ssext = debug.ssext_end = NULL; 4815 debug.external_fdr = NULL; 4816 debug.external_rfd = NULL; 4817 debug.external_ext = debug.external_ext_end = NULL; 4818 4819 mdebug_handle = bfd_ecoff_debug_init (abfd, &debug, swap, info); 4820 if (mdebug_handle == (PTR) NULL) 4821 return false; 4822 4823 esym.jmptbl = 0; 4824 esym.cobol_main = 0; 4825 esym.weakext = 0; 4826 esym.reserved = 0; 4827 esym.ifd = ifdNil; 4828 esym.asym.iss = issNil; 4829 esym.asym.st = stLocal; 4830 esym.asym.reserved = 0; 4831 esym.asym.index = indexNil; 4832 last = 0; 4833 for (i = 0; i < 8; i++) 4834 { 4835 esym.asym.sc = sc[i]; 4836 s = bfd_get_section_by_name (abfd, name[i]); 4837 if (s != NULL) 4838 { 4839 esym.asym.value = s->vma; 4840 last = s->vma + s->_raw_size; 4841 } 4842 else 4843 esym.asym.value = last; 4844 if (!bfd_ecoff_debug_one_external (abfd, &debug, swap, 4845 name[i], &esym)) 4846 return false; 4847 } 4848 4849 for (p = o->link_order_head; 4850 p != (struct bfd_link_order *) NULL; 4851 p = p->next) 4852 { 4853 asection *input_section; 4854 bfd *input_bfd; 4855 const struct ecoff_debug_swap *input_swap; 4856 struct ecoff_debug_info input_debug; 4857 char *eraw_src; 4858 char *eraw_end; 4859 4860 if (p->type != bfd_indirect_link_order) 4861 { 4862 if (p->type == bfd_fill_link_order) 4863 continue; 4864 abort (); 4865 } 4866 4867 input_section = p->u.indirect.section; 4868 input_bfd = input_section->owner; 4869 4870 if (bfd_get_flavour (input_bfd) != bfd_target_elf_flavour 4871 || (get_elf_backend_data (input_bfd) 4872 ->elf_backend_ecoff_debug_swap) == NULL) 4873 { 4874 /* I don't know what a non MIPS ELF bfd would be 4875 doing with a .mdebug section, but I don't really 4876 want to deal with it. */ 4877 continue; 4878 } 4879 4880 input_swap = (get_elf_backend_data (input_bfd) 4881 ->elf_backend_ecoff_debug_swap); 4882 4883 BFD_ASSERT (p->size == input_section->_raw_size); 4884 4885 /* The ECOFF linking code expects that we have already 4886 read in the debugging information and set up an 4887 ecoff_debug_info structure, so we do that now. */ 4888 if (! _bfd_mips_elf_read_ecoff_info (input_bfd, input_section, 4889 &input_debug)) 4890 return false; 4891 4892 if (! (bfd_ecoff_debug_accumulate 4893 (mdebug_handle, abfd, &debug, swap, input_bfd, 4894 &input_debug, input_swap, info))) 4895 return false; 4896 4897 /* Loop through the external symbols. For each one with 4898 interesting information, try to find the symbol in 4899 the linker global hash table and save the information 4900 for the output external symbols. */ 4901 eraw_src = input_debug.external_ext; 4902 eraw_end = (eraw_src 4903 + (input_debug.symbolic_header.iextMax 4904 * input_swap->external_ext_size)); 4905 for (; 4906 eraw_src < eraw_end; 4907 eraw_src += input_swap->external_ext_size) 4908 { 4909 EXTR ext; 4910 const char *name; 4911 struct mips_elf_link_hash_entry *h; 4912 4913 (*input_swap->swap_ext_in) (input_bfd, (PTR) eraw_src, &ext); 4914 if (ext.asym.sc == scNil 4915 || ext.asym.sc == scUndefined 4916 || ext.asym.sc == scSUndefined) 4917 continue; 4918 4919 name = input_debug.ssext + ext.asym.iss; 4920 h = mips_elf_link_hash_lookup (mips_elf_hash_table (info), 4921 name, false, false, true); 4922 if (h == NULL || h->esym.ifd != -2) 4923 continue; 4924 4925 if (ext.ifd != -1) 4926 { 4927 BFD_ASSERT (ext.ifd 4928 < input_debug.symbolic_header.ifdMax); 4929 ext.ifd = input_debug.ifdmap[ext.ifd]; 4930 } 4931 4932 h->esym = ext; 4933 } 4934 4935 /* Free up the information we just read. */ 4936 free (input_debug.line); 4937 free (input_debug.external_dnr); 4938 free (input_debug.external_pdr); 4939 free (input_debug.external_sym); 4940 free (input_debug.external_opt); 4941 free (input_debug.external_aux); 4942 free (input_debug.ss); 4943 free (input_debug.ssext); 4944 free (input_debug.external_fdr); 4945 free (input_debug.external_rfd); 4946 free (input_debug.external_ext); 4947 4948 /* Hack: reset the SEC_HAS_CONTENTS flag so that 4949 elf_link_input_bfd ignores this section. */ 4950 input_section->flags &= ~SEC_HAS_CONTENTS; 4951 } 4952 4953 if (SGI_COMPAT (abfd) && info->shared) 4954 { 4955 /* Create .rtproc section. */ 4956 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc"); 4957 if (rtproc_sec == NULL) 4958 { 4959 flagword flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY 4960 | SEC_LINKER_CREATED | SEC_READONLY); 4961 4962 rtproc_sec = bfd_make_section (abfd, ".rtproc"); 4963 if (rtproc_sec == NULL 4964 || ! bfd_set_section_flags (abfd, rtproc_sec, flags) 4965 || ! bfd_set_section_alignment (abfd, rtproc_sec, 4)) 4966 return false; 4967 } 4968 4969 if (! mips_elf_create_procedure_table (mdebug_handle, abfd, 4970 info, rtproc_sec, &debug)) 4971 return false; 4972 } 4973 4974 /* Build the external symbol information. */ 4975 einfo.abfd = abfd; 4976 einfo.info = info; 4977 einfo.debug = &debug; 4978 einfo.swap = swap; 4979 einfo.failed = false; 4980 mips_elf_link_hash_traverse (mips_elf_hash_table (info), 4981 mips_elf_output_extsym, 4982 (PTR) &einfo); 4983 if (einfo.failed) 4984 return false; 4985 4986 /* Set the size of the .mdebug section. */ 4987 o->_raw_size = bfd_ecoff_debug_size (abfd, &debug, swap); 4988 4989 /* Skip this section later on (I don't think this currently 4990 matters, but someday it might). */ 4991 o->link_order_head = (struct bfd_link_order *) NULL; 4992 4993 mdebug_sec = o; 4994 } 4995 4996 if (strncmp (o->name, ".gptab.", sizeof ".gptab." - 1) == 0) 4997 { 4998 const char *subname; 4999 unsigned int c; 5000 Elf32_gptab *tab; 5001 Elf32_External_gptab *ext_tab; 5002 unsigned int i; 5003 5004 /* The .gptab.sdata and .gptab.sbss sections hold 5005 information describing how the small data area would 5006 change depending upon the -G switch. These sections 5007 not used in executables files. */ 5008 if (! info->relocateable) 5009 { 5010 asection **secpp; 5011 5012 for (p = o->link_order_head; 5013 p != (struct bfd_link_order *) NULL; 5014 p = p->next) 5015 { 5016 asection *input_section; 5017 5018 if (p->type != bfd_indirect_link_order) 5019 { 5020 if (p->type == bfd_fill_link_order) 5021 continue; 5022 abort (); 5023 } 5024 5025 input_section = p->u.indirect.section; 5026 5027 /* Hack: reset the SEC_HAS_CONTENTS flag so that 5028 elf_link_input_bfd ignores this section. */ 5029 input_section->flags &= ~SEC_HAS_CONTENTS; 5030 } 5031 5032 /* Skip this section later on (I don't think this 5033 currently matters, but someday it might). */ 5034 o->link_order_head = (struct bfd_link_order *) NULL; 5035 5036 /* Really remove the section. */ 5037 for (secpp = &abfd->sections; 5038 *secpp != o; 5039 secpp = &(*secpp)->next) 5040 ; 5041 *secpp = (*secpp)->next; 5042 --abfd->section_count; 5043 5044 continue; 5045 } 5046 5047 /* There is one gptab for initialized data, and one for 5048 uninitialized data. */ 5049 if (strcmp (o->name, ".gptab.sdata") == 0) 5050 gptab_data_sec = o; 5051 else if (strcmp (o->name, ".gptab.sbss") == 0) 5052 gptab_bss_sec = o; 5053 else 5054 { 5055 (*_bfd_error_handler) 5056 (_("%s: illegal section name `%s'"), 5057 bfd_get_filename (abfd), o->name); 5058 bfd_set_error (bfd_error_nonrepresentable_section); 5059 return false; 5060 } 5061 5062 /* The linker script always combines .gptab.data and 5063 .gptab.sdata into .gptab.sdata, and likewise for 5064 .gptab.bss and .gptab.sbss. It is possible that there is 5065 no .sdata or .sbss section in the output file, in which 5066 case we must change the name of the output section. */ 5067 subname = o->name + sizeof ".gptab" - 1; 5068 if (bfd_get_section_by_name (abfd, subname) == NULL) 5069 { 5070 if (o == gptab_data_sec) 5071 o->name = ".gptab.data"; 5072 else 5073 o->name = ".gptab.bss"; 5074 subname = o->name + sizeof ".gptab" - 1; 5075 BFD_ASSERT (bfd_get_section_by_name (abfd, subname) != NULL); 5076 } 5077 5078 /* Set up the first entry. */ 5079 c = 1; 5080 tab = (Elf32_gptab *) bfd_malloc (c * sizeof (Elf32_gptab)); 5081 if (tab == NULL) 5082 return false; 5083 tab[0].gt_header.gt_current_g_value = elf_gp_size (abfd); 5084 tab[0].gt_header.gt_unused = 0; 5085 5086 /* Combine the input sections. */ 5087 for (p = o->link_order_head; 5088 p != (struct bfd_link_order *) NULL; 5089 p = p->next) 5090 { 5091 asection *input_section; 5092 bfd *input_bfd; 5093 bfd_size_type size; 5094 unsigned long last; 5095 bfd_size_type gpentry; 5096 5097 if (p->type != bfd_indirect_link_order) 5098 { 5099 if (p->type == bfd_fill_link_order) 5100 continue; 5101 abort (); 5102 } 5103 5104 input_section = p->u.indirect.section; 5105 input_bfd = input_section->owner; 5106 5107 /* Combine the gptab entries for this input section one 5108 by one. We know that the input gptab entries are 5109 sorted by ascending -G value. */ 5110 size = bfd_section_size (input_bfd, input_section); 5111 last = 0; 5112 for (gpentry = sizeof (Elf32_External_gptab); 5113 gpentry < size; 5114 gpentry += sizeof (Elf32_External_gptab)) 5115 { 5116 Elf32_External_gptab ext_gptab; 5117 Elf32_gptab int_gptab; 5118 unsigned long val; 5119 unsigned long add; 5120 boolean exact; 5121 unsigned int look; 5122 5123 if (! (bfd_get_section_contents 5124 (input_bfd, input_section, (PTR) &ext_gptab, 5125 gpentry, sizeof (Elf32_External_gptab)))) 5126 { 5127 free (tab); 5128 return false; 5129 } 5130 5131 bfd_mips_elf32_swap_gptab_in (input_bfd, &ext_gptab, 5132 &int_gptab); 5133 val = int_gptab.gt_entry.gt_g_value; 5134 add = int_gptab.gt_entry.gt_bytes - last; 5135 5136 exact = false; 5137 for (look = 1; look < c; look++) 5138 { 5139 if (tab[look].gt_entry.gt_g_value >= val) 5140 tab[look].gt_entry.gt_bytes += add; 5141 5142 if (tab[look].gt_entry.gt_g_value == val) 5143 exact = true; 5144 } 5145 5146 if (! exact) 5147 { 5148 Elf32_gptab *new_tab; 5149 unsigned int max; 5150 5151 /* We need a new table entry. */ 5152 new_tab = ((Elf32_gptab *) 5153 bfd_realloc ((PTR) tab, 5154 (c + 1) * sizeof (Elf32_gptab))); 5155 if (new_tab == NULL) 5156 { 5157 free (tab); 5158 return false; 5159 } 5160 tab = new_tab; 5161 tab[c].gt_entry.gt_g_value = val; 5162 tab[c].gt_entry.gt_bytes = add; 5163 5164 /* Merge in the size for the next smallest -G 5165 value, since that will be implied by this new 5166 value. */ 5167 max = 0; 5168 for (look = 1; look < c; look++) 5169 { 5170 if (tab[look].gt_entry.gt_g_value < val 5171 && (max == 0 5172 || (tab[look].gt_entry.gt_g_value 5173 > tab[max].gt_entry.gt_g_value))) 5174 max = look; 5175 } 5176 if (max != 0) 5177 tab[c].gt_entry.gt_bytes += 5178 tab[max].gt_entry.gt_bytes; 5179 5180 ++c; 5181 } 5182 5183 last = int_gptab.gt_entry.gt_bytes; 5184 } 5185 5186 /* Hack: reset the SEC_HAS_CONTENTS flag so that 5187 elf_link_input_bfd ignores this section. */ 5188 input_section->flags &= ~SEC_HAS_CONTENTS; 5189 } 5190 5191 /* The table must be sorted by -G value. */ 5192 if (c > 2) 5193 qsort (tab + 1, c - 1, sizeof (tab[0]), gptab_compare); 5194 5195 /* Swap out the table. */ 5196 ext_tab = ((Elf32_External_gptab *) 5197 bfd_alloc (abfd, c * sizeof (Elf32_External_gptab))); 5198 if (ext_tab == NULL) 5199 { 5200 free (tab); 5201 return false; 5202 } 5203 5204 for (i = 0; i < c; i++) 5205 bfd_mips_elf32_swap_gptab_out (abfd, tab + i, ext_tab + i); 5206 free (tab); 5207 5208 o->_raw_size = c * sizeof (Elf32_External_gptab); 5209 o->contents = (bfd_byte *) ext_tab; 5210 5211 /* Skip this section later on (I don't think this currently 5212 matters, but someday it might). */ 5213 o->link_order_head = (struct bfd_link_order *) NULL; 5214 } 5215 } 5216 5217 /* Invoke the regular ELF backend linker to do all the work. */ 5218 if (ABI_64_P (abfd)) 5219 { 5220 #ifdef BFD64 5221 if (!bfd_elf64_bfd_final_link (abfd, info)) 5222 return false; 5223 #else 5224 abort (); 5225 return false; 5226 #endif /* BFD64 */ 5227 } 5228 else if (!bfd_elf32_bfd_final_link (abfd, info)) 5229 return false; 5230 5231 /* Now write out the computed sections. */ 5232 5233 if (reginfo_sec != (asection *) NULL) 5234 { 5235 Elf32_External_RegInfo ext; 5236 5237 bfd_mips_elf32_swap_reginfo_out (abfd, ®info, &ext); 5238 if (! bfd_set_section_contents (abfd, reginfo_sec, (PTR) &ext, 5239 (file_ptr) 0, sizeof ext)) 5240 return false; 5241 } 5242 5243 if (mdebug_sec != (asection *) NULL) 5244 { 5245 BFD_ASSERT (abfd->output_has_begun); 5246 if (! bfd_ecoff_write_accumulated_debug (mdebug_handle, abfd, &debug, 5247 swap, info, 5248 mdebug_sec->filepos)) 5249 return false; 5250 5251 bfd_ecoff_debug_free (mdebug_handle, abfd, &debug, swap, info); 5252 } 5253 5254 if (gptab_data_sec != (asection *) NULL) 5255 { 5256 if (! bfd_set_section_contents (abfd, gptab_data_sec, 5257 gptab_data_sec->contents, 5258 (file_ptr) 0, 5259 gptab_data_sec->_raw_size)) 5260 return false; 5261 } 5262 5263 if (gptab_bss_sec != (asection *) NULL) 5264 { 5265 if (! bfd_set_section_contents (abfd, gptab_bss_sec, 5266 gptab_bss_sec->contents, 5267 (file_ptr) 0, 5268 gptab_bss_sec->_raw_size)) 5269 return false; 5270 } 5271 5272 if (SGI_COMPAT (abfd)) 5273 { 5274 rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc"); 5275 if (rtproc_sec != NULL) 5276 { 5277 if (! bfd_set_section_contents (abfd, rtproc_sec, 5278 rtproc_sec->contents, 5279 (file_ptr) 0, 5280 rtproc_sec->_raw_size)) 5281 return false; 5282 } 5283 } 5284 5285 return true; 5286 } 5287 5288 /* This function is called via qsort() to sort the dynamic relocation 5289 entries by increasing r_symndx value. */ 5290 5291 static int 5292 sort_dynamic_relocs (arg1, arg2) 5293 const PTR arg1; 5294 const PTR arg2; 5295 { 5296 const Elf32_External_Rel *ext_reloc1 = (const Elf32_External_Rel *) arg1; 5297 const Elf32_External_Rel *ext_reloc2 = (const Elf32_External_Rel *) arg2; 5298 5299 Elf_Internal_Rel int_reloc1; 5300 Elf_Internal_Rel int_reloc2; 5301 5302 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, ext_reloc1, &int_reloc1); 5303 bfd_elf32_swap_reloc_in (reldyn_sorting_bfd, ext_reloc2, &int_reloc2); 5304 5305 return (ELF32_R_SYM (int_reloc1.r_info) - ELF32_R_SYM (int_reloc2.r_info)); 5306 } 5307 5308 /* Returns the GOT section for ABFD. */ 5309 5310 static asection * 5311 mips_elf_got_section (abfd) 5312 bfd *abfd; 5313 { 5314 return bfd_get_section_by_name (abfd, ".got"); 5315 } 5316 5317 /* Returns the GOT information associated with the link indicated by 5318 INFO. If SGOTP is non-NULL, it is filled in with the GOT 5319 section. */ 5320 5321 static struct mips_got_info * 5322 mips_elf_got_info (abfd, sgotp) 5323 bfd *abfd; 5324 asection **sgotp; 5325 { 5326 asection *sgot; 5327 struct mips_got_info *g; 5328 5329 sgot = mips_elf_got_section (abfd); 5330 BFD_ASSERT (sgot != NULL); 5331 BFD_ASSERT (elf_section_data (sgot) != NULL); 5332 g = (struct mips_got_info *) elf_section_data (sgot)->tdata; 5333 BFD_ASSERT (g != NULL); 5334 5335 if (sgotp) 5336 *sgotp = sgot; 5337 return g; 5338 } 5339 5340 /* Return whether a relocation is against a local symbol. */ 5341 5342 static boolean 5343 mips_elf_local_relocation_p (input_bfd, relocation, local_sections, 5344 check_forced) 5345 bfd *input_bfd; 5346 const Elf_Internal_Rela *relocation; 5347 asection **local_sections; 5348 boolean check_forced; 5349 { 5350 unsigned long r_symndx; 5351 Elf_Internal_Shdr *symtab_hdr; 5352 struct mips_elf_link_hash_entry *h; 5353 size_t extsymoff; 5354 5355 r_symndx = ELF32_R_SYM (relocation->r_info); 5356 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 5357 extsymoff = (elf_bad_symtab (input_bfd)) ? 0 : symtab_hdr->sh_info; 5358 5359 if (r_symndx < extsymoff) 5360 return true; 5361 if (elf_bad_symtab (input_bfd) && local_sections[r_symndx] != NULL) 5362 return true; 5363 5364 if (check_forced) 5365 { 5366 /* Look up the hash table to check whether the symbol 5367 was forced local. */ 5368 h = (struct mips_elf_link_hash_entry *) 5369 elf_sym_hashes (input_bfd) [r_symndx - extsymoff]; 5370 /* Find the real hash-table entry for this symbol. */ 5371 while (h->root.root.type == bfd_link_hash_indirect 5372 || h->root.root.type == bfd_link_hash_warning) 5373 h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link; 5374 if ((h->root.elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0) 5375 return true; 5376 } 5377 5378 return false; 5379 } 5380 5381 /* Sign-extend VALUE, which has the indicated number of BITS. */ 5382 5383 static bfd_vma 5384 mips_elf_sign_extend (value, bits) 5385 bfd_vma value; 5386 int bits; 5387 { 5388 if (value & ((bfd_vma) 1 << (bits - 1))) 5389 /* VALUE is negative. */ 5390 value |= ((bfd_vma) - 1) << bits; 5391 5392 return value; 5393 } 5394 5395 /* Return non-zero if the indicated VALUE has overflowed the maximum 5396 range expressable by a signed number with the indicated number of 5397 BITS. */ 5398 5399 static boolean 5400 mips_elf_overflow_p (value, bits) 5401 bfd_vma value; 5402 int bits; 5403 { 5404 bfd_signed_vma svalue = (bfd_signed_vma) value; 5405 5406 if (svalue > (1 << (bits - 1)) - 1) 5407 /* The value is too big. */ 5408 return true; 5409 else if (svalue < -(1 << (bits - 1))) 5410 /* The value is too small. */ 5411 return true; 5412 5413 /* All is well. */ 5414 return false; 5415 } 5416 5417 /* Calculate the %high function. */ 5418 5419 static bfd_vma 5420 mips_elf_high (value) 5421 bfd_vma value; 5422 { 5423 return ((value + (bfd_vma) 0x8000) >> 16) & 0xffff; 5424 } 5425 5426 /* Calculate the %higher function. */ 5427 5428 static bfd_vma 5429 mips_elf_higher (value) 5430 bfd_vma value ATTRIBUTE_UNUSED; 5431 { 5432 #ifdef BFD64 5433 return ((value + (bfd_vma) 0x80008000) >> 32) & 0xffff; 5434 #else 5435 abort (); 5436 return (bfd_vma) -1; 5437 #endif 5438 } 5439 5440 /* Calculate the %highest function. */ 5441 5442 static bfd_vma 5443 mips_elf_highest (value) 5444 bfd_vma value ATTRIBUTE_UNUSED; 5445 { 5446 #ifdef BFD64 5447 return ((value + (bfd_vma) 0x800080008000) >> 48) & 0xffff; 5448 #else 5449 abort (); 5450 return (bfd_vma) -1; 5451 #endif 5452 } 5453 5454 /* Returns the GOT index for the global symbol indicated by H. */ 5455 5456 static bfd_vma 5457 mips_elf_global_got_index (abfd, h) 5458 bfd *abfd; 5459 struct elf_link_hash_entry *h; 5460 { 5461 bfd_vma index; 5462 asection *sgot; 5463 struct mips_got_info *g; 5464 5465 g = mips_elf_got_info (abfd, &sgot); 5466 5467 /* Once we determine the global GOT entry with the lowest dynamic 5468 symbol table index, we must put all dynamic symbols with greater 5469 indices into the GOT. That makes it easy to calculate the GOT 5470 offset. */ 5471 BFD_ASSERT (h->dynindx >= g->global_gotsym->dynindx); 5472 index = ((h->dynindx - g->global_gotsym->dynindx + g->local_gotno) 5473 * MIPS_ELF_GOT_SIZE (abfd)); 5474 BFD_ASSERT (index < sgot->_raw_size); 5475 5476 return index; 5477 } 5478 5479 /* Returns the offset for the entry at the INDEXth position 5480 in the GOT. */ 5481 5482 static bfd_vma 5483 mips_elf_got_offset_from_index (dynobj, output_bfd, index) 5484 bfd *dynobj; 5485 bfd *output_bfd; 5486 bfd_vma index; 5487 { 5488 asection *sgot; 5489 bfd_vma gp; 5490 5491 sgot = mips_elf_got_section (dynobj); 5492 gp = _bfd_get_gp_value (output_bfd); 5493 return (sgot->output_section->vma + sgot->output_offset + index - 5494 gp); 5495 } 5496 5497 /* If H is a symbol that needs a global GOT entry, but has a dynamic 5498 symbol table index lower than any we've seen to date, record it for 5499 posterity. */ 5500 5501 static boolean 5502 mips_elf_record_global_got_symbol (h, info, g) 5503 struct elf_link_hash_entry *h; 5504 struct bfd_link_info *info; 5505 struct mips_got_info *g ATTRIBUTE_UNUSED; 5506 { 5507 /* A global symbol in the GOT must also be in the dynamic symbol 5508 table. */ 5509 if (h->dynindx == -1 5510 && !bfd_elf32_link_record_dynamic_symbol (info, h)) 5511 return false; 5512 5513 /* If we've already marked this entry as need GOT space, we don't 5514 need to do it again. */ 5515 if (h->got.offset != (bfd_vma) - 1) 5516 return true; 5517 5518 /* By setting this to a value other than -1, we are indicating that 5519 there needs to be a GOT entry for H. */ 5520 h->got.offset = 0; 5521 5522 return true; 5523 } 5524 5525 /* This structure is passed to mips_elf_sort_hash_table_f when sorting 5526 the dynamic symbols. */ 5527 5528 struct mips_elf_hash_sort_data 5529 { 5530 /* The symbol in the global GOT with the lowest dynamic symbol table 5531 index. */ 5532 struct elf_link_hash_entry *low; 5533 /* The least dynamic symbol table index corresponding to a symbol 5534 with a GOT entry. */ 5535 long min_got_dynindx; 5536 /* The greatest dynamic symbol table index not corresponding to a 5537 symbol without a GOT entry. */ 5538 long max_non_got_dynindx; 5539 }; 5540 5541 /* If H needs a GOT entry, assign it the highest available dynamic 5542 index. Otherwise, assign it the lowest available dynamic 5543 index. */ 5544 5545 static boolean 5546 mips_elf_sort_hash_table_f (h, data) 5547 struct mips_elf_link_hash_entry *h; 5548 PTR data; 5549 { 5550 struct mips_elf_hash_sort_data *hsd 5551 = (struct mips_elf_hash_sort_data *) data; 5552 5553 /* Symbols without dynamic symbol table entries aren't interesting 5554 at all. */ 5555 if (h->root.dynindx == -1) 5556 return true; 5557 5558 if (h->root.got.offset != 0) 5559 h->root.dynindx = hsd->max_non_got_dynindx++; 5560 else 5561 { 5562 h->root.dynindx = --hsd->min_got_dynindx; 5563 hsd->low = (struct elf_link_hash_entry *) h; 5564 } 5565 5566 return true; 5567 } 5568 5569 /* Sort the dynamic symbol table so that symbols that need GOT entries 5570 appear towards the end. This reduces the amount of GOT space 5571 required. MAX_LOCAL is used to set the number of local symbols 5572 known to be in the dynamic symbol table. During 5573 mips_elf_size_dynamic_sections, this value is 1. Afterward, the 5574 section symbols are added and the count is higher. */ 5575 5576 static boolean 5577 mips_elf_sort_hash_table (info, max_local) 5578 struct bfd_link_info *info; 5579 unsigned long max_local; 5580 { 5581 struct mips_elf_hash_sort_data hsd; 5582 struct mips_got_info *g; 5583 bfd *dynobj; 5584 5585 dynobj = elf_hash_table (info)->dynobj; 5586 5587 hsd.low = NULL; 5588 hsd.min_got_dynindx = elf_hash_table (info)->dynsymcount; 5589 hsd.max_non_got_dynindx = max_local; 5590 mips_elf_link_hash_traverse (((struct mips_elf_link_hash_table *) 5591 elf_hash_table (info)), 5592 mips_elf_sort_hash_table_f, 5593 &hsd); 5594 5595 /* There shoud have been enough room in the symbol table to 5596 accomodate both the GOT and non-GOT symbols. */ 5597 BFD_ASSERT (hsd.max_non_got_dynindx <= hsd.min_got_dynindx); 5598 5599 /* Now we know which dynamic symbol has the lowest dynamic symbol 5600 table index in the GOT. */ 5601 g = mips_elf_got_info (dynobj, NULL); 5602 g->global_gotsym = hsd.low; 5603 5604 return true; 5605 } 5606 5607 /* Create a local GOT entry for VALUE. Return the index of the entry, 5608 or -1 if it could not be created. */ 5609 5610 static bfd_vma 5611 mips_elf_create_local_got_entry (abfd, g, sgot, value) 5612 bfd *abfd; 5613 struct mips_got_info *g; 5614 asection *sgot; 5615 bfd_vma value; 5616 { 5617 if (g->assigned_gotno >= g->local_gotno) 5618 { 5619 /* We didn't allocate enough space in the GOT. */ 5620 (*_bfd_error_handler) 5621 (_("not enough GOT space for local GOT entries")); 5622 bfd_set_error (bfd_error_bad_value); 5623 return (bfd_vma) -1; 5624 } 5625 5626 MIPS_ELF_PUT_WORD (abfd, value, 5627 (sgot->contents 5628 + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno)); 5629 return MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno++; 5630 } 5631 5632 /* Returns the GOT offset at which the indicated address can be found. 5633 If there is not yet a GOT entry for this value, create one. Returns 5634 -1 if no satisfactory GOT offset can be found. */ 5635 5636 static bfd_vma 5637 mips_elf_local_got_index (abfd, info, value) 5638 bfd *abfd; 5639 struct bfd_link_info *info; 5640 bfd_vma value; 5641 { 5642 asection *sgot; 5643 struct mips_got_info *g; 5644 bfd_byte *entry; 5645 5646 g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot); 5647 5648 /* Look to see if we already have an appropriate entry. */ 5649 for (entry = (sgot->contents 5650 + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO); 5651 entry != sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno; 5652 entry += MIPS_ELF_GOT_SIZE (abfd)) 5653 { 5654 bfd_vma address = MIPS_ELF_GET_WORD (abfd, entry); 5655 if (address == value) 5656 return entry - sgot->contents; 5657 } 5658 5659 return mips_elf_create_local_got_entry (abfd, g, sgot, value); 5660 } 5661 5662 /* Find a GOT entry that is within 32KB of the VALUE. These entries 5663 are supposed to be placed at small offsets in the GOT, i.e., 5664 within 32KB of GP. Return the index into the GOT for this page, 5665 and store the offset from this entry to the desired address in 5666 OFFSETP, if it is non-NULL. */ 5667 5668 static bfd_vma 5669 mips_elf_got_page (abfd, info, value, offsetp) 5670 bfd *abfd; 5671 struct bfd_link_info *info; 5672 bfd_vma value; 5673 bfd_vma *offsetp; 5674 { 5675 asection *sgot; 5676 struct mips_got_info *g; 5677 bfd_byte *entry; 5678 bfd_byte *last_entry; 5679 bfd_vma index = 0; 5680 bfd_vma address; 5681 5682 g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot); 5683 5684 /* Look to see if we aleady have an appropriate entry. */ 5685 last_entry = sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno; 5686 for (entry = (sgot->contents 5687 + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO); 5688 entry != last_entry; 5689 entry += MIPS_ELF_GOT_SIZE (abfd)) 5690 { 5691 address = MIPS_ELF_GET_WORD (abfd, entry); 5692 5693 if (!mips_elf_overflow_p (value - address, 16)) 5694 { 5695 /* This entry will serve as the page pointer. We can add a 5696 16-bit number to it to get the actual address. */ 5697 index = entry - sgot->contents; 5698 break; 5699 } 5700 } 5701 5702 /* If we didn't have an appropriate entry, we create one now. */ 5703 if (entry == last_entry) 5704 index = mips_elf_create_local_got_entry (abfd, g, sgot, value); 5705 5706 if (offsetp) 5707 { 5708 address = MIPS_ELF_GET_WORD (abfd, entry); 5709 *offsetp = value - address; 5710 } 5711 5712 return index; 5713 } 5714 5715 /* Find a GOT entry whose higher-order 16 bits are the same as those 5716 for value. Return the index into the GOT for this entry. */ 5717 5718 static bfd_vma 5719 mips_elf_got16_entry (abfd, info, value, external) 5720 bfd *abfd; 5721 struct bfd_link_info *info; 5722 bfd_vma value; 5723 boolean external; 5724 { 5725 asection *sgot; 5726 struct mips_got_info *g; 5727 bfd_byte *entry; 5728 bfd_byte *last_entry; 5729 bfd_vma index = 0; 5730 bfd_vma address; 5731 5732 if (! external) 5733 { 5734 /* Although the ABI says that it is "the high-order 16 bits" that we 5735 want, it is really the %high value. The complete value is 5736 calculated with a `addiu' of a LO16 relocation, just as with a 5737 HI16/LO16 pair. */ 5738 value = mips_elf_high (value) << 16; 5739 } 5740 5741 g = mips_elf_got_info (elf_hash_table (info)->dynobj, &sgot); 5742 5743 /* Look to see if we already have an appropriate entry. */ 5744 last_entry = sgot->contents + MIPS_ELF_GOT_SIZE (abfd) * g->assigned_gotno; 5745 for (entry = (sgot->contents 5746 + MIPS_ELF_GOT_SIZE (abfd) * MIPS_RESERVED_GOTNO); 5747 entry != last_entry; 5748 entry += MIPS_ELF_GOT_SIZE (abfd)) 5749 { 5750 address = MIPS_ELF_GET_WORD (abfd, entry); 5751 if (address == value) 5752 { 5753 /* This entry has the right high-order 16 bits, and the low-order 5754 16 bits are set to zero. */ 5755 index = entry - sgot->contents; 5756 break; 5757 } 5758 } 5759 5760 /* If we didn't have an appropriate entry, we create one now. */ 5761 if (entry == last_entry) 5762 index = mips_elf_create_local_got_entry (abfd, g, sgot, value); 5763 5764 return index; 5765 } 5766 5767 /* Returns the first relocation of type r_type found, beginning with 5768 RELOCATION. RELEND is one-past-the-end of the relocation table. */ 5769 5770 static const Elf_Internal_Rela * 5771 mips_elf_next_relocation (r_type, relocation, relend) 5772 unsigned int r_type; 5773 const Elf_Internal_Rela *relocation; 5774 const Elf_Internal_Rela *relend; 5775 { 5776 /* According to the MIPS ELF ABI, the R_MIPS_LO16 relocation must be 5777 immediately following. However, for the IRIX6 ABI, the next 5778 relocation may be a composed relocation consisting of several 5779 relocations for the same address. In that case, the R_MIPS_LO16 5780 relocation may occur as one of these. We permit a similar 5781 extension in general, as that is useful for GCC. */ 5782 while (relocation < relend) 5783 { 5784 if (ELF32_R_TYPE (relocation->r_info) == r_type) 5785 return relocation; 5786 5787 ++relocation; 5788 } 5789 5790 /* We didn't find it. */ 5791 bfd_set_error (bfd_error_bad_value); 5792 return NULL; 5793 } 5794 5795 /* Create a rel.dyn relocation for the dynamic linker to resolve. REL 5796 is the original relocation, which is now being transformed into a 5797 dynamic relocation. The ADDENDP is adjusted if necessary; the 5798 caller should store the result in place of the original addend. */ 5799 5800 static boolean 5801 mips_elf_create_dynamic_relocation (output_bfd, info, rel, h, sec, 5802 symbol, addendp, input_section) 5803 bfd *output_bfd; 5804 struct bfd_link_info *info; 5805 const Elf_Internal_Rela *rel; 5806 struct mips_elf_link_hash_entry *h; 5807 asection *sec; 5808 bfd_vma symbol; 5809 bfd_vma *addendp; 5810 asection *input_section; 5811 { 5812 Elf_Internal_Rel outrel; 5813 boolean skip; 5814 asection *sreloc; 5815 bfd *dynobj; 5816 int r_type; 5817 5818 r_type = ELF32_R_TYPE (rel->r_info); 5819 dynobj = elf_hash_table (info)->dynobj; 5820 sreloc 5821 = bfd_get_section_by_name (dynobj, 5822 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd)); 5823 BFD_ASSERT (sreloc != NULL); 5824 BFD_ASSERT (sreloc->contents != NULL); 5825 5826 skip = false; 5827 5828 /* We begin by assuming that the offset for the dynamic relocation 5829 is the same as for the original relocation. We'll adjust this 5830 later to reflect the correct output offsets. */ 5831 if (elf_section_data (input_section)->stab_info == NULL) 5832 outrel.r_offset = rel->r_offset; 5833 else 5834 { 5835 /* Except that in a stab section things are more complex. 5836 Because we compress stab information, the offset given in the 5837 relocation may not be the one we want; we must let the stabs 5838 machinery tell us the offset. */ 5839 outrel.r_offset 5840 = (_bfd_stab_section_offset 5841 (output_bfd, &elf_hash_table (info)->stab_info, 5842 input_section, 5843 &elf_section_data (input_section)->stab_info, 5844 rel->r_offset)); 5845 /* If we didn't need the relocation at all, this value will be 5846 -1. */ 5847 if (outrel.r_offset == (bfd_vma) -1) 5848 skip = true; 5849 } 5850 5851 /* If we've decided to skip this relocation, just output an empty 5852 record. Note that R_MIPS_NONE == 0, so that this call to memset 5853 is a way of setting R_TYPE to R_MIPS_NONE. */ 5854 if (skip) 5855 memset (&outrel, 0, sizeof (outrel)); 5856 else 5857 { 5858 long indx; 5859 bfd_vma section_offset; 5860 5861 /* We must now calculate the dynamic symbol table index to use 5862 in the relocation. */ 5863 if (h != NULL 5864 && (! info->symbolic || (h->root.elf_link_hash_flags 5865 & ELF_LINK_HASH_DEF_REGULAR) == 0)) 5866 { 5867 indx = h->root.dynindx; 5868 /* h->root.dynindx may be -1 if this symbol was marked to 5869 become local. */ 5870 if (indx == -1) 5871 indx = 0; 5872 } 5873 else 5874 { 5875 if (sec != NULL && bfd_is_abs_section (sec)) 5876 indx = 0; 5877 else if (sec == NULL || sec->owner == NULL) 5878 { 5879 bfd_set_error (bfd_error_bad_value); 5880 return false; 5881 } 5882 else 5883 { 5884 indx = elf_section_data (sec->output_section)->dynindx; 5885 if (indx == 0) 5886 abort (); 5887 } 5888 5889 /* Figure out how far the target of the relocation is from 5890 the beginning of its section. */ 5891 section_offset = symbol - sec->output_section->vma; 5892 /* The relocation we're building is section-relative. 5893 Therefore, the original addend must be adjusted by the 5894 section offset. */ 5895 *addendp += section_offset; 5896 /* Now, the relocation is just against the section. */ 5897 symbol = sec->output_section->vma; 5898 } 5899 5900 /* If the relocation was previously an absolute relocation and 5901 this symbol will not be referred to by the relocation, we must 5902 adjust it by the value we give it in the dynamic symbol table. 5903 Otherwise leave the job up to the dynamic linker. */ 5904 if (!indx && r_type != R_MIPS_REL32) 5905 *addendp += symbol; 5906 5907 /* The relocation is always an REL32 relocation because we don't 5908 know where the shared library will wind up at load-time. */ 5909 outrel.r_info = ELF32_R_INFO (indx, R_MIPS_REL32); 5910 5911 /* Adjust the output offset of the relocation to reference the 5912 correct location in the output file. */ 5913 outrel.r_offset += (input_section->output_section->vma 5914 + input_section->output_offset); 5915 } 5916 5917 /* Put the relocation back out. We have to use the special 5918 relocation outputter in the 64-bit case since the 64-bit 5919 relocation format is non-standard. */ 5920 if (ABI_64_P (output_bfd)) 5921 { 5922 (*get_elf_backend_data (output_bfd)->s->swap_reloc_out) 5923 (output_bfd, &outrel, 5924 (sreloc->contents 5925 + sreloc->reloc_count * sizeof (Elf64_Mips_External_Rel))); 5926 } 5927 else 5928 bfd_elf32_swap_reloc_out (output_bfd, &outrel, 5929 (((Elf32_External_Rel *) 5930 sreloc->contents) 5931 + sreloc->reloc_count)); 5932 5933 /* Record the index of the first relocation referencing H. This 5934 information is later emitted in the .msym section. */ 5935 if (h != NULL 5936 && (h->min_dyn_reloc_index == 0 5937 || sreloc->reloc_count < h->min_dyn_reloc_index)) 5938 h->min_dyn_reloc_index = sreloc->reloc_count; 5939 5940 /* We've now added another relocation. */ 5941 ++sreloc->reloc_count; 5942 5943 /* Make sure the output section is writable. The dynamic linker 5944 will be writing to it. */ 5945 elf_section_data (input_section->output_section)->this_hdr.sh_flags 5946 |= SHF_WRITE; 5947 5948 /* On IRIX5, make an entry of compact relocation info. */ 5949 if (! skip && IRIX_COMPAT (output_bfd) == ict_irix5) 5950 { 5951 asection *scpt = bfd_get_section_by_name (dynobj, ".compact_rel"); 5952 bfd_byte *cr; 5953 5954 if (scpt) 5955 { 5956 Elf32_crinfo cptrel; 5957 5958 mips_elf_set_cr_format (cptrel, CRF_MIPS_LONG); 5959 cptrel.vaddr = (rel->r_offset 5960 + input_section->output_section->vma 5961 + input_section->output_offset); 5962 if (r_type == R_MIPS_REL32) 5963 mips_elf_set_cr_type (cptrel, CRT_MIPS_REL32); 5964 else 5965 mips_elf_set_cr_type (cptrel, CRT_MIPS_WORD); 5966 mips_elf_set_cr_dist2to (cptrel, 0); 5967 cptrel.konst = *addendp; 5968 5969 cr = (scpt->contents 5970 + sizeof (Elf32_External_compact_rel)); 5971 bfd_elf32_swap_crinfo_out (output_bfd, &cptrel, 5972 ((Elf32_External_crinfo *) cr 5973 + scpt->reloc_count)); 5974 ++scpt->reloc_count; 5975 } 5976 } 5977 5978 return true; 5979 } 5980 5981 /* Calculate the value produced by the RELOCATION (which comes from 5982 the INPUT_BFD). The ADDEND is the addend to use for this 5983 RELOCATION; RELOCATION->R_ADDEND is ignored. 5984 5985 The result of the relocation calculation is stored in VALUEP. 5986 REQUIRE_JALXP indicates whether or not the opcode used with this 5987 relocation must be JALX. 5988 5989 This function returns bfd_reloc_continue if the caller need take no 5990 further action regarding this relocation, bfd_reloc_notsupported if 5991 something goes dramatically wrong, bfd_reloc_overflow if an 5992 overflow occurs, and bfd_reloc_ok to indicate success. */ 5993 5994 static bfd_reloc_status_type 5995 mips_elf_calculate_relocation (abfd, 5996 input_bfd, 5997 input_section, 5998 info, 5999 relocation, 6000 addend, 6001 howto, 6002 local_syms, 6003 local_sections, 6004 valuep, 6005 namep, 6006 require_jalxp) 6007 bfd *abfd; 6008 bfd *input_bfd; 6009 asection *input_section; 6010 struct bfd_link_info *info; 6011 const Elf_Internal_Rela *relocation; 6012 bfd_vma addend; 6013 reloc_howto_type *howto; 6014 Elf_Internal_Sym *local_syms; 6015 asection **local_sections; 6016 bfd_vma *valuep; 6017 const char **namep; 6018 boolean *require_jalxp; 6019 { 6020 /* The eventual value we will return. */ 6021 bfd_vma value; 6022 /* The address of the symbol against which the relocation is 6023 occurring. */ 6024 bfd_vma symbol = 0; 6025 /* The final GP value to be used for the relocatable, executable, or 6026 shared object file being produced. */ 6027 bfd_vma gp = (bfd_vma) - 1; 6028 /* The place (section offset or address) of the storage unit being 6029 relocated. */ 6030 bfd_vma p; 6031 /* The value of GP used to create the relocatable object. */ 6032 bfd_vma gp0 = (bfd_vma) - 1; 6033 /* The offset into the global offset table at which the address of 6034 the relocation entry symbol, adjusted by the addend, resides 6035 during execution. */ 6036 bfd_vma g = (bfd_vma) - 1; 6037 /* The section in which the symbol referenced by the relocation is 6038 located. */ 6039 asection *sec = NULL; 6040 struct mips_elf_link_hash_entry *h = NULL; 6041 /* True if the symbol referred to by this relocation is a local 6042 symbol. */ 6043 boolean local_p; 6044 /* True if the symbol referred to by this relocation is "_gp_disp". */ 6045 boolean gp_disp_p = false; 6046 Elf_Internal_Shdr *symtab_hdr; 6047 size_t extsymoff; 6048 unsigned long r_symndx; 6049 int r_type; 6050 /* True if overflow occurred during the calculation of the 6051 relocation value. */ 6052 boolean overflowed_p; 6053 /* True if this relocation refers to a MIPS16 function. */ 6054 boolean target_is_16_bit_code_p = false; 6055 6056 /* Parse the relocation. */ 6057 r_symndx = ELF32_R_SYM (relocation->r_info); 6058 r_type = ELF32_R_TYPE (relocation->r_info); 6059 p = (input_section->output_section->vma 6060 + input_section->output_offset 6061 + relocation->r_offset); 6062 6063 /* Assume that there will be no overflow. */ 6064 overflowed_p = false; 6065 6066 /* Figure out whether or not the symbol is local, and get the offset 6067 used in the array of hash table entries. */ 6068 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 6069 local_p = mips_elf_local_relocation_p (input_bfd, relocation, 6070 local_sections, false); 6071 if (! elf_bad_symtab (input_bfd)) 6072 extsymoff = symtab_hdr->sh_info; 6073 else 6074 { 6075 /* The symbol table does not follow the rule that local symbols 6076 must come before globals. */ 6077 extsymoff = 0; 6078 } 6079 6080 /* Figure out the value of the symbol. */ 6081 if (local_p) 6082 { 6083 Elf_Internal_Sym *sym; 6084 6085 sym = local_syms + r_symndx; 6086 sec = local_sections[r_symndx]; 6087 6088 symbol = sec->output_section->vma + sec->output_offset; 6089 if (ELF_ST_TYPE (sym->st_info) != STT_SECTION) 6090 symbol += sym->st_value; 6091 6092 /* MIPS16 text labels should be treated as odd. */ 6093 if (sym->st_other == STO_MIPS16) 6094 ++symbol; 6095 6096 /* Record the name of this symbol, for our caller. */ 6097 *namep = bfd_elf_string_from_elf_section (input_bfd, 6098 symtab_hdr->sh_link, 6099 sym->st_name); 6100 if (*namep == '\0') 6101 *namep = bfd_section_name (input_bfd, sec); 6102 6103 target_is_16_bit_code_p = (sym->st_other == STO_MIPS16); 6104 } 6105 else 6106 { 6107 /* For global symbols we look up the symbol in the hash-table. */ 6108 h = ((struct mips_elf_link_hash_entry *) 6109 elf_sym_hashes (input_bfd) [r_symndx - extsymoff]); 6110 /* Find the real hash-table entry for this symbol. */ 6111 while (h->root.root.type == bfd_link_hash_indirect 6112 || h->root.root.type == bfd_link_hash_warning) 6113 h = (struct mips_elf_link_hash_entry *) h->root.root.u.i.link; 6114 6115 /* Record the name of this symbol, for our caller. */ 6116 *namep = h->root.root.root.string; 6117 6118 /* See if this is the special _gp_disp symbol. Note that such a 6119 symbol must always be a global symbol. */ 6120 if (strcmp (h->root.root.root.string, "_gp_disp") == 0) 6121 { 6122 /* Relocations against _gp_disp are permitted only with 6123 R_MIPS_HI16 and R_MIPS_LO16 relocations. */ 6124 if (r_type != R_MIPS_HI16 && r_type != R_MIPS_LO16) 6125 return bfd_reloc_notsupported; 6126 6127 gp_disp_p = true; 6128 } 6129 /* If this symbol is defined, calculate its address. Note that 6130 _gp_disp is a magic symbol, always implicitly defined by the 6131 linker, so it's inappropriate to check to see whether or not 6132 its defined. */ 6133 else if ((h->root.root.type == bfd_link_hash_defined 6134 || h->root.root.type == bfd_link_hash_defweak) 6135 && h->root.root.u.def.section) 6136 { 6137 sec = h->root.root.u.def.section; 6138 if (sec->output_section) 6139 symbol = (h->root.root.u.def.value 6140 + sec->output_section->vma 6141 + sec->output_offset); 6142 else 6143 symbol = h->root.root.u.def.value; 6144 } 6145 else if (h->root.root.type == bfd_link_hash_undefweak) 6146 /* We allow relocations against undefined weak symbols, giving 6147 it the value zero, so that you can undefined weak functions 6148 and check to see if they exist by looking at their 6149 addresses. */ 6150 symbol = 0; 6151 else if (info->shared && !info->symbolic && !info->no_undefined 6152 && ELF_ST_VISIBILITY (h->root.other) == STV_DEFAULT) 6153 symbol = 0; 6154 else if (strcmp (h->root.root.root.string, "_DYNAMIC_LINK") == 0 || 6155 strcmp (h->root.root.root.string, "_DYNAMIC_LINKING") == 0) 6156 { 6157 /* If this is a dynamic link, we should have created a 6158 _DYNAMIC_LINK symbol or _DYNAMIC_LINKING(for normal mips) symbol 6159 in in mips_elf_create_dynamic_sections. 6160 Otherwise, we should define the symbol with a value of 0. 6161 FIXME: It should probably get into the symbol table 6162 somehow as well. */ 6163 BFD_ASSERT (! info->shared); 6164 BFD_ASSERT (bfd_get_section_by_name (abfd, ".dynamic") == NULL); 6165 symbol = 0; 6166 } 6167 else 6168 { 6169 if (! ((*info->callbacks->undefined_symbol) 6170 (info, h->root.root.root.string, input_bfd, 6171 input_section, relocation->r_offset, 6172 (!info->shared || info->no_undefined 6173 || ELF_ST_VISIBILITY (h->root.other))))) 6174 return bfd_reloc_undefined; 6175 symbol = 0; 6176 } 6177 6178 target_is_16_bit_code_p = (h->root.other == STO_MIPS16); 6179 } 6180 6181 /* If this is a 32-bit call to a 16-bit function with a stub, we 6182 need to redirect the call to the stub, unless we're already *in* 6183 a stub. */ 6184 if (r_type != R_MIPS16_26 && !info->relocateable 6185 && ((h != NULL && h->fn_stub != NULL) 6186 || (local_p && elf_tdata (input_bfd)->local_stubs != NULL 6187 && elf_tdata (input_bfd)->local_stubs[r_symndx] != NULL)) 6188 && !mips_elf_stub_section_p (input_bfd, input_section)) 6189 { 6190 /* This is a 32-bit call to a 16-bit function. We should 6191 have already noticed that we were going to need the 6192 stub. */ 6193 if (local_p) 6194 sec = elf_tdata (input_bfd)->local_stubs[r_symndx]; 6195 else 6196 { 6197 BFD_ASSERT (h->need_fn_stub); 6198 sec = h->fn_stub; 6199 } 6200 6201 symbol = sec->output_section->vma + sec->output_offset; 6202 } 6203 /* If this is a 16-bit call to a 32-bit function with a stub, we 6204 need to redirect the call to the stub. */ 6205 else if (r_type == R_MIPS16_26 && !info->relocateable 6206 && h != NULL 6207 && (h->call_stub != NULL || h->call_fp_stub != NULL) 6208 && !target_is_16_bit_code_p) 6209 { 6210 /* If both call_stub and call_fp_stub are defined, we can figure 6211 out which one to use by seeing which one appears in the input 6212 file. */ 6213 if (h->call_stub != NULL && h->call_fp_stub != NULL) 6214 { 6215 asection *o; 6216 6217 sec = NULL; 6218 for (o = input_bfd->sections; o != NULL; o = o->next) 6219 { 6220 if (strncmp (bfd_get_section_name (input_bfd, o), 6221 CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0) 6222 { 6223 sec = h->call_fp_stub; 6224 break; 6225 } 6226 } 6227 if (sec == NULL) 6228 sec = h->call_stub; 6229 } 6230 else if (h->call_stub != NULL) 6231 sec = h->call_stub; 6232 else 6233 sec = h->call_fp_stub; 6234 6235 BFD_ASSERT (sec->_raw_size > 0); 6236 symbol = sec->output_section->vma + sec->output_offset; 6237 } 6238 6239 /* Calls from 16-bit code to 32-bit code and vice versa require the 6240 special jalx instruction. */ 6241 *require_jalxp = (!info->relocateable 6242 && ((r_type == R_MIPS16_26) != target_is_16_bit_code_p)); 6243 6244 local_p = mips_elf_local_relocation_p (input_bfd, relocation, 6245 local_sections, true); 6246 6247 /* If we haven't already determined the GOT offset, or the GP value, 6248 and we're going to need it, get it now. */ 6249 switch (r_type) 6250 { 6251 case R_MIPS_CALL16: 6252 case R_MIPS_GOT16: 6253 case R_MIPS_GOT_DISP: 6254 case R_MIPS_GOT_HI16: 6255 case R_MIPS_CALL_HI16: 6256 case R_MIPS_GOT_LO16: 6257 case R_MIPS_CALL_LO16: 6258 /* Find the index into the GOT where this value is located. */ 6259 if (!local_p) 6260 { 6261 BFD_ASSERT (addend == 0); 6262 g = mips_elf_global_got_index 6263 (elf_hash_table (info)->dynobj, 6264 (struct elf_link_hash_entry *) h); 6265 if (! elf_hash_table(info)->dynamic_sections_created 6266 || (info->shared 6267 && (info->symbolic || h->root.dynindx == -1) 6268 && (h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))) 6269 { 6270 /* This is a static link or a -Bsymbolic link. The 6271 symbol is defined locally, or was forced to be local. 6272 We must initialize this entry in the GOT. */ 6273 asection *sgot = mips_elf_got_section(elf_hash_table 6274 (info)->dynobj); 6275 MIPS_ELF_PUT_WORD (elf_hash_table (info)->dynobj, 6276 symbol + addend, sgot->contents + g); 6277 } 6278 } 6279 else if (r_type == R_MIPS_GOT16 || r_type == R_MIPS_CALL16) 6280 /* There's no need to create a local GOT entry here; the 6281 calculation for a local GOT16 entry does not involve G. */ 6282 break; 6283 else 6284 { 6285 g = mips_elf_local_got_index (abfd, info, symbol + addend); 6286 if (g == (bfd_vma) -1) 6287 return false; 6288 } 6289 6290 /* Convert GOT indices to actual offsets. */ 6291 g = mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj, 6292 abfd, g); 6293 break; 6294 6295 case R_MIPS_HI16: 6296 case R_MIPS_LO16: 6297 case R_MIPS_GPREL16: 6298 case R_MIPS_GPREL32: 6299 case R_MIPS_LITERAL: 6300 gp0 = _bfd_get_gp_value (input_bfd); 6301 gp = _bfd_get_gp_value (abfd); 6302 break; 6303 6304 default: 6305 break; 6306 } 6307 6308 /* Figure out what kind of relocation is being performed. */ 6309 switch (r_type) 6310 { 6311 case R_MIPS_NONE: 6312 return bfd_reloc_continue; 6313 6314 case R_MIPS_16: 6315 value = symbol + mips_elf_sign_extend (addend, 16); 6316 overflowed_p = mips_elf_overflow_p (value, 16); 6317 break; 6318 6319 case R_MIPS_32: 6320 case R_MIPS_REL32: 6321 case R_MIPS_64: 6322 if ((info->shared 6323 || (elf_hash_table (info)->dynamic_sections_created 6324 && h != NULL 6325 && ((h->root.elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) 6326 != 0))) 6327 && (input_section->flags & SEC_ALLOC) != 0) 6328 { 6329 /* If we're creating a shared library, or this relocation is 6330 against a symbol in a shared library, then we can't know 6331 where the symbol will end up. So, we create a relocation 6332 record in the output, and leave the job up to the dynamic 6333 linker. */ 6334 value = addend; 6335 if (!mips_elf_create_dynamic_relocation (abfd, 6336 info, 6337 relocation, 6338 h, 6339 sec, 6340 symbol, 6341 &value, 6342 input_section)) 6343 return false; 6344 } 6345 else 6346 { 6347 if (r_type != R_MIPS_REL32) 6348 value = symbol + addend; 6349 else 6350 value = addend; 6351 } 6352 value &= howto->dst_mask; 6353 break; 6354 6355 case R_MIPS_PC32: 6356 case R_MIPS_PC64: 6357 case R_MIPS_GNU_REL_LO16: 6358 value = symbol + addend - p; 6359 value &= howto->dst_mask; 6360 break; 6361 6362 case R_MIPS_GNU_REL16_S2: 6363 value = symbol + mips_elf_sign_extend (addend << 2, 18) - p; 6364 overflowed_p = mips_elf_overflow_p (value, 18); 6365 value = (value >> 2) & howto->dst_mask; 6366 break; 6367 6368 case R_MIPS_GNU_REL_HI16: 6369 value = mips_elf_high (addend + symbol - p); 6370 value &= howto->dst_mask; 6371 break; 6372 6373 case R_MIPS16_26: 6374 /* The calculation for R_MIPS16_26 is just the same as for an 6375 R_MIPS_26. It's only the storage of the relocated field into 6376 the output file that's different. That's handled in 6377 mips_elf_perform_relocation. So, we just fall through to the 6378 R_MIPS_26 case here. */ 6379 case R_MIPS_26: 6380 if (local_p) 6381 value = (((addend << 2) | ((p + 4) & 0xf0000000)) + symbol) >> 2; 6382 else 6383 value = (mips_elf_sign_extend (addend << 2, 28) + symbol) >> 2; 6384 value &= howto->dst_mask; 6385 break; 6386 6387 case R_MIPS_HI16: 6388 if (!gp_disp_p) 6389 { 6390 value = mips_elf_high (addend + symbol); 6391 value &= howto->dst_mask; 6392 } 6393 else 6394 { 6395 value = mips_elf_high (addend + gp - p); 6396 overflowed_p = mips_elf_overflow_p (value, 16); 6397 } 6398 break; 6399 6400 case R_MIPS_LO16: 6401 if (!gp_disp_p) 6402 value = (symbol + addend) & howto->dst_mask; 6403 else 6404 { 6405 value = addend + gp - p + 4; 6406 /* The MIPS ABI requires checking the R_MIPS_LO16 relocation 6407 for overflow. But, on, say, Irix 5, relocations against 6408 _gp_disp are normally generated from the .cpload 6409 pseudo-op. It generates code that normally looks like 6410 this: 6411 6412 lui $gp,%hi(_gp_disp) 6413 addiu $gp,$gp,%lo(_gp_disp) 6414 addu $gp,$gp,$t9 6415 6416 Here $t9 holds the address of the function being called, 6417 as required by the MIPS ELF ABI. The R_MIPS_LO16 6418 relocation can easily overflow in this situation, but the 6419 R_MIPS_HI16 relocation will handle the overflow. 6420 Therefore, we consider this a bug in the MIPS ABI, and do 6421 not check for overflow here. */ 6422 } 6423 break; 6424 6425 case R_MIPS_LITERAL: 6426 /* Because we don't merge literal sections, we can handle this 6427 just like R_MIPS_GPREL16. In the long run, we should merge 6428 shared literals, and then we will need to additional work 6429 here. */ 6430 6431 /* Fall through. */ 6432 6433 case R_MIPS16_GPREL: 6434 /* The R_MIPS16_GPREL performs the same calculation as 6435 R_MIPS_GPREL16, but stores the relocated bits in a different 6436 order. We don't need to do anything special here; the 6437 differences are handled in mips_elf_perform_relocation. */ 6438 case R_MIPS_GPREL16: 6439 if (local_p) 6440 value = mips_elf_sign_extend (addend, 16) + symbol + gp0 - gp; 6441 else 6442 value = mips_elf_sign_extend (addend, 16) + symbol - gp; 6443 overflowed_p = mips_elf_overflow_p (value, 16); 6444 break; 6445 6446 case R_MIPS_GOT16: 6447 case R_MIPS_CALL16: 6448 if (local_p) 6449 { 6450 boolean forced; 6451 6452 /* The special case is when the symbol is forced to be local. We 6453 need the full address in the GOT since no R_MIPS_LO16 relocation 6454 follows. */ 6455 forced = ! mips_elf_local_relocation_p (input_bfd, relocation, 6456 local_sections, false); 6457 value = mips_elf_got16_entry (abfd, info, symbol + addend, forced); 6458 if (value == (bfd_vma) -1) 6459 return false; 6460 value 6461 = mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj, 6462 abfd, 6463 value); 6464 overflowed_p = mips_elf_overflow_p (value, 16); 6465 break; 6466 } 6467 6468 /* Fall through. */ 6469 6470 case R_MIPS_GOT_DISP: 6471 value = g; 6472 overflowed_p = mips_elf_overflow_p (value, 16); 6473 break; 6474 6475 case R_MIPS_GPREL32: 6476 value = (addend + symbol + gp0 - gp) & howto->dst_mask; 6477 break; 6478 6479 case R_MIPS_PC16: 6480 value = mips_elf_sign_extend (addend, 16) + symbol - p; 6481 value = (bfd_vma) ((bfd_signed_vma) value / 4); 6482 overflowed_p = mips_elf_overflow_p (value, 16); 6483 break; 6484 6485 case R_MIPS_GOT_HI16: 6486 case R_MIPS_CALL_HI16: 6487 /* We're allowed to handle these two relocations identically. 6488 The dynamic linker is allowed to handle the CALL relocations 6489 differently by creating a lazy evaluation stub. */ 6490 value = g; 6491 value = mips_elf_high (value); 6492 value &= howto->dst_mask; 6493 break; 6494 6495 case R_MIPS_GOT_LO16: 6496 case R_MIPS_CALL_LO16: 6497 value = g & howto->dst_mask; 6498 break; 6499 6500 case R_MIPS_GOT_PAGE: 6501 value = mips_elf_got_page (abfd, info, symbol + addend, NULL); 6502 if (value == (bfd_vma) -1) 6503 return false; 6504 value = mips_elf_got_offset_from_index (elf_hash_table (info)->dynobj, 6505 abfd, 6506 value); 6507 overflowed_p = mips_elf_overflow_p (value, 16); 6508 break; 6509 6510 case R_MIPS_GOT_OFST: 6511 mips_elf_got_page (abfd, info, symbol + addend, &value); 6512 overflowed_p = mips_elf_overflow_p (value, 16); 6513 break; 6514 6515 case R_MIPS_SUB: 6516 value = symbol - addend; 6517 value &= howto->dst_mask; 6518 break; 6519 6520 case R_MIPS_HIGHER: 6521 value = mips_elf_higher (addend + symbol); 6522 value &= howto->dst_mask; 6523 break; 6524 6525 case R_MIPS_HIGHEST: 6526 value = mips_elf_highest (addend + symbol); 6527 value &= howto->dst_mask; 6528 break; 6529 6530 case R_MIPS_SCN_DISP: 6531 value = symbol + addend - sec->output_offset; 6532 value &= howto->dst_mask; 6533 break; 6534 6535 case R_MIPS_PJUMP: 6536 case R_MIPS_JALR: 6537 /* Both of these may be ignored. R_MIPS_JALR is an optimization 6538 hint; we could improve performance by honoring that hint. */ 6539 return bfd_reloc_continue; 6540 6541 case R_MIPS_GNU_VTINHERIT: 6542 case R_MIPS_GNU_VTENTRY: 6543 /* We don't do anything with these at present. */ 6544 return bfd_reloc_continue; 6545 6546 default: 6547 /* An unrecognized relocation type. */ 6548 return bfd_reloc_notsupported; 6549 } 6550 6551 /* Store the VALUE for our caller. */ 6552 *valuep = value; 6553 return overflowed_p ? bfd_reloc_overflow : bfd_reloc_ok; 6554 } 6555 6556 /* Obtain the field relocated by RELOCATION. */ 6557 6558 static bfd_vma 6559 mips_elf_obtain_contents (howto, relocation, input_bfd, contents) 6560 reloc_howto_type *howto; 6561 const Elf_Internal_Rela *relocation; 6562 bfd *input_bfd; 6563 bfd_byte *contents; 6564 { 6565 bfd_vma x; 6566 bfd_byte *location = contents + relocation->r_offset; 6567 6568 /* Obtain the bytes. */ 6569 x = bfd_get (8 * bfd_get_reloc_size (howto), input_bfd, location); 6570 6571 if ((ELF32_R_TYPE (relocation->r_info) == R_MIPS16_26 6572 || ELF32_R_TYPE (relocation->r_info) == R_MIPS16_GPREL) 6573 && bfd_little_endian (input_bfd)) 6574 /* The two 16-bit words will be reversed on a little-endian 6575 system. See mips_elf_perform_relocation for more details. */ 6576 x = (((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16)); 6577 6578 return x; 6579 } 6580 6581 /* It has been determined that the result of the RELOCATION is the 6582 VALUE. Use HOWTO to place VALUE into the output file at the 6583 appropriate position. The SECTION is the section to which the 6584 relocation applies. If REQUIRE_JALX is true, then the opcode used 6585 for the relocation must be either JAL or JALX, and it is 6586 unconditionally converted to JALX. 6587 6588 Returns false if anything goes wrong. */ 6589 6590 static boolean 6591 mips_elf_perform_relocation (info, howto, relocation, value, 6592 input_bfd, input_section, 6593 contents, require_jalx) 6594 struct bfd_link_info *info; 6595 reloc_howto_type *howto; 6596 const Elf_Internal_Rela *relocation; 6597 bfd_vma value; 6598 bfd *input_bfd; 6599 asection *input_section; 6600 bfd_byte *contents; 6601 boolean require_jalx; 6602 { 6603 bfd_vma x; 6604 bfd_byte *location; 6605 int r_type = ELF32_R_TYPE (relocation->r_info); 6606 6607 /* Figure out where the relocation is occurring. */ 6608 location = contents + relocation->r_offset; 6609 6610 /* Obtain the current value. */ 6611 x = mips_elf_obtain_contents (howto, relocation, input_bfd, contents); 6612 6613 /* Clear the field we are setting. */ 6614 x &= ~howto->dst_mask; 6615 6616 /* If this is the R_MIPS16_26 relocation, we must store the 6617 value in a funny way. */ 6618 if (r_type == R_MIPS16_26) 6619 { 6620 /* R_MIPS16_26 is used for the mips16 jal and jalx instructions. 6621 Most mips16 instructions are 16 bits, but these instructions 6622 are 32 bits. 6623 6624 The format of these instructions is: 6625 6626 +--------------+--------------------------------+ 6627 ! JALX ! X! Imm 20:16 ! Imm 25:21 ! 6628 +--------------+--------------------------------+ 6629 ! Immediate 15:0 ! 6630 +-----------------------------------------------+ 6631 6632 JALX is the 5-bit value 00011. X is 0 for jal, 1 for jalx. 6633 Note that the immediate value in the first word is swapped. 6634 6635 When producing a relocateable object file, R_MIPS16_26 is 6636 handled mostly like R_MIPS_26. In particular, the addend is 6637 stored as a straight 26-bit value in a 32-bit instruction. 6638 (gas makes life simpler for itself by never adjusting a 6639 R_MIPS16_26 reloc to be against a section, so the addend is 6640 always zero). However, the 32 bit instruction is stored as 2 6641 16-bit values, rather than a single 32-bit value. In a 6642 big-endian file, the result is the same; in a little-endian 6643 file, the two 16-bit halves of the 32 bit value are swapped. 6644 This is so that a disassembler can recognize the jal 6645 instruction. 6646 6647 When doing a final link, R_MIPS16_26 is treated as a 32 bit 6648 instruction stored as two 16-bit values. The addend A is the 6649 contents of the targ26 field. The calculation is the same as 6650 R_MIPS_26. When storing the calculated value, reorder the 6651 immediate value as shown above, and don't forget to store the 6652 value as two 16-bit values. 6653 6654 To put it in MIPS ABI terms, the relocation field is T-targ26-16, 6655 defined as 6656 6657 big-endian: 6658 +--------+----------------------+ 6659 | | | 6660 | | targ26-16 | 6661 |31 26|25 0| 6662 +--------+----------------------+ 6663 6664 little-endian: 6665 +----------+------+-------------+ 6666 | | | | 6667 | sub1 | | sub2 | 6668 |0 9|10 15|16 31| 6669 +----------+--------------------+ 6670 where targ26-16 is sub1 followed by sub2 (i.e., the addend field A is 6671 ((sub1 << 16) | sub2)). 6672 6673 When producing a relocateable object file, the calculation is 6674 (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2) 6675 When producing a fully linked file, the calculation is 6676 let R = (((A < 2) | ((P + 4) & 0xf0000000) + S) >> 2) 6677 ((R & 0x1f0000) << 5) | ((R & 0x3e00000) >> 5) | (R & 0xffff) */ 6678 6679 if (!info->relocateable) 6680 /* Shuffle the bits according to the formula above. */ 6681 value = (((value & 0x1f0000) << 5) 6682 | ((value & 0x3e00000) >> 5) 6683 | (value & 0xffff)); 6684 } 6685 else if (r_type == R_MIPS16_GPREL) 6686 { 6687 /* R_MIPS16_GPREL is used for GP-relative addressing in mips16 6688 mode. A typical instruction will have a format like this: 6689 6690 +--------------+--------------------------------+ 6691 ! EXTEND ! Imm 10:5 ! Imm 15:11 ! 6692 +--------------+--------------------------------+ 6693 ! Major ! rx ! ry ! Imm 4:0 ! 6694 +--------------+--------------------------------+ 6695 6696 EXTEND is the five bit value 11110. Major is the instruction 6697 opcode. 6698 6699 This is handled exactly like R_MIPS_GPREL16, except that the 6700 addend is retrieved and stored as shown in this diagram; that 6701 is, the Imm fields above replace the V-rel16 field. 6702 6703 All we need to do here is shuffle the bits appropriately. As 6704 above, the two 16-bit halves must be swapped on a 6705 little-endian system. */ 6706 value = (((value & 0x7e0) << 16) 6707 | ((value & 0xf800) << 5) 6708 | (value & 0x1f)); 6709 } 6710 6711 /* Set the field. */ 6712 x |= (value & howto->dst_mask); 6713 6714 /* If required, turn JAL into JALX. */ 6715 if (require_jalx) 6716 { 6717 boolean ok; 6718 bfd_vma opcode = x >> 26; 6719 bfd_vma jalx_opcode; 6720 6721 /* Check to see if the opcode is already JAL or JALX. */ 6722 if (r_type == R_MIPS16_26) 6723 { 6724 ok = ((opcode == 0x6) || (opcode == 0x7)); 6725 jalx_opcode = 0x7; 6726 } 6727 else 6728 { 6729 ok = ((opcode == 0x3) || (opcode == 0x1d)); 6730 jalx_opcode = 0x1d; 6731 } 6732 6733 /* If the opcode is not JAL or JALX, there's a problem. */ 6734 if (!ok) 6735 { 6736 (*_bfd_error_handler) 6737 (_("%s: %s+0x%lx: jump to stub routine which is not jal"), 6738 bfd_get_filename (input_bfd), 6739 input_section->name, 6740 (unsigned long) relocation->r_offset); 6741 bfd_set_error (bfd_error_bad_value); 6742 return false; 6743 } 6744 6745 /* Make this the JALX opcode. */ 6746 x = (x & ~(0x3f << 26)) | (jalx_opcode << 26); 6747 } 6748 6749 /* Swap the high- and low-order 16 bits on little-endian systems 6750 when doing a MIPS16 relocation. */ 6751 if ((r_type == R_MIPS16_GPREL || r_type == R_MIPS16_26) 6752 && bfd_little_endian (input_bfd)) 6753 x = (((x & 0xffff) << 16) | ((x & 0xffff0000) >> 16)); 6754 6755 /* Put the value into the output. */ 6756 bfd_put (8 * bfd_get_reloc_size (howto), input_bfd, x, location); 6757 return true; 6758 } 6759 6760 /* Returns true if SECTION is a MIPS16 stub section. */ 6761 6762 static boolean 6763 mips_elf_stub_section_p (abfd, section) 6764 bfd *abfd ATTRIBUTE_UNUSED; 6765 asection *section; 6766 { 6767 const char *name = bfd_get_section_name (abfd, section); 6768 6769 return (strncmp (name, FN_STUB, sizeof FN_STUB - 1) == 0 6770 || strncmp (name, CALL_STUB, sizeof CALL_STUB - 1) == 0 6771 || strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0); 6772 } 6773 6774 /* Relocate a MIPS ELF section. */ 6775 6776 boolean 6777 _bfd_mips_elf_relocate_section (output_bfd, info, input_bfd, input_section, 6778 contents, relocs, local_syms, local_sections) 6779 bfd *output_bfd; 6780 struct bfd_link_info *info; 6781 bfd *input_bfd; 6782 asection *input_section; 6783 bfd_byte *contents; 6784 Elf_Internal_Rela *relocs; 6785 Elf_Internal_Sym *local_syms; 6786 asection **local_sections; 6787 { 6788 Elf_Internal_Rela *rel; 6789 const Elf_Internal_Rela *relend; 6790 bfd_vma addend = 0; 6791 boolean use_saved_addend_p = false; 6792 struct elf_backend_data *bed; 6793 6794 bed = get_elf_backend_data (output_bfd); 6795 relend = relocs + input_section->reloc_count * bed->s->int_rels_per_ext_rel; 6796 for (rel = relocs; rel < relend; ++rel) 6797 { 6798 const char *name; 6799 bfd_vma value; 6800 reloc_howto_type *howto; 6801 boolean require_jalx; 6802 /* True if the relocation is a RELA relocation, rather than a 6803 REL relocation. */ 6804 boolean rela_relocation_p = true; 6805 int r_type = ELF32_R_TYPE (rel->r_info); 6806 const char * msg = (const char *) NULL; 6807 6808 /* Find the relocation howto for this relocation. */ 6809 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd)) 6810 { 6811 /* Some 32-bit code uses R_MIPS_64. In particular, people use 6812 64-bit code, but make sure all their addresses are in the 6813 lowermost or uppermost 32-bit section of the 64-bit address 6814 space. Thus, when they use an R_MIPS_64 they mean what is 6815 usually meant by R_MIPS_32, with the exception that the 6816 stored value is sign-extended to 64 bits. */ 6817 howto = elf_mips_howto_table + R_MIPS_32; 6818 6819 /* On big-endian systems, we need to lie about the position 6820 of the reloc. */ 6821 if (bfd_big_endian (input_bfd)) 6822 rel->r_offset += 4; 6823 } 6824 else 6825 howto = mips_rtype_to_howto (r_type); 6826 6827 if (!use_saved_addend_p) 6828 { 6829 Elf_Internal_Shdr *rel_hdr; 6830 6831 /* If these relocations were originally of the REL variety, 6832 we must pull the addend out of the field that will be 6833 relocated. Otherwise, we simply use the contents of the 6834 RELA relocation. To determine which flavor or relocation 6835 this is, we depend on the fact that the INPUT_SECTION's 6836 REL_HDR is read before its REL_HDR2. */ 6837 rel_hdr = &elf_section_data (input_section)->rel_hdr; 6838 if ((size_t) (rel - relocs) 6839 >= (NUM_SHDR_ENTRIES (rel_hdr) * bed->s->int_rels_per_ext_rel)) 6840 rel_hdr = elf_section_data (input_section)->rel_hdr2; 6841 if (rel_hdr->sh_entsize == MIPS_ELF_REL_SIZE (input_bfd)) 6842 { 6843 /* Note that this is a REL relocation. */ 6844 rela_relocation_p = false; 6845 6846 /* Get the addend, which is stored in the input file. */ 6847 addend = mips_elf_obtain_contents (howto, 6848 rel, 6849 input_bfd, 6850 contents); 6851 addend &= howto->src_mask; 6852 6853 /* For some kinds of relocations, the ADDEND is a 6854 combination of the addend stored in two different 6855 relocations. */ 6856 if (r_type == R_MIPS_HI16 6857 || r_type == R_MIPS_GNU_REL_HI16 6858 || (r_type == R_MIPS_GOT16 6859 && mips_elf_local_relocation_p (input_bfd, rel, 6860 local_sections, false))) 6861 { 6862 bfd_vma l; 6863 const Elf_Internal_Rela *lo16_relocation; 6864 reloc_howto_type *lo16_howto; 6865 int lo; 6866 6867 /* The combined value is the sum of the HI16 addend, 6868 left-shifted by sixteen bits, and the LO16 6869 addend, sign extended. (Usually, the code does 6870 a `lui' of the HI16 value, and then an `addiu' of 6871 the LO16 value.) 6872 6873 Scan ahead to find a matching LO16 relocation. */ 6874 if (r_type == R_MIPS_GNU_REL_HI16) 6875 lo = R_MIPS_GNU_REL_LO16; 6876 else 6877 lo = R_MIPS_LO16; 6878 lo16_relocation 6879 = mips_elf_next_relocation (lo, rel, relend); 6880 if (lo16_relocation == NULL) 6881 return false; 6882 6883 /* Obtain the addend kept there. */ 6884 lo16_howto = mips_rtype_to_howto (lo); 6885 l = mips_elf_obtain_contents (lo16_howto, 6886 lo16_relocation, 6887 input_bfd, contents); 6888 l &= lo16_howto->src_mask; 6889 l = mips_elf_sign_extend (l, 16); 6890 6891 addend <<= 16; 6892 6893 /* Compute the combined addend. */ 6894 addend += l; 6895 } 6896 else if (r_type == R_MIPS16_GPREL) 6897 { 6898 /* The addend is scrambled in the object file. See 6899 mips_elf_perform_relocation for details on the 6900 format. */ 6901 addend = (((addend & 0x1f0000) >> 5) 6902 | ((addend & 0x7e00000) >> 16) 6903 | (addend & 0x1f)); 6904 } 6905 } 6906 else 6907 addend = rel->r_addend; 6908 } 6909 6910 if (info->relocateable) 6911 { 6912 Elf_Internal_Sym *sym; 6913 unsigned long r_symndx; 6914 6915 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd) 6916 && bfd_big_endian (input_bfd)) 6917 rel->r_offset -= 4; 6918 6919 /* Since we're just relocating, all we need to do is copy 6920 the relocations back out to the object file, unless 6921 they're against a section symbol, in which case we need 6922 to adjust by the section offset, or unless they're GP 6923 relative in which case we need to adjust by the amount 6924 that we're adjusting GP in this relocateable object. */ 6925 6926 if (!mips_elf_local_relocation_p (input_bfd, rel, local_sections, 6927 false)) 6928 /* There's nothing to do for non-local relocations. */ 6929 continue; 6930 6931 if (r_type == R_MIPS16_GPREL 6932 || r_type == R_MIPS_GPREL16 6933 || r_type == R_MIPS_GPREL32 6934 || r_type == R_MIPS_LITERAL) 6935 addend -= (_bfd_get_gp_value (output_bfd) 6936 - _bfd_get_gp_value (input_bfd)); 6937 else if (r_type == R_MIPS_26 || r_type == R_MIPS16_26 6938 || r_type == R_MIPS_GNU_REL16_S2) 6939 /* The addend is stored without its two least 6940 significant bits (which are always zero.) In a 6941 non-relocateable link, calculate_relocation will do 6942 this shift; here, we must do it ourselves. */ 6943 addend <<= 2; 6944 6945 r_symndx = ELF32_R_SYM (rel->r_info); 6946 sym = local_syms + r_symndx; 6947 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION) 6948 /* Adjust the addend appropriately. */ 6949 addend += local_sections[r_symndx]->output_offset; 6950 6951 /* If the relocation is for a R_MIPS_HI16 or R_MIPS_GOT16, 6952 then we only want to write out the high-order 16 bits. 6953 The subsequent R_MIPS_LO16 will handle the low-order bits. */ 6954 if (r_type == R_MIPS_HI16 || r_type == R_MIPS_GOT16 6955 || r_type == R_MIPS_GNU_REL_HI16) 6956 addend = mips_elf_high (addend); 6957 /* If the relocation is for an R_MIPS_26 relocation, then 6958 the two low-order bits are not stored in the object file; 6959 they are implicitly zero. */ 6960 else if (r_type == R_MIPS_26 || r_type == R_MIPS16_26 6961 || r_type == R_MIPS_GNU_REL16_S2) 6962 addend >>= 2; 6963 6964 if (rela_relocation_p) 6965 /* If this is a RELA relocation, just update the addend. 6966 We have to cast away constness for REL. */ 6967 rel->r_addend = addend; 6968 else 6969 { 6970 /* Otherwise, we have to write the value back out. Note 6971 that we use the source mask, rather than the 6972 destination mask because the place to which we are 6973 writing will be source of the addend in the final 6974 link. */ 6975 addend &= howto->src_mask; 6976 6977 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd)) 6978 /* See the comment above about using R_MIPS_64 in the 32-bit 6979 ABI. Here, we need to update the addend. It would be 6980 possible to get away with just using the R_MIPS_32 reloc 6981 but for endianness. */ 6982 { 6983 bfd_vma sign_bits; 6984 bfd_vma low_bits; 6985 bfd_vma high_bits; 6986 6987 if (addend & ((bfd_vma) 1 << 31)) 6988 sign_bits = ((bfd_vma) 1 << 32) - 1; 6989 else 6990 sign_bits = 0; 6991 6992 /* If we don't know that we have a 64-bit type, 6993 do two separate stores. */ 6994 if (bfd_big_endian (input_bfd)) 6995 { 6996 /* Store the sign-bits (which are most significant) 6997 first. */ 6998 low_bits = sign_bits; 6999 high_bits = addend; 7000 } 7001 else 7002 { 7003 low_bits = addend; 7004 high_bits = sign_bits; 7005 } 7006 bfd_put_32 (input_bfd, low_bits, 7007 contents + rel->r_offset); 7008 bfd_put_32 (input_bfd, high_bits, 7009 contents + rel->r_offset + 4); 7010 continue; 7011 } 7012 7013 if (!mips_elf_perform_relocation (info, howto, rel, addend, 7014 input_bfd, input_section, 7015 contents, false)) 7016 return false; 7017 } 7018 7019 /* Go on to the next relocation. */ 7020 continue; 7021 } 7022 7023 /* In the N32 and 64-bit ABIs there may be multiple consecutive 7024 relocations for the same offset. In that case we are 7025 supposed to treat the output of each relocation as the addend 7026 for the next. */ 7027 if (rel + 1 < relend 7028 && rel->r_offset == rel[1].r_offset 7029 && ELF32_R_TYPE (rel[1].r_info) != R_MIPS_NONE) 7030 use_saved_addend_p = true; 7031 else 7032 use_saved_addend_p = false; 7033 7034 /* Figure out what value we are supposed to relocate. */ 7035 switch (mips_elf_calculate_relocation (output_bfd, 7036 input_bfd, 7037 input_section, 7038 info, 7039 rel, 7040 addend, 7041 howto, 7042 local_syms, 7043 local_sections, 7044 &value, 7045 &name, 7046 &require_jalx)) 7047 { 7048 case bfd_reloc_continue: 7049 /* There's nothing to do. */ 7050 continue; 7051 7052 case bfd_reloc_undefined: 7053 /* mips_elf_calculate_relocation already called the 7054 undefined_symbol callback. There's no real point in 7055 trying to perform the relocation at this point, so we 7056 just skip ahead to the next relocation. */ 7057 continue; 7058 7059 case bfd_reloc_notsupported: 7060 msg = _("internal error: unsupported relocation error"); 7061 info->callbacks->warning 7062 (info, msg, name, input_bfd, input_section, rel->r_offset); 7063 return false; 7064 7065 case bfd_reloc_overflow: 7066 if (use_saved_addend_p) 7067 /* Ignore overflow until we reach the last relocation for 7068 a given location. */ 7069 ; 7070 else 7071 { 7072 BFD_ASSERT (name != NULL); 7073 if (! ((*info->callbacks->reloc_overflow) 7074 (info, name, howto->name, (bfd_vma) 0, 7075 input_bfd, input_section, rel->r_offset))) 7076 return false; 7077 } 7078 break; 7079 7080 case bfd_reloc_ok: 7081 break; 7082 7083 default: 7084 abort (); 7085 break; 7086 } 7087 7088 /* If we've got another relocation for the address, keep going 7089 until we reach the last one. */ 7090 if (use_saved_addend_p) 7091 { 7092 addend = value; 7093 continue; 7094 } 7095 7096 if (r_type == R_MIPS_64 && !ABI_64_P (output_bfd)) 7097 /* See the comment above about using R_MIPS_64 in the 32-bit 7098 ABI. Until now, we've been using the HOWTO for R_MIPS_32; 7099 that calculated the right value. Now, however, we 7100 sign-extend the 32-bit result to 64-bits, and store it as a 7101 64-bit value. We are especially generous here in that we 7102 go to extreme lengths to support this usage on systems with 7103 only a 32-bit VMA. */ 7104 { 7105 bfd_vma sign_bits; 7106 bfd_vma low_bits; 7107 bfd_vma high_bits; 7108 7109 if (value & ((bfd_vma) 1 << 31)) 7110 sign_bits = ((bfd_vma) 1 << 32) - 1; 7111 else 7112 sign_bits = 0; 7113 7114 /* If we don't know that we have a 64-bit type, 7115 do two separate stores. */ 7116 if (bfd_big_endian (input_bfd)) 7117 { 7118 /* Undo what we did above. */ 7119 rel->r_offset -= 4; 7120 /* Store the sign-bits (which are most significant) 7121 first. */ 7122 low_bits = sign_bits; 7123 high_bits = value; 7124 } 7125 else 7126 { 7127 low_bits = value; 7128 high_bits = sign_bits; 7129 } 7130 bfd_put_32 (input_bfd, low_bits, 7131 contents + rel->r_offset); 7132 bfd_put_32 (input_bfd, high_bits, 7133 contents + rel->r_offset + 4); 7134 continue; 7135 } 7136 7137 /* Actually perform the relocation. */ 7138 if (!mips_elf_perform_relocation (info, howto, rel, value, input_bfd, 7139 input_section, contents, 7140 require_jalx)) 7141 return false; 7142 } 7143 7144 return true; 7145 } 7146 7147 /* This hook function is called before the linker writes out a global 7148 symbol. We mark symbols as small common if appropriate. This is 7149 also where we undo the increment of the value for a mips16 symbol. */ 7150 7151 boolean 7152 _bfd_mips_elf_link_output_symbol_hook (abfd, info, name, sym, input_sec) 7153 bfd *abfd ATTRIBUTE_UNUSED; 7154 struct bfd_link_info *info ATTRIBUTE_UNUSED; 7155 const char *name ATTRIBUTE_UNUSED; 7156 Elf_Internal_Sym *sym; 7157 asection *input_sec; 7158 { 7159 /* If we see a common symbol, which implies a relocatable link, then 7160 if a symbol was small common in an input file, mark it as small 7161 common in the output file. */ 7162 if (sym->st_shndx == SHN_COMMON 7163 && strcmp (input_sec->name, ".scommon") == 0) 7164 sym->st_shndx = SHN_MIPS_SCOMMON; 7165 7166 if (sym->st_other == STO_MIPS16 7167 && (sym->st_value & 1) != 0) 7168 --sym->st_value; 7169 7170 return true; 7171 } 7172 7173 7174 /* Functions for the dynamic linker. */ 7175 7176 /* The name of the dynamic interpreter. This is put in the .interp 7177 section. */ 7178 7179 #define ELF_DYNAMIC_INTERPRETER(abfd) \ 7180 (ABI_N32_P (abfd) ? "/usr/lib32/libc.so.1" \ 7181 : ABI_64_P (abfd) ? "/usr/lib64/libc.so.1" \ 7182 : "/usr/lib/libc.so.1") 7183 7184 /* Create dynamic sections when linking against a dynamic object. */ 7185 7186 boolean 7187 _bfd_mips_elf_create_dynamic_sections (abfd, info) 7188 bfd *abfd; 7189 struct bfd_link_info *info; 7190 { 7191 struct elf_link_hash_entry *h; 7192 flagword flags; 7193 register asection *s; 7194 const char * const *namep; 7195 7196 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 7197 | SEC_LINKER_CREATED | SEC_READONLY); 7198 7199 /* Mips ABI requests the .dynamic section to be read only. */ 7200 s = bfd_get_section_by_name (abfd, ".dynamic"); 7201 if (s != NULL) 7202 { 7203 if (! bfd_set_section_flags (abfd, s, flags)) 7204 return false; 7205 } 7206 7207 /* We need to create .got section. */ 7208 if (! mips_elf_create_got_section (abfd, info)) 7209 return false; 7210 7211 /* Create the .msym section on IRIX6. It is used by the dynamic 7212 linker to speed up dynamic relocations, and to avoid computing 7213 the ELF hash for symbols. */ 7214 if (IRIX_COMPAT (abfd) == ict_irix6 7215 && !mips_elf_create_msym_section (abfd)) 7216 return false; 7217 7218 /* Create .stub section. */ 7219 if (bfd_get_section_by_name (abfd, 7220 MIPS_ELF_STUB_SECTION_NAME (abfd)) == NULL) 7221 { 7222 s = bfd_make_section (abfd, MIPS_ELF_STUB_SECTION_NAME (abfd)); 7223 if (s == NULL 7224 || ! bfd_set_section_flags (abfd, s, flags | SEC_CODE) 7225 || ! bfd_set_section_alignment (abfd, s, 7226 MIPS_ELF_LOG_FILE_ALIGN (abfd))) 7227 return false; 7228 } 7229 7230 if ((IRIX_COMPAT (abfd) == ict_irix5 || IRIX_COMPAT (abfd) == ict_none) 7231 && !info->shared 7232 && bfd_get_section_by_name (abfd, ".rld_map") == NULL) 7233 { 7234 s = bfd_make_section (abfd, ".rld_map"); 7235 if (s == NULL 7236 || ! bfd_set_section_flags (abfd, s, flags & ~SEC_READONLY) 7237 || ! bfd_set_section_alignment (abfd, s, 7238 MIPS_ELF_LOG_FILE_ALIGN (abfd))) 7239 return false; 7240 } 7241 7242 /* On IRIX5, we adjust add some additional symbols and change the 7243 alignments of several sections. There is no ABI documentation 7244 indicating that this is necessary on IRIX6, nor any evidence that 7245 the linker takes such action. */ 7246 if (IRIX_COMPAT (abfd) == ict_irix5) 7247 { 7248 for (namep = mips_elf_dynsym_rtproc_names; *namep != NULL; namep++) 7249 { 7250 h = NULL; 7251 if (! (_bfd_generic_link_add_one_symbol 7252 (info, abfd, *namep, BSF_GLOBAL, bfd_und_section_ptr, 7253 (bfd_vma) 0, (const char *) NULL, false, 7254 get_elf_backend_data (abfd)->collect, 7255 (struct bfd_link_hash_entry **) &h))) 7256 return false; 7257 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF; 7258 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; 7259 h->type = STT_SECTION; 7260 7261 if (! bfd_elf32_link_record_dynamic_symbol (info, h)) 7262 return false; 7263 } 7264 7265 /* We need to create a .compact_rel section. */ 7266 if (SGI_COMPAT (abfd)) 7267 { 7268 if (!mips_elf_create_compact_rel_section (abfd, info)) 7269 return false; 7270 } 7271 7272 /* Change aligments of some sections. */ 7273 s = bfd_get_section_by_name (abfd, ".hash"); 7274 if (s != NULL) 7275 bfd_set_section_alignment (abfd, s, 4); 7276 s = bfd_get_section_by_name (abfd, ".dynsym"); 7277 if (s != NULL) 7278 bfd_set_section_alignment (abfd, s, 4); 7279 s = bfd_get_section_by_name (abfd, ".dynstr"); 7280 if (s != NULL) 7281 bfd_set_section_alignment (abfd, s, 4); 7282 s = bfd_get_section_by_name (abfd, ".reginfo"); 7283 if (s != NULL) 7284 bfd_set_section_alignment (abfd, s, 4); 7285 s = bfd_get_section_by_name (abfd, ".dynamic"); 7286 if (s != NULL) 7287 bfd_set_section_alignment (abfd, s, 4); 7288 } 7289 7290 if (!info->shared) 7291 { 7292 h = NULL; 7293 if (SGI_COMPAT (abfd)) 7294 { 7295 if (!(_bfd_generic_link_add_one_symbol 7296 (info, abfd, "_DYNAMIC_LINK", BSF_GLOBAL, bfd_abs_section_ptr, 7297 (bfd_vma) 0, (const char *) NULL, false, 7298 get_elf_backend_data (abfd)->collect, 7299 (struct bfd_link_hash_entry **) &h))) 7300 return false; 7301 } 7302 else 7303 { 7304 /* For normal mips it is _DYNAMIC_LINKING. */ 7305 if (!(_bfd_generic_link_add_one_symbol 7306 (info, abfd, "_DYNAMIC_LINKING", BSF_GLOBAL, 7307 bfd_abs_section_ptr, (bfd_vma) 0, (const char *) NULL, false, 7308 get_elf_backend_data (abfd)->collect, 7309 (struct bfd_link_hash_entry **) &h))) 7310 return false; 7311 } 7312 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF; 7313 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; 7314 h->type = STT_SECTION; 7315 7316 if (! bfd_elf32_link_record_dynamic_symbol (info, h)) 7317 return false; 7318 7319 if (! mips_elf_hash_table (info)->use_rld_obj_head) 7320 { 7321 /* __rld_map is a four byte word located in the .data section 7322 and is filled in by the rtld to contain a pointer to 7323 the _r_debug structure. Its symbol value will be set in 7324 mips_elf_finish_dynamic_symbol. */ 7325 s = bfd_get_section_by_name (abfd, ".rld_map"); 7326 BFD_ASSERT (s != NULL); 7327 7328 h = NULL; 7329 if (SGI_COMPAT (abfd)) 7330 { 7331 if (!(_bfd_generic_link_add_one_symbol 7332 (info, abfd, "__rld_map", BSF_GLOBAL, s, 7333 (bfd_vma) 0, (const char *) NULL, false, 7334 get_elf_backend_data (abfd)->collect, 7335 (struct bfd_link_hash_entry **) &h))) 7336 return false; 7337 } 7338 else 7339 { 7340 /* For normal mips the symbol is __RLD_MAP. */ 7341 if (!(_bfd_generic_link_add_one_symbol 7342 (info, abfd, "__RLD_MAP", BSF_GLOBAL, s, 7343 (bfd_vma) 0, (const char *) NULL, false, 7344 get_elf_backend_data (abfd)->collect, 7345 (struct bfd_link_hash_entry **) &h))) 7346 return false; 7347 } 7348 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF; 7349 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; 7350 h->type = STT_OBJECT; 7351 7352 if (! bfd_elf32_link_record_dynamic_symbol (info, h)) 7353 return false; 7354 } 7355 } 7356 7357 return true; 7358 } 7359 7360 /* Create the .compact_rel section. */ 7361 7362 static boolean 7363 mips_elf_create_compact_rel_section (abfd, info) 7364 bfd *abfd; 7365 struct bfd_link_info *info ATTRIBUTE_UNUSED; 7366 { 7367 flagword flags; 7368 register asection *s; 7369 7370 if (bfd_get_section_by_name (abfd, ".compact_rel") == NULL) 7371 { 7372 flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED 7373 | SEC_READONLY); 7374 7375 s = bfd_make_section (abfd, ".compact_rel"); 7376 if (s == NULL 7377 || ! bfd_set_section_flags (abfd, s, flags) 7378 || ! bfd_set_section_alignment (abfd, s, 7379 MIPS_ELF_LOG_FILE_ALIGN (abfd))) 7380 return false; 7381 7382 s->_raw_size = sizeof (Elf32_External_compact_rel); 7383 } 7384 7385 return true; 7386 } 7387 7388 /* Create the .got section to hold the global offset table. */ 7389 7390 static boolean 7391 mips_elf_create_got_section (abfd, info) 7392 bfd *abfd; 7393 struct bfd_link_info *info; 7394 { 7395 flagword flags; 7396 register asection *s; 7397 struct elf_link_hash_entry *h; 7398 struct mips_got_info *g; 7399 7400 /* This function may be called more than once. */ 7401 if (mips_elf_got_section (abfd)) 7402 return true; 7403 7404 flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY 7405 | SEC_LINKER_CREATED); 7406 7407 s = bfd_make_section (abfd, ".got"); 7408 if (s == NULL 7409 || ! bfd_set_section_flags (abfd, s, flags) 7410 || ! bfd_set_section_alignment (abfd, s, 4)) 7411 return false; 7412 7413 /* Define the symbol _GLOBAL_OFFSET_TABLE_. We don't do this in the 7414 linker script because we don't want to define the symbol if we 7415 are not creating a global offset table. */ 7416 h = NULL; 7417 if (! (_bfd_generic_link_add_one_symbol 7418 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s, 7419 (bfd_vma) 0, (const char *) NULL, false, 7420 get_elf_backend_data (abfd)->collect, 7421 (struct bfd_link_hash_entry **) &h))) 7422 return false; 7423 h->elf_link_hash_flags &= ~ELF_LINK_NON_ELF; 7424 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR; 7425 h->type = STT_OBJECT; 7426 7427 if (info->shared 7428 && ! bfd_elf32_link_record_dynamic_symbol (info, h)) 7429 return false; 7430 7431 /* The first several global offset table entries are reserved. */ 7432 s->_raw_size = MIPS_RESERVED_GOTNO * MIPS_ELF_GOT_SIZE (abfd); 7433 7434 g = (struct mips_got_info *) bfd_alloc (abfd, 7435 sizeof (struct mips_got_info)); 7436 if (g == NULL) 7437 return false; 7438 g->global_gotsym = NULL; 7439 g->local_gotno = MIPS_RESERVED_GOTNO; 7440 g->assigned_gotno = MIPS_RESERVED_GOTNO; 7441 if (elf_section_data (s) == NULL) 7442 { 7443 s->used_by_bfd = 7444 (PTR) bfd_zalloc (abfd, sizeof (struct bfd_elf_section_data)); 7445 if (elf_section_data (s) == NULL) 7446 return false; 7447 } 7448 elf_section_data (s)->tdata = (PTR) g; 7449 elf_section_data (s)->this_hdr.sh_flags 7450 |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL; 7451 7452 return true; 7453 } 7454 7455 /* Returns the .msym section for ABFD, creating it if it does not 7456 already exist. Returns NULL to indicate error. */ 7457 7458 static asection * 7459 mips_elf_create_msym_section (abfd) 7460 bfd *abfd; 7461 { 7462 asection *s; 7463 7464 s = bfd_get_section_by_name (abfd, MIPS_ELF_MSYM_SECTION_NAME (abfd)); 7465 if (!s) 7466 { 7467 s = bfd_make_section (abfd, MIPS_ELF_MSYM_SECTION_NAME (abfd)); 7468 if (!s 7469 || !bfd_set_section_flags (abfd, s, 7470 SEC_ALLOC 7471 | SEC_LOAD 7472 | SEC_HAS_CONTENTS 7473 | SEC_LINKER_CREATED 7474 | SEC_READONLY) 7475 || !bfd_set_section_alignment (abfd, s, 7476 MIPS_ELF_LOG_FILE_ALIGN (abfd))) 7477 return NULL; 7478 } 7479 7480 return s; 7481 } 7482 7483 /* Add room for N relocations to the .rel.dyn section in ABFD. */ 7484 7485 static void 7486 mips_elf_allocate_dynamic_relocations (abfd, n) 7487 bfd *abfd; 7488 unsigned int n; 7489 { 7490 asection *s; 7491 7492 s = bfd_get_section_by_name (abfd, MIPS_ELF_REL_DYN_SECTION_NAME (abfd)); 7493 BFD_ASSERT (s != NULL); 7494 7495 if (s->_raw_size == 0) 7496 { 7497 /* Make room for a null element. */ 7498 s->_raw_size += MIPS_ELF_REL_SIZE (abfd); 7499 ++s->reloc_count; 7500 } 7501 s->_raw_size += n * MIPS_ELF_REL_SIZE (abfd); 7502 } 7503 7504 /* Look through the relocs for a section during the first phase, and 7505 allocate space in the global offset table. */ 7506 7507 boolean 7508 _bfd_mips_elf_check_relocs (abfd, info, sec, relocs) 7509 bfd *abfd; 7510 struct bfd_link_info *info; 7511 asection *sec; 7512 const Elf_Internal_Rela *relocs; 7513 { 7514 const char *name; 7515 bfd *dynobj; 7516 Elf_Internal_Shdr *symtab_hdr; 7517 struct elf_link_hash_entry **sym_hashes; 7518 struct mips_got_info *g; 7519 size_t extsymoff; 7520 const Elf_Internal_Rela *rel; 7521 const Elf_Internal_Rela *rel_end; 7522 asection *sgot; 7523 asection *sreloc; 7524 struct elf_backend_data *bed; 7525 7526 if (info->relocateable) 7527 return true; 7528 7529 dynobj = elf_hash_table (info)->dynobj; 7530 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 7531 sym_hashes = elf_sym_hashes (abfd); 7532 extsymoff = (elf_bad_symtab (abfd)) ? 0 : symtab_hdr->sh_info; 7533 7534 /* Check for the mips16 stub sections. */ 7535 7536 name = bfd_get_section_name (abfd, sec); 7537 if (strncmp (name, FN_STUB, sizeof FN_STUB - 1) == 0) 7538 { 7539 unsigned long r_symndx; 7540 7541 /* Look at the relocation information to figure out which symbol 7542 this is for. */ 7543 7544 r_symndx = ELF32_R_SYM (relocs->r_info); 7545 7546 if (r_symndx < extsymoff 7547 || sym_hashes[r_symndx - extsymoff] == NULL) 7548 { 7549 asection *o; 7550 7551 /* This stub is for a local symbol. This stub will only be 7552 needed if there is some relocation in this BFD, other 7553 than a 16 bit function call, which refers to this symbol. */ 7554 for (o = abfd->sections; o != NULL; o = o->next) 7555 { 7556 Elf_Internal_Rela *sec_relocs; 7557 const Elf_Internal_Rela *r, *rend; 7558 7559 /* We can ignore stub sections when looking for relocs. */ 7560 if ((o->flags & SEC_RELOC) == 0 7561 || o->reloc_count == 0 7562 || strncmp (bfd_get_section_name (abfd, o), FN_STUB, 7563 sizeof FN_STUB - 1) == 0 7564 || strncmp (bfd_get_section_name (abfd, o), CALL_STUB, 7565 sizeof CALL_STUB - 1) == 0 7566 || strncmp (bfd_get_section_name (abfd, o), CALL_FP_STUB, 7567 sizeof CALL_FP_STUB - 1) == 0) 7568 continue; 7569 7570 sec_relocs = (_bfd_elf32_link_read_relocs 7571 (abfd, o, (PTR) NULL, 7572 (Elf_Internal_Rela *) NULL, 7573 info->keep_memory)); 7574 if (sec_relocs == NULL) 7575 return false; 7576 7577 rend = sec_relocs + o->reloc_count; 7578 for (r = sec_relocs; r < rend; r++) 7579 if (ELF32_R_SYM (r->r_info) == r_symndx 7580 && ELF32_R_TYPE (r->r_info) != R_MIPS16_26) 7581 break; 7582 7583 if (! info->keep_memory) 7584 free (sec_relocs); 7585 7586 if (r < rend) 7587 break; 7588 } 7589 7590 if (o == NULL) 7591 { 7592 /* There is no non-call reloc for this stub, so we do 7593 not need it. Since this function is called before 7594 the linker maps input sections to output sections, we 7595 can easily discard it by setting the SEC_EXCLUDE 7596 flag. */ 7597 sec->flags |= SEC_EXCLUDE; 7598 return true; 7599 } 7600 7601 /* Record this stub in an array of local symbol stubs for 7602 this BFD. */ 7603 if (elf_tdata (abfd)->local_stubs == NULL) 7604 { 7605 unsigned long symcount; 7606 asection **n; 7607 7608 if (elf_bad_symtab (abfd)) 7609 symcount = NUM_SHDR_ENTRIES (symtab_hdr); 7610 else 7611 symcount = symtab_hdr->sh_info; 7612 n = (asection **) bfd_zalloc (abfd, 7613 symcount * sizeof (asection *)); 7614 if (n == NULL) 7615 return false; 7616 elf_tdata (abfd)->local_stubs = n; 7617 } 7618 7619 elf_tdata (abfd)->local_stubs[r_symndx] = sec; 7620 7621 /* We don't need to set mips16_stubs_seen in this case. 7622 That flag is used to see whether we need to look through 7623 the global symbol table for stubs. We don't need to set 7624 it here, because we just have a local stub. */ 7625 } 7626 else 7627 { 7628 struct mips_elf_link_hash_entry *h; 7629 7630 h = ((struct mips_elf_link_hash_entry *) 7631 sym_hashes[r_symndx - extsymoff]); 7632 7633 /* H is the symbol this stub is for. */ 7634 7635 h->fn_stub = sec; 7636 mips_elf_hash_table (info)->mips16_stubs_seen = true; 7637 } 7638 } 7639 else if (strncmp (name, CALL_STUB, sizeof CALL_STUB - 1) == 0 7640 || strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0) 7641 { 7642 unsigned long r_symndx; 7643 struct mips_elf_link_hash_entry *h; 7644 asection **loc; 7645 7646 /* Look at the relocation information to figure out which symbol 7647 this is for. */ 7648 7649 r_symndx = ELF32_R_SYM (relocs->r_info); 7650 7651 if (r_symndx < extsymoff 7652 || sym_hashes[r_symndx - extsymoff] == NULL) 7653 { 7654 /* This stub was actually built for a static symbol defined 7655 in the same file. We assume that all static symbols in 7656 mips16 code are themselves mips16, so we can simply 7657 discard this stub. Since this function is called before 7658 the linker maps input sections to output sections, we can 7659 easily discard it by setting the SEC_EXCLUDE flag. */ 7660 sec->flags |= SEC_EXCLUDE; 7661 return true; 7662 } 7663 7664 h = ((struct mips_elf_link_hash_entry *) 7665 sym_hashes[r_symndx - extsymoff]); 7666 7667 /* H is the symbol this stub is for. */ 7668 7669 if (strncmp (name, CALL_FP_STUB, sizeof CALL_FP_STUB - 1) == 0) 7670 loc = &h->call_fp_stub; 7671 else 7672 loc = &h->call_stub; 7673 7674 /* If we already have an appropriate stub for this function, we 7675 don't need another one, so we can discard this one. Since 7676 this function is called before the linker maps input sections 7677 to output sections, we can easily discard it by setting the 7678 SEC_EXCLUDE flag. We can also discard this section if we 7679 happen to already know that this is a mips16 function; it is 7680 not necessary to check this here, as it is checked later, but 7681 it is slightly faster to check now. */ 7682 if (*loc != NULL || h->root.other == STO_MIPS16) 7683 { 7684 sec->flags |= SEC_EXCLUDE; 7685 return true; 7686 } 7687 7688 *loc = sec; 7689 mips_elf_hash_table (info)->mips16_stubs_seen = true; 7690 } 7691 7692 if (dynobj == NULL) 7693 { 7694 sgot = NULL; 7695 g = NULL; 7696 } 7697 else 7698 { 7699 sgot = mips_elf_got_section (dynobj); 7700 if (sgot == NULL) 7701 g = NULL; 7702 else 7703 { 7704 BFD_ASSERT (elf_section_data (sgot) != NULL); 7705 g = (struct mips_got_info *) elf_section_data (sgot)->tdata; 7706 BFD_ASSERT (g != NULL); 7707 } 7708 } 7709 7710 sreloc = NULL; 7711 bed = get_elf_backend_data (abfd); 7712 rel_end = relocs + sec->reloc_count * bed->s->int_rels_per_ext_rel; 7713 for (rel = relocs; rel < rel_end; ++rel) 7714 { 7715 unsigned long r_symndx; 7716 int r_type; 7717 struct elf_link_hash_entry *h; 7718 7719 r_symndx = ELF32_R_SYM (rel->r_info); 7720 r_type = ELF32_R_TYPE (rel->r_info); 7721 7722 if (r_symndx < extsymoff) 7723 h = NULL; 7724 else if (r_symndx >= extsymoff + NUM_SHDR_ENTRIES (symtab_hdr)) 7725 { 7726 (*_bfd_error_handler) 7727 (_("Malformed reloc detected for section %s"), name); 7728 bfd_set_error (bfd_error_bad_value); 7729 return false; 7730 } 7731 else 7732 { 7733 h = sym_hashes[r_symndx - extsymoff]; 7734 7735 /* This may be an indirect symbol created because of a version. */ 7736 if (h != NULL) 7737 { 7738 while (h->root.type == bfd_link_hash_indirect) 7739 h = (struct elf_link_hash_entry *) h->root.u.i.link; 7740 } 7741 } 7742 7743 /* Some relocs require a global offset table. */ 7744 if (dynobj == NULL || sgot == NULL) 7745 { 7746 switch (r_type) 7747 { 7748 case R_MIPS_GOT16: 7749 case R_MIPS_CALL16: 7750 case R_MIPS_CALL_HI16: 7751 case R_MIPS_CALL_LO16: 7752 case R_MIPS_GOT_HI16: 7753 case R_MIPS_GOT_LO16: 7754 case R_MIPS_GOT_PAGE: 7755 case R_MIPS_GOT_OFST: 7756 case R_MIPS_GOT_DISP: 7757 if (dynobj == NULL) 7758 elf_hash_table (info)->dynobj = dynobj = abfd; 7759 if (! mips_elf_create_got_section (dynobj, info)) 7760 return false; 7761 g = mips_elf_got_info (dynobj, &sgot); 7762 break; 7763 7764 case R_MIPS_32: 7765 case R_MIPS_REL32: 7766 case R_MIPS_64: 7767 if (dynobj == NULL 7768 && (info->shared || h != NULL) 7769 && (sec->flags & SEC_ALLOC) != 0) 7770 elf_hash_table (info)->dynobj = dynobj = abfd; 7771 break; 7772 7773 default: 7774 break; 7775 } 7776 } 7777 7778 if (!h && (r_type == R_MIPS_CALL_LO16 7779 || r_type == R_MIPS_GOT_LO16 7780 || r_type == R_MIPS_GOT_DISP)) 7781 { 7782 /* We may need a local GOT entry for this relocation. We 7783 don't count R_MIPS_GOT_PAGE because we can estimate the 7784 maximum number of pages needed by looking at the size of 7785 the segment. Similar comments apply to R_MIPS_GOT16 and 7786 R_MIPS_CALL16. We don't count R_MIPS_GOT_HI16, or 7787 R_MIPS_CALL_HI16 because these are always followed by an 7788 R_MIPS_GOT_LO16 or R_MIPS_CALL_LO16. 7789 7790 This estimation is very conservative since we can merge 7791 duplicate entries in the GOT. In order to be less 7792 conservative, we could actually build the GOT here, 7793 rather than in relocate_section. */ 7794 g->local_gotno++; 7795 sgot->_raw_size += MIPS_ELF_GOT_SIZE (dynobj); 7796 } 7797 7798 switch (r_type) 7799 { 7800 case R_MIPS_CALL16: 7801 if (h == NULL) 7802 { 7803 (*_bfd_error_handler) 7804 (_("%s: CALL16 reloc at 0x%lx not against global symbol"), 7805 bfd_get_filename (abfd), (unsigned long) rel->r_offset); 7806 bfd_set_error (bfd_error_bad_value); 7807 return false; 7808 } 7809 /* Fall through. */ 7810 7811 case R_MIPS_CALL_HI16: 7812 case R_MIPS_CALL_LO16: 7813 if (h != NULL) 7814 { 7815 /* This symbol requires a global offset table entry. */ 7816 if (!mips_elf_record_global_got_symbol (h, info, g)) 7817 return false; 7818 7819 /* We need a stub, not a plt entry for the undefined 7820 function. But we record it as if it needs plt. See 7821 elf_adjust_dynamic_symbol in elflink.h. */ 7822 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; 7823 h->type = STT_FUNC; 7824 } 7825 break; 7826 7827 case R_MIPS_GOT16: 7828 case R_MIPS_GOT_HI16: 7829 case R_MIPS_GOT_LO16: 7830 case R_MIPS_GOT_DISP: 7831 /* This symbol requires a global offset table entry. */ 7832 if (h && !mips_elf_record_global_got_symbol (h, info, g)) 7833 return false; 7834 break; 7835 7836 case R_MIPS_32: 7837 case R_MIPS_REL32: 7838 case R_MIPS_64: 7839 if ((info->shared || h != NULL) 7840 && (sec->flags & SEC_ALLOC) != 0) 7841 { 7842 if (sreloc == NULL) 7843 { 7844 const char *name = MIPS_ELF_REL_DYN_SECTION_NAME (dynobj); 7845 7846 sreloc = bfd_get_section_by_name (dynobj, name); 7847 if (sreloc == NULL) 7848 { 7849 sreloc = bfd_make_section (dynobj, name); 7850 if (sreloc == NULL 7851 || ! bfd_set_section_flags (dynobj, sreloc, 7852 (SEC_ALLOC 7853 | SEC_LOAD 7854 | SEC_HAS_CONTENTS 7855 | SEC_IN_MEMORY 7856 | SEC_LINKER_CREATED 7857 | SEC_READONLY)) 7858 || ! bfd_set_section_alignment (dynobj, sreloc, 7859 4)) 7860 return false; 7861 } 7862 } 7863 if (info->shared) 7864 /* When creating a shared object, we must copy these 7865 reloc types into the output file as R_MIPS_REL32 7866 relocs. We make room for this reloc in the 7867 .rel.dyn reloc section. */ 7868 mips_elf_allocate_dynamic_relocations (dynobj, 1); 7869 else 7870 { 7871 struct mips_elf_link_hash_entry *hmips; 7872 7873 /* We only need to copy this reloc if the symbol is 7874 defined in a dynamic object. */ 7875 hmips = (struct mips_elf_link_hash_entry *) h; 7876 ++hmips->possibly_dynamic_relocs; 7877 } 7878 7879 /* Even though we don't directly need a GOT entry for 7880 this symbol, a symbol must have a dynamic symbol 7881 table index greater that DT_MIPS_GOTSYM if there are 7882 dynamic relocations against it. */ 7883 if (h != NULL 7884 && !mips_elf_record_global_got_symbol (h, info, g)) 7885 return false; 7886 } 7887 7888 if (SGI_COMPAT (abfd)) 7889 mips_elf_hash_table (info)->compact_rel_size += 7890 sizeof (Elf32_External_crinfo); 7891 break; 7892 7893 case R_MIPS_26: 7894 case R_MIPS_GPREL16: 7895 case R_MIPS_LITERAL: 7896 case R_MIPS_GPREL32: 7897 if (SGI_COMPAT (abfd)) 7898 mips_elf_hash_table (info)->compact_rel_size += 7899 sizeof (Elf32_External_crinfo); 7900 break; 7901 7902 /* This relocation describes the C++ object vtable hierarchy. 7903 Reconstruct it for later use during GC. */ 7904 case R_MIPS_GNU_VTINHERIT: 7905 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 7906 return false; 7907 break; 7908 7909 /* This relocation describes which C++ vtable entries are actually 7910 used. Record for later use during GC. */ 7911 case R_MIPS_GNU_VTENTRY: 7912 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_offset)) 7913 return false; 7914 break; 7915 7916 default: 7917 break; 7918 } 7919 7920 /* We must not create a stub for a symbol that has relocations 7921 related to taking the function's address. */ 7922 switch (r_type) 7923 { 7924 default: 7925 if (h != NULL) 7926 { 7927 struct mips_elf_link_hash_entry *mh; 7928 7929 mh = (struct mips_elf_link_hash_entry *) h; 7930 mh->no_fn_stub = true; 7931 } 7932 break; 7933 case R_MIPS_CALL16: 7934 case R_MIPS_CALL_HI16: 7935 case R_MIPS_CALL_LO16: 7936 break; 7937 } 7938 7939 /* If this reloc is not a 16 bit call, and it has a global 7940 symbol, then we will need the fn_stub if there is one. 7941 References from a stub section do not count. */ 7942 if (h != NULL 7943 && r_type != R_MIPS16_26 7944 && strncmp (bfd_get_section_name (abfd, sec), FN_STUB, 7945 sizeof FN_STUB - 1) != 0 7946 && strncmp (bfd_get_section_name (abfd, sec), CALL_STUB, 7947 sizeof CALL_STUB - 1) != 0 7948 && strncmp (bfd_get_section_name (abfd, sec), CALL_FP_STUB, 7949 sizeof CALL_FP_STUB - 1) != 0) 7950 { 7951 struct mips_elf_link_hash_entry *mh; 7952 7953 mh = (struct mips_elf_link_hash_entry *) h; 7954 mh->need_fn_stub = true; 7955 } 7956 } 7957 7958 return true; 7959 } 7960 7961 /* Return the section that should be marked against GC for a given 7962 relocation. */ 7963 7964 asection * 7965 _bfd_mips_elf_gc_mark_hook (abfd, info, rel, h, sym) 7966 bfd *abfd; 7967 struct bfd_link_info *info ATTRIBUTE_UNUSED; 7968 Elf_Internal_Rela *rel; 7969 struct elf_link_hash_entry *h; 7970 Elf_Internal_Sym *sym; 7971 { 7972 /* ??? Do mips16 stub sections need to be handled special? */ 7973 7974 if (h != NULL) 7975 { 7976 switch (ELF32_R_TYPE (rel->r_info)) 7977 { 7978 case R_MIPS_GNU_VTINHERIT: 7979 case R_MIPS_GNU_VTENTRY: 7980 break; 7981 7982 default: 7983 switch (h->root.type) 7984 { 7985 case bfd_link_hash_defined: 7986 case bfd_link_hash_defweak: 7987 return h->root.u.def.section; 7988 7989 case bfd_link_hash_common: 7990 return h->root.u.c.p->section; 7991 7992 default: 7993 break; 7994 } 7995 } 7996 } 7997 else 7998 { 7999 if (!(elf_bad_symtab (abfd) 8000 && ELF_ST_BIND (sym->st_info) != STB_LOCAL) 8001 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE) 8002 && sym->st_shndx != SHN_COMMON)) 8003 { 8004 return bfd_section_from_elf_index (abfd, sym->st_shndx); 8005 } 8006 } 8007 8008 return NULL; 8009 } 8010 8011 /* Update the got entry reference counts for the section being removed. */ 8012 8013 boolean 8014 _bfd_mips_elf_gc_sweep_hook (abfd, info, sec, relocs) 8015 bfd *abfd ATTRIBUTE_UNUSED; 8016 struct bfd_link_info *info ATTRIBUTE_UNUSED; 8017 asection *sec ATTRIBUTE_UNUSED; 8018 const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED; 8019 { 8020 #if 0 8021 Elf_Internal_Shdr *symtab_hdr; 8022 struct elf_link_hash_entry **sym_hashes; 8023 bfd_signed_vma *local_got_refcounts; 8024 const Elf_Internal_Rela *rel, *relend; 8025 unsigned long r_symndx; 8026 struct elf_link_hash_entry *h; 8027 8028 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 8029 sym_hashes = elf_sym_hashes (abfd); 8030 local_got_refcounts = elf_local_got_refcounts (abfd); 8031 8032 relend = relocs + sec->reloc_count; 8033 for (rel = relocs; rel < relend; rel++) 8034 switch (ELF32_R_TYPE (rel->r_info)) 8035 { 8036 case R_MIPS_GOT16: 8037 case R_MIPS_CALL16: 8038 case R_MIPS_CALL_HI16: 8039 case R_MIPS_CALL_LO16: 8040 case R_MIPS_GOT_HI16: 8041 case R_MIPS_GOT_LO16: 8042 /* ??? It would seem that the existing MIPS code does no sort 8043 of reference counting or whatnot on its GOT and PLT entries, 8044 so it is not possible to garbage collect them at this time. */ 8045 break; 8046 8047 default: 8048 break; 8049 } 8050 #endif 8051 8052 return true; 8053 } 8054 8055 /* Copy data from a MIPS ELF indirect symbol to its direct symbol, 8056 hiding the old indirect symbol. Process additional relocation 8057 information. */ 8058 8059 void 8060 _bfd_mips_elf_copy_indirect_symbol (dir, ind) 8061 struct elf_link_hash_entry *dir, *ind; 8062 { 8063 struct mips_elf_link_hash_entry *dirmips, *indmips; 8064 8065 _bfd_elf_link_hash_copy_indirect (dir, ind); 8066 8067 dirmips = (struct mips_elf_link_hash_entry *) dir; 8068 indmips = (struct mips_elf_link_hash_entry *) ind; 8069 dirmips->possibly_dynamic_relocs += indmips->possibly_dynamic_relocs; 8070 if (dirmips->min_dyn_reloc_index == 0 8071 || (indmips->min_dyn_reloc_index != 0 8072 && indmips->min_dyn_reloc_index < dirmips->min_dyn_reloc_index)) 8073 dirmips->min_dyn_reloc_index = indmips->min_dyn_reloc_index; 8074 if (indmips->no_fn_stub) 8075 dirmips->no_fn_stub = true; 8076 } 8077 8078 /* Adjust a symbol defined by a dynamic object and referenced by a 8079 regular object. The current definition is in some section of the 8080 dynamic object, but we're not including those sections. We have to 8081 change the definition to something the rest of the link can 8082 understand. */ 8083 8084 boolean 8085 _bfd_mips_elf_adjust_dynamic_symbol (info, h) 8086 struct bfd_link_info *info; 8087 struct elf_link_hash_entry *h; 8088 { 8089 bfd *dynobj; 8090 struct mips_elf_link_hash_entry *hmips; 8091 asection *s; 8092 8093 dynobj = elf_hash_table (info)->dynobj; 8094 8095 /* Make sure we know what is going on here. */ 8096 BFD_ASSERT (dynobj != NULL 8097 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) 8098 || h->weakdef != NULL 8099 || ((h->elf_link_hash_flags 8100 & ELF_LINK_HASH_DEF_DYNAMIC) != 0 8101 && (h->elf_link_hash_flags 8102 & ELF_LINK_HASH_REF_REGULAR) != 0 8103 && (h->elf_link_hash_flags 8104 & ELF_LINK_HASH_DEF_REGULAR) == 0))); 8105 8106 /* If this symbol is defined in a dynamic object, we need to copy 8107 any R_MIPS_32 or R_MIPS_REL32 relocs against it into the output 8108 file. */ 8109 hmips = (struct mips_elf_link_hash_entry *) h; 8110 if (! info->relocateable 8111 && hmips->possibly_dynamic_relocs != 0 8112 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 8113 mips_elf_allocate_dynamic_relocations (dynobj, 8114 hmips->possibly_dynamic_relocs); 8115 8116 /* For a function, create a stub, if allowed. */ 8117 if (! hmips->no_fn_stub 8118 && (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) 8119 { 8120 if (! elf_hash_table (info)->dynamic_sections_created) 8121 return true; 8122 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->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 8128 { 8129 /* We need .stub section. */ 8130 s = bfd_get_section_by_name (dynobj, 8131 MIPS_ELF_STUB_SECTION_NAME (dynobj)); 8132 BFD_ASSERT (s != NULL); 8133 8134 h->root.u.def.section = s; 8135 h->root.u.def.value = s->_raw_size; 8136 8137 /* XXX Write this stub address somewhere. */ 8138 h->plt.offset = s->_raw_size; 8139 8140 /* Make room for this stub code. */ 8141 s->_raw_size += MIPS_FUNCTION_STUB_SIZE; 8142 8143 /* The last half word of the stub will be filled with the index 8144 of this symbol in .dynsym section. */ 8145 return true; 8146 } 8147 } 8148 else if ((h->type == STT_FUNC) 8149 && (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) == 0) 8150 { 8151 /* This will set the entry for this symbol in the GOT to 0, and 8152 the dynamic linker will take care of this. */ 8153 h->root.u.def.value = 0; 8154 return true; 8155 } 8156 8157 /* If this is a weak symbol, and there is a real definition, the 8158 processor independent code will have arranged for us to see the 8159 real definition first, and we can just use the same value. */ 8160 if (h->weakdef != NULL) 8161 { 8162 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined 8163 || h->weakdef->root.type == bfd_link_hash_defweak); 8164 h->root.u.def.section = h->weakdef->root.u.def.section; 8165 h->root.u.def.value = h->weakdef->root.u.def.value; 8166 return true; 8167 } 8168 8169 /* This is a reference to a symbol defined by a dynamic object which 8170 is not a function. */ 8171 8172 return true; 8173 } 8174 8175 /* This function is called after all the input files have been read, 8176 and the input sections have been assigned to output sections. We 8177 check for any mips16 stub sections that we can discard. */ 8178 8179 static boolean mips_elf_check_mips16_stubs 8180 PARAMS ((struct mips_elf_link_hash_entry *, PTR)); 8181 8182 boolean 8183 _bfd_mips_elf_always_size_sections (output_bfd, info) 8184 bfd *output_bfd; 8185 struct bfd_link_info *info; 8186 { 8187 asection *ri; 8188 8189 /* The .reginfo section has a fixed size. */ 8190 ri = bfd_get_section_by_name (output_bfd, ".reginfo"); 8191 if (ri != NULL) 8192 bfd_set_section_size (output_bfd, ri, sizeof (Elf32_External_RegInfo)); 8193 8194 if (info->relocateable 8195 || ! mips_elf_hash_table (info)->mips16_stubs_seen) 8196 return true; 8197 8198 mips_elf_link_hash_traverse (mips_elf_hash_table (info), 8199 mips_elf_check_mips16_stubs, 8200 (PTR) NULL); 8201 8202 return true; 8203 } 8204 8205 /* Check the mips16 stubs for a particular symbol, and see if we can 8206 discard them. */ 8207 8208 static boolean 8209 mips_elf_check_mips16_stubs (h, data) 8210 struct mips_elf_link_hash_entry *h; 8211 PTR data ATTRIBUTE_UNUSED; 8212 { 8213 if (h->fn_stub != NULL 8214 && ! h->need_fn_stub) 8215 { 8216 /* We don't need the fn_stub; the only references to this symbol 8217 are 16 bit calls. Clobber the size to 0 to prevent it from 8218 being included in the link. */ 8219 h->fn_stub->_raw_size = 0; 8220 h->fn_stub->_cooked_size = 0; 8221 h->fn_stub->flags &= ~SEC_RELOC; 8222 h->fn_stub->reloc_count = 0; 8223 h->fn_stub->flags |= SEC_EXCLUDE; 8224 } 8225 8226 if (h->call_stub != NULL 8227 && h->root.other == STO_MIPS16) 8228 { 8229 /* We don't need the call_stub; this is a 16 bit function, so 8230 calls from other 16 bit functions are OK. Clobber the size 8231 to 0 to prevent it from being included in the link. */ 8232 h->call_stub->_raw_size = 0; 8233 h->call_stub->_cooked_size = 0; 8234 h->call_stub->flags &= ~SEC_RELOC; 8235 h->call_stub->reloc_count = 0; 8236 h->call_stub->flags |= SEC_EXCLUDE; 8237 } 8238 8239 if (h->call_fp_stub != NULL 8240 && h->root.other == STO_MIPS16) 8241 { 8242 /* We don't need the call_stub; this is a 16 bit function, so 8243 calls from other 16 bit functions are OK. Clobber the size 8244 to 0 to prevent it from being included in the link. */ 8245 h->call_fp_stub->_raw_size = 0; 8246 h->call_fp_stub->_cooked_size = 0; 8247 h->call_fp_stub->flags &= ~SEC_RELOC; 8248 h->call_fp_stub->reloc_count = 0; 8249 h->call_fp_stub->flags |= SEC_EXCLUDE; 8250 } 8251 8252 return true; 8253 } 8254 8255 /* Set the sizes of the dynamic sections. */ 8256 8257 boolean 8258 _bfd_mips_elf_size_dynamic_sections (output_bfd, info) 8259 bfd *output_bfd; 8260 struct bfd_link_info *info; 8261 { 8262 bfd *dynobj; 8263 asection *s; 8264 boolean reltext; 8265 struct mips_got_info *g = NULL; 8266 8267 dynobj = elf_hash_table (info)->dynobj; 8268 BFD_ASSERT (dynobj != NULL); 8269 8270 if (elf_hash_table (info)->dynamic_sections_created) 8271 { 8272 /* Set the contents of the .interp section to the interpreter. */ 8273 if (! info->shared) 8274 { 8275 s = bfd_get_section_by_name (dynobj, ".interp"); 8276 BFD_ASSERT (s != NULL); 8277 s->_raw_size 8278 = strlen (ELF_DYNAMIC_INTERPRETER (output_bfd)) + 1; 8279 s->contents 8280 = (bfd_byte *) ELF_DYNAMIC_INTERPRETER (output_bfd); 8281 } 8282 } 8283 8284 /* The check_relocs and adjust_dynamic_symbol entry points have 8285 determined the sizes of the various dynamic sections. Allocate 8286 memory for them. */ 8287 reltext = false; 8288 for (s = dynobj->sections; s != NULL; s = s->next) 8289 { 8290 const char *name; 8291 boolean strip; 8292 8293 /* It's OK to base decisions on the section name, because none 8294 of the dynobj section names depend upon the input files. */ 8295 name = bfd_get_section_name (dynobj, s); 8296 8297 if ((s->flags & SEC_LINKER_CREATED) == 0) 8298 continue; 8299 8300 strip = false; 8301 8302 if (strncmp (name, ".rel", 4) == 0) 8303 { 8304 if (s->_raw_size == 0) 8305 { 8306 /* We only strip the section if the output section name 8307 has the same name. Otherwise, there might be several 8308 input sections for this output section. FIXME: This 8309 code is probably not needed these days anyhow, since 8310 the linker now does not create empty output sections. */ 8311 if (s->output_section != NULL 8312 && strcmp (name, 8313 bfd_get_section_name (s->output_section->owner, 8314 s->output_section)) == 0) 8315 strip = true; 8316 } 8317 else 8318 { 8319 const char *outname; 8320 asection *target; 8321 8322 /* If this relocation section applies to a read only 8323 section, then we probably need a DT_TEXTREL entry. 8324 If the relocation section is .rel.dyn, we always 8325 assert a DT_TEXTREL entry rather than testing whether 8326 there exists a relocation to a read only section or 8327 not. */ 8328 outname = bfd_get_section_name (output_bfd, 8329 s->output_section); 8330 target = bfd_get_section_by_name (output_bfd, outname + 4); 8331 if ((target != NULL 8332 && (target->flags & SEC_READONLY) != 0 8333 && (target->flags & SEC_ALLOC) != 0) 8334 || strcmp (outname, 8335 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd)) == 0) 8336 reltext = true; 8337 8338 /* We use the reloc_count field as a counter if we need 8339 to copy relocs into the output file. */ 8340 if (strcmp (name, 8341 MIPS_ELF_REL_DYN_SECTION_NAME (output_bfd)) != 0) 8342 s->reloc_count = 0; 8343 } 8344 } 8345 else if (strncmp (name, ".got", 4) == 0) 8346 { 8347 int i; 8348 bfd_size_type loadable_size = 0; 8349 bfd_size_type local_gotno; 8350 bfd *sub; 8351 8352 BFD_ASSERT (elf_section_data (s) != NULL); 8353 g = (struct mips_got_info *) elf_section_data (s)->tdata; 8354 BFD_ASSERT (g != NULL); 8355 8356 /* Calculate the total loadable size of the output. That 8357 will give us the maximum number of GOT_PAGE entries 8358 required. */ 8359 for (sub = info->input_bfds; sub; sub = sub->link_next) 8360 { 8361 asection *subsection; 8362 8363 for (subsection = sub->sections; 8364 subsection; 8365 subsection = subsection->next) 8366 { 8367 if ((subsection->flags & SEC_ALLOC) == 0) 8368 continue; 8369 loadable_size += (subsection->_raw_size + 0xf) & ~0xf; 8370 } 8371 } 8372 loadable_size += MIPS_FUNCTION_STUB_SIZE; 8373 8374 /* Assume there are two loadable segments consisting of 8375 contiguous sections. Is 5 enough? */ 8376 local_gotno = (loadable_size >> 16) + 5; 8377 if (IRIX_COMPAT (output_bfd) == ict_irix6) 8378 /* It's possible we will need GOT_PAGE entries as well as 8379 GOT16 entries. Often, these will be able to share GOT 8380 entries, but not always. */ 8381 local_gotno *= 2; 8382 8383 g->local_gotno += local_gotno; 8384 s->_raw_size += local_gotno * MIPS_ELF_GOT_SIZE (dynobj); 8385 8386 /* There has to be a global GOT entry for every symbol with 8387 a dynamic symbol table index of DT_MIPS_GOTSYM or 8388 higher. Therefore, it make sense to put those symbols 8389 that need GOT entries at the end of the symbol table. We 8390 do that here. */ 8391 if (!mips_elf_sort_hash_table (info, 1)) 8392 return false; 8393 8394 if (g->global_gotsym != NULL) 8395 i = elf_hash_table (info)->dynsymcount - g->global_gotsym->dynindx; 8396 else 8397 /* If there are no global symbols, or none requiring 8398 relocations, then GLOBAL_GOTSYM will be NULL. */ 8399 i = 0; 8400 g->global_gotno = i; 8401 s->_raw_size += i * MIPS_ELF_GOT_SIZE (dynobj); 8402 } 8403 else if (strcmp (name, MIPS_ELF_STUB_SECTION_NAME (output_bfd)) == 0) 8404 { 8405 /* Irix rld assumes that the function stub isn't at the end 8406 of .text section. So put a dummy. XXX */ 8407 s->_raw_size += MIPS_FUNCTION_STUB_SIZE; 8408 } 8409 else if (! info->shared 8410 && ! mips_elf_hash_table (info)->use_rld_obj_head 8411 && strncmp (name, ".rld_map", 8) == 0) 8412 { 8413 /* We add a room for __rld_map. It will be filled in by the 8414 rtld to contain a pointer to the _r_debug structure. */ 8415 s->_raw_size += 4; 8416 } 8417 else if (SGI_COMPAT (output_bfd) 8418 && strncmp (name, ".compact_rel", 12) == 0) 8419 s->_raw_size += mips_elf_hash_table (info)->compact_rel_size; 8420 else if (strcmp (name, MIPS_ELF_MSYM_SECTION_NAME (output_bfd)) 8421 == 0) 8422 s->_raw_size = (sizeof (Elf32_External_Msym) 8423 * (elf_hash_table (info)->dynsymcount 8424 + bfd_count_sections (output_bfd))); 8425 else if (strncmp (name, ".init", 5) != 0) 8426 { 8427 /* It's not one of our sections, so don't allocate space. */ 8428 continue; 8429 } 8430 8431 if (strip) 8432 { 8433 _bfd_strip_section_from_output (info, s); 8434 continue; 8435 } 8436 8437 /* Allocate memory for the section contents. */ 8438 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size); 8439 if (s->contents == NULL && s->_raw_size != 0) 8440 { 8441 bfd_set_error (bfd_error_no_memory); 8442 return false; 8443 } 8444 } 8445 8446 if (elf_hash_table (info)->dynamic_sections_created) 8447 { 8448 /* Add some entries to the .dynamic section. We fill in the 8449 values later, in elf_mips_finish_dynamic_sections, but we 8450 must add the entries now so that we get the correct size for 8451 the .dynamic section. The DT_DEBUG entry is filled in by the 8452 dynamic linker and used by the debugger. */ 8453 if (! info->shared) 8454 { 8455 /* SGI object has the equivalence of DT_DEBUG in the 8456 DT_MIPS_RLD_MAP entry. */ 8457 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_RLD_MAP, 0)) 8458 return false; 8459 if (!SGI_COMPAT (output_bfd)) 8460 { 8461 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0)) 8462 return false; 8463 } 8464 } 8465 else 8466 { 8467 /* Shared libraries on traditional mips have DT_DEBUG. */ 8468 if (!SGI_COMPAT (output_bfd)) 8469 { 8470 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_DEBUG, 0)) 8471 return false; 8472 } 8473 } 8474 if (reltext && SGI_COMPAT (output_bfd)) 8475 { 8476 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_TEXTREL, 0)) 8477 return false; 8478 info->flags |= DF_TEXTREL; 8479 } 8480 8481 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_PLTGOT, 0)) 8482 return false; 8483 8484 if (bfd_get_section_by_name (dynobj, 8485 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj))) 8486 { 8487 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_REL, 0)) 8488 return false; 8489 8490 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELSZ, 0)) 8491 return false; 8492 8493 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_RELENT, 0)) 8494 return false; 8495 } 8496 8497 if (SGI_COMPAT (output_bfd)) 8498 { 8499 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_CONFLICTNO, 0)) 8500 return false; 8501 } 8502 8503 if (SGI_COMPAT (output_bfd)) 8504 { 8505 if (!MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LIBLISTNO, 0)) 8506 return false; 8507 } 8508 8509 if (bfd_get_section_by_name (dynobj, ".conflict") != NULL) 8510 { 8511 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_CONFLICT, 0)) 8512 return false; 8513 8514 s = bfd_get_section_by_name (dynobj, ".liblist"); 8515 BFD_ASSERT (s != NULL); 8516 8517 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LIBLIST, 0)) 8518 return false; 8519 } 8520 8521 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_RLD_VERSION, 0)) 8522 return false; 8523 8524 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_FLAGS, 0)) 8525 return false; 8526 8527 #if 0 8528 /* Time stamps in executable files are a bad idea. */ 8529 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_TIME_STAMP, 0)) 8530 return false; 8531 #endif 8532 8533 #if 0 /* FIXME */ 8534 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_ICHECKSUM, 0)) 8535 return false; 8536 #endif 8537 8538 #if 0 /* FIXME */ 8539 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_IVERSION, 0)) 8540 return false; 8541 #endif 8542 8543 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_BASE_ADDRESS, 0)) 8544 return false; 8545 8546 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_LOCAL_GOTNO, 0)) 8547 return false; 8548 8549 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_SYMTABNO, 0)) 8550 return false; 8551 8552 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_UNREFEXTNO, 0)) 8553 return false; 8554 8555 if (! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_GOTSYM, 0)) 8556 return false; 8557 8558 if (IRIX_COMPAT (dynobj) == ict_irix5 8559 && ! MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_HIPAGENO, 0)) 8560 return false; 8561 8562 if (IRIX_COMPAT (dynobj) == ict_irix6 8563 && (bfd_get_section_by_name 8564 (dynobj, MIPS_ELF_OPTIONS_SECTION_NAME (dynobj))) 8565 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_OPTIONS, 0)) 8566 return false; 8567 8568 if (bfd_get_section_by_name (dynobj, 8569 MIPS_ELF_MSYM_SECTION_NAME (dynobj)) 8570 && !MIPS_ELF_ADD_DYNAMIC_ENTRY (info, DT_MIPS_MSYM, 0)) 8571 return false; 8572 } 8573 8574 return true; 8575 } 8576 8577 /* If NAME is one of the special IRIX6 symbols defined by the linker, 8578 adjust it appropriately now. */ 8579 8580 static void 8581 mips_elf_irix6_finish_dynamic_symbol (abfd, name, sym) 8582 bfd *abfd ATTRIBUTE_UNUSED; 8583 const char *name; 8584 Elf_Internal_Sym *sym; 8585 { 8586 /* The linker script takes care of providing names and values for 8587 these, but we must place them into the right sections. */ 8588 static const char* const text_section_symbols[] = { 8589 "_ftext", 8590 "_etext", 8591 "__dso_displacement", 8592 "__elf_header", 8593 "__program_header_table", 8594 NULL 8595 }; 8596 8597 static const char* const data_section_symbols[] = { 8598 "_fdata", 8599 "_edata", 8600 "_end", 8601 "_fbss", 8602 NULL 8603 }; 8604 8605 const char* const *p; 8606 int i; 8607 8608 for (i = 0; i < 2; ++i) 8609 for (p = (i == 0) ? text_section_symbols : data_section_symbols; 8610 *p; 8611 ++p) 8612 if (strcmp (*p, name) == 0) 8613 { 8614 /* All of these symbols are given type STT_SECTION by the 8615 IRIX6 linker. */ 8616 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION); 8617 8618 /* The IRIX linker puts these symbols in special sections. */ 8619 if (i == 0) 8620 sym->st_shndx = SHN_MIPS_TEXT; 8621 else 8622 sym->st_shndx = SHN_MIPS_DATA; 8623 8624 break; 8625 } 8626 } 8627 8628 /* Finish up dynamic symbol handling. We set the contents of various 8629 dynamic sections here. */ 8630 8631 boolean 8632 _bfd_mips_elf_finish_dynamic_symbol (output_bfd, info, h, sym) 8633 bfd *output_bfd; 8634 struct bfd_link_info *info; 8635 struct elf_link_hash_entry *h; 8636 Elf_Internal_Sym *sym; 8637 { 8638 bfd *dynobj; 8639 bfd_vma gval; 8640 asection *sgot; 8641 asection *smsym; 8642 struct mips_got_info *g; 8643 const char *name; 8644 struct mips_elf_link_hash_entry *mh; 8645 8646 dynobj = elf_hash_table (info)->dynobj; 8647 gval = sym->st_value; 8648 mh = (struct mips_elf_link_hash_entry *) h; 8649 8650 if (h->plt.offset != (bfd_vma) -1) 8651 { 8652 asection *s; 8653 bfd_byte *p; 8654 bfd_byte stub[MIPS_FUNCTION_STUB_SIZE]; 8655 8656 /* This symbol has a stub. Set it up. */ 8657 8658 BFD_ASSERT (h->dynindx != -1); 8659 8660 s = bfd_get_section_by_name (dynobj, 8661 MIPS_ELF_STUB_SECTION_NAME (dynobj)); 8662 BFD_ASSERT (s != NULL); 8663 8664 /* Fill the stub. */ 8665 p = stub; 8666 bfd_put_32 (output_bfd, STUB_LW (output_bfd), p); 8667 p += 4; 8668 bfd_put_32 (output_bfd, STUB_MOVE (output_bfd), p); 8669 p += 4; 8670 8671 /* FIXME: Can h->dynindex be more than 64K? */ 8672 if (h->dynindx & 0xffff0000) 8673 return false; 8674 8675 bfd_put_32 (output_bfd, STUB_JALR, p); 8676 p += 4; 8677 bfd_put_32 (output_bfd, STUB_LI16 (output_bfd) + h->dynindx, p); 8678 8679 BFD_ASSERT (h->plt.offset <= s->_raw_size); 8680 memcpy (s->contents + h->plt.offset, stub, MIPS_FUNCTION_STUB_SIZE); 8681 8682 /* Mark the symbol as undefined. plt.offset != -1 occurs 8683 only for the referenced symbol. */ 8684 sym->st_shndx = SHN_UNDEF; 8685 8686 /* The run-time linker uses the st_value field of the symbol 8687 to reset the global offset table entry for this external 8688 to its stub address when unlinking a shared object. */ 8689 gval = s->output_section->vma + s->output_offset + h->plt.offset; 8690 sym->st_value = gval; 8691 } 8692 8693 BFD_ASSERT (h->dynindx != -1 8694 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0); 8695 8696 sgot = mips_elf_got_section (dynobj); 8697 BFD_ASSERT (sgot != NULL); 8698 BFD_ASSERT (elf_section_data (sgot) != NULL); 8699 g = (struct mips_got_info *) elf_section_data (sgot)->tdata; 8700 BFD_ASSERT (g != NULL); 8701 8702 /* Run through the global symbol table, creating GOT entries for all 8703 the symbols that need them. */ 8704 if (g->global_gotsym != NULL 8705 && h->dynindx >= g->global_gotsym->dynindx) 8706 { 8707 bfd_vma offset; 8708 bfd_vma value; 8709 8710 if (sym->st_value) 8711 value = sym->st_value; 8712 else 8713 { 8714 /* For an entity defined in a shared object, this will be 8715 NULL. (For functions in shared objects for 8716 which we have created stubs, ST_VALUE will be non-NULL. 8717 That's because such the functions are now no longer defined 8718 in a shared object.) */ 8719 8720 if (info->shared && h->root.type == bfd_link_hash_undefined) 8721 value = 0; 8722 else 8723 value = h->root.u.def.value; 8724 } 8725 offset = mips_elf_global_got_index (dynobj, h); 8726 MIPS_ELF_PUT_WORD (output_bfd, value, sgot->contents + offset); 8727 } 8728 8729 /* Create a .msym entry, if appropriate. */ 8730 smsym = bfd_get_section_by_name (dynobj, 8731 MIPS_ELF_MSYM_SECTION_NAME (dynobj)); 8732 if (smsym) 8733 { 8734 Elf32_Internal_Msym msym; 8735 8736 msym.ms_hash_value = bfd_elf_hash (h->root.root.string); 8737 /* It is undocumented what the `1' indicates, but IRIX6 uses 8738 this value. */ 8739 msym.ms_info = ELF32_MS_INFO (mh->min_dyn_reloc_index, 1); 8740 bfd_mips_elf_swap_msym_out 8741 (dynobj, &msym, 8742 ((Elf32_External_Msym *) smsym->contents) + h->dynindx); 8743 } 8744 8745 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ 8746 name = h->root.root.string; 8747 if (strcmp (name, "_DYNAMIC") == 0 8748 || strcmp (name, "_GLOBAL_OFFSET_TABLE_") == 0) 8749 sym->st_shndx = SHN_ABS; 8750 else if (strcmp (name, "_DYNAMIC_LINK") == 0 8751 || strcmp (name, "_DYNAMIC_LINKING") == 0) 8752 { 8753 sym->st_shndx = SHN_ABS; 8754 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION); 8755 sym->st_value = 1; 8756 } 8757 else if (strcmp (name, "_gp_disp") == 0) 8758 { 8759 sym->st_shndx = SHN_ABS; 8760 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION); 8761 sym->st_value = elf_gp (output_bfd); 8762 } 8763 else if (SGI_COMPAT (output_bfd)) 8764 { 8765 if (strcmp (name, mips_elf_dynsym_rtproc_names[0]) == 0 8766 || strcmp (name, mips_elf_dynsym_rtproc_names[1]) == 0) 8767 { 8768 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION); 8769 sym->st_other = STO_PROTECTED; 8770 sym->st_value = 0; 8771 sym->st_shndx = SHN_MIPS_DATA; 8772 } 8773 else if (strcmp (name, mips_elf_dynsym_rtproc_names[2]) == 0) 8774 { 8775 sym->st_info = ELF_ST_INFO (STB_GLOBAL, STT_SECTION); 8776 sym->st_other = STO_PROTECTED; 8777 sym->st_value = mips_elf_hash_table (info)->procedure_count; 8778 sym->st_shndx = SHN_ABS; 8779 } 8780 else if (sym->st_shndx != SHN_UNDEF && sym->st_shndx != SHN_ABS) 8781 { 8782 if (h->type == STT_FUNC) 8783 sym->st_shndx = SHN_MIPS_TEXT; 8784 else if (h->type == STT_OBJECT) 8785 sym->st_shndx = SHN_MIPS_DATA; 8786 } 8787 } 8788 8789 /* Handle the IRIX6-specific symbols. */ 8790 if (IRIX_COMPAT (output_bfd) == ict_irix6) 8791 mips_elf_irix6_finish_dynamic_symbol (output_bfd, name, sym); 8792 8793 if (! info->shared) 8794 { 8795 if (! mips_elf_hash_table (info)->use_rld_obj_head 8796 && (strcmp (name, "__rld_map") == 0 8797 || strcmp (name, "__RLD_MAP") == 0)) 8798 { 8799 asection *s = bfd_get_section_by_name (dynobj, ".rld_map"); 8800 BFD_ASSERT (s != NULL); 8801 sym->st_value = s->output_section->vma + s->output_offset; 8802 bfd_put_32 (output_bfd, (bfd_vma) 0, s->contents); 8803 if (mips_elf_hash_table (info)->rld_value == 0) 8804 mips_elf_hash_table (info)->rld_value = sym->st_value; 8805 } 8806 else if (mips_elf_hash_table (info)->use_rld_obj_head 8807 && strcmp (name, "__rld_obj_head") == 0) 8808 { 8809 /* IRIX6 does not use a .rld_map section. */ 8810 if (IRIX_COMPAT (output_bfd) == ict_irix5 8811 || IRIX_COMPAT (output_bfd) == ict_none) 8812 BFD_ASSERT (bfd_get_section_by_name (dynobj, ".rld_map") 8813 != NULL); 8814 mips_elf_hash_table (info)->rld_value = sym->st_value; 8815 } 8816 } 8817 8818 /* If this is a mips16 symbol, force the value to be even. */ 8819 if (sym->st_other == STO_MIPS16 8820 && (sym->st_value & 1) != 0) 8821 --sym->st_value; 8822 8823 return true; 8824 } 8825 8826 /* Finish up the dynamic sections. */ 8827 8828 boolean 8829 _bfd_mips_elf_finish_dynamic_sections (output_bfd, info) 8830 bfd *output_bfd; 8831 struct bfd_link_info *info; 8832 { 8833 bfd *dynobj; 8834 asection *sdyn; 8835 asection *sgot; 8836 struct mips_got_info *g; 8837 8838 dynobj = elf_hash_table (info)->dynobj; 8839 8840 sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); 8841 8842 sgot = mips_elf_got_section (dynobj); 8843 if (sgot == NULL) 8844 g = NULL; 8845 else 8846 { 8847 BFD_ASSERT (elf_section_data (sgot) != NULL); 8848 g = (struct mips_got_info *) elf_section_data (sgot)->tdata; 8849 BFD_ASSERT (g != NULL); 8850 } 8851 8852 if (elf_hash_table (info)->dynamic_sections_created) 8853 { 8854 bfd_byte *b; 8855 8856 BFD_ASSERT (sdyn != NULL); 8857 BFD_ASSERT (g != NULL); 8858 8859 for (b = sdyn->contents; 8860 b < sdyn->contents + sdyn->_raw_size; 8861 b += MIPS_ELF_DYN_SIZE (dynobj)) 8862 { 8863 Elf_Internal_Dyn dyn; 8864 const char *name; 8865 size_t elemsize; 8866 asection *s; 8867 boolean swap_out_p; 8868 8869 /* Read in the current dynamic entry. */ 8870 (*get_elf_backend_data (dynobj)->s->swap_dyn_in) (dynobj, b, &dyn); 8871 8872 /* Assume that we're going to modify it and write it out. */ 8873 swap_out_p = true; 8874 8875 switch (dyn.d_tag) 8876 { 8877 case DT_RELENT: 8878 s = (bfd_get_section_by_name 8879 (dynobj, 8880 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj))); 8881 BFD_ASSERT (s != NULL); 8882 dyn.d_un.d_val = MIPS_ELF_REL_SIZE (dynobj); 8883 break; 8884 8885 case DT_STRSZ: 8886 /* Rewrite DT_STRSZ. */ 8887 dyn.d_un.d_val = 8888 _bfd_stringtab_size (elf_hash_table (info)->dynstr); 8889 break; 8890 8891 case DT_PLTGOT: 8892 name = ".got"; 8893 goto get_vma; 8894 case DT_MIPS_CONFLICT: 8895 name = ".conflict"; 8896 goto get_vma; 8897 case DT_MIPS_LIBLIST: 8898 name = ".liblist"; 8899 get_vma: 8900 s = bfd_get_section_by_name (output_bfd, name); 8901 BFD_ASSERT (s != NULL); 8902 dyn.d_un.d_ptr = s->vma; 8903 break; 8904 8905 case DT_MIPS_RLD_VERSION: 8906 dyn.d_un.d_val = 1; /* XXX */ 8907 break; 8908 8909 case DT_MIPS_FLAGS: 8910 dyn.d_un.d_val = RHF_NOTPOT; /* XXX */ 8911 break; 8912 8913 case DT_MIPS_CONFLICTNO: 8914 name = ".conflict"; 8915 elemsize = sizeof (Elf32_Conflict); 8916 goto set_elemno; 8917 8918 case DT_MIPS_LIBLISTNO: 8919 name = ".liblist"; 8920 elemsize = sizeof (Elf32_Lib); 8921 set_elemno: 8922 s = bfd_get_section_by_name (output_bfd, name); 8923 if (s != NULL) 8924 { 8925 if (s->_cooked_size != 0) 8926 dyn.d_un.d_val = s->_cooked_size / elemsize; 8927 else 8928 dyn.d_un.d_val = s->_raw_size / elemsize; 8929 } 8930 else 8931 dyn.d_un.d_val = 0; 8932 break; 8933 8934 case DT_MIPS_TIME_STAMP: 8935 time ((time_t *) &dyn.d_un.d_val); 8936 break; 8937 8938 case DT_MIPS_ICHECKSUM: 8939 /* XXX FIXME: */ 8940 swap_out_p = false; 8941 break; 8942 8943 case DT_MIPS_IVERSION: 8944 /* XXX FIXME: */ 8945 swap_out_p = false; 8946 break; 8947 8948 case DT_MIPS_BASE_ADDRESS: 8949 s = output_bfd->sections; 8950 BFD_ASSERT (s != NULL); 8951 dyn.d_un.d_ptr = s->vma & ~(0xffff); 8952 break; 8953 8954 case DT_MIPS_LOCAL_GOTNO: 8955 dyn.d_un.d_val = g->local_gotno; 8956 break; 8957 8958 case DT_MIPS_UNREFEXTNO: 8959 /* The index into the dynamic symbol table which is the 8960 entry of the first external symbol that is not 8961 referenced within the same object. */ 8962 dyn.d_un.d_val = bfd_count_sections (output_bfd) + 1; 8963 break; 8964 8965 case DT_MIPS_GOTSYM: 8966 if (g->global_gotsym) 8967 { 8968 dyn.d_un.d_val = g->global_gotsym->dynindx; 8969 break; 8970 } 8971 /* In case if we don't have global got symbols we default 8972 to setting DT_MIPS_GOTSYM to the same value as 8973 DT_MIPS_SYMTABNO, so we just fall through. */ 8974 8975 case DT_MIPS_SYMTABNO: 8976 name = ".dynsym"; 8977 elemsize = MIPS_ELF_SYM_SIZE (output_bfd); 8978 s = bfd_get_section_by_name (output_bfd, name); 8979 BFD_ASSERT (s != NULL); 8980 8981 if (s->_cooked_size != 0) 8982 dyn.d_un.d_val = s->_cooked_size / elemsize; 8983 else 8984 dyn.d_un.d_val = s->_raw_size / elemsize; 8985 break; 8986 8987 case DT_MIPS_HIPAGENO: 8988 dyn.d_un.d_val = g->local_gotno - MIPS_RESERVED_GOTNO; 8989 break; 8990 8991 case DT_MIPS_RLD_MAP: 8992 dyn.d_un.d_ptr = mips_elf_hash_table (info)->rld_value; 8993 break; 8994 8995 case DT_MIPS_OPTIONS: 8996 s = (bfd_get_section_by_name 8997 (output_bfd, MIPS_ELF_OPTIONS_SECTION_NAME (output_bfd))); 8998 dyn.d_un.d_ptr = s->vma; 8999 break; 9000 9001 case DT_MIPS_MSYM: 9002 s = (bfd_get_section_by_name 9003 (output_bfd, MIPS_ELF_MSYM_SECTION_NAME (output_bfd))); 9004 dyn.d_un.d_ptr = s->vma; 9005 break; 9006 9007 default: 9008 swap_out_p = false; 9009 break; 9010 } 9011 9012 if (swap_out_p) 9013 (*get_elf_backend_data (dynobj)->s->swap_dyn_out) 9014 (dynobj, &dyn, b); 9015 } 9016 } 9017 9018 /* The first entry of the global offset table will be filled at 9019 runtime. The second entry will be used by some runtime loaders. 9020 This isn't the case of Irix rld. */ 9021 if (sgot != NULL && sgot->_raw_size > 0) 9022 { 9023 MIPS_ELF_PUT_WORD (output_bfd, (bfd_vma) 0, sgot->contents); 9024 MIPS_ELF_PUT_WORD (output_bfd, (bfd_vma) 0x80000000, 9025 sgot->contents + MIPS_ELF_GOT_SIZE (output_bfd)); 9026 } 9027 9028 if (sgot != NULL) 9029 elf_section_data (sgot->output_section)->this_hdr.sh_entsize 9030 = MIPS_ELF_GOT_SIZE (output_bfd); 9031 9032 { 9033 asection *smsym; 9034 asection *s; 9035 Elf32_compact_rel cpt; 9036 9037 /* ??? The section symbols for the output sections were set up in 9038 _bfd_elf_final_link. SGI sets the STT_NOTYPE attribute for these 9039 symbols. Should we do so? */ 9040 9041 smsym = bfd_get_section_by_name (dynobj, 9042 MIPS_ELF_MSYM_SECTION_NAME (dynobj)); 9043 if (smsym != NULL) 9044 { 9045 Elf32_Internal_Msym msym; 9046 9047 msym.ms_hash_value = 0; 9048 msym.ms_info = ELF32_MS_INFO (0, 1); 9049 9050 for (s = output_bfd->sections; s != NULL; s = s->next) 9051 { 9052 long dynindx = elf_section_data (s)->dynindx; 9053 9054 bfd_mips_elf_swap_msym_out 9055 (output_bfd, &msym, 9056 (((Elf32_External_Msym *) smsym->contents) 9057 + dynindx)); 9058 } 9059 } 9060 9061 if (SGI_COMPAT (output_bfd)) 9062 { 9063 /* Write .compact_rel section out. */ 9064 s = bfd_get_section_by_name (dynobj, ".compact_rel"); 9065 if (s != NULL) 9066 { 9067 cpt.id1 = 1; 9068 cpt.num = s->reloc_count; 9069 cpt.id2 = 2; 9070 cpt.offset = (s->output_section->filepos 9071 + sizeof (Elf32_External_compact_rel)); 9072 cpt.reserved0 = 0; 9073 cpt.reserved1 = 0; 9074 bfd_elf32_swap_compact_rel_out (output_bfd, &cpt, 9075 ((Elf32_External_compact_rel *) 9076 s->contents)); 9077 9078 /* Clean up a dummy stub function entry in .text. */ 9079 s = bfd_get_section_by_name (dynobj, 9080 MIPS_ELF_STUB_SECTION_NAME (dynobj)); 9081 if (s != NULL) 9082 { 9083 file_ptr dummy_offset; 9084 9085 BFD_ASSERT (s->_raw_size >= MIPS_FUNCTION_STUB_SIZE); 9086 dummy_offset = s->_raw_size - MIPS_FUNCTION_STUB_SIZE; 9087 memset (s->contents + dummy_offset, 0, 9088 MIPS_FUNCTION_STUB_SIZE); 9089 } 9090 } 9091 } 9092 9093 /* We need to sort the entries of the dynamic relocation section. */ 9094 9095 if (!ABI_64_P (output_bfd)) 9096 { 9097 asection *reldyn; 9098 9099 reldyn = bfd_get_section_by_name (dynobj, 9100 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj)); 9101 if (reldyn != NULL && reldyn->reloc_count > 2) 9102 { 9103 reldyn_sorting_bfd = output_bfd; 9104 qsort ((Elf32_External_Rel *) reldyn->contents + 1, 9105 (size_t) reldyn->reloc_count - 1, 9106 sizeof (Elf32_External_Rel), sort_dynamic_relocs); 9107 } 9108 } 9109 9110 /* Clean up a first relocation in .rel.dyn. */ 9111 s = bfd_get_section_by_name (dynobj, 9112 MIPS_ELF_REL_DYN_SECTION_NAME (dynobj)); 9113 if (s != NULL && s->_raw_size > 0) 9114 memset (s->contents, 0, MIPS_ELF_REL_SIZE (dynobj)); 9115 } 9116 9117 return true; 9118 } 9119 9120 9121 /* This is almost identical to bfd_generic_get_... except that some 9122 MIPS relocations need to be handled specially. Sigh. */ 9123 9124 static bfd_byte * 9125 elf32_mips_get_relocated_section_contents (abfd, link_info, link_order, data, 9126 relocateable, symbols) 9127 bfd *abfd; 9128 struct bfd_link_info *link_info; 9129 struct bfd_link_order *link_order; 9130 bfd_byte *data; 9131 boolean relocateable; 9132 asymbol **symbols; 9133 { 9134 /* Get enough memory to hold the stuff */ 9135 bfd *input_bfd = link_order->u.indirect.section->owner; 9136 asection *input_section = link_order->u.indirect.section; 9137 9138 long reloc_size = bfd_get_reloc_upper_bound (input_bfd, input_section); 9139 arelent **reloc_vector = NULL; 9140 long reloc_count; 9141 9142 if (reloc_size < 0) 9143 goto error_return; 9144 9145 reloc_vector = (arelent **) bfd_malloc (reloc_size); 9146 if (reloc_vector == NULL && reloc_size != 0) 9147 goto error_return; 9148 9149 /* read in the section */ 9150 if (!bfd_get_section_contents (input_bfd, 9151 input_section, 9152 (PTR) data, 9153 0, 9154 input_section->_raw_size)) 9155 goto error_return; 9156 9157 /* We're not relaxing the section, so just copy the size info */ 9158 input_section->_cooked_size = input_section->_raw_size; 9159 input_section->reloc_done = true; 9160 9161 reloc_count = bfd_canonicalize_reloc (input_bfd, 9162 input_section, 9163 reloc_vector, 9164 symbols); 9165 if (reloc_count < 0) 9166 goto error_return; 9167 9168 if (reloc_count > 0) 9169 { 9170 arelent **parent; 9171 /* for mips */ 9172 int gp_found; 9173 bfd_vma gp = 0x12345678; /* initialize just to shut gcc up */ 9174 9175 { 9176 struct bfd_hash_entry *h; 9177 struct bfd_link_hash_entry *lh; 9178 /* Skip all this stuff if we aren't mixing formats. */ 9179 if (abfd && input_bfd 9180 && abfd->xvec == input_bfd->xvec) 9181 lh = 0; 9182 else 9183 { 9184 h = bfd_hash_lookup (&link_info->hash->table, "_gp", false, false); 9185 lh = (struct bfd_link_hash_entry *) h; 9186 } 9187 lookup: 9188 if (lh) 9189 { 9190 switch (lh->type) 9191 { 9192 case bfd_link_hash_undefined: 9193 case bfd_link_hash_undefweak: 9194 case bfd_link_hash_common: 9195 gp_found = 0; 9196 break; 9197 case bfd_link_hash_defined: 9198 case bfd_link_hash_defweak: 9199 gp_found = 1; 9200 gp = lh->u.def.value; 9201 break; 9202 case bfd_link_hash_indirect: 9203 case bfd_link_hash_warning: 9204 lh = lh->u.i.link; 9205 /* @@FIXME ignoring warning for now */ 9206 goto lookup; 9207 case bfd_link_hash_new: 9208 default: 9209 abort (); 9210 } 9211 } 9212 else 9213 gp_found = 0; 9214 } 9215 /* end mips */ 9216 for (parent = reloc_vector; *parent != (arelent *) NULL; 9217 parent++) 9218 { 9219 char *error_message = (char *) NULL; 9220 bfd_reloc_status_type r; 9221 9222 /* Specific to MIPS: Deal with relocation types that require 9223 knowing the gp of the output bfd. */ 9224 asymbol *sym = *(*parent)->sym_ptr_ptr; 9225 if (bfd_is_abs_section (sym->section) && abfd) 9226 { 9227 /* The special_function wouldn't get called anyways. */ 9228 } 9229 else if (!gp_found) 9230 { 9231 /* The gp isn't there; let the special function code 9232 fall over on its own. */ 9233 } 9234 else if ((*parent)->howto->special_function 9235 == _bfd_mips_elf_gprel16_reloc) 9236 { 9237 /* bypass special_function call */ 9238 r = gprel16_with_gp (input_bfd, sym, *parent, input_section, 9239 relocateable, (PTR) data, gp); 9240 goto skip_bfd_perform_relocation; 9241 } 9242 /* end mips specific stuff */ 9243 9244 r = bfd_perform_relocation (input_bfd, 9245 *parent, 9246 (PTR) data, 9247 input_section, 9248 relocateable ? abfd : (bfd *) NULL, 9249 &error_message); 9250 skip_bfd_perform_relocation: 9251 9252 if (relocateable) 9253 { 9254 asection *os = input_section->output_section; 9255 9256 /* A partial link, so keep the relocs */ 9257 os->orelocation[os->reloc_count] = *parent; 9258 os->reloc_count++; 9259 } 9260 9261 if (r != bfd_reloc_ok) 9262 { 9263 switch (r) 9264 { 9265 case bfd_reloc_undefined: 9266 if (!((*link_info->callbacks->undefined_symbol) 9267 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr), 9268 input_bfd, input_section, (*parent)->address, 9269 true))) 9270 goto error_return; 9271 break; 9272 case bfd_reloc_dangerous: 9273 BFD_ASSERT (error_message != (char *) NULL); 9274 if (!((*link_info->callbacks->reloc_dangerous) 9275 (link_info, error_message, input_bfd, input_section, 9276 (*parent)->address))) 9277 goto error_return; 9278 break; 9279 case bfd_reloc_overflow: 9280 if (!((*link_info->callbacks->reloc_overflow) 9281 (link_info, bfd_asymbol_name (*(*parent)->sym_ptr_ptr), 9282 (*parent)->howto->name, (*parent)->addend, 9283 input_bfd, input_section, (*parent)->address))) 9284 goto error_return; 9285 break; 9286 case bfd_reloc_outofrange: 9287 default: 9288 abort (); 9289 break; 9290 } 9291 9292 } 9293 } 9294 } 9295 if (reloc_vector != NULL) 9296 free (reloc_vector); 9297 return data; 9298 9299 error_return: 9300 if (reloc_vector != NULL) 9301 free (reloc_vector); 9302 return NULL; 9303 } 9304 9305 #define bfd_elf32_bfd_get_relocated_section_contents \ 9306 elf32_mips_get_relocated_section_contents 1787 1788 1789 /* 1790 Set the low bit of the relocation offset if it's a MIPS64 reloc. 1791 Relocations will always be on (at least) 32-bit boundaries. */ 1792 1793 bfd_put_32 (abfd, ((irel->r_offset + datasec->output_offset) + 1794 ((ELF32_R_TYPE (irel->r_info) == (int) R_MIPS_64) ? 1 : 0)), 1795 p); 1796 memset (p + 4, 0, 8); 1797 if (targetsec != NULL) 1798 strncpy (p + 4, targetsec->output_section->name, 8); 1799 } 1800 1801 if (internal_relocs != NULL 1802 && elf_section_data (datasec)->relocs != internal_relocs) 1803 free (internal_relocs); 1804 if (isymbuf != NULL 1805 && symtab_hdr->contents != (unsigned char *) isymbuf) 1806 free (isymbuf); 1807 return TRUE; 1808 1809 error_return: 1810 if (internal_relocs != NULL 1811 && elf_section_data (datasec)->relocs != internal_relocs) 1812 free (internal_relocs); 1813 if (isymbuf != NULL 1814 && symtab_hdr->contents != (unsigned char *) isymbuf) 1815 free (isymbuf); 1816 return FALSE; 1817 } 9307 1818 9308 1819 … … 9350 1861 9351 1862 9352 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec9353 #define TARGET_LITTLE_NAME "elf32-littlemips"9354 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec9355 #define TARGET_BIG_NAME "elf32-bigmips"9356 1863 #define ELF_ARCH bfd_arch_mips 9357 1864 #define ELF_MACHINE_CODE EM_MIPS … … 9361 1868 #define ELF_MAXPAGESIZE 0x1000 9362 1869 9363 #define elf_backend_collect true 9364 #define elf_backend_type_change_ok true 9365 #define elf_backend_can_gc_sections true 9366 #define elf_backend_sign_extend_vma true 1870 #define elf_backend_collect TRUE 1871 #define elf_backend_type_change_ok TRUE 1872 #define elf_backend_can_gc_sections TRUE 9367 1873 #define elf_info_to_howto mips_info_to_howto_rela 9368 1874 #define elf_info_to_howto_rel mips_info_to_howto_rel 9369 1875 #define elf_backend_sym_is_global mips_elf_sym_is_global 9370 #define elf_backend_object_p _bfd_mips_elf_object_p 1876 #define elf_backend_object_p mips_elf32_object_p 1877 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing 1878 #define elf_backend_section_processing _bfd_mips_elf_section_processing 9371 1879 #define elf_backend_section_from_shdr _bfd_mips_elf_section_from_shdr 9372 1880 #define elf_backend_fake_sections _bfd_mips_elf_fake_sections 9373 1881 #define elf_backend_section_from_bfd_section \ 9374 1882 _bfd_mips_elf_section_from_bfd_section 9375 #define elf_backend_section_processing _bfd_mips_elf_section_processing9376 #define elf_backend_symbol_processing _bfd_mips_elf_symbol_processing9377 #define elf_backend_additional_program_headers \9378 _bfd_mips_elf_additional_program_headers9379 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map9380 #define elf_backend_final_write_processing \9381 _bfd_mips_elf_final_write_processing9382 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap9383 1883 #define elf_backend_add_symbol_hook _bfd_mips_elf_add_symbol_hook 1884 #define elf_backend_link_output_symbol_hook \ 1885 _bfd_mips_elf_link_output_symbol_hook 9384 1886 #define elf_backend_create_dynamic_sections \ 9385 1887 _bfd_mips_elf_create_dynamic_sections … … 9392 1894 _bfd_mips_elf_size_dynamic_sections 9393 1895 #define elf_backend_relocate_section _bfd_mips_elf_relocate_section 9394 #define elf_backend_link_output_symbol_hook \9395 _bfd_mips_elf_link_output_symbol_hook9396 1896 #define elf_backend_finish_dynamic_symbol \ 9397 1897 _bfd_mips_elf_finish_dynamic_symbol 9398 1898 #define elf_backend_finish_dynamic_sections \ 9399 1899 _bfd_mips_elf_finish_dynamic_sections 1900 #define elf_backend_final_write_processing \ 1901 _bfd_mips_elf_final_write_processing 1902 #define elf_backend_additional_program_headers \ 1903 _bfd_mips_elf_additional_program_headers 1904 #define elf_backend_modify_segment_map _bfd_mips_elf_modify_segment_map 9400 1905 #define elf_backend_gc_mark_hook _bfd_mips_elf_gc_mark_hook 9401 1906 #define elf_backend_gc_sweep_hook _bfd_mips_elf_gc_sweep_hook 9402 9403 #define elf_backend_got_header_size (4*MIPS_RESERVED_GOTNO)9404 #define elf_backend_plt_header_size 09405 9406 1907 #define elf_backend_copy_indirect_symbol \ 9407 1908 _bfd_mips_elf_copy_indirect_symbol 9408 9409 1909 #define elf_backend_hide_symbol _bfd_mips_elf_hide_symbol 9410 1910 #define elf_backend_grok_prstatus elf32_mips_grok_prstatus 1911 #define elf_backend_grok_psinfo elf32_mips_grok_psinfo 1912 #define elf_backend_ecoff_debug_swap &mips_elf32_ecoff_debug_swap 1913 1914 #define elf_backend_got_header_size (4 * MIPS_RESERVED_GOTNO) 1915 #define elf_backend_plt_header_size 0 1916 #define elf_backend_may_use_rel_p 1 1917 #define elf_backend_may_use_rela_p 0 1918 #define elf_backend_default_use_rela_p 0 1919 #define elf_backend_sign_extend_vma TRUE 1920 1921 #define elf_backend_discard_info _bfd_mips_elf_discard_info 1922 #define elf_backend_ignore_discarded_relocs \ 1923 _bfd_mips_elf_ignore_discarded_relocs 1924 #define elf_backend_mips_irix_compat elf32_mips_irix_compat 1925 #define elf_backend_mips_rtype_to_howto mips_elf32_rtype_to_howto 9411 1926 #define bfd_elf32_bfd_is_local_label_name \ 9412 1927 mips_elf_is_local_label_name 9413 1928 #define bfd_elf32_find_nearest_line _bfd_mips_elf_find_nearest_line 1929 #define bfd_elf32_new_section_hook _bfd_mips_elf_new_section_hook 9414 1930 #define bfd_elf32_set_section_contents _bfd_mips_elf_set_section_contents 1931 #define bfd_elf32_bfd_get_relocated_section_contents \ 1932 _bfd_elf_mips_get_relocated_section_contents 9415 1933 #define bfd_elf32_bfd_link_hash_table_create \ 9416 1934 _bfd_mips_elf_link_hash_table_create 9417 1935 #define bfd_elf32_bfd_final_link _bfd_mips_elf_final_link 9418 #define bfd_elf32_bfd_copy_private_bfd_data \9419 _bfd_mips_elf_copy_private_bfd_data9420 1936 #define bfd_elf32_bfd_merge_private_bfd_data \ 9421 1937 _bfd_mips_elf_merge_private_bfd_data … … 9423 1939 #define bfd_elf32_bfd_print_private_bfd_data \ 9424 1940 _bfd_mips_elf_print_private_bfd_data 1941 1942 /* Support for SGI-ish mips targets. */ 1943 #define TARGET_LITTLE_SYM bfd_elf32_littlemips_vec 1944 #define TARGET_LITTLE_NAME "elf32-littlemips" 1945 #define TARGET_BIG_SYM bfd_elf32_bigmips_vec 1946 #define TARGET_BIG_NAME "elf32-bigmips" 1947 9425 1948 #include "elf32-target.h" 9426 1949 9427 /* Support for traditional mips targets */ 9428 9429 #define INCLUDED_TARGET_FILE /* More a type of flag */ 1950 /* Support for traditional mips targets. */ 1951 #define INCLUDED_TARGET_FILE /* More a type of flag. */ 9430 1952 9431 1953 #undef TARGET_LITTLE_SYM … … 9439 1961 #define TARGET_BIG_NAME "elf32-tradbigmips" 9440 1962 9441 /* Include the target file again for this target */1963 /* Include the target file again for this target. */ 9442 1964 #include "elf32-target.h" -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.