This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
--gc-sections -r
- From: Alan Modra <amodra at gmail dot com>
- To: binutils at sourceware dot org
- Date: Thu, 28 Oct 2010 17:15:46 +1030
- Subject: --gc-sections -r
v850-elf fails "--gc-sections -r without -e" because the v850 linker
script contains EXTERN(). We don't distinguish these from symbols
given with -u on the command line, but the intention was to require a
command line -u or -e with --gc-sections -r. Like so.
* ldlang.h (ldlang_add_undef): Add cmdline param.
* ldlang.c (undef_from_cmdline): New var.
(ldlang_add_undef): Add cmdline param. Set undef_from_cmdline.
(lang_end): Really require -e or -u from command line on
relocatable --gc-sections.
* ldemul.c (after_parse_default): Adjust ldlang_add_undef call.
* ldgram.y (extern_name_list_body): Likewise.
* lexsup.c (parse_args): Likewise.
* emultempl/aix.em (gld${EMULATION_NAME}_read_file): Likewise.
Index: ld/ldemul.c
===================================================================
RCS file: /cvs/src/src/ld/ldemul.c,v
retrieving revision 1.33
diff -u -p -r1.33 ldemul.c
--- ld/ldemul.c 13 Sep 2009 07:19:18 -0000 1.33
+++ ld/ldemul.c 28 Oct 2010 03:49:48 -0000
@@ -219,7 +219,7 @@ after_parse_default (void)
is_vma = *send == '\0';
}
if (!is_vma)
- ldlang_add_undef (entry_symbol.name);
+ ldlang_add_undef (entry_symbol.name, entry_from_cmdline);
}
}
Index: ld/ldgram.y
===================================================================
RCS file: /cvs/src/src/ld/ldgram.y,v
retrieving revision 1.61
diff -u -p -r1.61 ldgram.y
--- ld/ldgram.y 5 Nov 2009 15:35:50 -0000 1.61
+++ ld/ldgram.y 28 Oct 2010 03:49:48 -0000
@@ -287,11 +287,11 @@ extern_name_list:
extern_name_list_body:
NAME
- { ldlang_add_undef ($1); }
+ { ldlang_add_undef ($1, FALSE); }
| extern_name_list_body NAME
- { ldlang_add_undef ($2); }
+ { ldlang_add_undef ($2, FALSE); }
| extern_name_list_body ',' NAME
- { ldlang_add_undef ($3); }
+ { ldlang_add_undef ($3, FALSE); }
;
script_file:
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.344
diff -u -p -r1.344 ldlang.c
--- ld/ldlang.c 14 Oct 2010 01:31:31 -0000 1.344
+++ ld/ldlang.c 28 Oct 2010 06:30:39 -0000
@@ -101,6 +101,7 @@ lang_statement_list_type input_file_chai
struct bfd_sym_chain entry_symbol = { NULL, NULL };
const char *entry_section = ".text";
bfd_boolean entry_from_cmdline;
+bfd_boolean undef_from_cmdline;
bfd_boolean lang_has_input_file = FALSE;
bfd_boolean had_output_filename = FALSE;
bfd_boolean lang_float_flag = FALSE;
@@ -3297,11 +3298,12 @@ typedef struct bfd_sym_chain ldlang_unde
#define ldlang_undef_chain_list_head entry_symbol.next
void
-ldlang_add_undef (const char *const name)
+ldlang_add_undef (const char *const name, bfd_boolean cmdline)
{
- ldlang_undef_chain_list_type *new_undef = (ldlang_undef_chain_list_type *)
- stat_alloc (sizeof (ldlang_undef_chain_list_type));
+ ldlang_undef_chain_list_type *new_undef;
+ undef_from_cmdline = undef_from_cmdline || cmdline;
+ new_undef = (ldlang_undef_chain_list_type *) stat_alloc (sizeof (*new_undef));
new_undef->next = ldlang_undef_chain_list_head;
ldlang_undef_chain_list_head = new_undef;
@@ -5583,8 +5585,7 @@ lang_end (void)
/* Force the user to specify a root when generating a relocatable with
--gc-sections. */
if (link_info.gc_sections && link_info.relocatable
- && (entry_symbol.name == NULL
- && ldlang_undef_chain_list_head == NULL))
+ && !(entry_from_cmdline || undef_from_cmdline))
einfo (_("%P%F: gc-sections requires either an entry or "
"an undefined symbol\n"));
Index: ld/ldlang.h
===================================================================
RCS file: /cvs/src/src/ld/ldlang.h,v
retrieving revision 1.90
diff -u -p -r1.90 ldlang.h
--- ld/ldlang.h 14 Oct 2010 01:31:31 -0000 1.90
+++ ld/ldlang.h 28 Oct 2010 03:49:49 -0000
@@ -568,7 +568,7 @@ extern lang_output_section_statement_typ
extern lang_output_section_statement_type *next_matching_output_section_statement
(lang_output_section_statement_type *, int);
extern void ldlang_add_undef
- (const char *const);
+ (const char *const, bfd_boolean);
extern void lang_add_output_format
(const char *, const char *, const char *, int);
extern void lang_list_init
Index: ld/lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.119
diff -u -p -r1.119 lexsup.c
--- ld/lexsup.c 14 Oct 2010 01:31:31 -0000 1.119
+++ ld/lexsup.c 28 Oct 2010 03:49:50 -0000
@@ -1307,7 +1307,7 @@ parse_args (unsigned argc, char **argv)
config.dynamic_link = FALSE;
break;
case 'u':
- ldlang_add_undef (optarg);
+ ldlang_add_undef (optarg, TRUE);
break;
case OPTION_UNIQUE:
if (optarg != NULL)
Index: ld/emultempl/aix.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/aix.em,v
retrieving revision 1.54
diff -u -p -r1.54 aix.em
--- ld/emultempl/aix.em 27 Jun 2010 04:07:54 -0000 1.54
+++ ld/emultempl/aix.em 28 Oct 2010 03:49:50 -0000
@@ -1193,7 +1193,7 @@ gld${EMULATION_NAME}_read_file (const ch
{
struct export_symbol_list *n;
- ldlang_add_undef (symname);
+ ldlang_add_undef (symname, TRUE);
n = ((struct export_symbol_list *)
xmalloc (sizeof (struct export_symbol_list)));
n->next = export_symbols;
--
Alan Modra
Australia Development Lab, IBM