This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Bugsquatting for the sledgehammer
- To: <patches at x86-64 dot org>, <binutils at sources dot redhat dot com>
- Subject: Bugsquatting for the sledgehammer
- From: Bo Thorsen <bo at suse dot de>
- Date: Wed, 14 Feb 2001 11:43:09 +0100 (CET)
This finally fixes dynamic linking to the point where the file looks good.
I'm sure there will still be bugs in the relocations, but this is a good
step forward.
2001-02-14 Bo Thorsen <bo@suse.de>
* elf64-x86-64.c: Small formatting fixes and rearrangements of code.
(elf64_86_64_size_info): Struct added to fix a problem
with the hashtable string entries.
(elf64_x86_64_adjust_dynamic_symbol): Add generation of .got.plt.
(elf64_x86_64_size_dynamic_sections): A FIXME removed.
(elf64_x86_64_size_dynamic_sections): Fix a dynamic entry and
remove the FIXME for this.
(elf64_x86_64_adjust_dynamic_symbol): Fix check for unneeded .plt
section. Also removed the FIXME for it.
(x86_64_elf_howto_table): Use bfd_elf_generic_reloc.
(ELF_DYNAMIC_INTERPRETER): Fix the name of the dynamic linker.
(elf64_x86_64_finish_dynamic_sections): Enable .got.plt writing.
Index: elf64-x86-64.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-x86-64.c,v
retrieving revision 1.6
diff -u -p -r1.6 elf64-x86-64.c
--- elf64-x86-64.c 2001/02/12 16:54:08 1.6
+++ elf64-x86-64.c 2001/02/14 10:35:43
@@ -36,22 +36,22 @@ Foundation, Inc., 59 Temple Place - Suit
name, partial_inplace, src_mask, dst_pack, pcrel_offset */
static reloc_howto_type x86_64_elf_howto_table[] =
{
- HOWTO(R_X86_64_NONE, 0,0, 0,false,0,complain_overflow_dont, 0, "R_X86_64_NONE", false,0x00000000,0x00000000,false),
- HOWTO(R_X86_64_64, 0,4,64,false,0,complain_overflow_bitfield,0, "R_X86_64_64", false,MINUS_ONE ,MINUS_ONE ,false),
- HOWTO(R_X86_64_PC32, 0,4,32,true ,0,complain_overflow_signed ,0, "R_X86_64_PC32", false,0xffffffff,0xffffffff,true),
- HOWTO(R_X86_64_GOT32, 0,4,32,false,0,complain_overflow_signed ,0, "R_X86_64_GOT32", false,0xffffffff,0xffffffff,false),
- HOWTO(R_X86_64_PLT32, 0,4,32,true ,0,complain_overflow_signed ,0, "R_X86_64_PLT32", false,0xffffffff,0xffffffff,true),
- HOWTO(R_X86_64_COPY, 0,4,32,false,0,complain_overflow_bitfield,0, "R_X86_64_COPY", false,0xffffffff,0xffffffff,false),
- HOWTO(R_X86_64_GLOB_DAT, 0,4,64,false,0,complain_overflow_bitfield,0,"R_X86_64_GLOB_DAT",false,MINUS_ONE ,MINUS_ONE ,false),
- HOWTO(R_X86_64_RELATIVE ,0,4,64,false,0,complain_overflow_bitfield,0,"R_X86_64_RELATIVE",false,MINUS_ONE ,MINUS_ONE ,false),
- HOWTO(R_X86_64_JUMP_SLOT,0,4,64,false,0,complain_overflow_bitfield,0,"R_X86_64_JUMP_SLOT",false,MINUS_ONE,MINUS_ONE ,false),
- HOWTO(R_X86_64_GOTPCREL, 0,4,32,true, 0,complain_overflow_signed ,0, "R_X86_64_GOTPCREL",false,0xffffffff,0xffffffff,true),
- HOWTO(R_X86_64_32, 0,4,32,false,0,complain_overflow_unsigned,0, "R_X86_64_32", false,0xffffffff,0xffffffff,false),
- HOWTO(R_X86_64_32S, 0,4,32,false,0,complain_overflow_signed, 0, "R_X86_64_32S", false,0xffffffff,0xffffffff,false),
- HOWTO(R_X86_64_16, 0,1,16,false,0,complain_overflow_bitfield,0, "R_X86_64_16", false,0xffff ,0xffff, false),
- HOWTO(R_X86_64_PC16, 0,1,16,true ,0,complain_overflow_bitfield,0, "R_X86_64_PC16", false,0xffff ,0xffff, true),
- HOWTO(R_X86_64_8, 0,0, 8,false,0,complain_overflow_signed ,0, "R_X86_64_8", false,0xff ,0xff, false),
- HOWTO(R_X86_64_PC8, 0,0, 8,true ,0,complain_overflow_signed ,0, "R_X86_64_PC8", false,0xff ,0xff, true),
+ HOWTO(R_X86_64_NONE, 0,0, 0,false,0,complain_overflow_dont, bfd_elf_generic_reloc, "R_X86_64_NONE", false,0x00000000,0x00000000,false),
+ HOWTO(R_X86_64_64, 0,4,64,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_X86_64_64", false,MINUS_ONE ,MINUS_ONE ,false),
+ HOWTO(R_X86_64_PC32, 0,4,32,true ,0,complain_overflow_signed ,bfd_elf_generic_reloc, "R_X86_64_PC32", false,0xffffffff,0xffffffff,true),
+ HOWTO(R_X86_64_GOT32, 0,4,32,false,0,complain_overflow_signed ,bfd_elf_generic_reloc, "R_X86_64_GOT32", false,0xffffffff,0xffffffff,false),
+ HOWTO(R_X86_64_PLT32, 0,4,32,true ,0,complain_overflow_signed ,bfd_elf_generic_reloc, "R_X86_64_PLT32", false,0xffffffff,0xffffffff,true),
+ HOWTO(R_X86_64_COPY, 0,4,32,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_X86_64_COPY", false,0xffffffff,0xffffffff,false),
+ HOWTO(R_X86_64_GLOB_DAT, 0,4,64,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_X86_64_GLOB_DAT",false,MINUS_ONE ,MINUS_ONE ,false),
+ HOWTO(R_X86_64_RELATIVE ,0,4,64,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_X86_64_RELATIVE",false,MINUS_ONE ,MINUS_ONE ,false),
+ HOWTO(R_X86_64_JUMP_SLOT,0,4,64,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_X86_64_JUMP_SLOT",false,MINUS_ONE,MINUS_ONE ,false),
+ HOWTO(R_X86_64_GOTPCREL, 0,4,32,true, 0,complain_overflow_signed ,bfd_elf_generic_reloc, "R_X86_64_GOTPCREL",false,0xffffffff,0xffffffff,true),
+ HOWTO(R_X86_64_32, 0,4,32,false,0,complain_overflow_unsigned,bfd_elf_generic_reloc, "R_X86_64_32", false,0xffffffff,0xffffffff,false),
+ HOWTO(R_X86_64_32S, 0,4,32,false,0,complain_overflow_signed, bfd_elf_generic_reloc, "R_X86_64_32S", false,0xffffffff,0xffffffff,false),
+ HOWTO(R_X86_64_16, 0,1,16,false,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_X86_64_16", false,0xffff ,0xffff, false),
+ HOWTO(R_X86_64_PC16, 0,1,16,true ,0,complain_overflow_bitfield,bfd_elf_generic_reloc, "R_X86_64_PC16", false,0xffff ,0xffff, true),
+ HOWTO(R_X86_64_8, 0,0, 8,false,0,complain_overflow_signed ,bfd_elf_generic_reloc, "R_X86_64_8", false,0xff ,0xff, false),
+ HOWTO(R_X86_64_PC8, 0,0, 8,true ,0,complain_overflow_signed ,bfd_elf_generic_reloc, "R_X86_64_PC8", false,0xff ,0xff, true),
};
/* Map BFD relocs to the x86_64 elf relocs. */
@@ -142,7 +142,7 @@ elf64_x86_64_info_to_howto (abfd, cache_
/* The name of the dynamic interpreter. This is put in the .interp
section. */
-#define ELF_DYNAMIC_INTERPRETER "/lib/libd64.so.1"
+#define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1"
/* The size in bytes of an entry in the global offset table. */
@@ -205,7 +205,8 @@ struct elf64_x86_64_link_hash_entry
/* x86-64 ELF linker hash table. */
-struct elf64_x86_64_link_hash_table {
+struct elf64_x86_64_link_hash_table
+{
struct elf_link_hash_table root;
};
@@ -713,21 +714,16 @@ elf64_x86_64_adjust_dynamic_symbol (info
if (h->type == STT_FUNC
|| (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0)
{
- if (! elf_hash_table (info)->dynamic_sections_created)
+ if ((! info->shared
+ && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0
+ && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0)
+ || (info->shared && h->plt.refcount <= 0))
{
- /* FIXME: These are the sparc64 comment and then the i386 comment.
- How we need to deal with this and why remains to be seen. */
- /* This case can occur if we saw a WPLT30 reloc in an input
- file, but none of the input files were dynamic objects.
- In such a case, we don't actually need to build a
- procedure linkage table, and we can just do a WDISP30
- reloc instead. */
/* This case can occur if we saw a PLT32 reloc in an input
file, but the symbol was never referred to by a dynamic
object, or if all references were garbage collected. In
such a case, we don't actually need to build a procedure
linkage table, and we can just do a PC32 reloc instead. */
- /* i386 code: */
h->plt.offset = (bfd_vma) -1;
h->elf_link_hash_flags &= ~ELF_LINK_HASH_NEEDS_PLT;
return true;
@@ -765,6 +761,12 @@ elf64_x86_64_adjust_dynamic_symbol (info
/* Make room for this entry. */
s->_raw_size += PLT_ENTRY_SIZE;
+ /* We also need to make an entry in the .got.plt section, which
+ will be placed in the .got section by the linker script. */
+ s = bfd_get_section_by_name (dynobj, ".got.plt");
+ BFD_ASSERT (s != NULL);
+ s->_raw_size += GOT_ENTRY_SIZE;
+
/* We also need to make an entry in the .rela.plt section. */
s = bfd_get_section_by_name (dynobj, ".rela.plt");
BFD_ASSERT (s != NULL);
@@ -1016,10 +1018,9 @@ elf64_x86_64_size_dynamic_sections (outp
if (plt)
{
- /* FIXME: Are all these needed? */
if (! bfd_elf64_add_dynamic_entry (info, DT_PLTGOT, 0)
|| ! bfd_elf64_add_dynamic_entry (info, DT_PLTRELSZ, 0)
- || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_REL)
+ || ! bfd_elf64_add_dynamic_entry (info, DT_PLTREL, DT_RELA)
|| ! bfd_elf64_add_dynamic_entry (info, DT_JMPREL, 0))
return false;
}
@@ -1696,8 +1697,7 @@ elf64_x86_64_finish_dynamic_sections (ou
asection *splt;
Elf64_External_Dyn *dyncon, *dynconend;
- splt = bfd_get_section_by_name (dynobj, ".plt");
- BFD_ASSERT (splt != NULL && sdyn != NULL);
+ BFD_ASSERT (sdyn != NULL);
dyncon = (Elf64_External_Dyn *) sdyn->contents;
dynconend = (Elf64_External_Dyn *) (sdyn->contents + sdyn->_raw_size);
@@ -1755,9 +1755,11 @@ elf64_x86_64_finish_dynamic_sections (ou
}
/* Initialize the contents of the .plt section. */
+ splt = bfd_get_section_by_name (dynobj, ".plt");
+ BFD_ASSERT (splt != NULL);
if (splt->_raw_size > 0)
{
- memcpy (splt->contents, elf64_x86_64_plt0_entry, PLT_ENTRY_SIZE);
+ memcpy (splt->contents, elf64_x86_64_plt0_entry, PLT_ENTRY_SIZE);
}
elf_section_data (splt->output_section)->this_hdr.sh_entsize =
@@ -1766,7 +1768,7 @@ elf64_x86_64_finish_dynamic_sections (ou
/* Set the first entry in the global offset table to the address of
the dynamic section. */
- sgot = bfd_get_section_by_name (dynobj, ".got");
+ sgot = bfd_get_section_by_name (dynobj, ".got.plt");
BFD_ASSERT (sgot != NULL);
if (sgot->_raw_size > 0)
{
@@ -1787,12 +1789,49 @@ elf64_x86_64_finish_dynamic_sections (ou
return true;
}
+/*
+ * Why was the hash table entry size definition changed from
+ * ARCH_SIZE/8 to 4? This breaks the 64 bit dynamic linker and
+ * this is the only reason for the elf64_x86_64_size_info structure.
+ */
+
+const struct elf_size_info elf64_86_64_size_info =
+{
+ sizeof (Elf64_External_Ehdr),
+ sizeof (Elf64_External_Phdr),
+ sizeof (Elf64_External_Shdr),
+ sizeof (Elf64_External_Rel),
+ sizeof (Elf64_External_Rela),
+ sizeof (Elf64_External_Sym),
+ sizeof (Elf64_External_Dyn),
+ sizeof (Elf_External_Note),
+ 8, /* hash-table entry size */
+ 1, /* internal relocations per external relocations */
+ 64, /* arch_size */
+ 8, /* file_align */
+ ELFCLASS64, EV_CURRENT,
+ bfd_elf64_write_out_phdrs,
+ bfd_elf64_write_shdrs_and_ehdr,
+ bfd_elf64_write_relocs,
+ bfd_elf64_swap_symbol_out,
+ bfd_elf64_slurp_reloc_table,
+ bfd_elf64_slurp_symbol_table,
+ bfd_elf64_swap_dyn_in,
+ bfd_elf64_swap_dyn_out,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+};
+
#define TARGET_LITTLE_SYM bfd_elf64_x86_64_vec
#define TARGET_LITTLE_NAME "elf64-x86-64"
#define ELF_ARCH bfd_arch_i386
#define ELF_MACHINE_CODE EM_X86_64
#define ELF_MAXPAGESIZE 0x100000
+#define elf_backend_size_info elf64_86_64_size_info
+
#define elf_backend_can_gc_sections 1
#define elf_backend_want_got_plt 1
#define elf_backend_plt_readonly 1
@@ -1801,8 +1840,6 @@ elf64_x86_64_finish_dynamic_sections (ou
#define elf_backend_plt_header_size PLT_ENTRY_SIZE
#define elf_info_to_howto elf64_x86_64_info_to_howto
-#define elf_backend_object_p elf64_x86_64_elf_object_p
-#define elf_backend_relocate_section elf64_x86_64_relocate_section
#define bfd_elf64_bfd_final_link _bfd_elf64_gc_common_final_link
#define bfd_elf64_bfd_link_hash_table_create \
@@ -1819,5 +1856,6 @@ elf64_x86_64_finish_dynamic_sections (ou
#define elf_backend_gc_sweep_hook elf64_x86_64_gc_sweep_hook
#define elf_backend_relocate_section elf64_x86_64_relocate_section
#define elf_backend_size_dynamic_sections elf64_x86_64_size_dynamic_sections
+#define elf_backend_object_p elf64_x86_64_elf_object_p
#include "elf64-target.h"
--
Bo Thorsen | Lahnsgade 31, st.
Free software developer | 5000 Odense C
SuSE Labs | Denmark