1 /* Motorola 68k series support for 32-bit ELF
2 Copyright 1993 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., 675 Mass Ave, Cambridge, MA 02139, 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 boolean elf_m68k_create_dynamic_sections
33 PARAMS ((bfd
*, struct bfd_link_info
*));
34 static boolean elf_m68k_create_got_section
35 PARAMS ((bfd
*, struct bfd_link_info
*));
36 static boolean elf_m68k_check_relocs
37 PARAMS ((bfd
*, struct bfd_link_info
*, asection
*,
38 const Elf_Internal_Rela
*));
39 static boolean elf_m68k_adjust_dynamic_symbol
40 PARAMS ((struct bfd_link_info
*, struct elf_link_hash_entry
*));
41 static boolean elf_m68k_adjust_dynindx
42 PARAMS ((struct elf_link_hash_entry
*, PTR
));
43 static boolean elf_m68k_size_dynamic_sections
44 PARAMS ((bfd
*, struct bfd_link_info
*));
45 static boolean elf_m68k_relocate_section
46 PARAMS ((bfd
*, struct bfd_link_info
*, bfd
*, asection
*, bfd_byte
*,
47 Elf_Internal_Rela
*, Elf_Internal_Sym
*, asection
**));
48 static boolean elf_m68k_finish_dynamic_symbol
49 PARAMS ((bfd
*, struct bfd_link_info
*, struct elf_link_hash_entry
*,
51 static boolean elf_m68k_finish_dynamic_sections
52 PARAMS ((bfd
*, struct bfd_link_info
*));
54 /* elf32 m68k code, generated by elf.el */
82 static reloc_howto_type howto_table
[] = {
83 HOWTO(R_68K_NONE
, 0, 0, 0, false,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_NONE", false, 0x00000000, 0x00000000,false),
84 HOWTO(R_68K_32
, 0, 2,32, false,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_32", false, 0xffffffff, 0xffffffff,false),
85 HOWTO(R_68K_16
, 0, 1,16, false,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_16", false, 0x0000ffff, 0x0000ffff,false),
86 HOWTO(R_68K_8
, 0, 0, 8, false,0, complain_overflow_bitfield
, bfd_elf_generic_reloc
, "R_68K_8", false, 0x000000ff, 0x000000ff,false),
87 HOWTO(R_68K_PC32
, 0, 2,32, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC32", false, 0xffffffff, 0xffffffff,true),
88 HOWTO(R_68K_PC16
, 0, 1,16, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC16", false, 0x0000ffff, 0x0000ffff,true),
89 HOWTO(R_68K_PC8
, 0, 0, 8, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PC8", false, 0x000000ff, 0x000000ff,true),
90 HOWTO(R_68K_GOT32
, 0, 2,32, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT32", false, 0xffffffff, 0xffffffff,true),
91 HOWTO(R_68K_GOT16
, 0, 1,16, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT16", false, 0x0000ffff, 0x0000ffff,true),
92 HOWTO(R_68K_GOT8
, 0, 0, 8, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT8", false, 0x000000ff, 0x000000ff,true),
93 HOWTO(R_68K_GOT32O
, 0, 2,32, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT32O", false, 0xffffffff, 0xffffffff,false),
94 HOWTO(R_68K_GOT16O
, 0, 1,16, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT16O", false, 0x0000ffff, 0x0000ffff,false),
95 HOWTO(R_68K_GOT8O
, 0, 0, 8, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_GOT8O", false, 0x000000ff, 0x000000ff,false),
96 HOWTO(R_68K_PLT32
, 0, 2,32, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT32", false, 0xffffffff, 0xffffffff,true),
97 HOWTO(R_68K_PLT16
, 0, 1,16, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT16", false, 0x0000ffff, 0x0000ffff,true),
98 HOWTO(R_68K_PLT8
, 0, 0, 8, true, 0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT8", false, 0x000000ff, 0x000000ff,true),
99 HOWTO(R_68K_PLT32O
, 0, 2,32, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT32O", false, 0xffffffff, 0xffffffff,false),
100 HOWTO(R_68K_PLT16O
, 0, 1,16, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT16O", false, 0x0000ffff, 0x0000ffff,false),
101 HOWTO(R_68K_PLT8O
, 0, 0, 8, false,0, complain_overflow_signed
, bfd_elf_generic_reloc
, "R_68K_PLT8O", false, 0x000000ff, 0x000000ff,false),
102 HOWTO(R_68K_COPY
, 0, 0, 0, false,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_COPY", false, 0xffffffff, 0xffffffff,false),
103 HOWTO(R_68K_GLOB_DAT
, 0, 2,32, false,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_GLOB_DAT", false, 0xffffffff, 0xffffffff,false),
104 HOWTO(R_68K_JMP_SLOT
, 0, 2,32, false,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_JMP_SLOT", false, 0xffffffff, 0xffffffff,false),
105 HOWTO(R_68K_RELATIVE
, 0, 2,32, false,0, complain_overflow_dont
, bfd_elf_generic_reloc
, "R_68K_RELATIVE", false, 0xffffffff, 0xffffffff,false),
109 rtype_to_howto (abfd
, cache_ptr
, dst
)
112 Elf_Internal_Rela
*dst
;
114 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_68K__max
);
115 cache_ptr
->howto
= &howto_table
[ELF32_R_TYPE(dst
->r_info
)];
119 rtype_to_howto_rel (abfd
, cache_ptr
, dst
)
122 Elf_Internal_Rel
*dst
;
124 BFD_ASSERT (ELF32_R_TYPE(dst
->r_info
) < (unsigned int) R_68K__max
);
125 cache_ptr
->howto
= &howto_table
[ELF32_R_TYPE(dst
->r_info
)];
128 #define elf_info_to_howto rtype_to_howto
129 #define elf_info_to_howto_rel rtype_to_howto_rel
131 static const struct { unsigned char bfd_val
, elf_val
; } reloc_map
[] = {
132 { BFD_RELOC_NONE
, R_68K_NONE
},
133 { BFD_RELOC_32
, R_68K_32
},
134 { BFD_RELOC_16
, R_68K_16
},
135 { BFD_RELOC_8
, R_68K_8
},
136 { BFD_RELOC_32_PCREL
, R_68K_PC32
},
137 { BFD_RELOC_16_PCREL
, R_68K_PC16
},
138 { BFD_RELOC_8_PCREL
, R_68K_PC8
},
139 { BFD_RELOC_32_GOT_PCREL
, R_68K_GOT32
},
140 { BFD_RELOC_16_GOT_PCREL
, R_68K_GOT16
},
141 { BFD_RELOC_8_GOT_PCREL
, R_68K_GOT8
},
142 { BFD_RELOC_32_GOTOFF
, R_68K_GOT32O
},
143 { BFD_RELOC_16_GOTOFF
, R_68K_GOT16O
},
144 { BFD_RELOC_8_GOTOFF
, R_68K_GOT8O
},
145 { BFD_RELOC_32_PLT_PCREL
, R_68K_PLT32
},
146 { BFD_RELOC_16_PLT_PCREL
, R_68K_PLT16
},
147 { BFD_RELOC_8_PLT_PCREL
, R_68K_PLT8
},
148 { BFD_RELOC_32_PLTOFF
, R_68K_PLT32O
},
149 { BFD_RELOC_16_PLTOFF
, R_68K_PLT16O
},
150 { BFD_RELOC_8_PLTOFF
, R_68K_PLT8O
},
151 { BFD_RELOC_NONE
, R_68K_COPY
},
152 { BFD_RELOC_68K_GLOB_DAT
, R_68K_GLOB_DAT
},
153 { BFD_RELOC_68K_JMP_SLOT
, R_68K_JMP_SLOT
},
154 { BFD_RELOC_68K_RELATIVE
, R_68K_RELATIVE
},
155 { BFD_RELOC_CTOR
, R_68K_32
},
158 static reloc_howto_type
*
159 reloc_type_lookup (abfd
, code
)
161 bfd_reloc_code_real_type code
;
164 for (i
= 0; i
< sizeof (reloc_map
) / sizeof (reloc_map
[0]); i
++)
166 if (reloc_map
[i
].bfd_val
== code
)
167 return &howto_table
[(int) reloc_map
[i
].elf_val
];
172 #define bfd_elf32_bfd_reloc_type_lookup reloc_type_lookup
173 #define ELF_ARCH bfd_arch_m68k
174 /* end code generated by elf.el */
179 /* Functions for the m68k ELF linker. */
181 /* The name of the dynamic interpreter. This is put in the .interp
184 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
186 /* The size in bytes of an entry in the procedure linkage table. */
188 #define PLT_ENTRY_SIZE 20
190 /* The first entry in a procedure linkage table looks like this. See
191 the SVR4 ABI m68k supplement to see how this works. */
193 static const bfd_byte elf_m68k_plt0_entry
[PLT_ENTRY_SIZE
] =
195 0x2f, 0x3b, 0x01, 0x70, /* move.l (%pc,addr),-(%sp) */
196 0, 0, 0, 0, /* replaced with address of .got + 4. */
197 0x4e, 0xfb, 0x01, 0x71, /* jmp ([%pc,addr]) */
198 0, 0, 0, 0, /* replaced with address of .got + 8. */
199 0, 0, 0, 0 /* pad out to 20 bytes. */
202 /* Subsequent entries in a procedure linkage table look like this. */
204 static const bfd_byte elf_m68k_plt_entry
[PLT_ENTRY_SIZE
] =
206 0x4e, 0xfb, 0x01, 0x71, /* jmp ([addr]) */
207 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
208 0x2f, 0x3c, /* move.l #offset,-(%sp) */
209 0, 0, 0, 0, /* replaced with offset into relocation table. */
210 0x60, 0xff, /* bra.l .plt */
211 0, 0, 0, 0 /* replaced with offset to start of .plt. */
214 /* Create dynamic sections when linking against a dynamic object. */
217 elf_m68k_create_dynamic_sections (abfd
, info
)
219 struct bfd_link_info
*info
;
222 register asection
*s
;
224 /* We need to create .plt, .rela.plt, .got, .got.plt, .dynbss, and
225 .rela.bss sections. */
227 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
229 s
= bfd_make_section (abfd
, ".plt");
231 || !bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
| SEC_CODE
)
232 || !bfd_set_section_alignment (abfd
, s
, 2))
235 s
= bfd_make_section (abfd
, ".rela.plt");
237 || !bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
238 || !bfd_set_section_alignment (abfd
, s
, 2))
241 if (!elf_m68k_create_got_section (abfd
, info
))
244 /* The .dynbss section is a place to put symbols which are defined
245 by dynamic objects, are referenced by regular objects, and are
246 not functions. We must allocate space for them in the process
247 image and use a R_68K_COPY reloc to tell the dynamic linker to
248 initialize them at run time. The linker script puts the .dynbss
249 section into the .bss section of the final image. */
250 s
= bfd_make_section (abfd
, ".dynbss");
252 || !bfd_set_section_flags (abfd
, s
, SEC_ALLOC
))
255 /* The .rela.bss section holds copy relocs. This section is not
256 normally needed. We need to create it here, though, so that the
257 linker will map it to an output section. We can't just create it
258 only if we need it, because we will not know whether we need it
259 until we have seen all the input files, and the first time the
260 main linker code calls BFD after examining all the input files
261 (size_dynamic_sections) the input sections have already been
262 mapped to the output sections. If the section turns out not to
263 be needed, we can discard it later. We will never need this
264 section when generating a shared object, since they do not use
268 s
= bfd_make_section (abfd
, ".rela.bss");
270 || !bfd_set_section_flags (abfd
, s
, flags
| SEC_READONLY
)
271 || !bfd_set_section_alignment (abfd
, s
, 2))
278 /* Create the .got section to hold the global offset table, and the
279 .got.plt section to hold procedure linkage table GOT entries. The
280 linker script will put .got.plt into the output .got section. */
283 elf_m68k_create_got_section (abfd
, info
)
285 struct bfd_link_info
*info
;
288 register asection
*s
;
289 struct elf_link_hash_entry
*h
;
291 /* This function may be called more than once. */
292 if (bfd_get_section_by_name (abfd
, ".got") != NULL
)
295 flags
= SEC_ALLOC
| SEC_LOAD
| SEC_HAS_CONTENTS
| SEC_IN_MEMORY
;
297 s
= bfd_make_section (abfd
, ".got");
299 || !bfd_set_section_flags (abfd
, s
, flags
)
300 || !bfd_set_section_alignment (abfd
, s
, 2))
303 s
= bfd_make_section (abfd
, ".got.plt");
305 || !bfd_set_section_flags (abfd
, s
, flags
)
306 || !bfd_set_section_alignment (abfd
, s
, 2))
309 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the
310 .got.plt section, which will be placed at the start of the output
311 .got section. We don't do this in the linker script because we
312 don't want to define the symbol if we are not creating a global
315 if (!(_bfd_generic_link_add_one_symbol
316 (info
, abfd
, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL
, s
, (bfd_vma
) 0,
317 (const char *) NULL
, false, get_elf_backend_data (abfd
)->collect
,
318 (struct bfd_link_hash_entry
**) &h
)))
320 h
->elf_link_hash_flags
|= ELF_LINK_HASH_DEF_REGULAR
;
321 h
->type
= STT_OBJECT
;
324 && !bfd_elf32_link_record_dynamic_symbol (info
, h
))
327 /* The first three global offset table entries are reserved. */
328 s
->_raw_size
+= 3 * 4;
333 /* Look through the relocs for a section during the first phase, and
334 allocate space in the global offset table or procedure linkage
338 elf_m68k_check_relocs (abfd
, info
, sec
, relocs
)
340 struct bfd_link_info
*info
;
342 const Elf_Internal_Rela
*relocs
;
345 Elf_Internal_Shdr
*symtab_hdr
;
346 struct elf_link_hash_entry
**sym_hashes
;
347 bfd_vma
*local_got_offsets
;
348 const Elf_Internal_Rela
*rel
;
349 const Elf_Internal_Rela
*rel_end
;
354 if (info
->relocateable
)
357 dynobj
= elf_hash_table (info
)->dynobj
;
358 symtab_hdr
= &elf_tdata (abfd
)->symtab_hdr
;
359 sym_hashes
= elf_sym_hashes (abfd
);
360 local_got_offsets
= elf_local_got_offsets (abfd
);
366 rel_end
= relocs
+ sec
->reloc_count
;
367 for (rel
= relocs
; rel
< rel_end
; rel
++)
370 struct elf_link_hash_entry
*h
;
372 r_symndx
= ELF32_R_SYM (rel
->r_info
);
374 if (r_symndx
< symtab_hdr
->sh_info
)
377 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
379 switch (ELF32_R_TYPE (rel
->r_info
))
387 /* This symbol requires a global offset table entry. */
390 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
395 /* Create the .got section. */
396 elf_hash_table (info
)->dynobj
= dynobj
= abfd
;
397 if (!elf_m68k_create_got_section (dynobj
, info
))
403 sgot
= bfd_get_section_by_name (dynobj
, ".got");
404 BFD_ASSERT (sgot
!= NULL
);
408 && (h
!= NULL
|| info
->shared
))
410 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
413 srelgot
= bfd_make_section (dynobj
, ".rela.got");
415 || !bfd_set_section_flags (dynobj
, srelgot
,
421 || !bfd_set_section_alignment (dynobj
, srelgot
, 2))
428 if (h
->got_offset
!= (bfd_vma
) -1)
430 /* We have already allocated space in the .got. */
433 h
->got_offset
= sgot
->_raw_size
;
435 /* Make sure this symbol is output as a dynamic symbol. */
436 if (h
->dynindx
== -1)
438 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
442 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
446 /* This is a global offset table entry for a local
448 if (local_got_offsets
== NULL
)
453 size
= symtab_hdr
->sh_info
* sizeof (bfd_vma
);
454 local_got_offsets
= (bfd_vma
*) bfd_alloc (abfd
, size
);
455 if (local_got_offsets
== NULL
)
457 bfd_set_error (bfd_error_no_memory
);
460 elf_local_got_offsets (abfd
) = local_got_offsets
;
461 for (i
= 0; i
< symtab_hdr
->sh_info
; i
++)
462 local_got_offsets
[i
] = (bfd_vma
) -1;
464 if (local_got_offsets
[r_symndx
] != (bfd_vma
) -1)
466 /* We have already allocated space in the .got. */
469 local_got_offsets
[r_symndx
] = sgot
->_raw_size
;
473 /* If we are generating a shared object, we need to
474 output a R_68K_RELATIVE reloc so that the dynamic
475 linker can adjust this GOT entry. */
476 srelgot
->_raw_size
+= sizeof (Elf32_External_Rela
);
480 sgot
->_raw_size
+= 4;
489 /* This symbol requires a procedure linkage table entry. We
490 actually build the entry in adjust_dynamic_symbol,
491 because this might be a case of linking PIC code without
492 linking in any dynamic objects, in which case we don't
493 need to generate a procedure linkage table after all. */
495 /* If this is a local symbol, we resolve it directly without
496 creating a procedure linkage table entry. */
500 /* Make sure this symbol is output as a dynamic symbol. */
501 if (h
->dynindx
== -1)
503 if (!bfd_elf32_link_record_dynamic_symbol (info
, h
))
507 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_PLT
;
517 && (sec
->flags
& SEC_ALLOC
) != 0)
519 /* When creating a shared object, we must copy these
520 reloc types into the output file. We create a reloc
521 section in dynobj and make room for this reloc. */
526 name
= (elf_string_from_elf_section
528 elf_elfheader (abfd
)->e_shstrndx
,
529 elf_section_data (sec
)->rel_hdr
.sh_name
));
533 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
534 && strcmp (bfd_get_section_name (abfd
, sec
),
537 sreloc
= bfd_get_section_by_name (dynobj
, name
);
540 sreloc
= bfd_make_section (dynobj
, name
);
542 || !bfd_set_section_flags (dynobj
, sreloc
,
548 || !bfd_set_section_alignment (dynobj
, sreloc
, 2))
553 sreloc
->_raw_size
+= sizeof (Elf32_External_Rela
);
566 /* Adjust a symbol defined by a dynamic object and referenced by a
567 regular object. The current definition is in some section of the
568 dynamic object, but we're not including those sections. We have to
569 change the definition to something the rest of the link can
573 elf_m68k_adjust_dynamic_symbol (info
, h
)
574 struct bfd_link_info
*info
;
575 struct elf_link_hash_entry
*h
;
579 unsigned int power_of_two
;
581 dynobj
= elf_hash_table (info
)->dynobj
;
583 /* Make sure we know what is going on here. */
584 BFD_ASSERT (dynobj
!= NULL
585 && ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
)
586 || ((h
->elf_link_hash_flags
587 & ELF_LINK_HASH_DEF_DYNAMIC
) != 0
588 && (h
->elf_link_hash_flags
589 & ELF_LINK_HASH_REF_REGULAR
) != 0
590 && (h
->elf_link_hash_flags
591 & ELF_LINK_HASH_DEF_REGULAR
) == 0)));
593 /* If this is a function, put it in the procedure linkage table. We
594 will fill in the contents of the procedure linkage table later,
595 when we know the address of the .got section. */
596 if (h
->type
== STT_FUNC
597 || (h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0)
599 if (!elf_hash_table (info
)->dynamic_sections_created
)
601 /* This case can occur if we saw a PLT32 reloc in an input
602 file, but none of the input files were dynamic objects.
603 In such a case, we don't actually need to build a
604 procedure linkage table, and we can just do a PC32 reloc
606 BFD_ASSERT ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_PLT
) != 0);
610 s
= bfd_get_section_by_name (dynobj
, ".plt");
611 BFD_ASSERT (s
!= NULL
);
613 /* If this is the first .plt entry, make room for the special
615 if (s
->_raw_size
== 0)
616 s
->_raw_size
+= PLT_ENTRY_SIZE
;
618 /* If this symbol is not defined in a regular file, and we are
619 not generating a shared library, then set the symbol to this
620 location in the .plt. This is required to make function
621 pointers compare as equal between the normal executable and
622 the shared library. */
624 && (h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
626 h
->root
.u
.def
.section
= s
;
627 h
->root
.u
.def
.value
= s
->_raw_size
;
630 h
->plt_offset
= s
->_raw_size
;
632 /* Make room for this entry. */
633 s
->_raw_size
+= PLT_ENTRY_SIZE
;
635 /* We also need to make an entry in the .got.plt section, which
636 will be placed in the .got section by the linker script. */
638 s
= bfd_get_section_by_name (dynobj
, ".got.plt");
639 BFD_ASSERT (s
!= NULL
);
642 /* We also need to make an entry in the .rela.plt section. */
644 s
= bfd_get_section_by_name (dynobj
, ".rela.plt");
645 BFD_ASSERT (s
!= NULL
);
646 s
->_raw_size
+= sizeof (Elf32_External_Rela
);
651 /* If this is a weak symbol, and there is a real definition, the
652 processor independent code will have arranged for us to see the
653 real definition first, and we can just use the same value. */
654 if (h
->weakdef
!= NULL
)
656 BFD_ASSERT (h
->weakdef
->root
.type
== bfd_link_hash_defined
657 || h
->weakdef
->root
.type
== bfd_link_hash_defweak
);
658 h
->root
.u
.def
.section
= h
->weakdef
->root
.u
.def
.section
;
659 h
->root
.u
.def
.value
= h
->weakdef
->root
.u
.def
.value
;
663 /* This is a reference to a symbol defined by a dynamic object which
664 is not a function. */
666 /* If we are creating a shared library, we must presume that the
667 only references to the symbol are via the global offset table.
668 For such cases we need not do anything here; the relocations will
669 be handled correctly by relocate_section. */
673 /* We must allocate the symbol in our .dynbss section, which will
674 become part of the .bss section of the executable. There will be
675 an entry for this symbol in the .dynsym section. The dynamic
676 object will contain position independent code, so all references
677 from the dynamic object to this symbol will go through the global
678 offset table. The dynamic linker will use the .dynsym entry to
679 determine the address it must put in the global offset table, so
680 both the dynamic object and the regular object will refer to the
681 same memory location for the variable. */
683 s
= bfd_get_section_by_name (dynobj
, ".dynbss");
684 BFD_ASSERT (s
!= NULL
);
686 /* If the symbol is currently defined in the .bss section of the
687 dynamic object, then it is OK to simply initialize it to zero.
688 If the symbol is in some other section, we must generate a
689 R_68K_COPY reloc to tell the dynamic linker to copy the initial
690 value out of the dynamic object and into the runtime process
691 image. We need to remember the offset into the .rela.bss section
692 we are going to use. */
693 if ((h
->root
.u
.def
.section
->flags
& SEC_LOAD
) != 0)
697 srel
= bfd_get_section_by_name (dynobj
, ".rela.bss");
698 BFD_ASSERT (srel
!= NULL
);
699 srel
->_raw_size
+= sizeof (Elf32_External_Rela
);
700 h
->elf_link_hash_flags
|= ELF_LINK_HASH_NEEDS_COPY
;
703 /* We need to figure out the alignment required for this symbol. I
704 have no idea how ELF linkers handle this. */
705 power_of_two
= bfd_log2 (h
->size
);
706 if (power_of_two
> 3)
709 /* Apply the required alignment. */
710 s
->_raw_size
= BFD_ALIGN (s
->_raw_size
,
711 (bfd_size_type
) (1 << power_of_two
));
712 if (power_of_two
> bfd_get_section_alignment (dynobj
, s
))
714 if (!bfd_set_section_alignment (dynobj
, s
, power_of_two
))
718 /* Define the symbol as being at this point in the section. */
719 h
->root
.u
.def
.section
= s
;
720 h
->root
.u
.def
.value
= s
->_raw_size
;
722 /* Increment the section size to make room for the symbol. */
723 s
->_raw_size
+= h
->size
;
728 /* Set the sizes of the dynamic sections. */
731 elf_m68k_size_dynamic_sections (output_bfd
, info
)
733 struct bfd_link_info
*info
;
741 dynobj
= elf_hash_table (info
)->dynobj
;
742 BFD_ASSERT (dynobj
!= NULL
);
744 if (elf_hash_table (info
)->dynamic_sections_created
)
746 /* Set the contents of the .interp section to the interpreter. */
749 s
= bfd_get_section_by_name (dynobj
, ".interp");
750 BFD_ASSERT (s
!= NULL
);
751 s
->_raw_size
= sizeof ELF_DYNAMIC_INTERPRETER
;
752 s
->contents
= (unsigned char *) ELF_DYNAMIC_INTERPRETER
;
757 /* We may have created entries in the .rela.got section.
758 However, if we are not creating the dynamic sections, we will
759 not actually use these entries. Reset the size of .rela.got,
760 which will cause it to get stripped from the output file
762 s
= bfd_get_section_by_name (dynobj
, ".rela.got");
767 /* The check_relocs and adjust_dynamic_symbol entry points have
768 determined the sizes of the various dynamic sections. Allocate
773 for (s
= dynobj
->sections
; s
!= NULL
; s
= s
->next
)
778 if ((s
->flags
& SEC_IN_MEMORY
) == 0)
781 /* It's OK to base decisions on the section name, because none
782 of the dynobj section names depend upon the input files. */
783 name
= bfd_get_section_name (dynobj
, s
);
787 if (strcmp (name
, ".plt") == 0)
789 if (s
->_raw_size
== 0)
791 /* Strip this section if we don't need it; see the
797 /* Remember whether there is a PLT. */
801 else if (strncmp (name
, ".rela", 5) == 0)
803 if (s
->_raw_size
== 0)
805 /* If we don't need this section, strip it from the
806 output file. This is mostly to handle .rela.bss and
807 .rela.plt. We must create both sections in
808 create_dynamic_sections, because they must be created
809 before the linker maps input sections to output
810 sections. The linker does that before
811 adjust_dynamic_symbol is called, and it is that
812 function which decides whether anything needs to go
813 into these sections. */
820 /* Remember whether there are any reloc sections other
822 if (strcmp (name
, ".rela.plt") != 0)
826 /* If this relocation section applies to a read only
827 section, then we probably need a DT_TEXTREL
828 entry. .rela.plt is actually associated with
829 .got.plt, which is never readonly. */
830 target
= bfd_get_section_by_name (output_bfd
, name
+ 5);
832 && (target
->flags
& SEC_READONLY
) != 0)
836 /* We use the reloc_count field as a counter if we need
837 to copy relocs into the output file. */
841 else if (strncmp (name
, ".got", 4) != 0)
843 /* It's not one of our sections, so don't allocate space. */
851 for (spp
= &s
->output_section
->owner
->sections
;
852 *spp
!= s
->output_section
;
855 *spp
= s
->output_section
->next
;
856 --s
->output_section
->owner
->section_count
;
861 /* Allocate memory for the section contents. */
862 s
->contents
= (bfd_byte
*) bfd_alloc (dynobj
, s
->_raw_size
);
863 if (s
->contents
== NULL
&& s
->_raw_size
!= 0)
865 bfd_set_error (bfd_error_no_memory
);
870 if (elf_hash_table (info
)->dynamic_sections_created
)
872 /* Add some entries to the .dynamic section. We fill in the
873 values later, in elf_m68k_finish_dynamic_sections, but we
874 must add the entries now so that we get the correct size for
875 the .dynamic section. The DT_DEBUG entry is filled in by the
876 dynamic linker and used by the debugger. */
879 if (!bfd_elf32_add_dynamic_entry (info
, DT_DEBUG
, 0))
885 if (!bfd_elf32_add_dynamic_entry (info
, DT_PLTGOT
, 0)
886 || !bfd_elf32_add_dynamic_entry (info
, DT_PLTRELSZ
, 0)
887 || !bfd_elf32_add_dynamic_entry (info
, DT_PLTREL
, DT_RELA
)
888 || !bfd_elf32_add_dynamic_entry (info
, DT_JMPREL
, 0))
894 if (!bfd_elf32_add_dynamic_entry (info
, DT_RELA
, 0)
895 || !bfd_elf32_add_dynamic_entry (info
, DT_RELASZ
, 0)
896 || !bfd_elf32_add_dynamic_entry (info
, DT_RELAENT
,
897 sizeof (Elf32_External_Rela
)))
903 if (!bfd_elf32_add_dynamic_entry (info
, DT_TEXTREL
, 0))
908 /* If we are generating a shared library, we generate a section
909 symbol for each output section. These are local symbols, which
910 means that they must come first in the dynamic symbol table.
911 That means we must increment the dynamic symbol index of every
912 other dynamic symbol. */
917 c
= bfd_count_sections (output_bfd
);
918 elf_link_hash_traverse (elf_hash_table (info
),
919 elf_m68k_adjust_dynindx
,
921 elf_hash_table (info
)->dynsymcount
+= c
;
923 for (i
= 1, s
= output_bfd
->sections
; s
!= NULL
; s
= s
->next
, i
++)
925 elf_section_data (s
)->dynindx
= i
;
926 /* These symbols will have no names, so we don't need to
927 fiddle with dynstr_index. */
934 /* Increment the index of a dynamic symbol by a given amount. Called
935 via elf_link_hash_traverse. */
938 elf_m68k_adjust_dynindx (h
, cparg
)
939 struct elf_link_hash_entry
*h
;
942 int *cp
= (int *) cparg
;
944 if (h
->dynindx
!= -1)
949 /* Relocate an M68K ELF section. */
952 elf_m68k_relocate_section (output_bfd
, info
, input_bfd
, input_section
,
953 contents
, relocs
, local_syms
, local_sections
)
955 struct bfd_link_info
*info
;
957 asection
*input_section
;
959 Elf_Internal_Rela
*relocs
;
960 Elf_Internal_Sym
*local_syms
;
961 asection
**local_sections
;
964 Elf_Internal_Shdr
*symtab_hdr
;
965 struct elf_link_hash_entry
**sym_hashes
;
966 bfd_vma
*local_got_offsets
;
971 Elf_Internal_Rela
*rel
;
972 Elf_Internal_Rela
*relend
;
974 dynobj
= elf_hash_table (info
)->dynobj
;
975 symtab_hdr
= &elf_tdata (input_bfd
)->symtab_hdr
;
976 sym_hashes
= elf_sym_hashes (input_bfd
);
977 local_got_offsets
= elf_local_got_offsets (input_bfd
);
985 relend
= relocs
+ input_section
->reloc_count
;
986 for (; rel
< relend
; rel
++)
989 reloc_howto_type
*howto
;
991 struct elf_link_hash_entry
*h
;
992 Elf_Internal_Sym
*sym
;
995 bfd_reloc_status_type r
;
997 r_type
= ELF32_R_TYPE (rel
->r_info
);
998 if (r_type
< 0 || r_type
>= (int) R_68K__max
)
1000 bfd_set_error (bfd_error_bad_value
);
1003 howto
= howto_table
+ r_type
;
1005 r_symndx
= ELF32_R_SYM (rel
->r_info
);
1007 if (info
->relocateable
)
1009 /* This is a relocateable link. We don't have to change
1010 anything, unless the reloc is against a section symbol,
1011 in which case we have to adjust according to where the
1012 section symbol winds up in the output section. */
1013 if (r_symndx
< symtab_hdr
->sh_info
)
1015 sym
= local_syms
+ r_symndx
;
1016 if (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
)
1018 sec
= local_sections
[r_symndx
];
1019 rel
->r_addend
+= sec
->output_offset
+ sym
->st_value
;
1026 /* This is a final link. */
1030 if (r_symndx
< symtab_hdr
->sh_info
)
1032 sym
= local_syms
+ r_symndx
;
1033 sec
= local_sections
[r_symndx
];
1034 relocation
= (sec
->output_section
->vma
1035 + sec
->output_offset
1040 h
= sym_hashes
[r_symndx
- symtab_hdr
->sh_info
];
1041 if (h
->root
.type
== bfd_link_hash_defined
1042 || h
->root
.type
== bfd_link_hash_defweak
)
1044 sec
= h
->root
.u
.def
.section
;
1045 if (((r_type
== R_68K_PLT8
1046 || r_type
== R_68K_PLT16
1047 || r_type
== R_68K_PLT32
1048 || r_type
== R_68K_PLT8O
1049 || r_type
== R_68K_PLT16O
1050 || r_type
== R_68K_PLT32O
)
1051 && h
->plt_offset
!= (bfd_vma
) -1)
1052 || ((r_type
== R_68K_GOT8O
1053 || r_type
== R_68K_GOT16O
1054 || r_type
== R_68K_GOT32O
1055 || ((r_type
== R_68K_GOT8
1056 || r_type
== R_68K_GOT16
1057 || r_type
== R_68K_GOT32
)
1058 && strcmp (h
->root
.root
.string
,
1059 "_GLOBAL_OFFSET_TABLE_") != 0))
1060 && elf_hash_table (info
)->dynamic_sections_created
)
1062 && (input_section
->flags
& SEC_ALLOC
) != 0
1063 && (r_type
== R_68K_8
1064 || r_type
== R_68K_16
1065 || r_type
== R_68K_32
1066 || r_type
== R_68K_PC8
1067 || r_type
== R_68K_PC16
1068 || r_type
== R_68K_PC32
)))
1070 /* In these cases, we don't need the relocation
1071 value. We check specially because in some
1072 obscure cases sec->output_section will be NULL. */
1076 relocation
= (h
->root
.u
.def
.value
1077 + sec
->output_section
->vma
1078 + sec
->output_offset
);
1080 else if (h
->root
.type
== bfd_link_hash_undefweak
)
1082 else if (info
->shared
)
1086 if (!(info
->callbacks
->undefined_symbol
1087 (info
, h
->root
.root
.string
, input_bfd
,
1088 input_section
, rel
->r_offset
)))
1099 /* Relocation is to the entry for this symbol in the global
1102 && strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1108 /* Relocation is the offset of the entry for this symbol in
1109 the global offset table. */
1113 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1114 BFD_ASSERT (sgot
!= NULL
);
1117 if (sgotplt
== NULL
)
1119 sgotplt
= bfd_get_section_by_name (dynobj
, ".got.plt");
1120 BFD_ASSERT (sgotplt
!= NULL
);
1127 off
= h
->got_offset
;
1128 BFD_ASSERT (off
!= (bfd_vma
) -1);
1130 if (!elf_hash_table (info
)->dynamic_sections_created
)
1132 /* This is actually a static link. We must
1133 initialize this entry in the global offset table.
1134 Since the offset must always be a multiple of 4,
1135 we use the least significant bit to record
1136 whether we have initialized it already.
1138 When doing a dynamic link, we create a .rela.got
1139 relocation entry to initialize the value. This
1140 is done in the finish_dynamic_symbol routine. */
1145 bfd_put_32 (output_bfd
, relocation
,
1146 sgot
->contents
+ off
);
1151 relocation
= sgot
->output_offset
+ off
;
1152 if (r_type
== R_68K_GOT8O
1153 || r_type
== R_68K_GOT16O
1154 || r_type
== R_68K_GOT32O
)
1155 relocation
-= sgotplt
->output_offset
;
1161 BFD_ASSERT (local_got_offsets
!= NULL
1162 && local_got_offsets
[r_symndx
] != (bfd_vma
) -1);
1164 off
= local_got_offsets
[r_symndx
];
1166 /* The offset must always be a multiple of 4. We use
1167 the least significant bit to record whether we have
1168 already generated the necessary reloc. */
1173 bfd_put_32 (output_bfd
, relocation
, sgot
->contents
+ off
);
1178 Elf_Internal_Rela outrel
;
1180 srelgot
= bfd_get_section_by_name (dynobj
, ".rela.got");
1181 BFD_ASSERT (srelgot
!= NULL
);
1183 outrel
.r_offset
= (sgot
->output_section
->vma
1184 + sgot
->output_offset
1186 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
1187 outrel
.r_addend
= 0;
1188 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
1189 (((Elf32_External_Rela
*)
1191 + srelgot
->reloc_count
));
1192 ++srelgot
->reloc_count
;
1195 local_got_offsets
[r_symndx
] |= 1;
1198 relocation
= sgot
->output_offset
+ off
;
1199 if (r_type
== R_68K_GOT8O
1200 || r_type
== R_68K_GOT16O
1201 || r_type
== R_68K_GOT32O
)
1202 relocation
-= sgotplt
->output_offset
;
1210 /* Relocation is to the entry for this symbol in the
1211 procedure linkage table. */
1213 /* Resolve a PLT32 reloc against a local symbol directly,
1214 without using the procedure linkage table. */
1218 if (h
->plt_offset
== (bfd_vma
) -1)
1220 /* We didn't make a PLT entry for this symbol. This
1221 happens when statically linking PIC code. */
1227 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1228 BFD_ASSERT (splt
!= NULL
);
1231 relocation
= (splt
->output_section
->vma
1232 + splt
->output_offset
1239 /* Relocation is the offset of the entry for this symbol in
1240 the procedure linkage table. */
1241 BFD_ASSERT (h
!= NULL
);
1243 if (h
->plt_offset
== (bfd_vma
) -1)
1245 /* We didn't make a PLT entry for this symbol. This
1246 happens when statically linking PIC code. */
1252 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1253 BFD_ASSERT (splt
!= NULL
);
1256 relocation
= h
->plt_offset
;
1266 && (input_section
->flags
& SEC_ALLOC
) != 0)
1268 Elf_Internal_Rela outrel
;
1270 /* When generating a shared object, these relocations
1271 are copied into the output file to be resolved at run
1278 name
= (elf_string_from_elf_section
1280 elf_elfheader (input_bfd
)->e_shstrndx
,
1281 elf_section_data (input_section
)->rel_hdr
.sh_name
));
1285 BFD_ASSERT (strncmp (name
, ".rela", 5) == 0
1286 && strcmp (bfd_get_section_name (input_bfd
,
1290 sreloc
= bfd_get_section_by_name (dynobj
, name
);
1291 BFD_ASSERT (sreloc
!= NULL
);
1294 outrel
.r_offset
= (rel
->r_offset
1295 + input_section
->output_section
->vma
1296 + input_section
->output_offset
);
1299 BFD_ASSERT (h
->dynindx
!= -1);
1300 outrel
.r_info
= ELF32_R_INFO (h
->dynindx
, r_type
);
1301 outrel
.r_addend
= rel
->r_addend
;
1305 if (r_type
== R_68K_32
)
1307 outrel
.r_info
= ELF32_R_INFO (0, R_68K_RELATIVE
);
1308 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1314 sym
= local_syms
+ r_symndx
;
1316 BFD_ASSERT (ELF_ST_TYPE (sym
->st_info
) == STT_SECTION
);
1318 sec
= local_sections
[r_symndx
];
1319 if (sec
!= NULL
&& bfd_is_abs_section (sec
))
1321 else if (sec
== NULL
|| sec
->owner
== NULL
)
1323 bfd_set_error (bfd_error_bad_value
);
1330 osec
= sec
->output_section
;
1331 indx
= elf_section_data (osec
)->dynindx
;
1336 outrel
.r_info
= ELF32_R_INFO (indx
, r_type
);
1337 outrel
.r_addend
= relocation
+ rel
->r_addend
;
1341 bfd_elf32_swap_reloca_out (output_bfd
, &outrel
,
1342 (((Elf32_External_Rela
*)
1344 + sreloc
->reloc_count
));
1345 ++sreloc
->reloc_count
;
1347 /* This reloc will be computed at runtime, so there's no
1348 need to do anything now. */
1358 r
= _bfd_final_link_relocate (howto
, input_bfd
, input_section
,
1359 contents
, rel
->r_offset
,
1360 relocation
, rel
->r_addend
);
1362 if (r
!= bfd_reloc_ok
)
1367 case bfd_reloc_outofrange
:
1369 case bfd_reloc_overflow
:
1374 name
= h
->root
.root
.string
;
1377 name
= elf_string_from_elf_section (input_bfd
,
1378 symtab_hdr
->sh_link
,
1383 name
= bfd_section_name (input_bfd
, sec
);
1385 if (!(info
->callbacks
->reloc_overflow
1386 (info
, name
, howto
->name
, (bfd_vma
) 0,
1387 input_bfd
, input_section
, rel
->r_offset
)))
1398 /* Finish up dynamic symbol handling. We set the contents of various
1399 dynamic sections here. */
1402 elf_m68k_finish_dynamic_symbol (output_bfd
, info
, h
, sym
)
1404 struct bfd_link_info
*info
;
1405 struct elf_link_hash_entry
*h
;
1406 Elf_Internal_Sym
*sym
;
1410 dynobj
= elf_hash_table (info
)->dynobj
;
1412 if (h
->plt_offset
!= (bfd_vma
) -1)
1419 Elf_Internal_Rela rela
;
1421 /* This symbol has an entry in the procedure linkage table. Set
1424 BFD_ASSERT (h
->dynindx
!= -1);
1426 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1427 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
1428 srela
= bfd_get_section_by_name (dynobj
, ".rela.plt");
1429 BFD_ASSERT (splt
!= NULL
&& sgot
!= NULL
&& srela
!= NULL
);
1431 /* Get the index in the procedure linkage table which
1432 corresponds to this symbol. This is the index of this symbol
1433 in all the symbols for which we are making plt entries. The
1434 first entry in the procedure linkage table is reserved. */
1435 plt_index
= h
->plt_offset
/ PLT_ENTRY_SIZE
- 1;
1437 /* Get the offset into the .got table of the entry that
1438 corresponds to this function. Each .got entry is 4 bytes.
1439 The first three are reserved. */
1440 got_offset
= (plt_index
+ 3) * 4;
1442 /* Fill in the entry in the procedure linkage table. */
1443 memcpy (splt
->contents
+ h
->plt_offset
, elf_m68k_plt_entry
,
1445 /* The offset is relative to the first extension word. */
1446 bfd_put_32 (output_bfd
,
1447 (sgot
->output_section
->vma
1448 + sgot
->output_offset
1450 - (splt
->output_section
->vma
1451 + h
->plt_offset
+ 2)),
1452 splt
->contents
+ h
->plt_offset
+ 4);
1454 bfd_put_32 (output_bfd
, plt_index
* sizeof (Elf32_External_Rela
),
1455 splt
->contents
+ h
->plt_offset
+ 10);
1456 bfd_put_32 (output_bfd
, - (h
->plt_offset
+ 16),
1457 splt
->contents
+ h
->plt_offset
+ 16);
1459 /* Fill in the entry in the global offset table. */
1460 bfd_put_32 (output_bfd
,
1461 (splt
->output_section
->vma
1462 + splt
->output_offset
1465 sgot
->contents
+ got_offset
);
1467 /* Fill in the entry in the .rela.plt section. */
1468 rela
.r_offset
= (sgot
->output_section
->vma
1469 + sgot
->output_offset
1471 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_JMP_SLOT
);
1473 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1474 ((Elf32_External_Rela
*) srela
->contents
1477 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_DEF_REGULAR
) == 0)
1479 /* Mark the symbol as undefined, rather than as defined in
1480 the .plt section. Leave the value alone. */
1481 sym
->st_shndx
= SHN_UNDEF
;
1485 if (h
->got_offset
!= (bfd_vma
) -1)
1489 Elf_Internal_Rela rela
;
1491 /* This symbol has an entry in the global offset table. Set it
1494 BFD_ASSERT (h
->dynindx
!= -1);
1496 sgot
= bfd_get_section_by_name (dynobj
, ".got");
1497 srela
= bfd_get_section_by_name (dynobj
, ".rela.got");
1498 BFD_ASSERT (sgot
!= NULL
&& srela
!= NULL
);
1500 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ h
->got_offset
);
1502 rela
.r_offset
= (sgot
->output_section
->vma
1503 + sgot
->output_offset
1505 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_GLOB_DAT
);
1507 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1508 ((Elf32_External_Rela
*) srela
->contents
1509 + srela
->reloc_count
));
1510 ++srela
->reloc_count
;
1513 if ((h
->elf_link_hash_flags
& ELF_LINK_HASH_NEEDS_COPY
) != 0)
1516 Elf_Internal_Rela rela
;
1518 /* This symbol needs a copy reloc. Set it up. */
1520 BFD_ASSERT (h
->dynindx
!= -1
1521 && (h
->root
.type
== bfd_link_hash_defined
1522 || h
->root
.type
== bfd_link_hash_defweak
));
1524 s
= bfd_get_section_by_name (h
->root
.u
.def
.section
->owner
,
1526 BFD_ASSERT (s
!= NULL
);
1528 rela
.r_offset
= (h
->root
.u
.def
.value
1529 + h
->root
.u
.def
.section
->output_section
->vma
1530 + h
->root
.u
.def
.section
->output_offset
);
1531 rela
.r_info
= ELF32_R_INFO (h
->dynindx
, R_68K_COPY
);
1533 bfd_elf32_swap_reloca_out (output_bfd
, &rela
,
1534 ((Elf32_External_Rela
*) s
->contents
1539 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
1540 if (strcmp (h
->root
.root
.string
, "_DYNAMIC") == 0
1541 || strcmp (h
->root
.root
.string
, "_GLOBAL_OFFSET_TABLE_") == 0)
1542 sym
->st_shndx
= SHN_ABS
;
1547 /* Finish up the dynamic sections. */
1550 elf_m68k_finish_dynamic_sections (output_bfd
, info
)
1552 struct bfd_link_info
*info
;
1558 dynobj
= elf_hash_table (info
)->dynobj
;
1560 sgot
= bfd_get_section_by_name (dynobj
, ".got.plt");
1561 BFD_ASSERT (sgot
!= NULL
);
1562 sdyn
= bfd_get_section_by_name (dynobj
, ".dynamic");
1564 if (elf_hash_table (info
)->dynamic_sections_created
)
1567 Elf32_External_Dyn
*dyncon
, *dynconend
;
1569 splt
= bfd_get_section_by_name (dynobj
, ".plt");
1570 BFD_ASSERT (splt
!= NULL
&& sdyn
!= NULL
);
1572 dyncon
= (Elf32_External_Dyn
*) sdyn
->contents
;
1573 dynconend
= (Elf32_External_Dyn
*) (sdyn
->contents
+ sdyn
->_raw_size
);
1574 for (; dyncon
< dynconend
; dyncon
++)
1576 Elf_Internal_Dyn dyn
;
1580 bfd_elf32_swap_dyn_in (dynobj
, dyncon
, &dyn
);
1593 s
= bfd_get_section_by_name (output_bfd
, name
);
1594 BFD_ASSERT (s
!= NULL
);
1595 dyn
.d_un
.d_ptr
= s
->vma
;
1596 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1600 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
1601 BFD_ASSERT (s
!= NULL
);
1602 if (s
->_cooked_size
!= 0)
1603 dyn
.d_un
.d_val
= s
->_cooked_size
;
1605 dyn
.d_un
.d_val
= s
->_raw_size
;
1606 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1610 /* My reading of the SVR4 ABI indicates that the
1611 procedure linkage table relocs (DT_JMPREL) should be
1612 included in the overall relocs (DT_RELA). This is
1613 what Solaris does. However, UnixWare can not handle
1614 that case. Therefore, we override the DT_RELASZ entry
1615 here to make it not include the JMPREL relocs. Since
1616 the linker script arranges for .rela.plt to follow all
1617 other relocation sections, we don't have to worry
1618 about changing the DT_RELA entry. */
1619 /* FIXME: This comment is from elf32-i386.c, what about
1620 the SVR4/m68k implementations? */
1621 s
= bfd_get_section_by_name (output_bfd
, ".rela.plt");
1624 if (s
->_cooked_size
!= 0)
1625 dyn
.d_un
.d_val
-= s
->_cooked_size
;
1627 dyn
.d_un
.d_val
-= s
->_raw_size
;
1629 bfd_elf32_swap_dyn_out (output_bfd
, &dyn
, dyncon
);
1634 /* Fill in the first entry in the procedure linkage table. */
1635 if (splt
->_raw_size
> 0)
1637 memcpy (splt
->contents
, elf_m68k_plt0_entry
, PLT_ENTRY_SIZE
);
1638 bfd_put_32 (output_bfd
,
1639 (sgot
->output_section
->vma
1640 + sgot
->output_offset
+ 4
1641 - (splt
->output_section
->vma
+ 2)),
1642 splt
->contents
+ 4);
1643 bfd_put_32 (output_bfd
,
1644 (sgot
->output_section
->vma
1645 + sgot
->output_offset
+ 8
1646 - (splt
->output_section
->vma
+ 10)),
1647 splt
->contents
+ 12);
1650 elf_section_data (splt
->output_section
)->this_hdr
.sh_entsize
1654 /* Fill in the first three entries in the global offset table. */
1655 if (sgot
->_raw_size
> 0)
1658 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
);
1660 bfd_put_32 (output_bfd
,
1661 sdyn
->output_section
->vma
+ sdyn
->output_offset
,
1663 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 4);
1664 bfd_put_32 (output_bfd
, (bfd_vma
) 0, sgot
->contents
+ 8);
1667 elf_section_data (sgot
->output_section
)->this_hdr
.sh_entsize
= 4;
1672 #define TARGET_BIG_SYM bfd_elf32_m68k_vec
1673 #define TARGET_BIG_NAME "elf32-m68k"
1674 #define ELF_MACHINE_CODE EM_68K
1675 #define ELF_MAXPAGESIZE 0x2000
1676 #define elf_backend_create_dynamic_sections \
1677 elf_m68k_create_dynamic_sections
1678 #define elf_backend_check_relocs elf_m68k_check_relocs
1679 #define elf_backend_adjust_dynamic_symbol \
1680 elf_m68k_adjust_dynamic_symbol
1681 #define elf_backend_size_dynamic_sections \
1682 elf_m68k_size_dynamic_sections
1683 #define elf_backend_relocate_section elf_m68k_relocate_section
1684 #define elf_backend_finish_dynamic_symbol \
1685 elf_m68k_finish_dynamic_symbol
1686 #define elf_backend_finish_dynamic_sections \
1687 elf_m68k_finish_dynamic_sections
1689 #include "elf32-target.h"