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: ld -e number makes an entry in symbol table


On Fri, Sep 11, 2009 at 10:54:15AM +0930, Alan Modra wrote:
> Good, that's what I think too.  The ldlang_add_undef should happen
> in main just before the ldemul_after_parse call, and be just like the
> existing calls in pe.em/pep.em, ie. don't add the undef when
> relocatable, and of course not for -e <number>.

Even better, move the ldlang_add_undef call into ldemul_after_parse so
that targets can override this action.

This patch does cause some testsuite failures because we don't bother
defining entry symbols in many of our tests.  I'll commit it after
fixing all the failures that show up.

     	PR ld/6766
	* lexsup.c (parse_args <-e>): Revert 2009-03-18 change.
	* ldemul.c (after_parse_default): Add entry symbol as undef.
	* emultempl/alphaelf.em (alpha_after_parse): Call after_parse_default.
	* emultempl/cr16elf.em (cr16elf_after_parse): Likewise.
	* emultempl/crxelf.em (crxelf_after_parse): Likewise.
	* emultempl/hppaelf.em (hppaelf_after_parse): Likewise.
	* emultempl/ia64elf.em (gld${EMULATION_NAME}_after_parse): Likewise.
	* emultempl/pe.em (gld_${EMULATION_NAME}_after_parse): Call
	after_parse_default and delete now duplicate code.
	* emultempl/pep.em (gld_${EMULATION_NAME}_after_parse): Likewise.

Index: ld/lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.113
diff -u -p -r1.113 lexsup.c
--- ld/lexsup.c	2 Sep 2009 07:25:35 -0000	1.113
+++ ld/lexsup.c	11 Sep 2009 05:54:10 -0000
@@ -828,7 +828,6 @@ parse_args (unsigned argc, char **argv)
 	  break;
 	case 'e':
 	  lang_add_entry (optarg, TRUE);
-	  ldlang_add_undef (optarg);
 	  break;
 	case 'f':
 	  if (command_line.auxiliary_filters == NULL)
Index: ld/ldemul.c
===================================================================
RCS file: /cvs/src/src/ld/ldemul.c,v
retrieving revision 1.32
diff -u -p -r1.32 ldemul.c
--- ld/ldemul.c	30 Aug 2009 05:47:43 -0000	1.32
+++ ld/ldemul.c	11 Sep 2009 05:54:09 -0000
@@ -195,6 +195,25 @@ ldemul_default_target (int argc ATTRIBUT
 void
 after_parse_default (void)
 {
+  if (!link_info.relocatable
+      && entry_symbol.name != NULL)
+    {
+      bfd_boolean is_vma = FALSE;
+
+      /* If the entry point was not specified as an address, then add
+	 the symbol as undefined.  This will cause ld to extract an
+	 archive element defining the entry if ld is linking against
+	 such an archive.  */
+      if (entry_from_cmdline)
+	{
+	  const char *send;
+
+	  bfd_scan_vma (entry_symbol.name, &send, 0);
+	  is_vma = *send == '\0';
+	}
+      if (!is_vma)
+	ldlang_add_undef (entry_symbol.name);
+    }
 }
 
 void
Index: ld/emultempl/alphaelf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/alphaelf.em,v
retrieving revision 1.14
diff -u -p -r1.14 alphaelf.em
--- ld/emultempl/alphaelf.em	2 Sep 2009 07:25:35 -0000	1.14
+++ ld/emultempl/alphaelf.em	11 Sep 2009 05:54:11 -0000
@@ -80,6 +80,8 @@ alpha_after_parse (void)
 				   exp_intop (ALPHA_TEXT_START_32BIT),
 				   exp_nameop (SIZEOF_HEADERS, NULL)),
 			NULL);
+
+  after_parse_default ();
 }
 
 static void
Index: ld/emultempl/cr16elf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/cr16elf.em,v
retrieving revision 1.5
diff -u -p -r1.5 cr16elf.em
--- ld/emultempl/cr16elf.em	2 Sep 2009 07:25:35 -0000	1.5
+++ ld/emultempl/cr16elf.em	11 Sep 2009 05:54:11 -0000
@@ -1,5 +1,5 @@
 # This shell script emits a C file. -*- C -*-
-# Copyright 2007, 2008 Free Software Foundation, Inc.
+# Copyright 2007, 2008, 2009 Free Software Foundation, Inc.
 # Contributed by M R Swami Reddy <MR.Swami.Reddy@nsc.com>
 #
 # This file is part of the GNU Binutils.
@@ -121,6 +121,8 @@ cr16elf_after_parse (void)
      meaninful in CR16 embedded systems. Moreover, when magic_demand_paged
      is true the link sometimes fails.  */
   config.magic_demand_paged = FALSE;
+
+  after_parse_default ();
 }
 
 /* This is called after the sections have been attached to output
Index: ld/emultempl/crxelf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/crxelf.em,v
retrieving revision 1.6
diff -u -p -r1.6 crxelf.em
--- ld/emultempl/crxelf.em	2 Sep 2009 07:25:35 -0000	1.6
+++ ld/emultempl/crxelf.em	11 Sep 2009 05:54:11 -0000
@@ -1,5 +1,5 @@
 # This shell script emits a C file. -*- C -*-
-#   Copyright 2004, 2005, 2007
+#   Copyright 2004, 2005, 2007, 2009
 #   Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
@@ -45,6 +45,8 @@ crxelf_after_parse (void)
      meaninful in CRX embedded systems. Moreover, when magic_demand_paged
      is true the link sometimes fails.  */
   config.magic_demand_paged = FALSE;
+
+  after_parse_default ();
 }
 
 /* This is called after the sections have been attached to output
Index: ld/emultempl/hppaelf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/hppaelf.em,v
retrieving revision 1.54
diff -u -p -r1.54 hppaelf.em
--- ld/emultempl/hppaelf.em	2 Sep 2009 07:25:35 -0000	1.54
+++ ld/emultempl/hppaelf.em	11 Sep 2009 05:54:11 -0000
@@ -59,6 +59,8 @@ hppaelf_after_parse (void)
      			  lang_input_file_is_l_enum,
 			  NULL);
   */
+
+  after_parse_default ();
 }
 
 /* This is called before the input files are opened.  We create a new
Index: ld/emultempl/ia64elf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/ia64elf.em,v
retrieving revision 1.9
diff -u -p -r1.9 ia64elf.em
--- ld/emultempl/ia64elf.em	2 Sep 2009 07:25:35 -0000	1.9
+++ ld/emultempl/ia64elf.em	11 Sep 2009 05:54:11 -0000
@@ -1,5 +1,5 @@
 # This shell script emits a C file. -*- C -*-
-#   Copyright 2003, 2005, 2006, 2007 Free Software Foundation, Inc.
+#   Copyright 2003, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
 #
 # This file is part of the GNU Binutils.
 #
@@ -35,6 +35,8 @@ gld${EMULATION_NAME}_after_parse (void)
 {
   link_info.relax_pass = 2;
   bfd_elf${ELFSIZE}_ia64_after_parse (itanium);
+
+  after_parse_default ();
 }
 
 EOF
Index: ld/emultempl/pe.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/pe.em,v
retrieving revision 1.150
diff -u -p -r1.150 pe.em
--- ld/emultempl/pe.em	15 May 2009 14:22:35 -0000	1.150
+++ ld/emultempl/pe.em	11 Sep 2009 05:54:13 -0000
@@ -877,27 +877,13 @@ gld_${EMULATION_NAME}_set_symbols (void)
 static void
 gld_${EMULATION_NAME}_after_parse (void)
 {
-  /* The Windows libraries are designed for the linker to treat the
-     entry point as an undefined symbol.  Otherwise, the .obj that
-     defines mainCRTStartup is brought in because it is the first
-     encountered in libc.lib and it has other symbols in it which will
-     be pulled in by the link process.  To avoid this, we act as
-     though the user specified -u with the entry point symbol.
-
-     This function is called after the linker script and command line
-     options have been read, so at this point we know the right entry
-     point.  This function is called before the input files are
-     opened, so registering the symbol as undefined will make a
-     difference.  */
-
-  if (! link_info.relocatable && entry_symbol.name != NULL)
-    ldlang_add_undef (entry_symbol.name);
-
   /* PR ld/6744:  Warn the user if they have used an ELF-only
      option hoping it will work on PE.  */
   if (link_info.export_dynamic)
     einfo (_("%P: warning: --export-dynamic is not supported for PE "
       "targets, did you mean --export-all-symbols?\n"));
+
+  after_parse_default ();
 }
 
 /* pe-dll.c directly accesses pe_data_import_dll,
Index: ld/emultempl/pep.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/pep.em,v
retrieving revision 1.27
diff -u -p -r1.27 pep.em
--- ld/emultempl/pep.em	15 May 2009 14:22:35 -0000	1.27
+++ ld/emultempl/pep.em	11 Sep 2009 05:54:14 -0000
@@ -814,27 +814,13 @@ gld_${EMULATION_NAME}_set_symbols (void)
 static void
 gld_${EMULATION_NAME}_after_parse (void)
 {
-  /* The Windows libraries are designed for the linker to treat the
-     entry point as an undefined symbol.  Otherwise, the .obj that
-     defines mainCRTStartup is brought in because it is the first
-     encountered in libc.lib and it has other symbols in it which will
-     be pulled in by the link process.  To avoid this, we act as
-     though the user specified -u with the entry point symbol.
-
-     This function is called after the linker script and command line
-     options have been read, so at this point we know the right entry
-     point.  This function is called before the input files are
-     opened, so registering the symbol as undefined will make a
-     difference.  */
-
-  if (! link_info.relocatable && entry_symbol.name != NULL)
-    ldlang_add_undef (entry_symbol.name);
-
   /* PR ld/6744:  Warn the user if they have used an ELF-only
      option hoping it will work on PE+.  */
   if (link_info.export_dynamic)
     einfo (_("%P: warning: --export-dynamic is not supported for PE+ "
       "targets, did you mean --export-all-symbols?\n"));
+
+  after_parse_default ();
 }
 
 /* pep-dll.c directly accesses pep_data_import_dll,

-- 
Alan Modra
Australia Development Lab, IBM


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