Changeset 609 for branches/GNU/src/binutils/bfd/elf32-sparc.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-sparc.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r608 r609 1 1 /* SPARC-specific support for 32-bit ELF 2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 3 Free Software Foundation, Inc.4 5 This file is part of BFD, the Binary File Descriptor library.6 7 This program is free software; you can redistribute it and/or modify8 it under the terms of the GNU General Public License as published by9 the Free Software Foundation; either version 2 of the License, or10 (at your option) any later version.11 12 This program is distributed in the hope that it will be useful,13 but WITHOUT ANY WARRANTY; without even the implied warranty of14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15 GNU General Public License for more details.16 17 You should have received a copy of the GNU General Public License18 along with this program; if not, write to the Free Software19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */2 Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 3 2003 Free Software Foundation, Inc. 4 5 This file is part of BFD, the Binary File Descriptor library. 6 7 This program is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as published by 9 the Free Software Foundation; either version 2 of the License, or 10 (at your option) any later version. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public License 18 along with this program; if not, write to the Free Software 19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 20 20 21 21 #include "bfd.h" … … 31 31 static void elf32_sparc_info_to_howto 32 32 PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); 33 static b oolean elf32_sparc_check_relocs33 static bfd_boolean elf32_sparc_check_relocs 34 34 PARAMS ((bfd *, struct bfd_link_info *, asection *, 35 35 const Elf_Internal_Rela *)); 36 static b oolean elf32_sparc_adjust_dynamic_symbol36 static bfd_boolean elf32_sparc_adjust_dynamic_symbol 37 37 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); 38 static boolean elf32_sparc_size_dynamic_sections 38 static bfd_boolean allocate_dynrelocs 39 PARAMS ((struct elf_link_hash_entry *, PTR)); 40 static bfd_boolean readonly_dynrelocs 41 PARAMS ((struct elf_link_hash_entry *, PTR)); 42 static bfd_boolean elf32_sparc_size_dynamic_sections 39 43 PARAMS ((bfd *, struct bfd_link_info *)); 40 static boolean elf32_sparc_relax_section 41 PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *)); 42 static boolean elf32_sparc_relocate_section 44 static bfd_boolean elf32_sparc_new_section_hook 45 PARAMS ((bfd *, asection *)); 46 static bfd_boolean elf32_sparc_relax_section 47 PARAMS ((bfd *, asection *, struct bfd_link_info *, bfd_boolean *)); 48 static bfd_vma dtpoff_base 49 PARAMS ((struct bfd_link_info *)); 50 static bfd_vma tpoff 51 PARAMS ((struct bfd_link_info *, bfd_vma)); 52 static bfd_boolean elf32_sparc_relocate_section 43 53 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, 44 54 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); 45 static b oolean elf32_sparc_finish_dynamic_symbol55 static bfd_boolean elf32_sparc_finish_dynamic_symbol 46 56 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, 47 57 Elf_Internal_Sym *)); 48 static b oolean elf32_sparc_finish_dynamic_sections58 static bfd_boolean elf32_sparc_finish_dynamic_sections 49 59 PARAMS ((bfd *, struct bfd_link_info *)); 50 static boolean elf32_sparc_merge_private_bfd_data PARAMS ((bfd *, bfd *)); 51 static boolean elf32_sparc_object_p 60 static bfd_boolean elf32_sparc_merge_private_bfd_data 61 PARAMS ((bfd *, bfd *)); 62 static struct bfd_hash_entry *link_hash_newfunc 63 PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); 64 static struct bfd_link_hash_table *elf32_sparc_link_hash_table_create 65 PARAMS ((bfd *)); 66 static bfd_boolean create_got_section 67 PARAMS ((bfd *, struct bfd_link_info *)); 68 static bfd_boolean elf32_sparc_create_dynamic_sections 69 PARAMS ((bfd *, struct bfd_link_info *)); 70 static void elf32_sparc_copy_indirect_symbol 71 PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *, 72 struct elf_link_hash_entry *)); 73 static int elf32_sparc_tls_transition 74 PARAMS ((struct bfd_link_info *, bfd *, int, int)); 75 76 static bfd_boolean elf32_sparc_mkobject 77 PARAMS ((bfd *)); 78 static bfd_boolean elf32_sparc_object_p 52 79 PARAMS ((bfd *)); 53 80 static void elf32_sparc_final_write_processing 54 PARAMS ((bfd *, boolean)); 81 PARAMS ((bfd *, bfd_boolean)); 82 static enum elf_reloc_type_class elf32_sparc_reloc_type_class 83 PARAMS ((const Elf_Internal_Rela *)); 84 static asection * elf32_sparc_gc_mark_hook 85 PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *, 86 struct elf_link_hash_entry *, Elf_Internal_Sym *)); 87 static bfd_boolean elf32_sparc_gc_sweep_hook 88 PARAMS ((bfd *, struct bfd_link_info *, asection *, 89 const Elf_Internal_Rela *)); 55 90 56 91 … … 61 96 static bfd_reloc_status_type sparc_elf_wdisp16_reloc 62 97 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); 98 static bfd_reloc_status_type sparc_elf_hix22_reloc 99 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); 100 static bfd_reloc_status_type sparc_elf_lox10_reloc 101 PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **)); 63 102 64 103 reloc_howto_type _bfd_sparc_elf_howto_table[] = 65 104 { 66 HOWTO(R_SPARC_NONE, 0,0, 0, false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", false,0,0x00000000,true),67 HOWTO(R_SPARC_8, 0,0, 8, false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_8", false,0,0x000000ff,true),68 HOWTO(R_SPARC_16, 0,1,16, false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_16", false,0,0x0000ffff,true),69 HOWTO(R_SPARC_32, 0,2,32, false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_32", false,0,0xffffffff,true),70 HOWTO(R_SPARC_DISP8, 0,0, 8, true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP8", false,0,0x000000ff,true),71 HOWTO(R_SPARC_DISP16, 0,1,16, true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP16", false,0,0x0000ffff,true),72 HOWTO(R_SPARC_DISP32, 0,2,32, true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP32", false,0,0x00ffffff,true),73 HOWTO(R_SPARC_WDISP30, 2,2,30, true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP30", false,0,0x3fffffff,true),74 HOWTO(R_SPARC_WDISP22, 2,2,22, true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP22", false,0,0x003fffff,true),75 HOWTO(R_SPARC_HI22, 10,2,22, false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HI22", false,0,0x003fffff,true),76 HOWTO(R_SPARC_22, 0,2,22, false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_22", false,0,0x003fffff,true),77 HOWTO(R_SPARC_13, 0,2,13, false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_13", false,0,0x00001fff,true),78 HOWTO(R_SPARC_LO10, 0,2,10, false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LO10", false,0,0x000003ff,true),79 HOWTO(R_SPARC_GOT10, 0,2,10, false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT10", false,0,0x000003ff,true),80 HOWTO(R_SPARC_GOT13, 0,2,13, false,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_GOT13", false,0,0x00001fff,true),81 HOWTO(R_SPARC_GOT22, 10,2,22, false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT22", false,0,0x003fffff,true),82 HOWTO(R_SPARC_PC10, 0,2,10, true, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC10", false,0,0x000003ff,true),83 HOWTO(R_SPARC_PC22, 10,2,22, true, 0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PC22", false,0,0x003fffff,true),84 HOWTO(R_SPARC_WPLT30, 2,2,30, true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WPLT30", false,0,0x3fffffff,true),85 HOWTO(R_SPARC_COPY, 0,0,00, false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_COPY", false,0,0x00000000,true),86 HOWTO(R_SPARC_GLOB_DAT, 0,0,00, false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GLOB_DAT",false,0,0x00000000,true),87 HOWTO(R_SPARC_JMP_SLOT, 0,0,00, false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_JMP_SLOT",false,0,0x00000000,true),88 HOWTO(R_SPARC_RELATIVE, 0,0,00, false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_RELATIVE",false,0,0x00000000,true),89 HOWTO(R_SPARC_UA32, 0,2,32, false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA32", false,0,0xffffffff,true),90 HOWTO(R_SPARC_PLT32, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_PLT32", false,0,0x00000000,true),91 HOWTO(R_SPARC_HIPLT22, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_HIPLT22", false,0,0x00000000,true),92 HOWTO(R_SPARC_LOPLT10, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_LOPLT10", false,0,0x00000000,true),93 HOWTO(R_SPARC_PCPLT32, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_PCPLT32", false,0,0x00000000,true),94 HOWTO(R_SPARC_PCPLT22, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_PCPLT22", false,0,0x00000000,true),95 HOWTO(R_SPARC_PCPLT10, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_PCPLT10", false,0,0x00000000,true),96 HOWTO(R_SPARC_10, 0,2,10, false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_10", false,0,0x000003ff,true),97 HOWTO(R_SPARC_11, 0,2,11, false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_11", false,0,0x000007ff,true),105 HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE), 106 HOWTO(R_SPARC_8, 0,0, 8,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_8", FALSE,0,0x000000ff,TRUE), 107 HOWTO(R_SPARC_16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_16", FALSE,0,0x0000ffff,TRUE), 108 HOWTO(R_SPARC_32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_32", FALSE,0,0xffffffff,TRUE), 109 HOWTO(R_SPARC_DISP8, 0,0, 8,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP8", FALSE,0,0x000000ff,TRUE), 110 HOWTO(R_SPARC_DISP16, 0,1,16,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP16", FALSE,0,0x0000ffff,TRUE), 111 HOWTO(R_SPARC_DISP32, 0,2,32,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_DISP32", FALSE,0,0xffffffff,TRUE), 112 HOWTO(R_SPARC_WDISP30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP30", FALSE,0,0x3fffffff,TRUE), 113 HOWTO(R_SPARC_WDISP22, 2,2,22,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP22", FALSE,0,0x003fffff,TRUE), 114 HOWTO(R_SPARC_HI22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_HI22", FALSE,0,0x003fffff,TRUE), 115 HOWTO(R_SPARC_22, 0,2,22,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_22", FALSE,0,0x003fffff,TRUE), 116 HOWTO(R_SPARC_13, 0,2,13,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_13", FALSE,0,0x00001fff,TRUE), 117 HOWTO(R_SPARC_LO10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_LO10", FALSE,0,0x000003ff,TRUE), 118 HOWTO(R_SPARC_GOT10, 0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT10", FALSE,0,0x000003ff,TRUE), 119 HOWTO(R_SPARC_GOT13, 0,2,13,FALSE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_GOT13", FALSE,0,0x00001fff,TRUE), 120 HOWTO(R_SPARC_GOT22, 10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GOT22", FALSE,0,0x003fffff,TRUE), 121 HOWTO(R_SPARC_PC10, 0,2,10,TRUE, 0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_PC10", FALSE,0,0x000003ff,TRUE), 122 HOWTO(R_SPARC_PC22, 10,2,22,TRUE, 0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PC22", FALSE,0,0x003fffff,TRUE), 123 HOWTO(R_SPARC_WPLT30, 2,2,30,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WPLT30", FALSE,0,0x3fffffff,TRUE), 124 HOWTO(R_SPARC_COPY, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_COPY", FALSE,0,0x00000000,TRUE), 125 HOWTO(R_SPARC_GLOB_DAT, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_GLOB_DAT",FALSE,0,0x00000000,TRUE), 126 HOWTO(R_SPARC_JMP_SLOT, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_JMP_SLOT",FALSE,0,0x00000000,TRUE), 127 HOWTO(R_SPARC_RELATIVE, 0,0,00,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_RELATIVE",FALSE,0,0x00000000,TRUE), 128 HOWTO(R_SPARC_UA32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA32", FALSE,0,0xffffffff,TRUE), 129 HOWTO(R_SPARC_PLT32, 0,0,00,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_PLT32", FALSE,0,0xffffffff,TRUE), 130 HOWTO(R_SPARC_HIPLT22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_HIPLT22", FALSE,0,0x00000000,TRUE), 131 HOWTO(R_SPARC_LOPLT10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_LOPLT10", FALSE,0,0x00000000,TRUE), 132 HOWTO(R_SPARC_PCPLT32, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_PCPLT32", FALSE,0,0x00000000,TRUE), 133 HOWTO(R_SPARC_PCPLT22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_PCPLT22", FALSE,0,0x00000000,TRUE), 134 HOWTO(R_SPARC_PCPLT10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_PCPLT10", FALSE,0,0x00000000,TRUE), 135 HOWTO(R_SPARC_10, 0,2,10,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_10", FALSE,0,0x000003ff,TRUE), 136 HOWTO(R_SPARC_11, 0,2,11,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_11", FALSE,0,0x000007ff,TRUE), 98 137 /* These are for sparc64 in a 64 bit environment. 99 138 Values need to be here because the table is indexed by reloc number. */ 100 HOWTO(R_SPARC_64, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_64", false,0,0x00000000,true),101 HOWTO(R_SPARC_OLO10, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_OLO10", false,0,0x00000000,true),102 HOWTO(R_SPARC_HH22, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_HH22", false,0,0x00000000,true),103 HOWTO(R_SPARC_HM10, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_HM10", false,0,0x00000000,true),104 HOWTO(R_SPARC_LM22, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_LM22", false,0,0x00000000,true),105 HOWTO(R_SPARC_PC_HH22, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_PC_HH22", false,0,0x00000000,true),106 HOWTO(R_SPARC_PC_HM10, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_PC_HM10", false,0,0x00000000,true),107 HOWTO(R_SPARC_PC_LM22, 0,0,00, false,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_PC_LM22", false,0,0x00000000,true),139 HOWTO(R_SPARC_64, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_64", FALSE,0,0x00000000,TRUE), 140 HOWTO(R_SPARC_OLO10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_OLO10", FALSE,0,0x00000000,TRUE), 141 HOWTO(R_SPARC_HH22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_HH22", FALSE,0,0x00000000,TRUE), 142 HOWTO(R_SPARC_HM10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_HM10", FALSE,0,0x00000000,TRUE), 143 HOWTO(R_SPARC_LM22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_LM22", FALSE,0,0x00000000,TRUE), 144 HOWTO(R_SPARC_PC_HH22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_PC_HH22", FALSE,0,0x00000000,TRUE), 145 HOWTO(R_SPARC_PC_HM10, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_PC_HM10", FALSE,0,0x00000000,TRUE), 146 HOWTO(R_SPARC_PC_LM22, 0,0,00,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_PC_LM22", FALSE,0,0x00000000,TRUE), 108 147 /* End sparc64 in 64 bit environment values. 109 148 The following are for sparc64 in a 32 bit environment. */ 110 HOWTO(R_SPARC_WDISP16, 2,2,16,true, 0,complain_overflow_signed, sparc_elf_wdisp16_reloc,"R_SPARC_WDISP16", false,0,0x00000000,true), 111 HOWTO(R_SPARC_WDISP19, 2,2,19,true, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP19", false,0,0x0007ffff,true), 112 HOWTO(R_SPARC_UNUSED_42, 0,0, 0,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_UNUSED_42",false,0,0x00000000,true), 113 HOWTO(R_SPARC_7, 0,2, 7,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_7", false,0,0x0000007f,true), 114 HOWTO(R_SPARC_5, 0,2, 5,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_5", false,0,0x0000001f,true), 115 HOWTO(R_SPARC_6, 0,2, 6,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_6", false,0,0x0000003f,true), 116 HOWTO(R_SPARC_NONE, 0,0, 0,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", false,0,0x00000000,true), 117 HOWTO(R_SPARC_NONE, 0,0, 0,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", false,0,0x00000000,true), 118 HOWTO(R_SPARC_NONE, 0,0, 0,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", false,0,0x00000000,true), 119 HOWTO(R_SPARC_NONE, 0,0, 0,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", false,0,0x00000000,true), 120 HOWTO(R_SPARC_NONE, 0,0, 0,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", false,0,0x00000000,true), 121 HOWTO(R_SPARC_NONE, 0,0, 0,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", false,0,0x00000000,true), 122 HOWTO(R_SPARC_NONE, 0,0, 0,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", false,0,0x00000000,true), 123 HOWTO(R_SPARC_NONE, 0,0, 0,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", false,0,0x00000000,true), 124 HOWTO(R_SPARC_UA64, 0,4,64,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA64", false,0,(~ (bfd_vma)0), true), 125 HOWTO(R_SPARC_UA16, 0,1,16,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA16", false,0,0x0000ffff,true), 126 HOWTO(R_SPARC_REV32, 0,2,32,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_REV32", false,0,0xffffffff,true), 149 HOWTO(R_SPARC_WDISP16, 2,2,16,TRUE, 0,complain_overflow_signed, sparc_elf_wdisp16_reloc,"R_SPARC_WDISP16", FALSE,0,0x00000000,TRUE), 150 HOWTO(R_SPARC_WDISP19, 2,2,19,TRUE, 0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_WDISP19", FALSE,0,0x0007ffff,TRUE), 151 HOWTO(R_SPARC_UNUSED_42, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_UNUSED_42",FALSE,0,0x00000000,TRUE), 152 HOWTO(R_SPARC_7, 0,2, 7,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_7", FALSE,0,0x0000007f,TRUE), 153 HOWTO(R_SPARC_5, 0,2, 5,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_5", FALSE,0,0x0000001f,TRUE), 154 HOWTO(R_SPARC_6, 0,2, 6,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_6", FALSE,0,0x0000003f,TRUE), 155 HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE), 156 HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE), 157 HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE), 158 HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE), 159 HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE), 160 HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE), 161 HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE), 162 HOWTO(R_SPARC_NONE, 0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_NONE", FALSE,0,0x00000000,TRUE), 163 HOWTO(R_SPARC_UA64, 0,0, 0,FALSE,0,complain_overflow_dont, sparc_elf_notsupported_reloc, "R_SPARC_UA64", FALSE,0,0x00000000,TRUE), 164 HOWTO(R_SPARC_UA16, 0,1,16,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_UA16", FALSE,0,0x0000ffff,TRUE), 165 HOWTO(R_SPARC_TLS_GD_HI22,10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_HI22",FALSE,0,0x003fffff,TRUE), 166 HOWTO(R_SPARC_TLS_GD_LO10,0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_LO10",FALSE,0,0x000003ff,TRUE), 167 HOWTO(R_SPARC_TLS_GD_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_ADD",FALSE,0,0x00000000,TRUE), 168 HOWTO(R_SPARC_TLS_GD_CALL,2,2,30,TRUE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_TLS_GD_CALL",FALSE,0,0x3fffffff,TRUE), 169 HOWTO(R_SPARC_TLS_LDM_HI22,10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_HI22",FALSE,0,0x003fffff,TRUE), 170 HOWTO(R_SPARC_TLS_LDM_LO10,0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_LO10",FALSE,0,0x000003ff,TRUE), 171 HOWTO(R_SPARC_TLS_LDM_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_ADD",FALSE,0,0x00000000,TRUE), 172 HOWTO(R_SPARC_TLS_LDM_CALL,2,2,30,TRUE,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_SPARC_TLS_LDM_CALL",FALSE,0,0x3fffffff,TRUE), 173 HOWTO(R_SPARC_TLS_LDO_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc,"R_SPARC_TLS_LDO_HIX22",FALSE,0,0x003fffff, FALSE), 174 HOWTO(R_SPARC_TLS_LDO_LOX10,0,2,0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_TLS_LDO_LOX10",FALSE,0,0x000003ff, FALSE), 175 HOWTO(R_SPARC_TLS_LDO_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_LDO_ADD",FALSE,0,0x00000000,TRUE), 176 HOWTO(R_SPARC_TLS_IE_HI22,10,2,22,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_HI22",FALSE,0,0x003fffff,TRUE), 177 HOWTO(R_SPARC_TLS_IE_LO10,0,2,10,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_LO10",FALSE,0,0x000003ff,TRUE), 178 HOWTO(R_SPARC_TLS_IE_LD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_LD",FALSE,0,0x00000000,TRUE), 179 HOWTO(R_SPARC_TLS_IE_LDX,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_LDX",FALSE,0,0x00000000,TRUE), 180 HOWTO(R_SPARC_TLS_IE_ADD,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_IE_ADD",FALSE,0,0x00000000,TRUE), 181 HOWTO(R_SPARC_TLS_LE_HIX22,0,2,0,FALSE,0,complain_overflow_bitfield,sparc_elf_hix22_reloc, "R_SPARC_TLS_LE_HIX22",FALSE,0,0x003fffff, FALSE), 182 HOWTO(R_SPARC_TLS_LE_LOX10,0,2,0,FALSE,0,complain_overflow_dont, sparc_elf_lox10_reloc, "R_SPARC_TLS_LE_LOX10",FALSE,0,0x000003ff, FALSE), 183 HOWTO(R_SPARC_TLS_DTPMOD32,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_DTPMOD32",FALSE,0,0x00000000,TRUE), 184 HOWTO(R_SPARC_TLS_DTPMOD64,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_DTPMOD64",FALSE,0,0x00000000,TRUE), 185 HOWTO(R_SPARC_TLS_DTPOFF32,0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc,"R_SPARC_TLS_DTPOFF32",FALSE,0,0xffffffff,TRUE), 186 HOWTO(R_SPARC_TLS_DTPOFF64,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_DTPOFF64",FALSE,0,0x00000000,TRUE), 187 HOWTO(R_SPARC_TLS_TPOFF32,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_TPOFF32",FALSE,0,0x00000000,TRUE), 188 HOWTO(R_SPARC_TLS_TPOFF64,0,0, 0,FALSE,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_SPARC_TLS_TPOFF64",FALSE,0,0x00000000,TRUE) 127 189 }; 128 190 static reloc_howto_type elf32_sparc_vtinherit_howto = 129 HOWTO (R_SPARC_GNU_VTINHERIT, 0,2,0, false,0,complain_overflow_dont, NULL, "R_SPARC_GNU_VTINHERIT", false,0, 0, false);191 HOWTO (R_SPARC_GNU_VTINHERIT, 0,2,0,FALSE,0,complain_overflow_dont, NULL, "R_SPARC_GNU_VTINHERIT", FALSE,0, 0, FALSE); 130 192 static reloc_howto_type elf32_sparc_vtentry_howto = 131 HOWTO (R_SPARC_GNU_VTENTRY, 0,2,0,false,0,complain_overflow_dont, _bfd_elf_rel_vtable_reloc_fn,"R_SPARC_GNU_VTENTRY", false,0,0, false); 193 HOWTO (R_SPARC_GNU_VTENTRY, 0,2,0,FALSE,0,complain_overflow_dont, _bfd_elf_rel_vtable_reloc_fn,"R_SPARC_GNU_VTENTRY", FALSE,0,0, FALSE); 194 static reloc_howto_type elf32_sparc_rev32_howto = 195 HOWTO(R_SPARC_REV32, 0,2,32,FALSE,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_SPARC_REV32", FALSE,0,0xffffffff,TRUE); 132 196 133 197 struct elf_reloc_map { … … 136 200 }; 137 201 138 static CONSTstruct elf_reloc_map sparc_reloc_map[] =202 static const struct elf_reloc_map sparc_reloc_map[] = 139 203 { 140 204 { BFD_RELOC_NONE, R_SPARC_NONE, }, 141 205 { BFD_RELOC_16, R_SPARC_16, }, 206 { BFD_RELOC_16_PCREL, R_SPARC_DISP16 }, 142 207 { BFD_RELOC_8, R_SPARC_8 }, 143 208 { BFD_RELOC_8_PCREL, R_SPARC_DISP8 }, … … 148 213 { BFD_RELOC_LO10, R_SPARC_LO10, }, 149 214 { BFD_RELOC_32_PCREL_S2, R_SPARC_WDISP30 }, 215 { BFD_RELOC_SPARC_PLT32, R_SPARC_PLT32 }, 150 216 { BFD_RELOC_SPARC22, R_SPARC_22 }, 151 217 { BFD_RELOC_SPARC13, R_SPARC_13 }, … … 179 245 { BFD_RELOC_SPARC_5, R_SPARC_5 }, 180 246 { BFD_RELOC_SPARC_6, R_SPARC_6 }, 181 { BFD_RELOC_SPARC_REV32, R_SPARC_REV32 }, 247 { BFD_RELOC_SPARC_TLS_GD_HI22, R_SPARC_TLS_GD_HI22 }, 248 { BFD_RELOC_SPARC_TLS_GD_LO10, R_SPARC_TLS_GD_LO10 }, 249 { BFD_RELOC_SPARC_TLS_GD_ADD, R_SPARC_TLS_GD_ADD }, 250 { BFD_RELOC_SPARC_TLS_GD_CALL, R_SPARC_TLS_GD_CALL }, 251 { BFD_RELOC_SPARC_TLS_LDM_HI22, R_SPARC_TLS_LDM_HI22 }, 252 { BFD_RELOC_SPARC_TLS_LDM_LO10, R_SPARC_TLS_LDM_LO10 }, 253 { BFD_RELOC_SPARC_TLS_LDM_ADD, R_SPARC_TLS_LDM_ADD }, 254 { BFD_RELOC_SPARC_TLS_LDM_CALL, R_SPARC_TLS_LDM_CALL }, 255 { BFD_RELOC_SPARC_TLS_LDO_HIX22, R_SPARC_TLS_LDO_HIX22 }, 256 { BFD_RELOC_SPARC_TLS_LDO_LOX10, R_SPARC_TLS_LDO_LOX10 }, 257 { BFD_RELOC_SPARC_TLS_LDO_ADD, R_SPARC_TLS_LDO_ADD }, 258 { BFD_RELOC_SPARC_TLS_IE_HI22, R_SPARC_TLS_IE_HI22 }, 259 { BFD_RELOC_SPARC_TLS_IE_LO10, R_SPARC_TLS_IE_LO10 }, 260 { BFD_RELOC_SPARC_TLS_IE_LD, R_SPARC_TLS_IE_LD }, 261 { BFD_RELOC_SPARC_TLS_IE_LDX, R_SPARC_TLS_IE_LDX }, 262 { BFD_RELOC_SPARC_TLS_IE_ADD, R_SPARC_TLS_IE_ADD }, 263 { BFD_RELOC_SPARC_TLS_LE_HIX22, R_SPARC_TLS_LE_HIX22 }, 264 { BFD_RELOC_SPARC_TLS_LE_LOX10, R_SPARC_TLS_LE_LOX10 }, 265 { BFD_RELOC_SPARC_TLS_DTPMOD32, R_SPARC_TLS_DTPMOD32 }, 266 { BFD_RELOC_SPARC_TLS_DTPMOD64, R_SPARC_TLS_DTPMOD64 }, 267 { BFD_RELOC_SPARC_TLS_DTPOFF32, R_SPARC_TLS_DTPOFF32 }, 268 { BFD_RELOC_SPARC_TLS_DTPOFF64, R_SPARC_TLS_DTPOFF64 }, 269 { BFD_RELOC_SPARC_TLS_TPOFF32, R_SPARC_TLS_TPOFF32 }, 270 { BFD_RELOC_SPARC_TLS_TPOFF64, R_SPARC_TLS_TPOFF64 }, 182 271 { BFD_RELOC_VTABLE_INHERIT, R_SPARC_GNU_VTINHERIT }, 183 272 { BFD_RELOC_VTABLE_ENTRY, R_SPARC_GNU_VTENTRY }, 273 { BFD_RELOC_SPARC_REV32, R_SPARC_REV32 } 184 274 }; 185 275 … … 199 289 return &elf32_sparc_vtentry_howto; 200 290 291 case BFD_RELOC_SPARC_REV32: 292 return &elf32_sparc_rev32_howto; 293 201 294 default: 202 for (i = 0; i < sizeof (sparc_reloc_map) / sizeof (struct elf_reloc_map); i++) 203 { 204 if (sparc_reloc_map[i].bfd_reloc_val == code) 205 return &_bfd_sparc_elf_howto_table[(int) sparc_reloc_map[i].elf_reloc_val]; 206 } 295 for (i = 0; 296 i < sizeof (sparc_reloc_map) / sizeof (struct elf_reloc_map); 297 i++) 298 { 299 if (sparc_reloc_map[i].bfd_reloc_val == code) 300 return (_bfd_sparc_elf_howto_table 301 + (int) sparc_reloc_map[i].elf_reloc_val); 302 } 207 303 } 208 304 bfd_set_error (bfd_error_bad_value); … … 227 323 case R_SPARC_GNU_VTENTRY: 228 324 cache_ptr->howto = &elf32_sparc_vtentry_howto; 325 break; 326 327 case R_SPARC_REV32: 328 cache_ptr->howto = &elf32_sparc_rev32_howto; 229 329 break; 230 330 … … 313 413 } 314 414 415 /* Handle the HIX22 reloc. */ 416 417 static bfd_reloc_status_type 418 sparc_elf_hix22_reloc (abfd, 419 reloc_entry, 420 symbol, 421 data, 422 input_section, 423 output_bfd, 424 error_message) 425 bfd *abfd; 426 arelent *reloc_entry; 427 asymbol *symbol; 428 PTR data; 429 asection *input_section; 430 bfd *output_bfd; 431 char **error_message ATTRIBUTE_UNUSED; 432 { 433 bfd_vma relocation; 434 bfd_vma insn; 435 436 if (output_bfd != (bfd *) NULL 437 && (symbol->flags & BSF_SECTION_SYM) == 0) 438 { 439 reloc_entry->address += input_section->output_offset; 440 return bfd_reloc_ok; 441 } 442 443 if (output_bfd != NULL) 444 return bfd_reloc_continue; 445 446 if (reloc_entry->address > input_section->_cooked_size) 447 return bfd_reloc_outofrange; 448 449 relocation = (symbol->value 450 + symbol->section->output_section->vma 451 + symbol->section->output_offset); 452 relocation += reloc_entry->addend; 453 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address); 454 455 insn = (insn &~ (bfd_vma) 0x3fffff) | (((~relocation) >> 10) & 0x3fffff); 456 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address); 457 458 return bfd_reloc_ok; 459 } 460 461 /* Handle the LOX10 reloc. */ 462 463 static bfd_reloc_status_type 464 sparc_elf_lox10_reloc (abfd, 465 reloc_entry, 466 symbol, 467 data, 468 input_section, 469 output_bfd, 470 error_message) 471 bfd *abfd; 472 arelent *reloc_entry; 473 asymbol *symbol; 474 PTR data; 475 asection *input_section; 476 bfd *output_bfd; 477 char **error_message ATTRIBUTE_UNUSED; 478 { 479 bfd_vma relocation; 480 bfd_vma insn; 481 482 if (output_bfd != (bfd *) NULL 483 && (symbol->flags & BSF_SECTION_SYM) == 0) 484 { 485 reloc_entry->address += input_section->output_offset; 486 return bfd_reloc_ok; 487 } 488 489 if (output_bfd != NULL) 490 return bfd_reloc_continue; 491 492 if (reloc_entry->address > input_section->_cooked_size) 493 return bfd_reloc_outofrange; 494 495 relocation = (symbol->value 496 + symbol->section->output_section->vma 497 + symbol->section->output_offset); 498 relocation += reloc_entry->addend; 499 insn = bfd_get_32 (abfd, (bfd_byte *) data + reloc_entry->address); 500 501 insn = (insn &~ (bfd_vma) 0x1fff) | 0x1c00 | (relocation & 0x3ff); 502 bfd_put_32 (abfd, insn, (bfd_byte *) data + reloc_entry->address); 503 504 return bfd_reloc_ok; 505 } 506 315 507 316 508 /* Functions for the SPARC ELF linker. */ … … 341 533 #define PLT_ENTRY_WORD2 SPARC_NOP 342 534 535 /* The SPARC linker needs to keep track of the number of relocs that it 536 decides to copy as dynamic relocs in check_relocs for each symbol. 537 This is so that it can later discard them if they are found to be 538 unnecessary. We store the information in a field extending the 539 regular ELF linker hash table. */ 540 541 struct elf32_sparc_dyn_relocs 542 { 543 struct elf32_sparc_dyn_relocs *next; 544 545 /* The input section of the reloc. */ 546 asection *sec; 547 548 /* Total number of relocs copied for the input section. */ 549 bfd_size_type count; 550 551 /* Number of pc-relative relocs copied for the input section. */ 552 bfd_size_type pc_count; 553 }; 554 555 /* SPARC ELF linker hash entry. */ 556 557 struct elf32_sparc_link_hash_entry 558 { 559 struct elf_link_hash_entry elf; 560 561 /* Track dynamic relocs copied for this symbol. */ 562 struct elf32_sparc_dyn_relocs *dyn_relocs; 563 564 #define GOT_UNKNOWN 0 565 #define GOT_NORMAL 1 566 #define GOT_TLS_GD 2 567 #define GOT_TLS_IE 3 568 unsigned char tls_type; 569 }; 570 571 #define elf32_sparc_hash_entry(ent) ((struct elf32_sparc_link_hash_entry *)(ent)) 572 573 struct elf32_sparc_obj_tdata 574 { 575 struct elf_obj_tdata root; 576 577 /* tls_type for each local got entry. */ 578 char *local_got_tls_type; 579 580 /* TRUE if TLS GD relocs has been seen for this object. */ 581 bfd_boolean has_tlsgd; 582 }; 583 584 #define elf32_sparc_tdata(abfd) \ 585 ((struct elf32_sparc_obj_tdata *) (abfd)->tdata.any) 586 587 #define elf32_sparc_local_got_tls_type(abfd) \ 588 (elf32_sparc_tdata (abfd)->local_got_tls_type) 589 590 static bfd_boolean 591 elf32_sparc_mkobject (abfd) 592 bfd *abfd; 593 { 594 bfd_size_type amt = sizeof (struct elf32_sparc_obj_tdata); 595 abfd->tdata.any = bfd_zalloc (abfd, amt); 596 if (abfd->tdata.any == NULL) 597 return FALSE; 598 return TRUE; 599 } 600 601 /* SPARC ELF linker hash table. */ 602 603 struct elf32_sparc_link_hash_table 604 { 605 struct elf_link_hash_table elf; 606 607 /* Short-cuts to get to dynamic linker sections. */ 608 asection *sgot; 609 asection *srelgot; 610 asection *splt; 611 asection *srelplt; 612 asection *sdynbss; 613 asection *srelbss; 614 615 union { 616 bfd_signed_vma refcount; 617 bfd_vma offset; 618 } tls_ldm_got; 619 620 /* Small local sym to section mapping cache. */ 621 struct sym_sec_cache sym_sec; 622 }; 623 624 /* Get the SPARC ELF linker hash table from a link_info structure. */ 625 626 #define elf32_sparc_hash_table(p) \ 627 ((struct elf32_sparc_link_hash_table *) ((p)->hash)) 628 629 /* Create an entry in an i386 ELF linker hash table. */ 630 631 static struct bfd_hash_entry * 632 link_hash_newfunc (entry, table, string) 633 struct bfd_hash_entry *entry; 634 struct bfd_hash_table *table; 635 const char *string; 636 { 637 /* Allocate the structure if it has not already been allocated by a 638 subclass. */ 639 if (entry == NULL) 640 { 641 entry = bfd_hash_allocate (table, 642 sizeof (struct elf32_sparc_link_hash_entry)); 643 if (entry == NULL) 644 return entry; 645 } 646 647 /* Call the allocation method of the superclass. */ 648 entry = _bfd_elf_link_hash_newfunc (entry, table, string); 649 if (entry != NULL) 650 { 651 struct elf32_sparc_link_hash_entry *eh; 652 653 eh = (struct elf32_sparc_link_hash_entry *) entry; 654 eh->dyn_relocs = NULL; 655 eh->tls_type = GOT_UNKNOWN; 656 } 657 658 return entry; 659 } 660 661 /* Create a SPARC ELF linker hash table. */ 662 663 static struct bfd_link_hash_table * 664 elf32_sparc_link_hash_table_create (abfd) 665 bfd *abfd; 666 { 667 struct elf32_sparc_link_hash_table *ret; 668 bfd_size_type amt = sizeof (struct elf32_sparc_link_hash_table); 669 670 ret = (struct elf32_sparc_link_hash_table *) bfd_malloc (amt); 671 if (ret == NULL) 672 return NULL; 673 674 if (! _bfd_elf_link_hash_table_init (&ret->elf, abfd, link_hash_newfunc)) 675 { 676 free (ret); 677 return NULL; 678 } 679 680 ret->sgot = NULL; 681 ret->srelgot = NULL; 682 ret->splt = NULL; 683 ret->srelplt = NULL; 684 ret->sdynbss = NULL; 685 ret->srelbss = NULL; 686 ret->tls_ldm_got.refcount = 0; 687 ret->sym_sec.abfd = NULL; 688 689 return &ret->elf.root; 690 } 691 692 /* Create .got and .rela.got sections in DYNOBJ, and set up 693 shortcuts to them in our hash table. */ 694 695 static bfd_boolean 696 create_got_section (dynobj, info) 697 bfd *dynobj; 698 struct bfd_link_info *info; 699 { 700 struct elf32_sparc_link_hash_table *htab; 701 702 if (! _bfd_elf_create_got_section (dynobj, info)) 703 return FALSE; 704 705 htab = elf32_sparc_hash_table (info); 706 htab->sgot = bfd_get_section_by_name (dynobj, ".got"); 707 if (!htab->sgot) 708 abort (); 709 710 htab->srelgot = bfd_make_section (dynobj, ".rela.got"); 711 if (htab->srelgot == NULL 712 || ! bfd_set_section_flags (dynobj, htab->srelgot, 713 (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS 714 | SEC_IN_MEMORY | SEC_LINKER_CREATED 715 | SEC_READONLY)) 716 || ! bfd_set_section_alignment (dynobj, htab->srelgot, 2)) 717 return FALSE; 718 return TRUE; 719 } 720 721 /* Create .plt, .rela.plt, .got, .rela.got, .dynbss, and 722 .rela.bss sections in DYNOBJ, and set up shortcuts to them in our 723 hash table. */ 724 725 static bfd_boolean 726 elf32_sparc_create_dynamic_sections (dynobj, info) 727 bfd *dynobj; 728 struct bfd_link_info *info; 729 { 730 struct elf32_sparc_link_hash_table *htab; 731 732 htab = elf32_sparc_hash_table (info); 733 if (!htab->sgot && !create_got_section (dynobj, info)) 734 return FALSE; 735 736 if (!_bfd_elf_create_dynamic_sections (dynobj, info)) 737 return FALSE; 738 739 htab->splt = bfd_get_section_by_name (dynobj, ".plt"); 740 htab->srelplt = bfd_get_section_by_name (dynobj, ".rela.plt"); 741 htab->sdynbss = bfd_get_section_by_name (dynobj, ".dynbss"); 742 if (!info->shared) 743 htab->srelbss = bfd_get_section_by_name (dynobj, ".rela.bss"); 744 745 if (!htab->splt || !htab->srelplt || !htab->sdynbss 746 || (!info->shared && !htab->srelbss)) 747 abort (); 748 749 return TRUE; 750 } 751 752 /* Copy the extra info we tack onto an elf_link_hash_entry. */ 753 754 static void 755 elf32_sparc_copy_indirect_symbol (bed, dir, ind) 756 struct elf_backend_data *bed; 757 struct elf_link_hash_entry *dir, *ind; 758 { 759 struct elf32_sparc_link_hash_entry *edir, *eind; 760 761 edir = (struct elf32_sparc_link_hash_entry *) dir; 762 eind = (struct elf32_sparc_link_hash_entry *) ind; 763 764 if (eind->dyn_relocs != NULL) 765 { 766 if (edir->dyn_relocs != NULL) 767 { 768 struct elf32_sparc_dyn_relocs **pp; 769 struct elf32_sparc_dyn_relocs *p; 770 771 if (ind->root.type == bfd_link_hash_indirect) 772 abort (); 773 774 /* Add reloc counts against the weak sym to the strong sym 775 list. Merge any entries against the same section. */ 776 for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) 777 { 778 struct elf32_sparc_dyn_relocs *q; 779 780 for (q = edir->dyn_relocs; q != NULL; q = q->next) 781 if (q->sec == p->sec) 782 { 783 q->pc_count += p->pc_count; 784 q->count += p->count; 785 *pp = p->next; 786 break; 787 } 788 if (q == NULL) 789 pp = &p->next; 790 } 791 *pp = edir->dyn_relocs; 792 } 793 794 edir->dyn_relocs = eind->dyn_relocs; 795 eind->dyn_relocs = NULL; 796 } 797 798 if (ind->root.type == bfd_link_hash_indirect 799 && dir->got.refcount <= 0) 800 { 801 edir->tls_type = eind->tls_type; 802 eind->tls_type = GOT_UNKNOWN; 803 } 804 _bfd_elf_link_hash_copy_indirect (bed, dir, ind); 805 } 806 807 static int 808 elf32_sparc_tls_transition (info, abfd, r_type, is_local) 809 struct bfd_link_info *info; 810 bfd *abfd; 811 int r_type; 812 int is_local; 813 { 814 if (r_type == R_SPARC_TLS_GD_HI22 815 && ! elf32_sparc_tdata (abfd)->has_tlsgd) 816 r_type = R_SPARC_REV32; 817 818 if (info->shared) 819 return r_type; 820 821 switch (r_type) 822 { 823 case R_SPARC_TLS_GD_HI22: 824 if (is_local) 825 return R_SPARC_TLS_LE_HIX22; 826 return R_SPARC_TLS_IE_HI22; 827 case R_SPARC_TLS_GD_LO10: 828 if (is_local) 829 return R_SPARC_TLS_LE_LOX10; 830 return R_SPARC_TLS_IE_LO10; 831 case R_SPARC_TLS_IE_HI22: 832 if (is_local) 833 return R_SPARC_TLS_LE_HIX22; 834 return r_type; 835 case R_SPARC_TLS_IE_LO10: 836 if (is_local) 837 return R_SPARC_TLS_LE_LOX10; 838 return r_type; 839 case R_SPARC_TLS_LDM_HI22: 840 return R_SPARC_TLS_LE_HIX22; 841 case R_SPARC_TLS_LDM_LO10: 842 return R_SPARC_TLS_LE_LOX10; 843 } 844 845 return r_type; 846 } 847 343 848 /* Look through the relocs for a section during the first phase, and 344 849 allocate space in the global offset table or procedure linkage 345 850 table. */ 346 851 347 static b oolean852 static bfd_boolean 348 853 elf32_sparc_check_relocs (abfd, info, sec, relocs) 349 854 bfd *abfd; … … 352 857 const Elf_Internal_Rela *relocs; 353 858 { 354 bfd *dynobj;859 struct elf32_sparc_link_hash_table *htab; 355 860 Elf_Internal_Shdr *symtab_hdr; 356 861 struct elf_link_hash_entry **sym_hashes; … … 358 863 const Elf_Internal_Rela *rel; 359 864 const Elf_Internal_Rela *rel_end; 360 asection *sgot;361 asection *srelgot;362 865 asection *sreloc; 866 bfd_boolean checked_tlsgd = FALSE; 363 867 364 868 if (info->relocateable) 365 return true;366 367 dynobj = elf_hash_table (info)->dynobj;869 return TRUE; 870 871 htab = elf32_sparc_hash_table (info); 368 872 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; 369 873 sym_hashes = elf_sym_hashes (abfd); 370 874 local_got_offsets = elf_local_got_offsets (abfd); 371 875 372 sgot = NULL;373 srelgot = NULL;374 876 sreloc = NULL; 375 877 … … 377 879 for (rel = relocs; rel < rel_end; rel++) 378 880 { 881 unsigned int r_type; 379 882 unsigned long r_symndx; 380 883 struct elf_link_hash_entry *h; 381 884 382 885 r_symndx = ELF32_R_SYM (rel->r_info); 886 r_type = ELF32_R_TYPE (rel->r_info); 887 888 if (r_symndx >= NUM_SHDR_ENTRIES (symtab_hdr)) 889 { 890 (*_bfd_error_handler) (_("%s: bad symbol index: %d"), 891 bfd_archive_filename (abfd), 892 r_symndx); 893 return FALSE; 894 } 895 383 896 if (r_symndx < symtab_hdr->sh_info) 384 897 h = NULL; … … 386 899 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 387 900 388 switch (ELF32_R_TYPE (rel->r_info)) 389 { 901 /* Compatibility with old R_SPARC_REV32 reloc conflicting 902 with R_SPARC_TLS_GD_HI22. */ 903 if (! checked_tlsgd) 904 switch (r_type) 905 { 906 case R_SPARC_TLS_GD_HI22: 907 { 908 const Elf_Internal_Rela *relt; 909 910 for (relt = rel + 1; relt < rel_end; relt++) 911 if (ELF32_R_TYPE (relt->r_info) == R_SPARC_TLS_GD_LO10 912 || ELF32_R_TYPE (relt->r_info) == R_SPARC_TLS_GD_ADD 913 || ELF32_R_TYPE (relt->r_info) == R_SPARC_TLS_GD_CALL) 914 break; 915 checked_tlsgd = TRUE; 916 elf32_sparc_tdata (abfd)->has_tlsgd = relt < rel_end; 917 } 918 break; 919 case R_SPARC_TLS_GD_LO10: 920 case R_SPARC_TLS_GD_ADD: 921 case R_SPARC_TLS_GD_CALL: 922 checked_tlsgd = TRUE; 923 elf32_sparc_tdata (abfd)->has_tlsgd = TRUE; 924 break; 925 } 926 927 r_type = elf32_sparc_tls_transition (info, abfd, r_type, h == NULL); 928 switch (r_type) 929 { 930 case R_SPARC_TLS_LDM_HI22: 931 case R_SPARC_TLS_LDM_LO10: 932 htab->tls_ldm_got.refcount += 1; 933 break; 934 935 case R_SPARC_TLS_LE_HIX22: 936 case R_SPARC_TLS_LE_LOX10: 937 if (info->shared) 938 goto r_sparc_plt32; 939 break; 940 941 case R_SPARC_TLS_IE_HI22: 942 case R_SPARC_TLS_IE_LO10: 943 if (info->shared) 944 info->flags |= DF_STATIC_TLS; 945 /* Fall through */ 946 390 947 case R_SPARC_GOT10: 391 948 case R_SPARC_GOT13: 392 949 case R_SPARC_GOT22: 950 case R_SPARC_TLS_GD_HI22: 951 case R_SPARC_TLS_GD_LO10: 393 952 /* This symbol requires a global offset table entry. */ 394 395 if (dynobj == NULL) 396 { 397 /* Create the .got section. */ 398 elf_hash_table (info)->dynobj = dynobj = abfd; 399 if (! _bfd_elf_create_got_section (dynobj, info)) 400 return false; 401 } 402 403 if (sgot == NULL) 404 { 405 sgot = bfd_get_section_by_name (dynobj, ".got"); 406 BFD_ASSERT (sgot != NULL); 407 } 408 409 if (srelgot == NULL 410 && (h != NULL || info->shared)) 411 { 412 srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); 413 if (srelgot == NULL) 414 { 415 srelgot = bfd_make_section (dynobj, ".rela.got"); 416 if (srelgot == NULL 417 || ! bfd_set_section_flags (dynobj, srelgot, 418 (SEC_ALLOC 419 | SEC_LOAD 420 | SEC_HAS_CONTENTS 421 | SEC_IN_MEMORY 422 | SEC_LINKER_CREATED 423 | SEC_READONLY)) 424 || ! bfd_set_section_alignment (dynobj, srelgot, 2)) 425 return false; 426 } 427 } 428 429 if (h != NULL) 430 { 431 if (h->got.offset != (bfd_vma) -1) 432 { 433 /* We have already allocated space in the .got. */ 434 break; 435 } 436 h->got.offset = sgot->_raw_size; 437 438 /* Make sure this symbol is output as a dynamic symbol. */ 439 if (h->dynindx == -1) 440 { 441 if (! bfd_elf32_link_record_dynamic_symbol (info, h)) 442 return false; 443 } 444 445 srelgot->_raw_size += sizeof (Elf32_External_Rela); 953 { 954 int tls_type, old_tls_type; 955 956 switch (r_type) 957 { 958 default: 959 case R_SPARC_GOT10: 960 case R_SPARC_GOT13: 961 case R_SPARC_GOT22: 962 tls_type = GOT_NORMAL; 963 break; 964 case R_SPARC_TLS_GD_HI22: 965 case R_SPARC_TLS_GD_LO10: 966 tls_type = GOT_TLS_GD; 967 break; 968 case R_SPARC_TLS_IE_HI22: 969 case R_SPARC_TLS_IE_LO10: 970 tls_type = GOT_TLS_IE; 971 break; 972 } 973 974 if (h != NULL) 975 { 976 h->got.refcount += 1; 977 old_tls_type = elf32_sparc_hash_entry(h)->tls_type; 978 } 979 else 980 { 981 bfd_signed_vma *local_got_refcounts; 982 983 /* This is a global offset table entry for a local symbol. */ 984 local_got_refcounts = elf_local_got_refcounts (abfd); 985 if (local_got_refcounts == NULL) 986 { 987 bfd_size_type size; 988 989 size = symtab_hdr->sh_info; 990 size *= (sizeof (bfd_signed_vma) + sizeof(char)); 991 local_got_refcounts = ((bfd_signed_vma *) 992 bfd_zalloc (abfd, size)); 993 if (local_got_refcounts == NULL) 994 return FALSE; 995 elf_local_got_refcounts (abfd) = local_got_refcounts; 996 elf32_sparc_local_got_tls_type (abfd) 997 = (char *) (local_got_refcounts + symtab_hdr->sh_info); 998 } 999 local_got_refcounts[r_symndx] += 1; 1000 old_tls_type = elf32_sparc_local_got_tls_type (abfd) [r_symndx]; 1001 } 1002 1003 /* If a TLS symbol is accessed using IE at least once, 1004 there is no point to use dynamic model for it. */ 1005 if (old_tls_type != tls_type && old_tls_type != GOT_UNKNOWN 1006 && (old_tls_type != GOT_TLS_GD 1007 || tls_type != GOT_TLS_IE)) 1008 { 1009 if (old_tls_type == GOT_TLS_IE && tls_type == GOT_TLS_GD) 1010 tls_type = old_tls_type; 1011 else 1012 { 1013 (*_bfd_error_handler) 1014 (_("%s: `%s' accessed both as normal and thread local symbol"), 1015 bfd_archive_filename (abfd), 1016 h ? h->root.root.string : "<local>"); 1017 return FALSE; 1018 } 1019 } 1020 1021 if (old_tls_type != tls_type) 1022 { 1023 if (h != NULL) 1024 elf32_sparc_hash_entry (h)->tls_type = tls_type; 1025 else 1026 elf32_sparc_local_got_tls_type (abfd) [r_symndx] = tls_type; 1027 } 1028 } 1029 1030 if (htab->elf.dynobj == NULL) 1031 htab->elf.dynobj = abfd; 1032 if (!create_got_section (htab->elf.dynobj, info)) 1033 return FALSE; 1034 break; 1035 1036 case R_SPARC_TLS_GD_CALL: 1037 case R_SPARC_TLS_LDM_CALL: 1038 if (info->shared) 1039 { 1040 /* These are basically R_SPARC_TLS_WPLT30 relocs against 1041 __tls_get_addr. */ 1042 struct bfd_link_hash_entry *bh = NULL; 1043 if (! _bfd_generic_link_add_one_symbol (info, abfd, 1044 "__tls_get_addr", 0, 1045 bfd_und_section_ptr, 0, 1046 NULL, FALSE, FALSE, 1047 &bh)) 1048 return FALSE; 1049 h = (struct elf_link_hash_entry *) bh; 446 1050 } 447 1051 else 448 { 449 /* This is a global offset table entry for a local 450 symbol. */ 451 if (local_got_offsets == NULL) 452 { 453 size_t size; 454 register unsigned int i; 455 456 size = symtab_hdr->sh_info * sizeof (bfd_vma); 457 local_got_offsets = (bfd_vma *) bfd_alloc (abfd, size); 458 if (local_got_offsets == NULL) 459 return false; 460 elf_local_got_offsets (abfd) = local_got_offsets; 461 for (i = 0; i < symtab_hdr->sh_info; i++) 462 local_got_offsets[i] = (bfd_vma) -1; 463 } 464 if (local_got_offsets[r_symndx] != (bfd_vma) -1) 465 { 466 /* We have already allocated space in the .got. */ 467 break; 468 } 469 local_got_offsets[r_symndx] = sgot->_raw_size; 470 471 if (info->shared) 472 { 473 /* If we are generating a shared object, we need to 474 output a R_SPARC_RELATIVE reloc so that the 475 dynamic linker can adjust this GOT entry. */ 476 srelgot->_raw_size += sizeof (Elf32_External_Rela); 477 } 478 } 479 480 sgot->_raw_size += 4; 481 482 /* If the .got section is more than 0x1000 bytes, we add 483 0x1000 to the value of _GLOBAL_OFFSET_TABLE_, so that 13 484 bit relocations have a greater chance of working. */ 485 if (sgot->_raw_size >= 0x1000 486 && elf_hash_table (info)->hgot->root.u.def.value == 0) 487 elf_hash_table (info)->hgot->root.u.def.value = 0x1000; 488 489 break; 490 1052 break; 1053 /* Fall through */ 1054 1055 case R_SPARC_PLT32: 491 1056 case R_SPARC_WPLT30: 492 1057 /* This symbol requires a procedure linkage table entry. We 493 494 495 496 1058 actually build the entry in adjust_dynamic_symbol, 1059 because this might be a case of linking PIC code without 1060 linking in any dynamic objects, in which case we don't 1061 need to generate a procedure linkage table after all. */ 497 1062 498 1063 if (h == NULL) 499 1064 { 500 1065 /* The Solaris native assembler will generate a WPLT30 501 reloc for a local symbol if you assemble a call from 502 one section to another when using -K pic. We treat 503 it as WDISP30. */ 1066 reloc for a local symbol if you assemble a call from 1067 one section to another when using -K pic. We treat 1068 it as WDISP30. */ 1069 if (ELF32_R_TYPE (rel->r_info) == R_SPARC_PLT32) 1070 goto r_sparc_plt32; 504 1071 break; 505 1072 } 506 1073 507 /* Make sure this symbol is output as a dynamic symbol. */508 if (h->dynindx == -1)509 {510 if (! bfd_elf32_link_record_dynamic_symbol (info, h))511 return false;512 }513 514 1074 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_PLT; 515 1075 1076 if (ELF32_R_TYPE (rel->r_info) == R_SPARC_PLT32) 1077 goto r_sparc_plt32; 1078 h->plt.refcount += 1; 516 1079 break; 517 1080 … … 525 1088 break; 526 1089 /* Fall through. */ 1090 527 1091 case R_SPARC_DISP8: 528 1092 case R_SPARC_DISP16: … … 532 1096 case R_SPARC_WDISP19: 533 1097 case R_SPARC_WDISP16: 534 if (h != NULL)535 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF;536 537 /* If we are linking with -Bsymbolic, we do not need to copy538 a PC relative reloc against a global symbol which is539 defined in an object we are including in the link (i.e.,540 DEF_REGULAR is set). FIXME: At this point we have not541 seen all the input files, so it is possible that542 DEF_REGULAR is not set now but will be set later (it is543 never cleared). This needs to be handled as in544 elf32-i386.c. */545 if (h == NULL546 || (info->symbolic547 && (h->elf_link_hash_flags548 & ELF_LINK_HASH_DEF_REGULAR) != 0))549 break;550 /* Fall through. */551 1098 case R_SPARC_8: 552 1099 case R_SPARC_16: … … 558 1105 case R_SPARC_UA16: 559 1106 case R_SPARC_UA32: 560 case R_SPARC_UA64:561 1107 if (h != NULL) 562 1108 h->elf_link_hash_flags |= ELF_LINK_NON_GOT_REF; 563 1109 564 if (info->shared) 565 { 1110 r_sparc_plt32: 1111 if (h != NULL && !info->shared) 1112 { 1113 /* We may need a .plt entry if the function this reloc 1114 refers to is in a shared lib. */ 1115 h->plt.refcount += 1; 1116 } 1117 1118 /* If we are creating a shared library, and this is a reloc 1119 against a global symbol, or a non PC relative reloc 1120 against a local symbol, then we need to copy the reloc 1121 into the shared library. However, if we are linking with 1122 -Bsymbolic, we do not need to copy a reloc against a 1123 global symbol which is defined in an object we are 1124 including in the link (i.e., DEF_REGULAR is set). At 1125 this point we have not seen all the input files, so it is 1126 possible that DEF_REGULAR is not set now but will be set 1127 later (it is never cleared). In case of a weak definition, 1128 DEF_REGULAR may be cleared later by a strong definition in 1129 a shared library. We account for that possibility below by 1130 storing information in the relocs_copied field of the hash 1131 table entry. A similar situation occurs when creating 1132 shared libraries and symbol visibility changes render the 1133 symbol local. 1134 1135 If on the other hand, we are creating an executable, we 1136 may need to keep relocations for symbols satisfied by a 1137 dynamic library if we manage to avoid copy relocs for the 1138 symbol. */ 1139 if ((info->shared 1140 && (sec->flags & SEC_ALLOC) != 0 1141 && (! _bfd_sparc_elf_howto_table[r_type].pc_relative 1142 || (h != NULL 1143 && (! info->symbolic 1144 || h->root.type == bfd_link_hash_defweak 1145 || (h->elf_link_hash_flags 1146 & ELF_LINK_HASH_DEF_REGULAR) == 0)))) 1147 || (!info->shared 1148 && (sec->flags & SEC_ALLOC) != 0 1149 && h != NULL 1150 && (h->root.type == bfd_link_hash_defweak 1151 || (h->elf_link_hash_flags 1152 & ELF_LINK_HASH_DEF_REGULAR) == 0))) 1153 { 1154 struct elf32_sparc_dyn_relocs *p; 1155 struct elf32_sparc_dyn_relocs **head; 1156 566 1157 /* When creating a shared object, we must copy these 567 568 1158 relocs into the output file. We create a reloc 1159 section in dynobj and make room for the reloc. */ 569 1160 if (sreloc == NULL) 570 1161 { 571 1162 const char *name; 1163 bfd *dynobj; 572 1164 573 1165 name = (bfd_elf_string_from_elf_section … … 576 1168 elf_section_data (sec)->rel_hdr.sh_name)); 577 1169 if (name == NULL) 578 return false;1170 return FALSE; 579 1171 580 1172 BFD_ASSERT (strncmp (name, ".rela", 5) == 0 581 1173 && strcmp (bfd_get_section_name (abfd, sec), 582 1174 name + 5) == 0); 1175 1176 if (htab->elf.dynobj == NULL) 1177 htab->elf.dynobj = abfd; 1178 dynobj = htab->elf.dynobj; 583 1179 584 1180 sreloc = bfd_get_section_by_name (dynobj, name); … … 595 1191 || ! bfd_set_section_flags (dynobj, sreloc, flags) 596 1192 || ! bfd_set_section_alignment (dynobj, sreloc, 2)) 597 return false;1193 return FALSE; 598 1194 } 1195 elf_section_data (sec)->sreloc = sreloc; 599 1196 } 600 1197 601 sreloc->_raw_size += sizeof (Elf32_External_Rela); 1198 /* If this is a global symbol, we count the number of 1199 relocations we need for this symbol. */ 1200 if (h != NULL) 1201 head = &((struct elf32_sparc_link_hash_entry *) h)->dyn_relocs; 1202 else 1203 { 1204 /* Track dynamic relocs needed for local syms too. 1205 We really need local syms available to do this 1206 easily. Oh well. */ 1207 1208 asection *s; 1209 s = bfd_section_from_r_symndx (abfd, &htab->sym_sec, 1210 sec, r_symndx); 1211 if (s == NULL) 1212 return FALSE; 1213 1214 head = ((struct elf32_sparc_dyn_relocs **) 1215 &elf_section_data (s)->local_dynrel); 1216 } 1217 1218 p = *head; 1219 if (p == NULL || p->sec != sec) 1220 { 1221 bfd_size_type amt = sizeof *p; 1222 p = ((struct elf32_sparc_dyn_relocs *) 1223 bfd_alloc (htab->elf.dynobj, amt)); 1224 if (p == NULL) 1225 return FALSE; 1226 p->next = *head; 1227 *head = p; 1228 p->sec = sec; 1229 p->count = 0; 1230 p->pc_count = 0; 1231 } 1232 1233 p->count += 1; 1234 if (_bfd_sparc_elf_howto_table[r_type].pc_relative) 1235 p->pc_count += 1; 602 1236 } 603 1237 604 1238 break; 605 1239 606 607 608 return false;609 610 611 612 613 return false;614 1240 case R_SPARC_GNU_VTINHERIT: 1241 if (!_bfd_elf32_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) 1242 return FALSE; 1243 break; 1244 1245 case R_SPARC_GNU_VTENTRY: 1246 if (!_bfd_elf32_gc_record_vtentry (abfd, sec, h, rel->r_addend)) 1247 return FALSE; 1248 break; 615 1249 616 1250 default: … … 619 1253 } 620 1254 621 return true;1255 return TRUE; 622 1256 } 623 1257 624 1258 static asection * 625 elf32_sparc_gc_mark_hook ( abfd, info, rel, h, sym)626 bfd *abfd;1259 elf32_sparc_gc_mark_hook (sec, info, rel, h, sym) 1260 asection *sec; 627 1261 struct bfd_link_info *info ATTRIBUTE_UNUSED; 628 1262 Elf_Internal_Rela *rel; … … 630 1264 Elf_Internal_Sym *sym; 631 1265 { 632 633 1266 if (h != NULL) 634 1267 { … … 637 1270 case R_SPARC_GNU_VTINHERIT: 638 1271 case R_SPARC_GNU_VTENTRY: 639 1272 break; 640 1273 641 1274 default: 642 643 644 645 646 647 648 649 1275 switch (h->root.type) 1276 { 1277 case bfd_link_hash_defined: 1278 case bfd_link_hash_defweak: 1279 return h->root.u.def.section; 1280 1281 case bfd_link_hash_common: 1282 return h->root.u.c.p->section; 650 1283 651 1284 default: 652 1285 break; 653 1286 } 654 1287 } 655 1288 } 656 1289 else 657 { 658 if (!(elf_bad_symtab (abfd) 659 && ELF_ST_BIND (sym->st_info) != STB_LOCAL) 660 && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE) 661 && sym->st_shndx != SHN_COMMON)) 662 { 663 return bfd_section_from_elf_index (abfd, sym->st_shndx); 664 } 665 } 1290 return bfd_section_from_elf_index (sec->owner, sym->st_shndx); 666 1291 667 1292 return NULL; … … 669 1294 670 1295 /* Update the got entry reference counts for the section being removed. */ 671 static b oolean1296 static bfd_boolean 672 1297 elf32_sparc_gc_sweep_hook (abfd, info, sec, relocs) 673 1298 bfd *abfd; … … 676 1301 const Elf_Internal_Rela *relocs; 677 1302 { 678 679 1303 Elf_Internal_Shdr *symtab_hdr; 680 1304 struct elf_link_hash_entry **sym_hashes; 681 1305 bfd_signed_vma *local_got_refcounts; 682 1306 const Elf_Internal_Rela *rel, *relend; 683 unsigned long r_symndx; 684 struct elf_link_hash_entry *h;1307 1308 elf_section_data (sec)->local_dynrel = NULL; 685 1309 686 1310 symtab_hdr = &elf_tdata (abfd)->symtab_hdr; … … 690 1314 relend = relocs + sec->reloc_count; 691 1315 for (rel = relocs; rel < relend; rel++) 692 switch (ELF32_R_TYPE (rel->r_info)) 693 { 694 case R_SPARC_GOT10: 695 case R_SPARC_GOT13: 696 case R_SPARC_GOT22: 697 r_symndx = ELF32_R_SYM (rel->r_info); 698 if (r_symndx >= symtab_hdr->sh_info) 699 { 700 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 701 if (h->got.refcount > 0) 702 h->got.refcount--; 703 } 704 else 705 { 706 if (local_got_refcounts[r_symndx] > 0) 707 local_got_refcounts[r_symndx]--; 708 } 709 break; 710 711 case R_SPARC_PLT32: 712 case R_SPARC_HIPLT22: 713 case R_SPARC_LOPLT10: 714 case R_SPARC_PCPLT32: 715 case R_SPARC_PCPLT10: 716 r_symndx = ELF32_R_SYM (rel->r_info); 717 if (r_symndx >= symtab_hdr->sh_info) 718 { 719 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 720 if (h->plt.refcount > 0) 721 h->plt.refcount--; 722 } 723 break; 724 725 default: 726 break; 727 } 728 729 return true; 1316 { 1317 unsigned long r_symndx; 1318 unsigned int r_type; 1319 struct elf_link_hash_entry *h = NULL; 1320 1321 r_symndx = ELF32_R_SYM (rel->r_info); 1322 if (r_symndx >= symtab_hdr->sh_info) 1323 { 1324 struct elf32_sparc_link_hash_entry *eh; 1325 struct elf32_sparc_dyn_relocs **pp; 1326 struct elf32_sparc_dyn_relocs *p; 1327 1328 h = sym_hashes[r_symndx - symtab_hdr->sh_info]; 1329 eh = (struct elf32_sparc_link_hash_entry *) h; 1330 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) 1331 if (p->sec == sec) 1332 { 1333 /* Everything must go for SEC. */ 1334 *pp = p->next; 1335 break; 1336 } 1337 } 1338 1339 r_type = ELF32_R_TYPE (rel->r_info); 1340 r_type = elf32_sparc_tls_transition (info, abfd, r_type, h != NULL); 1341 switch (r_type) 1342 { 1343 case R_SPARC_TLS_LDM_HI22: 1344 case R_SPARC_TLS_LDM_LO10: 1345 if (elf32_sparc_hash_table (info)->tls_ldm_got.refcount > 0) 1346 elf32_sparc_hash_table (info)->tls_ldm_got.refcount -= 1; 1347 break; 1348 1349 case R_SPARC_TLS_GD_HI22: 1350 case R_SPARC_TLS_GD_LO10: 1351 case R_SPARC_TLS_IE_HI22: 1352 case R_SPARC_TLS_IE_LO10: 1353 case R_SPARC_GOT10: 1354 case R_SPARC_GOT13: 1355 case R_SPARC_GOT22: 1356 if (h != NULL) 1357 { 1358 if (h->got.refcount > 0) 1359 h->got.refcount--; 1360 } 1361 else 1362 { 1363 if (local_got_refcounts[r_symndx] > 0) 1364 local_got_refcounts[r_symndx]--; 1365 } 1366 break; 1367 1368 case R_SPARC_PC10: 1369 case R_SPARC_PC22: 1370 if (h != NULL 1371 && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) 1372 break; 1373 /* Fall through. */ 1374 1375 case R_SPARC_DISP8: 1376 case R_SPARC_DISP16: 1377 case R_SPARC_DISP32: 1378 case R_SPARC_WDISP30: 1379 case R_SPARC_WDISP22: 1380 case R_SPARC_WDISP19: 1381 case R_SPARC_WDISP16: 1382 case R_SPARC_8: 1383 case R_SPARC_16: 1384 case R_SPARC_32: 1385 case R_SPARC_HI22: 1386 case R_SPARC_22: 1387 case R_SPARC_13: 1388 case R_SPARC_LO10: 1389 case R_SPARC_UA16: 1390 case R_SPARC_UA32: 1391 case R_SPARC_PLT32: 1392 if (info->shared) 1393 break; 1394 /* Fall through. */ 1395 1396 case R_SPARC_WPLT30: 1397 if (h != NULL) 1398 { 1399 if (h->plt.refcount > 0) 1400 h->plt.refcount--; 1401 } 1402 break; 1403 1404 default: 1405 break; 1406 } 1407 } 1408 1409 return TRUE; 730 1410 } 731 1411 … … 736 1416 understand. */ 737 1417 738 static b oolean1418 static bfd_boolean 739 1419 elf32_sparc_adjust_dynamic_symbol (info, h) 740 1420 struct bfd_link_info *info; 741 1421 struct elf_link_hash_entry *h; 742 1422 { 743 bfd *dynobj; 1423 struct elf32_sparc_link_hash_table *htab; 1424 struct elf32_sparc_link_hash_entry * eh; 1425 struct elf32_sparc_dyn_relocs *p; 744 1426 asection *s; 745 1427 unsigned int power_of_two; 746 1428 747 dynobj = elf_hash_table (info)->dynobj;1429 htab = elf32_sparc_hash_table (info); 748 1430 749 1431 /* Make sure we know what is going on here. */ 750 BFD_ASSERT ( dynobj != NULL1432 BFD_ASSERT (htab->elf.dynobj != NULL 751 1433 && ((h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) 752 1434 || h->weakdef != NULL … … 772 1454 && (h->root.u.def.section->flags & SEC_CODE) != 0)) 773 1455 { 774 if (! elf_hash_table (info)->dynamic_sections_created 775 || ((!info->shared || info->symbolic || h->dynindx == -1) 776 && (h->elf_link_hash_flags 777 & ELF_LINK_HASH_DEF_REGULAR) != 0)) 1456 if (h->plt.refcount <= 0 1457 || (! info->shared 1458 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0 1459 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0 1460 && h->root.type != bfd_link_hash_undefweak 1461 && h->root.type != bfd_link_hash_undefined)) 778 1462 { 779 1463 /* This case can occur if we saw a WPLT30 reloc in an input 780 file, but none of the input files were dynamic objects. 781 Or, when linking the main application or a -Bsymbolic 782 shared library against PIC code. Or when a global symbol 783 has been made private, e.g. via versioning. 784 785 In these cases we know what value the symbol will resolve 786 to, so we don't actually need to build a procedure linkage 787 table, and we can just do a WDISP30 reloc instead. */ 788 1464 file, but the symbol was never referred to by a dynamic 1465 object, or if all references were garbage collected. In 1466 such a case, we don't actually need to build a procedure 1467 linkage table, and we can just do a WDISP30 reloc instead. */ 1468 h->plt.offset = (bfd_vma) -1; 789 1469 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 790 return true; 791 } 792 793 s = bfd_get_section_by_name (dynobj, ".plt"); 794 BFD_ASSERT (s != NULL); 795 796 /* The first four entries in .plt are reserved. */ 797 if (s->_raw_size == 0) 798 s->_raw_size = 4 * PLT_ENTRY_SIZE; 799 800 /* The procedure linkage table has a maximum size. */ 801 if (s->_raw_size >= 0x400000) 802 { 803 bfd_set_error (bfd_error_bad_value); 804 return false; 805 } 806 807 /* If this symbol is not defined in a regular file, and we are 808 not generating a shared library, then set the symbol to this 809 location in the .plt. This is required to make function 810 pointers compare as equal between the normal executable and 811 the shared library. */ 812 if (! info->shared 813 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 814 { 815 h->root.u.def.section = s; 816 h->root.u.def.value = s->_raw_size; 817 } 818 819 h->plt.offset = s->_raw_size; 820 821 /* Make room for this entry. */ 822 s->_raw_size += PLT_ENTRY_SIZE; 823 824 /* We also need to make an entry in the .rela.plt section. */ 825 826 s = bfd_get_section_by_name (dynobj, ".rela.plt"); 827 BFD_ASSERT (s != NULL); 828 s->_raw_size += sizeof (Elf32_External_Rela); 829 830 return true; 831 } 1470 } 1471 1472 return TRUE; 1473 } 1474 else 1475 h->plt.offset = (bfd_vma) -1; 832 1476 833 1477 /* If this is a weak symbol, and there is a real definition, the … … 840 1484 h->root.u.def.section = h->weakdef->root.u.def.section; 841 1485 h->root.u.def.value = h->weakdef->root.u.def.value; 842 return true;1486 return TRUE; 843 1487 } 844 1488 … … 851 1495 be handled correctly by relocate_section. */ 852 1496 if (info->shared) 853 return true;1497 return TRUE; 854 1498 855 1499 /* If there are no references to this symbol that do not use the 856 1500 GOT, we don't need to generate a copy reloc. */ 857 1501 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0) 858 return true; 1502 return TRUE; 1503 1504 eh = (struct elf32_sparc_link_hash_entry *) h; 1505 for (p = eh->dyn_relocs; p != NULL; p = p->next) 1506 { 1507 s = p->sec->output_section; 1508 if (s != NULL && (s->flags & SEC_READONLY) != 0) 1509 break; 1510 } 1511 1512 /* If we didn't find any dynamic relocs in read-only sections, then 1513 we'll be keeping the dynamic relocs and avoiding the copy reloc. */ 1514 if (p == NULL) 1515 { 1516 h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; 1517 return TRUE; 1518 } 859 1519 860 1520 /* We must allocate the symbol in our .dynbss section, which will … … 868 1528 same memory location for the variable. */ 869 1529 870 s = bfd_get_section_by_name (dynobj, ".dynbss");871 BFD_ASSERT (s != NULL);872 873 1530 /* We must generate a R_SPARC_COPY reloc to tell the dynamic linker 874 1531 to copy the initial value out of the dynamic object and into the … … 877 1534 if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) 878 1535 { 879 asection *srel; 880 881 srel = bfd_get_section_by_name (dynobj, ".rela.bss"); 882 BFD_ASSERT (srel != NULL); 883 srel->_raw_size += sizeof (Elf32_External_Rela); 1536 htab->srelbss->_raw_size += sizeof (Elf32_External_Rela); 884 1537 h->elf_link_hash_flags |= ELF_LINK_HASH_NEEDS_COPY; 885 1538 } … … 892 1545 893 1546 /* Apply the required alignment. */ 1547 s = htab->sdynbss; 894 1548 s->_raw_size = BFD_ALIGN (s->_raw_size, 895 1549 (bfd_size_type) (1 << power_of_two)); … … 897 1551 { 898 1552 if (! bfd_set_section_alignment (dynobj, s, power_of_two)) 899 return false;1553 return FALSE; 900 1554 } 901 1555 … … 907 1561 s->_raw_size += h->size; 908 1562 909 return true;1563 return TRUE; 910 1564 } 911 1565 1566 /* This is the condition under which finish_dynamic_symbol will be called 1567 from elflink.h. If elflink.h doesn't call our finish_dynamic_symbol 1568 routine, we'll need to do something about initializing any .plt and .got 1569 entries in relocate_section. */ 1570 #define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \ 1571 ((DYN) \ 1572 && ((INFO)->shared \ 1573 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \ 1574 && ((H)->dynindx != -1 \ 1575 || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) 1576 1577 /* Allocate space in .plt, .got and associated reloc sections for 1578 dynamic relocs. */ 1579 1580 static bfd_boolean 1581 allocate_dynrelocs (h, inf) 1582 struct elf_link_hash_entry *h; 1583 PTR inf; 1584 { 1585 struct bfd_link_info *info; 1586 struct elf32_sparc_link_hash_table *htab; 1587 struct elf32_sparc_link_hash_entry *eh; 1588 struct elf32_sparc_dyn_relocs *p; 1589 1590 if (h->root.type == bfd_link_hash_indirect) 1591 return TRUE; 1592 1593 if (h->root.type == bfd_link_hash_warning) 1594 /* When warning symbols are created, they **replace** the "real" 1595 entry in the hash table, thus we never get to see the real 1596 symbol in a hash traversal. So look at it now. */ 1597 h = (struct elf_link_hash_entry *) h->root.u.i.link; 1598 1599 info = (struct bfd_link_info *) inf; 1600 htab = elf32_sparc_hash_table (info); 1601 1602 if (htab->elf.dynamic_sections_created 1603 && h->plt.refcount > 0) 1604 { 1605 /* Make sure this symbol is output as a dynamic symbol. 1606 Undefined weak syms won't yet be marked as dynamic. */ 1607 if (h->dynindx == -1 1608 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 1609 { 1610 if (! bfd_elf32_link_record_dynamic_symbol (info, h)) 1611 return FALSE; 1612 } 1613 1614 if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h)) 1615 { 1616 asection *s = htab->splt; 1617 1618 /* The first four entries in .plt are reserved. */ 1619 if (s->_raw_size == 0) 1620 s->_raw_size = 4 * PLT_ENTRY_SIZE; 1621 1622 /* The procedure linkage table has a maximum size. */ 1623 if (s->_raw_size >= 0x400000) 1624 { 1625 bfd_set_error (bfd_error_bad_value); 1626 return FALSE; 1627 } 1628 1629 h->plt.offset = s->_raw_size; 1630 1631 /* If this symbol is not defined in a regular file, and we are 1632 not generating a shared library, then set the symbol to this 1633 location in the .plt. This is required to make function 1634 pointers compare as equal between the normal executable and 1635 the shared library. */ 1636 if (! info->shared 1637 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 1638 { 1639 h->root.u.def.section = s; 1640 h->root.u.def.value = h->plt.offset; 1641 } 1642 1643 /* Make room for this entry. */ 1644 s->_raw_size += PLT_ENTRY_SIZE; 1645 1646 /* We also need to make an entry in the .rela.plt section. */ 1647 htab->srelplt->_raw_size += sizeof (Elf32_External_Rela); 1648 } 1649 else 1650 { 1651 h->plt.offset = (bfd_vma) -1; 1652 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 1653 } 1654 } 1655 else 1656 { 1657 h->plt.offset = (bfd_vma) -1; 1658 h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT; 1659 } 1660 1661 /* If R_SPARC_TLS_IE_{HI22,LO10} symbol is now local to the binary, 1662 make it a R_SPARC_TLS_LE_{HI22,LO10} requiring no TLS entry. */ 1663 if (h->got.refcount > 0 1664 && !info->shared 1665 && h->dynindx == -1 1666 && elf32_sparc_hash_entry(h)->tls_type == GOT_TLS_IE) 1667 h->got.offset = (bfd_vma) -1; 1668 else if (h->got.refcount > 0) 1669 { 1670 asection *s; 1671 bfd_boolean dyn; 1672 int tls_type = elf32_sparc_hash_entry(h)->tls_type; 1673 1674 /* Make sure this symbol is output as a dynamic symbol. 1675 Undefined weak syms won't yet be marked as dynamic. */ 1676 if (h->dynindx == -1 1677 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 1678 { 1679 if (! bfd_elf32_link_record_dynamic_symbol (info, h)) 1680 return FALSE; 1681 } 1682 1683 s = htab->sgot; 1684 h->got.offset = s->_raw_size; 1685 s->_raw_size += 4; 1686 /* R_SPARC_TLS_GD_HI{22,LO10} needs 2 consecutive GOT slots. */ 1687 if (tls_type == GOT_TLS_GD) 1688 s->_raw_size += 4; 1689 dyn = htab->elf.dynamic_sections_created; 1690 /* R_SPARC_TLS_IE_{HI22,LO10} needs one dynamic relocation, 1691 R_SPARC_TLS_GD_{HI22,LO10} needs one if local symbol and two if 1692 global. */ 1693 if ((tls_type == GOT_TLS_GD && h->dynindx == -1) 1694 || tls_type == GOT_TLS_IE) 1695 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela); 1696 else if (tls_type == GOT_TLS_GD) 1697 htab->srelgot->_raw_size += 2 * sizeof (Elf32_External_Rela); 1698 else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)) 1699 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela); 1700 } 1701 else 1702 h->got.offset = (bfd_vma) -1; 1703 1704 eh = (struct elf32_sparc_link_hash_entry *) h; 1705 if (eh->dyn_relocs == NULL) 1706 return TRUE; 1707 1708 /* In the shared -Bsymbolic case, discard space allocated for 1709 dynamic pc-relative relocs against symbols which turn out to be 1710 defined in regular objects. For the normal shared case, discard 1711 space for pc-relative relocs that have become local due to symbol 1712 visibility changes. */ 1713 1714 if (info->shared) 1715 { 1716 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 1717 && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 1718 || info->symbolic)) 1719 { 1720 struct elf32_sparc_dyn_relocs **pp; 1721 1722 for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) 1723 { 1724 p->count -= p->pc_count; 1725 p->pc_count = 0; 1726 if (p->count == 0) 1727 *pp = p->next; 1728 else 1729 pp = &p->next; 1730 } 1731 } 1732 } 1733 else 1734 { 1735 /* For the non-shared case, discard space for relocs against 1736 symbols which turn out to need copy relocs or are not 1737 dynamic. */ 1738 1739 if ((h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 1740 && (((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0 1741 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) 1742 || (htab->elf.dynamic_sections_created 1743 && (h->root.type == bfd_link_hash_undefweak 1744 || h->root.type == bfd_link_hash_undefined)))) 1745 { 1746 /* Make sure this symbol is output as a dynamic symbol. 1747 Undefined weak syms won't yet be marked as dynamic. */ 1748 if (h->dynindx == -1 1749 && (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) 1750 { 1751 if (! bfd_elf32_link_record_dynamic_symbol (info, h)) 1752 return FALSE; 1753 } 1754 1755 /* If that succeeded, we know we'll be keeping all the 1756 relocs. */ 1757 if (h->dynindx != -1) 1758 goto keep; 1759 } 1760 1761 eh->dyn_relocs = NULL; 1762 1763 keep: ; 1764 } 1765 1766 /* Finally, allocate space. */ 1767 for (p = eh->dyn_relocs; p != NULL; p = p->next) 1768 { 1769 asection *sreloc = elf_section_data (p->sec)->sreloc; 1770 sreloc->_raw_size += p->count * sizeof (Elf32_External_Rela); 1771 } 1772 1773 return TRUE; 1774 } 1775 1776 /* Find any dynamic relocs that apply to read-only sections. */ 1777 1778 static bfd_boolean 1779 readonly_dynrelocs (h, inf) 1780 struct elf_link_hash_entry *h; 1781 PTR inf; 1782 { 1783 struct elf32_sparc_link_hash_entry *eh; 1784 struct elf32_sparc_dyn_relocs *p; 1785 1786 if (h->root.type == bfd_link_hash_warning) 1787 h = (struct elf_link_hash_entry *) h->root.u.i.link; 1788 1789 eh = (struct elf32_sparc_link_hash_entry *) h; 1790 for (p = eh->dyn_relocs; p != NULL; p = p->next) 1791 { 1792 asection *s = p->sec->output_section; 1793 1794 if (s != NULL && (s->flags & SEC_READONLY) != 0) 1795 { 1796 struct bfd_link_info *info = (struct bfd_link_info *) inf; 1797 1798 info->flags |= DF_TEXTREL; 1799 1800 /* Not an error, just cut short the traversal. */ 1801 return FALSE; 1802 } 1803 } 1804 return TRUE; 1805 } 1806 912 1807 /* Set the sizes of the dynamic sections. */ 913 1808 914 static b oolean1809 static bfd_boolean 915 1810 elf32_sparc_size_dynamic_sections (output_bfd, info) 916 bfd *output_bfd ;1811 bfd *output_bfd ATTRIBUTE_UNUSED; 917 1812 struct bfd_link_info *info; 918 1813 { 1814 struct elf32_sparc_link_hash_table *htab; 919 1815 bfd *dynobj; 920 1816 asection *s; 921 b oolean reltext;922 boolean relplt; 923 924 dynobj = elf_hash_table (info)->dynobj;1817 bfd *ibfd; 1818 1819 htab = elf32_sparc_hash_table (info); 1820 dynobj = htab->elf.dynobj; 925 1821 BFD_ASSERT (dynobj != NULL); 926 1822 … … 935 1831 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; 936 1832 } 937 1833 } 1834 1835 /* Set up .got offsets for local syms, and space for local dynamic 1836 relocs. */ 1837 for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link_next) 1838 { 1839 bfd_signed_vma *local_got; 1840 bfd_signed_vma *end_local_got; 1841 char *local_tls_type; 1842 bfd_size_type locsymcount; 1843 Elf_Internal_Shdr *symtab_hdr; 1844 asection *srel; 1845 1846 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour) 1847 continue; 1848 1849 for (s = ibfd->sections; s != NULL; s = s->next) 1850 { 1851 struct elf32_sparc_dyn_relocs *p; 1852 1853 for (p = *((struct elf32_sparc_dyn_relocs **) 1854 &elf_section_data (s)->local_dynrel); 1855 p != NULL; 1856 p = p->next) 1857 { 1858 if (!bfd_is_abs_section (p->sec) 1859 && bfd_is_abs_section (p->sec->output_section)) 1860 { 1861 /* Input section has been discarded, either because 1862 it is a copy of a linkonce section or due to 1863 linker script /DISCARD/, so we'll be discarding 1864 the relocs too. */ 1865 } 1866 else if (p->count != 0) 1867 { 1868 srel = elf_section_data (p->sec)->sreloc; 1869 srel->_raw_size += p->count * sizeof (Elf32_External_Rela); 1870 if ((p->sec->output_section->flags & SEC_READONLY) != 0) 1871 info->flags |= DF_TEXTREL; 1872 } 1873 } 1874 } 1875 1876 local_got = elf_local_got_refcounts (ibfd); 1877 if (!local_got) 1878 continue; 1879 1880 symtab_hdr = &elf_tdata (ibfd)->symtab_hdr; 1881 locsymcount = symtab_hdr->sh_info; 1882 end_local_got = local_got + locsymcount; 1883 local_tls_type = elf32_sparc_local_got_tls_type (ibfd); 1884 s = htab->sgot; 1885 srel = htab->srelgot; 1886 for (; local_got < end_local_got; ++local_got, ++local_tls_type) 1887 { 1888 if (*local_got > 0) 1889 { 1890 *local_got = s->_raw_size; 1891 s->_raw_size += 4; 1892 if (*local_tls_type == GOT_TLS_GD) 1893 s->_raw_size += 4; 1894 if (info->shared 1895 || *local_tls_type == GOT_TLS_GD 1896 || *local_tls_type == GOT_TLS_IE) 1897 srel->_raw_size += sizeof (Elf32_External_Rela); 1898 } 1899 else 1900 *local_got = (bfd_vma) -1; 1901 } 1902 } 1903 1904 if (htab->tls_ldm_got.refcount > 0) 1905 { 1906 /* Allocate 2 got entries and 1 dynamic reloc for 1907 R_SPARC_TLS_LDM_{HI22,LO10} relocs. */ 1908 htab->tls_ldm_got.offset = htab->sgot->_raw_size; 1909 htab->sgot->_raw_size += 8; 1910 htab->srelgot->_raw_size += sizeof (Elf32_External_Rela); 1911 } 1912 else 1913 htab->tls_ldm_got.offset = -1; 1914 1915 /* Allocate global sym .plt and .got entries, and space for global 1916 sym dynamic relocs. */ 1917 elf_link_hash_traverse (&htab->elf, allocate_dynrelocs, (PTR) info); 1918 1919 if (elf_hash_table (info)->dynamic_sections_created) 1920 { 938 1921 /* Make space for the trailing nop in .plt. */ 939 s = bfd_get_section_by_name (dynobj, ".plt"); 940 BFD_ASSERT (s != NULL); 941 if (s->_raw_size > 0) 942 s->_raw_size += 4; 943 } 944 else 945 { 946 /* We may have created entries in the .rela.got section. 947 However, if we are not creating the dynamic sections, we will 948 not actually use these entries. Reset the size of .rela.got, 949 which will cause it to get stripped from the output file 950 below. */ 951 s = bfd_get_section_by_name (dynobj, ".rela.got"); 952 if (s != NULL) 953 s->_raw_size = 0; 1922 if (htab->splt->_raw_size > 0) 1923 htab->splt->_raw_size += 4; 1924 1925 /* If the .got section is more than 0x1000 bytes, we add 1926 0x1000 to the value of _GLOBAL_OFFSET_TABLE_, so that 13 1927 bit relocations have a greater chance of working. */ 1928 if (htab->sgot->_raw_size >= 0x1000 1929 && elf_hash_table (info)->hgot->root.u.def.value == 0) 1930 elf_hash_table (info)->hgot->root.u.def.value = 0x1000; 954 1931 } 955 1932 … … 957 1934 determined the sizes of the various dynamic sections. Allocate 958 1935 memory for them. */ 959 reltext = false;960 relplt = false;961 1936 for (s = dynobj->sections; s != NULL; s = s->next) 962 1937 { 963 1938 const char *name; 964 b oolean strip;1939 bfd_boolean strip = FALSE; 965 1940 966 1941 if ((s->flags & SEC_LINKER_CREATED) == 0) … … 970 1945 of the dynobj section names depend upon the input files. */ 971 1946 name = bfd_get_section_name (dynobj, s); 972 973 strip = false;974 1947 975 1948 if (strncmp (name, ".rela", 5) == 0) … … 986 1959 function which decides whether anything needs to go 987 1960 into these sections. */ 988 strip = true;1961 strip = TRUE; 989 1962 } 990 1963 else 991 1964 { 992 const char *outname;993 asection *target;994 995 /* If this relocation section applies to a read only996 section, then we probably need a DT_TEXTREL entry. */997 outname = bfd_get_section_name (output_bfd,998 s->output_section);999 target = bfd_get_section_by_name (output_bfd, outname + 5);1000 if (target != NULL1001 && (target->flags & SEC_READONLY) != 01002 && (target->flags & SEC_ALLOC) != 0)1003 reltext = true;1004 1005 if (strcmp (name, ".rela.plt") == 0)1006 relplt = true;1007 1008 1965 /* We use the reloc_count field as a counter if we need 1009 1966 to copy relocs into the output file. */ … … 1011 1968 } 1012 1969 } 1013 else if (strcmp (name, ".plt") != 0 1014 && strcmp (name, ".got") != 0) 1970 else if (s != htab->splt && s != htab->sgot) 1015 1971 { 1016 1972 /* It's not one of our sections, so don't allocate space. */ … … 1032 1988 s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->_raw_size); 1033 1989 if (s->contents == NULL && s->_raw_size != 0) 1034 return false;1990 return FALSE; 1035 1991 } 1036 1992 … … 1042 1998 the .dynamic section. The DT_DEBUG entry is filled in by the 1043 1999 dynamic linker and used by the debugger. */ 1044 if (! info->shared) 1045 { 1046 if (! bfd_elf32_add_dynamic_entry (info, DT_DEBUG, 0)) 1047 return false; 1048 } 1049 1050 if (relplt) 1051 { 1052 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0) 1053 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0) 1054 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_RELA) 1055 || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0)) 1056 return false; 1057 } 1058 1059 if (! bfd_elf32_add_dynamic_entry (info, DT_RELA, 0) 1060 || ! bfd_elf32_add_dynamic_entry (info, DT_RELASZ, 0) 1061 || ! bfd_elf32_add_dynamic_entry (info, DT_RELAENT, 1062 sizeof (Elf32_External_Rela))) 1063 return false; 1064 1065 if (reltext) 1066 { 1067 if (! bfd_elf32_add_dynamic_entry (info, DT_TEXTREL, 0)) 1068 return false; 1069 info->flags |= DF_TEXTREL; 1070 } 1071 } 1072 1073 return true; 2000 #define add_dynamic_entry(TAG, VAL) \ 2001 bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) 2002 2003 if (!info->shared) 2004 { 2005 if (!add_dynamic_entry (DT_DEBUG, 0)) 2006 return FALSE; 2007 } 2008 2009 if (htab->srelplt->_raw_size != 0) 2010 { 2011 if (!add_dynamic_entry (DT_PLTGOT, 0) 2012 || !add_dynamic_entry (DT_PLTRELSZ, 0) 2013 || !add_dynamic_entry (DT_PLTREL, DT_RELA) 2014 || !add_dynamic_entry (DT_JMPREL, 0)) 2015 return FALSE; 2016 } 2017 2018 if (!add_dynamic_entry (DT_RELA, 0) 2019 || !add_dynamic_entry (DT_RELASZ, 0) 2020 || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) 2021 return FALSE; 2022 2023 /* If any dynamic relocs apply to a read-only section, 2024 then we need a DT_TEXTREL entry. */ 2025 if ((info->flags & DF_TEXTREL) == 0) 2026 elf_link_hash_traverse (&htab->elf, readonly_dynrelocs, 2027 (PTR) info); 2028 2029 if (info->flags & DF_TEXTREL) 2030 { 2031 if (!add_dynamic_entry (DT_TEXTREL, 0)) 2032 return FALSE; 2033 } 2034 } 2035 #undef add_dynamic_entry 2036 2037 return TRUE; 1074 2038 } 1075 2039 1076 #define SET_SEC_DO_RELAX(section) do { elf_section_data(section)->tdata = (void *)1; } while (0) 1077 #define SEC_DO_RELAX(section) (elf_section_data(section)->tdata == (void *)1) 1078 1079 static boolean 2040 struct elf32_sparc_section_data 2041 { 2042 struct bfd_elf_section_data elf; 2043 unsigned int do_relax; 2044 }; 2045 2046 #define sec_do_relax(sec) \ 2047 ((struct elf32_sparc_section_data *) elf_section_data (sec))->do_relax 2048 2049 static bfd_boolean 2050 elf32_sparc_new_section_hook (abfd, sec) 2051 bfd *abfd; 2052 asection *sec; 2053 { 2054 struct elf32_sparc_section_data *sdata; 2055 bfd_size_type amt = sizeof (*sdata); 2056 2057 sdata = (struct elf32_sparc_section_data *) bfd_zalloc (abfd, amt); 2058 if (sdata == NULL) 2059 return FALSE; 2060 sec->used_by_bfd = (PTR) sdata; 2061 2062 return _bfd_elf_new_section_hook (abfd, sec); 2063 } 2064 2065 static bfd_boolean 1080 2066 elf32_sparc_relax_section (abfd, section, link_info, again) 1081 2067 bfd *abfd ATTRIBUTE_UNUSED; 1082 2068 asection *section ATTRIBUTE_UNUSED; 1083 2069 struct bfd_link_info *link_info ATTRIBUTE_UNUSED; 1084 b oolean *again;1085 { 1086 *again = false;1087 SET_SEC_DO_RELAX (section);1088 return true;2070 bfd_boolean *again; 2071 { 2072 *again = FALSE; 2073 sec_do_relax (section) = 1; 2074 return TRUE; 1089 2075 } 1090 2076 2077 /* Return the base VMA address which should be subtracted from real addresses 2078 when resolving @dtpoff relocation. 2079 This is PT_TLS segment p_vaddr. */ 2080 2081 static bfd_vma 2082 dtpoff_base (info) 2083 struct bfd_link_info *info; 2084 { 2085 /* If tls_segment is NULL, we should have signalled an error already. */ 2086 if (elf_hash_table (info)->tls_segment == NULL) 2087 return 0; 2088 return elf_hash_table (info)->tls_segment->start; 2089 } 2090 2091 /* Return the relocation value for @tpoff relocation 2092 if STT_TLS virtual address is ADDRESS. */ 2093 2094 static bfd_vma 2095 tpoff (info, address) 2096 struct bfd_link_info *info; 2097 bfd_vma address; 2098 { 2099 struct elf_link_tls_segment *tls_segment 2100 = elf_hash_table (info)->tls_segment; 2101 2102 /* If tls_segment is NULL, we should have signalled an error already. */ 2103 if (tls_segment == NULL) 2104 return 0; 2105 return -(align_power (tls_segment->size, tls_segment->align) 2106 + tls_segment->start - address); 2107 } 2108 1091 2109 /* Relocate a SPARC ELF section. */ 1092 2110 1093 static b oolean2111 static bfd_boolean 1094 2112 elf32_sparc_relocate_section (output_bfd, info, input_bfd, input_section, 1095 2113 contents, relocs, local_syms, local_sections) … … 1103 2121 asection **local_sections; 1104 2122 { 1105 bfd *dynobj;2123 struct elf32_sparc_link_hash_table *htab; 1106 2124 Elf_Internal_Shdr *symtab_hdr; 1107 2125 struct elf_link_hash_entry **sym_hashes; 1108 2126 bfd_vma *local_got_offsets; 1109 2127 bfd_vma got_base; 1110 asection *sgot;1111 asection *splt;1112 2128 asection *sreloc; 1113 2129 Elf_Internal_Rela *rel; 1114 2130 Elf_Internal_Rela *relend; 1115 2131 1116 dynobj = elf_hash_table (info)->dynobj; 2132 if (info->relocateable) 2133 return TRUE; 2134 2135 htab = elf32_sparc_hash_table (info); 1117 2136 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; 1118 2137 sym_hashes = elf_sym_hashes (input_bfd); … … 1124 2143 got_base = elf_hash_table (info)->hgot->root.u.def.value; 1125 2144 1126 sgot = NULL; 1127 splt = NULL; 1128 sreloc = NULL; 2145 sreloc = elf_section_data (input_section)->sreloc; 1129 2146 1130 2147 rel = relocs; … … 1132 2149 for (; rel < relend; rel++) 1133 2150 { 1134 int r_type ;2151 int r_type, tls_type; 1135 2152 reloc_howto_type *howto; 1136 2153 unsigned long r_symndx; … … 1138 2155 Elf_Internal_Sym *sym; 1139 2156 asection *sec; 1140 bfd_vma relocation ;2157 bfd_vma relocation, off; 1141 2158 bfd_reloc_status_type r; 2159 bfd_boolean is_plt = FALSE; 2160 bfd_boolean unresolved_reloc; 1142 2161 1143 2162 r_type = ELF32_R_TYPE (rel->r_info); 1144 2163 1145 2164 if (r_type == R_SPARC_GNU_VTINHERIT 1146 1147 2165 || r_type == R_SPARC_GNU_VTENTRY) 2166 continue; 1148 2167 1149 2168 if (r_type < 0 || r_type >= (int) R_SPARC_max_std) 1150 2169 { 1151 2170 bfd_set_error (bfd_error_bad_value); 1152 return false;2171 return FALSE; 1153 2172 } 1154 2173 howto = _bfd_sparc_elf_howto_table + r_type; 1155 2174 2175 /* This is a final link. */ 1156 2176 r_symndx = ELF32_R_SYM (rel->r_info); 1157 1158 if (info->relocateable)1159 {1160 /* This is a relocateable link. We don't have to change1161 anything, unless the reloc is against a section symbol,1162 in which case we have to adjust according to where the1163 section symbol winds up in the output section. */1164 if (r_symndx < symtab_hdr->sh_info)1165 {1166 sym = local_syms + r_symndx;1167 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)1168 {1169 sec = local_sections[r_symndx];1170 rel->r_addend += sec->output_offset + sym->st_value;1171 }1172 }1173 1174 continue;1175 }1176 1177 /* This is a final link. */1178 2177 h = NULL; 1179 2178 sym = NULL; 1180 2179 sec = NULL; 2180 unresolved_reloc = FALSE; 1181 2181 if (r_symndx < symtab_hdr->sh_info) 1182 2182 { 1183 2183 sym = local_syms + r_symndx; 1184 2184 sec = local_sections[r_symndx]; 1185 relocation = (sec->output_section->vma 1186 + sec->output_offset 1187 + sym->st_value); 2185 relocation = _bfd_elf_rela_local_sym (output_bfd, sym, sec, rel); 1188 2186 } 1189 2187 else … … 1193 2191 || h->root.type == bfd_link_hash_warning) 1194 2192 h = (struct elf_link_hash_entry *) h->root.u.i.link; 2193 2194 relocation = 0; 1195 2195 if (h->root.type == bfd_link_hash_defined 1196 2196 || h->root.type == bfd_link_hash_defweak) 1197 2197 { 1198 2198 sec = h->root.u.def.section; 1199 if ((r_type == R_SPARC_WPLT30 1200 && h->plt.offset != (bfd_vma) -1) 1201 || ((r_type == R_SPARC_GOT10 1202 || r_type == R_SPARC_GOT13 1203 || r_type == R_SPARC_GOT22) 1204 && elf_hash_table (info)->dynamic_sections_created 1205 && (! info->shared 1206 || (! info->symbolic && h->dynindx != -1) 1207 || (h->elf_link_hash_flags 1208 & ELF_LINK_HASH_DEF_REGULAR) == 0)) 1209 || (info->shared 1210 && ((! info->symbolic && h->dynindx != -1) 1211 || (h->elf_link_hash_flags 1212 & ELF_LINK_HASH_DEF_REGULAR) == 0) 1213 && (r_type == R_SPARC_8 1214 || r_type == R_SPARC_16 1215 || r_type == R_SPARC_32 1216 || r_type == R_SPARC_DISP8 1217 || r_type == R_SPARC_DISP16 1218 || r_type == R_SPARC_DISP32 1219 || r_type == R_SPARC_WDISP30 1220 || r_type == R_SPARC_WDISP22 1221 || r_type == R_SPARC_WDISP19 1222 || r_type == R_SPARC_WDISP16 1223 || r_type == R_SPARC_HI22 1224 || r_type == R_SPARC_22 1225 || r_type == R_SPARC_13 1226 || r_type == R_SPARC_LO10 1227 || r_type == R_SPARC_UA16 1228 || r_type == R_SPARC_UA32 1229 || r_type == R_SPARC_UA64 1230 || ((r_type == R_SPARC_PC10 1231 || r_type == R_SPARC_PC22) 1232 && strcmp (h->root.root.string, 1233 "_GLOBAL_OFFSET_TABLE_") != 0)))) 1234 { 1235 /* In these cases, we don't need the relocation 1236 value. We check specially because in some 1237 obscure cases sec->output_section will be NULL. */ 1238 relocation = 0; 1239 } 2199 if (sec->output_section == NULL) 2200 /* Set a flag that will be cleared later if we find a 2201 relocation value for this symbol. output_section 2202 is typically NULL for symbols satisfied by a shared 2203 library. */ 2204 unresolved_reloc = TRUE; 1240 2205 else 1241 2206 relocation = (h->root.u.def.value … … 1244 2209 } 1245 2210 else if (h->root.type == bfd_link_hash_undefweak) 1246 relocation = 0;1247 else if (info->shared && !info->symbolic2211 ; 2212 else if (info->shared 1248 2213 && !info->no_undefined 1249 2214 && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) 1250 relocation = 0;2215 ; 1251 2216 else 1252 2217 { … … 1256 2221 (!info->shared || info->no_undefined 1257 2222 || ELF_ST_VISIBILITY (h->other))))) 1258 return false; 1259 relocation = 0; 2223 return FALSE; 1260 2224 } 1261 2225 } … … 1267 2231 case R_SPARC_GOT22: 1268 2232 /* Relocation is to the entry for this symbol in the global 1269 offset table. */ 1270 if (sgot == NULL) 1271 { 1272 sgot = bfd_get_section_by_name (dynobj, ".got"); 1273 BFD_ASSERT (sgot != NULL); 1274 } 2233 offset table. */ 2234 if (htab->sgot == NULL) 2235 abort (); 1275 2236 1276 2237 if (h != NULL) 1277 2238 { 1278 bfd_ vma off;2239 bfd_boolean dyn; 1279 2240 1280 2241 off = h->got.offset; 1281 2242 BFD_ASSERT (off != (bfd_vma) -1); 1282 1283 if (! elf_hash_table (info)->dynamic_sections_created 2243 dyn = elf_hash_table (info)->dynamic_sections_created; 2244 2245 if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h) 1284 2246 || (info->shared 1285 && (info->symbolic || h->dynindx == -1) 2247 && (info->symbolic 2248 || h->dynindx == -1 2249 || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)) 1286 2250 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))) 1287 2251 { 1288 2252 /* This is actually a static link, or it is a 1289 1290 1291 1292 1293 1294 1295 2253 -Bsymbolic link and the symbol is defined 2254 locally, or the symbol was forced to be local 2255 because of a version file. We must initialize 2256 this entry in the global offset table. Since the 2257 offset must always be a multiple of 4, we use the 2258 least significant bit to record whether we have 2259 initialized it already. 1296 2260 1297 2261 When doing a dynamic link, we create a .rela.got … … 1303 2267 { 1304 2268 bfd_put_32 (output_bfd, relocation, 1305 sgot->contents + off);2269 htab->sgot->contents + off); 1306 2270 h->got.offset |= 1; 1307 2271 } 1308 2272 } 1309 1310 relocation = sgot->output_offset + off - got_base;2273 else 2274 unresolved_reloc = FALSE; 1311 2275 } 1312 2276 else 1313 2277 { 1314 bfd_vma off;1315 1316 2278 BFD_ASSERT (local_got_offsets != NULL 1317 2279 && local_got_offsets[r_symndx] != (bfd_vma) -1); … … 1326 2288 else 1327 2289 { 1328 bfd_put_32 (output_bfd, relocation, sgot->contents + off);1329 2290 1330 2291 if (info->shared) 1331 2292 { 1332 asection *s relgot;2293 asection *s; 1333 2294 Elf_Internal_Rela outrel; 2295 bfd_byte *loc; 1334 2296 1335 2297 /* We need to generate a R_SPARC_RELATIVE reloc 1336 2298 for the dynamic linker. */ 1337 s relgot = bfd_get_section_by_name (dynobj, ".rela.got");1338 BFD_ASSERT (s relgot!= NULL);1339 1340 outrel.r_offset = ( sgot->output_section->vma1341 + sgot->output_offset2299 s = htab->srelgot; 2300 BFD_ASSERT (s != NULL); 2301 2302 outrel.r_offset = (htab->sgot->output_section->vma 2303 + htab->sgot->output_offset 1342 2304 + off); 1343 2305 outrel.r_info = ELF32_R_INFO (0, R_SPARC_RELATIVE); 1344 outrel.r_addend = 0; 1345 bfd_elf32_swap_reloca_out (output_bfd, &outrel, 1346 (((Elf32_External_Rela *) 1347 srelgot->contents) 1348 + srelgot->reloc_count)); 1349 ++srelgot->reloc_count; 2306 outrel.r_addend = relocation; 2307 relocation = 0; 2308 loc = s->contents; 2309 loc += s->reloc_count++ * sizeof (Elf32_External_Rela); 2310 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); 1350 2311 } 1351 2312 2313 bfd_put_32 (output_bfd, relocation, 2314 htab->sgot->contents + off); 1352 2315 local_got_offsets[r_symndx] |= 1; 1353 2316 } 1354 1355 relocation = sgot->output_offset + off - got_base; 1356 } 1357 2317 } 2318 relocation = htab->sgot->output_offset + off - got_base; 1358 2319 break; 1359 2320 2321 case R_SPARC_PLT32: 2322 if (h == NULL || h->plt.offset == (bfd_vma) -1) 2323 { 2324 r_type = R_SPARC_32; 2325 goto r_sparc_plt32; 2326 } 2327 /* Fall through. */ 1360 2328 case R_SPARC_WPLT30: 2329 r_sparc_wplt30: 1361 2330 /* Relocation is to the entry for this symbol in the 1362 2331 procedure linkage table. */ 1363 2332 1364 2333 /* The Solaris native assembler will generate a WPLT30 reloc … … 1372 2341 { 1373 2342 /* We didn't make a PLT entry for this symbol. This 1374 1375 2343 happens when statically linking PIC code, or when 2344 using -Bsymbolic. */ 1376 2345 break; 1377 2346 } 1378 2347 1379 if (splt == NULL) 1380 { 1381 splt = bfd_get_section_by_name (dynobj, ".plt"); 1382 BFD_ASSERT (splt != NULL); 1383 } 1384 1385 relocation = (splt->output_section->vma 1386 + splt->output_offset 2348 if (htab->splt == NULL) 2349 abort (); 2350 2351 relocation = (htab->splt->output_section->vma 2352 + htab->splt->output_offset 1387 2353 + h->plt.offset); 2354 unresolved_reloc = FALSE; 2355 if (r_type == R_SPARC_PLT32) 2356 { 2357 r_type = R_SPARC_32; 2358 is_plt = TRUE; 2359 goto r_sparc_plt32; 2360 } 1388 2361 break; 1389 2362 … … 1401 2374 case R_SPARC_WDISP19: 1402 2375 case R_SPARC_WDISP16: 1403 if (h == NULL1404 || (info->symbolic1405 && (h->elf_link_hash_flags1406 & ELF_LINK_HASH_DEF_REGULAR) != 0))1407 break;1408 /* Fall through. */1409 2376 case R_SPARC_8: 1410 2377 case R_SPARC_16: … … 1416 2383 case R_SPARC_UA16: 1417 2384 case R_SPARC_UA32: 1418 case R_SPARC_UA64: 1419 if (info->shared) 2385 r_sparc_plt32: 2386 /* r_symndx will be zero only for relocs against symbols 2387 from removed linkonce sections, or sections discarded by 2388 a linker script. */ 2389 if (r_symndx == 0 2390 || (input_section->flags & SEC_ALLOC) == 0) 2391 break; 2392 2393 if ((info->shared 2394 && (! howto->pc_relative 2395 || (h != NULL 2396 && h->dynindx != -1 2397 && (! info->symbolic 2398 || (h->elf_link_hash_flags 2399 & ELF_LINK_HASH_DEF_REGULAR) == 0)))) 2400 || (!info->shared 2401 && h != NULL 2402 && h->dynindx != -1 2403 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 2404 && (((h->elf_link_hash_flags 2405 & ELF_LINK_HASH_DEF_DYNAMIC) != 0 2406 && (h->elf_link_hash_flags 2407 & ELF_LINK_HASH_DEF_REGULAR) == 0) 2408 || h->root.type == bfd_link_hash_undefweak 2409 || h->root.type == bfd_link_hash_undefined))) 1420 2410 { 1421 2411 Elf_Internal_Rela outrel; 1422 boolean skip; 2412 bfd_byte *loc; 2413 bfd_boolean skip, relocate = FALSE; 1423 2414 1424 2415 /* When generating a shared object, these relocations 1425 are copied into the output file to be resolved at run 1426 time. */ 1427 1428 if (sreloc == NULL) 1429 { 1430 const char *name; 1431 1432 name = (bfd_elf_string_from_elf_section 1433 (input_bfd, 1434 elf_elfheader (input_bfd)->e_shstrndx, 1435 elf_section_data (input_section)->rel_hdr.sh_name)); 1436 if (name == NULL) 1437 return false; 1438 1439 BFD_ASSERT (strncmp (name, ".rela", 5) == 0 1440 && strcmp (bfd_get_section_name (input_bfd, 1441 input_section), 1442 name + 5) == 0); 1443 1444 sreloc = bfd_get_section_by_name (dynobj, name); 1445 BFD_ASSERT (sreloc != NULL); 1446 } 1447 1448 skip = false; 1449 1450 if (elf_section_data (input_section)->stab_info == NULL) 1451 outrel.r_offset = rel->r_offset; 1452 else 1453 { 1454 bfd_vma off; 1455 1456 off = (_bfd_stab_section_offset 1457 (output_bfd, &elf_hash_table (info)->stab_info, 1458 input_section, 1459 &elf_section_data (input_section)->stab_info, 1460 rel->r_offset)); 1461 if (off == (bfd_vma) -1) 1462 skip = true; 1463 outrel.r_offset = off; 1464 } 1465 2416 are copied into the output file to be resolved at run 2417 time. */ 2418 2419 BFD_ASSERT (sreloc != NULL); 2420 2421 skip = FALSE; 2422 2423 outrel.r_offset = 2424 _bfd_elf_section_offset (output_bfd, info, input_section, 2425 rel->r_offset); 2426 if (outrel.r_offset == (bfd_vma) -1) 2427 skip = TRUE; 2428 else if (outrel.r_offset == (bfd_vma) -2) 2429 skip = TRUE, relocate = TRUE; 1466 2430 outrel.r_offset += (input_section->output_section->vma 1467 2431 + input_section->output_offset); 2432 2433 /* Optimize unaligned reloc usage now that we know where 2434 it finally resides. */ 2435 switch (r_type) 2436 { 2437 case R_SPARC_16: 2438 if (outrel.r_offset & 1) 2439 r_type = R_SPARC_UA16; 2440 break; 2441 case R_SPARC_UA16: 2442 if (!(outrel.r_offset & 1)) 2443 r_type = R_SPARC_16; 2444 break; 2445 case R_SPARC_32: 2446 if (outrel.r_offset & 3) 2447 r_type = R_SPARC_UA32; 2448 break; 2449 case R_SPARC_UA32: 2450 if (!(outrel.r_offset & 3)) 2451 r_type = R_SPARC_32; 2452 break; 2453 case R_SPARC_DISP8: 2454 case R_SPARC_DISP16: 2455 case R_SPARC_DISP32: 2456 /* If the symbol is not dynamic, we should not keep 2457 a dynamic relocation. But an .rela.* slot has been 2458 allocated for it, output R_SPARC_NONE. 2459 FIXME: Add code tracking needed dynamic relocs as 2460 e.g. i386 has. */ 2461 if (h->dynindx == -1) 2462 skip = TRUE, relocate = TRUE; 2463 break; 2464 } 1468 2465 1469 2466 if (skip) 1470 2467 memset (&outrel, 0, sizeof outrel); 1471 2468 /* h->dynindx may be -1 if the symbol was marked to 1472 1473 else if (h != NULL 2469 become local. */ 2470 else if (h != NULL && ! is_plt 1474 2471 && ((! info->symbolic && h->dynindx != -1) 1475 2472 || (h->elf_link_hash_flags … … 1491 2488 long indx; 1492 2489 1493 if (h == NULL) 2490 if (is_plt) 2491 sec = htab->splt; 2492 else if (h == NULL) 1494 2493 sec = local_sections[r_symndx]; 1495 2494 else … … 1505 2504 { 1506 2505 bfd_set_error (bfd_error_bad_value); 1507 return false;2506 return FALSE; 1508 2507 } 1509 2508 else … … 1521 2520 (*_bfd_error_handler) 1522 2521 (_("%s: probably compiled without -fPIC?"), 1523 bfd_ get_filename (input_bfd));2522 bfd_archive_filename (input_bfd)); 1524 2523 bfd_set_error (bfd_error_bad_value); 1525 return false;2524 return FALSE; 1526 2525 } 1527 2526 } … … 1532 2531 } 1533 2532 2533 loc = sreloc->contents; 2534 loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); 2535 bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); 2536 2537 /* This reloc will be computed at runtime, so there's no 2538 need to do anything now. */ 2539 if (! relocate) 2540 continue; 2541 } 2542 break; 2543 2544 case R_SPARC_TLS_GD_HI22: 2545 if (! elf32_sparc_tdata (input_bfd)->has_tlsgd) 2546 { 2547 /* R_SPARC_REV32 used the same reloc number as 2548 R_SPARC_TLS_GD_HI22. */ 2549 r_type = R_SPARC_REV32; 2550 break; 2551 } 2552 /* Fall through */ 2553 2554 case R_SPARC_TLS_GD_LO10: 2555 case R_SPARC_TLS_IE_HI22: 2556 case R_SPARC_TLS_IE_LO10: 2557 r_type = elf32_sparc_tls_transition (info, input_bfd, r_type, 2558 h == NULL); 2559 tls_type = GOT_UNKNOWN; 2560 if (h == NULL && local_got_offsets) 2561 tls_type = elf32_sparc_local_got_tls_type (input_bfd) [r_symndx]; 2562 else if (h != NULL) 2563 { 2564 tls_type = elf32_sparc_hash_entry(h)->tls_type; 2565 if (!info->shared && h->dynindx == -1 && tls_type == GOT_TLS_IE) 2566 switch (ELF32_R_TYPE (rel->r_info)) 2567 { 2568 case R_SPARC_TLS_GD_HI22: 2569 case R_SPARC_TLS_IE_HI22: 2570 r_type = R_SPARC_TLS_LE_HIX22; 2571 break; 2572 default: 2573 r_type = R_SPARC_TLS_LE_LOX10; 2574 break; 2575 } 2576 } 2577 if (tls_type == GOT_TLS_IE) 2578 switch (r_type) 2579 { 2580 case R_SPARC_TLS_GD_HI22: 2581 r_type = R_SPARC_TLS_IE_HI22; 2582 break; 2583 case R_SPARC_TLS_GD_LO10: 2584 r_type = R_SPARC_TLS_IE_LO10; 2585 break; 2586 } 2587 2588 if (r_type == R_SPARC_TLS_LE_HIX22) 2589 { 2590 relocation = tpoff (info, relocation); 2591 break; 2592 } 2593 if (r_type == R_SPARC_TLS_LE_LOX10) 2594 { 2595 /* Change add into xor. */ 2596 relocation = tpoff (info, relocation); 2597 bfd_put_32 (output_bfd, (bfd_get_32 (input_bfd, 2598 contents + rel->r_offset) 2599 | 0x80182000), contents + rel->r_offset); 2600 break; 2601 } 2602 2603 if (h != NULL) 2604 { 2605 off = h->got.offset; 2606 h->got.offset |= 1; 2607 } 2608 else 2609 { 2610 BFD_ASSERT (local_got_offsets != NULL); 2611 off = local_got_offsets[r_symndx]; 2612 local_got_offsets[r_symndx] |= 1; 2613 } 2614 2615 r_sparc_tlsldm: 2616 if (htab->sgot == NULL) 2617 abort (); 2618 2619 if ((off & 1) != 0) 2620 off &= ~1; 2621 else 2622 { 2623 Elf_Internal_Rela outrel; 2624 Elf32_External_Rela *loc; 2625 int dr_type, indx; 2626 2627 if (htab->srelgot == NULL) 2628 abort (); 2629 2630 bfd_put_32 (output_bfd, 0, htab->sgot->contents + off); 2631 outrel.r_offset = (htab->sgot->output_section->vma 2632 + htab->sgot->output_offset + off); 2633 indx = h && h->dynindx != -1 ? h->dynindx : 0; 2634 if (r_type == R_SPARC_TLS_IE_HI22 2635 || r_type == R_SPARC_TLS_IE_LO10) 2636 dr_type = R_SPARC_TLS_TPOFF32; 2637 else 2638 dr_type = R_SPARC_TLS_DTPMOD32; 2639 if (dr_type == R_SPARC_TLS_TPOFF32 && indx == 0) 2640 outrel.r_addend = relocation - dtpoff_base (info); 2641 else 2642 outrel.r_addend = 0; 2643 outrel.r_info = ELF32_R_INFO (indx, dr_type); 2644 loc = (Elf32_External_Rela *) htab->srelgot->contents; 2645 loc += htab->srelgot->reloc_count++; 1534 2646 bfd_elf32_swap_reloca_out (output_bfd, &outrel, 1535 (((Elf32_External_Rela *) 1536 sreloc->contents) 1537 + sreloc->reloc_count)); 2647 (bfd_byte *) loc); 2648 2649 if (r_type == R_SPARC_TLS_GD_HI22 2650 || r_type == R_SPARC_TLS_GD_LO10) 2651 { 2652 if (indx == 0) 2653 { 2654 BFD_ASSERT (! unresolved_reloc); 2655 bfd_put_32 (output_bfd, 2656 relocation - dtpoff_base (info), 2657 htab->sgot->contents + off + 4); 2658 } 2659 else 2660 { 2661 bfd_put_32 (output_bfd, 0, 2662 htab->sgot->contents + off + 4); 2663 outrel.r_info = ELF32_R_INFO (indx, 2664 R_SPARC_TLS_DTPOFF32); 2665 outrel.r_offset += 4; 2666 htab->srelgot->reloc_count++; 2667 loc++; 2668 bfd_elf32_swap_reloca_out (output_bfd, &outrel, 2669 (bfd_byte *) loc); 2670 } 2671 } 2672 else if (dr_type == R_SPARC_TLS_DTPMOD32) 2673 { 2674 bfd_put_32 (output_bfd, 0, 2675 htab->sgot->contents + off + 4); 2676 } 2677 } 2678 2679 if (off >= (bfd_vma) -2) 2680 abort (); 2681 2682 relocation = htab->sgot->output_offset + off - got_base; 2683 unresolved_reloc = FALSE; 2684 howto = _bfd_sparc_elf_howto_table + r_type; 2685 break; 2686 2687 case R_SPARC_TLS_LDM_HI22: 2688 case R_SPARC_TLS_LDM_LO10: 2689 if (! info->shared) 2690 { 2691 bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset); 2692 continue; 2693 } 2694 off = htab->tls_ldm_got.offset; 2695 htab->tls_ldm_got.offset |= 1; 2696 goto r_sparc_tlsldm; 2697 2698 case R_SPARC_TLS_LDO_HIX22: 2699 case R_SPARC_TLS_LDO_LOX10: 2700 if (info->shared) 2701 relocation -= dtpoff_base (info); 2702 else 2703 relocation = tpoff (info, relocation); 2704 break; 2705 2706 case R_SPARC_TLS_LE_HIX22: 2707 case R_SPARC_TLS_LE_LOX10: 2708 if (info->shared) 2709 { 2710 Elf_Internal_Rela outrel; 2711 bfd_boolean skip, relocate = FALSE; 2712 2713 BFD_ASSERT (sreloc != NULL); 2714 skip = FALSE; 2715 outrel.r_offset = 2716 _bfd_elf_section_offset (output_bfd, info, input_section, 2717 rel->r_offset); 2718 if (outrel.r_offset == (bfd_vma) -1) 2719 skip = TRUE; 2720 else if (outrel.r_offset == (bfd_vma) -2) 2721 skip = TRUE, relocate = TRUE; 2722 outrel.r_offset += (input_section->output_section->vma 2723 + input_section->output_offset); 2724 if (skip) 2725 memset (&outrel, 0, sizeof outrel); 2726 else 2727 { 2728 outrel.r_info = ELF32_R_INFO (0, r_type); 2729 outrel.r_addend = relocation - dtpoff_base (info) 2730 + rel->r_addend; 2731 } 2732 2733 bfd_elf32_swap_reloca_out (output_bfd, &outrel, 2734 (bfd_byte *) (((Elf32_External_Rela *) 2735 sreloc->contents) 2736 + sreloc->reloc_count)); 1538 2737 ++sreloc->reloc_count; 1539 1540 /* This reloc will be computed at runtime, so there's no 1541 need to do anything now, unless this is a RELATIVE 1542 reloc in an unallocated section. */ 1543 if (skip 1544 || (input_section->flags & SEC_ALLOC) != 0 1545 || ELF32_R_TYPE (outrel.r_info) != R_SPARC_RELATIVE) 1546 continue; 1547 } 2738 continue; 2739 } 2740 relocation = tpoff (info, relocation); 2741 break; 2742 2743 case R_SPARC_TLS_LDM_CALL: 2744 if (! info->shared) 2745 { 2746 /* mov %g0, %o0 */ 2747 bfd_put_32 (output_bfd, 0x90100000, contents + rel->r_offset); 2748 continue; 2749 } 2750 /* Fall through */ 2751 2752 case R_SPARC_TLS_GD_CALL: 2753 tls_type = GOT_UNKNOWN; 2754 if (h == NULL && local_got_offsets) 2755 tls_type = elf32_sparc_local_got_tls_type (input_bfd) [r_symndx]; 2756 else if (h != NULL) 2757 tls_type = elf32_sparc_hash_entry(h)->tls_type; 2758 if (! info->shared 2759 || (r_type == R_SPARC_TLS_GD_CALL && tls_type == GOT_TLS_IE)) 2760 { 2761 bfd_vma insn; 2762 2763 if (!info->shared && (h == NULL || h->dynindx == -1)) 2764 { 2765 /* GD -> LE */ 2766 bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset); 2767 continue; 2768 } 2769 2770 /* GD -> IE */ 2771 if (rel + 1 < relend 2772 && ELF32_R_TYPE (rel[1].r_info) == R_SPARC_TLS_GD_ADD 2773 && rel[1].r_offset == rel->r_offset + 4 2774 && ELF32_R_SYM (rel[1].r_info) == r_symndx 2775 && (((insn = bfd_get_32 (input_bfd, 2776 contents + rel[1].r_offset)) 2777 >> 25) & 0x1f) == 8) 2778 { 2779 /* We have 2780 call __tls_get_addr, %tgd_call(foo) 2781 add %reg1, %reg2, %o0, %tgd_add(foo) 2782 and change it into IE: 2783 ld [%reg1 + %reg2], %o0, %tie_ld(foo) 2784 add %g7, %o0, %o0, %tie_add(foo). 2785 add is 0x80000000 | (rd << 25) | (rs1 << 14) | rs2, 2786 ld is 0xc0000000 | (rd << 25) | (rs1 << 14) | rs2. */ 2787 bfd_put_32 (output_bfd, insn | 0xc0000000, 2788 contents + rel->r_offset); 2789 bfd_put_32 (output_bfd, 0x9001c008, 2790 contents + rel->r_offset + 4); 2791 rel++; 2792 continue; 2793 } 2794 2795 bfd_put_32 (output_bfd, 0x9001c008, contents + rel->r_offset); 2796 continue; 2797 } 2798 2799 h = (struct elf_link_hash_entry *) 2800 bfd_link_hash_lookup (info->hash, "__tls_get_addr", FALSE, 2801 FALSE, TRUE); 2802 BFD_ASSERT (h != NULL); 2803 r_type = R_SPARC_WPLT30; 2804 howto = _bfd_sparc_elf_howto_table + r_type; 2805 goto r_sparc_wplt30; 2806 2807 case R_SPARC_TLS_GD_ADD: 2808 tls_type = GOT_UNKNOWN; 2809 if (h == NULL && local_got_offsets) 2810 tls_type = elf32_sparc_local_got_tls_type (input_bfd) [r_symndx]; 2811 else if (h != NULL) 2812 tls_type = elf32_sparc_hash_entry(h)->tls_type; 2813 if (! info->shared || tls_type == GOT_TLS_IE) 2814 { 2815 /* add %reg1, %reg2, %reg3, %tgd_add(foo) 2816 changed into IE: 2817 ld [%reg1 + %reg2], %reg3, %tie_ld(foo) 2818 or LE: 2819 add %g7, %reg2, %reg3. */ 2820 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 2821 if ((h != NULL && h->dynindx != -1) || info->shared) 2822 relocation = insn | 0xc0000000; 2823 else 2824 relocation = (insn & ~0x7c000) | 0x1c000; 2825 bfd_put_32 (output_bfd, relocation, contents + rel->r_offset); 2826 } 2827 continue; 2828 2829 case R_SPARC_TLS_LDM_ADD: 2830 if (! info->shared) 2831 bfd_put_32 (output_bfd, SPARC_NOP, contents + rel->r_offset); 2832 continue; 2833 2834 case R_SPARC_TLS_LDO_ADD: 2835 if (! info->shared) 2836 { 2837 /* Change rs1 into %g7. */ 2838 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 2839 insn = (insn & ~0x7c000) | 0x1c000; 2840 bfd_put_32 (output_bfd, insn, contents + rel->r_offset); 2841 } 2842 continue; 2843 2844 case R_SPARC_TLS_IE_LD: 2845 case R_SPARC_TLS_IE_LDX: 2846 if (! info->shared && (h == NULL || h->dynindx == -1)) 2847 { 2848 bfd_vma insn = bfd_get_32 (input_bfd, contents + rel->r_offset); 2849 int rs2 = insn & 0x1f; 2850 int rd = (insn >> 25) & 0x1f; 2851 2852 if (rs2 == rd) 2853 relocation = SPARC_NOP; 2854 else 2855 relocation = 0x80100000 | (insn & 0x3e00001f); 2856 bfd_put_32 (output_bfd, relocation, contents + rel->r_offset); 2857 } 2858 continue; 2859 2860 case R_SPARC_TLS_IE_ADD: 2861 /* Totally useless relocation. */ 2862 continue; 2863 2864 case R_SPARC_TLS_DTPOFF32: 2865 relocation -= dtpoff_base (info); 1548 2866 break; 1549 2867 … … 1551 2869 break; 1552 2870 } 2871 2872 /* Dynamic relocs are not propagated for SEC_DEBUGGING sections 2873 because such sections are not SEC_ALLOC and thus ld.so will 2874 not process them. */ 2875 if (unresolved_reloc 2876 && !((input_section->flags & SEC_DEBUGGING) != 0 2877 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0)) 2878 (*_bfd_error_handler) 2879 (_("%s(%s+0x%lx): unresolvable relocation against symbol `%s'"), 2880 bfd_archive_filename (input_bfd), 2881 bfd_get_section_name (input_bfd, input_section), 2882 (long) rel->r_offset, 2883 h->root.root.string); 1553 2884 1554 2885 r = bfd_reloc_continue; … … 1584 2915 r = bfd_reloc_ok; 1585 2916 } 2917 else if (r_type == R_SPARC_TLS_LDO_HIX22 2918 || r_type == R_SPARC_TLS_LE_HIX22) 2919 { 2920 bfd_vma x; 2921 2922 relocation += rel->r_addend; 2923 relocation = relocation ^ 0xffffffff; 2924 2925 x = bfd_get_32 (input_bfd, contents + rel->r_offset); 2926 x = (x & ~(bfd_vma) 0x3fffff) | ((relocation >> 10) & 0x3fffff); 2927 bfd_put_32 (input_bfd, x, contents + rel->r_offset); 2928 r = bfd_reloc_ok; 2929 } 2930 else if (r_type == R_SPARC_TLS_LDO_LOX10 2931 || r_type == R_SPARC_TLS_LE_LOX10) 2932 { 2933 bfd_vma x; 2934 2935 relocation += rel->r_addend; 2936 relocation = (relocation & 0x3ff) | 0x1c00; 2937 2938 x = bfd_get_32 (input_bfd, contents + rel->r_offset); 2939 x = (x & ~(bfd_vma) 0x1fff) | relocation; 2940 bfd_put_32 (input_bfd, x, contents + rel->r_offset); 2941 2942 r = bfd_reloc_ok; 2943 } 1586 2944 else if ((r_type == R_SPARC_WDISP30 || r_type == R_SPARC_WPLT30) 1587 && SEC_DO_RELAX(input_section)2945 && sec_do_relax (input_section) 1588 2946 && rel->r_offset + 4 < input_section->_raw_size) 1589 2947 { … … 1665 3023 break; 1666 3024 1667 bfd_put_32 (input_bfd, INSN_NOP,3025 bfd_put_32 (input_bfd, (bfd_vma) INSN_NOP, 1668 3026 contents + rel->r_offset + 4); 1669 3027 } … … 1698 3056 sym->st_name); 1699 3057 if (name == NULL) 1700 return false;3058 return FALSE; 1701 3059 if (*name == '\0') 1702 3060 name = bfd_section_name (input_bfd, sec); … … 1705 3063 (info, name, howto->name, (bfd_vma) 0, 1706 3064 input_bfd, input_section, rel->r_offset))) 1707 return false;3065 return FALSE; 1708 3066 } 1709 3067 break; … … 1712 3070 } 1713 3071 1714 return true;3072 return TRUE; 1715 3073 } 1716 3074 … … 1718 3076 dynamic sections here. */ 1719 3077 1720 static b oolean3078 static bfd_boolean 1721 3079 elf32_sparc_finish_dynamic_symbol (output_bfd, info, h, sym) 1722 3080 bfd *output_bfd; … … 1726 3084 { 1727 3085 bfd *dynobj; 1728 1729 dynobj = elf_hash_table (info)->dynobj; 3086 struct elf32_sparc_link_hash_table *htab; 3087 3088 htab = elf32_sparc_hash_table (info); 3089 dynobj = htab->elf.dynobj; 1730 3090 1731 3091 if (h->plt.offset != (bfd_vma) -1) … … 1734 3094 asection *srela; 1735 3095 Elf_Internal_Rela rela; 3096 bfd_byte *loc; 1736 3097 1737 3098 /* This symbol has an entry in the procedure linkage table. Set 1738 3099 it up. */ 1739 3100 1740 3101 BFD_ASSERT (h->dynindx != -1); 1741 3102 1742 splt = bfd_get_section_by_name (dynobj, ".plt");1743 srela = bfd_get_section_by_name (dynobj, ".rela.plt");3103 splt = htab->splt; 3104 srela = htab->srelplt; 1744 3105 BFD_ASSERT (splt != NULL && srela != NULL); 1745 3106 … … 1752 3113 + (((- (h->plt.offset + 4)) >> 2) & 0x3fffff)), 1753 3114 splt->contents + h->plt.offset + 4); 1754 bfd_put_32 (output_bfd, PLT_ENTRY_WORD2,3115 bfd_put_32 (output_bfd, (bfd_vma) PLT_ENTRY_WORD2, 1755 3116 splt->contents + h->plt.offset + 8); 1756 3117 … … 1761 3122 rela.r_info = ELF32_R_INFO (h->dynindx, R_SPARC_JMP_SLOT); 1762 3123 rela.r_addend = 0; 1763 bfd_elf32_swap_reloca_out (output_bfd, &rela,1764 ((Elf32_External_Rela *) srela->contents 1765 + h->plt.offset / PLT_ENTRY_SIZE - 4));3124 loc = srela->contents; 3125 loc += (h->plt.offset / PLT_ENTRY_SIZE - 4) * sizeof (Elf32_External_Rela); 3126 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 1766 3127 1767 3128 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0) … … 1780 3141 } 1781 3142 1782 if (h->got.offset != (bfd_vma) -1) 3143 if (h->got.offset != (bfd_vma) -1 3144 && elf32_sparc_hash_entry(h)->tls_type != GOT_TLS_GD 3145 && elf32_sparc_hash_entry(h)->tls_type != GOT_TLS_IE) 1783 3146 { 1784 3147 asection *sgot; 1785 3148 asection *srela; 1786 3149 Elf_Internal_Rela rela; 3150 bfd_byte *loc; 1787 3151 1788 3152 /* This symbol has an entry in the global offset table. Set it 1789 1790 1791 sgot = bfd_get_section_by_name (dynobj, ".got");1792 srela = bfd_get_section_by_name (dynobj, ".rela.got");3153 up. */ 3154 3155 sgot = htab->sgot; 3156 srela = htab->srelgot; 1793 3157 BFD_ASSERT (sgot != NULL && srela != NULL); 1794 3158 1795 3159 rela.r_offset = (sgot->output_section->vma 1796 3160 + sgot->output_offset 1797 + (h->got.offset &~ 1));3161 + (h->got.offset &~ (bfd_vma) 1)); 1798 3162 1799 3163 /* If this is a -Bsymbolic link, and the symbol is defined … … 1805 3169 && (info->symbolic || h->dynindx == -1) 1806 3170 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) 1807 rela.r_info = ELF32_R_INFO (0, R_SPARC_RELATIVE); 3171 { 3172 asection *sec = h->root.u.def.section; 3173 rela.r_info = ELF32_R_INFO (0, R_SPARC_RELATIVE); 3174 rela.r_addend = (h->root.u.def.value 3175 + sec->output_section->vma 3176 + sec->output_offset); 3177 } 1808 3178 else 1809 3179 { 1810 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + h->got.offset);1811 3180 rela.r_info = ELF32_R_INFO (h->dynindx, R_SPARC_GLOB_DAT); 1812 } 1813 1814 rela.r_addend = 0; 1815 bfd_elf32_swap_reloca_out (output_bfd, &rela, 1816 ((Elf32_External_Rela *) srela->contents 1817 + srela->reloc_count)); 1818 ++srela->reloc_count; 3181 rela.r_addend = 0; 3182 } 3183 3184 bfd_put_32 (output_bfd, (bfd_vma) 0, 3185 sgot->contents + (h->got.offset &~ (bfd_vma) 1)); 3186 loc = srela->contents; 3187 loc += srela->reloc_count++ * sizeof (Elf32_External_Rela); 3188 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 1819 3189 } 1820 3190 … … 1823 3193 asection *s; 1824 3194 Elf_Internal_Rela rela; 3195 bfd_byte *loc; 1825 3196 1826 3197 /* This symbols needs a copy reloc. Set it up. */ … … 1837 3208 rela.r_info = ELF32_R_INFO (h->dynindx, R_SPARC_COPY); 1838 3209 rela.r_addend = 0; 1839 bfd_elf32_swap_reloca_out (output_bfd, &rela, 1840 ((Elf32_External_Rela *) s->contents 1841 + s->reloc_count)); 1842 ++s->reloc_count; 3210 loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); 3211 bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); 1843 3212 } 1844 3213 … … 1849 3218 sym->st_shndx = SHN_ABS; 1850 3219 1851 return true;3220 return TRUE; 1852 3221 } 1853 3222 1854 3223 /* Finish up the dynamic sections. */ 1855 3224 1856 static b oolean3225 static bfd_boolean 1857 3226 elf32_sparc_finish_dynamic_sections (output_bfd, info) 1858 3227 bfd *output_bfd; … … 1861 3230 bfd *dynobj; 1862 3231 asection *sdyn; 1863 asection *sgot; 1864 1865 dynobj = elf_hash_table (info)->dynobj; 3232 struct elf32_sparc_link_hash_table *htab; 3233 3234 htab = elf32_sparc_hash_table (info); 3235 dynobj = htab->elf.dynobj; 1866 3236 1867 3237 sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); … … 1881 3251 Elf_Internal_Dyn dyn; 1882 3252 const char *name; 1883 b oolean size;3253 bfd_boolean size; 1884 3254 1885 3255 bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); … … 1887 3257 switch (dyn.d_tag) 1888 3258 { 1889 case DT_PLTGOT: name = ".plt"; size = false; break;1890 case DT_PLTRELSZ: name = ".rela.plt"; size = true; break;1891 case DT_JMPREL: name = ".rela.plt"; size = false; break;1892 default: name = NULL; size = false; break;3259 case DT_PLTGOT: name = ".plt"; size = FALSE; break; 3260 case DT_PLTRELSZ: name = ".rela.plt"; size = TRUE; break; 3261 case DT_JMPREL: name = ".rela.plt"; size = FALSE; break; 3262 default: name = NULL; size = FALSE; break; 1893 3263 } 1894 3264 … … 1921 3291 { 1922 3292 memset (splt->contents, 0, 4 * PLT_ENTRY_SIZE); 1923 bfd_put_32 (output_bfd, SPARC_NOP,3293 bfd_put_32 (output_bfd, (bfd_vma) SPARC_NOP, 1924 3294 splt->contents + splt->_raw_size - 4); 1925 3295 } … … 1931 3301 /* Set the first entry in the global offset table to the address of 1932 3302 the dynamic section. */ 1933 sgot = bfd_get_section_by_name (dynobj, ".got"); 1934 BFD_ASSERT (sgot != NULL); 1935 if (sgot->_raw_size > 0) 3303 if (htab->sgot && htab->sgot->_raw_size > 0) 1936 3304 { 1937 3305 if (sdyn == NULL) 1938 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents);3306 bfd_put_32 (output_bfd, (bfd_vma) 0, htab->sgot->contents); 1939 3307 else 1940 3308 bfd_put_32 (output_bfd, 1941 3309 sdyn->output_section->vma + sdyn->output_offset, 1942 sgot->contents); 1943 } 1944 1945 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; 1946 1947 return true; 3310 htab->sgot->contents); 3311 } 3312 3313 if (htab->sgot) 3314 elf_section_data (htab->sgot->output_section)->this_hdr.sh_entsize = 4; 3315 3316 return TRUE; 1948 3317 } 1949 3318 … … 1959 3328 object file when linking. */ 1960 3329 1961 static b oolean3330 static bfd_boolean 1962 3331 elf32_sparc_merge_private_bfd_data (ibfd, obfd) 1963 3332 bfd *ibfd; 1964 3333 bfd *obfd; 1965 3334 { 1966 b oolean error;3335 bfd_boolean error; 1967 3336 /* FIXME: This should not be static. */ 1968 3337 static unsigned long previous_ibfd_e_flags = (unsigned long) -1; … … 1970 3339 if (bfd_get_flavour (ibfd) != bfd_target_elf_flavour 1971 3340 || bfd_get_flavour (obfd) != bfd_target_elf_flavour) 1972 return true;1973 1974 error = false;3341 return TRUE; 3342 3343 error = FALSE; 1975 3344 1976 3345 if (bfd_get_mach (ibfd) >= bfd_mach_sparc_v9) 1977 3346 { 1978 error = true;3347 error = TRUE; 1979 3348 (*_bfd_error_handler) 1980 3349 (_("%s: compiled for a 64 bit system and target is 32 bit"), 1981 bfd_ get_filename (ibfd));3350 bfd_archive_filename (ibfd)); 1982 3351 } 1983 3352 else if ((ibfd->flags & DYNAMIC) == 0) … … 1993 3362 (*_bfd_error_handler) 1994 3363 (_("%s: linking little endian files with big endian files"), 1995 bfd_ get_filename (ibfd));1996 error = true;3364 bfd_archive_filename (ibfd)); 3365 error = TRUE; 1997 3366 } 1998 3367 previous_ibfd_e_flags = elf_elfheader (ibfd)->e_flags & EF_SPARC_LEDATA; … … 2001 3370 { 2002 3371 bfd_set_error (bfd_error_bad_value); 2003 return false;2004 } 2005 2006 return true;3372 return FALSE; 3373 } 3374 3375 return TRUE; 2007 3376 } 2008 3377 … … 2010 3379 /* Set the right machine number. */ 2011 3380 2012 static b oolean3381 static bfd_boolean 2013 3382 elf32_sparc_object_p (abfd) 2014 3383 bfd *abfd; 2015 3384 { 3385 /* Allocate our special target data. */ 3386 struct elf32_sparc_obj_tdata *new_tdata; 3387 bfd_size_type amt = sizeof (struct elf32_sparc_obj_tdata); 3388 new_tdata = bfd_zalloc (abfd, amt); 3389 if (new_tdata == NULL) 3390 return FALSE; 3391 new_tdata->root = *abfd->tdata.elf_obj_data; 3392 abfd->tdata.any = new_tdata; 3393 2016 3394 if (elf_elfheader (abfd)->e_machine == EM_SPARC32PLUS) 2017 3395 { … … 2026 3404 bfd_mach_sparc_v8plus); 2027 3405 else 2028 return false;3406 return FALSE; 2029 3407 } 2030 3408 else if (elf_elfheader (abfd)->e_flags & EF_SPARC_LEDATA) 2031 3409 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, 2032 3410 bfd_mach_sparc_sparclite_le); 2033 3411 else 2034 3412 return bfd_default_set_arch_mach (abfd, bfd_arch_sparc, bfd_mach_sparc); … … 2041 3419 elf32_sparc_final_write_processing (abfd, linker) 2042 3420 bfd *abfd; 2043 b oolean linker ATTRIBUTE_UNUSED;3421 bfd_boolean linker ATTRIBUTE_UNUSED; 2044 3422 { 2045 3423 switch (bfd_get_mach (abfd)) … … 2073 3451 } 2074 3452 3453 static enum elf_reloc_type_class 3454 elf32_sparc_reloc_type_class (rela) 3455 const Elf_Internal_Rela *rela; 3456 { 3457 switch ((int) ELF32_R_TYPE (rela->r_info)) 3458 { 3459 case R_SPARC_RELATIVE: 3460 return reloc_class_relative; 3461 case R_SPARC_JMP_SLOT: 3462 return reloc_class_plt; 3463 case R_SPARC_COPY: 3464 return reloc_class_copy; 3465 default: 3466 return reloc_class_normal; 3467 } 3468 } 3469 2075 3470 2076 3471 #define TARGET_BIG_SYM bfd_elf32_sparc_vec … … 2082 3477 2083 3478 #define bfd_elf32_bfd_reloc_type_lookup elf32_sparc_reloc_type_lookup 3479 #define bfd_elf32_bfd_link_hash_table_create \ 3480 elf32_sparc_link_hash_table_create 2084 3481 #define bfd_elf32_bfd_relax_section elf32_sparc_relax_section 3482 #define bfd_elf32_new_section_hook elf32_sparc_new_section_hook 2085 3483 #define elf_info_to_howto elf32_sparc_info_to_howto 3484 #define elf_backend_copy_indirect_symbol \ 3485 elf32_sparc_copy_indirect_symbol 2086 3486 #define elf_backend_create_dynamic_sections \ 2087 _bfd_elf_create_dynamic_sections3487 elf32_sparc_create_dynamic_sections 2088 3488 #define elf_backend_check_relocs elf32_sparc_check_relocs 2089 3489 #define elf_backend_adjust_dynamic_symbol \ … … 2098 3498 #define bfd_elf32_bfd_merge_private_bfd_data \ 2099 3499 elf32_sparc_merge_private_bfd_data 3500 #define bfd_elf32_mkobject elf32_sparc_mkobject 2100 3501 #define elf_backend_object_p elf32_sparc_object_p 2101 3502 #define elf_backend_final_write_processing \ 2102 3503 elf32_sparc_final_write_processing 2103 #define elf_backend_gc_mark_hook 3504 #define elf_backend_gc_mark_hook elf32_sparc_gc_mark_hook 2104 3505 #define elf_backend_gc_sweep_hook elf32_sparc_gc_sweep_hook 3506 #define elf_backend_reloc_type_class elf32_sparc_reloc_type_class 2105 3507 2106 3508 #define elf_backend_can_gc_sections 1 3509 #define elf_backend_can_refcount 1 2107 3510 #define elf_backend_want_got_plt 0 2108 3511 #define elf_backend_plt_readonly 0 … … 2110 3513 #define elf_backend_got_header_size 4 2111 3514 #define elf_backend_plt_header_size (4*PLT_ENTRY_SIZE) 3515 #define elf_backend_rela_normal 1 2112 3516 2113 3517 #include "elf32-target.h" -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.