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 - fix for bug 13343


This patch saves the current script file name info in an expression
tree, and changes vfinfo %S to take an expression tree arg if
available.  There are rather a lot of error messages in ldexp.c that
benefit from this change, since many expressions are not evaluated
immediately.

Besides now giving correct file/line numbers, I made a change to
--defsym errors.  Instead of copying the command line option, ld now
reports --defsym:n for the nth --defsym on the line.  Some examples:

$ ld --defsym z=0 --defsym 'x=\4' hello.o
built in linker script:205: undefined symbol `\4' referenced in expression
$ ld --defsym z=0 --defsym 'y=()' hello.o
ld:--defsym y=(): ignoring invalid character `(' in expression
ld:--defsym y=(): ignoring invalid character `)' in expression
ld:--defsym y=(): syntax error

are now reported as

$ ld --defsym z=0 --defsym 'x=\4' hello.o
--defsym:2: undefined symbol `\4' referenced in expression
$ ld --defsym z=0 --defsym 'y=()' hello.o
ld/ld-new:--defsym:2: ignoring invalid character `(' in expression
ld/ld-new:--defsym:2: ignoring invalid character `)' in expression
ld/ld-new:--defsym:2: syntax error

	PR ld/13343
	* ld.h (parsing_defsym): Delete.
	* ldexp.c (exp_intop, exp_bigintop, exp_relop): Set type.filename.
	(fold_binary, fold_name, exp_fold_tree_1, exp_get_vma, exp_get_fill,
	exp_get_abs_int): Add tree arg for %S in error messages.  Don't
	fudge lineno.
	(exp_binop, exp_unop, exp_nameop, exp_assop, exp_assert): Copy
	type.filename from sub-tree.
	(exp_trinop): Likewise, and use "cond" rather than "lhs".
	* ldexp.h (node_type): Add filename field to struct.
	* ldfile.c (ldfile_input_filename): Delete.  Remove all refs.
	* ldfile.h (ldfile_input_filename): Delete.
	* ldgram.y (phdr_type, phdr_qualifiers, yyerror): Add NULL arg for
	%S in error messages.
	* ldemul.c (syslib_default, hll_default): Likewise.
	* ldlang.c (lang_memory_region_lookup, lang_memory_region_alias,
	lang_get_regions, lang_new_phdr): Likewise.
	(lang_size_sections_1): Pass addr_tree for %S.
	* ldlex.h (lex_redirect): Update prototype.
	(ldlex_filename): Declare.
	* ldlex.l (<EOF>): Don't set ldfile_input_filename.
	(lex_redirect): Add fake_filename and count params.  Push
	fake_filename to file_name_stack and init lineno from count.
	(ldlex_filename): New function.
	(lex_warn_invalid): Use above.
	* ldmain.c (main): Update lex_redirect call.
	* ldmisc.c (vfinfo <%S>): Take file name and line number from
	etree_type arg, or use current if arg is NULL.
	* lexsup.c (parsing_defsym): Delete.
	(parse_args <OPTION_DEFSYM>): Update lex_redirect call.

Index: ld/ld.h
===================================================================
RCS file: /cvs/src/src/ld/ld.h,v
retrieving revision 1.52
diff -u -p -r1.52 ld.h
--- ld/ld.h	16 Jul 2011 07:58:40 -0000	1.52
+++ ld/ld.h	17 Feb 2012 04:25:17 -0000
@@ -1,6 +1,6 @@
 /* ld.h -- general linker header file
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
 
    This file is part of the GNU Binutils.
@@ -326,9 +326,6 @@ extern ld_config_type config;
 extern FILE * saved_script_handle;
 extern bfd_boolean force_make_executable;
 
-/* Non-zero if we are processing a --defsym from the command line.  */
-extern int parsing_defsym;
-
 extern int yyparse (void);
 extern void add_cref (const char *, bfd *, asection *, bfd_vma);
 extern bfd_boolean handle_asneeded_cref (bfd *, enum notice_asneeded_action);
Index: ld/ldemul.c
===================================================================
RCS file: /cvs/src/src/ld/ldemul.c,v
retrieving revision 1.37
diff -u -p -r1.37 ldemul.c
--- ld/ldemul.c	13 Jan 2011 13:34:54 -0000	1.37
+++ ld/ldemul.c	17 Feb 2012 04:25:17 -0000
@@ -1,6 +1,6 @@
 /* ldemul.c -- clearing house for ld emulation states
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2005, 2007, 2008, 2009, 2010, 2011
+   2001, 2002, 2003, 2005, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
 
    This file is part of the GNU Binutils.
@@ -262,13 +262,13 @@ set_output_arch_default (void)
 void
 syslib_default (char *ignore ATTRIBUTE_UNUSED)
 {
-  info_msg (_("%S SYSLIB ignored\n"));
+  info_msg (_("%S SYSLIB ignored\n"), NULL);
 }
 
 void
 hll_default (char *ignore ATTRIBUTE_UNUSED)
 {
-  info_msg (_("%S HLL ignored\n"));
+  info_msg (_("%S HLL ignored\n"), NULL);
 }
 
 ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST };
Index: ld/ldexp.c
===================================================================
RCS file: /cvs/src/src/ld/ldexp.c,v
retrieving revision 1.95
diff -u -p -r1.95 ldexp.c
--- ld/ldexp.c	16 May 2011 11:34:48 -0000	1.95
+++ ld/ldexp.c	17 Feb 2012 04:25:17 -0000
@@ -1,6 +1,6 @@
 /* This module handles expression trees.
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support <sac@cygnus.com>.
 
@@ -156,6 +156,7 @@ exp_intop (bfd_vma value)
 {
   etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->value));
   new_e->type.node_code = INT;
+  new_e->type.filename = ldlex_filename ();
   new_e->type.lineno = lineno;
   new_e->value.value = value;
   new_e->value.str = NULL;
@@ -168,6 +169,7 @@ exp_bigintop (bfd_vma value, char *str)
 {
   etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->value));
   new_e->type.node_code = INT;
+  new_e->type.filename = ldlex_filename ();
   new_e->type.lineno = lineno;
   new_e->value.value = value;
   new_e->value.str = str;
@@ -182,6 +184,7 @@ exp_relop (asection *section, bfd_vma va
 {
   etree_type *new_e = (etree_type *) stat_alloc (sizeof (new_e->rel));
   new_e->type.node_code = REL;
+  new_e->type.filename = ldlex_filename ();
   new_e->type.lineno = lineno;
   new_e->type.node_class = etree_rel;
   new_e->rel.section = section;
@@ -404,7 +407,7 @@ fold_binary (etree_type *tree)
 	    expld.result.value = ((bfd_signed_vma) lhs.value
 				  % (bfd_signed_vma) expld.result.value);
 	  else if (expld.phase != lang_mark_phase_enum)
-	    einfo (_("%F%S %% by zero\n"));
+	    einfo (_("%F%S %% by zero\n"), tree->binary.rhs);
 	  if (expld.result.section == lhs.section)
 	    expld.result.section = NULL;
 	  break;
@@ -414,7 +417,7 @@ fold_binary (etree_type *tree)
 	    expld.result.value = ((bfd_signed_vma) lhs.value
 				  / (bfd_signed_vma) expld.result.value);
 	  else if (expld.phase != lang_mark_phase_enum)
-	    einfo (_("%F%S / by zero\n"));
+	    einfo (_("%F%S / by zero\n"), tree->binary.rhs);
 	  if (expld.result.section == lhs.section)
 	    expld.result.section = NULL;
 	  break;
@@ -590,7 +592,7 @@ fold_name (etree_type *tree)
 		  if (expld.phase != lang_mark_phase_enum)
 		    einfo (_("%X%S: unresolvable symbol `%s'"
 			     " referenced in expression\n"),
-			   tree->name.name);
+			   tree, tree->name.name);
 		}
 	      else if (output_section == bfd_abs_section_ptr
 		       && (expld.section != bfd_abs_section_ptr
@@ -602,8 +607,9 @@ fold_name (etree_type *tree)
 	    }
 	  else if (expld.phase == lang_final_phase_enum
 		   || expld.assigning_to_dot)
-	    einfo (_("%F%S: undefined symbol `%s' referenced in expression\n"),
-		   tree->name.name);
+	    einfo (_("%F%S: undefined symbol `%s'"
+		     " referenced in expression\n"),
+		   tree, tree->name.name);
 	  else if (h->type == bfd_link_hash_new)
 	    {
 	      h->type = bfd_link_hash_undefined;
@@ -623,8 +629,9 @@ fold_name (etree_type *tree)
 	  if (os == NULL)
 	    {
 	      if (expld.phase == lang_final_phase_enum)
-		einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
-		       tree->name.name);
+		einfo (_("%F%S: undefined section `%s'"
+			 " referenced in expression\n"),
+		       tree, tree->name.name);
 	    }
 	  else if (os->processed_vma)
 	    new_rel (0, os->bfd_section);
@@ -640,8 +647,9 @@ fold_name (etree_type *tree)
 	  if (os == NULL)
 	    {
 	      if (expld.phase == lang_final_phase_enum)
-		einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
-		       tree->name.name);
+		einfo (_("%F%S: undefined section `%s'"
+			 " referenced in expression\n"),
+		       tree, tree->name.name);
 	    }
 	  else if (os->processed_lma)
 	    {
@@ -667,8 +675,9 @@ fold_name (etree_type *tree)
 	  if (os == NULL)
 	    {
 	      if (expld.phase == lang_final_phase_enum)
-		einfo (_("%F%S: undefined section `%s' referenced in expression\n"),
-		       tree->name.name);
+		einfo (_("%F%S: undefined section `%s'"
+			 " referenced in expression\n"),
+		       tree, tree->name.name);
 	      new_number (0);
 	    }
 	  else if (os->processed_vma)
@@ -695,7 +704,8 @@ fold_name (etree_type *tree)
           new_number (mem->length);
         else          
           einfo (_("%F%S: undefined MEMORY region `%s'"
-		   " referenced in expression\n"), tree->name.name);
+		   " referenced in expression\n"),
+		 tree, tree->name.name);
       }
       break;
 
@@ -709,7 +719,8 @@ fold_name (etree_type *tree)
 	    new_rel_from_abs (mem->origin);
 	  else          
 	    einfo (_("%F%S: undefined MEMORY region `%s'"
-		     " referenced in expression\n"), tree->name.name);
+		     " referenced in expression\n"),
+		   tree, tree->name.name);
 	}
       break;
 
@@ -720,7 +731,7 @@ fold_name (etree_type *tree)
 	new_number (config.commonpagesize);
       else
 	einfo (_("%F%S: unknown constant `%s' referenced in expression\n"),
-	       tree->name.name);
+	       tree, tree->name.name);
       break;
 
     default:
@@ -784,7 +795,8 @@ exp_fold_tree_1 (etree_type *tree)
       if (tree->assign.dst[0] == '.' && tree->assign.dst[1] == 0)
 	{
 	  if (tree->type.node_class != etree_assign)
-	    einfo (_("%F%S can not PROVIDE assignment to location counter\n"));
+	    einfo (_("%F%S can not PROVIDE assignment to"
+		     " location counter\n"), tree);
 	  /* After allocation, assignment to dot should not be done inside
 	     an output section since allocation adds a padding statement
 	     that effectively duplicates the assignment.  */
@@ -802,11 +814,12 @@ exp_fold_tree_1 (etree_type *tree)
 	      if (!expld.result.valid_p)
 		{
 		  if (expld.phase != lang_mark_phase_enum)
-		    einfo (_("%F%S invalid assignment to location counter\n"));
+		    einfo (_("%F%S invalid assignment to"
+			     " location counter\n"), tree);
 		}
 	      else if (expld.dotp == NULL)
 		einfo (_("%F%S assignment to location counter"
-			 " invalid outside of SECTION\n"));
+			 " invalid outside of SECTION\n"), tree);
 	      else
 		{
 		  bfd_vma nextdot;
@@ -819,7 +832,8 @@ exp_fold_tree_1 (etree_type *tree)
 		  if (nextdot < expld.dot
 		      && expld.section != bfd_abs_section_ptr)
 		    einfo (_("%F%S cannot move location counter backwards"
-			     " (from %V to %V)\n"), expld.dot, nextdot);
+			     " (from %V to %V)\n"),
+			   tree, expld.dot, nextdot);
 		  else
 		    {
 		      expld.dot = nextdot;
@@ -955,6 +969,7 @@ exp_binop (int code, etree_type *lhs, et
   etree_type value, *new_e;
 
   value.type.node_code = code;
+  value.type.filename = lhs->type.filename;
   value.type.lineno = lhs->type.lineno;
   value.binary.lhs = lhs;
   value.binary.rhs = rhs;
@@ -974,7 +989,8 @@ exp_trinop (int code, etree_type *cond, 
   etree_type value, *new_e;
 
   value.type.node_code = code;
-  value.type.lineno = lhs->type.lineno;
+  value.type.filename = cond->type.filename;
+  value.type.lineno = cond->type.lineno;
   value.trinary.lhs = lhs;
   value.trinary.cond = cond;
   value.trinary.rhs = rhs;
@@ -994,6 +1010,7 @@ exp_unop (int code, etree_type *child)
   etree_type value, *new_e;
 
   value.unary.type.node_code = code;
+  value.unary.type.filename = child->type.filename;
   value.unary.type.lineno = child->type.lineno;
   value.unary.child = child;
   value.unary.type.node_class = etree_unary;
@@ -1012,6 +1029,7 @@ exp_nameop (int code, const char *name)
   etree_type value, *new_e;
 
   value.name.type.node_code = code;
+  value.name.type.filename = ldlex_filename ();
   value.name.type.lineno = lineno;
   value.name.name = name;
   value.name.type.node_class = etree_name;
@@ -1036,6 +1054,7 @@ exp_assop (const char *dst,
 
   n = (etree_type *) stat_alloc (sizeof (n->assign));
   n->assign.type.node_code = '=';
+  n->assign.type.filename = src->type.filename;
   n->assign.type.lineno = src->type.lineno;
   n->assign.type.node_class = class;
   n->assign.src = src;
@@ -1073,6 +1092,7 @@ exp_assert (etree_type *exp, const char 
 
   n = (etree_type *) stat_alloc (sizeof (n->assert_s));
   n->assert_s.type.node_code = '!';
+  n->assert_s.type.filename = exp->type.filename;
   n->assert_s.type.lineno = exp->type.lineno;
   n->assert_s.type.node_class = etree_assert;
   n->assert_s.child = exp;
@@ -1188,7 +1208,8 @@ exp_get_vma (etree_type *tree, bfd_vma d
       if (expld.result.valid_p)
 	return expld.result.value;
       else if (name != NULL && expld.phase != lang_mark_phase_enum)
-	einfo (_("%F%S: nonconstant expression for %s\n"), name);
+	einfo (_("%F%S: nonconstant expression for %s\n"),
+	       tree, name);
     }
   return def;
 }
@@ -1213,7 +1234,8 @@ exp_get_fill (etree_type *tree, fill_typ
   if (!expld.result.valid_p)
     {
       if (name != NULL && expld.phase != lang_mark_phase_enum)
-	einfo (_("%F%S: nonconstant expression for %s\n"), name);
+	einfo (_("%F%S: nonconstant expression for %s\n"),
+	       tree, name);
       return def;
     }
 
@@ -1272,8 +1294,8 @@ exp_get_abs_int (etree_type *tree, int d
 	}
       else if (name != NULL && expld.phase != lang_mark_phase_enum)
 	{
-	  lineno = tree->type.lineno;
-	  einfo (_("%F%S: nonconstant expression for %s\n"), name);
+	  einfo (_("%F%S: nonconstant expression for %s\n"),
+		 tree, name);
 	}
     }
   return def;
Index: ld/ldexp.h
===================================================================
RCS file: /cvs/src/src/ld/ldexp.h,v
retrieving revision 1.29
diff -u -p -r1.29 ldexp.h
--- ld/ldexp.h	3 May 2011 14:56:14 -0000	1.29
+++ ld/ldexp.h	17 Feb 2012 04:25:17 -0000
@@ -1,6 +1,6 @@
 /* ldexp.h -
    Copyright 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001, 2002,
-   2003, 2004, 2005, 2007, 2011 Free Software Foundation, Inc.
+   2003, 2004, 2005, 2007, 2011, 2012 Free Software Foundation, Inc.
 
    This file is part of the GNU Binutils.
 
@@ -46,6 +46,7 @@ enum node_tree_enum {
 typedef struct {
   int node_code;
   unsigned int lineno;
+  const char *filename;
   enum node_tree_enum node_class;
 } node_type;
 
Index: ld/ldfile.c
===================================================================
RCS file: /cvs/src/src/ld/ldfile.c,v
retrieving revision 1.63
diff -u -p -r1.63 ldfile.c
--- ld/ldfile.c	20 Apr 2011 00:22:08 -0000	1.63
+++ ld/ldfile.c	17 Feb 2012 04:25:18 -0000
@@ -1,6 +1,6 @@
 /* Linker file opening and searching.
    Copyright 1991, 1992, 1993, 1994, 1995, 1998, 1999, 2000, 2001, 2002,
-   2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
+   2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
 
    This file is part of the GNU Binutils.
@@ -40,7 +40,6 @@
 #include "plugin.h"
 #endif /* ENABLE_PLUGINS */
 
-const char * ldfile_input_filename;
 bfd_boolean  ldfile_assumed_script = FALSE;
 const char * ldfile_output_machine_name = "";
 unsigned long ldfile_output_machine;
@@ -638,7 +637,6 @@ ldfile_open_command_file_1 (const char *
 
   lex_push_file (ldlex_input_stack, name);
 
-  ldfile_input_filename = name;
   lineno = 1;
 
   saved_script_handle = ldlex_input_stack;
Index: ld/ldfile.h
===================================================================
RCS file: /cvs/src/src/ld/ldfile.h,v
retrieving revision 1.18
diff -u -p -r1.18 ldfile.h
--- ld/ldfile.h	2 Sep 2009 07:25:35 -0000	1.18
+++ ld/ldfile.h	17 Feb 2012 04:25:18 -0000
@@ -1,6 +1,6 @@
 /* ldfile.h -
-   Copyright 1991, 1992, 1993, 1994, 1995, 2000, 2002, 2003, 2004, 2005, 2007
-   Free Software Foundation, Inc.
+   Copyright 1991, 1992, 1993, 1994, 1995, 2000, 2002, 2003, 2004, 2005,
+   2007, 2012 Free Software Foundation, Inc.
 
    This file is part of the GNU Binutils.
 
@@ -22,7 +22,6 @@
 #ifndef LDFILE_H
 #define LDFILE_H
 
-extern const char *ldfile_input_filename;
 extern bfd_boolean ldfile_assumed_script;
 extern unsigned long ldfile_output_machine;
 extern enum bfd_architecture ldfile_output_architecture;
Index: ld/ldgram.y
===================================================================
RCS file: /cvs/src/src/ld/ldgram.y,v
retrieving revision 1.67
diff -u -p -r1.67 ldgram.y
--- ld/ldgram.y	9 Feb 2012 05:26:13 -0000	1.67
+++ ld/ldgram.y	17 Feb 2012 04:25:18 -0000
@@ -1,6 +1,6 @@
 /* A YACC grammar to parse a superset of the AT&T linker scripting language.
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support (steve@cygnus.com).
 
@@ -1219,7 +1219,7 @@ phdr_type:
 			    {
 			      einfo (_("\
 %X%P:%S: unknown phdr type `%s' (try integer literal)\n"),
-				     s);
+				     NULL, s);
 			      $$ = exp_intop (0);
 			    }
 			}
@@ -1242,7 +1242,8 @@ phdr_qualifiers:
 		  else if (strcmp ($1, "FLAGS") == 0 && $2 != NULL)
 		    $$.flags = $2;
 		  else
-		    einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"), $1);
+		    einfo (_("%X%P:%S: PHDRS syntax error at `%s'\n"),
+			   NULL, $1);
 		}
 	|	AT '(' exp ')' phdr_qualifiers
 		{
@@ -1448,9 +1449,9 @@ yyerror(arg)
 {
   if (ldfile_assumed_script)
     einfo (_("%P:%s: file format not recognized; treating as linker script\n"),
-	   ldfile_input_filename);
+	   ldlex_filename ());
   if (error_index > 0 && error_index < ERROR_NAME_MAX)
-     einfo ("%P%F:%S: %s in %s\n", arg, error_names[error_index-1]);
+    einfo ("%P%F:%S: %s in %s\n", NULL, arg, error_names[error_index - 1]);
   else
-     einfo ("%P%F:%S: %s\n", arg);
+    einfo ("%P%F:%S: %s\n", NULL, arg);
 }
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.382
diff -u -p -r1.382 ldlang.c
--- ld/ldlang.c	31 Jan 2012 17:54:36 -0000	1.382
+++ ld/ldlang.c	17 Feb 2012 04:25:21 -0000
@@ -1312,12 +1312,13 @@ lang_memory_region_lookup (const char *c
         {
           if (create)
             einfo (_("%P:%S: warning: redeclaration of memory region `%s'\n"),
-                   name);
+                   NULL, name);
           return r;
         }
 
   if (!create && strcmp (name, DEFAULT_MEMORY_REGION))
-    einfo (_("%P:%S: warning: memory region `%s' not declared\n"), name);
+    einfo (_("%P:%S: warning: memory region `%s' not declared\n"),
+	   NULL, name);
 
   new_region = (lang_memory_region_type *)
       stat_alloc (sizeof (lang_memory_region_type));
@@ -1351,7 +1352,7 @@ lang_memory_region_alias (const char * a
      the default memory region.  */
   if (strcmp (region_name, DEFAULT_MEMORY_REGION) == 0
       || strcmp (alias, DEFAULT_MEMORY_REGION) == 0)
-    einfo (_("%F%P:%S: error: alias for default memory region\n"));
+    einfo (_("%F%P:%S: error: alias for default memory region\n"), NULL);
 
   /* Look for the target region and check if the alias is not already
      in use.  */
@@ -1364,15 +1365,14 @@ lang_memory_region_alias (const char * a
         if (strcmp (n->name, alias) == 0)
           einfo (_("%F%P:%S: error: redefinition of memory region "
                    "alias `%s'\n"),
-                 alias);
+                 NULL, alias);
       }
 
   /* Check if the target region exists.  */
   if (region == NULL)
     einfo (_("%F%P:%S: error: memory region `%s' "
              "for alias `%s' does not exist\n"),
-           region_name,
-           alias);
+           NULL, region_name, alias);
 
   /* Add alias to region name list.  */
   n = (lang_memory_region_name *) stat_alloc (sizeof (lang_memory_region_name));
@@ -4891,7 +4891,7 @@ lang_size_sections_1
 		else if (expld.phase != lang_mark_phase_enum)
 		  einfo (_("%F%S: non constant or forward reference"
 			   " address expression for section %s\n"),
-			 os->name);
+			 os->addr_tree, os->name);
 	      }
 
 	    if (os->bfd_section == NULL)
@@ -6948,7 +6951,8 @@ lang_get_regions (lang_memory_region_typ
     *region = lang_memory_region_lookup (memspec, FALSE);
 
   if (have_lma && lma_memspec != 0)
-    einfo (_("%X%P:%S: section has both a load address and a load region\n"));
+    einfo (_("%X%P:%S: section has both a load address and a load region\n"),
+	   NULL);
 }
 
 void
@@ -7135,7 +7139,8 @@ lang_new_phdr (const char *name,
 	&& (*pp)->type == 1
 	&& !((*pp)->filehdr || (*pp)->phdrs))
       {
-	einfo (_("%X%P:%S: PHDRS and FILEHDR are not supported when prior PT_LOAD headers lack them\n"));
+	einfo (_("%X%P:%S: PHDRS and FILEHDR are not supported"
+		 " when prior PT_LOAD headers lack them\n"), NULL);
 	hdrs = FALSE;
       }
 
Index: ld/ldlex.h
===================================================================
RCS file: /cvs/src/src/ld/ldlex.h,v
retrieving revision 1.8
diff -u -p -r1.8 ldlex.h
--- ld/ldlex.h	2 Sep 2009 07:25:35 -0000	1.8
+++ ld/ldlex.h	17 Feb 2012 04:25:21 -0000
@@ -1,6 +1,6 @@
 /* ldlex.h -
-   Copyright 1991, 1992, 1993, 1994, 1995, 1997, 2000, 2003, 2005, 2006, 2007
-   Free Software Foundation, Inc.
+   Copyright 1991, 1992, 1993, 1994, 1995, 1997, 2000, 2003, 2005, 2006,
+   2007, 2012 Free Software Foundation, Inc.
 
    This file is part of the GNU Binutils.
 
@@ -42,7 +42,7 @@ extern const char *lex_string;
 /* In ldlex.l.  */
 extern int yylex (void);
 extern void lex_push_file (FILE *, const char *);
-extern void lex_redirect (const char *);
+extern void lex_redirect (const char *, const char *, unsigned int);
 extern void ldlex_script (void);
 extern void ldlex_mri_script (void);
 extern void ldlex_version_script (void);
@@ -52,6 +52,7 @@ extern void ldlex_expression (void);
 extern void ldlex_both (void);
 extern void ldlex_command (void);
 extern void ldlex_popstate (void);
+extern const char* ldlex_filename (void);
 
 /* In lexsup.c.  */
 extern int lex_input (void);
Index: ld/ldlex.l
===================================================================
RCS file: /cvs/src/src/ld/ldlex.l,v
retrieving revision 1.53
diff -u -p -r1.53 ldlex.l
--- ld/ldlex.l	11 Jul 2011 15:03:09 -0000	1.53
+++ ld/ldlex.l	17 Feb 2012 13:22:38 -0000
@@ -3,7 +3,7 @@
 %{
 
 /* Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support.
 
@@ -448,17 +448,11 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([
 
 <<EOF>> {
   include_stack_ptr--;
-
   if (include_stack_ptr == 0)
-  {
     yyterminate ();
-  }
   else
-  {
     yy_switch_to_buffer (include_stack[include_stack_ptr]);
-  }
 
-  ldfile_input_filename = file_name_stack[include_stack_ptr - 1];
   lineno = lineno_stack[include_stack_ptr];
 
   return END;
@@ -534,7 +528,7 @@ yy_create_string_buffer (const char *str
    on the include stack.  */
 
 void
-lex_redirect (const char *string)
+lex_redirect (const char *string, const char *fake_filename, unsigned int count)
 {
   YY_BUFFER_STATE tmp;
 
@@ -543,11 +537,11 @@ lex_redirect (const char *string)
     {
       einfo("%F: macros nested too deeply\n");
     }
-  file_name_stack[include_stack_ptr] = "redirect";
+  file_name_stack[include_stack_ptr] = fake_filename;
   lineno_stack[include_stack_ptr] = lineno;
   include_stack[include_stack_ptr] = YY_CURRENT_BUFFER;
   include_stack_ptr++;
-  lineno = 1;
+  lineno = count;
   tmp = yy_create_string_buffer (string, strlen (string));
   yy_switch_to_buffer (tmp);
 }
@@ -612,6 +606,15 @@ ldlex_popstate (void)
 {
   yy_start = *(--state_stack_p);
 }
+
+/* Return the current file name, or the previous file if no file is
+   current.  */
+
+const char*
+ldlex_filename (void)
+{
+  return file_name_stack[include_stack_ptr - (include_stack_ptr != 0)];
+}
 
 
 /* Place up to MAX_SIZE characters in BUF and return
@@ -685,7 +688,7 @@ lex_warn_invalid (char *where, char *wha
   if (ldfile_assumed_script)
     {
       bfd_set_error (bfd_error_file_not_recognized);
-      einfo ("%F%s: file not recognized: %E\n", ldfile_input_filename);
+      einfo ("%F%s: file not recognized: %E\n", ldlex_filename ());
     }
 
   if (! ISPRINT (*what))
@@ -694,5 +697,5 @@ lex_warn_invalid (char *where, char *wha
       what = buf;
     }
 
-  einfo ("%P:%S: ignoring invalid character `%s'%s\n", what, where);
+  einfo ("%P:%S: ignoring invalid character `%s'%s\n", NULL, what, where);
 }
Index: ld/ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.161
diff -u -p -r1.161 ldmain.c
--- ld/ldmain.c	10 Oct 2011 12:43:14 -0000	1.161
+++ ld/ldmain.c	17 Feb 2012 04:25:22 -0000
@@ -1,6 +1,6 @@
 /* Main program of GNU linker.
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
+   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
    Free Software Foundation, Inc.
    Written by Steve Chamberlain steve@cygnus.com
 
@@ -327,7 +327,7 @@ main (int argc, char **argv)
       else
 	{
 	  lex_string = s;
-	  lex_redirect (s);
+	  lex_redirect (s, _("built in linker script"), 1);
 	}
       parser_input = input_script;
       yyparse ();
Index: ld/ldmisc.c
===================================================================
RCS file: /cvs/src/src/ld/ldmisc.c,v
retrieving revision 1.40
diff -u -p -r1.40 ldmisc.c
--- ld/ldmisc.c	23 May 2011 06:13:35 -0000	1.40
+++ ld/ldmisc.c	17 Feb 2012 13:22:38 -0000
@@ -1,6 +1,6 @@
 /* ldmisc.c
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2011
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2011, 2012
    Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support.
 
@@ -51,7 +51,7 @@
  %I filename from a lang_input_statement_type
  %P print program name
  %R info about a relent
- %S print script file and linenumber
+ %S print script file and linenumber from etree_type.
  %T symbol name
  %V hex bfd_vma
  %W hex bfd_vma with 0x with no leading zeros taking up 8 spaces
@@ -240,12 +240,19 @@ vfinfo (FILE *fp, const char *fmt, va_li
 
 	    case 'S':
 	      /* Print script file and linenumber.  */
-	      if (parsing_defsym)
-		fprintf (fp, "--defsym %s", lex_string);
-	      else if (ldfile_input_filename != NULL)
-		fprintf (fp, "%s:%u", ldfile_input_filename, lineno);
-	      else
-		fprintf (fp, _("built in linker script:%u"), lineno);
+	      {
+		node_type node;
+		etree_type *tp = va_arg (arg, etree_type *);
+
+		if (tp == NULL)
+		  {
+		    tp = (etree_type *) &node;
+		    tp->type.filename = ldlex_filename ();
+		    tp->type.lineno = lineno;
+		  }
+		if (tp->type.filename != NULL)
+		  fprintf (fp, "%s:%u", tp->type.filename, tp->type.lineno);
+	      }
 	      break;
 
 	    case 'R':
Index: ld/lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.128
diff -u -p -r1.128 lexsup.c
--- ld/lexsup.c	10 Oct 2011 12:43:14 -0000	1.128
+++ ld/lexsup.c	17 Feb 2012 13:22:38 -0000
@@ -1,6 +1,6 @@
 /* Parse options for the GNU linker.
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011
+   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012
    Free Software Foundation, Inc.
 
    This file is part of the GNU Binutils.
@@ -62,9 +62,6 @@ static void set_section_start (char *, c
 static void set_segment_start (const char *, char *);
 static void help (void);
 
-/* Non-zero if we are processing a --defsym from the command line.  */
-int parsing_defsym = 0;
-
 /* Codes used for the long options with no short synonyms.  150 isn't
    special; it's just an arbitrary non-ASCII char value.  */
 enum option_values
@@ -729,6 +726,7 @@ parse_args (unsigned argc, char **argv)
     {
       int longind;
       int optc;
+      static unsigned int defsym_count;
 
       /* Using last_optind lets us avoid calling ldemul_parse_args
 	 multiple times on a single option, which would lead to
@@ -823,11 +821,9 @@ parse_args (unsigned argc, char **argv)
 	  break;
 	case OPTION_DEFSYM:
 	  lex_string = optarg;
-	  lex_redirect (optarg);
+	  lex_redirect (optarg, "--defsym", ++defsym_count);
 	  parser_input = input_defsym;
-	  parsing_defsym = 1;
 	  yyparse ();
-	  parsing_defsym = 0;
 	  lex_string = NULL;
 	  break;
 	case OPTION_DEMANGLE:

-- 
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]