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_bitfield
, 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_bitfield
, 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_bitfield
, 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_bitfield
, 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_bitfield
, 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
1128 || (! info
->symbolic
&& h
->dynindx
!= -1)
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
1200 && (info
->symbolic
|| h
->dynindx
== -1)
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, or the symbol was forced to be local
1206 because of a version file.. We must initialize
1207 this entry in the global offset table. Since
1208 the offset must always be a multiple of 4, we
1209 use the least significant bit to record whether
1210 we have initialized it already.
1212 When doing a dynamic link, we create a .rela.got
1213 relocation entry to initialize the value. This
1214 is done in the finish_dynamic_symbol routine. */
1219 bfd_put_32 (output_bfd
, relocation
,
1220 sgot
->contents
+ off
);
1227 BFD_ASSERT (local_got_offsets
!= NULL
1228 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1230 off
= local_got_offsets
[r_symndx
];
1232 /* The offset must always be a multiple of 4. We use
1233 the least significant bit to record whether we have
1234 already generated the necessary reloc. */
1239 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
1244 Elf_Internal_Rela outrel
;
1246 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1247 BFD_ASSERT (srelgot
!= NULL
);
1249 outrel
.r_offset
= (sgot
->output_section
->vma
1250 + sgot
->output_offset
1252 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
1253 outrel
.r_addend
= relocation
;
1254 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
1255 (((Elf32_External_Rela
*)
1257 + srelgot
->reloc_count
));
1258 ++srelgot
->reloc_count
;
1261 local_got_offsets
[r_symndx
] |= 1;
1265 relocation
= sgot
->output_offset
+ off
;
1266 if (r_type
== R_68K_GOT8O
1267 || r_type
== R_68K_GOT16O
1268 || r_type
== R_68K_GOT32O
)
1270 /* This relocation does not use the addend. */
1274 relocation
+= sgot
->output_section
->vma
;
1281 /* Relocation is to the entry for this symbol in the
1282 procedure linkage table. */
1284 /* Resolve a PLTxx reloc against a local symbol directly,
1285 without using the procedure linkage table. */
1289 if (h
->plt_offset
== (bfd_vma
) -1)
1291 /* We didn't make a PLT entry for this symbol. This
1292 happens when statically linking PIC code, or when
1293 using -Bsymbolic. */
1299 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1300 BFD_ASSERT (splt
!= NULL
);
1303 relocation
= (splt
->output_section
->vma
1304 + splt
->output_offset
1311 /* Relocation is the offset of the entry for this symbol in
1312 the procedure linkage table. */
1313 BFD_ASSERT (h
!= NULL
&& h
->plt_offset
== (bfd_vma
) -1);
1317 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1318 BFD_ASSERT (splt
!= NULL
);
1321 relocation
= h
->plt_offset
;
1323 /* This relocation does not use the addend. */
1338 && (input_section
->flags
& SEC_ALLOC
) != 0
1339 && ((r_type
!= R_68K_PC8
1340 && r_type
!= R_68K_PC16
1341 && r_type
!= R_68K_PC32
)
1343 || (h
->elf_link_hash_flags
1344 & ELF_LINK_HASH_DEF_REGULAR
) == 0)))
1346 Elf_Internal_Rela outrel
;
1347 boolean skip
, relocate
;
1349 /* When generating a shared object, these relocations
1350 are copied into the output file to be resolved at run
1357 name
= (bfd_elf_string_from_elf_section
1359 elf_elfheader (input_bfd
)->e_shstrndx
,
1360 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1364 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1365 && strcmp (bfd_get_section_name (input_bfd
,
1369 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1370 BFD_ASSERT (sreloc
!= NULL
);
1375 if (elf_section_data (input_section
)->stab_info
== NULL
)
1376 outrel
.r_offset
= rel
->r_offset
;
1381 off
= (_bfd_stab_section_offset
1382 (output_bfd
, &elf_hash_table (info
)->stab_info
,
1384 &elf_section_data (input_section
)->stab_info
,
1386 if (off
== (bfd_vma
) -1)
1388 outrel
.r_offset
= off
;
1391 outrel
.r_offset
+= (input_section
->output_section
->vma
1392 + input_section
->output_offset
);
1396 memset (&outrel
, 0, sizeof outrel
);
1399 /* h->dynindx may be -1 if the symbol was marked to
1402 && ((! info
->symbolic
&& h
->dynindx
!= -1)
1403 || (h
->elf_link_hash_flags
1404 & ELF_LINK_HASH_DEF_REGULAR
) == 0))
1406 BFD_ASSERT (h
->dynindx
!= -1);
1408 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1409 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1413 if (r_type
== R_68K_32
)
1416 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
1417 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1424 sec
= local_sections
[r_symndx
];
1427 BFD_ASSERT (h
->root
.type
== bfd_link_hash_defined
1429 == bfd_link_hash_defweak
));
1430 sec
= h
->root
.u
.def
.section
;
1432 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
1434 else if (sec
== NULL
|| sec
->owner
== NULL
)
1436 bfd_set_error (bfd_error_bad_value
);
1443 osec
= sec
->output_section
;
1444 indx
= elf_section_data (osec
)->dynindx
;
1450 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
1451 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1455 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
1456 (((Elf32_External_Rela
*)
1458 + sreloc
->reloc_count
));
1459 ++sreloc
->reloc_count
;
1461 /* This reloc will be computed at runtime, so there's no
1462 need to do anything now, except for R_68K_32
1463 relocations that have been turned into
1475 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1476 contents
, rel
->r_offset
,
1477 relocation
, rel
->r_addend
);
1479 if (r
!= bfd_reloc_ok
)
1484 case bfd_reloc_outofrange
:
1486 case bfd_reloc_overflow
:
1491 name
= h
->root
.root
.string
;
1494 name
= bfd_elf_string_from_elf_section (input_bfd
,
1495 symtab_hdr
->sh_link
,
1500 name
= bfd_section_name (input_bfd
, sec
);
1502 if (!(info
->callbacks
->reloc_overflow
1503 (info
, name
, howto
->name
, (bfd_vma
) 0,
1504 input_bfd
, input_section
, rel
->r_offset
)))
1515 /* Finish up dynamic symbol handling. We set the contents of various
1516 dynamic sections here. */
1519 elf_m68k_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1521 struct bfd_link_info
*info
;
1522 struct elf_link_hash_entry
*h
;
1523 Elf_Internal_Sym
*sym
;
1527 dynobj
= elf_hash_table (info
)->dynobj
;
1529 if (h
->plt_offset
!= (bfd_vma
) -1)
1536 Elf_Internal_Rela rela
;
1538 /* This symbol has an entry in the procedure linkage table. Set
1541 BFD_ASSERT (h
->dynindx
!= -1);
1543 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1544 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
1545 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1546 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
1548 /* Get the index in the procedure linkage table which
1549 corresponds to this symbol. This is the index of this symbol
1550 in all the symbols for which we are making plt entries. The
1551 first entry in the procedure linkage table is reserved. */
1552 plt_index
= h
->plt_offset
/ PLT_ENTRY_SIZE
- 1;
1554 /* Get the offset into the .got table of the entry that
1555 corresponds to this function. Each .got entry is 4 bytes.
1556 The first three are reserved. */
1557 got_offset
= (plt_index
+ 3) * 4;
1559 /* Fill in the entry in the procedure linkage table. */
1560 memcpy (splt
->contents
+ h
->plt_offset
, elf_m68k_plt_entry
,
1562 /* The offset is relative to the first extension word. */
1563 bfd_put_32 (output_bfd
,
1564 (sgot
->output_section
->vma
1565 + sgot
->output_offset
1567 - (splt
->output_section
->vma
1568 + h
->plt_offset
+ 2)),
1569 splt
->contents
+ h
->plt_offset
+ 4);
1571 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
1572 splt
->contents
+ h
->plt_offset
+ 10);
1573 bfd_put_32 (output_bfd
, - (h
->plt_offset
+ 16),
1574 splt
->contents
+ h
->plt_offset
+ 16);
1576 /* Fill in the entry in the global offset table. */
1577 bfd_put_32 (output_bfd
,
1578 (splt
->output_section
->vma
1579 + splt
->output_offset
1582 sgot
->contents
+ got_offset
);
1584 /* Fill in the entry in the .rela.plt section. */
1585 rela
.r_offset
= (sgot
->output_section
->vma
1586 + sgot
->output_offset
1588 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_JMP_SLOT
);
1590 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1591 ((Elf32_External_Rela
*) srela
->contents
1594 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1596 /* Mark the symbol as undefined, rather than as defined in
1597 the .plt section. Leave the value alone. */
1598 sym
->st_shndx
= SHN_UNDEF
;
1602 if (h
->got_offset
!= (bfd_vma
) -1)
1606 Elf_Internal_Rela rela
;
1608 /* This symbol has an entry in the global offset table. Set it
1611 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1612 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1613 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1615 rela
.r_offset
= (sgot
->output_section
->vma
1616 + sgot
->output_offset
1617 + (h
->got_offset
&~ 1));
1619 /* If this is a -Bsymbolic link, and the symbol is defined
1620 locally, we just want to emit a RELATIVE reloc. Likewise if
1621 the symbol was forced to be local because of a version file.
1622 The entry in the global offset table will already have been
1623 initialized in the relocate_section function. */
1625 && (info
->symbolic
|| h
->dynindx
== -1)
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_signed_32 (output_bfd
,
1631 + (h
->got_offset
& ~1)));
1635 bfd_put_32 (output_bfd
, (bfd_vma
) 0,
1636 sgot
->contents
+ (h
->got_offset
& ~1));
1637 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_GLOB_DAT
);
1641 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1642 ((Elf32_External_Rela
*) srela
->contents
1643 + srela
->reloc_count
));
1644 ++srela
->reloc_count
;
1647 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
1650 Elf_Internal_Rela rela
;
1652 /* This symbol needs a copy reloc. Set it up. */
1654 BFD_ASSERT (h
->dynindx
!= -1
1655 && (h
->root
.type
== bfd_link_hash_defined
1656 || h
->root
.type
== bfd_link_hash_defweak
));
1658 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1660 BFD_ASSERT (s
!= NULL
);
1662 rela
.r_offset
= (h
->root
.u
.def
.value
1663 + h
->root
.u
.def
.section
->output_section
->vma
1664 + h
->root
.u
.def
.section
->output_offset
);
1665 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_COPY
);
1667 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1668 ((Elf32_External_Rela
*) s
->contents
1673 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1674 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1675 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1676 sym
->st_shndx
= SHN_ABS
;
1681 /* Finish up the dynamic sections. */
1684 elf_m68k_finish_dynamic_sections (output_bfd
, info
)
1686 struct bfd_link_info
*info
;
1692 dynobj
= elf_hash_table (info
)->dynobj
;
1694 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
1695 BFD_ASSERT (sgot
!= NULL
);
1696 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1698 if (elf_hash_table (info
)->dynamic_sections_created
)
1701 Elf32_External_Dyn
*dyncon
, *dynconend
;
1703 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1704 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
1706 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
1707 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
1708 for (; dyncon
< dynconend
; dyncon
++)
1710 Elf_Internal_Dyn dyn
;
1714 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1727 s
= bfd_get_section_by_name (output_bfd
, name
);
1728 BFD_ASSERT (s
!= NULL
);
1729 dyn
.d_un
.d_ptr
= s
->vma
;
1730 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1734 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
1735 BFD_ASSERT (s
!= NULL
);
1736 if (s
->_cooked_size
!= 0)
1737 dyn
.d_un
.d_val
= s
->_cooked_size
;
1739 dyn
.d_un
.d_val
= s
->_raw_size
;
1740 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1744 /* The procedure linkage table relocs (DT_JMPREL) should
1745 not be included in the overall relocs (DT_RELA).
1746 Therefore, we override the DT_RELASZ entry here to
1747 make it not include the JMPREL relocs. Since the
1748 linker script arranges for .rela.plt to follow all
1749 other relocation sections, we don't have to worry
1750 about changing the DT_RELA entry. */
1751 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
1754 if (s
->_cooked_size
!= 0)
1755 dyn
.d_un
.d_val
-= s
->_cooked_size
;
1757 dyn
.d_un
.d_val
-= s
->_raw_size
;
1759 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1764 /* Fill in the first entry in the procedure linkage table. */
1765 if (splt
->_raw_size
> 0)
1767 memcpy (splt
->contents
, elf_m68k_plt0_entry
, PLT_ENTRY_SIZE
);
1768 bfd_put_32 (output_bfd
,
1769 (sgot
->output_section
->vma
1770 + sgot
->output_offset
+ 4
1771 - (splt
->output_section
->vma
+ 2)),
1772 splt
->contents
+ 4);
1773 bfd_put_32 (output_bfd
,
1774 (sgot
->output_section
->vma
1775 + sgot
->output_offset
+ 8
1776 - (splt
->output_section
->vma
+ 10)),
1777 splt
->contents
+ 12);
1780 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
1784 /* Fill in the first three entries in the global offset table. */
1785 if (sgot
->_raw_size
> 0)
1788 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
1790 bfd_put_32 (output_bfd
,
1791 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
1793 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
1794 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
1797 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
1802 #define TARGET_BIG_SYM bfd_elf32_m68k_vec
1803 #define TARGET_BIG_NAME "elf32-m68k"
1804 #define ELF_MACHINE_CODE EM_68K
1805 #define ELF_MAXPAGESIZE 0x2000
1806 #define elf_backend_create_dynamic_sections \
1807 _bfd_elf_create_dynamic_sections
1808 #define bfd_elf32_bfd_link_hash_table_create \
1809 elf_m68k_link_hash_table_create
1810 #define elf_backend_check_relocs elf_m68k_check_relocs
1811 #define elf_backend_adjust_dynamic_symbol \
1812 elf_m68k_adjust_dynamic_symbol
1813 #define elf_backend_size_dynamic_sections \
1814 elf_m68k_size_dynamic_sections
1815 #define elf_backend_relocate_section elf_m68k_relocate_section
1816 #define elf_backend_finish_dynamic_symbol \
1817 elf_m68k_finish_dynamic_symbol
1818 #define elf_backend_finish_dynamic_sections \
1819 elf_m68k_finish_dynamic_sections
1820 #define elf_backend_want_got_plt 1
1821 #define elf_backend_plt_readonly 1
1822 #define elf_backend_want_plt_sym 0
1824 #include "elf32-target.h"