This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: DJGPP port of binutils broken due to 64 bit cygwin fix.
- From: Alan Modra <amodra at gmail dot com>
- To: Juan Manuel Guerrero <juan dot guerrero at gmx dot de>
- Cc: binutils at sourceware dot org, Nick Clifton <nickc at redhat dot com>, djgpp at delorie dot com
- Date: Tue, 9 Jun 2015 15:14:42 +0930
- Subject: Re: DJGPP port of binutils broken due to 64 bit cygwin fix.
- Authentication-results: sourceware.org; auth=none
- References: <55703CF2 dot 5030900 at gmx dot de>
On Thu, Jun 04, 2015 at 01:56:34PM +0200, Juan Manuel Guerrero wrote:
http://lists.gnu.org/archive/html/bug-binutils/2015-06/msg00010.html
> An inspection of the repository of binutils, specially a comparision between
> the binutil-2_25-branch/master and the binutil-2_24-branch reveals that the
> function _bfd_coff_generic_relocate_section in bfd/cofflink.c has been modified
> by the following patch (55bfc9ac025c1c9cd1ad5422829b3dc70f357a79):
[snip]
> @@ -3059,6 +3059,11 @@ _bfd_coff_generic_relocate_section (bfd *output_bfd,
> else
> {
> sec = sections[symndx];
> +
> + /* If the output section has been discarded then ignore this reloc. */
> + if (sec->output_section->vma == 0)
> + continue;
> +
> val = (sec->output_section->vma
> + sec->output_offset
> + sym->n_value);
Nick's patch https://sourceware.org/ml/binutils/2014-03/msg00270.html
looks wrong on a number of fronts. Why the odd test for a discarded
section? I think we ought to apply something like the following,
handling not just local but also global symbols defined in discarded
sections. This also zeros out the relocation field as is done for the
ELF linker.
However, I'm not an expert on the COFF linker, and don't have the
means to test this on a native cygwin toolchain without significant
effort on my part. So this patch ought to be reviewed by someone
before I commit it.
* cofflink.c (_bfd_coff_generic_relocate_section): Revert
2014-03-26 change. Call _bfd_clear_contents for relocs against
local and global symbols defined in discarded input sections.
diff --git a/bfd/cofflink.c b/bfd/cofflink.c
index 0ac10de..c1541d1 100644
--- a/bfd/cofflink.c
+++ b/bfd/cofflink.c
@@ -2915,6 +2915,7 @@ _bfd_coff_generic_relocate_section (bfd *output_bfd,
struct internal_syment *sym;
bfd_vma addend;
bfd_vma val;
+ asection *sec;
reloc_howto_type *howto;
bfd_reloc_status_type rstat;
@@ -2965,11 +2966,9 @@ _bfd_coff_generic_relocate_section (bfd *output_bfd,
}
val = 0;
-
+ sec = NULL;
if (h == NULL)
{
- asection *sec;
-
if (symndx == -1)
{
sec = bfd_abs_section_ptr;
@@ -2978,11 +2977,6 @@ _bfd_coff_generic_relocate_section (bfd *output_bfd,
else
{
sec = sections[symndx];
-
- /* If the output section has been discarded then ignore this reloc. */
- if (sec->output_section->vma == 0)
- continue;
-
val = (sec->output_section->vma
+ sec->output_offset
+ sym->n_value);
@@ -2996,8 +2990,6 @@ _bfd_coff_generic_relocate_section (bfd *output_bfd,
|| h->root.type == bfd_link_hash_defweak)
{
/* Defined weak symbols are a GNU extension. */
- asection *sec;
-
sec = h->root.u.def.section;
val = (h->root.u.def.value
+ sec->output_section->vma
@@ -3018,7 +3010,6 @@ _bfd_coff_generic_relocate_section (bfd *output_bfd,
will resolve a weak external only if a normal
external causes the library member to be linked.
See also linker.c: generic_link_check_archive_element. */
- asection *sec;
struct coff_link_hash_entry *h2 =
h->auxbfd->tdata.coff_obj_data->sym_hashes[
h->aux->x_sym.x_tagndx.l];
@@ -3049,6 +3040,15 @@ _bfd_coff_generic_relocate_section (bfd *output_bfd,
}
}
+ /* If the input section defining the symbol has been discarded
+ then zero this reloc field. */
+ if (sec != NULL && discarded_section (sec))
+ {
+ _bfd_clear_contents (howto, input_bfd, input_section,
+ contents + (rel->r_vaddr - input_section->vma));
+ continue;
+ }
+
if (info->base_file)
{
/* Emit a reloc if the backend thinks it needs it. */
--
Alan Modra
Australia Development Lab, IBM