| 1 | /* Motorola 68k series support for 32-bit ELF |
| 2 | Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
| 3 | 2004, 2005, 2006, 2007 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 3 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., 51 Franklin Street - Fifth Floor, Boston, |
| 20 | MA 02110-1301, USA. */ |
| 21 | |
| 22 | #include "sysdep.h" |
| 23 | #include "bfd.h" |
| 24 | #include "bfdlink.h" |
| 25 | #include "libbfd.h" |
| 26 | #include "elf-bfd.h" |
| 27 | #include "elf/m68k.h" |
| 28 | #include "opcode/m68k.h" |
| 29 | |
| 30 | static reloc_howto_type *reloc_type_lookup |
| 31 | PARAMS ((bfd *, bfd_reloc_code_real_type)); |
| 32 | static void rtype_to_howto |
| 33 | PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); |
| 34 | static struct bfd_hash_entry *elf_m68k_link_hash_newfunc |
| 35 | PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); |
| 36 | static struct bfd_link_hash_table *elf_m68k_link_hash_table_create |
| 37 | PARAMS ((bfd *)); |
| 38 | static bfd_boolean elf_m68k_check_relocs |
| 39 | PARAMS ((bfd *, struct bfd_link_info *, asection *, |
| 40 | const Elf_Internal_Rela *)); |
| 41 | static bfd_boolean elf_m68k_adjust_dynamic_symbol |
| 42 | PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); |
| 43 | static bfd_boolean elf_m68k_size_dynamic_sections |
| 44 | PARAMS ((bfd *, struct bfd_link_info *)); |
| 45 | static bfd_boolean elf_m68k_discard_copies |
| 46 | PARAMS ((struct elf_link_hash_entry *, PTR)); |
| 47 | static bfd_boolean elf_m68k_relocate_section |
| 48 | PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, |
| 49 | Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); |
| 50 | static bfd_boolean elf_m68k_finish_dynamic_symbol |
| 51 | PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, |
| 52 | Elf_Internal_Sym *)); |
| 53 | static bfd_boolean elf_m68k_finish_dynamic_sections |
| 54 | PARAMS ((bfd *, struct bfd_link_info *)); |
| 55 | |
| 56 | static bfd_boolean elf32_m68k_set_private_flags |
| 57 | PARAMS ((bfd *, flagword)); |
| 58 | static bfd_boolean elf32_m68k_merge_private_bfd_data |
| 59 | PARAMS ((bfd *, bfd *)); |
| 60 | static bfd_boolean elf32_m68k_print_private_bfd_data |
| 61 | PARAMS ((bfd *, PTR)); |
| 62 | static enum elf_reloc_type_class elf32_m68k_reloc_type_class |
| 63 | PARAMS ((const Elf_Internal_Rela *)); |
| 64 | |
| 65 | static reloc_howto_type howto_table[] = { |
| 66 | HOWTO(R_68K_NONE, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_NONE", FALSE, 0, 0x00000000,FALSE), |
| 67 | HOWTO(R_68K_32, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_32", FALSE, 0, 0xffffffff,FALSE), |
| 68 | HOWTO(R_68K_16, 0, 1,16, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_16", FALSE, 0, 0x0000ffff,FALSE), |
| 69 | HOWTO(R_68K_8, 0, 0, 8, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_8", FALSE, 0, 0x000000ff,FALSE), |
| 70 | HOWTO(R_68K_PC32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PC32", FALSE, 0, 0xffffffff,TRUE), |
| 71 | HOWTO(R_68K_PC16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC16", FALSE, 0, 0x0000ffff,TRUE), |
| 72 | HOWTO(R_68K_PC8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PC8", FALSE, 0, 0x000000ff,TRUE), |
| 73 | HOWTO(R_68K_GOT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32", FALSE, 0, 0xffffffff,TRUE), |
| 74 | HOWTO(R_68K_GOT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16", FALSE, 0, 0x0000ffff,TRUE), |
| 75 | HOWTO(R_68K_GOT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8", FALSE, 0, 0x000000ff,TRUE), |
| 76 | HOWTO(R_68K_GOT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_GOT32O", FALSE, 0, 0xffffffff,FALSE), |
| 77 | HOWTO(R_68K_GOT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT16O", FALSE, 0, 0x0000ffff,FALSE), |
| 78 | HOWTO(R_68K_GOT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_GOT8O", FALSE, 0, 0x000000ff,FALSE), |
| 79 | HOWTO(R_68K_PLT32, 0, 2,32, TRUE, 0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32", FALSE, 0, 0xffffffff,TRUE), |
| 80 | HOWTO(R_68K_PLT16, 0, 1,16, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16", FALSE, 0, 0x0000ffff,TRUE), |
| 81 | HOWTO(R_68K_PLT8, 0, 0, 8, TRUE, 0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8", FALSE, 0, 0x000000ff,TRUE), |
| 82 | HOWTO(R_68K_PLT32O, 0, 2,32, FALSE,0, complain_overflow_bitfield, bfd_elf_generic_reloc, "R_68K_PLT32O", FALSE, 0, 0xffffffff,FALSE), |
| 83 | HOWTO(R_68K_PLT16O, 0, 1,16, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT16O", FALSE, 0, 0x0000ffff,FALSE), |
| 84 | HOWTO(R_68K_PLT8O, 0, 0, 8, FALSE,0, complain_overflow_signed, bfd_elf_generic_reloc, "R_68K_PLT8O", FALSE, 0, 0x000000ff,FALSE), |
| 85 | HOWTO(R_68K_COPY, 0, 0, 0, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_COPY", FALSE, 0, 0xffffffff,FALSE), |
| 86 | HOWTO(R_68K_GLOB_DAT, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_GLOB_DAT", FALSE, 0, 0xffffffff,FALSE), |
| 87 | HOWTO(R_68K_JMP_SLOT, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_JMP_SLOT", FALSE, 0, 0xffffffff,FALSE), |
| 88 | HOWTO(R_68K_RELATIVE, 0, 2,32, FALSE,0, complain_overflow_dont, bfd_elf_generic_reloc, "R_68K_RELATIVE", FALSE, 0, 0xffffffff,FALSE), |
| 89 | /* GNU extension to record C++ vtable hierarchy. */ |
| 90 | HOWTO (R_68K_GNU_VTINHERIT, /* type */ |
| 91 | 0, /* rightshift */ |
| 92 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 93 | 0, /* bitsize */ |
| 94 | FALSE, /* pc_relative */ |
| 95 | 0, /* bitpos */ |
| 96 | complain_overflow_dont, /* complain_on_overflow */ |
| 97 | NULL, /* special_function */ |
| 98 | "R_68K_GNU_VTINHERIT", /* name */ |
| 99 | FALSE, /* partial_inplace */ |
| 100 | 0, /* src_mask */ |
| 101 | 0, /* dst_mask */ |
| 102 | FALSE), |
| 103 | /* GNU extension to record C++ vtable member usage. */ |
| 104 | HOWTO (R_68K_GNU_VTENTRY, /* type */ |
| 105 | 0, /* rightshift */ |
| 106 | 2, /* size (0 = byte, 1 = short, 2 = long) */ |
| 107 | 0, /* bitsize */ |
| 108 | FALSE, /* pc_relative */ |
| 109 | 0, /* bitpos */ |
| 110 | complain_overflow_dont, /* complain_on_overflow */ |
| 111 | _bfd_elf_rel_vtable_reloc_fn, /* special_function */ |
| 112 | "R_68K_GNU_VTENTRY", /* name */ |
| 113 | FALSE, /* partial_inplace */ |
| 114 | 0, /* src_mask */ |
| 115 | 0, /* dst_mask */ |
| 116 | FALSE), |
| 117 | }; |
| 118 | |
| 119 | static void |
| 120 | rtype_to_howto (abfd, cache_ptr, dst) |
| 121 | bfd *abfd ATTRIBUTE_UNUSED; |
| 122 | arelent *cache_ptr; |
| 123 | Elf_Internal_Rela *dst; |
| 124 | { |
| 125 | BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_68K_max); |
| 126 | cache_ptr->howto = &howto_table[ELF32_R_TYPE(dst->r_info)]; |
| 127 | } |
| 128 | |
| 129 | #define elf_info_to_howto rtype_to_howto |
| 130 | |
| 131 | static const struct |
| 132 | { |
| 133 | bfd_reloc_code_real_type bfd_val; |
| 134 | int elf_val; |
| 135 | } reloc_map[] = { |
| 136 | { BFD_RELOC_NONE, R_68K_NONE }, |
| 137 | { BFD_RELOC_32, R_68K_32 }, |
| 138 | { BFD_RELOC_16, R_68K_16 }, |
| 139 | { BFD_RELOC_8, R_68K_8 }, |
| 140 | { BFD_RELOC_32_PCREL, R_68K_PC32 }, |
| 141 | { BFD_RELOC_16_PCREL, R_68K_PC16 }, |
| 142 | { BFD_RELOC_8_PCREL, R_68K_PC8 }, |
| 143 | { BFD_RELOC_32_GOT_PCREL, R_68K_GOT32 }, |
| 144 | { BFD_RELOC_16_GOT_PCREL, R_68K_GOT16 }, |
| 145 | { BFD_RELOC_8_GOT_PCREL, R_68K_GOT8 }, |
| 146 | { BFD_RELOC_32_GOTOFF, R_68K_GOT32O }, |
| 147 | { BFD_RELOC_16_GOTOFF, R_68K_GOT16O }, |
| 148 | { BFD_RELOC_8_GOTOFF, R_68K_GOT8O }, |
| 149 | { BFD_RELOC_32_PLT_PCREL, R_68K_PLT32 }, |
| 150 | { BFD_RELOC_16_PLT_PCREL, R_68K_PLT16 }, |
| 151 | { BFD_RELOC_8_PLT_PCREL, R_68K_PLT8 }, |
| 152 | { BFD_RELOC_32_PLTOFF, R_68K_PLT32O }, |
| 153 | { BFD_RELOC_16_PLTOFF, R_68K_PLT16O }, |
| 154 | { BFD_RELOC_8_PLTOFF, R_68K_PLT8O }, |
| 155 | { BFD_RELOC_NONE, R_68K_COPY }, |
| 156 | { BFD_RELOC_68K_GLOB_DAT, R_68K_GLOB_DAT }, |
| 157 | { BFD_RELOC_68K_JMP_SLOT, R_68K_JMP_SLOT }, |
| 158 | { BFD_RELOC_68K_RELATIVE, R_68K_RELATIVE }, |
| 159 | { BFD_RELOC_CTOR, R_68K_32 }, |
| 160 | { BFD_RELOC_VTABLE_INHERIT, R_68K_GNU_VTINHERIT }, |
| 161 | { BFD_RELOC_VTABLE_ENTRY, R_68K_GNU_VTENTRY }, |
| 162 | }; |
| 163 | |
| 164 | static reloc_howto_type * |
| 165 | reloc_type_lookup (abfd, code) |
| 166 | bfd *abfd ATTRIBUTE_UNUSED; |
| 167 | bfd_reloc_code_real_type code; |
| 168 | { |
| 169 | unsigned int i; |
| 170 | for (i = 0; i < sizeof (reloc_map) / sizeof (reloc_map[0]); i++) |
| 171 | { |
| 172 | if (reloc_map[i].bfd_val == code) |
| 173 | return &howto_table[reloc_map[i].elf_val]; |
| 174 | } |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | static reloc_howto_type * |
| 179 | reloc_name_lookup (bfd *abfd ATTRIBUTE_UNUSED, const char *r_name) |
| 180 | { |
| 181 | unsigned int i; |
| 182 | |
| 183 | for (i = 0; i < sizeof (howto_table) / sizeof (howto_table[0]); i++) |
| 184 | if (howto_table[i].name != NULL |
| 185 | && strcasecmp (howto_table[i].name, r_name) == 0) |
| 186 | return &howto_table[i]; |
| 187 | |
| 188 | return NULL; |
| 189 | } |
| 190 | |
| 191 | #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup |
| 192 | #define bfd_elf32_bfd_reloc_name_lookup reloc_name_lookup |
| 193 | #define ELF_ARCH bfd_arch_m68k |
| 194 | \f |
| 195 | /* Functions for the m68k ELF linker. */ |
| 196 | |
| 197 | /* The name of the dynamic interpreter. This is put in the .interp |
| 198 | section. */ |
| 199 | |
| 200 | #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1" |
| 201 | |
| 202 | /* Describes one of the various PLT styles. */ |
| 203 | |
| 204 | struct elf_m68k_plt_info |
| 205 | { |
| 206 | /* The size of each PLT entry. */ |
| 207 | bfd_vma size; |
| 208 | |
| 209 | /* The template for the first PLT entry. */ |
| 210 | const bfd_byte *plt0_entry; |
| 211 | |
| 212 | /* Offsets of fields in PLT0_ENTRY that require R_68K_PC32 relocations. |
| 213 | The comments by each member indicate the value that the relocation |
| 214 | is against. */ |
| 215 | struct { |
| 216 | unsigned int got4; /* .got + 4 */ |
| 217 | unsigned int got8; /* .got + 8 */ |
| 218 | } plt0_relocs; |
| 219 | |
| 220 | /* The template for a symbol's PLT entry. */ |
| 221 | const bfd_byte *symbol_entry; |
| 222 | |
| 223 | /* Offsets of fields in SYMBOL_ENTRY that require R_68K_PC32 relocations. |
| 224 | The comments by each member indicate the value that the relocation |
| 225 | is against. */ |
| 226 | struct { |
| 227 | unsigned int got; /* the symbol's .got.plt entry */ |
| 228 | unsigned int plt; /* .plt */ |
| 229 | } symbol_relocs; |
| 230 | |
| 231 | /* The offset of the resolver stub from the start of SYMBOL_ENTRY. |
| 232 | The stub starts with "move.l #relocoffset,%d0". */ |
| 233 | bfd_vma symbol_resolve_entry; |
| 234 | }; |
| 235 | |
| 236 | /* The size in bytes of an entry in the procedure linkage table. */ |
| 237 | |
| 238 | #define PLT_ENTRY_SIZE 20 |
| 239 | |
| 240 | /* The first entry in a procedure linkage table looks like this. See |
| 241 | the SVR4 ABI m68k supplement to see how this works. */ |
| 242 | |
| 243 | static const bfd_byte elf_m68k_plt0_entry[PLT_ENTRY_SIZE] = |
| 244 | { |
| 245 | 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */ |
| 246 | 0, 0, 0, 2, /* + (.got + 4) - . */ |
| 247 | 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */ |
| 248 | 0, 0, 0, 2, /* + (.got + 8) - . */ |
| 249 | 0, 0, 0, 0 /* pad out to 20 bytes. */ |
| 250 | }; |
| 251 | |
| 252 | /* Subsequent entries in a procedure linkage table look like this. */ |
| 253 | |
| 254 | static const bfd_byte elf_m68k_plt_entry[PLT_ENTRY_SIZE] = |
| 255 | { |
| 256 | 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */ |
| 257 | 0, 0, 0, 2, /* + (.got.plt entry) - . */ |
| 258 | 0x2f, 0x3c, /* move.l #offset,-(%sp) */ |
| 259 | 0, 0, 0, 0, /* + reloc index */ |
| 260 | 0x60, 0xff, /* bra.l .plt */ |
| 261 | 0, 0, 0, 0 /* + .plt - . */ |
| 262 | }; |
| 263 | |
| 264 | static const struct elf_m68k_plt_info elf_m68k_plt_info = { |
| 265 | PLT_ENTRY_SIZE, |
| 266 | elf_m68k_plt0_entry, { 4, 12 }, |
| 267 | elf_m68k_plt_entry, { 4, 16 }, 8 |
| 268 | }; |
| 269 | |
| 270 | #define ISAB_PLT_ENTRY_SIZE 24 |
| 271 | |
| 272 | static const bfd_byte elf_isab_plt0_entry[ISAB_PLT_ENTRY_SIZE] = |
| 273 | { |
| 274 | 0x20, 0x3c, /* move.l #offset,%d0 */ |
| 275 | 0, 0, 0, 0, /* + (.got + 4) - . */ |
| 276 | 0x2f, 0x3b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),-(%sp) */ |
| 277 | 0x20, 0x3c, /* move.l #offset,%d0 */ |
| 278 | 0, 0, 0, 0, /* + (.got + 8) - . */ |
| 279 | 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ |
| 280 | 0x4e, 0xd0, /* jmp (%a0) */ |
| 281 | 0x4e, 0x71 /* nop */ |
| 282 | }; |
| 283 | |
| 284 | /* Subsequent entries in a procedure linkage table look like this. */ |
| 285 | |
| 286 | static const bfd_byte elf_isab_plt_entry[ISAB_PLT_ENTRY_SIZE] = |
| 287 | { |
| 288 | 0x20, 0x3c, /* move.l #offset,%d0 */ |
| 289 | 0, 0, 0, 0, /* + (.got.plt entry) - . */ |
| 290 | 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ |
| 291 | 0x4e, 0xd0, /* jmp (%a0) */ |
| 292 | 0x2f, 0x3c, /* move.l #offset,-(%sp) */ |
| 293 | 0, 0, 0, 0, /* + reloc index */ |
| 294 | 0x60, 0xff, /* bra.l .plt */ |
| 295 | 0, 0, 0, 0 /* + .plt - . */ |
| 296 | }; |
| 297 | |
| 298 | static const struct elf_m68k_plt_info elf_isab_plt_info = { |
| 299 | ISAB_PLT_ENTRY_SIZE, |
| 300 | elf_isab_plt0_entry, { 2, 12 }, |
| 301 | elf_isab_plt_entry, { 2, 20 }, 12 |
| 302 | }; |
| 303 | |
| 304 | #define ISAC_PLT_ENTRY_SIZE 24 |
| 305 | |
| 306 | static const bfd_byte elf_isac_plt0_entry[ISAC_PLT_ENTRY_SIZE] = |
| 307 | { |
| 308 | 0x20, 0x3c, /* move.l #offset,%d0 */ |
| 309 | 0, 0, 0, 0, /* replaced with .got + 4 - . */ |
| 310 | 0x2e, 0xbb, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l),(%sp) */ |
| 311 | 0x20, 0x3c, /* move.l #offset,%d0 */ |
| 312 | 0, 0, 0, 0, /* replaced with .got + 8 - . */ |
| 313 | 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ |
| 314 | 0x4e, 0xd0, /* jmp (%a0) */ |
| 315 | 0x4e, 0x71 /* nop */ |
| 316 | }; |
| 317 | |
| 318 | /* Subsequent entries in a procedure linkage table look like this. */ |
| 319 | |
| 320 | static const bfd_byte elf_isac_plt_entry[ISAC_PLT_ENTRY_SIZE] = |
| 321 | { |
| 322 | 0x20, 0x3c, /* move.l #offset,%d0 */ |
| 323 | 0, 0, 0, 0, /* replaced with (.got entry) - . */ |
| 324 | 0x20, 0x7b, 0x08, 0xfa, /* move.l (-6,%pc,%d0:l), %a0 */ |
| 325 | 0x4e, 0xd0, /* jmp (%a0) */ |
| 326 | 0x2f, 0x3c, /* move.l #offset,-(%sp) */ |
| 327 | 0, 0, 0, 0, /* replaced with offset into relocation table */ |
| 328 | 0x61, 0xff, /* bsr.l .plt */ |
| 329 | 0, 0, 0, 0 /* replaced with .plt - . */ |
| 330 | }; |
| 331 | |
| 332 | static const struct elf_m68k_plt_info elf_isac_plt_info = { |
| 333 | ISAC_PLT_ENTRY_SIZE, |
| 334 | elf_isac_plt0_entry, { 2, 12}, |
| 335 | elf_isac_plt_entry, { 2, 20 }, 12 |
| 336 | }; |
| 337 | |
| 338 | #define CPU32_PLT_ENTRY_SIZE 24 |
| 339 | /* Procedure linkage table entries for the cpu32 */ |
| 340 | static const bfd_byte elf_cpu32_plt0_entry[CPU32_PLT_ENTRY_SIZE] = |
| 341 | { |
| 342 | 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */ |
| 343 | 0, 0, 0, 2, /* + (.got + 4) - . */ |
| 344 | 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */ |
| 345 | 0, 0, 0, 2, /* + (.got + 8) - . */ |
| 346 | 0x4e, 0xd1, /* jmp %a1@ */ |
| 347 | 0, 0, 0, 0, /* pad out to 24 bytes. */ |
| 348 | 0, 0 |
| 349 | }; |
| 350 | |
| 351 | static const bfd_byte elf_cpu32_plt_entry[CPU32_PLT_ENTRY_SIZE] = |
| 352 | { |
| 353 | 0x22, 0x7b, 0x01, 0x70, /* moveal %pc@(0xc), %a1 */ |
| 354 | 0, 0, 0, 2, /* + (.got.plt entry) - . */ |
| 355 | 0x4e, 0xd1, /* jmp %a1@ */ |
| 356 | 0x2f, 0x3c, /* move.l #offset,-(%sp) */ |
| 357 | 0, 0, 0, 0, /* + reloc index */ |
| 358 | 0x60, 0xff, /* bra.l .plt */ |
| 359 | 0, 0, 0, 0, /* + .plt - . */ |
| 360 | 0, 0 |
| 361 | }; |
| 362 | |
| 363 | static const struct elf_m68k_plt_info elf_cpu32_plt_info = { |
| 364 | CPU32_PLT_ENTRY_SIZE, |
| 365 | elf_cpu32_plt0_entry, { 4, 12 }, |
| 366 | elf_cpu32_plt_entry, { 4, 18 }, 10 |
| 367 | }; |
| 368 | |
| 369 | /* The m68k linker needs to keep track of the number of relocs that it |
| 370 | decides to copy in check_relocs for each symbol. This is so that it |
| 371 | can discard PC relative relocs if it doesn't need them when linking |
| 372 | with -Bsymbolic. We store the information in a field extending the |
| 373 | regular ELF linker hash table. */ |
| 374 | |
| 375 | /* This structure keeps track of the number of PC relative relocs we have |
| 376 | copied for a given symbol. */ |
| 377 | |
| 378 | struct elf_m68k_pcrel_relocs_copied |
| 379 | { |
| 380 | /* Next section. */ |
| 381 | struct elf_m68k_pcrel_relocs_copied *next; |
| 382 | /* A section in dynobj. */ |
| 383 | asection *section; |
| 384 | /* Number of relocs copied in this section. */ |
| 385 | bfd_size_type count; |
| 386 | }; |
| 387 | |
| 388 | /* m68k ELF linker hash entry. */ |
| 389 | |
| 390 | struct elf_m68k_link_hash_entry |
| 391 | { |
| 392 | struct elf_link_hash_entry root; |
| 393 | |
| 394 | /* Number of PC relative relocs copied for this symbol. */ |
| 395 | struct elf_m68k_pcrel_relocs_copied *pcrel_relocs_copied; |
| 396 | }; |
| 397 | |
| 398 | #define elf_m68k_hash_entry(ent) ((struct elf_m68k_link_hash_entry *) (ent)) |
| 399 | |
| 400 | /* m68k ELF linker hash table. */ |
| 401 | |
| 402 | struct elf_m68k_link_hash_table |
| 403 | { |
| 404 | struct elf_link_hash_table root; |
| 405 | |
| 406 | /* Small local sym to section mapping cache. */ |
| 407 | struct sym_sec_cache sym_sec; |
| 408 | |
| 409 | /* The PLT format used by this link, or NULL if the format has not |
| 410 | yet been chosen. */ |
| 411 | const struct elf_m68k_plt_info *plt_info; |
| 412 | }; |
| 413 | |
| 414 | /* Get the m68k ELF linker hash table from a link_info structure. */ |
| 415 | |
| 416 | #define elf_m68k_hash_table(p) \ |
| 417 | ((struct elf_m68k_link_hash_table *) (p)->hash) |
| 418 | |
| 419 | /* Create an entry in an m68k ELF linker hash table. */ |
| 420 | |
| 421 | static struct bfd_hash_entry * |
| 422 | elf_m68k_link_hash_newfunc (entry, table, string) |
| 423 | struct bfd_hash_entry *entry; |
| 424 | struct bfd_hash_table *table; |
| 425 | const char *string; |
| 426 | { |
| 427 | struct bfd_hash_entry *ret = entry; |
| 428 | |
| 429 | /* Allocate the structure if it has not already been allocated by a |
| 430 | subclass. */ |
| 431 | if (ret == NULL) |
| 432 | ret = bfd_hash_allocate (table, |
| 433 | sizeof (struct elf_m68k_link_hash_entry)); |
| 434 | if (ret == NULL) |
| 435 | return ret; |
| 436 | |
| 437 | /* Call the allocation method of the superclass. */ |
| 438 | ret = _bfd_elf_link_hash_newfunc (ret, table, string); |
| 439 | if (ret != NULL) |
| 440 | elf_m68k_hash_entry (ret)->pcrel_relocs_copied = NULL; |
| 441 | |
| 442 | return ret; |
| 443 | } |
| 444 | |
| 445 | /* Create an m68k ELF linker hash table. */ |
| 446 | |
| 447 | static struct bfd_link_hash_table * |
| 448 | elf_m68k_link_hash_table_create (abfd) |
| 449 | bfd *abfd; |
| 450 | { |
| 451 | struct elf_m68k_link_hash_table *ret; |
| 452 | bfd_size_type amt = sizeof (struct elf_m68k_link_hash_table); |
| 453 | |
| 454 | ret = (struct elf_m68k_link_hash_table *) bfd_malloc (amt); |
| 455 | if (ret == (struct elf_m68k_link_hash_table *) NULL) |
| 456 | return NULL; |
| 457 | |
| 458 | if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, |
| 459 | elf_m68k_link_hash_newfunc, |
| 460 | sizeof (struct elf_m68k_link_hash_entry))) |
| 461 | { |
| 462 | free (ret); |
| 463 | return NULL; |
| 464 | } |
| 465 | |
| 466 | ret->sym_sec.abfd = NULL; |
| 467 | ret->plt_info = NULL; |
| 468 | |
| 469 | return &ret->root.root; |
| 470 | } |
| 471 | |
| 472 | /* Set the right machine number. */ |
| 473 | |
| 474 | static bfd_boolean |
| 475 | elf32_m68k_object_p (bfd *abfd) |
| 476 | { |
| 477 | unsigned int mach = 0; |
| 478 | unsigned features = 0; |
| 479 | flagword eflags = elf_elfheader (abfd)->e_flags; |
| 480 | |
| 481 | if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) |
| 482 | features |= m68000; |
| 483 | else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) |
| 484 | features |= cpu32; |
| 485 | else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) |
| 486 | features |= fido_a; |
| 487 | else |
| 488 | { |
| 489 | switch (eflags & EF_M68K_CF_ISA_MASK) |
| 490 | { |
| 491 | case EF_M68K_CF_ISA_A_NODIV: |
| 492 | features |= mcfisa_a; |
| 493 | break; |
| 494 | case EF_M68K_CF_ISA_A: |
| 495 | features |= mcfisa_a|mcfhwdiv; |
| 496 | break; |
| 497 | case EF_M68K_CF_ISA_A_PLUS: |
| 498 | features |= mcfisa_a|mcfisa_aa|mcfhwdiv|mcfusp; |
| 499 | break; |
| 500 | case EF_M68K_CF_ISA_B_NOUSP: |
| 501 | features |= mcfisa_a|mcfisa_b|mcfhwdiv; |
| 502 | break; |
| 503 | case EF_M68K_CF_ISA_B: |
| 504 | features |= mcfisa_a|mcfisa_b|mcfhwdiv|mcfusp; |
| 505 | break; |
| 506 | case EF_M68K_CF_ISA_C: |
| 507 | features |= mcfisa_a|mcfisa_c|mcfhwdiv|mcfusp; |
| 508 | break; |
| 509 | case EF_M68K_CF_ISA_C_NODIV: |
| 510 | features |= mcfisa_a|mcfisa_c|mcfusp; |
| 511 | break; |
| 512 | } |
| 513 | switch (eflags & EF_M68K_CF_MAC_MASK) |
| 514 | { |
| 515 | case EF_M68K_CF_MAC: |
| 516 | features |= mcfmac; |
| 517 | break; |
| 518 | case EF_M68K_CF_EMAC: |
| 519 | features |= mcfemac; |
| 520 | break; |
| 521 | } |
| 522 | if (eflags & EF_M68K_CF_FLOAT) |
| 523 | features |= cfloat; |
| 524 | } |
| 525 | |
| 526 | mach = bfd_m68k_features_to_mach (features); |
| 527 | bfd_default_set_arch_mach (abfd, bfd_arch_m68k, mach); |
| 528 | |
| 529 | return TRUE; |
| 530 | } |
| 531 | |
| 532 | /* Keep m68k-specific flags in the ELF header. */ |
| 533 | static bfd_boolean |
| 534 | elf32_m68k_set_private_flags (abfd, flags) |
| 535 | bfd *abfd; |
| 536 | flagword flags; |
| 537 | { |
| 538 | elf_elfheader (abfd)->e_flags = flags; |
| 539 | elf_flags_init (abfd) = TRUE; |
| 540 | return TRUE; |
| 541 | } |
| 542 | |
| 543 | /* Merge backend specific data from an object file to the output |
| 544 | object file when linking. */ |
| 545 | static bfd_boolean |
| 546 | elf32_m68k_merge_private_bfd_data (ibfd, obfd) |
| 547 | bfd *ibfd; |
| 548 | bfd *obfd; |
| 549 | { |
| 550 | flagword out_flags; |
| 551 | flagword in_flags; |
| 552 | flagword out_isa; |
| 553 | flagword in_isa; |
| 554 | const bfd_arch_info_type *arch_info; |
| 555 | |
| 556 | if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour |
| 557 | || bfd_get_flavour (obfd) != bfd_target_elf_flavour) |
| 558 | return FALSE; |
| 559 | |
| 560 | /* Get the merged machine. This checks for incompatibility between |
| 561 | Coldfire & non-Coldfire flags, incompability between different |
| 562 | Coldfire ISAs, and incompability between different MAC types. */ |
| 563 | arch_info = bfd_arch_get_compatible (ibfd, obfd, FALSE); |
| 564 | if (!arch_info) |
| 565 | return FALSE; |
| 566 | |
| 567 | bfd_set_arch_mach (obfd, bfd_arch_m68k, arch_info->mach); |
| 568 | |
| 569 | in_flags = elf_elfheader (ibfd)->e_flags; |
| 570 | if (!elf_flags_init (obfd)) |
| 571 | { |
| 572 | elf_flags_init (obfd) = TRUE; |
| 573 | out_flags = in_flags; |
| 574 | } |
| 575 | else |
| 576 | { |
| 577 | out_flags = elf_elfheader (obfd)->e_flags; |
| 578 | unsigned int variant_mask; |
| 579 | |
| 580 | if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) |
| 581 | variant_mask = 0; |
| 582 | else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) |
| 583 | variant_mask = 0; |
| 584 | else if ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) |
| 585 | variant_mask = 0; |
| 586 | else |
| 587 | variant_mask = EF_M68K_CF_ISA_MASK; |
| 588 | |
| 589 | in_isa = (in_flags & variant_mask); |
| 590 | out_isa = (out_flags & variant_mask); |
| 591 | if (in_isa > out_isa) |
| 592 | out_flags ^= in_isa ^ out_isa; |
| 593 | if (((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32 |
| 594 | && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) |
| 595 | || ((in_flags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO |
| 596 | && (out_flags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32)) |
| 597 | out_flags = EF_M68K_FIDO; |
| 598 | else |
| 599 | out_flags |= in_flags ^ in_isa; |
| 600 | } |
| 601 | elf_elfheader (obfd)->e_flags = out_flags; |
| 602 | |
| 603 | return TRUE; |
| 604 | } |
| 605 | |
| 606 | /* Display the flags field. */ |
| 607 | static bfd_boolean |
| 608 | elf32_m68k_print_private_bfd_data (abfd, ptr) |
| 609 | bfd *abfd; |
| 610 | PTR ptr; |
| 611 | { |
| 612 | FILE *file = (FILE *) ptr; |
| 613 | flagword eflags = elf_elfheader (abfd)->e_flags; |
| 614 | |
| 615 | BFD_ASSERT (abfd != NULL && ptr != NULL); |
| 616 | |
| 617 | /* Print normal ELF private data. */ |
| 618 | _bfd_elf_print_private_bfd_data (abfd, ptr); |
| 619 | |
| 620 | /* Ignore init flag - it may not be set, despite the flags field containing valid data. */ |
| 621 | |
| 622 | /* xgettext:c-format */ |
| 623 | fprintf (file, _("private flags = %lx:"), elf_elfheader (abfd)->e_flags); |
| 624 | |
| 625 | if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_M68000) |
| 626 | fprintf (file, " [m68000]"); |
| 627 | else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CPU32) |
| 628 | fprintf (file, " [cpu32]"); |
| 629 | else if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_FIDO) |
| 630 | fprintf (file, " [fido]"); |
| 631 | else |
| 632 | { |
| 633 | if ((eflags & EF_M68K_ARCH_MASK) == EF_M68K_CFV4E) |
| 634 | fprintf (file, " [cfv4e]"); |
| 635 | |
| 636 | if (eflags & EF_M68K_CF_ISA_MASK) |
| 637 | { |
| 638 | char const *isa = _("unknown"); |
| 639 | char const *mac = _("unknown"); |
| 640 | char const *additional = ""; |
| 641 | |
| 642 | switch (eflags & EF_M68K_CF_ISA_MASK) |
| 643 | { |
| 644 | case EF_M68K_CF_ISA_A_NODIV: |
| 645 | isa = "A"; |
| 646 | additional = " [nodiv]"; |
| 647 | break; |
| 648 | case EF_M68K_CF_ISA_A: |
| 649 | isa = "A"; |
| 650 | break; |
| 651 | case EF_M68K_CF_ISA_A_PLUS: |
| 652 | isa = "A+"; |
| 653 | break; |
| 654 | case EF_M68K_CF_ISA_B_NOUSP: |
| 655 | isa = "B"; |
| 656 | additional = " [nousp]"; |
| 657 | break; |
| 658 | case EF_M68K_CF_ISA_B: |
| 659 | isa = "B"; |
| 660 | break; |
| 661 | case EF_M68K_CF_ISA_C: |
| 662 | isa = "C"; |
| 663 | break; |
| 664 | case EF_M68K_CF_ISA_C_NODIV: |
| 665 | isa = "C"; |
| 666 | additional = " [nodiv]"; |
| 667 | break; |
| 668 | } |
| 669 | fprintf (file, " [isa %s]%s", isa, additional); |
| 670 | if (eflags & EF_M68K_CF_FLOAT) |
| 671 | fprintf (file, " [float]"); |
| 672 | switch (eflags & EF_M68K_CF_MAC_MASK) |
| 673 | { |
| 674 | case 0: |
| 675 | mac = NULL; |
| 676 | break; |
| 677 | case EF_M68K_CF_MAC: |
| 678 | mac = "mac"; |
| 679 | break; |
| 680 | case EF_M68K_CF_EMAC: |
| 681 | mac = "emac"; |
| 682 | break; |
| 683 | } |
| 684 | if (mac) |
| 685 | fprintf (file, " [%s]", mac); |
| 686 | } |
| 687 | } |
| 688 | |
| 689 | fputc ('\n', file); |
| 690 | |
| 691 | return TRUE; |
| 692 | } |
| 693 | /* Look through the relocs for a section during the first phase, and |
| 694 | allocate space in the global offset table or procedure linkage |
| 695 | table. */ |
| 696 | |
| 697 | static bfd_boolean |
| 698 | elf_m68k_check_relocs (abfd, info, sec, relocs) |
| 699 | bfd *abfd; |
| 700 | struct bfd_link_info *info; |
| 701 | asection *sec; |
| 702 | const Elf_Internal_Rela *relocs; |
| 703 | { |
| 704 | bfd *dynobj; |
| 705 | Elf_Internal_Shdr *symtab_hdr; |
| 706 | struct elf_link_hash_entry **sym_hashes; |
| 707 | bfd_signed_vma *local_got_refcounts; |
| 708 | const Elf_Internal_Rela *rel; |
| 709 | const Elf_Internal_Rela *rel_end; |
| 710 | asection *sgot; |
| 711 | asection *srelgot; |
| 712 | asection *sreloc; |
| 713 | |
| 714 | if (info->relocatable) |
| 715 | return TRUE; |
| 716 | |
| 717 | dynobj = elf_hash_table (info)->dynobj; |
| 718 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 719 | sym_hashes = elf_sym_hashes (abfd); |
| 720 | local_got_refcounts = elf_local_got_refcounts (abfd); |
| 721 | |
| 722 | sgot = NULL; |
| 723 | srelgot = NULL; |
| 724 | sreloc = NULL; |
| 725 | |
| 726 | rel_end = relocs + sec->reloc_count; |
| 727 | for (rel = relocs; rel < rel_end; rel++) |
| 728 | { |
| 729 | unsigned long r_symndx; |
| 730 | struct elf_link_hash_entry *h; |
| 731 | |
| 732 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 733 | |
| 734 | if (r_symndx < symtab_hdr->sh_info) |
| 735 | h = NULL; |
| 736 | else |
| 737 | { |
| 738 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 739 | while (h->root.type == bfd_link_hash_indirect |
| 740 | || h->root.type == bfd_link_hash_warning) |
| 741 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 742 | } |
| 743 | |
| 744 | switch (ELF32_R_TYPE (rel->r_info)) |
| 745 | { |
| 746 | case R_68K_GOT8: |
| 747 | case R_68K_GOT16: |
| 748 | case R_68K_GOT32: |
| 749 | if (h != NULL |
| 750 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) |
| 751 | break; |
| 752 | /* Fall through. */ |
| 753 | case R_68K_GOT8O: |
| 754 | case R_68K_GOT16O: |
| 755 | case R_68K_GOT32O: |
| 756 | /* This symbol requires a global offset table entry. */ |
| 757 | |
| 758 | if (dynobj == NULL) |
| 759 | { |
| 760 | /* Create the .got section. */ |
| 761 | elf_hash_table (info)->dynobj = dynobj = abfd; |
| 762 | if (!_bfd_elf_create_got_section (dynobj, info)) |
| 763 | return FALSE; |
| 764 | } |
| 765 | |
| 766 | if (sgot == NULL) |
| 767 | { |
| 768 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 769 | BFD_ASSERT (sgot != NULL); |
| 770 | } |
| 771 | |
| 772 | if (srelgot == NULL |
| 773 | && (h != NULL || info->shared)) |
| 774 | { |
| 775 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 776 | if (srelgot == NULL) |
| 777 | { |
| 778 | srelgot = bfd_make_section_with_flags (dynobj, |
| 779 | ".rela.got", |
| 780 | (SEC_ALLOC |
| 781 | | SEC_LOAD |
| 782 | | SEC_HAS_CONTENTS |
| 783 | | SEC_IN_MEMORY |
| 784 | | SEC_LINKER_CREATED |
| 785 | | SEC_READONLY)); |
| 786 | if (srelgot == NULL |
| 787 | || !bfd_set_section_alignment (dynobj, srelgot, 2)) |
| 788 | return FALSE; |
| 789 | } |
| 790 | } |
| 791 | |
| 792 | if (h != NULL) |
| 793 | { |
| 794 | if (h->got.refcount == 0) |
| 795 | { |
| 796 | /* Make sure this symbol is output as a dynamic symbol. */ |
| 797 | if (h->dynindx == -1 |
| 798 | && !h->forced_local) |
| 799 | { |
| 800 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) |
| 801 | return FALSE; |
| 802 | } |
| 803 | |
| 804 | /* Allocate space in the .got section. */ |
| 805 | sgot->size += 4; |
| 806 | /* Allocate relocation space. */ |
| 807 | srelgot->size += sizeof (Elf32_External_Rela); |
| 808 | } |
| 809 | h->got.refcount++; |
| 810 | } |
| 811 | else |
| 812 | { |
| 813 | /* This is a global offset table entry for a local symbol. */ |
| 814 | if (local_got_refcounts == NULL) |
| 815 | { |
| 816 | bfd_size_type size; |
| 817 | |
| 818 | size = symtab_hdr->sh_info; |
| 819 | size *= sizeof (bfd_signed_vma); |
| 820 | local_got_refcounts = ((bfd_signed_vma *) |
| 821 | bfd_zalloc (abfd, size)); |
| 822 | if (local_got_refcounts == NULL) |
| 823 | return FALSE; |
| 824 | elf_local_got_refcounts (abfd) = local_got_refcounts; |
| 825 | } |
| 826 | if (local_got_refcounts[r_symndx] == 0) |
| 827 | { |
| 828 | sgot->size += 4; |
| 829 | if (info->shared) |
| 830 | { |
| 831 | /* If we are generating a shared object, we need to |
| 832 | output a R_68K_RELATIVE reloc so that the dynamic |
| 833 | linker can adjust this GOT entry. */ |
| 834 | srelgot->size += sizeof (Elf32_External_Rela); |
| 835 | } |
| 836 | } |
| 837 | local_got_refcounts[r_symndx]++; |
| 838 | } |
| 839 | break; |
| 840 | |
| 841 | case R_68K_PLT8: |
| 842 | case R_68K_PLT16: |
| 843 | case R_68K_PLT32: |
| 844 | /* This symbol requires a procedure linkage table entry. We |
| 845 | actually build the entry in adjust_dynamic_symbol, |
| 846 | because this might be a case of linking PIC code which is |
| 847 | never referenced by a dynamic object, in which case we |
| 848 | don't need to generate a procedure linkage table entry |
| 849 | after all. */ |
| 850 | |
| 851 | /* If this is a local symbol, we resolve it directly without |
| 852 | creating a procedure linkage table entry. */ |
| 853 | if (h == NULL) |
| 854 | continue; |
| 855 | |
| 856 | h->needs_plt = 1; |
| 857 | h->plt.refcount++; |
| 858 | break; |
| 859 | |
| 860 | case R_68K_PLT8O: |
| 861 | case R_68K_PLT16O: |
| 862 | case R_68K_PLT32O: |
| 863 | /* This symbol requires a procedure linkage table entry. */ |
| 864 | |
| 865 | if (h == NULL) |
| 866 | { |
| 867 | /* It does not make sense to have this relocation for a |
| 868 | local symbol. FIXME: does it? How to handle it if |
| 869 | it does make sense? */ |
| 870 | bfd_set_error (bfd_error_bad_value); |
| 871 | return FALSE; |
| 872 | } |
| 873 | |
| 874 | /* Make sure this symbol is output as a dynamic symbol. */ |
| 875 | if (h->dynindx == -1 |
| 876 | && !h->forced_local) |
| 877 | { |
| 878 | if (!bfd_elf_link_record_dynamic_symbol (info, h)) |
| 879 | return FALSE; |
| 880 | } |
| 881 | |
| 882 | h->needs_plt = 1; |
| 883 | h->plt.refcount++; |
| 884 | break; |
| 885 | |
| 886 | case R_68K_PC8: |
| 887 | case R_68K_PC16: |
| 888 | case R_68K_PC32: |
| 889 | /* If we are creating a shared library and this is not a local |
| 890 | symbol, we need to copy the reloc into the shared library. |
| 891 | However when linking with -Bsymbolic and this is a global |
| 892 | symbol which is defined in an object we are including in the |
| 893 | link (i.e., DEF_REGULAR is set), then we can resolve the |
| 894 | reloc directly. At this point we have not seen all the input |
| 895 | files, so it is possible that DEF_REGULAR is not set now but |
| 896 | will be set later (it is never cleared). We account for that |
| 897 | possibility below by storing information in the |
| 898 | pcrel_relocs_copied field of the hash table entry. */ |
| 899 | if (!(info->shared |
| 900 | && (sec->flags & SEC_ALLOC) != 0 |
| 901 | && h != NULL |
| 902 | && (!info->symbolic |
| 903 | || h->root.type == bfd_link_hash_defweak |
| 904 | || !h->def_regular))) |
| 905 | { |
| 906 | if (h != NULL) |
| 907 | { |
| 908 | /* Make sure a plt entry is created for this symbol if |
| 909 | it turns out to be a function defined by a dynamic |
| 910 | object. */ |
| 911 | h->plt.refcount++; |
| 912 | } |
| 913 | break; |
| 914 | } |
| 915 | /* Fall through. */ |
| 916 | case R_68K_8: |
| 917 | case R_68K_16: |
| 918 | case R_68K_32: |
| 919 | if (h != NULL) |
| 920 | { |
| 921 | /* Make sure a plt entry is created for this symbol if it |
| 922 | turns out to be a function defined by a dynamic object. */ |
| 923 | h->plt.refcount++; |
| 924 | } |
| 925 | |
| 926 | /* If we are creating a shared library, we need to copy the |
| 927 | reloc into the shared library. */ |
| 928 | if (info->shared |
| 929 | && (sec->flags & SEC_ALLOC) != 0) |
| 930 | { |
| 931 | /* When creating a shared object, we must copy these |
| 932 | reloc types into the output file. We create a reloc |
| 933 | section in dynobj and make room for this reloc. */ |
| 934 | if (sreloc == NULL) |
| 935 | { |
| 936 | const char *name; |
| 937 | |
| 938 | name = (bfd_elf_string_from_elf_section |
| 939 | (abfd, |
| 940 | elf_elfheader (abfd)->e_shstrndx, |
| 941 | elf_section_data (sec)->rel_hdr.sh_name)); |
| 942 | if (name == NULL) |
| 943 | return FALSE; |
| 944 | |
| 945 | BFD_ASSERT (CONST_STRNEQ (name, ".rela") |
| 946 | && strcmp (bfd_get_section_name (abfd, sec), |
| 947 | name + 5) == 0); |
| 948 | |
| 949 | sreloc = bfd_get_section_by_name (dynobj, name); |
| 950 | if (sreloc == NULL) |
| 951 | { |
| 952 | sreloc = bfd_make_section_with_flags (dynobj, |
| 953 | name, |
| 954 | (SEC_ALLOC |
| 955 | | SEC_LOAD |
| 956 | | SEC_HAS_CONTENTS |
| 957 | | SEC_IN_MEMORY |
| 958 | | SEC_LINKER_CREATED |
| 959 | | SEC_READONLY)); |
| 960 | if (sreloc == NULL |
| 961 | || !bfd_set_section_alignment (dynobj, sreloc, 2)) |
| 962 | return FALSE; |
| 963 | } |
| 964 | elf_section_data (sec)->sreloc = sreloc; |
| 965 | } |
| 966 | |
| 967 | if (sec->flags & SEC_READONLY |
| 968 | /* Don't set DF_TEXTREL yet for PC relative |
| 969 | relocations, they might be discarded later. */ |
| 970 | && !(ELF32_R_TYPE (rel->r_info) == R_68K_PC8 |
| 971 | || ELF32_R_TYPE (rel->r_info) == R_68K_PC16 |
| 972 | || ELF32_R_TYPE (rel->r_info) == R_68K_PC32)) |
| 973 | info->flags |= DF_TEXTREL; |
| 974 | |
| 975 | sreloc->size += sizeof (Elf32_External_Rela); |
| 976 | |
| 977 | /* We count the number of PC relative relocations we have |
| 978 | entered for this symbol, so that we can discard them |
| 979 | again if, in the -Bsymbolic case, the symbol is later |
| 980 | defined by a regular object, or, in the normal shared |
| 981 | case, the symbol is forced to be local. Note that this |
| 982 | function is only called if we are using an m68kelf linker |
| 983 | hash table, which means that h is really a pointer to an |
| 984 | elf_m68k_link_hash_entry. */ |
| 985 | if (ELF32_R_TYPE (rel->r_info) == R_68K_PC8 |
| 986 | || ELF32_R_TYPE (rel->r_info) == R_68K_PC16 |
| 987 | || ELF32_R_TYPE (rel->r_info) == R_68K_PC32) |
| 988 | { |
| 989 | struct elf_m68k_pcrel_relocs_copied *p; |
| 990 | struct elf_m68k_pcrel_relocs_copied **head; |
| 991 | |
| 992 | if (h != NULL) |
| 993 | { |
| 994 | struct elf_m68k_link_hash_entry *eh |
| 995 | = elf_m68k_hash_entry (h); |
| 996 | head = &eh->pcrel_relocs_copied; |
| 997 | } |
| 998 | else |
| 999 | { |
| 1000 | asection *s; |
| 1001 | void *vpp; |
| 1002 | |
| 1003 | s = (bfd_section_from_r_symndx |
| 1004 | (abfd, &elf_m68k_hash_table (info)->sym_sec, |
| 1005 | sec, r_symndx)); |
| 1006 | if (s == NULL) |
| 1007 | return FALSE; |
| 1008 | |
| 1009 | vpp = &elf_section_data (s)->local_dynrel; |
| 1010 | head = (struct elf_m68k_pcrel_relocs_copied **) vpp; |
| 1011 | } |
| 1012 | |
| 1013 | for (p = *head; p != NULL; p = p->next) |
| 1014 | if (p->section == sreloc) |
| 1015 | break; |
| 1016 | |
| 1017 | if (p == NULL) |
| 1018 | { |
| 1019 | p = ((struct elf_m68k_pcrel_relocs_copied *) |
| 1020 | bfd_alloc (dynobj, (bfd_size_type) sizeof *p)); |
| 1021 | if (p == NULL) |
| 1022 | return FALSE; |
| 1023 | p->next = *head; |
| 1024 | *head = p; |
| 1025 | p->section = sreloc; |
| 1026 | p->count = 0; |
| 1027 | } |
| 1028 | |
| 1029 | ++p->count; |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | break; |
| 1034 | |
| 1035 | /* This relocation describes the C++ object vtable hierarchy. |
| 1036 | Reconstruct it for later use during GC. */ |
| 1037 | case R_68K_GNU_VTINHERIT: |
| 1038 | if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset)) |
| 1039 | return FALSE; |
| 1040 | break; |
| 1041 | |
| 1042 | /* This relocation describes which C++ vtable entries are actually |
| 1043 | used. Record for later use during GC. */ |
| 1044 | case R_68K_GNU_VTENTRY: |
| 1045 | if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) |
| 1046 | return FALSE; |
| 1047 | break; |
| 1048 | |
| 1049 | default: |
| 1050 | break; |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | return TRUE; |
| 1055 | } |
| 1056 | |
| 1057 | /* Return the section that should be marked against GC for a given |
| 1058 | relocation. */ |
| 1059 | |
| 1060 | static asection * |
| 1061 | elf_m68k_gc_mark_hook (asection *sec, |
| 1062 | struct bfd_link_info *info, |
| 1063 | Elf_Internal_Rela *rel, |
| 1064 | struct elf_link_hash_entry *h, |
| 1065 | Elf_Internal_Sym *sym) |
| 1066 | { |
| 1067 | if (h != NULL) |
| 1068 | switch (ELF32_R_TYPE (rel->r_info)) |
| 1069 | { |
| 1070 | case R_68K_GNU_VTINHERIT: |
| 1071 | case R_68K_GNU_VTENTRY: |
| 1072 | return NULL; |
| 1073 | } |
| 1074 | |
| 1075 | return _bfd_elf_gc_mark_hook (sec, info, rel, h, sym); |
| 1076 | } |
| 1077 | |
| 1078 | /* Update the got entry reference counts for the section being removed. */ |
| 1079 | |
| 1080 | static bfd_boolean |
| 1081 | elf_m68k_gc_sweep_hook (bfd *abfd, |
| 1082 | struct bfd_link_info *info, |
| 1083 | asection *sec, |
| 1084 | const Elf_Internal_Rela *relocs) |
| 1085 | { |
| 1086 | Elf_Internal_Shdr *symtab_hdr; |
| 1087 | struct elf_link_hash_entry **sym_hashes; |
| 1088 | bfd_signed_vma *local_got_refcounts; |
| 1089 | const Elf_Internal_Rela *rel, *relend; |
| 1090 | bfd *dynobj; |
| 1091 | asection *sgot; |
| 1092 | asection *srelgot; |
| 1093 | |
| 1094 | dynobj = elf_hash_table (info)->dynobj; |
| 1095 | if (dynobj == NULL) |
| 1096 | return TRUE; |
| 1097 | |
| 1098 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 1099 | sym_hashes = elf_sym_hashes (abfd); |
| 1100 | local_got_refcounts = elf_local_got_refcounts (abfd); |
| 1101 | |
| 1102 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 1103 | srelgot = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 1104 | |
| 1105 | relend = relocs + sec->reloc_count; |
| 1106 | for (rel = relocs; rel < relend; rel++) |
| 1107 | { |
| 1108 | unsigned long r_symndx; |
| 1109 | struct elf_link_hash_entry *h = NULL; |
| 1110 | |
| 1111 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 1112 | if (r_symndx >= symtab_hdr->sh_info) |
| 1113 | { |
| 1114 | h = sym_hashes[r_symndx - symtab_hdr->sh_info]; |
| 1115 | while (h->root.type == bfd_link_hash_indirect |
| 1116 | || h->root.type == bfd_link_hash_warning) |
| 1117 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 1118 | } |
| 1119 | |
| 1120 | switch (ELF32_R_TYPE (rel->r_info)) |
| 1121 | { |
| 1122 | case R_68K_GOT8: |
| 1123 | case R_68K_GOT16: |
| 1124 | case R_68K_GOT32: |
| 1125 | case R_68K_GOT8O: |
| 1126 | case R_68K_GOT16O: |
| 1127 | case R_68K_GOT32O: |
| 1128 | if (h != NULL) |
| 1129 | { |
| 1130 | if (h->got.refcount > 0) |
| 1131 | { |
| 1132 | --h->got.refcount; |
| 1133 | if (h->got.refcount == 0) |
| 1134 | { |
| 1135 | /* We don't need the .got entry any more. */ |
| 1136 | sgot->size -= 4; |
| 1137 | srelgot->size -= sizeof (Elf32_External_Rela); |
| 1138 | } |
| 1139 | } |
| 1140 | } |
| 1141 | else if (local_got_refcounts != NULL) |
| 1142 | { |
| 1143 | if (local_got_refcounts[r_symndx] > 0) |
| 1144 | { |
| 1145 | --local_got_refcounts[r_symndx]; |
| 1146 | if (local_got_refcounts[r_symndx] == 0) |
| 1147 | { |
| 1148 | /* We don't need the .got entry any more. */ |
| 1149 | sgot->size -= 4; |
| 1150 | if (info->shared) |
| 1151 | srelgot->size -= sizeof (Elf32_External_Rela); |
| 1152 | } |
| 1153 | } |
| 1154 | } |
| 1155 | break; |
| 1156 | |
| 1157 | case R_68K_PLT8: |
| 1158 | case R_68K_PLT16: |
| 1159 | case R_68K_PLT32: |
| 1160 | case R_68K_PLT8O: |
| 1161 | case R_68K_PLT16O: |
| 1162 | case R_68K_PLT32O: |
| 1163 | case R_68K_PC8: |
| 1164 | case R_68K_PC16: |
| 1165 | case R_68K_PC32: |
| 1166 | case R_68K_8: |
| 1167 | case R_68K_16: |
| 1168 | case R_68K_32: |
| 1169 | if (h != NULL) |
| 1170 | { |
| 1171 | if (h->plt.refcount > 0) |
| 1172 | --h->plt.refcount; |
| 1173 | } |
| 1174 | break; |
| 1175 | |
| 1176 | default: |
| 1177 | break; |
| 1178 | } |
| 1179 | } |
| 1180 | |
| 1181 | return TRUE; |
| 1182 | } |
| 1183 | \f |
| 1184 | /* Return the type of PLT associated with OUTPUT_BFD. */ |
| 1185 | |
| 1186 | static const struct elf_m68k_plt_info * |
| 1187 | elf_m68k_get_plt_info (bfd *output_bfd) |
| 1188 | { |
| 1189 | unsigned int features; |
| 1190 | |
| 1191 | features = bfd_m68k_mach_to_features (bfd_get_mach (output_bfd)); |
| 1192 | if (features & cpu32) |
| 1193 | return &elf_cpu32_plt_info; |
| 1194 | if (features & mcfisa_b) |
| 1195 | return &elf_isab_plt_info; |
| 1196 | if (features & mcfisa_c) |
| 1197 | return &elf_isac_plt_info; |
| 1198 | return &elf_m68k_plt_info; |
| 1199 | } |
| 1200 | |
| 1201 | /* This function is called after all the input files have been read, |
| 1202 | and the input sections have been assigned to output sections. |
| 1203 | It's a convenient place to determine the PLT style. */ |
| 1204 | |
| 1205 | static bfd_boolean |
| 1206 | elf_m68k_always_size_sections (bfd *output_bfd, struct bfd_link_info *info) |
| 1207 | { |
| 1208 | elf_m68k_hash_table (info)->plt_info = elf_m68k_get_plt_info (output_bfd); |
| 1209 | return TRUE; |
| 1210 | } |
| 1211 | |
| 1212 | /* Adjust a symbol defined by a dynamic object and referenced by a |
| 1213 | regular object. The current definition is in some section of the |
| 1214 | dynamic object, but we're not including those sections. We have to |
| 1215 | change the definition to something the rest of the link can |
| 1216 | understand. */ |
| 1217 | |
| 1218 | static bfd_boolean |
| 1219 | elf_m68k_adjust_dynamic_symbol (info, h) |
| 1220 | struct bfd_link_info *info; |
| 1221 | struct elf_link_hash_entry *h; |
| 1222 | { |
| 1223 | struct elf_m68k_link_hash_table *htab; |
| 1224 | bfd *dynobj; |
| 1225 | asection *s; |
| 1226 | |
| 1227 | htab = elf_m68k_hash_table (info); |
| 1228 | dynobj = elf_hash_table (info)->dynobj; |
| 1229 | |
| 1230 | /* Make sure we know what is going on here. */ |
| 1231 | BFD_ASSERT (dynobj != NULL |
| 1232 | && (h->needs_plt |
| 1233 | || h->u.weakdef != NULL |
| 1234 | || (h->def_dynamic |
| 1235 | && h->ref_regular |
| 1236 | && !h->def_regular))); |
| 1237 | |
| 1238 | /* If this is a function, put it in the procedure linkage table. We |
| 1239 | will fill in the contents of the procedure linkage table later, |
| 1240 | when we know the address of the .got section. */ |
| 1241 | if (h->type == STT_FUNC |
| 1242 | || h->needs_plt) |
| 1243 | { |
| 1244 | if ((h->plt.refcount <= 0 |
| 1245 | || SYMBOL_CALLS_LOCAL (info, h) |
| 1246 | || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT |
| 1247 | && h->root.type == bfd_link_hash_undefweak)) |
| 1248 | /* We must always create the plt entry if it was referenced |
| 1249 | by a PLTxxO relocation. In this case we already recorded |
| 1250 | it as a dynamic symbol. */ |
| 1251 | && h->dynindx == -1) |
| 1252 | { |
| 1253 | /* This case can occur if we saw a PLTxx reloc in an input |
| 1254 | file, but the symbol was never referred to by a dynamic |
| 1255 | object, or if all references were garbage collected. In |
| 1256 | such a case, we don't actually need to build a procedure |
| 1257 | linkage table, and we can just do a PCxx reloc instead. */ |
| 1258 | h->plt.offset = (bfd_vma) -1; |
| 1259 | h->needs_plt = 0; |
| 1260 | return TRUE; |
| 1261 | } |
| 1262 | |
| 1263 | /* Make sure this symbol is output as a dynamic symbol. */ |
| 1264 | if (h->dynindx == -1 |
| 1265 | && !h->forced_local) |
| 1266 | { |
| 1267 | if (! bfd_elf_link_record_dynamic_symbol (info, h)) |
| 1268 | return FALSE; |
| 1269 | } |
| 1270 | |
| 1271 | s = bfd_get_section_by_name (dynobj, ".plt"); |
| 1272 | BFD_ASSERT (s != NULL); |
| 1273 | |
| 1274 | /* If this is the first .plt entry, make room for the special |
| 1275 | first entry. */ |
| 1276 | if (s->size == 0) |
| 1277 | s->size = htab->plt_info->size; |
| 1278 | |
| 1279 | /* If this symbol is not defined in a regular file, and we are |
| 1280 | not generating a shared library, then set the symbol to this |
| 1281 | location in the .plt. This is required to make function |
| 1282 | pointers compare as equal between the normal executable and |
| 1283 | the shared library. */ |
| 1284 | if (!info->shared |
| 1285 | && !h->def_regular) |
| 1286 | { |
| 1287 | h->root.u.def.section = s; |
| 1288 | h->root.u.def.value = s->size; |
| 1289 | } |
| 1290 | |
| 1291 | h->plt.offset = s->size; |
| 1292 | |
| 1293 | /* Make room for this entry. */ |
| 1294 | s->size += htab->plt_info->size; |
| 1295 | |
| 1296 | /* We also need to make an entry in the .got.plt section, which |
| 1297 | will be placed in the .got section by the linker script. */ |
| 1298 | s = bfd_get_section_by_name (dynobj, ".got.plt"); |
| 1299 | BFD_ASSERT (s != NULL); |
| 1300 | s->size += 4; |
| 1301 | |
| 1302 | /* We also need to make an entry in the .rela.plt section. */ |
| 1303 | s = bfd_get_section_by_name (dynobj, ".rela.plt"); |
| 1304 | BFD_ASSERT (s != NULL); |
| 1305 | s->size += sizeof (Elf32_External_Rela); |
| 1306 | |
| 1307 | return TRUE; |
| 1308 | } |
| 1309 | |
| 1310 | /* Reinitialize the plt offset now that it is not used as a reference |
| 1311 | count any more. */ |
| 1312 | h->plt.offset = (bfd_vma) -1; |
| 1313 | |
| 1314 | /* If this is a weak symbol, and there is a real definition, the |
| 1315 | processor independent code will have arranged for us to see the |
| 1316 | real definition first, and we can just use the same value. */ |
| 1317 | if (h->u.weakdef != NULL) |
| 1318 | { |
| 1319 | BFD_ASSERT (h->u.weakdef->root.type == bfd_link_hash_defined |
| 1320 | || h->u.weakdef->root.type == bfd_link_hash_defweak); |
| 1321 | h->root.u.def.section = h->u.weakdef->root.u.def.section; |
| 1322 | h->root.u.def.value = h->u.weakdef->root.u.def.value; |
| 1323 | return TRUE; |
| 1324 | } |
| 1325 | |
| 1326 | /* This is a reference to a symbol defined by a dynamic object which |
| 1327 | is not a function. */ |
| 1328 | |
| 1329 | /* If we are creating a shared library, we must presume that the |
| 1330 | only references to the symbol are via the global offset table. |
| 1331 | For such cases we need not do anything here; the relocations will |
| 1332 | be handled correctly by relocate_section. */ |
| 1333 | if (info->shared) |
| 1334 | return TRUE; |
| 1335 | |
| 1336 | if (h->size == 0) |
| 1337 | { |
| 1338 | (*_bfd_error_handler) (_("dynamic variable `%s' is zero size"), |
| 1339 | h->root.root.string); |
| 1340 | return TRUE; |
| 1341 | } |
| 1342 | |
| 1343 | /* We must allocate the symbol in our .dynbss section, which will |
| 1344 | become part of the .bss section of the executable. There will be |
| 1345 | an entry for this symbol in the .dynsym section. The dynamic |
| 1346 | object will contain position independent code, so all references |
| 1347 | from the dynamic object to this symbol will go through the global |
| 1348 | offset table. The dynamic linker will use the .dynsym entry to |
| 1349 | determine the address it must put in the global offset table, so |
| 1350 | both the dynamic object and the regular object will refer to the |
| 1351 | same memory location for the variable. */ |
| 1352 | |
| 1353 | s = bfd_get_section_by_name (dynobj, ".dynbss"); |
| 1354 | BFD_ASSERT (s != NULL); |
| 1355 | |
| 1356 | /* We must generate a R_68K_COPY reloc to tell the dynamic linker to |
| 1357 | copy the initial value out of the dynamic object and into the |
| 1358 | runtime process image. We need to remember the offset into the |
| 1359 | .rela.bss section we are going to use. */ |
| 1360 | if ((h->root.u.def.section->flags & SEC_ALLOC) != 0) |
| 1361 | { |
| 1362 | asection *srel; |
| 1363 | |
| 1364 | srel = bfd_get_section_by_name (dynobj, ".rela.bss"); |
| 1365 | BFD_ASSERT (srel != NULL); |
| 1366 | srel->size += sizeof (Elf32_External_Rela); |
| 1367 | h->needs_copy = 1; |
| 1368 | } |
| 1369 | |
| 1370 | return _bfd_elf_adjust_dynamic_copy (h, s); |
| 1371 | } |
| 1372 | |
| 1373 | /* Set the sizes of the dynamic sections. */ |
| 1374 | |
| 1375 | static bfd_boolean |
| 1376 | elf_m68k_size_dynamic_sections (output_bfd, info) |
| 1377 | bfd *output_bfd ATTRIBUTE_UNUSED; |
| 1378 | struct bfd_link_info *info; |
| 1379 | { |
| 1380 | bfd *dynobj; |
| 1381 | asection *s; |
| 1382 | bfd_boolean plt; |
| 1383 | bfd_boolean relocs; |
| 1384 | |
| 1385 | dynobj = elf_hash_table (info)->dynobj; |
| 1386 | BFD_ASSERT (dynobj != NULL); |
| 1387 | |
| 1388 | if (elf_hash_table (info)->dynamic_sections_created) |
| 1389 | { |
| 1390 | /* Set the contents of the .interp section to the interpreter. */ |
| 1391 | if (info->executable) |
| 1392 | { |
| 1393 | s = bfd_get_section_by_name (dynobj, ".interp"); |
| 1394 | BFD_ASSERT (s != NULL); |
| 1395 | s->size = sizeof ELF_DYNAMIC_INTERPRETER; |
| 1396 | s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER; |
| 1397 | } |
| 1398 | } |
| 1399 | else |
| 1400 | { |
| 1401 | /* We may have created entries in the .rela.got section. |
| 1402 | However, if we are not creating the dynamic sections, we will |
| 1403 | not actually use these entries. Reset the size of .rela.got, |
| 1404 | which will cause it to get stripped from the output file |
| 1405 | below. */ |
| 1406 | s = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 1407 | if (s != NULL) |
| 1408 | s->size = 0; |
| 1409 | } |
| 1410 | |
| 1411 | /* If this is a -Bsymbolic shared link, then we need to discard all |
| 1412 | PC relative relocs against symbols defined in a regular object. |
| 1413 | For the normal shared case we discard the PC relative relocs |
| 1414 | against symbols that have become local due to visibility changes. |
| 1415 | We allocated space for them in the check_relocs routine, but we |
| 1416 | will not fill them in in the relocate_section routine. */ |
| 1417 | if (info->shared) |
| 1418 | elf_link_hash_traverse (elf_hash_table (info), |
| 1419 | elf_m68k_discard_copies, |
| 1420 | (PTR) info); |
| 1421 | |
| 1422 | /* The check_relocs and adjust_dynamic_symbol entry points have |
| 1423 | determined the sizes of the various dynamic sections. Allocate |
| 1424 | memory for them. */ |
| 1425 | plt = FALSE; |
| 1426 | relocs = FALSE; |
| 1427 | for (s = dynobj->sections; s != NULL; s = s->next) |
| 1428 | { |
| 1429 | const char *name; |
| 1430 | |
| 1431 | if ((s->flags & SEC_LINKER_CREATED) == 0) |
| 1432 | continue; |
| 1433 | |
| 1434 | /* It's OK to base decisions on the section name, because none |
| 1435 | of the dynobj section names depend upon the input files. */ |
| 1436 | name = bfd_get_section_name (dynobj, s); |
| 1437 | |
| 1438 | if (strcmp (name, ".plt") == 0) |
| 1439 | { |
| 1440 | /* Remember whether there is a PLT. */ |
| 1441 | plt = s->size != 0; |
| 1442 | } |
| 1443 | else if (CONST_STRNEQ (name, ".rela")) |
| 1444 | { |
| 1445 | if (s->size != 0) |
| 1446 | { |
| 1447 | relocs = TRUE; |
| 1448 | |
| 1449 | /* We use the reloc_count field as a counter if we need |
| 1450 | to copy relocs into the output file. */ |
| 1451 | s->reloc_count = 0; |
| 1452 | } |
| 1453 | } |
| 1454 | else if (! CONST_STRNEQ (name, ".got") |
| 1455 | && strcmp (name, ".dynbss") != 0) |
| 1456 | { |
| 1457 | /* It's not one of our sections, so don't allocate space. */ |
| 1458 | continue; |
| 1459 | } |
| 1460 | |
| 1461 | if (s->size == 0) |
| 1462 | { |
| 1463 | /* If we don't need this section, strip it from the |
| 1464 | output file. This is mostly to handle .rela.bss and |
| 1465 | .rela.plt. We must create both sections in |
| 1466 | create_dynamic_sections, because they must be created |
| 1467 | before the linker maps input sections to output |
| 1468 | sections. The linker does that before |
| 1469 | adjust_dynamic_symbol is called, and it is that |
| 1470 | function which decides whether anything needs to go |
| 1471 | into these sections. */ |
| 1472 | s->flags |= SEC_EXCLUDE; |
| 1473 | continue; |
| 1474 | } |
| 1475 | |
| 1476 | if ((s->flags & SEC_HAS_CONTENTS) == 0) |
| 1477 | continue; |
| 1478 | |
| 1479 | /* Allocate memory for the section contents. */ |
| 1480 | /* FIXME: This should be a call to bfd_alloc not bfd_zalloc. |
| 1481 | Unused entries should be reclaimed before the section's contents |
| 1482 | are written out, but at the moment this does not happen. Thus in |
| 1483 | order to prevent writing out garbage, we initialise the section's |
| 1484 | contents to zero. */ |
| 1485 | s->contents = (bfd_byte *) bfd_zalloc (dynobj, s->size); |
| 1486 | if (s->contents == NULL) |
| 1487 | return FALSE; |
| 1488 | } |
| 1489 | |
| 1490 | if (elf_hash_table (info)->dynamic_sections_created) |
| 1491 | { |
| 1492 | /* Add some entries to the .dynamic section. We fill in the |
| 1493 | values later, in elf_m68k_finish_dynamic_sections, but we |
| 1494 | must add the entries now so that we get the correct size for |
| 1495 | the .dynamic section. The DT_DEBUG entry is filled in by the |
| 1496 | dynamic linker and used by the debugger. */ |
| 1497 | #define add_dynamic_entry(TAG, VAL) \ |
| 1498 | _bfd_elf_add_dynamic_entry (info, TAG, VAL) |
| 1499 | |
| 1500 | if (!info->shared) |
| 1501 | { |
| 1502 | if (!add_dynamic_entry (DT_DEBUG, 0)) |
| 1503 | return FALSE; |
| 1504 | } |
| 1505 | |
| 1506 | if (plt) |
| 1507 | { |
| 1508 | if (!add_dynamic_entry (DT_PLTGOT, 0) |
| 1509 | || !add_dynamic_entry (DT_PLTRELSZ, 0) |
| 1510 | || !add_dynamic_entry (DT_PLTREL, DT_RELA) |
| 1511 | || !add_dynamic_entry (DT_JMPREL, 0)) |
| 1512 | return FALSE; |
| 1513 | } |
| 1514 | |
| 1515 | if (relocs) |
| 1516 | { |
| 1517 | if (!add_dynamic_entry (DT_RELA, 0) |
| 1518 | || !add_dynamic_entry (DT_RELASZ, 0) |
| 1519 | || !add_dynamic_entry (DT_RELAENT, sizeof (Elf32_External_Rela))) |
| 1520 | return FALSE; |
| 1521 | } |
| 1522 | |
| 1523 | if ((info->flags & DF_TEXTREL) != 0) |
| 1524 | { |
| 1525 | if (!add_dynamic_entry (DT_TEXTREL, 0)) |
| 1526 | return FALSE; |
| 1527 | } |
| 1528 | } |
| 1529 | #undef add_dynamic_entry |
| 1530 | |
| 1531 | return TRUE; |
| 1532 | } |
| 1533 | |
| 1534 | /* This function is called via elf_link_hash_traverse if we are |
| 1535 | creating a shared object. In the -Bsymbolic case it discards the |
| 1536 | space allocated to copy PC relative relocs against symbols which |
| 1537 | are defined in regular objects. For the normal shared case, it |
| 1538 | discards space for pc-relative relocs that have become local due to |
| 1539 | symbol visibility changes. We allocated space for them in the |
| 1540 | check_relocs routine, but we won't fill them in in the |
| 1541 | relocate_section routine. |
| 1542 | |
| 1543 | We also check whether any of the remaining relocations apply |
| 1544 | against a readonly section, and set the DF_TEXTREL flag in this |
| 1545 | case. */ |
| 1546 | |
| 1547 | static bfd_boolean |
| 1548 | elf_m68k_discard_copies (h, inf) |
| 1549 | struct elf_link_hash_entry *h; |
| 1550 | PTR inf; |
| 1551 | { |
| 1552 | struct bfd_link_info *info = (struct bfd_link_info *) inf; |
| 1553 | struct elf_m68k_pcrel_relocs_copied *s; |
| 1554 | |
| 1555 | if (h->root.type == bfd_link_hash_warning) |
| 1556 | h = (struct elf_link_hash_entry *) h->root.u.i.link; |
| 1557 | |
| 1558 | if (!h->def_regular |
| 1559 | || (!info->symbolic |
| 1560 | && !h->forced_local)) |
| 1561 | { |
| 1562 | if ((info->flags & DF_TEXTREL) == 0) |
| 1563 | { |
| 1564 | /* Look for relocations against read-only sections. */ |
| 1565 | for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied; |
| 1566 | s != NULL; |
| 1567 | s = s->next) |
| 1568 | if ((s->section->flags & SEC_READONLY) != 0) |
| 1569 | { |
| 1570 | info->flags |= DF_TEXTREL; |
| 1571 | break; |
| 1572 | } |
| 1573 | } |
| 1574 | |
| 1575 | return TRUE; |
| 1576 | } |
| 1577 | |
| 1578 | for (s = elf_m68k_hash_entry (h)->pcrel_relocs_copied; |
| 1579 | s != NULL; |
| 1580 | s = s->next) |
| 1581 | s->section->size -= s->count * sizeof (Elf32_External_Rela); |
| 1582 | |
| 1583 | return TRUE; |
| 1584 | } |
| 1585 | |
| 1586 | /* Relocate an M68K ELF section. */ |
| 1587 | |
| 1588 | static bfd_boolean |
| 1589 | elf_m68k_relocate_section (output_bfd, info, input_bfd, input_section, |
| 1590 | contents, relocs, local_syms, local_sections) |
| 1591 | bfd *output_bfd; |
| 1592 | struct bfd_link_info *info; |
| 1593 | bfd *input_bfd; |
| 1594 | asection *input_section; |
| 1595 | bfd_byte *contents; |
| 1596 | Elf_Internal_Rela *relocs; |
| 1597 | Elf_Internal_Sym *local_syms; |
| 1598 | asection **local_sections; |
| 1599 | { |
| 1600 | bfd *dynobj; |
| 1601 | Elf_Internal_Shdr *symtab_hdr; |
| 1602 | struct elf_link_hash_entry **sym_hashes; |
| 1603 | bfd_vma *local_got_offsets; |
| 1604 | asection *sgot; |
| 1605 | asection *splt; |
| 1606 | asection *sreloc; |
| 1607 | Elf_Internal_Rela *rel; |
| 1608 | Elf_Internal_Rela *relend; |
| 1609 | |
| 1610 | dynobj = elf_hash_table (info)->dynobj; |
| 1611 | symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr; |
| 1612 | sym_hashes = elf_sym_hashes (input_bfd); |
| 1613 | local_got_offsets = elf_local_got_offsets (input_bfd); |
| 1614 | |
| 1615 | sgot = NULL; |
| 1616 | splt = NULL; |
| 1617 | sreloc = NULL; |
| 1618 | |
| 1619 | rel = relocs; |
| 1620 | relend = relocs + input_section->reloc_count; |
| 1621 | for (; rel < relend; rel++) |
| 1622 | { |
| 1623 | int r_type; |
| 1624 | reloc_howto_type *howto; |
| 1625 | unsigned long r_symndx; |
| 1626 | struct elf_link_hash_entry *h; |
| 1627 | Elf_Internal_Sym *sym; |
| 1628 | asection *sec; |
| 1629 | bfd_vma relocation; |
| 1630 | bfd_boolean unresolved_reloc; |
| 1631 | bfd_reloc_status_type r; |
| 1632 | |
| 1633 | r_type = ELF32_R_TYPE (rel->r_info); |
| 1634 | if (r_type < 0 || r_type >= (int) R_68K_max) |
| 1635 | { |
| 1636 | bfd_set_error (bfd_error_bad_value); |
| 1637 | return FALSE; |
| 1638 | } |
| 1639 | howto = howto_table + r_type; |
| 1640 | |
| 1641 | r_symndx = ELF32_R_SYM (rel->r_info); |
| 1642 | |
| 1643 | h = NULL; |
| 1644 | sym = NULL; |
| 1645 | sec = NULL; |
| 1646 | unresolved_reloc = FALSE; |
| 1647 | |
| 1648 | if (r_symndx < symtab_hdr->sh_info) |
| 1649 | { |
| 1650 | sym = local_syms + r_symndx; |
| 1651 | sec = local_sections[r_symndx]; |
| 1652 | relocation = _bfd_elf_rela_local_sym (output_bfd, sym, &sec, rel); |
| 1653 | } |
| 1654 | else |
| 1655 | { |
| 1656 | bfd_boolean warned; |
| 1657 | |
| 1658 | RELOC_FOR_GLOBAL_SYMBOL (info, input_bfd, input_section, rel, |
| 1659 | r_symndx, symtab_hdr, sym_hashes, |
| 1660 | h, sec, relocation, |
| 1661 | unresolved_reloc, warned); |
| 1662 | } |
| 1663 | |
| 1664 | if (sec != NULL && elf_discarded_section (sec)) |
| 1665 | { |
| 1666 | /* For relocs against symbols from removed linkonce sections, |
| 1667 | or sections discarded by a linker script, we just want the |
| 1668 | section contents zeroed. Avoid any special processing. */ |
| 1669 | _bfd_clear_contents (howto, input_bfd, contents + rel->r_offset); |
| 1670 | rel->r_info = 0; |
| 1671 | rel->r_addend = 0; |
| 1672 | continue; |
| 1673 | } |
| 1674 | |
| 1675 | if (info->relocatable) |
| 1676 | continue; |
| 1677 | |
| 1678 | switch (r_type) |
| 1679 | { |
| 1680 | case R_68K_GOT8: |
| 1681 | case R_68K_GOT16: |
| 1682 | case R_68K_GOT32: |
| 1683 | /* Relocation is to the address of the entry for this symbol |
| 1684 | in the global offset table. */ |
| 1685 | if (h != NULL |
| 1686 | && strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0) |
| 1687 | break; |
| 1688 | /* Fall through. */ |
| 1689 | case R_68K_GOT8O: |
| 1690 | case R_68K_GOT16O: |
| 1691 | case R_68K_GOT32O: |
| 1692 | /* Relocation is the offset of the entry for this symbol in |
| 1693 | the global offset table. */ |
| 1694 | |
| 1695 | { |
| 1696 | bfd_vma off; |
| 1697 | |
| 1698 | if (sgot == NULL) |
| 1699 | { |
| 1700 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 1701 | BFD_ASSERT (sgot != NULL); |
| 1702 | } |
| 1703 | |
| 1704 | if (h != NULL) |
| 1705 | { |
| 1706 | bfd_boolean dyn; |
| 1707 | |
| 1708 | off = h->got.offset; |
| 1709 | BFD_ASSERT (off != (bfd_vma) -1); |
| 1710 | |
| 1711 | dyn = elf_hash_table (info)->dynamic_sections_created; |
| 1712 | if (!WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) |
| 1713 | || (info->shared |
| 1714 | && (info->symbolic |
| 1715 | || h->dynindx == -1 |
| 1716 | || h->forced_local) |
| 1717 | && h->def_regular)) |
| 1718 | { |
| 1719 | /* This is actually a static link, or it is a |
| 1720 | -Bsymbolic link and the symbol is defined |
| 1721 | locally, or the symbol was forced to be local |
| 1722 | because of a version file.. We must initialize |
| 1723 | this entry in the global offset table. Since |
| 1724 | the offset must always be a multiple of 4, we |
| 1725 | use the least significant bit to record whether |
| 1726 | we have initialized it already. |
| 1727 | |
| 1728 | When doing a dynamic link, we create a .rela.got |
| 1729 | relocation entry to initialize the value. This |
| 1730 | is done in the finish_dynamic_symbol routine. */ |
| 1731 | if ((off & 1) != 0) |
| 1732 | off &= ~1; |
| 1733 | else |
| 1734 | { |
| 1735 | bfd_put_32 (output_bfd, relocation, |
| 1736 | sgot->contents + off); |
| 1737 | h->got.offset |= 1; |
| 1738 | } |
| 1739 | } |
| 1740 | else |
| 1741 | unresolved_reloc = FALSE; |
| 1742 | } |
| 1743 | else |
| 1744 | { |
| 1745 | BFD_ASSERT (local_got_offsets != NULL |
| 1746 | && local_got_offsets[r_symndx] != (bfd_vma) -1); |
| 1747 | |
| 1748 | off = local_got_offsets[r_symndx]; |
| 1749 | |
| 1750 | /* The offset must always be a multiple of 4. We use |
| 1751 | the least significant bit to record whether we have |
| 1752 | already generated the necessary reloc. */ |
| 1753 | if ((off & 1) != 0) |
| 1754 | off &= ~1; |
| 1755 | else |
| 1756 | { |
| 1757 | bfd_put_32 (output_bfd, relocation, sgot->contents + off); |
| 1758 | |
| 1759 | if (info->shared) |
| 1760 | { |
| 1761 | asection *s; |
| 1762 | Elf_Internal_Rela outrel; |
| 1763 | bfd_byte *loc; |
| 1764 | |
| 1765 | s = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 1766 | BFD_ASSERT (s != NULL); |
| 1767 | |
| 1768 | outrel.r_offset = (sgot->output_section->vma |
| 1769 | + sgot->output_offset |
| 1770 | + off); |
| 1771 | outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE); |
| 1772 | outrel.r_addend = relocation; |
| 1773 | loc = s->contents; |
| 1774 | loc += s->reloc_count++ * sizeof (Elf32_External_Rela); |
| 1775 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
| 1776 | } |
| 1777 | |
| 1778 | local_got_offsets[r_symndx] |= 1; |
| 1779 | } |
| 1780 | } |
| 1781 | |
| 1782 | relocation = sgot->output_offset + off; |
| 1783 | if (r_type == R_68K_GOT8O |
| 1784 | || r_type == R_68K_GOT16O |
| 1785 | || r_type == R_68K_GOT32O) |
| 1786 | { |
| 1787 | /* This relocation does not use the addend. */ |
| 1788 | rel->r_addend = 0; |
| 1789 | } |
| 1790 | else |
| 1791 | relocation += sgot->output_section->vma; |
| 1792 | } |
| 1793 | break; |
| 1794 | |
| 1795 | case R_68K_PLT8: |
| 1796 | case R_68K_PLT16: |
| 1797 | case R_68K_PLT32: |
| 1798 | /* Relocation is to the entry for this symbol in the |
| 1799 | procedure linkage table. */ |
| 1800 | |
| 1801 | /* Resolve a PLTxx reloc against a local symbol directly, |
| 1802 | without using the procedure linkage table. */ |
| 1803 | if (h == NULL) |
| 1804 | break; |
| 1805 | |
| 1806 | if (h->plt.offset == (bfd_vma) -1 |
| 1807 | || !elf_hash_table (info)->dynamic_sections_created) |
| 1808 | { |
| 1809 | /* We didn't make a PLT entry for this symbol. This |
| 1810 | happens when statically linking PIC code, or when |
| 1811 | using -Bsymbolic. */ |
| 1812 | break; |
| 1813 | } |
| 1814 | |
| 1815 | if (splt == NULL) |
| 1816 | { |
| 1817 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 1818 | BFD_ASSERT (splt != NULL); |
| 1819 | } |
| 1820 | |
| 1821 | relocation = (splt->output_section->vma |
| 1822 | + splt->output_offset |
| 1823 | + h->plt.offset); |
| 1824 | unresolved_reloc = FALSE; |
| 1825 | break; |
| 1826 | |
| 1827 | case R_68K_PLT8O: |
| 1828 | case R_68K_PLT16O: |
| 1829 | case R_68K_PLT32O: |
| 1830 | /* Relocation is the offset of the entry for this symbol in |
| 1831 | the procedure linkage table. */ |
| 1832 | BFD_ASSERT (h != NULL && h->plt.offset != (bfd_vma) -1); |
| 1833 | |
| 1834 | if (splt == NULL) |
| 1835 | { |
| 1836 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 1837 | BFD_ASSERT (splt != NULL); |
| 1838 | } |
| 1839 | |
| 1840 | relocation = h->plt.offset; |
| 1841 | unresolved_reloc = FALSE; |
| 1842 | |
| 1843 | /* This relocation does not use the addend. */ |
| 1844 | rel->r_addend = 0; |
| 1845 | |
| 1846 | break; |
| 1847 | |
| 1848 | case R_68K_PC8: |
| 1849 | case R_68K_PC16: |
| 1850 | case R_68K_PC32: |
| 1851 | if (h == NULL |
| 1852 | || (info->shared |
| 1853 | && h->forced_local)) |
| 1854 | break; |
| 1855 | /* Fall through. */ |
| 1856 | case R_68K_8: |
| 1857 | case R_68K_16: |
| 1858 | case R_68K_32: |
| 1859 | if (info->shared |
| 1860 | && r_symndx != 0 |
| 1861 | && (input_section->flags & SEC_ALLOC) != 0 |
| 1862 | && (h == NULL |
| 1863 | || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT |
| 1864 | || h->root.type != bfd_link_hash_undefweak) |
| 1865 | && ((r_type != R_68K_PC8 |
| 1866 | && r_type != R_68K_PC16 |
| 1867 | && r_type != R_68K_PC32) |
| 1868 | || (h != NULL |
| 1869 | && h->dynindx != -1 |
| 1870 | && (!info->symbolic |
| 1871 | || !h->def_regular)))) |
| 1872 | { |
| 1873 | Elf_Internal_Rela outrel; |
| 1874 | bfd_byte *loc; |
| 1875 | bfd_boolean skip, relocate; |
| 1876 | |
| 1877 | /* When generating a shared object, these relocations |
| 1878 | are copied into the output file to be resolved at run |
| 1879 | time. */ |
| 1880 | |
| 1881 | skip = FALSE; |
| 1882 | relocate = FALSE; |
| 1883 | |
| 1884 | outrel.r_offset = |
| 1885 | _bfd_elf_section_offset (output_bfd, info, input_section, |
| 1886 | rel->r_offset); |
| 1887 | if (outrel.r_offset == (bfd_vma) -1) |
| 1888 | skip = TRUE; |
| 1889 | else if (outrel.r_offset == (bfd_vma) -2) |
| 1890 | skip = TRUE, relocate = TRUE; |
| 1891 | outrel.r_offset += (input_section->output_section->vma |
| 1892 | + input_section->output_offset); |
| 1893 | |
| 1894 | if (skip) |
| 1895 | memset (&outrel, 0, sizeof outrel); |
| 1896 | else if (h != NULL |
| 1897 | && h->dynindx != -1 |
| 1898 | && (r_type == R_68K_PC8 |
| 1899 | || r_type == R_68K_PC16 |
| 1900 | || r_type == R_68K_PC32 |
| 1901 | || !info->shared |
| 1902 | || !info->symbolic |
| 1903 | || !h->def_regular)) |
| 1904 | { |
| 1905 | outrel.r_info = ELF32_R_INFO (h->dynindx, r_type); |
| 1906 | outrel.r_addend = rel->r_addend; |
| 1907 | } |
| 1908 | else |
| 1909 | { |
| 1910 | /* This symbol is local, or marked to become local. */ |
| 1911 | outrel.r_addend = relocation + rel->r_addend; |
| 1912 | |
| 1913 | if (r_type == R_68K_32) |
| 1914 | { |
| 1915 | relocate = TRUE; |
| 1916 | outrel.r_info = ELF32_R_INFO (0, R_68K_RELATIVE); |
| 1917 | } |
| 1918 | else |
| 1919 | { |
| 1920 | long indx; |
| 1921 | |
| 1922 | if (bfd_is_abs_section (sec)) |
| 1923 | indx = 0; |
| 1924 | else if (sec == NULL || sec->owner == NULL) |
| 1925 | { |
| 1926 | bfd_set_error (bfd_error_bad_value); |
| 1927 | return FALSE; |
| 1928 | } |
| 1929 | else |
| 1930 | { |
| 1931 | asection *osec; |
| 1932 | |
| 1933 | /* We are turning this relocation into one |
| 1934 | against a section symbol. It would be |
| 1935 | proper to subtract the symbol's value, |
| 1936 | osec->vma, from the emitted reloc addend, |
| 1937 | but ld.so expects buggy relocs. */ |
| 1938 | osec = sec->output_section; |
| 1939 | indx = elf_section_data (osec)->dynindx; |
| 1940 | if (indx == 0) |
| 1941 | { |
| 1942 | struct elf_link_hash_table *htab; |
| 1943 | htab = elf_hash_table (info); |
| 1944 | osec = htab->text_index_section; |
| 1945 | indx = elf_section_data (osec)->dynindx; |
| 1946 | } |
| 1947 | BFD_ASSERT (indx != 0); |
| 1948 | } |
| 1949 | |
| 1950 | outrel.r_info = ELF32_R_INFO (indx, r_type); |
| 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | sreloc = elf_section_data (input_section)->sreloc; |
| 1955 | if (sreloc == NULL) |
| 1956 | abort (); |
| 1957 | |
| 1958 | loc = sreloc->contents; |
| 1959 | loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rela); |
| 1960 | bfd_elf32_swap_reloca_out (output_bfd, &outrel, loc); |
| 1961 | |
| 1962 | /* This reloc will be computed at runtime, so there's no |
| 1963 | need to do anything now, except for R_68K_32 |
| 1964 | relocations that have been turned into |
| 1965 | R_68K_RELATIVE. */ |
| 1966 | if (!relocate) |
| 1967 | continue; |
| 1968 | } |
| 1969 | |
| 1970 | break; |
| 1971 | |
| 1972 | case R_68K_GNU_VTINHERIT: |
| 1973 | case R_68K_GNU_VTENTRY: |
| 1974 | /* These are no-ops in the end. */ |
| 1975 | continue; |
| 1976 | |
| 1977 | default: |
| 1978 | break; |
| 1979 | } |
| 1980 | |
| 1981 | /* Dynamic relocs are not propagated for SEC_DEBUGGING sections |
| 1982 | because such sections are not SEC_ALLOC and thus ld.so will |
| 1983 | not process them. */ |
| 1984 | if (unresolved_reloc |
| 1985 | && !((input_section->flags & SEC_DEBUGGING) != 0 |
| 1986 | && h->def_dynamic)) |
| 1987 | { |
| 1988 | (*_bfd_error_handler) |
| 1989 | (_("%B(%A+0x%lx): unresolvable %s relocation against symbol `%s'"), |
| 1990 | input_bfd, |
| 1991 | input_section, |
| 1992 | (long) rel->r_offset, |
| 1993 | howto->name, |
| 1994 | h->root.root.string); |
| 1995 | return FALSE; |
| 1996 | } |
| 1997 | |
| 1998 | r = _bfd_final_link_relocate (howto, input_bfd, input_section, |
| 1999 | contents, rel->r_offset, |
| 2000 | relocation, rel->r_addend); |
| 2001 | |
| 2002 | if (r != bfd_reloc_ok) |
| 2003 | { |
| 2004 | const char *name; |
| 2005 | |
| 2006 | if (h != NULL) |
| 2007 | name = h->root.root.string; |
| 2008 | else |
| 2009 | { |
| 2010 | name = bfd_elf_string_from_elf_section (input_bfd, |
| 2011 | symtab_hdr->sh_link, |
| 2012 | sym->st_name); |
| 2013 | if (name == NULL) |
| 2014 | return FALSE; |
| 2015 | if (*name == '\0') |
| 2016 | name = bfd_section_name (input_bfd, sec); |
| 2017 | } |
| 2018 | |
| 2019 | if (r == bfd_reloc_overflow) |
| 2020 | { |
| 2021 | if (!(info->callbacks->reloc_overflow |
| 2022 | (info, (h ? &h->root : NULL), name, howto->name, |
| 2023 | (bfd_vma) 0, input_bfd, input_section, |
| 2024 | rel->r_offset))) |
| 2025 | return FALSE; |
| 2026 | } |
| 2027 | else |
| 2028 | { |
| 2029 | (*_bfd_error_handler) |
| 2030 | (_("%B(%A+0x%lx): reloc against `%s': error %d"), |
| 2031 | input_bfd, input_section, |
| 2032 | (long) rel->r_offset, name, (int) r); |
| 2033 | return FALSE; |
| 2034 | } |
| 2035 | } |
| 2036 | } |
| 2037 | |
| 2038 | return TRUE; |
| 2039 | } |
| 2040 | |
| 2041 | /* Install an M_68K_PC32 relocation against VALUE at offset OFFSET |
| 2042 | into section SEC. */ |
| 2043 | |
| 2044 | static void |
| 2045 | elf_m68k_install_pc32 (asection *sec, bfd_vma offset, bfd_vma value) |
| 2046 | { |
| 2047 | /* Make VALUE PC-relative. */ |
| 2048 | value -= sec->output_section->vma + offset; |
| 2049 | |
| 2050 | /* Apply any in-place addend. */ |
| 2051 | value += bfd_get_32 (sec->owner, sec->contents + offset); |
| 2052 | |
| 2053 | bfd_put_32 (sec->owner, value, sec->contents + offset); |
| 2054 | } |
| 2055 | |
| 2056 | /* Finish up dynamic symbol handling. We set the contents of various |
| 2057 | dynamic sections here. */ |
| 2058 | |
| 2059 | static bfd_boolean |
| 2060 | elf_m68k_finish_dynamic_symbol (output_bfd, info, h, sym) |
| 2061 | bfd *output_bfd; |
| 2062 | struct bfd_link_info *info; |
| 2063 | struct elf_link_hash_entry *h; |
| 2064 | Elf_Internal_Sym *sym; |
| 2065 | { |
| 2066 | bfd *dynobj; |
| 2067 | |
| 2068 | dynobj = elf_hash_table (info)->dynobj; |
| 2069 | |
| 2070 | if (h->plt.offset != (bfd_vma) -1) |
| 2071 | { |
| 2072 | const struct elf_m68k_plt_info *plt_info; |
| 2073 | asection *splt; |
| 2074 | asection *sgot; |
| 2075 | asection *srela; |
| 2076 | bfd_vma plt_index; |
| 2077 | bfd_vma got_offset; |
| 2078 | Elf_Internal_Rela rela; |
| 2079 | bfd_byte *loc; |
| 2080 | |
| 2081 | /* This symbol has an entry in the procedure linkage table. Set |
| 2082 | it up. */ |
| 2083 | |
| 2084 | BFD_ASSERT (h->dynindx != -1); |
| 2085 | |
| 2086 | plt_info = elf_m68k_hash_table (info)->plt_info; |
| 2087 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 2088 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); |
| 2089 | srela = bfd_get_section_by_name (dynobj, ".rela.plt"); |
| 2090 | BFD_ASSERT (splt != NULL && sgot != NULL && srela != NULL); |
| 2091 | |
| 2092 | /* Get the index in the procedure linkage table which |
| 2093 | corresponds to this symbol. This is the index of this symbol |
| 2094 | in all the symbols for which we are making plt entries. The |
| 2095 | first entry in the procedure linkage table is reserved. */ |
| 2096 | plt_index = (h->plt.offset / plt_info->size) - 1; |
| 2097 | |
| 2098 | /* Get the offset into the .got table of the entry that |
| 2099 | corresponds to this function. Each .got entry is 4 bytes. |
| 2100 | The first three are reserved. */ |
| 2101 | got_offset = (plt_index + 3) * 4; |
| 2102 | |
| 2103 | memcpy (splt->contents + h->plt.offset, |
| 2104 | plt_info->symbol_entry, |
| 2105 | plt_info->size); |
| 2106 | |
| 2107 | elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.got, |
| 2108 | (sgot->output_section->vma |
| 2109 | + sgot->output_offset |
| 2110 | + got_offset)); |
| 2111 | |
| 2112 | bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rela), |
| 2113 | splt->contents |
| 2114 | + h->plt.offset |
| 2115 | + plt_info->symbol_resolve_entry + 2); |
| 2116 | |
| 2117 | elf_m68k_install_pc32 (splt, h->plt.offset + plt_info->symbol_relocs.plt, |
| 2118 | splt->output_section->vma); |
| 2119 | |
| 2120 | /* Fill in the entry in the global offset table. */ |
| 2121 | bfd_put_32 (output_bfd, |
| 2122 | (splt->output_section->vma |
| 2123 | + splt->output_offset |
| 2124 | + h->plt.offset |
| 2125 | + plt_info->symbol_resolve_entry), |
| 2126 | sgot->contents + got_offset); |
| 2127 | |
| 2128 | /* Fill in the entry in the .rela.plt section. */ |
| 2129 | rela.r_offset = (sgot->output_section->vma |
| 2130 | + sgot->output_offset |
| 2131 | + got_offset); |
| 2132 | rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_JMP_SLOT); |
| 2133 | rela.r_addend = 0; |
| 2134 | loc = srela->contents + plt_index * sizeof (Elf32_External_Rela); |
| 2135 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
| 2136 | |
| 2137 | if (!h->def_regular) |
| 2138 | { |
| 2139 | /* Mark the symbol as undefined, rather than as defined in |
| 2140 | the .plt section. Leave the value alone. */ |
| 2141 | sym->st_shndx = SHN_UNDEF; |
| 2142 | } |
| 2143 | } |
| 2144 | |
| 2145 | if (h->got.offset != (bfd_vma) -1) |
| 2146 | { |
| 2147 | asection *sgot; |
| 2148 | asection *srela; |
| 2149 | Elf_Internal_Rela rela; |
| 2150 | bfd_byte *loc; |
| 2151 | |
| 2152 | /* This symbol has an entry in the global offset table. Set it |
| 2153 | up. */ |
| 2154 | |
| 2155 | sgot = bfd_get_section_by_name (dynobj, ".got"); |
| 2156 | srela = bfd_get_section_by_name (dynobj, ".rela.got"); |
| 2157 | BFD_ASSERT (sgot != NULL && srela != NULL); |
| 2158 | |
| 2159 | rela.r_offset = (sgot->output_section->vma |
| 2160 | + sgot->output_offset |
| 2161 | + (h->got.offset &~ (bfd_vma) 1)); |
| 2162 | |
| 2163 | /* If this is a -Bsymbolic link, and the symbol is defined |
| 2164 | locally, we just want to emit a RELATIVE reloc. Likewise if |
| 2165 | the symbol was forced to be local because of a version file. |
| 2166 | The entry in the global offset table will already have been |
| 2167 | initialized in the relocate_section function. */ |
| 2168 | if (info->shared |
| 2169 | && (info->symbolic |
| 2170 | || h->dynindx == -1 |
| 2171 | || h->forced_local) |
| 2172 | && h->def_regular) |
| 2173 | { |
| 2174 | rela.r_info = ELF32_R_INFO (0, R_68K_RELATIVE); |
| 2175 | rela.r_addend = bfd_get_signed_32 (output_bfd, |
| 2176 | (sgot->contents |
| 2177 | + (h->got.offset &~ (bfd_vma) 1))); |
| 2178 | } |
| 2179 | else |
| 2180 | { |
| 2181 | bfd_put_32 (output_bfd, (bfd_vma) 0, |
| 2182 | sgot->contents + (h->got.offset &~ (bfd_vma) 1)); |
| 2183 | rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_GLOB_DAT); |
| 2184 | rela.r_addend = 0; |
| 2185 | } |
| 2186 | |
| 2187 | loc = srela->contents; |
| 2188 | loc += srela->reloc_count++ * sizeof (Elf32_External_Rela); |
| 2189 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
| 2190 | } |
| 2191 | |
| 2192 | if (h->needs_copy) |
| 2193 | { |
| 2194 | asection *s; |
| 2195 | Elf_Internal_Rela rela; |
| 2196 | bfd_byte *loc; |
| 2197 | |
| 2198 | /* This symbol needs a copy reloc. Set it up. */ |
| 2199 | |
| 2200 | BFD_ASSERT (h->dynindx != -1 |
| 2201 | && (h->root.type == bfd_link_hash_defined |
| 2202 | || h->root.type == bfd_link_hash_defweak)); |
| 2203 | |
| 2204 | s = bfd_get_section_by_name (h->root.u.def.section->owner, |
| 2205 | ".rela.bss"); |
| 2206 | BFD_ASSERT (s != NULL); |
| 2207 | |
| 2208 | rela.r_offset = (h->root.u.def.value |
| 2209 | + h->root.u.def.section->output_section->vma |
| 2210 | + h->root.u.def.section->output_offset); |
| 2211 | rela.r_info = ELF32_R_INFO (h->dynindx, R_68K_COPY); |
| 2212 | rela.r_addend = 0; |
| 2213 | loc = s->contents + s->reloc_count++ * sizeof (Elf32_External_Rela); |
| 2214 | bfd_elf32_swap_reloca_out (output_bfd, &rela, loc); |
| 2215 | } |
| 2216 | |
| 2217 | /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */ |
| 2218 | if (strcmp (h->root.root.string, "_DYNAMIC") == 0 |
| 2219 | || h == elf_hash_table (info)->hgot) |
| 2220 | sym->st_shndx = SHN_ABS; |
| 2221 | |
| 2222 | return TRUE; |
| 2223 | } |
| 2224 | |
| 2225 | /* Finish up the dynamic sections. */ |
| 2226 | |
| 2227 | static bfd_boolean |
| 2228 | elf_m68k_finish_dynamic_sections (output_bfd, info) |
| 2229 | bfd *output_bfd; |
| 2230 | struct bfd_link_info *info; |
| 2231 | { |
| 2232 | bfd *dynobj; |
| 2233 | asection *sgot; |
| 2234 | asection *sdyn; |
| 2235 | |
| 2236 | dynobj = elf_hash_table (info)->dynobj; |
| 2237 | |
| 2238 | sgot = bfd_get_section_by_name (dynobj, ".got.plt"); |
| 2239 | BFD_ASSERT (sgot != NULL); |
| 2240 | sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); |
| 2241 | |
| 2242 | if (elf_hash_table (info)->dynamic_sections_created) |
| 2243 | { |
| 2244 | asection *splt; |
| 2245 | Elf32_External_Dyn *dyncon, *dynconend; |
| 2246 | |
| 2247 | splt = bfd_get_section_by_name (dynobj, ".plt"); |
| 2248 | BFD_ASSERT (splt != NULL && sdyn != NULL); |
| 2249 | |
| 2250 | dyncon = (Elf32_External_Dyn *) sdyn->contents; |
| 2251 | dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->size); |
| 2252 | for (; dyncon < dynconend; dyncon++) |
| 2253 | { |
| 2254 | Elf_Internal_Dyn dyn; |
| 2255 | const char *name; |
| 2256 | asection *s; |
| 2257 | |
| 2258 | bfd_elf32_swap_dyn_in (dynobj, dyncon, &dyn); |
| 2259 | |
| 2260 | switch (dyn.d_tag) |
| 2261 | { |
| 2262 | default: |
| 2263 | break; |
| 2264 | |
| 2265 | case DT_PLTGOT: |
| 2266 | name = ".got"; |
| 2267 | goto get_vma; |
| 2268 | case DT_JMPREL: |
| 2269 | name = ".rela.plt"; |
| 2270 | get_vma: |
| 2271 | s = bfd_get_section_by_name (output_bfd, name); |
| 2272 | BFD_ASSERT (s != NULL); |
| 2273 | dyn.d_un.d_ptr = s->vma; |
| 2274 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 2275 | break; |
| 2276 | |
| 2277 | case DT_PLTRELSZ: |
| 2278 | s = bfd_get_section_by_name (output_bfd, ".rela.plt"); |
| 2279 | BFD_ASSERT (s != NULL); |
| 2280 | dyn.d_un.d_val = s->size; |
| 2281 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 2282 | break; |
| 2283 | |
| 2284 | case DT_RELASZ: |
| 2285 | /* The procedure linkage table relocs (DT_JMPREL) should |
| 2286 | not be included in the overall relocs (DT_RELA). |
| 2287 | Therefore, we override the DT_RELASZ entry here to |
| 2288 | make it not include the JMPREL relocs. Since the |
| 2289 | linker script arranges for .rela.plt to follow all |
| 2290 | other relocation sections, we don't have to worry |
| 2291 | about changing the DT_RELA entry. */ |
| 2292 | s = bfd_get_section_by_name (output_bfd, ".rela.plt"); |
| 2293 | if (s != NULL) |
| 2294 | dyn.d_un.d_val -= s->size; |
| 2295 | bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon); |
| 2296 | break; |
| 2297 | } |
| 2298 | } |
| 2299 | |
| 2300 | /* Fill in the first entry in the procedure linkage table. */ |
| 2301 | if (splt->size > 0) |
| 2302 | { |
| 2303 | const struct elf_m68k_plt_info *plt_info; |
| 2304 | |
| 2305 | plt_info = elf_m68k_hash_table (info)->plt_info; |
| 2306 | memcpy (splt->contents, plt_info->plt0_entry, plt_info->size); |
| 2307 | |
| 2308 | elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got4, |
| 2309 | (sgot->output_section->vma |
| 2310 | + sgot->output_offset |
| 2311 | + 4)); |
| 2312 | |
| 2313 | elf_m68k_install_pc32 (splt, plt_info->plt0_relocs.got8, |
| 2314 | (sgot->output_section->vma |
| 2315 | + sgot->output_offset |
| 2316 | + 8)); |
| 2317 | |
| 2318 | elf_section_data (splt->output_section)->this_hdr.sh_entsize |
| 2319 | = plt_info->size; |
| 2320 | } |
| 2321 | } |
| 2322 | |
| 2323 | /* Fill in the first three entries in the global offset table. */ |
| 2324 | if (sgot->size > 0) |
| 2325 | { |
| 2326 | if (sdyn == NULL) |
| 2327 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents); |
| 2328 | else |
| 2329 | bfd_put_32 (output_bfd, |
| 2330 | sdyn->output_section->vma + sdyn->output_offset, |
| 2331 | sgot->contents); |
| 2332 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4); |
| 2333 | bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8); |
| 2334 | } |
| 2335 | |
| 2336 | elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4; |
| 2337 | |
| 2338 | return TRUE; |
| 2339 | } |
| 2340 | |
| 2341 | /* Given a .data section and a .emreloc in-memory section, store |
| 2342 | relocation information into the .emreloc section which can be |
| 2343 | used at runtime to relocate the section. This is called by the |
| 2344 | linker when the --embedded-relocs switch is used. This is called |
| 2345 | after the add_symbols entry point has been called for all the |
| 2346 | objects, and before the final_link entry point is called. */ |
| 2347 | |
| 2348 | bfd_boolean |
| 2349 | bfd_m68k_elf32_create_embedded_relocs (abfd, info, datasec, relsec, errmsg) |
| 2350 | bfd *abfd; |
| 2351 | struct bfd_link_info *info; |
| 2352 | asection *datasec; |
| 2353 | asection *relsec; |
| 2354 | char **errmsg; |
| 2355 | { |
| 2356 | Elf_Internal_Shdr *symtab_hdr; |
| 2357 | Elf_Internal_Sym *isymbuf = NULL; |
| 2358 | Elf_Internal_Rela *internal_relocs = NULL; |
| 2359 | Elf_Internal_Rela *irel, *irelend; |
| 2360 | bfd_byte *p; |
| 2361 | bfd_size_type amt; |
| 2362 | |
| 2363 | BFD_ASSERT (! info->relocatable); |
| 2364 | |
| 2365 | *errmsg = NULL; |
| 2366 | |
| 2367 | if (datasec->reloc_count == 0) |
| 2368 | return TRUE; |
| 2369 | |
| 2370 | symtab_hdr = &elf_tdata (abfd)->symtab_hdr; |
| 2371 | |
| 2372 | /* Get a copy of the native relocations. */ |
| 2373 | internal_relocs = (_bfd_elf_link_read_relocs |
| 2374 | (abfd, datasec, (PTR) NULL, (Elf_Internal_Rela *) NULL, |
| 2375 | info->keep_memory)); |
| 2376 | if (internal_relocs == NULL) |
| 2377 | goto error_return; |
| 2378 | |
| 2379 | amt = (bfd_size_type) datasec->reloc_count * 12; |
| 2380 | relsec->contents = (bfd_byte *) bfd_alloc (abfd, amt); |
| 2381 | if (relsec->contents == NULL) |
| 2382 | goto error_return; |
| 2383 | |
| 2384 | p = relsec->contents; |
| 2385 | |
| 2386 | irelend = internal_relocs + datasec->reloc_count; |
| 2387 | for (irel = internal_relocs; irel < irelend; irel++, p += 12) |
| 2388 | { |
| 2389 | asection *targetsec; |
| 2390 | |
| 2391 | /* We are going to write a four byte longword into the runtime |
| 2392 | reloc section. The longword will be the address in the data |
| 2393 | section which must be relocated. It is followed by the name |
| 2394 | of the target section NUL-padded or truncated to 8 |
| 2395 | characters. */ |
| 2396 | |
| 2397 | /* We can only relocate absolute longword relocs at run time. */ |
| 2398 | if (ELF32_R_TYPE (irel->r_info) != (int) R_68K_32) |
| 2399 | { |
| 2400 | *errmsg = _("unsupported reloc type"); |
| 2401 | bfd_set_error (bfd_error_bad_value); |
| 2402 | goto error_return; |
| 2403 | } |
| 2404 | |
| 2405 | /* Get the target section referred to by the reloc. */ |
| 2406 | if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info) |
| 2407 | { |
| 2408 | /* A local symbol. */ |
| 2409 | Elf_Internal_Sym *isym; |
| 2410 | |
| 2411 | /* Read this BFD's local symbols if we haven't done so already. */ |
| 2412 | if (isymbuf == NULL) |
| 2413 | { |
| 2414 | isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents; |
| 2415 | if (isymbuf == NULL) |
| 2416 | isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr, |
| 2417 | symtab_hdr->sh_info, 0, |
| 2418 | NULL, NULL, NULL); |
| 2419 | if (isymbuf == NULL) |
| 2420 | goto error_return; |
| 2421 | } |
| 2422 | |
| 2423 | isym = isymbuf + ELF32_R_SYM (irel->r_info); |
| 2424 | targetsec = bfd_section_from_elf_index (abfd, isym->st_shndx); |
| 2425 | } |
| 2426 | else |
| 2427 | { |
| 2428 | unsigned long indx; |
| 2429 | struct elf_link_hash_entry *h; |
| 2430 | |
| 2431 | /* An external symbol. */ |
| 2432 | indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info; |
| 2433 | h = elf_sym_hashes (abfd)[indx]; |
| 2434 | BFD_ASSERT (h != NULL); |
| 2435 | if (h->root.type == bfd_link_hash_defined |
| 2436 | || h->root.type == bfd_link_hash_defweak) |
| 2437 | targetsec = h->root.u.def.section; |
| 2438 | else |
| 2439 | targetsec = NULL; |
| 2440 | } |
| 2441 | |
| 2442 | bfd_put_32 (abfd, irel->r_offset + datasec->output_offset, p); |
| 2443 | memset (p + 4, 0, 8); |
| 2444 | if (targetsec != NULL) |
| 2445 | strncpy ((char *) p + 4, targetsec->output_section->name, 8); |
| 2446 | } |
| 2447 | |
| 2448 | if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) |
| 2449 | free (isymbuf); |
| 2450 | if (internal_relocs != NULL |
| 2451 | && elf_section_data (datasec)->relocs != internal_relocs) |
| 2452 | free (internal_relocs); |
| 2453 | return TRUE; |
| 2454 | |
| 2455 | error_return: |
| 2456 | if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf) |
| 2457 | free (isymbuf); |
| 2458 | if (internal_relocs != NULL |
| 2459 | && elf_section_data (datasec)->relocs != internal_relocs) |
| 2460 | free (internal_relocs); |
| 2461 | return FALSE; |
| 2462 | } |
| 2463 | |
| 2464 | static enum elf_reloc_type_class |
| 2465 | elf32_m68k_reloc_type_class (rela) |
| 2466 | const Elf_Internal_Rela *rela; |
| 2467 | { |
| 2468 | switch ((int) ELF32_R_TYPE (rela->r_info)) |
| 2469 | { |
| 2470 | case R_68K_RELATIVE: |
| 2471 | return reloc_class_relative; |
| 2472 | case R_68K_JMP_SLOT: |
| 2473 | return reloc_class_plt; |
| 2474 | case R_68K_COPY: |
| 2475 | return reloc_class_copy; |
| 2476 | default: |
| 2477 | return reloc_class_normal; |
| 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | /* Return address for Ith PLT stub in section PLT, for relocation REL |
| 2482 | or (bfd_vma) -1 if it should not be included. */ |
| 2483 | |
| 2484 | static bfd_vma |
| 2485 | elf_m68k_plt_sym_val (bfd_vma i, const asection *plt, |
| 2486 | const arelent *rel ATTRIBUTE_UNUSED) |
| 2487 | { |
| 2488 | return plt->vma + (i + 1) * elf_m68k_get_plt_info (plt->owner)->size; |
| 2489 | } |
| 2490 | |
| 2491 | #define TARGET_BIG_SYM bfd_elf32_m68k_vec |
| 2492 | #define TARGET_BIG_NAME "elf32-m68k" |
| 2493 | #define ELF_MACHINE_CODE EM_68K |
| 2494 | #define ELF_MAXPAGESIZE 0x2000 |
| 2495 | #define elf_backend_create_dynamic_sections \ |
| 2496 | _bfd_elf_create_dynamic_sections |
| 2497 | #define bfd_elf32_bfd_link_hash_table_create \ |
| 2498 | elf_m68k_link_hash_table_create |
| 2499 | #define bfd_elf32_bfd_final_link bfd_elf_gc_common_final_link |
| 2500 | |
| 2501 | #define elf_backend_check_relocs elf_m68k_check_relocs |
| 2502 | #define elf_backend_always_size_sections \ |
| 2503 | elf_m68k_always_size_sections |
| 2504 | #define elf_backend_adjust_dynamic_symbol \ |
| 2505 | elf_m68k_adjust_dynamic_symbol |
| 2506 | #define elf_backend_size_dynamic_sections \ |
| 2507 | elf_m68k_size_dynamic_sections |
| 2508 | #define elf_backend_init_index_section _bfd_elf_init_1_index_section |
| 2509 | #define elf_backend_relocate_section elf_m68k_relocate_section |
| 2510 | #define elf_backend_finish_dynamic_symbol \ |
| 2511 | elf_m68k_finish_dynamic_symbol |
| 2512 | #define elf_backend_finish_dynamic_sections \ |
| 2513 | elf_m68k_finish_dynamic_sections |
| 2514 | #define elf_backend_gc_mark_hook elf_m68k_gc_mark_hook |
| 2515 | #define elf_backend_gc_sweep_hook elf_m68k_gc_sweep_hook |
| 2516 | #define bfd_elf32_bfd_merge_private_bfd_data \ |
| 2517 | elf32_m68k_merge_private_bfd_data |
| 2518 | #define bfd_elf32_bfd_set_private_flags \ |
| 2519 | elf32_m68k_set_private_flags |
| 2520 | #define bfd_elf32_bfd_print_private_bfd_data \ |
| 2521 | elf32_m68k_print_private_bfd_data |
| 2522 | #define elf_backend_reloc_type_class elf32_m68k_reloc_type_class |
| 2523 | #define elf_backend_plt_sym_val elf_m68k_plt_sym_val |
| 2524 | #define elf_backend_object_p elf32_m68k_object_p |
| 2525 | |
| 2526 | #define elf_backend_can_gc_sections 1 |
| 2527 | #define elf_backend_can_refcount 1 |
| 2528 | #define elf_backend_want_got_plt 1 |
| 2529 | #define elf_backend_plt_readonly 1 |
| 2530 | #define elf_backend_want_plt_sym 0 |
| 2531 | #define elf_backend_got_header_size 12 |
| 2532 | #define elf_backend_rela_normal 1 |
| 2533 | |
| 2534 | #include "elf32-target.h" |