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]

[PATCH] Copy symbol flags when doing an assignment with a ternary operator.


Hello,

The patch below extends ld to copy symbol flags when using a ternary operator,
e.g. __entry = DEFINED (__reset_vector) ? 0xbfc00000 : _start;.  

This is valuable in the case when the existing symbol has some architecture 
specific flags (e.g. microMIPS flag for MIPS targets). 

No new regressions on mips-img-elf or on x86_64-linux-gnu.

Thanks,
Simon

ld/ChangeLog

	* ld/ldexp.c:	(try_copy_symbol_flags): New. Factored out from..
			(exp_fold_tree_1): Here. Cope with ternary operator
			in assignments. Use new helper.
---
 ld/ldexp.c | 44 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 34 insertions(+), 10 deletions(-)

diff --git a/ld/ldexp.c b/ld/ldexp.c
index 5c4f8dd..3e54f39 100644
--- a/ld/ldexp.c
+++ b/ld/ldexp.c
@@ -873,6 +873,23 @@ is_align_conditional (const etree_type *tree)
   return 0;
 }
 
+/* Subroutine of exp_fold_tree_1 for copying a symbol type.  */
+
+static void
+try_copy_symbol_type (struct bfd_link_hash_entry * h, etree_type *src)
+{
+  if (src->type.node_class == etree_name)
+    {
+      struct bfd_link_hash_entry *hsrc;
+      hsrc = bfd_link_hash_lookup (link_info.hash, src->name.name,
+				    FALSE, FALSE, TRUE);
+      if (hsrc)
+	bfd_copy_link_hash_symbol_type (link_info.output_bfd, h,
+						    hsrc);
+    }
+
+}
+
 static void
 exp_fold_tree_1 (etree_type *tree)
 {
@@ -1051,18 +1068,25 @@ exp_fold_tree_1 (etree_type *tree)
 		tree->type.node_class = etree_provided;
 
 	      /* Copy the symbol type if this is a simple assignment of
-	         one symbol to another.  This could be more general
-		 (e.g. a ?: operator with NAMEs in each branch).  */
+	         one symbol to another.  Also, handle the case of a foldable
+		 ternary conditional with names on either side.  */
 	      if (tree->assign.src->type.node_class == etree_name)
+		try_copy_symbol_type (h, tree->assign.src);
+	      else if (tree->assign.src->type.node_class == etree_trinary)
 		{
-		  struct bfd_link_hash_entry *hsrc;
-
-		  hsrc = bfd_link_hash_lookup (link_info.hash,
-					       tree->assign.src->name.name,
-					       FALSE, FALSE, TRUE);
-		  if (hsrc)
-		    bfd_copy_link_hash_symbol_type (link_info.output_bfd, h,
-						    hsrc);
+		  exp_fold_tree_1 (tree->assign.src->trinary.cond);
+		  if (expld.result.valid_p)
+		    {
+		      if (expld.result.value
+			  && tree->assign.src->trinary.lhs->type.node_class
+			     == etree_name)
+			try_copy_symbol_type (h, tree->assign.src->trinary.lhs);
+
+		      if (!expld.result.value
+			  && tree->assign.src->trinary.rhs->type.node_class
+			     == etree_name)
+			try_copy_symbol_type (h, tree->assign.src->trinary.rhs);
+		    }
 		}
 	    }
 	  else if (expld.phase == lang_final_phase_enum)
-- 
2.1.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]