1 /* Motorola 68k series support for 32-bit ELF
2 Copyright 1993, 1995, 1996, 1997 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_size_dynamic_sections
42 PARAMS ((bfd
*, struct bfd_link_info
*));
43 static boolean elf_m68k_relocate_section
44 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
45 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
46 static boolean elf_m68k_finish_dynamic_symbol
47 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
49 static boolean elf_m68k_finish_dynamic_sections
50 PARAMS ((bfd
*, struct bfd_link_info
*));
52 /* elf32 m68k code, generated by elf.el */
80 static reloc_howto_type howto_table
[] = {
81 HOWTO(R_68K_NONE
, 0, 0, 0, false,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_NONE", false, 0, 0x00000000,false),
82 HOWTO(R_68K_32
, 0, 2,32, false,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_32", false, 0, 0xffffffff,false),
83 HOWTO(R_68K_16
, 0, 1,16, false,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_16", false, 0, 0x0000ffff,false),
84 HOWTO(R_68K_8
, 0, 0, 8, false,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_8", false, 0, 0x000000ff,false),
85 HOWTO(R_68K_PC32
, 0, 2,32, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC32", false, 0, 0xffffffff,true),
86 HOWTO(R_68K_PC16
, 0, 1,16, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC16", false, 0, 0x0000ffff,true),
87 HOWTO(R_68K_PC8
, 0, 0, 8, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC8", false, 0, 0x000000ff,true),
88 HOWTO(R_68K_GOT32
, 0, 2,32, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT32", false, 0, 0xffffffff,true),
89 HOWTO(R_68K_GOT16
, 0, 1,16, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT16", false, 0, 0x0000ffff,true),
90 HOWTO(R_68K_GOT8
, 0, 0, 8, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT8", false, 0, 0x000000ff,true),
91 HOWTO(R_68K_GOT32O
, 0, 2,32, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT32O", false, 0, 0xffffffff,false),
92 HOWTO(R_68K_GOT16O
, 0, 1,16, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT16O", false, 0, 0x0000ffff,false),
93 HOWTO(R_68K_GOT8O
, 0, 0, 8, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT8O", false, 0, 0x000000ff,false),
94 HOWTO(R_68K_PLT32
, 0, 2,32, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT32", false, 0, 0xffffffff,true),
95 HOWTO(R_68K_PLT16
, 0, 1,16, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT16", false, 0, 0x0000ffff,true),
96 HOWTO(R_68K_PLT8
, 0, 0, 8, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT8", false, 0, 0x000000ff,true),
97 HOWTO(R_68K_PLT32O
, 0, 2,32, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT32O", false, 0, 0xffffffff,false),
98 HOWTO(R_68K_PLT16O
, 0, 1,16, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT16O", false, 0, 0x0000ffff,false),
99 HOWTO(R_68K_PLT8O
, 0, 0, 8, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT8O", false, 0, 0x000000ff,false),
100 HOWTO(R_68K_COPY
, 0, 0, 0, false,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_COPY", false, 0, 0xffffffff,false),
101 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),
102 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),
103 HOWTO(R_68K_RELATIVE
, 0, 2,32, false,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_RELATIVE", false, 0, 0xffffffff,false),
107 rtype_to_howto (abfd
, cache_ptr
, dst
)
110 Elf_Internal_Rela
*dst
;
112 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_68K__max
);
113 cache_ptr
->howto
= &howto_table
[ELF32_R_TYPE(dst
->r_info
)];
117 rtype_to_howto_rel (abfd
, cache_ptr
, dst
)
120 Elf_Internal_Rel
*dst
;
122 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_68K__max
);
123 cache_ptr
->howto
= &howto_table
[ELF32_R_TYPE(dst
->r_info
)];
126 #define elf_info_to_howto rtype_to_howto
127 #define elf_info_to_howto_rel rtype_to_howto_rel
129 static const struct { unsigned char bfd_val
, elf_val
; } reloc_map
[] = {
130 { BFD_RELOC_NONE
, R_68K_NONE
},
131 { BFD_RELOC_32
, R_68K_32
},
132 { BFD_RELOC_16
, R_68K_16
},
133 { BFD_RELOC_8
, R_68K_8
},
134 { BFD_RELOC_32_PCREL
, R_68K_PC32
},
135 { BFD_RELOC_16_PCREL
, R_68K_PC16
},
136 { BFD_RELOC_8_PCREL
, R_68K_PC8
},
137 { BFD_RELOC_32_GOT_PCREL
, R_68K_GOT32
},
138 { BFD_RELOC_16_GOT_PCREL
, R_68K_GOT16
},
139 { BFD_RELOC_8_GOT_PCREL
, R_68K_GOT8
},
140 { BFD_RELOC_32_GOTOFF
, R_68K_GOT32O
},
141 { BFD_RELOC_16_GOTOFF
, R_68K_GOT16O
},
142 { BFD_RELOC_8_GOTOFF
, R_68K_GOT8O
},
143 { BFD_RELOC_32_PLT_PCREL
, R_68K_PLT32
},
144 { BFD_RELOC_16_PLT_PCREL
, R_68K_PLT16
},
145 { BFD_RELOC_8_PLT_PCREL
, R_68K_PLT8
},
146 { BFD_RELOC_32_PLTOFF
, R_68K_PLT32O
},
147 { BFD_RELOC_16_PLTOFF
, R_68K_PLT16O
},
148 { BFD_RELOC_8_PLTOFF
, R_68K_PLT8O
},
149 { BFD_RELOC_NONE
, R_68K_COPY
},
150 { BFD_RELOC_68K_GLOB_DAT
, R_68K_GLOB_DAT
},
151 { BFD_RELOC_68K_JMP_SLOT
, R_68K_JMP_SLOT
},
152 { BFD_RELOC_68K_RELATIVE
, R_68K_RELATIVE
},
153 { BFD_RELOC_CTOR
, R_68K_32
},
156 static reloc_howto_type
*
157 reloc_type_lookup (abfd
, code
)
159 bfd_reloc_code_real_type code
;
162 for (i
= 0; i
< sizeof (reloc_map
) / sizeof (reloc_map
[0]); i
++)
164 if (reloc_map
[i
].bfd_val
== code
)
165 return &howto_table
[(int) reloc_map
[i
].elf_val
];
170 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
171 #define ELF_ARCH bfd_arch_m68k
172 /* end code generated by elf.el */
177 /* Functions for the m68k ELF linker. */
179 /* The name of the dynamic interpreter. This is put in the .interp
182 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
184 /* The size in bytes of an entry in the procedure linkage table. */
186 #define PLT_ENTRY_SIZE 20
188 /* The first entry in a procedure linkage table looks like this. See
189 the SVR4 ABI m68k supplement to see how this works. */
191 static const bfd_byte elf_m68k_plt0_entry
[PLT_ENTRY_SIZE
] =
193 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
194 0, 0, 0, 0, /* replaced with offset to .got + 4. */
195 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
196 0, 0, 0, 0, /* replaced with offset to .got + 8. */
197 0, 0, 0, 0 /* pad out to 20 bytes. */
200 /* Subsequent entries in a procedure linkage table look like this. */
202 static const bfd_byte elf_m68k_plt_entry
[PLT_ENTRY_SIZE
] =
204 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,symbol@GOTPC]) */
205 0, 0, 0, 0, /* replaced with offset to symbol's .got entry. */
206 0x2f, 0x3c, /* move.l #offset,-(%sp) */
207 0, 0, 0, 0, /* replaced with offset into relocation table. */
208 0x60, 0xff, /* bra.l .plt */
209 0, 0, 0, 0 /* replaced with offset to start of .plt. */
212 /* The m68k linker needs to keep track of the number of relocs that it
213 decides to copy in check_relocs for each symbol. This is so that it
214 can discard PC relative relocs if it doesn't need them when linking
215 with -Bsymbolic. We store the information in a field extending the
216 regular ELF linker hash table. */
218 /* This structure keeps track of the number of PC relative relocs we have
219 copied for a given symbol. */
221 struct elf_m68k_pcrel_relocs_copied
224 struct elf_m68k_pcrel_relocs_copied
*next
;
225 /* A section in dynobj. */
227 /* Number of relocs copied in this section. */
231 /* m68k ELF linker hash entry. */
233 struct elf_m68k_link_hash_entry
235 struct elf_link_hash_entry root
;
237 /* Number of PC relative relocs copied for this symbol. */
238 struct elf_m68k_pcrel_relocs_copied
*pcrel_relocs_copied
;
241 /* m68k ELF linker hash table. */
243 struct elf_m68k_link_hash_table
245 struct elf_link_hash_table root
;
248 /* Declare this now that the above structures are defined. */
250 static boolean elf_m68k_discard_copies
251 PARAMS ((struct elf_m68k_link_hash_entry
*, PTR
));
253 /* Traverse an m68k ELF linker hash table. */
255 #define elf_m68k_link_hash_traverse(table, func, info) \
256 (elf_link_hash_traverse \
258 (boolean (*) PARAMS ((struct elf_link_hash_entry *, PTR))) (func), \
261 /* Get the m68k ELF linker hash table from a link_info structure. */
263 #define elf_m68k_hash_table(p) \
264 ((struct elf_m68k_link_hash_table *) (p)->hash)
266 /* Create an entry in an m68k ELF linker hash table. */
268 static struct bfd_hash_entry
*
269 elf_m68k_link_hash_newfunc (entry
, table
, string
)
270 struct bfd_hash_entry
*entry
;
271 struct bfd_hash_table
*table
;
274 struct elf_m68k_link_hash_entry
*ret
=
275 (struct elf_m68k_link_hash_entry
*) entry
;
277 /* Allocate the structure if it has not already been allocated by a
279 if (ret
== (struct elf_m68k_link_hash_entry
*) NULL
)
280 ret
= ((struct elf_m68k_link_hash_entry
*)
281 bfd_hash_allocate (table
,
282 sizeof (struct elf_m68k_link_hash_entry
)));
283 if (ret
== (struct elf_m68k_link_hash_entry
*) NULL
)
284 return (struct bfd_hash_entry
*) ret
;
286 /* Call the allocation method of the superclass. */
287 ret
= ((struct elf_m68k_link_hash_entry
*)
288 _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry
*) ret
,
290 if (ret
!= (struct elf_m68k_link_hash_entry
*) NULL
)
292 ret
->pcrel_relocs_copied
= NULL
;
295 return (struct bfd_hash_entry
*) ret
;
298 /* Create an m68k ELF linker hash table. */
300 static struct bfd_link_hash_table
*
301 elf_m68k_link_hash_table_create (abfd
)
304 struct elf_m68k_link_hash_table
*ret
;
306 ret
= ((struct elf_m68k_link_hash_table
*)
307 bfd_alloc (abfd
, sizeof (struct elf_m68k_link_hash_table
)));
308 if (ret
== (struct elf_m68k_link_hash_table
*) NULL
)
311 if (! _bfd_elf_link_hash_table_init (&ret
->root
, abfd
,
312 elf_m68k_link_hash_newfunc
))
314 bfd_release (abfd
, ret
);
318 return &ret
->root
.root
;
321 /* Look through the relocs for a section during the first phase, and
322 allocate space in the global offset table or procedure linkage
326 elf_m68k_check_relocs (abfd
, info
, sec
, relocs
)
328 struct bfd_link_info
*info
;
330 const Elf_Internal_Rela
*relocs
;
333 Elf_Internal_Shdr
*symtab_hdr
;
334 struct elf_link_hash_entry
**sym_hashes
;
335 bfd_vma
*local_got_offsets
;
336 const Elf_Internal_Rela
*rel
;
337 const Elf_Internal_Rela
*rel_end
;
342 if (info
->relocateable
)
345 dynobj
= elf_hash_table (info
)->dynobj
;
346 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
347 sym_hashes
= elf_sym_hashes (abfd
);
348 local_got_offsets
= elf_local_got_offsets (abfd
);
354 rel_end
= relocs
+ sec
->reloc_count
;
355 for (rel
= relocs
; rel
< rel_end
; rel
++)
357 unsigned long r_symndx
;
358 struct elf_link_hash_entry
*h
;
360 r_symndx
= ELF32_R_SYM (rel
->r_info
);
362 if (r_symndx
< symtab_hdr
->sh_info
)
365 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
367 switch (ELF32_R_TYPE (rel
->r_info
))
373 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
379 /* This symbol requires a global offset table entry. */
383 /* Create the .got section. */
384 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
385 if (!_bfd_elf_create_got_section (dynobj
, info
))
391 sgot
= bfd_get_section_by_name (dynobj
, ".got");
392 BFD_ASSERT (sgot
!= NULL
);
396 && (h
!= NULL
|| info
->shared
))
398 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
401 srelgot
= bfd_make_section (dynobj
, ".rela.got");
403 || !bfd_set_section_flags (dynobj
, srelgot
,
410 || !bfd_set_section_alignment (dynobj
, srelgot
, 2))
417 if (h
->got_offset
!= (bfd_vma
) -1)
419 /* We have already allocated space in the .got. */
422 h
->got_offset
= sgot
->_raw_size
;
424 /* Make sure this symbol is output as a dynamic symbol. */
425 if (h
->dynindx
== -1)
427 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
431 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
435 /* This is a global offset table entry for a local
437 if (local_got_offsets
== NULL
)
440 register unsigned int i
;
442 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
443 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
444 if (local_got_offsets
== NULL
)
446 elf_local_got_offsets (abfd
) = local_got_offsets
;
447 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
448 local_got_offsets
[i
] = (bfd_vma
) -1;
450 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
452 /* We have already allocated space in the .got. */
455 local_got_offsets
[r_symndx
] = sgot
->_raw_size
;
459 /* If we are generating a shared object, we need to
460 output a R_68K_RELATIVE reloc so that the dynamic
461 linker can adjust this GOT entry. */
462 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
466 sgot
->_raw_size
+= 4;
472 /* This symbol requires a procedure linkage table entry. We
473 actually build the entry in adjust_dynamic_symbol,
474 because this might be a case of linking PIC code which is
475 never referenced by a dynamic object, in which case we
476 don't need to generate a procedure linkage table entry
479 /* If this is a local symbol, we resolve it directly without
480 creating a procedure linkage table entry. */
484 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
490 /* This symbol requires a procedure linkage table entry. */
494 /* It does not make sense to have this relocation for a
495 local symbol. FIXME: does it? How to handle it if
496 it does make sense? */
497 bfd_set_error (bfd_error_bad_value
);
501 /* Make sure this symbol is output as a dynamic symbol. */
502 if (h
->dynindx
== -1)
504 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
508 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
514 /* If we are creating a shared library and this is not a local
515 symbol, we need to copy the reloc into the shared library.
516 However when linking with -Bsymbolic and this is a global
517 symbol which is defined in an object we are including in the
518 link (i.e., DEF_REGULAR is set), then we can resolve the
519 reloc directly. At this point we have not seen all the input
520 files, so it is possible that DEF_REGULAR is not set now but
521 will be set later (it is never cleared). We account for that
522 possibility below by storing information in the
523 pcrel_relocs_copied field of the hash table entry. */
525 && (sec
->flags
& SEC_ALLOC
) != 0
528 || (h
->elf_link_hash_flags
529 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
535 /* If we are creating a shared library, we need to copy the
536 reloc into the shared library. */
538 && (sec
->flags
& SEC_ALLOC
) != 0)
540 /* When creating a shared object, we must copy these
541 reloc types into the output file. We create a reloc
542 section in dynobj and make room for this reloc. */
547 name
= (bfd_elf_string_from_elf_section
549 elf_elfheader (abfd
)->e_shstrndx
,
550 elf_section_data (sec
)->rel_hdr
.sh_name
));
554 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
555 && strcmp (bfd_get_section_name (abfd
, sec
),
558 sreloc
= bfd_get_section_by_name (dynobj
, name
);
561 sreloc
= bfd_make_section (dynobj
, name
);
563 || !bfd_set_section_flags (dynobj
, sreloc
,
570 || !bfd_set_section_alignment (dynobj
, sreloc
, 2))
575 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
577 /* If we are linking with -Bsymbolic, we count the number of
578 PC relative relocations we have entered for this symbol,
579 so that we can discard them again if the symbol is later
580 defined by a regular object. Note that this function is
581 only called if we are using an m68kelf linker hash table,
582 which means that h is really a pointer to an
583 elf_m68k_link_hash_entry. */
584 if ((ELF32_R_TYPE (rel
->r_info
) == R_68K_PC8
585 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC16
586 || ELF32_R_TYPE (rel
->r_info
) == R_68K_PC32
)
589 struct elf_m68k_link_hash_entry
*eh
;
590 struct elf_m68k_pcrel_relocs_copied
*p
;
592 eh
= (struct elf_m68k_link_hash_entry
*) h
;
594 for (p
= eh
->pcrel_relocs_copied
; p
!= NULL
; p
= p
->next
)
595 if (p
->section
== sreloc
)
600 p
= ((struct elf_m68k_pcrel_relocs_copied
*)
601 bfd_alloc (dynobj
, sizeof *p
));
604 p
->next
= eh
->pcrel_relocs_copied
;
605 eh
->pcrel_relocs_copied
= p
;
624 /* Adjust a symbol defined by a dynamic object and referenced by a
625 regular object. The current definition is in some section of the
626 dynamic object, but we're not including those sections. We have to
627 change the definition to something the rest of the link can
631 elf_m68k_adjust_dynamic_symbol (info
, h
)
632 struct bfd_link_info
*info
;
633 struct elf_link_hash_entry
*h
;
637 unsigned int power_of_two
;
639 dynobj
= elf_hash_table (info
)->dynobj
;
641 /* Make sure we know what is going on here. */
642 BFD_ASSERT (dynobj
!= NULL
643 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
644 || h
->weakdef
!= NULL
645 || ((h
->elf_link_hash_flags
646 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
647 && (h
->elf_link_hash_flags
648 & ELF_LINK_HASH_REF_REGULAR
) != 0
649 && (h
->elf_link_hash_flags
650 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
652 /* If this is a function, put it in the procedure linkage table. We
653 will fill in the contents of the procedure linkage table later,
654 when we know the address of the .got section. */
655 if (h
->type
== STT_FUNC
656 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
659 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_DYNAMIC
) == 0
660 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_REF_DYNAMIC
) == 0
661 /* We must always create the plt entry if it was referenced
662 by a PLTxxO relocation. In this case we already recorded
663 it as a dynamic symbol. */
666 /* This case can occur if we saw a PLTxx reloc in an input
667 file, but the symbol was never referred to by a dynamic
668 object. In such a case, we don't actually need to build
669 a procedure linkage table, and we can just do a PCxx
671 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
675 /* Make sure this symbol is output as a dynamic symbol. */
676 if (h
->dynindx
== -1)
678 if (! bfd_elf32_link_record_dynamic_symbol (info
, h
))
682 s
= bfd_get_section_by_name (dynobj
, ".plt");
683 BFD_ASSERT (s
!= NULL
);
685 /* If this is the first .plt entry, make room for the special
687 if (s
->_raw_size
== 0)
688 s
->_raw_size
+= PLT_ENTRY_SIZE
;
690 /* If this symbol is not defined in a regular file, and we are
691 not generating a shared library, then set the symbol to this
692 location in the .plt. This is required to make function
693 pointers compare as equal between the normal executable and
694 the shared library. */
696 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
698 h
->root
.u
.def
.section
= s
;
699 h
->root
.u
.def
.value
= s
->_raw_size
;
702 h
->plt_offset
= s
->_raw_size
;
704 /* Make room for this entry. */
705 s
->_raw_size
+= PLT_ENTRY_SIZE
;
707 /* We also need to make an entry in the .got.plt section, which
708 will be placed in the .got section by the linker script. */
710 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
711 BFD_ASSERT (s
!= NULL
);
714 /* We also need to make an entry in the .rela.plt section. */
716 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
717 BFD_ASSERT (s
!= NULL
);
718 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
723 /* If this is a weak symbol, and there is a real definition, the
724 processor independent code will have arranged for us to see the
725 real definition first, and we can just use the same value. */
726 if (h
->weakdef
!= NULL
)
728 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
729 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
730 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
731 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
735 /* This is a reference to a symbol defined by a dynamic object which
736 is not a function. */
738 /* If we are creating a shared library, we must presume that the
739 only references to the symbol are via the global offset table.
740 For such cases we need not do anything here; the relocations will
741 be handled correctly by relocate_section. */
745 /* We must allocate the symbol in our .dynbss section, which will
746 become part of the .bss section of the executable. There will be
747 an entry for this symbol in the .dynsym section. The dynamic
748 object will contain position independent code, so all references
749 from the dynamic object to this symbol will go through the global
750 offset table. The dynamic linker will use the .dynsym entry to
751 determine the address it must put in the global offset table, so
752 both the dynamic object and the regular object will refer to the
753 same memory location for the variable. */
755 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
756 BFD_ASSERT (s
!= NULL
);
758 /* We must generate a R_68K_COPY reloc to tell the dynamic linker to
759 copy the initial value out of the dynamic object and into the
760 runtime process image. We need to remember the offset into the
761 .rela.bss section we are going to use. */
762 if ((h
->root
.u
.def
.section
->flags
& SEC_ALLOC
) != 0)
766 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
767 BFD_ASSERT (srel
!= NULL
);
768 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
769 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
772 /* We need to figure out the alignment required for this symbol. I
773 have no idea how ELF linkers handle this. */
774 power_of_two
= bfd_log2 (h
->size
);
775 if (power_of_two
> 3)
778 /* Apply the required alignment. */
779 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
780 (bfd_size_type
) (1 << power_of_two
));
781 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
783 if (!bfd_set_section_alignment (dynobj
, s
, power_of_two
))
787 /* Define the symbol as being at this point in the section. */
788 h
->root
.u
.def
.section
= s
;
789 h
->root
.u
.def
.value
= s
->_raw_size
;
791 /* Increment the section size to make room for the symbol. */
792 s
->_raw_size
+= h
->size
;
797 /* Set the sizes of the dynamic sections. */
800 elf_m68k_size_dynamic_sections (output_bfd
, info
)
802 struct bfd_link_info
*info
;
810 dynobj
= elf_hash_table (info
)->dynobj
;
811 BFD_ASSERT (dynobj
!= NULL
);
813 if (elf_hash_table (info
)->dynamic_sections_created
)
815 /* Set the contents of the .interp section to the interpreter. */
818 s
= bfd_get_section_by_name (dynobj
, ".interp");
819 BFD_ASSERT (s
!= NULL
);
820 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
821 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
826 /* We may have created entries in the .rela.got section.
827 However, if we are not creating the dynamic sections, we will
828 not actually use these entries. Reset the size of .rela.got,
829 which will cause it to get stripped from the output file
831 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
836 /* If this is a -Bsymbolic shared link, then we need to discard all PC
837 relative relocs against symbols defined in a regular object. We
838 allocated space for them in the check_relocs routine, but we will not
839 fill them in in the relocate_section routine. */
840 if (info
->shared
&& info
->symbolic
)
841 elf_m68k_link_hash_traverse (elf_m68k_hash_table (info
),
842 elf_m68k_discard_copies
,
845 /* The check_relocs and adjust_dynamic_symbol entry points have
846 determined the sizes of the various dynamic sections. Allocate
851 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
856 if ((s
->flags
& SEC_LINKER_CREATED
) == 0)
859 /* It's OK to base decisions on the section name, because none
860 of the dynobj section names depend upon the input files. */
861 name
= bfd_get_section_name (dynobj
, s
);
865 if (strcmp (name
, ".plt") == 0)
867 if (s
->_raw_size
== 0)
869 /* Strip this section if we don't need it; see the
875 /* Remember whether there is a PLT. */
879 else if (strncmp (name
, ".rela", 5) == 0)
881 if (s
->_raw_size
== 0)
883 /* If we don't need this section, strip it from the
884 output file. This is mostly to handle .rela.bss and
885 .rela.plt. We must create both sections in
886 create_dynamic_sections, because they must be created
887 before the linker maps input sections to output
888 sections. The linker does that before
889 adjust_dynamic_symbol is called, and it is that
890 function which decides whether anything needs to go
891 into these sections. */
898 /* Remember whether there are any reloc sections other
900 if (strcmp (name
, ".rela.plt") != 0)
906 /* If this relocation section applies to a read only
907 section, then we probably need a DT_TEXTREL
908 entry. .rela.plt is actually associated with
909 .got.plt, which is never readonly. */
910 outname
= bfd_get_section_name (output_bfd
,
912 target
= bfd_get_section_by_name (output_bfd
, outname
+ 5);
914 && (target
->flags
& SEC_READONLY
) != 0)
918 /* We use the reloc_count field as a counter if we need
919 to copy relocs into the output file. */
923 else if (strncmp (name
, ".got", 4) != 0)
925 /* It's not one of our sections, so don't allocate space. */
933 for (spp
= &s
->output_section
->owner
->sections
;
934 *spp
!= s
->output_section
;
937 *spp
= s
->output_section
->next
;
938 --s
->output_section
->owner
->section_count
;
943 /* Allocate memory for the section contents. */
944 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
945 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
949 if (elf_hash_table (info
)->dynamic_sections_created
)
951 /* Add some entries to the .dynamic section. We fill in the
952 values later, in elf_m68k_finish_dynamic_sections, but we
953 must add the entries now so that we get the correct size for
954 the .dynamic section. The DT_DEBUG entry is filled in by the
955 dynamic linker and used by the debugger. */
958 if (!bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
964 if (!bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0)
965 || !bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
966 || !bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
967 || !bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
973 if (!bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
974 || !bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
975 || !bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
976 sizeof (Elf32_External_Rela
)))
982 if (!bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
990 /* This function is called via elf_m68k_link_hash_traverse if we are
991 creating a shared object with -Bsymbolic. It discards the space
992 allocated to copy PC relative relocs against symbols which are defined
993 in regular objects. We allocated space for them in the check_relocs
994 routine, but we won't fill them in in the relocate_section routine. */
998 elf_m68k_discard_copies (h
, ignore
)
999 struct elf_m68k_link_hash_entry
*h
;
1002 struct elf_m68k_pcrel_relocs_copied
*s
;
1004 /* We only discard relocs for symbols defined in a regular object. */
1005 if ((h
->root
.elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1008 for (s
= h
->pcrel_relocs_copied
; s
!= NULL
; s
= s
->next
)
1009 s
->section
->_raw_size
-= s
->count
* sizeof (Elf32_External_Rela
);
1014 /* Relocate an M68K ELF section. */
1017 elf_m68k_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
1018 contents
, relocs
, local_syms
, local_sections
)
1020 struct bfd_link_info
*info
;
1022 asection
*input_section
;
1024 Elf_Internal_Rela
*relocs
;
1025 Elf_Internal_Sym
*local_syms
;
1026 asection
**local_sections
;
1029 Elf_Internal_Shdr
*symtab_hdr
;
1030 struct elf_link_hash_entry
**sym_hashes
;
1031 bfd_vma
*local_got_offsets
;
1035 Elf_Internal_Rela
*rel
;
1036 Elf_Internal_Rela
*relend
;
1038 dynobj
= elf_hash_table (info
)->dynobj
;
1039 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
1040 sym_hashes
= elf_sym_hashes (input_bfd
);
1041 local_got_offsets
= elf_local_got_offsets (input_bfd
);
1048 relend
= relocs
+ input_section
->reloc_count
;
1049 for (; rel
< relend
; rel
++)
1052 reloc_howto_type
*howto
;
1053 unsigned long r_symndx
;
1054 struct elf_link_hash_entry
*h
;
1055 Elf_Internal_Sym
*sym
;
1058 bfd_reloc_status_type r
;
1060 r_type
= ELF32_R_TYPE (rel
->r_info
);
1061 if (r_type
< 0 || r_type
>= (int) R_68K__max
)
1063 bfd_set_error (bfd_error_bad_value
);
1066 howto
= howto_table
+ r_type
;
1068 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1070 if (info
->relocateable
)
1072 /* This is a relocateable link. We don't have to change
1073 anything, unless the reloc is against a section symbol,
1074 in which case we have to adjust according to where the
1075 section symbol winds up in the output section. */
1076 if (r_symndx
< symtab_hdr
->sh_info
)
1078 sym
= local_syms
+ r_symndx
;
1079 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1081 sec
= local_sections
[r_symndx
];
1082 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1089 /* This is a final link. */
1093 if (r_symndx
< symtab_hdr
->sh_info
)
1095 sym
= local_syms
+ r_symndx
;
1096 sec
= local_sections
[r_symndx
];
1097 relocation
= (sec
->output_section
->vma
1098 + sec
->output_offset
1103 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1104 while (h
->root
.type
== bfd_link_hash_indirect
1105 || h
->root
.type
== bfd_link_hash_warning
)
1106 h
= (struct elf_link_hash_entry
*) h
->root
.u
.i
.link
;
1107 if (h
->root
.type
== bfd_link_hash_defined
1108 || h
->root
.type
== bfd_link_hash_defweak
)
1110 sec
= h
->root
.u
.def
.section
;
1111 if (((r_type
== R_68K_PLT8
1112 || r_type
== R_68K_PLT16
1113 || r_type
== R_68K_PLT32
1114 || r_type
== R_68K_PLT8O
1115 || r_type
== R_68K_PLT16O
1116 || r_type
== R_68K_PLT32O
)
1117 && h
->plt_offset
!= (bfd_vma
) -1)
1118 || ((r_type
== R_68K_GOT8O
1119 || r_type
== R_68K_GOT16O
1120 || r_type
== R_68K_GOT32O
1121 || ((r_type
== R_68K_GOT8
1122 || r_type
== R_68K_GOT16
1123 || r_type
== R_68K_GOT32
)
1124 && strcmp (h
->root
.root
.string
,
1125 "_GLOBAL_OFFSET_TABLE_") != 0))
1126 && elf_hash_table (info
)->dynamic_sections_created
1129 || (h
->elf_link_hash_flags
1130 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1132 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1133 || (h
->elf_link_hash_flags
1134 & ELF_LINK_HASH_DEF_REGULAR
) == 0)
1135 && (input_section
->flags
& SEC_ALLOC
) != 0
1136 && (r_type
== R_68K_8
1137 || r_type
== R_68K_16
1138 || r_type
== R_68K_32
1139 || r_type
== R_68K_PC8
1140 || r_type
== R_68K_PC16
1141 || r_type
== R_68K_PC32
)))
1143 /* In these cases, we don't need the relocation
1144 value. We check specially because in some
1145 obscure cases sec->output_section will be NULL. */
1149 relocation
= (h
->root
.u
.def
.value
1150 + sec
->output_section
->vma
1151 + sec
->output_offset
);
1153 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1155 else if (info
->shared
&& !info
->symbolic
)
1159 if (!(info
->callbacks
->undefined_symbol
1160 (info
, h
->root
.root
.string
, input_bfd
,
1161 input_section
, rel
->r_offset
)))
1172 /* Relocation is to the address of the entry for this symbol
1173 in the global offset table. */
1175 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1181 /* Relocation is the offset of the entry for this symbol in
1182 the global offset table. */
1189 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1190 BFD_ASSERT (sgot
!= NULL
);
1195 off
= h
->got_offset
;
1196 BFD_ASSERT (off
!= (bfd_vma
) -1);
1198 if (!elf_hash_table (info
)->dynamic_sections_created
1201 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
)))
1203 /* This is actually a static link, or it is a
1204 -Bsymbolic link and the symbol is defined
1205 locally. We must initialize this entry in the
1206 global offset table. Since the offset must
1207 always be a multiple of 4, we use the least
1208 significant bit to record whether we have
1209 initialized it already.
1211 When doing a dynamic link, we create a .rela.got
1212 relocation entry to initialize the value. This
1213 is done in the finish_dynamic_symbol routine. */
1218 bfd_put_32 (output_bfd
, relocation
,
1219 sgot
->contents
+ off
);
1226 BFD_ASSERT (local_got_offsets
!= NULL
1227 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1229 off
= local_got_offsets
[r_symndx
];
1231 /* The offset must always be a multiple of 4. We use
1232 the least significant bit to record whether we have
1233 already generated the necessary reloc. */
1238 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
1243 Elf_Internal_Rela outrel
;
1245 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1246 BFD_ASSERT (srelgot
!= NULL
);
1248 outrel
.r_offset
= (sgot
->output_section
->vma
1249 + sgot
->output_offset
1251 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
1252 outrel
.r_addend
= relocation
;
1253 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
1254 (((Elf32_External_Rela
*)
1256 + srelgot
->reloc_count
));
1257 ++srelgot
->reloc_count
;
1260 local_got_offsets
[r_symndx
] |= 1;
1264 relocation
= sgot
->output_offset
+ off
;
1265 if (r_type
== R_68K_GOT8O
1266 || r_type
== R_68K_GOT16O
1267 || r_type
== R_68K_GOT32O
)
1269 /* This relocation does not use the addend. */
1273 relocation
+= sgot
->output_section
->vma
;
1280 /* Relocation is to the entry for this symbol in the
1281 procedure linkage table. */
1283 /* Resolve a PLTxx reloc against a local symbol directly,
1284 without using the procedure linkage table. */
1288 if (h
->plt_offset
== (bfd_vma
) -1)
1290 /* We didn't make a PLT entry for this symbol. This
1291 happens when statically linking PIC code, or when
1292 using -Bsymbolic. */
1298 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1299 BFD_ASSERT (splt
!= NULL
);
1302 relocation
= (splt
->output_section
->vma
1303 + splt
->output_offset
1310 /* Relocation is the offset of the entry for this symbol in
1311 the procedure linkage table. */
1312 BFD_ASSERT (h
!= NULL
&& h
->plt_offset
== (bfd_vma
) -1);
1316 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1317 BFD_ASSERT (splt
!= NULL
);
1320 relocation
= h
->plt_offset
;
1322 /* This relocation does not use the addend. */
1337 && (input_section
->flags
& SEC_ALLOC
) != 0
1338 && ((r_type
!= R_68K_PC8
1339 && r_type
!= R_68K_PC16
1340 && r_type
!= R_68K_PC32
)
1342 || (h
->elf_link_hash_flags
1343 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1345 Elf_Internal_Rela outrel
;
1346 boolean skip
, relocate
;
1348 /* When generating a shared object, these relocations
1349 are copied into the output file to be resolved at run
1356 name
= (bfd_elf_string_from_elf_section
1358 elf_elfheader (input_bfd
)->e_shstrndx
,
1359 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1363 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1364 && strcmp (bfd_get_section_name (input_bfd
,
1368 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1369 BFD_ASSERT (sreloc
!= NULL
);
1374 if (elf_section_data (input_section
)->stab_info
== NULL
)
1375 outrel
.r_offset
= rel
->r_offset
;
1380 off
= (_bfd_stab_section_offset
1381 (output_bfd
, &elf_hash_table (info
)->stab_info
,
1383 &elf_section_data (input_section
)->stab_info
,
1385 if (off
== (bfd_vma
) -1)
1387 outrel
.r_offset
= off
;
1390 outrel
.r_offset
+= (input_section
->output_section
->vma
1391 + input_section
->output_offset
);
1395 memset (&outrel
, 0, sizeof outrel
);
1398 /* h->dynindx may be -1 if the symbol was marked to
1401 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1402 || (h
->elf_link_hash_flags
1403 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1405 BFD_ASSERT (h
->dynindx
!= -1);
1407 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1408 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1412 if (r_type
== R_68K_32
)
1415 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
1416 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1423 sec
= local_sections
[r_symndx
];
1426 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
1428 == bfd_link_hash_defweak
));
1429 sec
= h
->root
.u
.def
.section
;
1431 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
1433 else if (sec
== NULL
|| sec
->owner
== NULL
)
1435 bfd_set_error (bfd_error_bad_value
);
1442 osec
= sec
->output_section
;
1443 indx
= elf_section_data (osec
)->dynindx
;
1449 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
1450 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1454 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
1455 (((Elf32_External_Rela
*)
1457 + sreloc
->reloc_count
));
1458 ++sreloc
->reloc_count
;
1460 /* This reloc will be computed at runtime, so there's no
1461 need to do anything now, except for R_68K_32
1462 relocations that have been turned into
1474 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1475 contents
, rel
->r_offset
,
1476 relocation
, rel
->r_addend
);
1478 if (r
!= bfd_reloc_ok
)
1483 case bfd_reloc_outofrange
:
1485 case bfd_reloc_overflow
:
1490 name
= h
->root
.root
.string
;
1493 name
= bfd_elf_string_from_elf_section (input_bfd
,
1494 symtab_hdr
->sh_link
,
1499 name
= bfd_section_name (input_bfd
, sec
);
1501 if (!(info
->callbacks
->reloc_overflow
1502 (info
, name
, howto
->name
, (bfd_vma
) 0,
1503 input_bfd
, input_section
, rel
->r_offset
)))
1514 /* Finish up dynamic symbol handling. We set the contents of various
1515 dynamic sections here. */
1518 elf_m68k_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1520 struct bfd_link_info
*info
;
1521 struct elf_link_hash_entry
*h
;
1522 Elf_Internal_Sym
*sym
;
1526 dynobj
= elf_hash_table (info
)->dynobj
;
1528 if (h
->plt_offset
!= (bfd_vma
) -1)
1535 Elf_Internal_Rela rela
;
1537 /* This symbol has an entry in the procedure linkage table. Set
1540 BFD_ASSERT (h
->dynindx
!= -1);
1542 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1543 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
1544 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1545 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
1547 /* Get the index in the procedure linkage table which
1548 corresponds to this symbol. This is the index of this symbol
1549 in all the symbols for which we are making plt entries. The
1550 first entry in the procedure linkage table is reserved. */
1551 plt_index
= h
->plt_offset
/ PLT_ENTRY_SIZE
- 1;
1553 /* Get the offset into the .got table of the entry that
1554 corresponds to this function. Each .got entry is 4 bytes.
1555 The first three are reserved. */
1556 got_offset
= (plt_index
+ 3) * 4;
1558 /* Fill in the entry in the procedure linkage table. */
1559 memcpy (splt
->contents
+ h
->plt_offset
, elf_m68k_plt_entry
,
1561 /* The offset is relative to the first extension word. */
1562 bfd_put_32 (output_bfd
,
1563 (sgot
->output_section
->vma
1564 + sgot
->output_offset
1566 - (splt
->output_section
->vma
1567 + h
->plt_offset
+ 2)),
1568 splt
->contents
+ h
->plt_offset
+ 4);
1570 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
1571 splt
->contents
+ h
->plt_offset
+ 10);
1572 bfd_put_32 (output_bfd
, - (h
->plt_offset
+ 16),
1573 splt
->contents
+ h
->plt_offset
+ 16);
1575 /* Fill in the entry in the global offset table. */
1576 bfd_put_32 (output_bfd
,
1577 (splt
->output_section
->vma
1578 + splt
->output_offset
1581 sgot
->contents
+ got_offset
);
1583 /* Fill in the entry in the .rela.plt section. */
1584 rela
.r_offset
= (sgot
->output_section
->vma
1585 + sgot
->output_offset
1587 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_JMP_SLOT
);
1589 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1590 ((Elf32_External_Rela
*) srela
->contents
1593 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1595 /* Mark the symbol as undefined, rather than as defined in
1596 the .plt section. Leave the value alone. */
1597 sym
->st_shndx
= SHN_UNDEF
;
1601 if (h
->got_offset
!= (bfd_vma
) -1)
1605 Elf_Internal_Rela rela
;
1607 /* This symbol has an entry in the global offset table. Set it
1610 BFD_ASSERT (h
->dynindx
!= -1);
1612 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1613 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1614 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1616 rela
.r_offset
= (sgot
->output_section
->vma
1617 + sgot
->output_offset
1618 + (h
->got_offset
&~ 1));
1620 /* If this is a -Bsymbolic link, and the symbol is defined
1621 locally, we just want to emit a RELATIVE reloc. The entry in
1622 the global offset table will already have been initialized in
1623 the relocate_section function. */
1626 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
))
1628 rela
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
1629 rela
.r_addend
= bfd_get_32 (output_bfd
,
1630 sgot
->contents
+ (h
->got_offset
& ~1));
1634 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
1635 sgot
->contents
+ (h
->got_offset
& ~1));
1636 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_GLOB_DAT
);
1640 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1641 ((Elf32_External_Rela
*) srela
->contents
1642 + srela
->reloc_count
));
1643 ++srela
->reloc_count
;
1646 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
1649 Elf_Internal_Rela rela
;
1651 /* This symbol needs a copy reloc. Set it up. */
1653 BFD_ASSERT (h
->dynindx
!= -1
1654 && (h
->root
.type
== bfd_link_hash_defined
1655 || h
->root
.type
== bfd_link_hash_defweak
));
1657 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1659 BFD_ASSERT (s
!= NULL
);
1661 rela
.r_offset
= (h
->root
.u
.def
.value
1662 + h
->root
.u
.def
.section
->output_section
->vma
1663 + h
->root
.u
.def
.section
->output_offset
);
1664 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_COPY
);
1666 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1667 ((Elf32_External_Rela
*) s
->contents
1672 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1673 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1674 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1675 sym
->st_shndx
= SHN_ABS
;
1680 /* Finish up the dynamic sections. */
1683 elf_m68k_finish_dynamic_sections (output_bfd
, info
)
1685 struct bfd_link_info
*info
;
1691 dynobj
= elf_hash_table (info
)->dynobj
;
1693 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
1694 BFD_ASSERT (sgot
!= NULL
);
1695 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1697 if (elf_hash_table (info
)->dynamic_sections_created
)
1700 Elf32_External_Dyn
*dyncon
, *dynconend
;
1702 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1703 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
1705 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
1706 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
1707 for (; dyncon
< dynconend
; dyncon
++)
1709 Elf_Internal_Dyn dyn
;
1713 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1726 s
= bfd_get_section_by_name (output_bfd
, name
);
1727 BFD_ASSERT (s
!= NULL
);
1728 dyn
.d_un
.d_ptr
= s
->vma
;
1729 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1733 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
1734 BFD_ASSERT (s
!= NULL
);
1735 if (s
->_cooked_size
!= 0)
1736 dyn
.d_un
.d_val
= s
->_cooked_size
;
1738 dyn
.d_un
.d_val
= s
->_raw_size
;
1739 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1743 /* The procedure linkage table relocs (DT_JMPREL) should
1744 not be included in the overall relocs (DT_RELA).
1745 Therefore, we override the DT_RELASZ entry here to
1746 make it not include the JMPREL relocs. Since the
1747 linker script arranges for .rela.plt to follow all
1748 other relocation sections, we don't have to worry
1749 about changing the DT_RELA entry. */
1750 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
1753 if (s
->_cooked_size
!= 0)
1754 dyn
.d_un
.d_val
-= s
->_cooked_size
;
1756 dyn
.d_un
.d_val
-= s
->_raw_size
;
1758 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1763 /* Fill in the first entry in the procedure linkage table. */
1764 if (splt
->_raw_size
> 0)
1766 memcpy (splt
->contents
, elf_m68k_plt0_entry
, PLT_ENTRY_SIZE
);
1767 bfd_put_32 (output_bfd
,
1768 (sgot
->output_section
->vma
1769 + sgot
->output_offset
+ 4
1770 - (splt
->output_section
->vma
+ 2)),
1771 splt
->contents
+ 4);
1772 bfd_put_32 (output_bfd
,
1773 (sgot
->output_section
->vma
1774 + sgot
->output_offset
+ 8
1775 - (splt
->output_section
->vma
+ 10)),
1776 splt
->contents
+ 12);
1779 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
1783 /* Fill in the first three entries in the global offset table. */
1784 if (sgot
->_raw_size
> 0)
1787 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
1789 bfd_put_32 (output_bfd
,
1790 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
1792 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
1793 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
1796 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
1801 #define TARGET_BIG_SYM bfd_elf32_m68k_vec
1802 #define TARGET_BIG_NAME "elf32-m68k"
1803 #define ELF_MACHINE_CODE EM_68K
1804 #define ELF_MAXPAGESIZE 0x2000
1805 #define elf_backend_create_dynamic_sections \
1806 _bfd_elf_create_dynamic_sections
1807 #define bfd_elf32_bfd_link_hash_table_create \
1808 elf_m68k_link_hash_table_create
1809 #define elf_backend_check_relocs elf_m68k_check_relocs
1810 #define elf_backend_adjust_dynamic_symbol \
1811 elf_m68k_adjust_dynamic_symbol
1812 #define elf_backend_size_dynamic_sections \
1813 elf_m68k_size_dynamic_sections
1814 #define elf_backend_relocate_section elf_m68k_relocate_section
1815 #define elf_backend_finish_dynamic_symbol \
1816 elf_m68k_finish_dynamic_symbol
1817 #define elf_backend_finish_dynamic_sections \
1818 elf_m68k_finish_dynamic_sections
1819 #define elf_backend_want_got_plt 1
1820 #define elf_backend_plt_readonly 1
1821 #define elf_backend_want_plt_sym 0
1823 #include "elf32-target.h"