]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
PR ld/6766
authorAlan Modra <amodra@gmail.com>
Sun, 13 Sep 2009 07:19:18 +0000 (07:19 +0000)
committerAlan Modra <amodra@gmail.com>
Sun, 13 Sep 2009 07:19:18 +0000 (07:19 +0000)
* 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.
* scripttempl/elf32cr16.sc: No need to make entry extern.
* scripttempl/elf32cr16c.sc: Likewise.
* scripttempl/elf32crx.sc: Likewise.
* scripttempl/elf32xc16xs.sc: Only provide ENTRY on final link.

14 files changed:
ld/ChangeLog
ld/emultempl/alphaelf.em
ld/emultempl/cr16elf.em
ld/emultempl/crxelf.em
ld/emultempl/hppaelf.em
ld/emultempl/ia64elf.em
ld/emultempl/pe.em
ld/emultempl/pep.em
ld/ldemul.c
ld/lexsup.c
ld/scripttempl/elf32cr16.sc
ld/scripttempl/elf32cr16c.sc
ld/scripttempl/elf32crx.sc
ld/scripttempl/elf32xc16xs.sc

index 8d7288266eb45fa17710337a63ecebd2f03a29b0..94dd411f7d8bfab8166732c9e3c429e4b5a188b9 100644 (file)
@@ -1,3 +1,21 @@
+2009-09-13  Alan Modra  <amodra@bigpond.net.au>
+
+       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.
+       * scripttempl/elf32cr16.sc: No need to make entry extern.
+       * scripttempl/elf32cr16c.sc: Likewise.
+       * scripttempl/elf32crx.sc: Likewise.
+       * scripttempl/elf32xc16xs.sc: Only provide ENTRY on final link.
+
 2009-09-11  Nick Clifton  <nickc@redhat.com>
 
        * po/ld.pot: Updated by the Translation project.
index 1bee6f90e7131d208fc6031d895621fceb387805..864e6998acb5455064f94f06e12ba3d5b612e40a 100644 (file)
@@ -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 3c66f6642c39f9771ec135e8cedd9e942d28670a..83f07834b5ce6e3c4ca700b9fe910b8b0c6a0c27 100644 (file)
@@ -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 d177a611116e1f256c306c1674126236aa37614c..a257c06d5809fab243d54139a02a81a0664691ed 100644 (file)
@@ -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 1f9a3075ee09e476bf162015278ab66dbe4fa106..3ce5d54af7f3c657a79b55935fe815d95bcf504a 100644 (file)
@@ -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 b29e16cff656d3f01169f678626f656298865663..88d57480af7a8c3c0a54047616329d42dc8a9180 100644 (file)
@@ -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 2437bfb91a28f6ee080589fc270de6e5648d469e..788818d657f171a5bcbe1fbd6aa1d4eaa8b7de7d 100644 (file)
@@ -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 e4519c576e1440e1e07817342fbde5c9896876e0..90af02052df0eb224857a9657a7d29bb61732864 100644 (file)
@@ -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,
index b29703627f51b22bdad5fbf21d9498d060db76d5..c77eeb0eb54cdb453f9b8071bb7772069e685236 100644 (file)
@@ -192,9 +192,35 @@ ldemul_default_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
   return ld_emulation->target_name;
 }
 
+/* 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.
+
+   We don't do this when generating shared libraries unless given -e
+   on the command line, because most shared libs are not designed to
+   be run as an executable.  However, some are, eg. glibc ld.so and
+   may rely on the default linker script supplying ENTRY.  So we can't
+   remove the ENTRY from the script, but would rather not insert
+   undefined _start syms.  */
+
 void
 after_parse_default (void)
 {
+  if (entry_symbol.name != NULL
+      && (link_info.executable || entry_from_cmdline))
+    {
+      bfd_boolean is_vma = FALSE;
+
+      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 d3d6e569837bd1ecd9057693a3ad7e068a41fe1b..47c72dba6a21bb70f3e773256765874cfc3588e1 100644 (file)
@@ -832,7 +832,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 7c357c145d4378b64f96cbb1c80df0b028d11c6d..61351c579bdfa6e2ddf54a641afdf4782dc05970 100644 (file)
@@ -10,14 +10,8 @@ cat <<EOF
 
 /* Example Linker Script for linking NS CR16 elf32 files. */
 
-/* The next line forces the entry point (${ENTRY} in this script)
-   to be entered in the output file as an undefined symbol.
-   It is needed in case the entry point is not called explicitly
-   (which is the usual case) AND is in an archive.  */
-
 OUTPUT_FORMAT("${OUTPUT_FORMAT}")
 OUTPUT_ARCH(${ARCH})
-${RELOCATING+EXTERN(${ENTRY})}
 ${RELOCATING+ENTRY(${ENTRY})}
 
 /* Define memory regions.  */
index 56bab60379c03b33fc38a146dcdf26a0508a53fb..84fc61c617d2ccaef6888c582a7853b7553877cf 100644 (file)
@@ -7,12 +7,6 @@ cat <<EOF
    elf32 files, which were compiled with either the near data
    model or the default data model.  */
 
-/* Force the entry point to be entered in the output file as
-   an undefined symbol. This is needed in case the entry point
-   (which is not called explicitly) is in an archive (which is
-   the usual case).  */
-
-${RELOCATING+EXTERN(${ENTRY})}
 ${RELOCATING+ENTRY(${ENTRY})}
 
 MEMORY
index 514254a3bc75c3a9ba9554adf8775f24a1c04e6b..c320bda93e60e7cea618fe377c698ba917eaff58 100644 (file)
@@ -10,14 +10,8 @@ cat <<EOF
 
 /* Example Linker Script for linking NS CRX elf32 files. */
 
-/* The next line forces the entry point (${ENTRY} in this script)
-   to be entered in the output file as an undefined symbol.
-   It is needed in case the entry point is not called explicitly
-   (which is the usual case) AND is in an archive.  */
-
 OUTPUT_FORMAT("${OUTPUT_FORMAT}")
 OUTPUT_ARCH(${ARCH})
-${RELOCATING+EXTERN(${ENTRY})}
 ${RELOCATING+ENTRY(${ENTRY})}
 
 /* Define memory regions.  */
index 215b50ae9c73902d28d145dce330afda8f997692..3565ecec36746b889bee6c7c55e2b0df4e8ec4bb 100644 (file)
@@ -1,7 +1,7 @@
 cat <<EOF
 OUTPUT_FORMAT("${OUTPUT_FORMAT}")
 OUTPUT_ARCH(${ARCH})
-ENTRY("_start")
+${RELOCATING+ENTRY ("_start")}
 MEMORY
 {
        vectarea : o =0xc00000, l = 0x0300