This is the mail archive of the binutils@sources.redhat.com 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: [RFC] Providing init_fini_syms earlier?


On Wed, Jul 13, 2005 at 11:02:11PM +0930, Alan Modra wrote:
> > How does it support relaxation
> > when it will be called more then once?
> 
> If they are section relative, then there is no problem with relaxation
> unless the init or fini sections change size, which I think is
> unlikely to happen.  There is one disadvantage of section relative syms;

The section size is 0 when it is called from ldemul_before_allocation.

> They cause their output section to be kept.  Hmm, I suppose we could
> change that.  We might even be able to do without bfd_mark_used_section
> entirely now that vma is set correctly for stripped output sections.
> 

This patch assumes that the end symbol is provided by linker if it is
relative to the same section and its value is 0. I asssume those
section sizes won't change during relaxation. It they do, I can
move it to lang_do_assignments.


H.J.
----
bfd/

2005-07-13  H.J. Lu  <hongjiu.lu@intel.com>

	* elflink.c (_bfd_elf_provide_section_bound_symbols): Use
	section relative value. Redefine the end symbol if it is
	relative to the same section and its value is 0.

ld/

2005-07-13  H.J. Lu  <hongjiu.lu@intel.com>

	* emultempl/aix.em (ld_${EMULATION_NAME}_emulation): Set to the
	provide_symbols field to NULL.
	* emultempl/armcoff.em: Likewise.
	* emultempl/beos.em: Likewise.
	* emultempl/generic.em: Likewise.
	* emultempl/gld960.em: Likewise.
	* emultempl/gld960c.em: Likewise.
	* emultempl/linux.em: Likewise.
	* emultempl/lnk960.em: Likewise.
	* emultempl/m68kcoff.em: Likewise.
	* emultempl/pe.em: Likewise.
	* emultempl/sunos.em: Likewise.
	* emultempl/ticoff.em: Likewise.
	* emultempl/vanilla.em: Likewise.

	* emultempl/elf32.em (gld${EMULATION_NAME}_provide_init_fini_syms):
	Renamd to ...
	(gld${EMULATION_NAME}_provide_section_symbols): This.
	(gld${EMULATION_NAME}_before_allocation): Call it.

	* emultempl/elf32.em (gld${EMULATION_NAME}_finish): Remove call
	to gld${EMULATION_NAME}_provide_init_fini_syms.
	* emultempl/hppaelf.em: Likewise.
	* emultempl/ppc64elf.em: Likewise.

	* ldemul.c (ldemul_provide_section_symbols): New.

	* ldemul.h (ldemul_provide_section_symbols): New.
	(ld_emulation_xfer_struct): Add the provide_symbols field.

	* ldlang.c (lang_process): Call ldemul_provide_section_symbols
	after lang_size_sections.

--- binutils/bfd/elflink.c.provide	2005-07-13 07:59:11.191323105 -0700
+++ binutils/bfd/elflink.c	2005-07-13 08:22:30.539207333 -0700
@@ -9900,15 +9900,22 @@ _bfd_elf_provide_section_bound_symbols (
 
   he = elf_link_hash_lookup (elf_hash_table (info), end, FALSE,
 			     FALSE, FALSE);
-  do_end = he != NULL && !he->def_regular;
+  /* This function should be called only twice. The section size is 0
+     at the first time.  At the second time, we assume that the end
+     symbol is provided by linker if it is relative to the same section
+     and its value is 0.  */
+  do_end = (he != NULL
+	    && (!he->def_regular
+		|| (he->root.u.def.section == sec
+		    && he->root.u.def.value == 0)));
 
   if (!do_start && !do_end)
     return;
 
   if (sec != NULL)
     {
-      start_val = sec->vma;
-      end_val = start_val + sec->size;
+      start_val = 0;
+      end_val = sec->size;
     }
   else
     {
@@ -9926,8 +9933,8 @@ _bfd_elf_provide_section_bound_symbols (
     }
 
   if (do_start)
-    bfd_elf_set_symbol (hs, start_val, NULL);
+    bfd_elf_set_symbol (hs, start_val, sec);
 
   if (do_end)
-    bfd_elf_set_symbol (he, end_val, NULL);
+    bfd_elf_set_symbol (he, end_val, sec);
 }
--- binutils/ld/emultempl/aix.em.provide	2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/aix.em	2005-07-13 07:59:21.774582740 -0700
@@ -1348,6 +1348,7 @@ struct ld_emulation_xfer_struct ld_${EMU
   0,				/* open_dynamic_archive */
   0,				/* place_orphan */
   0,				/* set_symbols */
+  0,				/* provide_symbols */
   gld${EMULATION_NAME}_parse_args,
   gld${EMULATION_NAME}_add_options,
   gld${EMULATION_NAME}_handle_option,
--- binutils/ld/emultempl/armcoff.em.provide	2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/armcoff.em	2005-07-13 07:59:21.775582576 -0700
@@ -268,6 +268,7 @@ struct ld_emulation_xfer_struct ld_${EMU
   NULL,	/* open dynamic archive */
   NULL,	/* place orphan */
   NULL,	/* set symbols */
+  NULL,	/* provide symbols */
   NULL, /* parse_args */
   gld${EMULATION_NAME}_add_options,
   gld${EMULATION_NAME}_handle_option,
--- binutils/ld/emultempl/beos.em.provide	2005-06-02 16:02:26.000000000 -0700
+++ binutils/ld/emultempl/beos.em	2005-07-13 07:59:21.776582412 -0700
@@ -775,6 +775,7 @@ struct ld_emulation_xfer_struct ld_${EMU
   NULL, /* open dynamic archive */
   gld${EMULATION_NAME}_place_orphan,
   gld_${EMULATION_NAME}_set_symbols,
+  NULL, /* provide_symbols */
   NULL, /* parse_args */
   gld${EMULATION_NAME}_add_options,
   gld${EMULATION_NAME}_handle_option,
--- binutils/ld/emultempl/elf32.em.provide	2005-07-13 07:59:11.193322776 -0700
+++ binutils/ld/emultempl/elf32.em	2005-07-13 07:59:21.777582247 -0700
@@ -61,7 +61,7 @@ static void gld${EMULATION_NAME}_before_
 static bfd_boolean gld${EMULATION_NAME}_place_orphan
   (lang_input_statement_type *file, asection *s);
 static void gld${EMULATION_NAME}_layout_sections_again (void);
-static void gld${EMULATION_NAME}_provide_init_fini_syms (void);
+static void gld${EMULATION_NAME}_provide_section_symbols (void);
 static void gld${EMULATION_NAME}_finish (void) ATTRIBUTE_UNUSED;
 
 EOF
@@ -1057,6 +1057,9 @@ gld${EMULATION_NAME}_before_allocation (
      referred to by dynamic objects.  */
   lang_for_each_statement (gld${EMULATION_NAME}_find_statement_assignment);
 
+  /* We need to do the same for linker provided symbols.  */
+  gld${EMULATION_NAME}_provide_section_symbols ();
+
   /* Let the ELF backend work out the sizes of any sections required
      by dynamic linking.  */
   rpath = command_line.rpath;
@@ -1474,7 +1477,7 @@ gld${EMULATION_NAME}_provide_bound_symbo
    section alignment affecting where the section starts.  */
 
 static void
-gld${EMULATION_NAME}_provide_init_fini_syms (void)
+gld${EMULATION_NAME}_provide_section_symbols (void)
 {
   if (!link_info.relocatable && link_info.executable)
     {
@@ -1510,8 +1513,6 @@ gld${EMULATION_NAME}_finish (void)
 {
   if (bfd_elf_discard_info (output_bfd, &link_info))
     gld${EMULATION_NAME}_layout_sections_again ();
-
-  gld${EMULATION_NAME}_provide_init_fini_syms ();
 }
 EOF
 fi
@@ -1890,6 +1891,7 @@ struct ld_emulation_xfer_struct ld_${EMU
   ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-gld${EMULATION_NAME}_open_dynamic_archive},
   ${LDEMUL_PLACE_ORPHAN-gld${EMULATION_NAME}_place_orphan},
   ${LDEMUL_SET_SYMBOLS-NULL},
+  ${LDEMUL_PROVIDE_SYMBOLS-gld${EMULATION_NAME}_provide_section_symbols},
   ${LDEMUL_PARSE_ARGS-NULL},
   gld${EMULATION_NAME}_add_options,
   gld${EMULATION_NAME}_handle_option,
--- binutils/ld/emultempl/generic.em.provide	2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/generic.em	2005-07-13 07:59:21.778582083 -0700
@@ -136,6 +136,7 @@ struct ld_emulation_xfer_struct ld_${EMU
   ${LDEMUL_OPEN_DYNAMIC_ARCHIVE-NULL},
   ${LDEMUL_PLACE_ORPHAN-NULL},
   ${LDEMUL_SET_SYMBOLS-NULL},
+  ${LDEMUL_PROVIDE_SYMBOLS-NULL},
   ${LDEMUL_PARSE_ARGS-NULL},
   NULL,	/* add_options */
   NULL,	/* handle_option */
--- binutils/ld/emultempl/gld960.em.provide	2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/gld960.em	2005-07-13 07:59:21.778582083 -0700
@@ -142,6 +142,7 @@ struct ld_emulation_xfer_struct ld_gld96
   NULL,	/* open dynamic archive */
   NULL,	/* place orphan */
   NULL,	/* set symbols */
+  NULL,	/* provide symbols */
   NULL,	/* parse args */
   NULL,	/* add_options */
   NULL,	/* handle_option */
--- binutils/ld/emultempl/gld960c.em.provide	2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/gld960c.em	2005-07-13 07:59:21.779581918 -0700
@@ -157,6 +157,7 @@ struct ld_emulation_xfer_struct ld_gld96
   NULL,	/* open dynamic archive */
   NULL,	/* place orphan */
   NULL,	/* set symbols */
+  NULL,	/* provide symbols */
   NULL,	/* parse args */
   NULL,	/* add_options */
   NULL,	/* handle_option */
--- binutils/ld/emultempl/hppaelf.em.provide	2005-07-13 07:59:11.193322776 -0700
+++ binutils/ld/emultempl/hppaelf.em	2005-07-13 07:59:21.780581754 -0700
@@ -304,8 +304,6 @@ hppaelf_finish (void)
 	    einfo ("%X%P: can not build stubs: %E\n");
 	}
     }
-
-  gld${EMULATION_NAME}_provide_init_fini_syms ();
 }
 
 
--- binutils/ld/emultempl/linux.em.provide	2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/linux.em	2005-07-13 07:59:21.780581754 -0700
@@ -197,6 +197,7 @@ struct ld_emulation_xfer_struct ld_${EMU
   gld${EMULATION_NAME}_open_dynamic_archive,
   NULL,	/* place orphan */
   NULL,	/* set symbols */
+  NULL,	/* provide symbols */
   NULL,	/* parse args */
   NULL,	/* add_options */
   NULL,	/* handle_option */
--- binutils/ld/emultempl/lnk960.em.provide	2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/lnk960.em	2005-07-13 07:59:21.781581589 -0700
@@ -277,6 +277,7 @@ struct ld_emulation_xfer_struct ld_lnk96
   NULL,	/* open dynamic archive */
   NULL,	/* place orphan */
   NULL,	/* set symbols */
+  NULL,	/* provide symbols */
   NULL,	/* parse args */
   NULL,	/* add_options */
   NULL,	/* handle_option */
--- binutils/ld/emultempl/m68kcoff.em.provide	2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/m68kcoff.em	2005-07-13 07:59:21.782581425 -0700
@@ -230,6 +230,7 @@ struct ld_emulation_xfer_struct ld_${EMU
   NULL,	/* open dynamic archive */
   NULL,	/* place orphan */
   NULL,	/* set symbols */
+  NULL,	/* provide symbols */
   NULL,	/* parse args */
   NULL,	/* add_options */
   NULL,	/* handle_option */
--- binutils/ld/emultempl/pe.em.provide	2005-07-11 14:08:22.000000000 -0700
+++ binutils/ld/emultempl/pe.em	2005-07-13 07:59:21.783581261 -0700
@@ -1830,6 +1830,7 @@ struct ld_emulation_xfer_struct ld_${EMU
   gld_${EMULATION_NAME}_open_dynamic_archive,
   gld_${EMULATION_NAME}_place_orphan,
   gld_${EMULATION_NAME}_set_symbols,
+  NULL, /* provide_symbols */
   NULL, /* parse_args */
   gld${EMULATION_NAME}_add_options,
   gld${EMULATION_NAME}_handle_option,
--- binutils/ld/emultempl/ppc64elf.em.provide	2005-07-13 07:59:11.194322611 -0700
+++ binutils/ld/emultempl/ppc64elf.em	2005-07-13 07:59:21.784581096 -0700
@@ -379,7 +379,6 @@ ppc_finish (void)
     }
 
   ppc64_elf_restore_symbols (&link_info);
-  gld${EMULATION_NAME}_provide_init_fini_syms ();
 }
 
 
--- binutils/ld/emultempl/sunos.em.provide	2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/sunos.em	2005-07-13 07:59:21.785580932 -0700
@@ -1021,6 +1021,7 @@ struct ld_emulation_xfer_struct ld_${EMU
   NULL,	/* open dynamic archive */
   NULL,	/* place orphan */
   gld${EMULATION_NAME}_set_symbols,
+  NULL,	/* provide_symbols */
   NULL,	/* parse args */
   NULL,	/* add_options */
   NULL,	/* handle_option */
--- binutils/ld/emultempl/ticoff.em.provide	2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/ticoff.em	2005-07-13 07:59:21.785580932 -0700
@@ -170,6 +170,7 @@ struct ld_emulation_xfer_struct ld_${EMU
   NULL, /* open dynamic archive */
   NULL, /* place orphan */
   NULL, /* set_symbols */
+  NULL, /* provide_symbols */
   NULL, /* parse_args */
   gld${EMULATION_NAME}_add_options,
   gld${EMULATION_NAME}_handle_option,
--- binutils/ld/emultempl/vanilla.em.provide	2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/vanilla.em	2005-07-13 07:59:21.786580767 -0700
@@ -73,6 +73,7 @@ struct ld_emulation_xfer_struct ld_vanil
   NULL,	/* open dynamic archive */
   NULL,	/* place orphan */
   NULL,	/* set symbols */
+  NULL,	/* provide symbols */
   NULL,	/* parse args */
   NULL,	/* add_options */
   NULL,	/* handle_option */
--- binutils/ld/ldemul.c.provide	2005-05-16 11:04:39.000000000 -0700
+++ binutils/ld/ldemul.c	2005-07-13 07:59:21.786580767 -0700
@@ -100,6 +100,13 @@ ldemul_set_symbols (void)
 }
 
 void
+ldemul_provide_section_symbols (void)
+{
+  if (ld_emulation->provide_symbols)
+    ld_emulation->provide_symbols ();
+}
+
+void
 ldemul_create_output_section_statements (void)
 {
   if (ld_emulation->create_output_section_statements)
--- binutils/ld/ldemul.h.provide	2005-03-03 08:56:33.000000000 -0800
+++ binutils/ld/ldemul.h	2005-07-13 07:59:21.787580603 -0700
@@ -51,6 +51,8 @@ extern void ldemul_finish
   (void);
 extern void ldemul_set_symbols
   (void);
+extern void ldemul_provide_section_symbols
+  (void);
 extern void ldemul_create_output_section_statements
   (void);
 extern bfd_boolean ldemul_place_orphan
@@ -149,6 +151,10 @@ typedef struct ld_emulation_xfer_struct 
      reading the script.  Used to initialize symbols used in the script.  */
   void	(*set_symbols) (void);
 
+  /* Called in lang_do_assignments.  Used to provide symbols by linker
+     emulation.  */
+  void	(*provide_symbols) (void);
+
   /* Parse args which the base linker doesn't understand.
      Return TRUE if the arg needs no further processing.  */
   bfd_boolean (*parse_args) (int, char **);
--- binutils/ld/ldlang.c.provide	2005-07-13 07:50:24.198984363 -0700
+++ binutils/ld/ldlang.c	2005-07-13 08:14:01.033992921 -0700
@@ -5368,6 +5368,9 @@ lang_process (void)
   /* Size up the sections.  */
   lang_size_sections (NULL, !command_line.relax);
 
+  /* Assign values for symbols provided by emulation.  */
+  ldemul_provide_section_symbols ();
+
   /* Now run around and relax if we can.  */
   if (command_line.relax)
     {


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