This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
PATCH: Fix and use elf_append_rel
- From: "H.J. Lu" <hongjiu dot lu at intel dot com>
- To: binutils at sourceware dot org
- Date: Wed, 19 Dec 2012 16:59:47 -0800
- Subject: PATCH: Fix and use elf_append_rel
- Reply-to: "H.J. Lu" <hjl dot tools at gmail dot com>
Resend. H.J.
----- Forwarded message from "H.J. Lu" <hongjiu.lu@intel.com> -----
Date: Wed, 19 Dec 2012 11:47:52 -0800
From: "H.J. Lu" <hongjiu.lu@intel.com>
To: binutils@sourceware.org
User-Agent: Mutt/1.5.21 (2010-09-15)
Hi,
There is a typo in elf_append_rel. I checked in this patch to fix
it and use it in elf32-i386.c. It checks relocation offset overflow.
H.J.
---
Index: ChangeLog
===================================================================
RCS file: /cvs/src/src/bfd/ChangeLog,v
retrieving revision 1.5889
diff -u -p -r1.5889 ChangeLog
--- ChangeLog 19 Dec 2012 19:41:17 -0000 1.5889
+++ ChangeLog 19 Dec 2012 19:45:09 -0000
@@ -1,3 +1,12 @@
+2012-12-19 H.J. Lu <hongjiu.lu@intel.com>
+
+ * elf32-i386.c (elf_i386_relocate_section): Replace
+ bfd_elf32_swap_reloc_out with elf_append_rel.
+ (elf_i386_finish_dynamic_symbol): Likewise.
+
+ * elflink.c (elf_append_rel): Call swap_reloc_out instead of
+ swap_reloca_out.
+
2012-12-18 H.J. Lu <hongjiu.lu@intel.com>
* elf32-i386.c (elf_i386_finish_dynamic_symbol): Reindent.
Index: elf32-i386.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-i386.c,v
retrieving revision 1.290
diff -u -p -r1.290 elf32-i386.c
--- elf32-i386.c 19 Dec 2012 19:41:18 -0000 1.290
+++ elf32-i386.c 19 Dec 2012 19:45:09 -0000
@@ -3365,7 +3365,6 @@ elf_i386_relocate_section (bfd *output_b
if (info->shared && h->non_got_ref)
{
Elf_Internal_Rela outrel;
- bfd_byte *loc;
asection *sreloc;
bfd_vma offset;
@@ -3399,10 +3398,7 @@ elf_i386_relocate_section (bfd *output_b
outrel.r_info = ELF32_R_INFO (h->dynindx, r_type);
sreloc = htab->elf.irelifunc;
- loc = sreloc->contents;
- loc += (sreloc->reloc_count++
- * sizeof (Elf32_External_Rel));
- bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
+ elf_append_rel (output_bfd, sreloc, &outrel);
/* If this reloc is against an external symbol, we
do not want to fiddle with the addend. Otherwise,
@@ -3556,7 +3552,6 @@ elf_i386_relocate_section (bfd *output_b
{
asection *s;
Elf_Internal_Rela outrel;
- bfd_byte *loc;
s = htab->elf.srelgot;
if (s == NULL)
@@ -3566,9 +3561,7 @@ elf_i386_relocate_section (bfd *output_b
+ htab->elf.sgot->output_offset
+ off);
outrel.r_info = ELF32_R_INFO (0, R_386_RELATIVE);
- loc = s->contents;
- loc += s->reloc_count++ * sizeof (Elf32_External_Rel);
- bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
+ elf_append_rel (output_bfd, s, &outrel);
}
local_got_offsets[r_symndx] |= 1;
@@ -3696,7 +3689,6 @@ elf_i386_relocate_section (bfd *output_b
|| h->root.type == bfd_link_hash_undefined)))
{
Elf_Internal_Rela outrel;
- bfd_byte *loc;
bfd_boolean skip, relocate;
asection *sreloc;
@@ -3741,10 +3733,7 @@ elf_i386_relocate_section (bfd *output_b
goto check_relocation_error;
}
- loc = sreloc->contents;
- loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
-
- bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
+ elf_append_rel (output_bfd, sreloc, &outrel);
/* If this reloc is against an external symbol, we do
not want to fiddle with the addend. Otherwise, we
@@ -3759,7 +3748,6 @@ elf_i386_relocate_section (bfd *output_b
if (!info->executable)
{
Elf_Internal_Rela outrel;
- bfd_byte *loc;
asection *sreloc;
outrel.r_offset = rel->r_offset
@@ -3769,9 +3757,7 @@ elf_i386_relocate_section (bfd *output_b
sreloc = elf_section_data (input_section)->sreloc;
if (sreloc == NULL)
abort ();
- loc = sreloc->contents;
- loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
- bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
+ elf_append_rel (output_bfd, sreloc, &outrel);
}
/* Fall through */
@@ -3997,7 +3983,6 @@ elf_i386_relocate_section (bfd *output_b
else
{
Elf_Internal_Rela outrel;
- bfd_byte *loc;
int dr_type;
asection *sreloc;
@@ -4008,6 +3993,7 @@ elf_i386_relocate_section (bfd *output_b
if (GOT_TLS_GDESC_P (tls_type))
{
+ bfd_byte *loc;
outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_DESC);
BFD_ASSERT (htab->sgotplt_jump_table_size + offplt + 8
<= htab->elf.sgotplt->size);
@@ -4065,11 +4051,7 @@ elf_i386_relocate_section (bfd *output_b
htab->elf.sgot->contents + off);
outrel.r_info = ELF32_R_INFO (indx, dr_type);
- loc = sreloc->contents;
- loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
- BFD_ASSERT (loc + sizeof (Elf32_External_Rel)
- <= sreloc->contents + sreloc->size);
- bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
+ elf_append_rel (output_bfd, sreloc, &outrel);
if (GOT_TLS_GD_P (tls_type))
{
@@ -4087,11 +4069,7 @@ elf_i386_relocate_section (bfd *output_b
outrel.r_info = ELF32_R_INFO (indx,
R_386_TLS_DTPOFF32);
outrel.r_offset += 4;
- sreloc->reloc_count++;
- loc += sizeof (Elf32_External_Rel);
- BFD_ASSERT (loc + sizeof (Elf32_External_Rel)
- <= sreloc->contents + sreloc->size);
- bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
+ elf_append_rel (output_bfd, sreloc, &outrel);
}
}
else if (tls_type == GOT_TLS_IE_BOTH)
@@ -4103,9 +4081,7 @@ elf_i386_relocate_section (bfd *output_b
htab->elf.sgot->contents + off + 4);
outrel.r_info = ELF32_R_INFO (indx, R_386_TLS_TPOFF);
outrel.r_offset += 4;
- sreloc->reloc_count++;
- loc += sizeof (Elf32_External_Rel);
- bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
+ elf_append_rel (output_bfd, sreloc, &outrel);
}
dr_done:
@@ -4287,7 +4263,6 @@ elf_i386_relocate_section (bfd *output_b
else
{
Elf_Internal_Rela outrel;
- bfd_byte *loc;
if (htab->elf.srelgot == NULL)
abort ();
@@ -4300,9 +4275,7 @@ elf_i386_relocate_section (bfd *output_b
bfd_put_32 (output_bfd, 0,
htab->elf.sgot->contents + off + 4);
outrel.r_info = ELF32_R_INFO (0, R_386_TLS_DTPMOD32);
- loc = htab->elf.srelgot->contents;
- loc += htab->elf.srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
- bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
+ elf_append_rel (output_bfd, htab->elf.srelgot, &outrel);
htab->tls_ldm_got.offset |= 1;
}
relocation = htab->elf.sgot->output_section->vma
@@ -4326,7 +4299,6 @@ elf_i386_relocate_section (bfd *output_b
{
Elf_Internal_Rela outrel;
asection *sreloc;
- bfd_byte *loc;
outrel.r_offset = rel->r_offset
+ input_section->output_section->vma
@@ -4342,9 +4314,7 @@ elf_i386_relocate_section (bfd *output_b
sreloc = elf_section_data (input_section)->sreloc;
if (sreloc == NULL)
abort ();
- loc = sreloc->contents;
- loc += sreloc->reloc_count++ * sizeof (Elf32_External_Rel);
- bfd_elf32_swap_reloc_out (output_bfd, &outrel, loc);
+ elf_append_rel (output_bfd, sreloc, &outrel);
if (indx)
continue;
else if (r_type == R_386_TLS_LE_32)
@@ -4632,7 +4602,6 @@ elf_i386_finish_dynamic_symbol (bfd *out
&& (elf_i386_hash_entry(h)->tls_type & GOT_TLS_IE) == 0)
{
Elf_Internal_Rela rel;
- bfd_byte *loc;
/* This symbol has an entry in the global offset table. Set it
up. */
@@ -4690,15 +4659,12 @@ do_glob_dat:
rel.r_info = ELF32_R_INFO (h->dynindx, R_386_GLOB_DAT);
}
- loc = htab->elf.srelgot->contents;
- loc += htab->elf.srelgot->reloc_count++ * sizeof (Elf32_External_Rel);
- bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
+ elf_append_rel (output_bfd, htab->elf.srelgot, &rel);
}
if (h->needs_copy)
{
Elf_Internal_Rela rel;
- bfd_byte *loc;
/* This symbol needs a copy reloc. Set it up. */
@@ -4712,9 +4678,7 @@ do_glob_dat:
+ h->root.u.def.section->output_section->vma
+ h->root.u.def.section->output_offset);
rel.r_info = ELF32_R_INFO (h->dynindx, R_386_COPY);
- loc = htab->srelbss->contents;
- loc += htab->srelbss->reloc_count++ * sizeof (Elf32_External_Rel);
- bfd_elf32_swap_reloc_out (output_bfd, &rel, loc);
+ elf_append_rel (output_bfd, htab->srelbss, &rel);
}
return TRUE;
Index: elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.457
diff -u -p -r1.457 elflink.c
--- elflink.c 20 Nov 2012 22:17:26 -0000 1.457
+++ elflink.c 19 Dec 2012 19:45:10 -0000
@@ -13077,5 +13077,5 @@ elf_append_rel (bfd *abfd, asection *s,
const struct elf_backend_data *bed = get_elf_backend_data (abfd);
bfd_byte *loc = s->contents + (s->reloc_count++ * bed->s->sizeof_rel);
BFD_ASSERT (loc + bed->s->sizeof_rel <= s->contents + s->size);
- bed->s->swap_reloca_out (abfd, rel, loc);
+ bed->s->swap_reloc_out (abfd, rel, loc);
}
----- End forwarded message -----