1 /* Motorola 68k series support for 32-bit ELF
2 Copyright 1993, 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
4 This file is part of BFD, the Binary File Descriptor library.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
26 static reloc_howto_type
*reloc_type_lookup
27 PARAMS ((bfd
*, bfd_reloc_code_real_type
));
28 static void rtype_to_howto
29 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rela
*));
30 static void rtype_to_howto_rel
31 PARAMS ((bfd
*, arelent
*, Elf32_Internal_Rel
*));
32 static struct bfd_hash_entry
*elf_m68k_link_hash_newfunc
33 PARAMS ((struct bfd_hash_entry
*, struct bfd_hash_table
*, const char *));
34 static struct bfd_link_hash_table
*elf_m68k_link_hash_table_create
36 static boolean elf_m68k_check_relocs
37 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
38 const Elf_Internal_Rela
*));
39 static boolean elf_m68k_adjust_dynamic_symbol
40 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
41 static boolean elf_m68k_adjust_dynindx
42 PARAMS ((struct elf_link_hash_entry
*, PTR
));
43 static boolean elf_m68k_size_dynamic_sections
44 PARAMS ((bfd
*, struct bfd_link_info
*));
45 static boolean elf_m68k_relocate_section
46 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
47 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
48 static boolean elf_m68k_finish_dynamic_symbol
49 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
51 static boolean elf_m68k_finish_dynamic_sections
52 PARAMS ((bfd
*, struct bfd_link_info
*));
54 /* elf32 m68k code, generated by elf.el */
82 static reloc_howto_type howto_table
[] = {
83 HOWTO(R_68K_NONE
, 0, 0, 0, false,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_NONE", false, 0, 0x00000000,false),
84 HOWTO(R_68K_32
, 0, 2,32, false,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_32", false, 0, 0xffffffff,false),
85 HOWTO(R_68K_16
, 0, 1,16, false,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_16", false, 0, 0x0000ffff,false),
86 HOWTO(R_68K_8
, 0, 0, 8, false,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_8", false, 0, 0x000000ff,false),
87 HOWTO(R_68K_PC32
, 0, 2,32, true, 0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_PC32", false, 0, 0xffffffff,true),
88 HOWTO(R_68K_PC16
, 0, 1,16, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC16", false, 0, 0x0000ffff,true),
89 HOWTO(R_68K_PC8
, 0, 0, 8, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC8", false, 0, 0x000000ff,true),
90 HOWTO(R_68K_GOT32
, 0, 2,32, true, 0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_GOT32", false, 0, 0xffffffff,true),
91 HOWTO(R_68K_GOT16
, 0, 1,16, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT16", false, 0, 0x0000ffff,true),
92 HOWTO(R_68K_GOT8
, 0, 0, 8, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT8", false, 0, 0x000000ff,true),
93 HOWTO(R_68K_GOT32O
, 0, 2,32, false,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_GOT32O", false, 0, 0xffffffff,false),
94 HOWTO(R_68K_GOT16O
, 0, 1,16, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT16O", false, 0, 0x0000ffff,false),
95 HOWTO(R_68K_GOT8O
, 0, 0, 8, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT8O", false, 0, 0x000000ff,false),
96 HOWTO(R_68K_PLT32
, 0, 2,32, true, 0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_PLT32", false, 0, 0xffffffff,true),
97 HOWTO(R_68K_PLT16
, 0, 1,16, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT16", false, 0, 0x0000ffff,true),
98 HOWTO(R_68K_PLT8
, 0, 0, 8, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT8", false, 0, 0x000000ff,true),
99 HOWTO(R_68K_PLT32O
, 0, 2,32, false,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_PLT32O", false, 0, 0xffffffff,false),
100 HOWTO(R_68K_PLT16O
, 0, 1,16, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT16O", false, 0, 0x0000ffff,false),
101 HOWTO(R_68K_PLT8O
, 0, 0, 8, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT8O", false, 0, 0x000000ff,false),
102 HOWTO(R_68K_COPY
, 0, 0, 0, false,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_COPY", false, 0, 0xffffffff,false),
103 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),
104 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),
105 HOWTO(R_68K_RELATIVE
, 0, 2,32, false,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_RELATIVE", false, 0, 0xffffffff,false),
109 rtype_to_howto (abfd
, cache_ptr
, dst
)
112 Elf_Internal_Rela
*dst
;
114 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_68K__max
);
115 cache_ptr
->howto
= &howto_table
[ELF32_R_TYPE(dst
->r_info
)];
119 rtype_to_howto_rel (abfd
, cache_ptr
, dst
)
122 Elf_Internal_Rel
*dst
;
124 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_68K__max
);
125 cache_ptr
->howto
= &howto_table
[ELF32_R_TYPE(dst
->r_info
)];
128 #define elf_info_to_howto rtype_to_howto
129 #define elf_info_to_howto_rel rtype_to_howto_rel
131 static const struct { unsigned char bfd_val
, elf_val
; } reloc_map
[] = {
132 { BFD_RELOC_NONE
, R_68K_NONE
},
133 { BFD_RELOC_32
, R_68K_32
},
134 { BFD_RELOC_16
, R_68K_16
},
135 { BFD_RELOC_8
, R_68K_8
},
136 { BFD_RELOC_32_PCREL
, R_68K_PC32
},
137 { BFD_RELOC_16_PCREL
, R_68K_PC16
},
138 { BFD_RELOC_8_PCREL
, R_68K_PC8
},
139 { BFD_RELOC_32_GOT_PCREL
, R_68K_GOT32
},
140 { BFD_RELOC_16_GOT_PCREL
, R_68K_GOT16
},
141 { BFD_RELOC_8_GOT_PCREL
, R_68K_GOT8
},
142 { BFD_RELOC_32_GOTOFF
, R_68K_GOT32O
},
143 { BFD_RELOC_16_GOTOFF
, R_68K_GOT16O
},
144 { BFD_RELOC_8_GOTOFF
, R_68K_GOT8O
},
145 { BFD_RELOC_32_PLT_PCREL
, R_68K_PLT32
},
146 { BFD_RELOC_16_PLT_PCREL
, R_68K_PLT16
},
147 { BFD_RELOC_8_PLT_PCREL
, R_68K_PLT8
},
148 { BFD_RELOC_32_PLTOFF
, R_68K_PLT32O
},
149 { BFD_RELOC_16_PLTOFF
, R_68K_PLT16O
},
150 { BFD_RELOC_8_PLTOFF
, R_68K_PLT8O
},
151 { BFD_RELOC_NONE
, R_68K_COPY
},
152 { BFD_RELOC_68K_GLOB_DAT
, R_68K_GLOB_DAT
},
153 { BFD_RELOC_68K_JMP_SLOT
, R_68K_JMP_SLOT
},
154 { BFD_RELOC_68K_RELATIVE
, R_68K_RELATIVE
},
155 { BFD_RELOC_CTOR
, R_68K_32
},
158 static reloc_howto_type
*
159 reloc_type_lookup (abfd
, code
)
161 bfd_reloc_code_real_type code
;
164 for (i
= 0; i
< sizeof (reloc_map
) / sizeof (reloc_map
[0]); i
++)
166 if (reloc_map
[i
].bfd_val
== code
)
167 return &howto_table
[(int) reloc_map
[i
].elf_val
];
172 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
173 #define ELF_ARCH bfd_arch_m68k
174 /* end code generated by elf.el */
179 /* Functions for the m68k ELF linker. */
181 /* The name of the dynamic interpreter. This is put in the .interp
184 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
186 /* The size in bytes of an entry in the procedure linkage table. */
188 #define PLT_ENTRY_SIZE 20
190 /* The first entry in a procedure linkage table looks like this. See
191 the SVR4 ABI m68k supplement to see how this works. */
193 static const bfd_byte elf_m68k_plt0_entry
[PLT_ENTRY_SIZE
] =
195 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
196 0, 0, 0, 0, /* replaced with offset to .got + 4. */
197 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
198 0, 0, 0, 0, /* replaced with offset to .got + 8. */
199 0, 0, 0, 0 /* pad out to 20 bytes. */
202 /* Subsequent entries in a procedure linkage table look like this. */
204 static const bfd_byte elf_m68k_plt_entry
[PLT_ENTRY_SIZE
] =
206 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
207 0, 0, 0, 0, /* replaced with offset to symbol's .got entry. */
208 0x2f, 0x3c, /* move.l #offset,-(%sp) */
209 0, 0, 0, 0, /* replaced with offset into relocation table. */
210 0x60, 0xff, /* bra.l .plt */
211 0, 0, 0, 0 /* replaced with offset to start of .plt. */
214 /* The m68k linker needs to keep track of the number of relocs that it
215 decides to copy in check_relocs for each symbol. This is so that it
216 can discard PC relative relocs if it doesn't need them when linking
217 with -Bsymbolic. We store the information in a field extending the
218 regular ELF linker hash table. */
220 /* This structure keeps track of the number of PC relative relocs we have
221 copied for a given symbol. */
223 struct elf_m68k_pcrel_relocs_copied
226 struct elf_m68k_pcrel_relocs_copied
*next
;
227 /* A section in dynobj. */
229 /* Number of relocs copied in this section. */
233 /* m68k ELF linker hash entry. */
235 struct elf_m68k_link_hash_entry
237 struct elf_link_hash_entry root
;
239 /* Number of PC relative relocs copied for this symbol. */
240 struct elf_m68k_pcrel_relocs_copied
*pcrel_relocs_copied
;
243 /* m68k ELF linker hash table. */
245 struct elf_m68k_link_hash_table
247 struct elf_link_hash_table root
;
250 /* Declare this now that the above structures are defined. */
252 static boolean elf_m68k_discard_copies
253 PARAMS ((struct elf_m68k_link_hash_entry
*, PTR
));
255 /* Traverse an m68k ELF linker hash table. */
257 #define elf_m68k_link_hash_traverse(table, func, info) \
258 (elf_link_hash_traverse \
260 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
263 /* Get the m68k ELF linker hash table from a link_info structure. */
265 #define elf_m68k_hash_table(p) \
266 ((struct elf_m68k_link_hash_table *) (p)->hash)
268 /* Create an entry in an m68k ELF linker hash table. */
270 static struct bfd_hash_entry
*
271 elf_m68k_link_hash_newfunc (entry
, table
, string
)
272 struct bfd_hash_entry
*entry
;
273 struct bfd_hash_table
*table
;
276 struct elf_m68k_link_hash_entry
*ret
=
277 (struct elf_m68k_link_hash_entry
*) entry
;
279 /* Allocate the structure if it has not already been allocated by a
281 if (ret
== (struct elf_m68k_link_hash_entry
*) NULL
)
282 ret
= ((struct elf_m68k_link_hash_entry
*)
283 bfd_hash_allocate (table
,
284 sizeof (struct elf_m68k_link_hash_entry
)));
285 if (ret
== (struct elf_m68k_link_hash_entry
*) NULL
)
286 return (struct bfd_hash_entry
*) ret
;
288 /* Call the allocation method of the superclass. */
289 ret
= ((struct elf_m68k_link_hash_entry
*)
290 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
292 if (ret
!= (struct elf_m68k_link_hash_entry
*) NULL
)
294 ret
->pcrel_relocs_copied
= NULL
;
297 return (struct bfd_hash_entry
*) ret
;
300 /* Create an m68k ELF linker hash table. */
302 static struct bfd_link_hash_table
*
303 elf_m68k_link_hash_table_create (abfd
)
306 struct elf_m68k_link_hash_table
*ret
;
308 ret
= ((struct elf_m68k_link_hash_table
*)
309 bfd_alloc (abfd
, sizeof (struct elf_m68k_link_hash_table
)));
310 if (ret
== (struct elf_m68k_link_hash_table
*) NULL
)
313 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
314 elf_m68k_link_hash_newfunc
))
316 bfd_release (abfd
, ret
);
320 return &ret
->root
.root
;
323 /* Look through the relocs for a section during the first phase, and
324 allocate space in the global offset table or procedure linkage
328 elf_m68k_check_relocs (abfd
, info
, sec
, relocs
)
330 struct bfd_link_info
*info
;
332 const Elf_Internal_Rela
*relocs
;
335 Elf_Internal_Shdr
*symtab_hdr
;
336 struct elf_link_hash_entry
**sym_hashes
;
337 bfd_vma
*local_got_offsets
;
338 const Elf_Internal_Rela
*rel
;
339 const Elf_Internal_Rela
*rel_end
;
344 if (info
->relocateable
)
347 dynobj
= elf_hash_table (info
)->dynobj
;
348 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
349 sym_hashes
= elf_sym_hashes (abfd
);
350 local_got_offsets
= elf_local_got_offsets (abfd
);
356 rel_end
= relocs
+ sec
->reloc_count
;
357 for (rel
= relocs
; rel
< rel_end
; rel
++)
359 unsigned long r_symndx
;
360 struct elf_link_hash_entry
*h
;
362 r_symndx
= ELF32_R_SYM (rel
->r_info
);
364 if (r_symndx
< symtab_hdr
->sh_info
)
367 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
369 switch (ELF32_R_TYPE (rel
->r_info
))
375 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
381 /* This symbol requires a global offset table entry. */
385 /* Create the .got section. */
386 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
387 if (!_bfd_elf_create_got_section (dynobj
, info
))
393 sgot
= bfd_get_section_by_name (dynobj
, ".got");
394 BFD_ASSERT (sgot
!= NULL
);
398 && (h
!= NULL
|| info
->shared
))
400 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
403 srelgot
= bfd_make_section (dynobj
, ".rela.got");
405 || !bfd_set_section_flags (dynobj
, srelgot
,
412 || !bfd_set_section_alignment (dynobj
, srelgot
, 2))
419 if (h
->got
.offset
!= (bfd_vma
) -1)
421 /* We have already allocated space in the .got. */
424 h
->got
.offset
= sgot
->_raw_size
;
426 /* Make sure this symbol is output as a dynamic symbol. */
427 if (h
->dynindx
== -1)
429 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
433 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
437 /* This is a global offset table entry for a local
439 if (local_got_offsets
== NULL
)
442 register unsigned int i
;
444 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
445 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
446 if (local_got_offsets
== NULL
)
448 elf_local_got_offsets (abfd
) = local_got_offsets
;
449 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
450 local_got_offsets
[i
] = (bfd_vma
) -1;
452 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
454 /* We have already allocated space in the .got. */
457 local_got_offsets
[r_symndx
] = sgot
->_raw_size
;
461 /* If we are generating a shared object, we need to
462 output a R_68K_RELATIVE reloc so that the dynamic
463 linker can adjust this GOT entry. */
464 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
468 sgot
->_raw_size
+= 4;
474 /* This symbol requires a procedure linkage table entry. We
475 actually build the entry in adjust_dynamic_symbol,
476 because this might be a case of linking PIC code which is
477 never referenced by a dynamic object, in which case we
478 don't need to generate a procedure linkage table entry
481 /* If this is a local symbol, we resolve it directly without
482 creating a procedure linkage table entry. */
486 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
492 /* This symbol requires a procedure linkage table entry. */
496 /* It does not make sense to have this relocation for a
497 local symbol. FIXME: does it? How to handle it if
498 it does make sense? */
499 bfd_set_error (bfd_error_bad_value
);
503 /* Make sure this symbol is output as a dynamic symbol. */
504 if (h
->dynindx
== -1)
506 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
510 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
516 /* If we are creating a shared library and this is not a local
517 symbol, we need to copy the reloc into the shared library.
518 However when linking with -Bsymbolic and this is a global
519 symbol which is defined in an object we are including in the
520 link (i.e., DEF_REGULAR is set), then we can resolve the
521 reloc directly. At this point we have not seen all the input
522 files, so it is possible that DEF_REGULAR is not set now but
523 will be set later (it is never cleared). We account for that
524 possibility below by storing information in the
525 pcrel_relocs_copied field of the hash table entry. */
527 && (sec
->flags
& SEC_ALLOC
) != 0
530 || (h
->elf_link_hash_flags
531 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
537 /* If we are creating a shared library, we need to copy the
538 reloc into the shared library. */
540 && (sec
->flags
& SEC_ALLOC
) != 0)
542 /* When creating a shared object, we must copy these
543 reloc types into the output file. We create a reloc
544 section in dynobj and make room for this reloc. */
549 name
= (bfd_elf_string_from_elf_section
551 elf_elfheader (abfd
)->e_shstrndx
,
552 elf_section_data (sec
)->rel_hdr
.sh_name
));
556 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
557 && strcmp (bfd_get_section_name (abfd
, sec
),
560 sreloc
= bfd_get_section_by_name (dynobj
, name
);
563 sreloc
= bfd_make_section (dynobj
, name
);
565 || !bfd_set_section_flags (dynobj
, sreloc
,
572 || !bfd_set_section_alignment (dynobj
, sreloc
, 2))
577 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
579 /* If we are linking with -Bsymbolic, we count the number of
580 PC relative relocations we have entered for this symbol,
581 so that we can discard them again if the symbol is later
582 defined by a regular object. Note that this function is
583 only called if we are using an m68kelf linker hash table,
584 which means that h is really a pointer to an
585 elf_m68k_link_hash_entry. */
586 if ((ELF32_R_TYPE (rel
->r_info
) == R_68K_PC8
587 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC16
588 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC32
)
591 struct elf_m68k_link_hash_entry
*eh
;
592 struct elf_m68k_pcrel_relocs_copied
*p
;
594 eh
= (struct elf_m68k_link_hash_entry
*) h
;
596 for (p
= eh
->pcrel_relocs_copied
; p
!= NULL
; p
= p
->next
)
597 if (p
->section
== sreloc
)
602 p
= ((struct elf_m68k_pcrel_relocs_copied
*)
603 bfd_alloc (dynobj
, sizeof *p
));
606 p
->next
= eh
->pcrel_relocs_copied
;
607 eh
->pcrel_relocs_copied
= p
;
626 /* Adjust a symbol defined by a dynamic object and referenced by a
627 regular object. The current definition is in some section of the
628 dynamic object, but we're not including those sections. We have to
629 change the definition to something the rest of the link can
633 elf_m68k_adjust_dynamic_symbol (info
, h
)
634 struct bfd_link_info
*info
;
635 struct elf_link_hash_entry
*h
;
639 unsigned int power_of_two
;
641 dynobj
= elf_hash_table (info
)->dynobj
;
643 /* Make sure we know what is going on here. */
644 BFD_ASSERT (dynobj
!= NULL
645 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
646 || h
->weakdef
!= NULL
647 || ((h
->elf_link_hash_flags
648 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
649 && (h
->elf_link_hash_flags
650 & ELF_LINK_HASH_REF_REGULAR
) != 0
651 && (h
->elf_link_hash_flags
652 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
654 /* If this is a function, put it in the procedure linkage table. We
655 will fill in the contents of the procedure linkage table later,
656 when we know the address of the .got section. */
657 if (h
->type
== STT_FUNC
658 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
661 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
662 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0
663 /* We must always create the plt entry if it was referenced
664 by a PLTxxO relocation. In this case we already recorded
665 it as a dynamic symbol. */
668 /* This case can occur if we saw a PLTxx reloc in an input
669 file, but the symbol was never referred to by a dynamic
670 object. In such a case, we don't actually need to build
671 a procedure linkage table, and we can just do a PCxx
673 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
677 /* Make sure this symbol is output as a dynamic symbol. */
678 if (h
->dynindx
== -1)
680 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
684 s
= bfd_get_section_by_name (dynobj
, ".plt");
685 BFD_ASSERT (s
!= NULL
);
687 /* If this is the first .plt entry, make room for the special
689 if (s
->_raw_size
== 0)
690 s
->_raw_size
+= PLT_ENTRY_SIZE
;
692 /* If this symbol is not defined in a regular file, and we are
693 not generating a shared library, then set the symbol to this
694 location in the .plt. This is required to make function
695 pointers compare as equal between the normal executable and
696 the shared library. */
698 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
700 h
->root
.u
.def
.section
= s
;
701 h
->root
.u
.def
.value
= s
->_raw_size
;
704 h
->plt
.offset
= s
->_raw_size
;
706 /* Make room for this entry. */
707 s
->_raw_size
+= PLT_ENTRY_SIZE
;
709 /* We also need to make an entry in the .got.plt section, which
710 will be placed in the .got section by the linker script. */
712 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
713 BFD_ASSERT (s
!= NULL
);
716 /* We also need to make an entry in the .rela.plt section. */
718 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
719 BFD_ASSERT (s
!= NULL
);
720 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
725 /* If this is a weak symbol, and there is a real definition, the
726 processor independent code will have arranged for us to see the
727 real definition first, and we can just use the same value. */
728 if (h
->weakdef
!= NULL
)
730 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
731 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
732 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
733 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
737 /* This is a reference to a symbol defined by a dynamic object which
738 is not a function. */
740 /* If we are creating a shared library, we must presume that the
741 only references to the symbol are via the global offset table.
742 For such cases we need not do anything here; the relocations will
743 be handled correctly by relocate_section. */
747 /* We must allocate the symbol in our .dynbss section, which will
748 become part of the .bss section of the executable. There will be
749 an entry for this symbol in the .dynsym section. The dynamic
750 object will contain position independent code, so all references
751 from the dynamic object to this symbol will go through the global
752 offset table. The dynamic linker will use the .dynsym entry to
753 determine the address it must put in the global offset table, so
754 both the dynamic object and the regular object will refer to the
755 same memory location for the variable. */
757 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
758 BFD_ASSERT (s
!= NULL
);
760 /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
761 copy the initial value out of the dynamic object and into the
762 runtime process image. We need to remember the offset into the
763 .rela.bss section we are going to use. */
764 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
768 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
769 BFD_ASSERT (srel
!= NULL
);
770 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
771 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
774 /* We need to figure out the alignment required for this symbol. I
775 have no idea how ELF linkers handle this. */
776 power_of_two
= bfd_log2 (h
->size
);
777 if (power_of_two
> 3)
780 /* Apply the required alignment. */
781 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
782 (bfd_size_type
) (1 << power_of_two
));
783 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
785 if (!bfd_set_section_alignment (dynobj
, s
, power_of_two
))
789 /* Define the symbol as being at this point in the section. */
790 h
->root
.u
.def
.section
= s
;
791 h
->root
.u
.def
.value
= s
->_raw_size
;
793 /* Increment the section size to make room for the symbol. */
794 s
->_raw_size
+= h
->size
;
799 /* Set the sizes of the dynamic sections. */
802 elf_m68k_size_dynamic_sections (output_bfd
, info
)
804 struct bfd_link_info
*info
;
812 dynobj
= elf_hash_table (info
)->dynobj
;
813 BFD_ASSERT (dynobj
!= NULL
);
815 if (elf_hash_table (info
)->dynamic_sections_created
)
817 /* Set the contents of the .interp section to the interpreter. */
820 s
= bfd_get_section_by_name (dynobj
, ".interp");
821 BFD_ASSERT (s
!= NULL
);
822 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
823 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
828 /* We may have created entries in the .rela.got section.
829 However, if we are not creating the dynamic sections, we will
830 not actually use these entries. Reset the size of .rela.got,
831 which will cause it to get stripped from the output file
833 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
838 /* If this is a -Bsymbolic shared link, then we need to discard all PC
839 relative relocs against symbols defined in a regular object. We
840 allocated space for them in the check_relocs routine, but we will not
841 fill them in in the relocate_section routine. */
842 if (info
->shared
&& info
->symbolic
)
843 elf_m68k_link_hash_traverse (elf_m68k_hash_table (info
),
844 elf_m68k_discard_copies
,
847 /* The check_relocs and adjust_dynamic_symbol entry points have
848 determined the sizes of the various dynamic sections. Allocate
853 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
858 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
861 /* It's OK to base decisions on the section name, because none
862 of the dynobj section names depend upon the input files. */
863 name
= bfd_get_section_name (dynobj
, s
);
867 if (strcmp (name
, ".plt") == 0)
869 if (s
->_raw_size
== 0)
871 /* Strip this section if we don't need it; see the
877 /* Remember whether there is a PLT. */
881 else if (strncmp (name
, ".rela", 5) == 0)
883 if (s
->_raw_size
== 0)
885 /* If we don't need this section, strip it from the
886 output file. This is mostly to handle .rela.bss and
887 .rela.plt. We must create both sections in
888 create_dynamic_sections, because they must be created
889 before the linker maps input sections to output
890 sections. The linker does that before
891 adjust_dynamic_symbol is called, and it is that
892 function which decides whether anything needs to go
893 into these sections. */
900 /* Remember whether there are any reloc sections other
902 if (strcmp (name
, ".rela.plt") != 0)
908 /* If this relocation section applies to a read only
909 section, then we probably need a DT_TEXTREL
910 entry. .rela.plt is actually associated with
911 .got.plt, which is never readonly. */
912 outname
= bfd_get_section_name (output_bfd
,
914 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
916 && (target
->flags
& SEC_READONLY
) != 0
917 && (target
->flags
& SEC_ALLOC
) != 0)
921 /* We use the reloc_count field as a counter if we need
922 to copy relocs into the output file. */
926 else if (strncmp (name
, ".got", 4) != 0)
928 /* It's not one of our sections, so don't allocate space. */
936 for (spp
= &s
->output_section
->owner
->sections
;
937 *spp
!= s
->output_section
;
940 *spp
= s
->output_section
->next
;
941 --s
->output_section
->owner
->section_count
;
946 /* Allocate memory for the section contents. */
947 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
948 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
952 if (elf_hash_table (info
)->dynamic_sections_created
)
954 /* Add some entries to the .dynamic section. We fill in the
955 values later, in elf_m68k_finish_dynamic_sections, but we
956 must add the entries now so that we get the correct size for
957 the .dynamic section. The DT_DEBUG entry is filled in by the
958 dynamic linker and used by the debugger. */
961 if (!bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
967 if (!bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0)
968 || !bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
969 || !bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
970 || !bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
976 if (!bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
977 || !bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
978 || !bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
979 sizeof (Elf32_External_Rela
)))
985 if (!bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
990 /* If we are generating a shared library, we generate a section
991 symbol for each output section for which we might need to copy
992 relocs. These are local symbols, which means that they must come
993 first in the dynamic symbol table. That means we must increment
994 the dynamic symbol index of every other dynamic symbol. */
1000 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
1002 if ((s
->flags
& SEC_LINKER_CREATED
) != 0
1003 || (s
->flags
& SEC_ALLOC
) == 0)
1006 elf_section_data (s
)->dynindx
= c
+ 1;
1008 /* These symbols will have no names, so we don't need to
1009 fiddle with dynstr_index. */
1014 elf_link_hash_traverse (elf_hash_table (info
),
1015 elf_m68k_adjust_dynindx
,
1017 elf_hash_table (info
)->dynsymcount
+= c
;
1023 /* Increment the index of a dynamic symbol by a given amount. Called
1024 via elf_link_hash_traverse. */
1027 elf_m68k_adjust_dynindx (h
, cparg
)
1028 struct elf_link_hash_entry
*h
;
1031 int *cp
= (int *) cparg
;
1033 if (h
->dynindx
!= -1)
1038 /* This function is called via elf_m68k_link_hash_traverse if we are
1039 creating a shared object with -Bsymbolic. It discards the space
1040 allocated to copy PC relative relocs against symbols which are defined
1041 in regular objects. We allocated space for them in the check_relocs
1042 routine, but we won't fill them in in the relocate_section routine. */
1046 elf_m68k_discard_copies (h
, ignore
)
1047 struct elf_m68k_link_hash_entry
*h
;
1050 struct elf_m68k_pcrel_relocs_copied
*s
;
1052 /* We only discard relocs for symbols defined in a regular object. */
1053 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1056 for (s
= h
->pcrel_relocs_copied
; s
!= NULL
; s
= s
->next
)
1057 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rela
);
1062 /* Relocate an M68K ELF section. */
1065 elf_m68k_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1066 contents
, relocs
, local_syms
, local_sections
)
1068 struct bfd_link_info
*info
;
1070 asection
*input_section
;
1072 Elf_Internal_Rela
*relocs
;
1073 Elf_Internal_Sym
*local_syms
;
1074 asection
**local_sections
;
1077 Elf_Internal_Shdr
*symtab_hdr
;
1078 struct elf_link_hash_entry
**sym_hashes
;
1079 bfd_vma
*local_got_offsets
;
1083 Elf_Internal_Rela
*rel
;
1084 Elf_Internal_Rela
*relend
;
1086 dynobj
= elf_hash_table (info
)->dynobj
;
1087 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1088 sym_hashes
= elf_sym_hashes (input_bfd
);
1089 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1096 relend
= relocs
+ input_section
->reloc_count
;
1097 for (; rel
< relend
; rel
++)
1100 reloc_howto_type
*howto
;
1101 unsigned long r_symndx
;
1102 struct elf_link_hash_entry
*h
;
1103 Elf_Internal_Sym
*sym
;
1106 bfd_reloc_status_type r
;
1108 r_type
= ELF32_R_TYPE (rel
->r_info
);
1109 if (r_type
< 0 || r_type
>= (int) R_68K__max
)
1111 bfd_set_error (bfd_error_bad_value
);
1114 howto
= howto_table
+ r_type
;
1116 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1118 if (info
->relocateable
)
1120 /* This is a relocateable link. We don't have to change
1121 anything, unless the reloc is against a section symbol,
1122 in which case we have to adjust according to where the
1123 section symbol winds up in the output section. */
1124 if (r_symndx
< symtab_hdr
->sh_info
)
1126 sym
= local_syms
+ r_symndx
;
1127 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1129 sec
= local_sections
[r_symndx
];
1130 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1137 /* This is a final link. */
1141 if (r_symndx
< symtab_hdr
->sh_info
)
1143 sym
= local_syms
+ r_symndx
;
1144 sec
= local_sections
[r_symndx
];
1145 relocation
= (sec
->output_section
->vma
1146 + sec
->output_offset
1151 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1152 while (h
->root
.type
== bfd_link_hash_indirect
1153 || h
->root
.type
== bfd_link_hash_warning
)
1154 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1155 if (h
->root
.type
== bfd_link_hash_defined
1156 || h
->root
.type
== bfd_link_hash_defweak
)
1158 sec
= h
->root
.u
.def
.section
;
1159 if (((r_type
== R_68K_PLT8
1160 || r_type
== R_68K_PLT16
1161 || r_type
== R_68K_PLT32
1162 || r_type
== R_68K_PLT8O
1163 || r_type
== R_68K_PLT16O
1164 || r_type
== R_68K_PLT32O
)
1165 && h
->plt
.offset
!= (bfd_vma
) -1)
1166 || ((r_type
== R_68K_GOT8O
1167 || r_type
== R_68K_GOT16O
1168 || r_type
== R_68K_GOT32O
1169 || ((r_type
== R_68K_GOT8
1170 || r_type
== R_68K_GOT16
1171 || r_type
== R_68K_GOT32
)
1172 && strcmp (h
->root
.root
.string
,
1173 "_GLOBAL_OFFSET_TABLE_") != 0))
1174 && elf_hash_table (info
)->dynamic_sections_created
1176 || (! info
->symbolic
&& h
->dynindx
!= -1)
1177 || (h
->elf_link_hash_flags
1178 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1180 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1181 || (h
->elf_link_hash_flags
1182 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
1183 && (input_section
->flags
& SEC_ALLOC
) != 0
1184 && (r_type
== R_68K_8
1185 || r_type
== R_68K_16
1186 || r_type
== R_68K_32
1187 || r_type
== R_68K_PC8
1188 || r_type
== R_68K_PC16
1189 || r_type
== R_68K_PC32
)))
1191 /* In these cases, we don't need the relocation
1192 value. We check specially because in some
1193 obscure cases sec->output_section will be NULL. */
1197 relocation
= (h
->root
.u
.def
.value
1198 + sec
->output_section
->vma
1199 + sec
->output_offset
);
1201 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1203 else if (info
->shared
&& !info
->symbolic
)
1207 if (!(info
->callbacks
->undefined_symbol
1208 (info
, h
->root
.root
.string
, input_bfd
,
1209 input_section
, rel
->r_offset
)))
1220 /* Relocation is to the address of the entry for this symbol
1221 in the global offset table. */
1223 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1229 /* Relocation is the offset of the entry for this symbol in
1230 the global offset table. */
1237 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1238 BFD_ASSERT (sgot
!= NULL
);
1243 off
= h
->got
.offset
;
1244 BFD_ASSERT (off
!= (bfd_vma
) -1);
1246 if (!elf_hash_table (info
)->dynamic_sections_created
1248 && (info
->symbolic
|| h
->dynindx
== -1)
1249 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
1251 /* This is actually a static link, or it is a
1252 -Bsymbolic link and the symbol is defined
1253 locally, or the symbol was forced to be local
1254 because of a version file.. We must initialize
1255 this entry in the global offset table. Since
1256 the offset must always be a multiple of 4, we
1257 use the least significant bit to record whether
1258 we have initialized it already.
1260 When doing a dynamic link, we create a .rela.got
1261 relocation entry to initialize the value. This
1262 is done in the finish_dynamic_symbol routine. */
1267 bfd_put_32 (output_bfd
, relocation
,
1268 sgot
->contents
+ off
);
1275 BFD_ASSERT (local_got_offsets
!= NULL
1276 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1278 off
= local_got_offsets
[r_symndx
];
1280 /* The offset must always be a multiple of 4. We use
1281 the least significant bit to record whether we have
1282 already generated the necessary reloc. */
1287 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
1292 Elf_Internal_Rela outrel
;
1294 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1295 BFD_ASSERT (srelgot
!= NULL
);
1297 outrel
.r_offset
= (sgot
->output_section
->vma
1298 + sgot
->output_offset
1300 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
1301 outrel
.r_addend
= relocation
;
1302 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
1303 (((Elf32_External_Rela
*)
1305 + srelgot
->reloc_count
));
1306 ++srelgot
->reloc_count
;
1309 local_got_offsets
[r_symndx
] |= 1;
1313 relocation
= sgot
->output_offset
+ off
;
1314 if (r_type
== R_68K_GOT8O
1315 || r_type
== R_68K_GOT16O
1316 || r_type
== R_68K_GOT32O
)
1318 /* This relocation does not use the addend. */
1322 relocation
+= sgot
->output_section
->vma
;
1329 /* Relocation is to the entry for this symbol in the
1330 procedure linkage table. */
1332 /* Resolve a PLTxx reloc against a local symbol directly,
1333 without using the procedure linkage table. */
1337 if (h
->plt
.offset
== (bfd_vma
) -1)
1339 /* We didn't make a PLT entry for this symbol. This
1340 happens when statically linking PIC code, or when
1341 using -Bsymbolic. */
1347 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1348 BFD_ASSERT (splt
!= NULL
);
1351 relocation
= (splt
->output_section
->vma
1352 + splt
->output_offset
1359 /* Relocation is the offset of the entry for this symbol in
1360 the procedure linkage table. */
1361 BFD_ASSERT (h
!= NULL
&& h
->plt
.offset
!= (bfd_vma
) -1);
1365 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1366 BFD_ASSERT (splt
!= NULL
);
1369 relocation
= h
->plt
.offset
;
1371 /* This relocation does not use the addend. */
1386 && (input_section
->flags
& SEC_ALLOC
) != 0
1387 && ((r_type
!= R_68K_PC8
1388 && r_type
!= R_68K_PC16
1389 && r_type
!= R_68K_PC32
)
1391 || (h
->elf_link_hash_flags
1392 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1394 Elf_Internal_Rela outrel
;
1395 boolean skip
, relocate
;
1397 /* When generating a shared object, these relocations
1398 are copied into the output file to be resolved at run
1405 name
= (bfd_elf_string_from_elf_section
1407 elf_elfheader (input_bfd
)->e_shstrndx
,
1408 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1412 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1413 && strcmp (bfd_get_section_name (input_bfd
,
1417 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1418 BFD_ASSERT (sreloc
!= NULL
);
1423 if (elf_section_data (input_section
)->stab_info
== NULL
)
1424 outrel
.r_offset
= rel
->r_offset
;
1429 off
= (_bfd_stab_section_offset
1430 (output_bfd
, &elf_hash_table (info
)->stab_info
,
1432 &elf_section_data (input_section
)->stab_info
,
1434 if (off
== (bfd_vma
) -1)
1436 outrel
.r_offset
= off
;
1439 outrel
.r_offset
+= (input_section
->output_section
->vma
1440 + input_section
->output_offset
);
1444 memset (&outrel
, 0, sizeof outrel
);
1447 /* h->dynindx may be -1 if the symbol was marked to
1450 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1451 || (h
->elf_link_hash_flags
1452 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1454 BFD_ASSERT (h
->dynindx
!= -1);
1456 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1457 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1461 if (r_type
== R_68K_32
)
1464 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
1465 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1472 sec
= local_sections
[r_symndx
];
1475 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
1477 == bfd_link_hash_defweak
));
1478 sec
= h
->root
.u
.def
.section
;
1480 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
1482 else if (sec
== NULL
|| sec
->owner
== NULL
)
1484 bfd_set_error (bfd_error_bad_value
);
1491 osec
= sec
->output_section
;
1492 indx
= elf_section_data (osec
)->dynindx
;
1493 BFD_ASSERT (indx
> 0);
1497 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
1498 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1502 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
1503 (((Elf32_External_Rela
*)
1505 + sreloc
->reloc_count
));
1506 ++sreloc
->reloc_count
;
1508 /* This reloc will be computed at runtime, so there's no
1509 need to do anything now, except for R_68K_32
1510 relocations that have been turned into
1522 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1523 contents
, rel
->r_offset
,
1524 relocation
, rel
->r_addend
);
1526 if (r
!= bfd_reloc_ok
)
1531 case bfd_reloc_outofrange
:
1533 case bfd_reloc_overflow
:
1538 name
= h
->root
.root
.string
;
1541 name
= bfd_elf_string_from_elf_section (input_bfd
,
1542 symtab_hdr
->sh_link
,
1547 name
= bfd_section_name (input_bfd
, sec
);
1549 if (!(info
->callbacks
->reloc_overflow
1550 (info
, name
, howto
->name
, (bfd_vma
) 0,
1551 input_bfd
, input_section
, rel
->r_offset
)))
1562 /* Finish up dynamic symbol handling. We set the contents of various
1563 dynamic sections here. */
1566 elf_m68k_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1568 struct bfd_link_info
*info
;
1569 struct elf_link_hash_entry
*h
;
1570 Elf_Internal_Sym
*sym
;
1574 dynobj
= elf_hash_table (info
)->dynobj
;
1576 if (h
->plt
.offset
!= (bfd_vma
) -1)
1583 Elf_Internal_Rela rela
;
1585 /* This symbol has an entry in the procedure linkage table. Set
1588 BFD_ASSERT (h
->dynindx
!= -1);
1590 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1591 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
1592 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1593 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
1595 /* Get the index in the procedure linkage table which
1596 corresponds to this symbol. This is the index of this symbol
1597 in all the symbols for which we are making plt entries. The
1598 first entry in the procedure linkage table is reserved. */
1599 plt_index
= h
->plt
.offset
/ PLT_ENTRY_SIZE
- 1;
1601 /* Get the offset into the .got table of the entry that
1602 corresponds to this function. Each .got entry is 4 bytes.
1603 The first three are reserved. */
1604 got_offset
= (plt_index
+ 3) * 4;
1606 /* Fill in the entry in the procedure linkage table. */
1607 memcpy (splt
->contents
+ h
->plt
.offset
, elf_m68k_plt_entry
,
1609 /* The offset is relative to the first extension word. */
1610 bfd_put_32 (output_bfd
,
1611 (sgot
->output_section
->vma
1612 + sgot
->output_offset
1614 - (splt
->output_section
->vma
1615 + h
->plt
.offset
+ 2)),
1616 splt
->contents
+ h
->plt
.offset
+ 4);
1618 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
1619 splt
->contents
+ h
->plt
.offset
+ 10);
1620 bfd_put_32 (output_bfd
, - (h
->plt
.offset
+ 16),
1621 splt
->contents
+ h
->plt
.offset
+ 16);
1623 /* Fill in the entry in the global offset table. */
1624 bfd_put_32 (output_bfd
,
1625 (splt
->output_section
->vma
1626 + splt
->output_offset
1629 sgot
->contents
+ got_offset
);
1631 /* Fill in the entry in the .rela.plt section. */
1632 rela
.r_offset
= (sgot
->output_section
->vma
1633 + sgot
->output_offset
1635 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_JMP_SLOT
);
1637 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1638 ((Elf32_External_Rela
*) srela
->contents
1641 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1643 /* Mark the symbol as undefined, rather than as defined in
1644 the .plt section. Leave the value alone. */
1645 sym
->st_shndx
= SHN_UNDEF
;
1649 if (h
->got
.offset
!= (bfd_vma
) -1)
1653 Elf_Internal_Rela rela
;
1655 /* This symbol has an entry in the global offset table. Set it
1658 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1659 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1660 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1662 rela
.r_offset
= (sgot
->output_section
->vma
1663 + sgot
->output_offset
1664 + (h
->got
.offset
&~ 1));
1666 /* If this is a -Bsymbolic link, and the symbol is defined
1667 locally, we just want to emit a RELATIVE reloc. Likewise if
1668 the symbol was forced to be local because of a version file.
1669 The entry in the global offset table will already have been
1670 initialized in the relocate_section function. */
1672 && (info
->symbolic
|| h
->dynindx
== -1)
1673 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
1675 rela
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
1676 rela
.r_addend
= bfd_get_signed_32 (output_bfd
,
1678 + (h
->got
.offset
& ~1)));
1682 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
1683 sgot
->contents
+ (h
->got
.offset
& ~1));
1684 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_GLOB_DAT
);
1688 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1689 ((Elf32_External_Rela
*) srela
->contents
1690 + srela
->reloc_count
));
1691 ++srela
->reloc_count
;
1694 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
1697 Elf_Internal_Rela rela
;
1699 /* This symbol needs a copy reloc. Set it up. */
1701 BFD_ASSERT (h
->dynindx
!= -1
1702 && (h
->root
.type
== bfd_link_hash_defined
1703 || h
->root
.type
== bfd_link_hash_defweak
));
1705 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1707 BFD_ASSERT (s
!= NULL
);
1709 rela
.r_offset
= (h
->root
.u
.def
.value
1710 + h
->root
.u
.def
.section
->output_section
->vma
1711 + h
->root
.u
.def
.section
->output_offset
);
1712 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_COPY
);
1714 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1715 ((Elf32_External_Rela
*) s
->contents
1720 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1721 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1722 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1723 sym
->st_shndx
= SHN_ABS
;
1728 /* Finish up the dynamic sections. */
1731 elf_m68k_finish_dynamic_sections (output_bfd
, info
)
1733 struct bfd_link_info
*info
;
1739 dynobj
= elf_hash_table (info
)->dynobj
;
1741 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
1742 BFD_ASSERT (sgot
!= NULL
);
1743 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1745 if (elf_hash_table (info
)->dynamic_sections_created
)
1748 Elf32_External_Dyn
*dyncon
, *dynconend
;
1750 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1751 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
1753 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
1754 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
1755 for (; dyncon
< dynconend
; dyncon
++)
1757 Elf_Internal_Dyn dyn
;
1761 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1774 s
= bfd_get_section_by_name (output_bfd
, name
);
1775 BFD_ASSERT (s
!= NULL
);
1776 dyn
.d_un
.d_ptr
= s
->vma
;
1777 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1781 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
1782 BFD_ASSERT (s
!= NULL
);
1783 if (s
->_cooked_size
!= 0)
1784 dyn
.d_un
.d_val
= s
->_cooked_size
;
1786 dyn
.d_un
.d_val
= s
->_raw_size
;
1787 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1791 /* The procedure linkage table relocs (DT_JMPREL) should
1792 not be included in the overall relocs (DT_RELA).
1793 Therefore, we override the DT_RELASZ entry here to
1794 make it not include the JMPREL relocs. Since the
1795 linker script arranges for .rela.plt to follow all
1796 other relocation sections, we don't have to worry
1797 about changing the DT_RELA entry. */
1798 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
1801 if (s
->_cooked_size
!= 0)
1802 dyn
.d_un
.d_val
-= s
->_cooked_size
;
1804 dyn
.d_un
.d_val
-= s
->_raw_size
;
1806 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1811 /* Fill in the first entry in the procedure linkage table. */
1812 if (splt
->_raw_size
> 0)
1814 memcpy (splt
->contents
, elf_m68k_plt0_entry
, PLT_ENTRY_SIZE
);
1815 bfd_put_32 (output_bfd
,
1816 (sgot
->output_section
->vma
1817 + sgot
->output_offset
+ 4
1818 - (splt
->output_section
->vma
+ 2)),
1819 splt
->contents
+ 4);
1820 bfd_put_32 (output_bfd
,
1821 (sgot
->output_section
->vma
1822 + sgot
->output_offset
+ 8
1823 - (splt
->output_section
->vma
+ 10)),
1824 splt
->contents
+ 12);
1827 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
1831 /* Fill in the first three entries in the global offset table. */
1832 if (sgot
->_raw_size
> 0)
1835 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
1837 bfd_put_32 (output_bfd
,
1838 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
1840 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
1841 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
1844 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
1850 Elf_Internal_Sym sym
;
1853 /* Set up the section symbols for the output sections. */
1855 sdynsym
= bfd_get_section_by_name (dynobj
, ".dynsym");
1856 BFD_ASSERT (sdynsym
!= NULL
);
1860 sym
.st_info
= ELF_ST_INFO (STB_LOCAL
, STT_SECTION
);
1864 for (s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
)
1868 if (elf_section_data (s
)->dynindx
== 0)
1871 sym
.st_value
= s
->vma
;
1873 indx
= elf_section_data (s
)->this_idx
;
1874 BFD_ASSERT (indx
> 0);
1875 sym
.st_shndx
= indx
;
1877 bfd_elf32_swap_symbol_out (output_bfd
, &sym
,
1878 (PTR
) (((Elf32_External_Sym
*)
1880 + elf_section_data (s
)->dynindx
));
1885 /* Set the sh_info field of the output .dynsym section to the
1886 index of the first global symbol. */
1887 elf_section_data (sdynsym
->output_section
)->this_hdr
.sh_info
= c
+ 1;
1893 #define TARGET_BIG_SYM bfd_elf32_m68k_vec
1894 #define TARGET_BIG_NAME "elf32-m68k"
1895 #define ELF_MACHINE_CODE EM_68K
1896 #define ELF_MAXPAGESIZE 0x2000
1897 #define elf_backend_create_dynamic_sections \
1898 _bfd_elf_create_dynamic_sections
1899 #define bfd_elf32_bfd_link_hash_table_create \
1900 elf_m68k_link_hash_table_create
1901 #define elf_backend_check_relocs elf_m68k_check_relocs
1902 #define elf_backend_adjust_dynamic_symbol \
1903 elf_m68k_adjust_dynamic_symbol
1904 #define elf_backend_size_dynamic_sections \
1905 elf_m68k_size_dynamic_sections
1906 #define elf_backend_relocate_section elf_m68k_relocate_section
1907 #define elf_backend_finish_dynamic_symbol \
1908 elf_m68k_finish_dynamic_symbol
1909 #define elf_backend_finish_dynamic_sections \
1910 elf_m68k_finish_dynamic_sections
1911 #define elf_backend_want_got_plt 1
1912 #define elf_backend_plt_readonly 1
1913 #define elf_backend_want_plt_sym 0
1915 #include "elf32-target.h"