From: Alan Modra Date: Sun, 13 Sep 2009 07:19:18 +0000 (+0000) Subject: PR ld/6766 X-Git-Tag: gdb_7_0-2009-09-16-branchpoint~41 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=97b11f4094739634d104156f5c586ba7916ef0fa;p=external%2Fbinutils.git 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. --- diff --git a/ld/ChangeLog b/ld/ChangeLog index 8d72882..94dd411 100644 --- a/ld/ChangeLog +++ b/ld/ChangeLog @@ -1,3 +1,21 @@ +2009-09-13 Alan Modra + + 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 * po/ld.pot: Updated by the Translation project. diff --git a/ld/emultempl/alphaelf.em b/ld/emultempl/alphaelf.em index 1bee6f9..864e699 100644 --- a/ld/emultempl/alphaelf.em +++ b/ld/emultempl/alphaelf.em @@ -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 diff --git a/ld/emultempl/cr16elf.em b/ld/emultempl/cr16elf.em index 3c66f66..83f0783 100644 --- a/ld/emultempl/cr16elf.em +++ b/ld/emultempl/cr16elf.em @@ -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 # # 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 diff --git a/ld/emultempl/crxelf.em b/ld/emultempl/crxelf.em index d177a61..a257c06 100644 --- a/ld/emultempl/crxelf.em +++ b/ld/emultempl/crxelf.em @@ -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 diff --git a/ld/emultempl/hppaelf.em b/ld/emultempl/hppaelf.em index 1f9a307..3ce5d54 100644 --- a/ld/emultempl/hppaelf.em +++ b/ld/emultempl/hppaelf.em @@ -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 diff --git a/ld/emultempl/ia64elf.em b/ld/emultempl/ia64elf.em index b29e16c..88d5748 100644 --- a/ld/emultempl/ia64elf.em +++ b/ld/emultempl/ia64elf.em @@ -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 diff --git a/ld/emultempl/pe.em b/ld/emultempl/pe.em index 2437bfb..788818d 100644 --- a/ld/emultempl/pe.em +++ b/ld/emultempl/pe.em @@ -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, diff --git a/ld/emultempl/pep.em b/ld/emultempl/pep.em index e4519c5..90af020 100644 --- a/ld/emultempl/pep.em +++ b/ld/emultempl/pep.em @@ -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, diff --git a/ld/ldemul.c b/ld/ldemul.c index b297036..c77eeb0 100644 --- a/ld/ldemul.c +++ b/ld/ldemul.c @@ -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 diff --git a/ld/lexsup.c b/ld/lexsup.c index d3d6e56..47c72db 100644 --- a/ld/lexsup.c +++ b/ld/lexsup.c @@ -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) diff --git a/ld/scripttempl/elf32cr16.sc b/ld/scripttempl/elf32cr16.sc index 7c357c1..61351c5 100644 --- a/ld/scripttempl/elf32cr16.sc +++ b/ld/scripttempl/elf32cr16.sc @@ -10,14 +10,8 @@ cat <