1 /* Intel 80386/80486-specific 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 CONST struct reloc_howto_struct *elf_i386_reloc_type_lookup
27 PARAMS ((bfd *, bfd_reloc_code_real_type));
28 static void elf_i386_info_to_howto
29 PARAMS ((bfd *, arelent *, Elf32_Internal_Rela *));
30 static void elf_i386_info_to_howto_rel
31 PARAMS ((bfd *, arelent *, Elf32_Internal_Rel *));
32 static boolean elf_i386_create_dynamic_sections
33 PARAMS ((bfd *, struct bfd_link_info *));
34 static boolean elf_i386_adjust_dynamic_symbol
35 PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *));
36 static boolean elf_i386_allocate_dynamic_section
37 PARAMS ((bfd *, const char *));
38 static boolean elf_i386_size_dynamic_sections
39 PARAMS ((bfd *, struct bfd_link_info *));
40 static boolean elf_i386_relocate_section
41 PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,
42 Elf_Internal_Rela *, Elf_Internal_Sym *, asection **));
43 static boolean elf_i386_finish_dynamic_symbol
44 PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *,
46 static boolean elf_i386_finish_dynamic_sections
47 PARAMS ((bfd *, struct bfd_link_info *));
49 #define USE_REL 1 /* 386 uses REL relocations instead of RELA */
68 static CONST char *CONST reloc_type_names[] =
84 static reloc_howto_type elf_howto_table[]=
86 HOWTO(R_386_NONE, 0,0, 0,false,0,complain_overflow_bitfield, bfd_elf_generic_reloc,"R_386_NONE", true,0x00000000,0x00000000,false),
87 HOWTO(R_386_32, 0,2,32,false,0,complain_overflow_bitfield, bfd_elf_generic_reloc,"R_386_32", true,0xffffffff,0xffffffff,false),
88 HOWTO(R_386_PC32, 0,2,32,true, 0,complain_overflow_bitfield, bfd_elf_generic_reloc,"R_386_PC32", true,0xffffffff,0xffffffff,true),
89 HOWTO(R_386_GOT32, 0,2,32,false,0,complain_overflow_bitfield, bfd_elf_generic_reloc,"R_386_GOT32", true,0xffffffff,0xffffffff,false),
90 HOWTO(R_386_PLT32, 0,2,32,false,0,complain_overflow_bitfield, bfd_elf_generic_reloc,"R_386_PLT32", true,0xffffffff,0xffffffff,false),
91 HOWTO(R_386_COPY, 0,2,32,false,0,complain_overflow_bitfield, bfd_elf_generic_reloc,"R_386_COPY", true,0xffffffff,0xffffffff,false),
92 HOWTO(R_386_GLOB_DAT, 0,2,32,false,0,complain_overflow_bitfield, bfd_elf_generic_reloc,"R_386_GLOB_DAT", true,0xffffffff,0xffffffff,false),
93 HOWTO(R_386_JUMP_SLOT, 0,2,32,false,0,complain_overflow_bitfield, bfd_elf_generic_reloc,"R_386_JUMP_SLOT",true,0xffffffff,0xffffffff,false),
94 HOWTO(R_386_RELATIVE, 0,2,32,false,0,complain_overflow_bitfield, bfd_elf_generic_reloc,"R_386_RELATIVE", true,0xffffffff,0xffffffff,false),
95 HOWTO(R_386_GOTOFF, 0,2,32,false,0,complain_overflow_bitfield, bfd_elf_generic_reloc,"R_386_GOTOFF", true,0xffffffff,0xffffffff,false),
96 HOWTO(R_386_GOTPC, 0,2,32,false,0,complain_overflow_bitfield, bfd_elf_generic_reloc,"R_386_GOTPC", true,0xffffffff,0xffffffff,false),
99 #ifdef DEBUG_GEN_RELOC
100 #define TRACE(str) fprintf (stderr, "i386 bfd reloc lookup %d (%s)\n", code, str)
105 static CONST struct reloc_howto_struct *
106 elf_i386_reloc_type_lookup (abfd, code)
108 bfd_reloc_code_real_type code;
113 TRACE ("BFD_RELOC_NONE");
114 return &elf_howto_table[ (int)R_386_NONE ];
117 TRACE ("BFD_RELOC_32");
118 return &elf_howto_table[ (int)R_386_32 ];
120 case BFD_RELOC_32_PCREL:
121 TRACE ("BFD_RELOC_PC32");
122 return &elf_howto_table[ (int)R_386_PC32 ];
124 case BFD_RELOC_386_GOT32:
125 TRACE ("BFD_RELOC_386_GOT32");
126 return &elf_howto_table[ (int)R_386_GOT32 ];
128 case BFD_RELOC_386_PLT32:
129 TRACE ("BFD_RELOC_386_PLT32");
130 return &elf_howto_table[ (int)R_386_PLT32 ];
132 case BFD_RELOC_386_COPY:
133 TRACE ("BFD_RELOC_386_COPY");
134 return &elf_howto_table[ (int)R_386_COPY ];
136 case BFD_RELOC_386_GLOB_DAT:
137 TRACE ("BFD_RELOC_386_GLOB_DAT");
138 return &elf_howto_table[ (int)R_386_GLOB_DAT ];
140 case BFD_RELOC_386_JUMP_SLOT:
141 TRACE ("BFD_RELOC_386_JUMP_SLOT");
142 return &elf_howto_table[ (int)R_386_JUMP_SLOT ];
144 case BFD_RELOC_386_RELATIVE:
145 TRACE ("BFD_RELOC_386_RELATIVE");
146 return &elf_howto_table[ (int)R_386_RELATIVE ];
148 case BFD_RELOC_386_GOTOFF:
149 TRACE ("BFD_RELOC_386_GOTOFF");
150 return &elf_howto_table[ (int)R_386_GOTOFF ];
152 case BFD_RELOC_386_GOTPC:
153 TRACE ("BFD_RELOC_386_GOTPC");
154 return &elf_howto_table[ (int)R_386_GOTPC ];
165 elf_i386_info_to_howto (abfd, cache_ptr, dst)
168 Elf32_Internal_Rela *dst;
170 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_386_max);
172 cache_ptr->howto = &elf_howto_table[ELF32_R_TYPE(dst->r_info)];
176 elf_i386_info_to_howto_rel (abfd, cache_ptr, dst)
179 Elf32_Internal_Rel *dst;
181 BFD_ASSERT (ELF32_R_TYPE(dst->r_info) < (unsigned int) R_386_max);
183 cache_ptr->howto = &elf_howto_table[ELF32_R_TYPE(dst->r_info)];
186 /* Functions for the i386 ELF linker. */
188 /* The name of the dynamic interpreter. This is put in the .interp
191 #define ELF_DYNAMIC_INTERPRETER "/usr/lib/libc.so.1"
193 /* The size in bytes of an entry in the procedure linkage table. */
195 #define PLT_ENTRY_SIZE 16
197 /* The first entry in an absolute procedure linkage table looks like
198 this. See the SVR4 ABI i386 supplement to see how this works. */
200 static bfd_byte elf_i386_plt0_entry[PLT_ENTRY_SIZE] =
202 0xff, 0x35, /* pushl contents of address */
203 0, 0, 0, 0, /* replaced with address of .got + 4. */
204 0xff, 0x25, /* jmp indirect */
205 0, 0, 0, 0, /* replaced with address of .got + 8. */
206 0, 0, 0, 0 /* pad out to 16 bytes. */
209 /* Subsequent entries in an absolute procedure linkage table look like
212 static bfd_byte elf_i386_plt_entry[PLT_ENTRY_SIZE] =
214 0xff, 0x25, /* jmp indirect */
215 0, 0, 0, 0, /* replaced with address of this symbol in .got. */
216 0x68, /* pushl immediate */
217 0, 0, 0, 0, /* replaced with offset into relocation table. */
218 0xe9, /* jmp relative */
219 0, 0, 0, 0 /* replaced with offset to start of .plt. */
222 /* Create dynamic sections when linking against a dynamic object. */
225 elf_i386_create_dynamic_sections (abfd, info)
227 struct bfd_link_info *info;
230 register asection *s;
231 struct elf_link_hash_entry *h;
233 /* We need to create .plt, .rel.plt, .got, .dynbss, and .rel.bss
236 flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
238 s = bfd_make_section (abfd, ".plt");
240 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY | SEC_CODE)
241 || ! bfd_set_section_alignment (abfd, s, 2))
244 s = bfd_make_section (abfd, ".rel.plt");
246 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
247 || ! bfd_set_section_alignment (abfd, s, 2))
250 s = bfd_make_section (abfd, ".got");
252 || ! bfd_set_section_flags (abfd, s, flags)
253 || ! bfd_set_section_alignment (abfd, s, 2))
256 /* Define the symbol _GLOBAL_OFFSET_TABLE_ at the start of the .got
257 section. We don't do this in the linker script because we don't
258 want to define the symbol if we are not creating a global offset
261 if (! (_bfd_generic_link_add_one_symbol
262 (info, abfd, "_GLOBAL_OFFSET_TABLE_", BSF_GLOBAL, s, (bfd_vma) 0,
263 (const char *) NULL, false, get_elf_backend_data (abfd)->collect,
264 (struct bfd_link_hash_entry **) &h)))
266 h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
268 /* The first three global offset table entries are reserved. */
269 s->_raw_size += 3 * 4;
271 /* The .dynbss section is a place to put symbols which are defined
272 by dynamic objects, are referenced by regular objects, and are
273 not functions. We must allocate space for them in the process
274 image and use a R_386_COPY reloc to tell the dynamic linker to
275 initialize them at run time. The linker script puts the .dynbss
276 section into the .bss section of the final image. */
277 s = bfd_make_section (abfd, ".dynbss");
279 || ! bfd_set_section_flags (abfd, s, SEC_ALLOC))
282 /* The .rel.bss section holds copy relocs. This section is not
283 normally needed. We need to create it here, though, so that the
284 linker will map it to an output section. If it turns out not to
285 be needed, we can discard it later. */
286 s = bfd_make_section (abfd, ".rel.bss");
288 || ! bfd_set_section_flags (abfd, s, flags | SEC_READONLY)
289 || ! bfd_set_section_alignment (abfd, s, 2))
295 /* Adjust a symbol defined by a dynamic object and referenced by a
296 regular object. The current definition is in some section of the
297 dynamic object, but we're not including those sections. We have to
298 change the definition to something the rest of the link can
302 elf_i386_adjust_dynamic_symbol (info, h)
303 struct bfd_link_info *info;
304 struct elf_link_hash_entry *h;
308 unsigned int power_of_two;
311 dynobj = elf_hash_table (info)->dynobj;
313 /* Make sure we know what is going on here. */
314 BFD_ASSERT (dynobj != NULL
315 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) != 0
316 && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) != 0
317 && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
318 && h->root.type == bfd_link_hash_defined
319 && (bfd_get_flavour (h->root.u.def.section->owner)
320 == bfd_target_elf_flavour)
321 && (elf_elfheader (h->root.u.def.section->owner)->e_type
323 && h->root.u.def.section->output_section == NULL);
325 /* If this is a function, put it in the procedure linkage table. We
326 will fill in the contents of the procedure linkage table later,
327 when we know the address of the .got section. */
328 if (h->type == STT_FUNC)
330 s = bfd_get_section_by_name (dynobj, ".plt");
331 BFD_ASSERT (s != NULL);
333 /* If this is the first .plt entry, make room for the special
335 if (s->_raw_size == 0)
336 s->_raw_size += PLT_ENTRY_SIZE;
338 /* Set the symbol to this location in the .plt. */
339 h->root.u.def.section = s;
340 h->root.u.def.value = s->_raw_size;
342 /* Make room for this entry. */
343 s->_raw_size += PLT_ENTRY_SIZE;
345 /* We also need to make an entry in the .got section. */
347 s = bfd_get_section_by_name (dynobj, ".got");
348 BFD_ASSERT (s != NULL);
351 /* We also need to make an entry in the .rel.plt section. */
353 s = bfd_get_section_by_name (dynobj, ".rel.plt");
354 BFD_ASSERT (s != NULL);
355 s->_raw_size += sizeof (Elf32_External_Rel);
360 /* If this is a weak symbol, and there is a real definition, the
361 processor independent code will have arranged for us to see the
362 real definition first, and we can just use the same value. */
363 if (h->weakdef != NULL)
365 BFD_ASSERT (h->weakdef->root.type == bfd_link_hash_defined);
366 h->root.u.def.section = h->weakdef->root.u.def.section;
367 h->root.u.def.value = h->weakdef->root.u.def.value;
368 h->align = (bfd_size_type) -1;
372 /* This is a reference to a symbol defined by a dynamic object which
373 is not a function. We must allocate it in our .dynbss section,
374 which will become part of the .bss section of the executable.
375 There will be an entry for this symbol in the .dynsym section.
376 The dynamic object will contain position independent code, so all
377 references from the dynamic object to this symbol will go through
378 the global offset table. The dynamic linker will use the .dynsym
379 entry to determine the address it must put in the global offset
380 table, so both the dynamic object and the regular object will
381 refer to the same memory location for the variable. */
383 s = bfd_get_section_by_name (dynobj, ".dynbss");
384 BFD_ASSERT (s != NULL);
386 /* If the symbol is currently defined in the .bss section of the
387 dynamic object, then it is OK to simply initialize it to zero.
388 If the symbol is in some other section, we must generate a
389 R_386_COPY reloc to tell the dynamic linker to copy the initial
390 value out of the dynamic object and into the runtime process
391 image. We need to remember the offset into the .rel.bss section
392 we are going to use, and we coopt the align field for this
393 purpose (the align field is only used for common symbols, and
394 these symbols are always defined). It would be cleaner to use a
395 new field, but that would waste memory. */
396 if ((h->root.u.def.section->flags & SEC_LOAD) == 0)
397 h->align = (bfd_size_type) -1;
402 srel = bfd_get_section_by_name (dynobj, ".rel.bss");
403 BFD_ASSERT (srel != NULL);
404 h->align = srel->_raw_size;
405 srel->_raw_size += sizeof (Elf32_External_Rel);
408 /* We need to figure out the alignment required for this symbol. I
409 have no idea how ELF linkers handle this. */
439 /* Apply the required alignment. */
440 s->_raw_size = BFD_ALIGN (s->_raw_size, align);
441 if (power_of_two > bfd_get_section_alignment (dynobj, s))
443 if (! bfd_set_section_alignment (dynobj, s, power_of_two))
447 /* Define the symbol as being at this point in the section. */
448 h->root.u.def.section = s;
449 h->root.u.def.value = s->_raw_size;
451 /* Increment the section size to make room for the symbol. */
452 s->_raw_size += h->size;
457 /* Allocate contents for a section. */
459 static INLINE boolean
460 elf_i386_allocate_dynamic_section (dynobj, name)
464 register asection *s;
466 s = bfd_get_section_by_name (dynobj, name);
467 BFD_ASSERT (s != NULL);
468 s->contents = (bfd_byte *) bfd_alloc (dynobj, s->_raw_size);
469 if (s->contents == NULL && s->_raw_size != 0)
471 bfd_set_error (bfd_error_no_memory);
477 /* Set the sizes of the dynamic sections. */
480 elf_i386_size_dynamic_sections (output_bfd, info)
482 struct bfd_link_info *info;
487 dynobj = elf_hash_table (info)->dynobj;
488 BFD_ASSERT (dynobj != NULL);
490 /* Set the contents of the .interp section to the interpreter. */
491 s = bfd_get_section_by_name (dynobj, ".interp");
492 BFD_ASSERT (s != NULL);
493 s->_raw_size = sizeof ELF_DYNAMIC_INTERPRETER;
494 s->contents = (unsigned char *) ELF_DYNAMIC_INTERPRETER;
496 /* The adjust_dynamic_symbol entry point has determined the sizes of
497 the various dynamic sections. Allocate some memory for them to
499 if (! elf_i386_allocate_dynamic_section (dynobj, ".plt")
500 || ! elf_i386_allocate_dynamic_section (dynobj, ".rel.plt")
501 || ! elf_i386_allocate_dynamic_section (dynobj, ".got")
502 || ! elf_i386_allocate_dynamic_section (dynobj, ".rel.bss"))
505 /* Add some entries to the .dynamic section. We fill in the values
506 later, in elf_i386_finish_dynamic_sections, but we must add the
507 entries now so that we get the correct size for the .dynamic
509 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTGOT, 0))
512 s = bfd_get_section_by_name (dynobj, ".plt");
513 BFD_ASSERT (s != NULL);
514 if (s->_raw_size != 0)
516 if (! bfd_elf32_add_dynamic_entry (info, DT_PLTRELSZ, 0)
517 || ! bfd_elf32_add_dynamic_entry (info, DT_PLTREL, DT_REL)
518 || ! bfd_elf32_add_dynamic_entry (info, DT_JMPREL, 0))
522 /* If we didn't need the .rel.bss section, then discard it from the
523 output file. This is a hack. We don't bother to do it for the
524 other sections because they normally are needed. */
525 s = bfd_get_section_by_name (dynobj, ".rel.bss");
526 BFD_ASSERT (s != NULL);
527 if (s->_raw_size == 0)
531 for (spp = &s->output_section->owner->sections;
532 *spp != s->output_section;
535 *spp = s->output_section->next;
536 --s->output_section->owner->section_count;
540 if (! bfd_elf32_add_dynamic_entry (info, DT_REL, 0)
541 || ! bfd_elf32_add_dynamic_entry (info, DT_RELSZ, 0)
542 || ! bfd_elf32_add_dynamic_entry (info, DT_RELENT,
543 sizeof (Elf32_External_Rel)))
550 /* Relocate an i386 ELF section. */
553 elf_i386_relocate_section (output_bfd, info, input_bfd, input_section,
554 contents, relocs, local_syms, local_sections)
556 struct bfd_link_info *info;
558 asection *input_section;
560 Elf_Internal_Rela *relocs;
561 Elf_Internal_Sym *local_syms;
562 asection **local_sections;
564 Elf_Internal_Shdr *symtab_hdr;
565 Elf_Internal_Rela *rel;
566 Elf_Internal_Rela *relend;
568 symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
571 relend = relocs + input_section->reloc_count;
572 for (; rel < relend; rel++)
575 const reloc_howto_type *howto;
577 struct elf_link_hash_entry *h;
578 Elf_Internal_Sym *sym;
581 bfd_reloc_status_type r;
583 r_type = ELF32_R_TYPE (rel->r_info);
584 if (r_type < 0 || r_type >= (int) R_386_max)
586 bfd_set_error (bfd_error_bad_value);
589 howto = elf_howto_table + r_type;
591 r_symndx = ELF32_R_SYM (rel->r_info);
593 if (info->relocateable)
595 /* This is a relocateable link. We don't have to change
596 anything, unless the reloc is against a section symbol,
597 in which case we have to adjust according to where the
598 section symbol winds up in the output section. */
599 if (r_symndx < symtab_hdr->sh_info)
601 sym = local_syms + r_symndx;
602 if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
606 sec = local_sections[r_symndx];
607 val = bfd_get_32 (input_bfd, contents + rel->r_offset);
608 val += sec->output_offset + sym->st_value;
609 bfd_put_32 (input_bfd, val, contents + rel->r_offset);
616 /* This is a final link. */
620 if (r_symndx < symtab_hdr->sh_info)
622 sym = local_syms + r_symndx;
623 sec = local_sections[r_symndx];
624 relocation = (sec->output_section->vma
632 indx = r_symndx - symtab_hdr->sh_info;
633 h = elf_sym_hashes (input_bfd)[indx];
634 if (h->root.type == bfd_link_hash_defined)
636 sec = h->root.u.def.section;
637 relocation = (h->root.u.def.value
638 + sec->output_section->vma
639 + sec->output_offset);
641 else if (h->root.type == bfd_link_hash_weak)
645 if (! ((*info->callbacks->undefined_symbol)
646 (info, h->root.root.string, input_bfd,
647 input_section, rel->r_offset)))
653 r = _bfd_final_link_relocate (howto, input_bfd, input_section,
654 contents, rel->r_offset,
655 relocation, (bfd_vma) 0);
657 if (r != bfd_reloc_ok)
662 case bfd_reloc_outofrange:
664 case bfd_reloc_overflow:
669 name = h->root.root.string;
672 name = elf_string_from_elf_section (input_bfd,
678 name = bfd_section_name (input_bfd, sec);
680 if (! ((*info->callbacks->reloc_overflow)
681 (info, name, howto->name, (bfd_vma) 0,
682 input_bfd, input_section, rel->r_offset)))
693 /* Finish up dynamic symbol handling. We set the contents of various
694 dynamic sections here. */
697 elf_i386_finish_dynamic_symbol (output_bfd, info, h, sym)
699 struct bfd_link_info *info;
700 struct elf_link_hash_entry *h;
701 Elf_Internal_Sym *sym;
703 /* If this symbol is not defined by a dynamic object, or is not
704 referenced by a regular object, ignore it. */
705 if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0
706 || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
707 || (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
709 /* Mark _DYNAMIC and _GLOBAL_OFFSET_TABLE_ as absolute. */
710 if (strcmp (h->root.root.string, "_DYNAMIC") == 0
711 || strcmp (h->root.root.string, "_GLOBAL_OFFSET_TABLE_") == 0)
712 sym->st_shndx = SHN_ABS;
716 BFD_ASSERT (h->root.type == bfd_link_hash_defined);
717 BFD_ASSERT (h->dynindx != -1);
719 if (h->type == STT_FUNC)
726 Elf_Internal_Rel rel;
728 splt = h->root.u.def.section;
729 BFD_ASSERT (strcmp (bfd_get_section_name (splt->owner, splt), ".plt")
731 sgot = bfd_get_section_by_name (splt->owner, ".got");
732 BFD_ASSERT (sgot != NULL);
733 srel = bfd_get_section_by_name (splt->owner, ".rel.plt");
734 BFD_ASSERT (srel != NULL);
736 /* FIXME: This only handles an absolute procedure linkage table.
737 When producing a dynamic object, we need to generate a
738 position independent procedure linkage table. */
740 /* Get the index in the procedure linkage table which
741 corresponds to this symbol. This is the index of this symbol
742 in all the symbols for which we are making plt entries. The
743 first entry in the procedure linkage table is reserved. */
744 plt_index = h->root.u.def.value / PLT_ENTRY_SIZE - 1;
746 /* Get the offset into the .got table of the entry that
747 corresponds to this function. Each .got entry is 4 bytes.
748 The first three are reserved. */
749 got_offset = (plt_index + 3) * 4;
751 /* Fill in the entry in the procedure linkage table. */
752 memcpy (splt->contents + h->root.u.def.value, elf_i386_plt_entry,
754 bfd_put_32 (output_bfd,
755 (sgot->output_section->vma
756 + sgot->output_offset
758 splt->contents + h->root.u.def.value + 2);
759 bfd_put_32 (output_bfd, plt_index * sizeof (Elf32_External_Rel),
760 splt->contents + h->root.u.def.value + 7);
761 bfd_put_32 (output_bfd, - (h->root.u.def.value + PLT_ENTRY_SIZE),
762 splt->contents + h->root.u.def.value + 12);
764 /* Fill in the entry in the global offset table. */
765 bfd_put_32 (output_bfd,
766 (splt->output_section->vma
767 + splt->output_offset
768 + h->root.u.def.value
770 sgot->contents + got_offset);
772 /* Fill in the entry in the .rel.plt section. */
773 rel.r_offset = (sgot->output_section->vma
774 + sgot->output_offset
776 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_JUMP_SLOT);
777 bfd_elf32_swap_reloc_out (output_bfd, &rel,
778 ((Elf32_External_Rel *) srel->contents
781 /* Mark the symbol as undefined, rather than as defined in the
782 .plt section. Leave the value alone. */
783 sym->st_shndx = SHN_UNDEF;
787 /* This is not a function. We have already allocated memory for
788 it in the .bss section (via .dynbss). All we have to do here
789 is create a COPY reloc if required. */
790 if (h->align != (bfd_size_type) -1)
793 Elf_Internal_Rel rel;
795 s = bfd_get_section_by_name (h->root.u.def.section->owner,
797 BFD_ASSERT (s != NULL);
799 rel.r_offset = (h->root.u.def.value
800 + h->root.u.def.section->output_section->vma
801 + h->root.u.def.section->output_offset);
802 rel.r_info = ELF32_R_INFO (h->dynindx, R_386_COPY);
803 bfd_elf32_swap_reloc_out (output_bfd, &rel,
804 ((Elf32_External_Rel *)
805 (s->contents + h->align)));
812 /* Finish up the dynamic sections. */
815 elf_i386_finish_dynamic_sections (output_bfd, info)
817 struct bfd_link_info *info;
822 Elf32_External_Dyn *dyncon, *dynconend;
824 splt = bfd_get_section_by_name (elf_hash_table (info)->dynobj, ".plt");
825 sgot = bfd_get_section_by_name (elf_hash_table (info)->dynobj, ".got");
826 sdyn = bfd_get_section_by_name (elf_hash_table (info)->dynobj, ".dynamic");
827 BFD_ASSERT (splt != NULL && sgot != NULL && sdyn != NULL);
829 dyncon = (Elf32_External_Dyn *) sdyn->contents;
830 dynconend = (Elf32_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
831 for (; dyncon < dynconend; dyncon++)
833 Elf_Internal_Dyn dyn;
837 bfd_elf32_swap_dyn_in (elf_hash_table (info)->dynobj, dyncon, &dyn);
839 /* My reading of the SVR4 ABI indicates that the procedure
840 linkage table relocs (DT_JMPREL) should be included in the
841 overall relocs (DT_REL). This is what Solaris does.
842 However, UnixWare can not handle that case. Therefore, we
843 override the DT_REL and DT_RELSZ entries here to make them
844 not include the JMPREL relocs. */
848 case DT_PLTGOT: name = ".got"; size = false; break;
849 case DT_PLTRELSZ: name = ".rel.plt"; size = true; break;
850 case DT_JMPREL: name = ".rel.plt"; size = false; break;
851 case DT_REL: name = ".rel.bss"; size = false; break;
852 case DT_RELSZ: name = ".rel.bss"; size = true; break;
853 default: name = NULL; size = false; break;
860 s = bfd_get_section_by_name (output_bfd, name);
861 BFD_ASSERT (s != NULL);
863 dyn.d_un.d_ptr = s->vma;
866 if (s->_cooked_size != 0)
867 dyn.d_un.d_val = s->_cooked_size;
869 dyn.d_un.d_val = s->_raw_size;
871 bfd_elf32_swap_dyn_out (output_bfd, &dyn, dyncon);
875 /* Fill in the first entry in the procedure linkage table. */
876 if (splt->_raw_size > 0)
878 memcpy (splt->contents, elf_i386_plt0_entry, PLT_ENTRY_SIZE);
879 bfd_put_32 (output_bfd,
880 sgot->output_section->vma + sgot->output_offset + 4,
882 bfd_put_32 (output_bfd,
883 sgot->output_section->vma + sgot->output_offset + 8,
887 /* Fill in the first three entries in the global offset table. */
888 if (sgot->_raw_size > 0)
890 bfd_put_32 (output_bfd,
891 sdyn->output_section->vma + sdyn->output_offset,
893 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 4);
894 bfd_put_32 (output_bfd, (bfd_vma) 0, sgot->contents + 8);
897 elf_section_data (sgot->output_section)->this_hdr.sh_entsize = 4;
899 /* UnixWare sets the entsize of .plt to 4, although that doesn't
900 really seem like the right value. */
901 elf_section_data (splt->output_section)->this_hdr.sh_entsize = 4;
906 #define TARGET_LITTLE_SYM bfd_elf32_i386_vec
907 #define TARGET_LITTLE_NAME "elf32-i386"
908 #define ELF_ARCH bfd_arch_i386
909 #define ELF_MACHINE_CODE EM_386
910 #define elf_info_to_howto elf_i386_info_to_howto
911 #define elf_info_to_howto_rel elf_i386_info_to_howto_rel
912 #define bfd_elf32_bfd_reloc_type_lookup elf_i386_reloc_type_lookup
913 #define ELF_MAXPAGESIZE 0x1000
914 #define elf_backend_create_dynamic_sections \
915 elf_i386_create_dynamic_sections
916 #define elf_backend_adjust_dynamic_symbol \
917 elf_i386_adjust_dynamic_symbol
918 #define elf_backend_size_dynamic_sections \
919 elf_i386_size_dynamic_sections
920 #define elf_backend_relocate_section elf_i386_relocate_section
921 #define elf_backend_finish_dynamic_symbol \
922 elf_i386_finish_dynamic_symbol
923 #define elf_backend_finish_dynamic_sections \
924 elf_i386_finish_dynamic_sections
926 #include "elf32-target.h"