[RFC] Providing init_fini_syms earlier?

H. J. Lu hjl@lucon.org
Mon Jul 11 21:26:00 GMT 2005


On Mon, Jul 11, 2005 at 09:06:23PM +0200, Jakub Jelinek wrote:
> On Mon, Jul 11, 2005 at 02:06:55PM -0400, Carlos O'Donell wrote:
> > On Mon, Jul 11, 2005 at 10:47:41AM -0700, H. J. Lu wrote:
> > > On Mon, Jul 11, 2005 at 10:51:07AM -0400, Carlos O'Donell wrote:
> > > > On Mon, Jul 11, 2005 at 07:45:00AM -0700, H. J. Lu wrote:
> > > > > That was a glibc bug. I posted a patch for the linker bug.
> > > > 
> > > > There may have been a linker bug, but it doesn't solve the problem.
> > > > The symbol provide by the linker is still too late for the backend to
> > > > do anything about the extra reloc space.
> > > 
> > > Please try the linker patch with the FIXED glibc.
> > 
> > Could you provide a reference to your libc patch please?
> > 
> > I know you recently posted:
> > 2005-04-13  H.J. Lu  <hongjiu.lu@intel.com>
> >         [BZ #974]
> > 	...
> > 
> > Though it doesn't look like that patch would change the definitions of
> > the symbols.
> > 
> > I'm a bit confused because it also looks like the definition in 2.3.2
> > were marked hidden.
> 
> That's actually a fedora*-branch local change:
> http://sources.redhat.com/cgi-bin/cvsweb.cgi/libc/csu/elf-init.c.diff?r1=1.3&r2=1.3.2.1&cvsroot=glibc
> ld should work correctly with or without that, what really matters
> is if the definitions of the symbols are hidden or not (and they are
> supposed to be hidden).
> 

Linker provided symbols need to be handled similar to linker script
assignments. My patch

http://sourceware.org/ml/binutils/2005-05/msg00767.html

missed the one suggested in

http://sourceware.org/ml/binutils/2005-07/msg00103.html

This updated patch should work on x86-64, ppc and ia64.


H.J.
----
bfd/

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

	* elf-bfd.h (elf_link_hash_entry): Add the provide field.

	* elflink.c (bfd_elf_set_symbol): Set the provide field to 1.
	(_bfd_elf_provide_section_bound_symbols): Also provide the
	symbol if the provide field is non-zero.

ld/

2005-07-11  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_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_symbols): New.

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

	* ldlang.c (lang_do_assignments): Call ldemul_provide_symbols.

--- binutils/bfd/elf-bfd.h.provide	2005-07-11 14:09:06.465258091 -0700
+++ binutils/bfd/elf-bfd.h	2005-07-11 14:09:06.512250351 -0700
@@ -172,6 +172,10 @@ struct elf_link_hash_entry
      matters.  */
   unsigned int pointer_equality_needed : 1;
 
+  /* Symbol is provided by linker emulation.  */
+  unsigned int provide: 1;
+
+  /* Symbol is referenced by a shared object.  */
   /* String table index in .dynstr if this is a dynamic symbol.  */
   unsigned long dynstr_index;
 
--- binutils/bfd/elflink.c.provide	2005-07-11 14:09:06.475256444 -0700
+++ binutils/bfd/elflink.c	2005-07-11 14:09:06.522248704 -0700
@@ -9859,6 +9859,7 @@ bfd_elf_set_symbol (struct elf_link_hash
   h->root.u.def.section = s ? s : bfd_abs_section_ptr;
   h->root.u.def.value = val;
   h->def_regular = 1;
+  h->provide = 1;
   h->type = STT_OBJECT;
   h->other = STV_HIDDEN | (h->other & ~ ELF_ST_VISIBILITY (-1));
   h->forced_local = 1;
@@ -9896,11 +9897,11 @@ _bfd_elf_provide_section_bound_symbols (
   /* Check if we need them or not first.  */
   hs = elf_link_hash_lookup (elf_hash_table (info), start, FALSE,
 			     FALSE, FALSE);
-  do_start = hs != NULL && !hs->def_regular;
+  do_start = hs != NULL && (hs->provide || !hs->def_regular);
 
   he = elf_link_hash_lookup (elf_hash_table (info), end, FALSE,
 			     FALSE, FALSE);
-  do_end = he != NULL && !he->def_regular;
+  do_end = he != NULL && (he->provide || !he->def_regular);
 
   if (!do_start && !do_end)
     return;
--- binutils/ld/emultempl/aix.em.provide	2005-05-16 11:04:41.000000000 -0700
+++ binutils/ld/emultempl/aix.em	2005-07-11 14:09:06.528247716 -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-11 14:09:06.532247057 -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-11 14:09:06.534246727 -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-08 08:42:48.000000000 -0700
+++ binutils/ld/emultempl/elf32.em	2005-07-11 14:20:33.446986269 -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_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_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_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_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-11 14:09:06.551243928 -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-11 14:09:06.552243763 -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-11 14:09:06.554243434 -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-08 08:42:48.000000000 -0700
+++ binutils/ld/emultempl/hppaelf.em	2005-07-11 14:09:06.557242940 -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-11 14:09:06.559242610 -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-11 14:09:06.560242446 -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-11 14:09:06.561242281 -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.120561734 -0700
+++ binutils/ld/emultempl/pe.em	2005-07-11 14:09:06.563241951 -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-08 08:42:48.000000000 -0700
+++ binutils/ld/emultempl/ppc64elf.em	2005-07-11 14:09:06.565241622 -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-11 14:09:06.574240140 -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-11 14:09:06.575239975 -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-11 14:09:06.576239810 -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-11 14:09:06.583238658 -0700
@@ -100,6 +100,13 @@ ldemul_set_symbols (void)
 }
 
 void
+ldemul_provide_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-11 14:09:06.584238493 -0700
@@ -51,6 +51,8 @@ extern void ldemul_finish
   (void);
 extern void ldemul_set_symbols
   (void);
+extern void ldemul_provide_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-11 14:09:06.506251339 -0700
+++ binutils/ld/ldlang.c	2005-07-11 14:09:06.590237505 -0700
@@ -4593,6 +4593,9 @@ lang_do_assignments (void)
 {
   lang_statement_iteration++;
   lang_do_assignments_1 (statement_list.head, abs_output_section, NULL, 0);
+
+  /* Assign values for symbols provided by emulation.  */
+  ldemul_provide_symbols ();
 }
 
 /* Fix any .startof. or .sizeof. symbols.  When the assemblers see the



More information about the Binutils mailing list