public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* PR 12001, --defsym
@ 2010-12-20 11:07 Alan Modra
  2010-12-29 17:35 ` H.J. Lu
  0 siblings, 1 reply; 15+ messages in thread
From: Alan Modra @ 2010-12-20 11:07 UTC (permalink / raw)
  To: binutils

This patch reverts Nick's support for early --defsym symbol creation,
and instead implements the same in open_input_bfds.  This is quite a
lot simpler, but the main reason for this patch is that I want to run
a pass over assignments early.  The idea being to control ld
expression behaviour by a magic assignment in a linker script.  One of
the benefits is that --defsym is restored to acting at the point it is
used on the command line, for example
 --defsym x=1 some_script --defsym x=2 some_script
could control actions in "some_script".  This positional behaviour
will also affect extraction of objects from archives.

ld/
	PR ld/12001
	Revert 2010-11-03 Nick Clifton
	* ldlang.c (ldlang_def_chain_list): Delete.
	(insert_defined, ldlang_add_def, lang_place_defineds): Delete.
	(lang_process): Don't call lang_place_defineds.
	(lang_add_assignment): Don't do anything special for --defsym.

	* ldexp.h (struct ldexp_control): Add uses_defined.
	(exp_fold_tree_no_dot): Declare.
	* ldexp.c (exp_fold_tree): Clear uses_defined.
	(exp_fold_tree_no_dot): Likewise.  Make global.
	(fold_name <DEFINED>): Set uses_defined.
	(exp_fold_tree_1 <etree_assign>): Define symbol during first phase
	even when the value being assigned isn't valid.
	* ldlang.c (open_input_bfds): Process assignment statements.
	(lang_process): Bump lang_statement_iteration.
	(scan_for_self_assignment): Formatting.
	(print_assignment): Style.

ld/testsuite/
	* ld-scripts/default-script2.d: Revert 2010-11-03 change.

Index: ld/ldexp.c
===================================================================
RCS file: /cvs/src/src/ld/ldexp.c,v
retrieving revision 1.87
diff -u -p -r1.87 ldexp.c
--- ld/ldexp.c	1 Oct 2010 08:15:41 -0000	1.87
+++ ld/ldexp.c	20 Dec 2010 04:44:33 -0000
@@ -44,7 +44,6 @@
 #include "safe-ctype.h"
 
 static void exp_fold_tree_1 (etree_type *);
-static void exp_fold_tree_no_dot (etree_type *);
 static bfd_vma align_n (bfd_vma, bfd_vma);
 
 segment_type *segments;
@@ -504,6 +503,7 @@ fold_name (etree_type *tree)
       break;
 
     case DEFINED:
+      expld.uses_defined = TRUE;
       if (expld.phase == lang_first_phase_enum)
 	lang_track_definedness (tree->name.name);
       else
@@ -802,7 +802,9 @@ exp_fold_tree_1 (etree_type *tree)
 	    }
 
 	  exp_fold_tree_1 (tree->assign.src);
-	  if (expld.result.valid_p)
+	  if (expld.result.valid_p
+	      || (expld.phase == lang_first_phase_enum
+		  && !expld.uses_defined))
 	    {
 	      if (h == NULL)
 		{
@@ -872,15 +874,17 @@ exp_fold_tree (etree_type *tree, asectio
   expld.dot = *dotp;
   expld.dotp = dotp;
   expld.section = current_section;
+  expld.uses_defined = FALSE;
   exp_fold_tree_1 (tree);
 }
 
-static void
+void
 exp_fold_tree_no_dot (etree_type *tree)
 {
   expld.dot = 0;
   expld.dotp = NULL;
   expld.section = bfd_abs_section_ptr;
+  expld.uses_defined = FALSE;
   exp_fold_tree_1 (tree);
 }
 
Index: ld/ldexp.h
===================================================================
RCS file: /cvs/src/src/ld/ldexp.h,v
retrieving revision 1.23
diff -u -p -r1.23 ldexp.h
--- ld/ldexp.h	11 Sep 2009 15:27:35 -0000	1.23
+++ ld/ldexp.h	20 Dec 2010 04:44:33 -0000
@@ -127,6 +127,7 @@ struct ldexp_control {
   /* Working results.  */
   etree_value_type result;
   bfd_vma dot;
+  bfd_boolean uses_defined;
 
   /* Current dot and section passed to ldexp folder.  */
   bfd_vma *dotp;
@@ -173,6 +174,8 @@ etree_type *exp_relop
   (asection *, bfd_vma);
 void exp_fold_tree
   (etree_type *, asection *, bfd_vma *);
+void exp_fold_tree_no_dot
+  (etree_type *);
 etree_type *exp_binop
   (int, etree_type *, etree_type *);
 etree_type *exp_trinop
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.353
diff -u -p -r1.353 ldlang.c
--- ld/ldlang.c	15 Dec 2010 14:56:37 -0000	1.353
+++ ld/ldlang.c	20 Dec 2010 04:44:36 -0000
@@ -3249,6 +3249,9 @@ open_input_bfds (lang_statement_union_ty
 		}
 	    }
 	  break;
+	case lang_assignment_statement_enum:
+	  exp_fold_tree_no_dot (s->assignment_statement.exp);
+	  break;
 	default:
 	  break;
 	}
@@ -3395,65 +3398,6 @@ lang_place_undefineds (void)
     insert_undefined (ptr->name);
 }
 
-typedef struct bfd_sym_chain ldlang_def_chain_list_type;
-
-static ldlang_def_chain_list_type ldlang_def_chain_list_head;
-
-/* Insert NAME as defined in the symbol table.  */
-
-static void
-insert_defined (const char *name)
-{
-  struct bfd_link_hash_entry *h;
-
-  h = bfd_link_hash_lookup (link_info.hash, name, TRUE, FALSE, TRUE);
-  if (h == NULL)
-    einfo (_("%P%F: bfd_link_hash_lookup failed: %E\n"));
-  if (h->type == bfd_link_hash_new
-      || h->type == bfd_link_hash_undefined
-      || h->type == bfd_link_hash_undefweak)
-    {
-      h->type = bfd_link_hash_defined;
-      h->u.def.section = bfd_abs_section_ptr;
-      h->u.def.value   = 0;
-    }
-}
-
-/* Like lang_add_undef, but this time for symbols defined on the
-   command line.  */
-
-static void
-ldlang_add_def (const char *const name)
-{
-  if (link_info.output_bfd != NULL)
-    insert_defined (xstrdup (name));
-  else
-    {
-      ldlang_def_chain_list_type *new_def;
-
-      new_def = (ldlang_def_chain_list_type *) stat_alloc (sizeof (*new_def));
-      new_def->next = ldlang_def_chain_list_head.next;
-      ldlang_def_chain_list_head.next = new_def;
-
-      new_def->name = xstrdup (name);
-    }
-}
-
-/* Run through the list of defineds created above and place them
-   into the linker hash table as defined symbols belonging to the
-   script file.  */
-
-static void
-lang_place_defineds (void)
-{
-  ldlang_def_chain_list_type *ptr;
-
-  for (ptr = ldlang_def_chain_list_head.next;
-       ptr != NULL;
-       ptr = ptr->next)
-    insert_defined (ptr->name);
-}
-
 /* Check for all readonly or some readwrite sections.  */
 
 static void
@@ -3982,12 +3926,12 @@ scan_for_self_assignment (const char * d
   switch (rhs->type.node_class)
     {
     case etree_binary:
-      return scan_for_self_assignment (dst, rhs->binary.lhs)
-	||   scan_for_self_assignment (dst, rhs->binary.rhs);
+      return (scan_for_self_assignment (dst, rhs->binary.lhs)
+	      || scan_for_self_assignment (dst, rhs->binary.rhs));
 
     case etree_trinary:
-      return scan_for_self_assignment (dst, rhs->trinary.lhs)
-	||   scan_for_self_assignment (dst, rhs->trinary.rhs);
+      return (scan_for_self_assignment (dst, rhs->trinary.lhs)
+	      || scan_for_self_assignment (dst, rhs->trinary.rhs));
 
     case etree_assign:
     case etree_provided:
@@ -4042,7 +3986,7 @@ print_assignment (lang_assignment_statem
 
       is_dot = (dst[0] == '.' && dst[1] == 0);
       tree = assignment->exp->assign.src;
-      computation_is_valid = is_dot || (scan_for_self_assignment (dst, tree) == FALSE);
+      computation_is_valid = is_dot || !scan_for_self_assignment (dst, tree);
     }
 
   osec = output_section->bfd_section;
@@ -6461,7 +6405,6 @@ lang_process (void)
 
   /* Add to the hash table all undefineds on the command line.  */
   lang_place_undefineds ();
-  lang_place_defineds ();
 
   if (!bfd_section_already_linked_table_init ())
     einfo (_("%P%F: Failed to create hash table\n"));
@@ -6523,6 +6466,7 @@ lang_process (void)
 
   /* Run through the contours of the script and attach input sections
      to the correct output sections.  */
+  lang_statement_iteration++;
   map_input_to_output_sections (statement_list.head, NULL, NULL);
 
   process_insert_statements ();
@@ -6746,10 +6690,6 @@ lang_add_assignment (etree_type *exp)
 {
   lang_assignment_statement_type *new_stmt;
 
-  extern int parsing_defsym;
-  if (parsing_defsym)
-    ldlang_add_def (exp->assign.dst);
-
   new_stmt = new_stat (lang_assignment_statement, stat_ptr);
   new_stmt->exp = exp;
   return new_stmt;
Index: ld/testsuite/ld-scripts/default-script2.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-scripts/default-script2.d,v
retrieving revision 1.4
diff -u -p -r1.4 default-script2.d
--- ld/testsuite/ld-scripts/default-script2.d	3 Nov 2010 17:18:22 -0000	1.4
+++ ld/testsuite/ld-scripts/default-script2.d	20 Dec 2010 04:44:38 -0000
@@ -5,5 +5,5 @@
 #...
 0*8000000 . _START
 #...
-0*8000000 T text
+0*9000000 T text
 #pass

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2010-12-20 11:07 PR 12001, --defsym Alan Modra
@ 2010-12-29 17:35 ` H.J. Lu
  2011-01-13 13:06   ` Alan Modra
  0 siblings, 1 reply; 15+ messages in thread
From: H.J. Lu @ 2010-12-29 17:35 UTC (permalink / raw)
  To: binutils

On Sun, Dec 19, 2010 at 10:30 PM, Alan Modra <amodra@gmail.com> wrote:
> This patch reverts Nick's support for early --defsym symbol creation,
> and instead implements the same in open_input_bfds.  This is quite a
> lot simpler, but the main reason for this patch is that I want to run
> a pass over assignments early.  The idea being to control ld
> expression behaviour by a magic assignment in a linker script.  One of
> the benefits is that --defsym is restored to acting at the point it is
> used on the command line, for example
>  --defsym x=1 some_script --defsym x=2 some_script
> could control actions in "some_script".  This positional behaviour
> will also affect extraction of objects from archives.
>
> ld/
>        PR ld/12001
>        Revert 2010-11-03 Nick Clifton
>        * ldlang.c (ldlang_def_chain_list): Delete.
>        (insert_defined, ldlang_add_def, lang_place_defineds): Delete.
>        (lang_process): Don't call lang_place_defineds.
>        (lang_add_assignment): Don't do anything special for --defsym.
>
>        * ldexp.h (struct ldexp_control): Add uses_defined.
>        (exp_fold_tree_no_dot): Declare.
>        * ldexp.c (exp_fold_tree): Clear uses_defined.
>        (exp_fold_tree_no_dot): Likewise.  Make global.
>        (fold_name <DEFINED>): Set uses_defined.
>        (exp_fold_tree_1 <etree_assign>): Define symbol during first phase
>        even when the value being assigned isn't valid.
>        * ldlang.c (open_input_bfds): Process assignment statements.
>        (lang_process): Bump lang_statement_iteration.
>        (scan_for_self_assignment): Formatting.
>        (print_assignment): Style.
>

This caused:

http://sourceware.org/bugzilla/show_bug.cgi?id=12356


-- 
H.J.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2010-12-29 17:35 ` H.J. Lu
@ 2011-01-13 13:06   ` Alan Modra
  2011-01-13 13:16     ` H.J. Lu
  2011-01-13 13:28     ` Alan Modra
  0 siblings, 2 replies; 15+ messages in thread
From: Alan Modra @ 2011-01-13 13:06 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Wed, Dec 29, 2010 at 09:30:14AM -0800, H.J. Lu wrote:
> This caused:
> 
> http://sourceware.org/bugzilla/show_bug.cgi?id=12356

Given this bug report and Daniel's objections over using a linker
script assignment to control ld behaviour, I've implemented a new
LD_FEATURE linker script keyword.

The following is just a tidy of exp_assop, which is everywhere passed
'=' as its first argument.  Oh, and one new function in preparation
for the real fix, exp_defsym.

	PR ld/12356
	* ldexp.h (exp_assop): Delete.
	(exp_assign, exp_defsym): Declare.
	* ldexp.c (exp_assop): Make static, handle all assignment variations.
	(exp_assign, exp_defsym): New functions.
	(exp_provide): Use exp_assop.
	* ldgram.y (defsym_expr): Use exp_defsym.
	* ldctor.c, * ldgram.y, * ldlang.c, * mri.c, * emultempl/beos.em,
	* emultempl/pe.em, * emultempl/pep.em, * emultempl/spuelf.em,
	* emultempl/xtensaelf.em: Update exp_assop -> exp_assign.

Index: ld/ldexp.h
===================================================================
RCS file: /cvs/src/src/ld/ldexp.h,v
retrieving revision 1.26
diff -u -p -r1.26 ldexp.h
--- ld/ldexp.h	12 Jan 2011 12:07:19 -0000	1.26
+++ ld/ldexp.h	13 Jan 2011 12:36:28 -0000
@@ -46,7 +46,7 @@ enum node_tree_enum {
 typedef struct {
   int node_code;
   unsigned int lineno;
-  enum  node_tree_enum node_class;
+  enum node_tree_enum node_class;
 } node_type;
 
 typedef union etree_union {
@@ -190,8 +190,10 @@ etree_type *exp_unop
   (int, etree_type *);
 etree_type *exp_nameop
   (int, const char *);
-etree_type *exp_assop
-  (int, const char *, etree_type *);
+etree_type *exp_assign
+  (const char *, etree_type *);
+etree_type *exp_defsym
+  (const char *, etree_type *);
 etree_type *exp_provide
   (const char *, etree_type *, bfd_boolean);
 etree_type *exp_assert
Index: ld/ldexp.c
===================================================================
RCS file: /cvs/src/src/ld/ldexp.c,v
retrieving revision 1.90
diff -u -p -r1.90 ldexp.c
--- ld/ldexp.c	12 Jan 2011 12:07:19 -0000	1.90
+++ ld/ldexp.c	13 Jan 2011 12:36:28 -0000
@@ -974,37 +974,44 @@ exp_nameop (int code, const char *name)
 
 }
 
-etree_type *
-exp_assop (int code, const char *dst, etree_type *src)
-{
-  etree_type *new_e;
-
-  new_e = (etree_type *) stat_alloc (sizeof (new_e->assign));
-  new_e->type.node_code = code;
-  new_e->type.lineno = src->type.lineno;
-  new_e->type.node_class = etree_assign;
-  new_e->assign.src = src;
-  new_e->assign.dst = dst;
-  return new_e;
-}
-
-/* Handle PROVIDE.  */
-
-etree_type *
-exp_provide (const char *dst, etree_type *src, bfd_boolean hidden)
+static etree_type *
+exp_assop (const char *dst,
+	   etree_type *src,
+	   enum node_tree_enum class,
+	   bfd_boolean hidden)
 {
   etree_type *n;
 
   n = (etree_type *) stat_alloc (sizeof (n->assign));
   n->assign.type.node_code = '=';
   n->assign.type.lineno = src->type.lineno;
-  n->assign.type.node_class = etree_provide;
+  n->assign.type.node_class = class;
   n->assign.src = src;
   n->assign.dst = dst;
   n->assign.hidden = hidden;
   return n;
 }
 
+etree_type *
+exp_assign (const char *dst, etree_type *src)
+{
+  return exp_assop (dst, src, etree_assign, FALSE);
+}
+
+etree_type *
+exp_defsym (const char *dst, etree_type *src)
+{
+  return exp_assop (dst, src, etree_assign, TRUE);
+}
+
+/* Handle PROVIDE.  */
+
+etree_type *
+exp_provide (const char *dst, etree_type *src, bfd_boolean hidden)
+{
+  return exp_assop (dst, src, etree_provide, hidden);
+}
+
 /* Handle ASSERT.  */
 
 etree_type *
Index: ld/ldctor.c
===================================================================
RCS file: /cvs/src/src/ld/ldctor.c,v
retrieving revision 1.17
diff -u -p -r1.17 ldctor.c
--- ld/ldctor.c	11 Sep 2009 15:27:35 -0000	1.17
+++ ld/ldctor.c	13 Jan 2011 11:00:19 -0000
@@ -319,11 +319,11 @@ ldctor_build_sets (void)
 	  break;
 	}
 
-      lang_add_assignment (exp_assop ('=', ".",
-				      exp_unop (ALIGN_K,
-						exp_intop (reloc_size))));
-      lang_add_assignment (exp_assop ('=', p->h->root.string,
-				      exp_nameop (NAME, ".")));
+      lang_add_assignment (exp_assign (".",
+				       exp_unop (ALIGN_K,
+						 exp_intop (reloc_size))));
+      lang_add_assignment (exp_assign (p->h->root.string,
+				       exp_nameop (NAME, ".")));
       lang_add_data (size, exp_intop (p->count));
 
       for (e = p->elements; e != NULL; e = e->next)
Index: ld/ldgram.y
===================================================================
RCS file: /cvs/src/src/ld/ldgram.y,v
retrieving revision 1.63
diff -u -p -r1.63 ldgram.y
--- ld/ldgram.y	15 Dec 2010 14:56:37 -0000	1.63
+++ ld/ldgram.y	13 Jan 2011 11:00:20 -0000
@@ -176,7 +177,7 @@ defsym_expr:
 		NAME '=' exp
 		{
 		  ldlex_popstate();
-		  lang_add_assignment(exp_assop($3,$2,$4));
+		  lang_add_assignment (exp_defsym ($2, $4));
 		}
 	;
 
@@ -657,15 +660,15 @@ end:	';' | ','
 assignment:
 		NAME '=' mustbe_exp
 		{
-		  lang_add_assignment (exp_assop ($2, $1, $3));
+		  lang_add_assignment (exp_assign ($1, $3));
 		}
 	|	NAME assign_op mustbe_exp
 		{
-		  lang_add_assignment (exp_assop ('=', $1,
-						  exp_binop ($2,
-							     exp_nameop (NAME,
-									 $1),
-							     $3)));
+		  lang_add_assignment (exp_assign ($1,
+						   exp_binop ($2,
+							      exp_nameop (NAME,
+									  $1),
+							      $3)));
 		}
 	|	PROVIDE '(' NAME '=' mustbe_exp ')'
 		{
@@ -983,7 +986,7 @@ section:	NAME 		{ ldlex_expression(); }
 		opt_exp_with_type
 		{
 		  ldlex_popstate ();
-		  lang_add_assignment (exp_assop ('=', ".", $3));
+		  lang_add_assignment (exp_assign (".", $3));
 		}
 		'{' sec_or_group_p1 '}'
 	|	INCLUDE filename
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.357
diff -u -p -r1.357 ldlang.c
--- ld/ldlang.c	12 Jan 2011 12:07:19 -0000	1.357
+++ ld/ldlang.c	13 Jan 2011 11:00:24 -0000
@@ -1809,7 +1808,7 @@ lang_insert_orphan (asection *s,
 	  sprintf (symname + (symname[0] != 0), "__start_%s", secname);
 	  e_align = exp_unop (ALIGN_K,
 			      exp_intop ((bfd_vma) 1 << s->alignment_power));
-	  lang_add_assignment (exp_assop ('=', ".", e_align));
+	  lang_add_assignment (exp_assign (".", e_align));
 	  lang_add_assignment (exp_provide (symname,
 					    exp_unop (ABSOLUTE,
 						      exp_nameop (NAME, ".")),
@@ -7229,7 +7230,7 @@ lang_leave_overlay (etree_type *lma_expr
      overlay region.  */
   if (overlay_list != NULL)
     overlay_list->os->update_dot_tree
-      = exp_assop ('=', ".", exp_binop ('+', overlay_vma, overlay_max));
+      = exp_assign (".", exp_binop ('+', overlay_vma, overlay_max));
 
   l = overlay_list;
   while (l != NULL)
Index: ld/mri.c
===================================================================
RCS file: /cvs/src/src/ld/mri.c,v
retrieving revision 1.23
diff -u -p -r1.23 mri.c
--- ld/mri.c	11 Sep 2009 15:27:35 -0000	1.23
+++ ld/mri.c	13 Jan 2011 11:00:24 -0000
@@ -295,7 +295,7 @@ mri_format (const char *name)
 void
 mri_public (const char *name, etree_type *exp)
 {
-  lang_add_assignment (exp_assop ('=', name, exp));
+  lang_add_assignment (exp_assign (name, exp));
 }
 
 void
Index: ld/emultempl/beos.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/beos.em,v
retrieving revision 1.45
diff -u -p -r1.45 beos.em
--- ld/emultempl/beos.em	20 Dec 2010 13:00:14 -0000	1.45
+++ ld/emultempl/beos.em	13 Jan 2011 11:00:25 -0000
@@ -351,7 +351,7 @@ gld_${EMULATION_NAME}_set_symbols (void)
   for (j = 0; init[j].ptr; j++)
     {
       long val = init[j].value;
-      lang_add_assignment (exp_assop ('=', init[j].symbol, exp_intop (val)));
+      lang_add_assignment (exp_assign (init[j].symbol, exp_intop (val)));
       if (init[j].size == sizeof(short))
 	*(short *)init[j].ptr = val;
       else if (init[j].size == sizeof(int))
Index: ld/emultempl/pe.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/pe.em,v
retrieving revision 1.165
diff -u -p -r1.165 pe.em
--- ld/emultempl/pe.em	20 Dec 2010 13:00:14 -0000	1.165
+++ ld/emultempl/pe.em	13 Jan 2011 11:00:26 -0000
@@ -946,8 +946,8 @@ gld_${EMULATION_NAME}_set_symbols (void)
       long val = init[j].value;
       lang_assignment_statement_type *rv;
 
-      rv = lang_add_assignment (exp_assop ('=', GET_INIT_SYMBOL_NAME (j),
-					   exp_intop (val)));
+      rv = lang_add_assignment (exp_assign (GET_INIT_SYMBOL_NAME (j),
+					    exp_intop (val)));
       if (init[j].size == sizeof (short))
 	*(short *) init[j].ptr = val;
       else if (init[j].size == sizeof (int))
@@ -1722,8 +1722,8 @@ gld_${EMULATION_NAME}_unrecognized_file 
 		= pe_def_file->base_address;
 	      init[IMAGEBASEOFF].inited = 1;
 	      if (image_base_statement)
-		image_base_statement->exp = exp_assop ('=', "__image_base__",
-						       exp_intop (pe.ImageBase));
+		image_base_statement->exp = exp_assign ("__image_base__",
+							exp_intop (pe.ImageBase));
 	    }
 
 	  if (pe_def_file->stack_reserve != -1
Index: ld/emultempl/pep.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/pep.em,v
retrieving revision 1.41
diff -u -p -r1.41 pep.em
--- ld/emultempl/pep.em	20 Dec 2010 13:00:14 -0000	1.41
+++ ld/emultempl/pep.em	13 Jan 2011 11:00:26 -0000
@@ -858,8 +858,8 @@ gld_${EMULATION_NAME}_set_symbols (void)
       bfd_vma val = init[j].value;
       lang_assignment_statement_type *rv;
 
-      rv = lang_add_assignment (exp_assop ('=', GET_INIT_SYMBOL_NAME (j),
-					   exp_intop (val)));
+      rv = lang_add_assignment (exp_assign (GET_INIT_SYMBOL_NAME (j),
+					    exp_intop (val)));
       if (init[j].size == sizeof (short))
 	*(short *) init[j].ptr = (short) val;
       else if (init[j].size == sizeof (int))
@@ -1525,8 +1525,8 @@ gld_${EMULATION_NAME}_unrecognized_file 
 		= pep_def_file->base_address;
 	      init[IMAGEBASEOFF].inited = 1;
 	      if (image_base_statement)
-		image_base_statement->exp = exp_assop ('=', "__image_base__",
-						       exp_intop (pep.ImageBase));
+		image_base_statement->exp = exp_assign ("__image_base__",
+							exp_intop (pep.ImageBase));
 	    }
 
 	  if (pep_def_file->stack_reserve != -1
Index: ld/emultempl/spuelf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/spuelf.em,v
retrieving revision 1.42
diff -u -p -r1.42 spuelf.em
--- ld/emultempl/spuelf.em	5 Nov 2010 17:20:17 -0000	1.42
+++ ld/emultempl/spuelf.em	13 Jan 2011 11:00:27 -0000
@@ -164,7 +164,7 @@ spu_place_special_section (asection *s, 
 
 	  push_stat_ptr (&os->children);
 	  e_size = exp_intop (params.line_size - s->size);
-	  lang_add_assignment (exp_assop ('=', ".", e_size));
+	  lang_add_assignment (exp_assign (".", e_size));
 	  pop_stat_ptr ();
 	}
       lang_add_section (&os->children, s, os);
Index: ld/emultempl/xtensaelf.em
===================================================================
RCS file: /cvs/src/src/ld/emultempl/xtensaelf.em,v
retrieving revision 1.27
diff -u -p -r1.27 xtensaelf.em
--- ld/emultempl/xtensaelf.em	4 Oct 2010 14:13:10 -0000	1.27
+++ ld/emultempl/xtensaelf.em	13 Jan 2011 11:00:28 -0000
@@ -1885,7 +1885,7 @@ ld_xtensa_insert_page_offsets (bfd_vma d
 		etree_type *name_op = exp_nameop (NAME, ".");
 		etree_type *addend_op = exp_intop (1 << xtensa_page_power);
 		etree_type *add_op = exp_binop ('+', name_op, addend_op);
-		etree_type *assign_op = exp_assop ('=', ".", add_op);
+		etree_type *assign_op = exp_assign (".", add_op);
 
 		lang_assignment_statement_type *assign_stmt;
 		lang_statement_union_type *assign_union;

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2011-01-13 13:06   ` Alan Modra
@ 2011-01-13 13:16     ` H.J. Lu
  2011-01-13 13:42       ` Alan Modra
  2011-01-13 13:28     ` Alan Modra
  1 sibling, 1 reply; 15+ messages in thread
From: H.J. Lu @ 2011-01-13 13:16 UTC (permalink / raw)
  To: H.J. Lu, binutils

On Thu, Jan 13, 2011 at 5:05 AM, Alan Modra <amodra@gmail.com> wrote:
> On Wed, Dec 29, 2010 at 09:30:14AM -0800, H.J. Lu wrote:
>> This caused:
>>
>> http://sourceware.org/bugzilla/show_bug.cgi?id=12356
>
> Given this bug report and Daniel's objections over using a linker
> script assignment to control ld behaviour, I've implemented a new
> LD_FEATURE linker script keyword.
>
> The following is just a tidy of exp_assop, which is everywhere passed
> '=' as its first argument.  Oh, and one new function in preparation
> for the real fix, exp_defsym.
>
>        PR ld/12356
>        * ldexp.h (exp_assop): Delete.
>        (exp_assign, exp_defsym): Declare.
>        * ldexp.c (exp_assop): Make static, handle all assignment variations.
>        (exp_assign, exp_defsym): New functions.
>        (exp_provide): Use exp_assop.
>        * ldgram.y (defsym_expr): Use exp_defsym.
>        * ldctor.c, * ldgram.y, * ldlang.c, * mri.c, * emultempl/beos.em,
>        * emultempl/pe.em, * emultempl/pep.em, * emultempl/spuelf.em,
>        * emultempl/xtensaelf.em: Update exp_assop -> exp_assign.
>

Where is LD_FEATURE implemented? Is __ld_compatibility still supported?
Do we have testcases for new features? Is linker document up to date?


-- 
H.J.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2011-01-13 13:06   ` Alan Modra
  2011-01-13 13:16     ` H.J. Lu
@ 2011-01-13 13:28     ` Alan Modra
  2011-01-13 13:37       ` H.J. Lu
  1 sibling, 1 reply; 15+ messages in thread
From: Alan Modra @ 2011-01-13 13:28 UTC (permalink / raw)
  To: H.J. Lu, binutils

On Thu, Jan 13, 2011 at 11:35:39PM +1030, Alan Modra wrote:
> Given this bug report and Daniel's objections over using a linker
> script assignment to control ld behaviour, I've implemented a new
> LD_FEATURE linker script keyword.

I've kept the new code in open_input_bfds handling early creation of
--defsym symbols, but only handle --defsym assignments there so we
won't get an error if a script defines a symbol that is also defined
in an object file.  LD_FEATURE is designed to be extensible;  At the 
moment we just have LD_FEATURE ("SANE_EXPR").

	PR ld/12356
	* ld.texinfo (Miscellaneous Commands): Describe LD_FEATURE.
	(Expression Section): Update.
	* ld.h (ld_config_type): Add sane_expr.
	* ldgram.y (ifile_p1): Add LD_FEATURE.
	* ldlex.l (LD_FEATYRE): New.
	* ldemul.c (after_parse_default): Delete code handling ld_compatibility.
	* ldexp.h (struct ldexp_control): Delete uses_defined.
	* ldexp.c: Remove all uses of uses_defined.
	(fold_name): Test config.sane_expr rather than ld_compatibility.
	(exp_fold_tree_1): Likewise.  Adjust handling of assignments
	during first phase.
	* ldlang.h (ld_compatibility): Delete.
	(lang_ld_feature): Declare.
	* ldlang.c (ld_compatibility): Delete.
	(open_input_bfds): Only handle assignments for --defsym.
	(lang_ld_feature): New function.

Index: ld/ld.texinfo
===================================================================
RCS file: /cvs/src/src/ld/ld.texinfo,v
retrieving revision 1.269
diff -u -p -r1.269 ld.texinfo
--- ld/ld.texinfo	20 Dec 2010 13:00:12 -0000	1.269
+++ ld/ld.texinfo	13 Jan 2011 13:13:58 -0000
@@ -3344,6 +3344,13 @@ of the names used by the BFD library (@p
 architecture of an object file by using the @code{objdump} program with
 the @samp{-f} option.
 @end ifclear
+
+@item LD_FEATURE(@var{string})
+@kindex LD_FEATURE(@var{string})
+This command may be used to modify @command{ld} behavior.  If
+@var{string} is @code{"SANE_EXPR"} then absolute symbols and numbers
+in a script are simply treated as numbers everywhere.
+@xref{Expression Section}.
 @end table
 
 @node Assignments
@@ -5503,15 +5510,15 @@ section relative symbols and for builtin
 address, such as @code{ADDR}, @code{LOADADDR}, @code{ORIGIN} and
 @code{SEGMENT_START}.  Other terms are simply numbers, or are builtin
 functions that return a non-address value, such as @code{LENGTH}.
-One complication is that unless you assign @code{__ld_compatibility}
-a value of 221 or larger, numbers and absolute symbols are treated
+One complication is that unless you set @code{LD_FEATURE ("SANE_EXPR")}
+(@pxref{Miscellaneous Commands}), numbers and absolute symbols are treated
 differently depending on their location, for compatibility with older
 versions of @code{ld}.  Expressions appearing outside an output
 section definition treat all numbers as absolute addresses.
 Expressions appearing inside an output section definition treat
-absolute symbols as numbers.  If @code{__ld_compatibility} is assigned
-a value larger than 221, then absolute symbols and numbers are simply
-treated as numbers everywhere.
+absolute symbols as numbers.  If @code{LD_FEATURE ("SANE_EXPR")} is
+given, then absolute symbols and numbers are simply treated as numbers
+everywhere.
 
 In the following simple example,
 
Index: ld/ld.h
===================================================================
RCS file: /cvs/src/src/ld/ld.h,v
retrieving revision 1.47
diff -u -p -r1.47 ld.h
--- ld/ld.h	15 Dec 2010 14:56:37 -0000	1.47
+++ ld/ld.h	13 Jan 2011 13:13:53 -0000
@@ -292,6 +292,10 @@ typedef struct {
      on the command line.  */
   bfd_boolean only_cmd_line_lib_dirs;
 
+  /* If set, numbers and absolute symbols are simply treated as
+     numbers everywhere.  */
+  bfd_boolean sane_expr;
+
   /* The rpath separation character.  Usually ':'.  */
   char rpath_separator;
 
Index: ld/ldgram.y
===================================================================
RCS file: /cvs/src/src/ld/ldgram.y,v
retrieving revision 1.64
diff -u -p -r1.64 ldgram.y
--- ld/ldgram.y	13 Jan 2011 13:06:22 -0000	1.64
+++ ld/ldgram.y	13 Jan 2011 13:14:00 -0000
@@ -134,6 +134,7 @@ static int error_index;
 %token INCLUDE
 %token MEMORY
 %token REGION_ALIAS
+%token LD_FEATURE
 %token NOLOAD DSECT COPY INFO OVERLAY
 %token DEFINED TARGET_K SEARCH_DIR MAP ENTRY
 %token <integer> NEXT
@@ -357,6 +358,8 @@ ifile_p1:
 		{ lang_add_insert ($3, 1); }
 	|	REGION_ALIAS '(' NAME ',' NAME ')'
 		{ lang_memory_region_alias ($3, $5); }
+	|	LD_FEATURE '(' NAME ')'
+		{ lang_ld_feature ($3); }
 	;
 
 input_list:
Index: ld/ldlex.l
===================================================================
RCS file: /cvs/src/src/ld/ldlex.l,v
retrieving revision 1.48
diff -u -p -r1.48 ldlex.l
--- ld/ldlex.l	15 Dec 2010 14:56:37 -0000	1.48
+++ ld/ldlex.l	13 Jan 2011 13:14:06 -0000
@@ -241,6 +241,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([
 <BOTH,SCRIPT,EXPRESSION,MRI>";"		{ RTOKEN(';');}
 <BOTH,SCRIPT>"MEMORY"			{ RTOKEN(MEMORY);}
 <BOTH,SCRIPT>"REGION_ALIAS"		{ RTOKEN(REGION_ALIAS);}
+<BOTH,SCRIPT>"LD_FEATURE"		{ RTOKEN(LD_FEATURE);}
 <BOTH,SCRIPT,EXPRESSION>"ORIGIN"	{ RTOKEN(ORIGIN);}
 <BOTH,SCRIPT>"VERSION"			{ RTOKEN(VERSIONK);}
 <EXPRESSION,BOTH,SCRIPT>"BLOCK"		{ RTOKEN(BLOCK);}
Index: ld/ldemul.c
===================================================================
RCS file: /cvs/src/src/ld/ldemul.c,v
retrieving revision 1.35
diff -u -p -r1.35 ldemul.c
--- ld/ldemul.c	20 Dec 2010 13:00:13 -0000	1.35
+++ ld/ldemul.c	13 Jan 2011 13:14:00 -0000
@@ -226,16 +226,6 @@ after_parse_default (void)
 void
 after_open_default (void)
 {
-  struct bfd_link_hash_entry *h;
-
-  h = bfd_wrapped_link_hash_lookup (link_info.output_bfd,
-				    &link_info,
-				    "__ld_compatibility",
-				    FALSE, FALSE, TRUE);
-  if (h != NULL
-      && (h->type == bfd_link_hash_defined
-	  || h->type == bfd_link_hash_defweak))
-    ld_compatibility = h->u.def.value;
 }
 
 void
Index: ld/ldexp.h
===================================================================
RCS file: /cvs/src/src/ld/ldexp.h,v
retrieving revision 1.27
diff -u -p -r1.27 ldexp.h
--- ld/ldexp.h	13 Jan 2011 13:06:22 -0000	1.27
+++ ld/ldexp.h	13 Jan 2011 13:14:00 -0000
@@ -132,8 +132,6 @@ struct ldexp_control {
   /* Working results.  */
   etree_value_type result;
   bfd_vma dot;
-  /* Set if an expression contains DEFINED().  */
-  bfd_boolean uses_defined;
 
   /* Current dot and section passed to ldexp folder.  */
   bfd_vma *dotp;
Index: ld/ldexp.c
===================================================================
RCS file: /cvs/src/src/ld/ldexp.c,v
retrieving revision 1.91
diff -u -p -r1.91 ldexp.c
--- ld/ldexp.c	13 Jan 2011 13:06:22 -0000	1.91
+++ ld/ldexp.c	13 Jan 2011 13:14:00 -0000
@@ -512,7 +512,6 @@ fold_name (etree_type *tree)
       break;
 
     case DEFINED:
-      expld.uses_defined = TRUE;
       if (expld.phase == lang_first_phase_enum)
 	lang_track_definedness (tree->name.name);
       else
@@ -564,7 +563,7 @@ fold_name (etree_type *tree)
 		}
 	      else if (output_section == bfd_abs_section_ptr
 		       && (expld.section != bfd_abs_section_ptr
-			   || ld_compatibility >= 221))
+			   || config.sane_expr))
 		new_number (h->u.def.value + h->u.def.section->output_offset);
 	      else
 		new_rel (h->u.def.value + h->u.def.section->output_offset,
@@ -712,7 +711,7 @@ exp_fold_tree_1 (etree_type *tree)
     {
     case etree_value:
       if (expld.section == bfd_abs_section_ptr
-	  && ld_compatibility < 221)
+	  && !config.sane_expr)
 	new_abs (tree->value.value);
       else
 	new_number (tree->value.value);
@@ -819,7 +818,8 @@ exp_fold_tree_1 (etree_type *tree)
 	  exp_fold_tree_1 (tree->assign.src);
 	  if (expld.result.valid_p
 	      || (expld.phase == lang_first_phase_enum
-		  && !expld.uses_defined))
+		  && tree->type.node_class == etree_assign
+		  && tree->assign.hidden))
 	    {
 	      if (h == NULL)
 		{
@@ -883,7 +883,6 @@ exp_fold_tree (etree_type *tree, asectio
   expld.dot = *dotp;
   expld.dotp = dotp;
   expld.section = current_section;
-  expld.uses_defined = FALSE;
   exp_fold_tree_1 (tree);
 }
 
@@ -893,7 +892,6 @@ exp_fold_tree_no_dot (etree_type *tree)
   expld.dot = 0;
   expld.dotp = NULL;
   expld.section = bfd_abs_section_ptr;
-  expld.uses_defined = FALSE;
   exp_fold_tree_1 (tree);
 }
 
Index: ld/ldlang.h
===================================================================
RCS file: /cvs/src/src/ld/ldlang.h,v
retrieving revision 1.93
diff -u -p -r1.93 ldlang.h
--- ld/ldlang.h	20 Dec 2010 13:00:14 -0000	1.93
+++ ld/ldlang.h	13 Jan 2011 13:14:03 -0000
@@ -469,7 +469,6 @@ extern bfd_boolean entry_from_cmdline;
 extern lang_statement_list_type file_chain;
 extern lang_statement_list_type input_file_chain;
 
-extern int ld_compatibility;
 extern int lang_statement_iteration;
 extern bfd_boolean missing_file;
 
@@ -651,4 +650,7 @@ extern bfd_boolean
 ldlang_override_segment_assignment
   (struct bfd_link_info *, bfd *, asection *, asection *, bfd_boolean);
 
+extern void
+lang_ld_feature (char *);
+
 #endif
Index: ld/ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.358
diff -u -p -r1.358 ldlang.c
--- ld/ldlang.c	13 Jan 2011 13:06:22 -0000	1.358
+++ ld/ldlang.c	13 Jan 2011 13:14:03 -0000
@@ -108,7 +108,6 @@ bfd_boolean delete_output_file_on_failur
 struct lang_phdr *lang_phdr_list;
 struct lang_nocrossrefs *nocrossref_list;
 bfd_boolean missing_file = FALSE;
-int ld_compatibility;
 
  /* Functions that traverse the linker script and might evaluate
     DEFINED() need to increment this.  */
@@ -3250,7 +3249,9 @@ open_input_bfds (lang_statement_union_ty
 	    }
 	  break;
 	case lang_assignment_statement_enum:
-	  exp_fold_tree_no_dot (s->assignment_statement.exp);
+	  if (s->assignment_statement.exp->assign.hidden)
+	    /* This is from a --defsym on the command line.  */
+	    exp_fold_tree_no_dot (s->assignment_statement.exp);
 	  break;
 	default:
 	  break;
@@ -7845,3 +7846,32 @@ lang_append_dynamic_list_cpp_new (void)
 
   lang_append_dynamic_list (dynamic);
 }
+
+/* Scan a space and/or comma separated string of features.  */
+
+void
+lang_ld_feature (char *str)
+{
+  char *p, *q;
+
+  p = str;
+  while (*p)
+    {
+      char sep;
+      while (*p == ',' || ISSPACE (*p))
+	++p;
+      if (!*p)
+	break;
+      q = p + 1;
+      while (*q && *q != ',' && !ISSPACE (*q))
+	++q;
+      sep = *q;
+      *q = 0;
+      if (strcasecmp (p, "SANE_EXPR") == 0)
+	config.sane_expr = TRUE;
+      else
+	einfo (_("%X%P: unknown feature `%s'\n"), p);
+      *q = sep;
+      p = q;
+    }
+}

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2011-01-13 13:28     ` Alan Modra
@ 2011-01-13 13:37       ` H.J. Lu
  2011-01-13 13:55         ` Alan Modra
  0 siblings, 1 reply; 15+ messages in thread
From: H.J. Lu @ 2011-01-13 13:37 UTC (permalink / raw)
  To: binutils

On Thu, Jan 13, 2011 at 5:28 AM, Alan Modra <amodra@gmail.com> wrote:
> On Thu, Jan 13, 2011 at 11:35:39PM +1030, Alan Modra wrote:
>> Given this bug report and Daniel's objections over using a linker
>> script assignment to control ld behaviour, I've implemented a new
>> LD_FEATURE linker script keyword.
>
> I've kept the new code in open_input_bfds handling early creation of
> --defsym symbols, but only handle --defsym assignments there so we
> won't get an error if a script defines a symbol that is also defined
> in an object file.  LD_FEATURE is designed to be extensible;  At the
> moment we just have LD_FEATURE ("SANE_EXPR").
>
>        PR ld/12356
>        * ld.texinfo (Miscellaneous Commands): Describe LD_FEATURE.
>        (Expression Section): Update.
>        * ld.h (ld_config_type): Add sane_expr.
>        * ldgram.y (ifile_p1): Add LD_FEATURE.
>        * ldlex.l (LD_FEATYRE): New.
>        * ldemul.c (after_parse_default): Delete code handling ld_compatibility.
>        * ldexp.h (struct ldexp_control): Delete uses_defined.
>        * ldexp.c: Remove all uses of uses_defined.
>        (fold_name): Test config.sane_expr rather than ld_compatibility.
>        (exp_fold_tree_1): Likewise.  Adjust handling of assignments
>        during first phase.
>        * ldlang.h (ld_compatibility): Delete.
>        (lang_ld_feature): Declare.
>        * ldlang.c (ld_compatibility): Delete.
>        (open_input_bfds): Only handle assignments for --defsym.
>        (lang_ld_feature): New function.
>

You should add some testcases for this new feature.


-- 
H.J.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2011-01-13 13:16     ` H.J. Lu
@ 2011-01-13 13:42       ` Alan Modra
  2011-01-13 14:02         ` H.J. Lu
  0 siblings, 1 reply; 15+ messages in thread
From: Alan Modra @ 2011-01-13 13:42 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Thu, Jan 13, 2011 at 05:16:45AM -0800, H.J. Lu wrote:
> Where is LD_FEATURE implemented? Is __ld_compatibility still supported?
> Do we have testcases for new features? Is linker document up to date?

The followup patch should answer most of these questions.  I tested
LD_FEATURE with the following, and am considering applying this.

Index: ld/scripttempl/elf.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elf.sc,v
retrieving revision 1.105
diff -u -p -r1.105 elf.sc
--- ld/scripttempl/elf.sc	15 Dec 2010 14:56:38 -0000	1.105
+++ ld/scripttempl/elf.sc	13 Jan 2011 13:41:14 -0000
@@ -302,6 +302,7 @@ else
 fi
 
 cat <<EOF
+LD_FEATURE("SANE_EXPR")
 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
 	      "${LITTLE_OUTPUT_FORMAT}")
 OUTPUT_ARCH(${OUTPUT_ARCH})

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2011-01-13 13:37       ` H.J. Lu
@ 2011-01-13 13:55         ` Alan Modra
  2011-01-13 14:06           ` H.J. Lu
  2011-01-13 15:13           ` H.J. Lu
  0 siblings, 2 replies; 15+ messages in thread
From: Alan Modra @ 2011-01-13 13:55 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

On Thu, Jan 13, 2011 at 05:37:25AM -0800, H.J. Lu wrote:
> You should add some testcases for this new feature.

Blah.  How about *you* fix some of your recently added testcases,
which you added without approval, again.

alpha-dec-vms  +FAIL: ld-misc/defsym1
frv-linux  +FAIL: ld-misc/defsym1
microblaze-elf  +FAIL: ld-misc/defsym1
tic30-unknown-aout  +FAIL: ld-misc/defsym1
pdp11-dec-aout  +ERROR: /src/binutils-current/ld/testsuite/ld-misc/start.s: assembly failed

alpha-dec-vms  +FAIL: ld-scripts/defined4
mips64-linux  +FAIL: ld-scripts/defined4
mipsel-linux-gnu  +FAIL: ld-scripts/defined4
mipsisa32el-linux  +FAIL: ld-scripts/defined4
mips-linux  +FAIL: ld-scripts/defined4
mmix  +FAIL: ld-scripts/defined4
rs6000-aix4.3.3  +FAIL: ld-scripts/defined4
rs6000-aix5.1  +FAIL: ld-scripts/defined4
sh-pe  +FAIL: ld-scripts/defined4
tic30-unknown-aout  +FAIL: ld-scripts/defined4

alpha-dec-vms  +FAIL: ld-scripts/assert2

alpha-dec-vms  +FAIL: ld-scripts/expr2
arm-aout  +FAIL: ld-scripts/expr2
rs6000-aix4.3.3  +FAIL: ld-scripts/expr2
rs6000-aix5.1  +FAIL: ld-scripts/expr2
tic30-unknown-aout  +FAIL: ld-scripts/expr2

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2011-01-13 13:42       ` Alan Modra
@ 2011-01-13 14:02         ` H.J. Lu
  0 siblings, 0 replies; 15+ messages in thread
From: H.J. Lu @ 2011-01-13 14:02 UTC (permalink / raw)
  To: binutils

On Thu, Jan 13, 2011 at 5:42 AM, Alan Modra <amodra@gmail.com> wrote:
> On Thu, Jan 13, 2011 at 05:16:45AM -0800, H.J. Lu wrote:
>> Where is LD_FEATURE implemented? Is __ld_compatibility still supported?
>> Do we have testcases for new features? Is linker document up to date?
>
> The followup patch should answer most of these questions.  I tested
> LD_FEATURE with the following, and am considering applying this.
>
> Index: ld/scripttempl/elf.sc
> ===================================================================
> RCS file: /cvs/src/src/ld/scripttempl/elf.sc,v
> retrieving revision 1.105
> diff -u -p -r1.105 elf.sc
> --- ld/scripttempl/elf.sc       15 Dec 2010 14:56:38 -0000      1.105
> +++ ld/scripttempl/elf.sc       13 Jan 2011 13:41:14 -0000
> @@ -302,6 +302,7 @@ else
>  fi
>
>  cat <<EOF
> +LD_FEATURE("SANE_EXPR")
>  OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
>              "${LITTLE_OUTPUT_FORMAT}")
>  OUTPUT_ARCH(${OUTPUT_ARCH})
>

You should test explicitly with and without it. You should verify different
behaviors.

-- 
H.J.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2011-01-13 13:55         ` Alan Modra
@ 2011-01-13 14:06           ` H.J. Lu
  2011-01-13 15:13           ` H.J. Lu
  1 sibling, 0 replies; 15+ messages in thread
From: H.J. Lu @ 2011-01-13 14:06 UTC (permalink / raw)
  To: binutils

On Thu, Jan 13, 2011 at 5:55 AM, Alan Modra <amodra@gmail.com> wrote:
> On Thu, Jan 13, 2011 at 05:37:25AM -0800, H.J. Lu wrote:
>> You should add some testcases for this new feature.
>
> Blah.  How about *you* fix some of your recently added testcases,

I will investigate.

> which you added without approval, again.

They don't change linker. I added them to prevent further linker
damages, on popular targets.

> alpha-dec-vms  +FAIL: ld-misc/defsym1
> frv-linux  +FAIL: ld-misc/defsym1
> microblaze-elf  +FAIL: ld-misc/defsym1
> tic30-unknown-aout  +FAIL: ld-misc/defsym1
> pdp11-dec-aout  +ERROR: /src/binutils-current/ld/testsuite/ld-misc/start.s: assembly failed
>
> alpha-dec-vms  +FAIL: ld-scripts/defined4
> mips64-linux  +FAIL: ld-scripts/defined4
> mipsel-linux-gnu  +FAIL: ld-scripts/defined4
> mipsisa32el-linux  +FAIL: ld-scripts/defined4
> mips-linux  +FAIL: ld-scripts/defined4
> mmix  +FAIL: ld-scripts/defined4
> rs6000-aix4.3.3  +FAIL: ld-scripts/defined4
> rs6000-aix5.1  +FAIL: ld-scripts/defined4
> sh-pe  +FAIL: ld-scripts/defined4
> tic30-unknown-aout  +FAIL: ld-scripts/defined4
>
> alpha-dec-vms  +FAIL: ld-scripts/assert2
>
> alpha-dec-vms  +FAIL: ld-scripts/expr2
> arm-aout  +FAIL: ld-scripts/expr2
> rs6000-aix4.3.3  +FAIL: ld-scripts/expr2
> rs6000-aix5.1  +FAIL: ld-scripts/expr2
> tic30-unknown-aout  +FAIL: ld-scripts/expr2
>

-- 
H.J.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2011-01-13 13:55         ` Alan Modra
  2011-01-13 14:06           ` H.J. Lu
@ 2011-01-13 15:13           ` H.J. Lu
  2011-01-13 16:24             ` Hans-Peter Nilsson
  2011-01-13 16:25             ` Paul Koning
  1 sibling, 2 replies; 15+ messages in thread
From: H.J. Lu @ 2011-01-13 15:13 UTC (permalink / raw)
  To: binutils

On Thu, Jan 13, 2011 at 5:55 AM, Alan Modra <amodra@gmail.com> wrote:
> On Thu, Jan 13, 2011 at 05:37:25AM -0800, H.J. Lu wrote:
>> You should add some testcases for this new feature.
>
> Blah.  How about *you* fix some of your recently added testcases,
> which you added without approval, again.
>
> alpha-dec-vms  +FAIL: ld-misc/defsym1

Executing on host: sh -c {./ld-new
-L/export/gnu/import/git/binutils/ld/testsuite/ld-misc  -e 0 --defsym
foo=1 tmpdir/start.o tmpdir/libfoo.a -o tmpdir/dump tmpdir/dump0.o
2>&1}  /dev/null ld.tmp (timeout = 300)
spawn [open ...]^M
./ld-new: cannot find -limagelib
./ld-new: cannot find -lstarlet
./ld-new: cannot find -lsys$public_vectors
failed with: <./ld-new: cannot find -limagelib
./ld-new: cannot find -lstarlet
./ld-new: cannot find -lsys$public_vectors>, expected: <>
./ld-new: cannot find -limagelib
./ld-new: cannot find -lstarlet
./ld-new: cannot find -lsys$public_vectors
failed with: <./ld-new: cannot find -limagelib
./ld-new: cannot find -lstarlet
./ld-new: cannot find -lsys$public_vectors>, expected: <>
FAIL: ld-misc/defsym1

There are many similar failures.

> frv-linux  +FAIL: ld-misc/defsym1

Executing on host: sh -c {./ld-new
-L/export/gnu/import/git/binutils/ld/testsuite/ld-misc  -e 0 --defsym
foo=1 tmpdir/start.o tmpdir/libfoo.a -o tmpdir/dump tmpdir/dump0.o
2>&1}  /dev/null ld.tmp (timeout = 300)
spawn [open ...]^M
tmpdir/start.o: In function `main':
(.text+0x0): warning: cannot emit fixups in read-only section
./ld-new: final link failed: Nonrepresentable section on output
failed with: <tmpdir/start.o: In function `main':
(.text+0x0): warning: cannot emit fixups in read-only section
./ld-new: final link failed: Nonrepresentable section on output>, expected: <>
tmpdir/start.o: In function `main':
(.text+0x0): warning: cannot emit fixups in read-only section
./ld-new: final link failed: Nonrepresentable section on output
failed with: <tmpdir/start.o: In function `main':
(.text+0x0): warning: cannot emit fixups in read-only section
./ld-new: final link failed: Nonrepresentable section on output>, expected: <>
FAIL: ld-misc/defsym1

Not supported or linker bug?

> microblaze-elf  +FAIL: ld-misc/defsym1

Executing on host: sh -c {./ld-new
-L/export/gnu/import/git/binutils/ld/testsuite/ld-misc  -e 0 --defsym
foo=1 tmpdir/start.o tmpdir/libfoo.a -o tmpdir/dump tmpdir/dump0.o
2>&1}  /dev/null ld.tmp (timeout = 300)
spawn [open ...]^M
./ld-new: tmpdir/dump: Not enough room for program headers, try linking with -N
./ld-new: final link failed: Bad value
failed with: <./ld-new: tmpdir/dump: Not enough room for program
headers, try linking with -N
./ld-new: final link failed: Bad value>, expected: <>
./ld-new: tmpdir/dump: Not enough room for program headers, try linking with -N
./ld-new: final link failed: Bad value
failed with: <./ld-new: tmpdir/dump: Not enough room for program
headers, try linking with -N
./ld-new: final link failed: Bad value>, expected: <>
FAIL: ld-misc/defsym1

There are many similar failures.

> tic30-unknown-aout  +FAIL: ld-misc/defsym1

Executing on host: sh -c {./ld-new
-L/export/gnu/import/git/binutils/ld/testsuite/ld-misc  -e 0 --defsym
foo=1 tmpdir/start.o tmpdir/libfoo.a -o tmpdir/dump tmpdir/dump0.o
2>&1}  /dev/null ld.tmp (timeout = 300)
spawn [open ...]^M
sh: line 1: 17982 Segmentation fault      ./ld-new
-L/export/gnu/import/git/binutils/ld/testsuite/ld-misc -e 0 --defsym
foo=1 tmpdir/start.o tmpdir/libfoo.a -o tmpdir/dump tmpdir/dump0.o
2>&1
failed with: <sh: line 1: 17982 Segmentation fault      ./ld-new
-L/export/gnu/import/git/binutils/ld/testsuite/ld-misc -e 0 --defsym
foo=1 tmpdir/start.o tmpdir/libfoo.a -o tmpdir/dump tmpdir/dump0.o
2>&1>, expected: <>
sh: line 1: 17982 Segmentation fault      ./ld-new
-L/export/gnu/import/git/binutils/ld/testsuite/ld-misc -e 0 --defsym
foo=1 tmpdir/start.o tmpdir/libfoo.a -o tmpdir/dump tmpdir/dump0.o
2>&1
failed with: <sh: line 1: 17982 Segmentation fault      ./ld-new
-L/export/gnu/import/git/binutils/ld/testsuite/ld-misc -e 0 --defsym
foo=1 tmpdir/start.o tmpdir/libfoo.a -o tmpdir/dump tmpdir/dump0.o
2>&1>, expected: <>
FAIL: ld-misc/defsym1

Looks like linker bugs to me.

> pdp11-dec-aout  +ERROR: /src/binutils-current/ld/testsuite/ld-misc/start.s: assembly failed

/export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:
Assembler messages:
/export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:10: Fatal
error: Case value 2 unexpected at line 267 of file
"/export/gnu/import/git/binutils/gas/config/tc-pdp11.c"

/export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:
Assembler messages:
/export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:10: Fatal
error: Case value 2 unexpected at line 267 of file
"/export/gnu/import/git/binutils/gas/config/tc-pdp11.c"

ERROR: /export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:
assembly failed

Unsupported?

> alpha-dec-vms  +FAIL: ld-scripts/defined4

Same as ld-misc/defsym1.

> mips64-linux  +FAIL: ld-scripts/defined4
> mipsel-linux-gnu  +FAIL: ld-scripts/defined4
> mipsisa32el-linux  +FAIL: ld-scripts/defined4
> mips-linux  +FAIL: ld-scripts/defined4

We check that defined and defined1 have the same address.  MIPS targets
use different address. I will skip it on MIPS.

> mmix  +FAIL: ld-scripts/defined4

I got

[hjl@gnu-6 ld]$ ../binutils/objdump -t -h tmpdir/dump

tmpdir/dump:     file format mmo

Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         00000000  0000000000000000  0000000000000000  00000000  2**2

  1 .data         00000002  0000000000000000  0000000000000000  00000000  2**2
                  CONTENTS, ALLOC, LOAD, DATA
SYMBOL TABLE:
0000000000000000 g       .text Main
0000000000000000 g       .text defined1
0000000000000000 g       .text defined

Don't know why symbols are in .text section. I will skip it also.

> rs6000-aix4.3.3  +FAIL: ld-scripts/defined4
> rs6000-aix5.1  +FAIL: ld-scripts/defined4

Should XFAIL on rs6000-*-aix*.

> sh-pe  +FAIL: ld-scripts/defined4

Executing on host: sh -c {./ld-new
-L/export/gnu/import/git/binutils/ld/testsuite/ld-scripts
-Tdefined2.t -o tmpdir/dump tmpdir/dump0.o  2>&1}  /dev/null ld.tmp
(timeout = 300)
spawn [open ...]^M
DJ: zero vma section reloc detected: `.text' #0 f=283
succeeded with: <DJ: zero vma section reloc detected: `.text' #0
f=283>, expected: <>
DJ: zero vma section reloc detected: `.text' #0 f=283
succeeded with: <DJ: zero vma section reloc detected: `.text' #0
f=283>, expected: <>
FAIL: ld-scripts/defined2

There are many similar failures.

> tic30-unknown-aout  +FAIL: ld-scripts/defined4
>
> alpha-dec-vms  +FAIL: ld-scripts/assert2

Same as ld-misc/defsym1.

> alpha-dec-vms  +FAIL: ld-scripts/expr2

Same as ld-misc/defsym1.

> arm-aout  +FAIL: ld-scripts/expr2

[hjl@gnu-6 ld]$
/export/build/gnu/binutils-cross/build-arm-aout/ld/../gas/as-new    -o
tmpdir/dump0.o /export/gnu/import/git/binutils/ld/testsuite/ld-scripts/expr2.s
[hjl@gnu-6 ld]$ ./ld-new
-L/export/gnu/import/git/binutils/ld/testsuite/ld-scripts  -T expr2.t
-o tmpdir/dump tmpdir/dump0.o
[hjl@gnu-6 ld]$
/export/build/gnu/binutils-cross/build-arm-aout/ld/../binutils/nm-new
-B tmpdir/dump > tmpdir/dump.out
[hjl@gnu-6 ld]$ cat tmpdir/dump.out
00000000 a
0000c000 D
0000c000 A _end
0000c000 D _text
[hjl@gnu-6 ld]$

I will xfail it also.

> rs6000-aix4.3.3  +FAIL: ld-scripts/expr2
> rs6000-aix5.1  +FAIL: ld-scripts/expr2

Same as ld-scripts/defined4.

> tic30-unknown-aout  +FAIL: ld-scripts/expr2

Same as ld-misc/defsym1.

I am checking in this patch,

-- 
H.J.
---
diff --git a/ld/testsuite/ld-scripts/defined4.d
b/ld/testsuite/ld-scripts/defined4.d
index 2c3a6ea..b434e40 100644
--- a/ld/testsuite/ld-scripts/defined4.d
+++ b/ld/testsuite/ld-scripts/defined4.d
@@ -1,6 +1,10 @@
 #ld: -Tdefined4.t
 #nm: -B
 #source: defined4.s
+#xfail: rs6000-*-aix*
+#notarget: mips*-*-* mmix-*-*
+# We check that defined and defined1 have the same address.  MIPS targets
+# use different address. MMIX puts defined and defined1 in text section.

 # Check that arithmetic on DEFINED works.
 #...
diff --git a/ld/testsuite/ld-scripts/expr2.d b/ld/testsuite/ld-scripts/expr2.d
index 6f7e253..26354f6 100644
--- a/ld/testsuite/ld-scripts/expr2.d
+++ b/ld/testsuite/ld-scripts/expr2.d
@@ -1,5 +1,6 @@
 # ld: -T expr2.t
 #nm: -B
+#xfail: rs6000-*-aix* arm-*-*aout

 #...
 .* D defined

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2011-01-13 15:13           ` H.J. Lu
@ 2011-01-13 16:24             ` Hans-Peter Nilsson
  2011-01-13 16:38               ` H.J. Lu
  2011-01-13 16:25             ` Paul Koning
  1 sibling, 1 reply; 15+ messages in thread
From: Hans-Peter Nilsson @ 2011-01-13 16:24 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1247 bytes --]

On Thu, 13 Jan 2011, H.J. Lu wrote:
> > mmix  +FAIL: ld-scripts/defined4
>
> I got
>
> [hjl@gnu-6 ld]$ ../binutils/objdump -t -h tmpdir/dump
>
> tmpdir/dump:     file format mmo
>
> Sections:
> Idx Name          Size      VMA               LMA               File off  Algn
>   0 .text         00000000  0000000000000000  0000000000000000  00000000  2**2
>
>   1 .data         00000002  0000000000000000  0000000000000000  00000000  2**2
>                   CONTENTS, ALLOC, LOAD, DATA
> SYMBOL TABLE:
> 0000000000000000 g       .text Main
> 0000000000000000 g       .text defined1
> 0000000000000000 g       .text defined
>
> Don't know why symbols are in .text section. I will skip it also.

The "mmo" object (or rather, executable) format is very limited
and symbols are just numbers (or absolute values if you like):
the mapping to sections is done heuristically according to the
values and whatever sections there are, hence ".text" here.
Having said that, I realize that the heuristic got this
corner-case wrong: the .text section is empty and there is a
non-empty .data section, with defined/defined1 better described
as having the first address there.  So, a true bug.  Not a very
important one, though.  But since you asked...

brgds, H-P

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2011-01-13 15:13           ` H.J. Lu
  2011-01-13 16:24             ` Hans-Peter Nilsson
@ 2011-01-13 16:25             ` Paul Koning
  2011-01-13 16:39               ` H.J. Lu
  1 sibling, 1 reply; 15+ messages in thread
From: Paul Koning @ 2011-01-13 16:25 UTC (permalink / raw)
  To: H.J. Lu; +Cc: binutils


On Jan 13, 2011, at 10:12 AM, H.J. Lu wrote:

> ...
> 
>> pdp11-dec-aout  +ERROR: /src/binutils-current/ld/testsuite/ld-misc/start.s: assembly failed
> 
> /export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:
> Assembler messages:
> /export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:10: Fatal
> error: Case value 2 unexpected at line 267 of file
> "/export/gnu/import/git/binutils/gas/config/tc-pdp11.c"
> 
> /export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:
> Assembler messages:
> /export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:10: Fatal
> error: Case value 2 unexpected at line 267 of file
> "/export/gnu/import/git/binutils/gas/config/tc-pdp11.c"
> 
> ERROR: /export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:
> assembly failed
> 
> Unsupported?

Yes -- you can't have a relocatable 32-bit value in a pdp11.  It shouldn't be an internal error, though.

	paul


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2011-01-13 16:24             ` Hans-Peter Nilsson
@ 2011-01-13 16:38               ` H.J. Lu
  0 siblings, 0 replies; 15+ messages in thread
From: H.J. Lu @ 2011-01-13 16:38 UTC (permalink / raw)
  To: Hans-Peter Nilsson; +Cc: binutils

On Thu, Jan 13, 2011 at 8:24 AM, Hans-Peter Nilsson <hp@bitrange.com> wrote:
> On Thu, 13 Jan 2011, H.J. Lu wrote:
>> > mmix  +FAIL: ld-scripts/defined4
>>
>> I got
>>
>> [hjl@gnu-6 ld]$ ../binutils/objdump -t -h tmpdir/dump
>>
>> tmpdir/dump:     file format mmo
>>
>> Sections:
>> Idx Name          Size      VMA               LMA               File off  Algn
>>   0 .text         00000000  0000000000000000  0000000000000000  00000000  2**2
>>
>>   1 .data         00000002  0000000000000000  0000000000000000  00000000  2**2
>>                   CONTENTS, ALLOC, LOAD, DATA
>> SYMBOL TABLE:
>> 0000000000000000 g       .text Main
>> 0000000000000000 g       .text defined1
>> 0000000000000000 g       .text defined
>>
>> Don't know why symbols are in .text section. I will skip it also.
>
> The "mmo" object (or rather, executable) format is very limited
> and symbols are just numbers (or absolute values if you like):
> the mapping to sections is done heuristically according to the
> values and whatever sections there are, hence ".text" here.
> Having said that, I realize that the heuristic got this
> corner-case wrong: the .text section is empty and there is a
> non-empty .data section, with defined/defined1 better described
> as having the first address there.  So, a true bug.  Not a very
> important one, though.  But since you asked...
>

Feel free to change ld-scripts/defined4.

-- 
H.J.

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: PR 12001, --defsym
  2011-01-13 16:25             ` Paul Koning
@ 2011-01-13 16:39               ` H.J. Lu
  0 siblings, 0 replies; 15+ messages in thread
From: H.J. Lu @ 2011-01-13 16:39 UTC (permalink / raw)
  To: Paul Koning; +Cc: binutils

On Thu, Jan 13, 2011 at 8:25 AM, Paul Koning <paul_koning@dell.com> wrote:
>
> On Jan 13, 2011, at 10:12 AM, H.J. Lu wrote:
>
>> ...
>>
>>> pdp11-dec-aout  +ERROR: /src/binutils-current/ld/testsuite/ld-misc/start.s: assembly failed
>>
>> /export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:
>> Assembler messages:
>> /export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:10: Fatal
>> error: Case value 2 unexpected at line 267 of file
>> "/export/gnu/import/git/binutils/gas/config/tc-pdp11.c"
>>
>> /export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:
>> Assembler messages:
>> /export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:10: Fatal
>> error: Case value 2 unexpected at line 267 of file
>> "/export/gnu/import/git/binutils/gas/config/tc-pdp11.c"
>>
>> ERROR: /export/gnu/import/git/binutils/ld/testsuite/ld-misc/start.s:
>> assembly failed
>>
>> Unsupported?
>
> Yes -- you can't have a relocatable 32-bit value in a pdp11.  It shouldn't be an internal error, though.
>

Feel free to skip this test on pdp11 after you fix the
assembler.


-- 
H.J.

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2011-01-13 16:39 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-20 11:07 PR 12001, --defsym Alan Modra
2010-12-29 17:35 ` H.J. Lu
2011-01-13 13:06   ` Alan Modra
2011-01-13 13:16     ` H.J. Lu
2011-01-13 13:42       ` Alan Modra
2011-01-13 14:02         ` H.J. Lu
2011-01-13 13:28     ` Alan Modra
2011-01-13 13:37       ` H.J. Lu
2011-01-13 13:55         ` Alan Modra
2011-01-13 14:06           ` H.J. Lu
2011-01-13 15:13           ` H.J. Lu
2011-01-13 16:24             ` Hans-Peter Nilsson
2011-01-13 16:38               ` H.J. Lu
2011-01-13 16:25             ` Paul Koning
2011-01-13 16:39               ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).