This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: ld/2462: -Wl,-s always output unused bytes at the end


On Fri, Mar 17, 2006 at 10:05:33AM -0500, Daniel Jacobowitz wrote:
> On Fri, Mar 17, 2006 at 06:32:22AM -0800, H. J. Lu wrote:
> > Before your patch, _bfd_elf_link_output_relocs was called only for
> > relocatable files or finfo->info->emitrelocations is true. Now it
> > called on all ELF targets for all cases.
> 
> I had to spend twenty minutes going over your patch and the current and
> previous code in order to find where this happened.  If you'd just said
> something like "because of how emit_relocs is set in
> bfd_elf_final_link", maybe folks would have been able to understand
> what you were doing.
> 
> That means the patch is, by definition, not obvious.
> 
> After much mucking around, I think that just fixing the assignment to
> emit_relocs (by removing the check for elf_backend_emit_relocs) will

What did you mean? The current elf_link_input_bfd doesn't check
elf_backend_emit_relocs for emit_relocs.

> work correctly.
> 

After 2005-05-05, elf_link_input_bfd calls _bfd_elf_link_output_relocs
for all ELF targets on all output formats even if it isn't needed at
all. Why should we do that?

This update tries to restore the old behavior with one difference. That
is reloc_emitter will set to bed->elf_backend_emit_relocs if it isn't
NULL. Before 2005-05-05, we have

             if (bed->elf_backend_emit_relocs
                 && !(finfo->info->relocatable
                      || finfo->info->emitrelocations))
               reloc_emitter = bed->elf_backend_emit_relocs;
             else
               reloc_emitter = _bfd_elf_link_output_relocs;


H.J.
-----
2006-03-17  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/2462
	* elflink.c (elf_link_input_bfd): Emit relocations only when
	needed. Put back reloc_emitter removed on 2005-05-05 and set
	to bed->elf_backend_emit_relocs if it isn't NULL. Call
	reloc_emitter instead of bed->elf_backend_emit_relocs.

	* elfxx-target.h (elf_backend_emit_relocs): Default to NULL.

--- bfd/elflink.c.reloc	2006-03-16 21:44:49.000000000 -0800
+++ bfd/elflink.c	2006-03-17 07:01:04.000000000 -0800
@@ -6833,6 +6833,9 @@ elf_link_input_bfd (struct elf_final_lin
   const struct elf_backend_data *bed;
   bfd_boolean emit_relocs;
   struct elf_link_hash_entry **sym_hashes;
+  bfd_boolean (*reloc_emitter)
+    (bfd *, asection *, Elf_Internal_Shdr *, Elf_Internal_Rela *,
+     struct elf_link_hash_entry **);
 
   output_bfd = finfo->output_bfd;
   bed = get_elf_backend_data (output_bfd);
@@ -6845,7 +6848,13 @@ elf_link_input_bfd (struct elf_final_lin
     return TRUE;
 
   emit_relocs = (finfo->info->relocatable
-		 || finfo->info->emitrelocations);
+		 || finfo->info->emitrelocations
+		 || bed->elf_backend_emit_relocs);
+
+  if (bed->elf_backend_emit_relocs)
+    reloc_emitter = bed->elf_backend_emit_relocs;
+  else
+    reloc_emitter = _bfd_elf_link_output_relocs;
 
   symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
   if (elf_bad_symtab (input_bfd))
@@ -7416,10 +7425,9 @@ elf_link_input_bfd (struct elf_final_lin
 
 	      /* Swap out the relocs.  */
 	      if (input_rel_hdr->sh_size != 0
-		  && !bed->elf_backend_emit_relocs (output_bfd, o,
-						    input_rel_hdr,
-						    internal_relocs,
-						    rel_hash_list))
+		  && ! (*reloc_emitter) (output_bfd, o, input_rel_hdr,
+					 internal_relocs,
+					 rel_hash_list))
 		return FALSE;
 
 	      input_rel_hdr2 = elf_section_data (o)->rel_hdr2;
@@ -7428,10 +7436,9 @@ elf_link_input_bfd (struct elf_final_lin
 		  internal_relocs += (NUM_SHDR_ENTRIES (input_rel_hdr)
 				      * bed->s->int_rels_per_ext_rel);
 		  rel_hash_list += NUM_SHDR_ENTRIES (input_rel_hdr);
-		  if (!bed->elf_backend_emit_relocs (output_bfd, o,
-						     input_rel_hdr2,
-						     internal_relocs,
-						     rel_hash_list))
+		  if (! (*reloc_emitter) (output_bfd, o, input_rel_hdr2,
+					  internal_relocs,
+					  rel_hash_list))
 		    return FALSE;
 		}
 	    }
--- bfd/elfxx-target.h.reloc	2006-02-27 15:50:54.000000000 -0800
+++ bfd/elfxx-target.h	2006-03-17 05:27:36.000000000 -0800
@@ -430,7 +430,7 @@
 #define elf_backend_ignore_undef_symbol		NULL
 #endif
 #ifndef elf_backend_emit_relocs
-#define elf_backend_emit_relocs			_bfd_elf_link_output_relocs
+#define elf_backend_emit_relocs			NULL
 #endif
 #ifndef elf_backend_count_relocs
 #define elf_backend_count_relocs		NULL


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]