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: [PATHC, GOLD]: Allow evaluation without a result section


Hi Ian,

I've come to believe that default arguments are not a good idea, as they
essentially introduce a new version of the function with the same name.
They save a little typing but they obscure what is happening.

OK then, here is a revised version of the patch without default arguments.


Can you send diffs with -u instead of -c?

Sure.


Is this version OK ?

Cheers
  Nick

gold/ChangeLog
2010-10-01  Nick Clifton  <nickc@redhat.com>

	* expression.cc (eval): Replace dummy argument with NULL.
	(eval_maybe_dot): Check for a NULL result section pointer.
	(Symbol_expression::value): Likewise.
	(Dot_expression::value): Likewise.
	(BINARY_EXPRESSION): Likewise.
	(Max_expression::value): Likewise.
	(Min_expression::value): Likewise.
	(Absolute_expression::value): Likewise.
	(Addr_expression::value_from_output_section): Likewise.
	(Loaddddr_expression::value_from_output_section): Likewise.
	(Segment_start_expression::value): Likewise.
	* script-sections.cc
	(Sections_elememt_dot_assignment::finalize_symbols): Replace dummy
	argument with NULL.
	(Sections_elememt_dot_assignment::set_section_addresses):
	Likewise.
	(Output_data_expression::do_write_to_buffer): Likewise.
	(Output_section_definition::finalize_symbols): Likewise.
	(Output_section_definition::set_section_addresses): Likewise.

Index: gold/expression.cc
===================================================================
RCS file: /cvs/src/src/gold/expression.cc,v
retrieving revision 1.16
diff -u -3 -p -r1.16 expression.cc
--- gold/expression.cc	8 Sep 2010 16:10:31 -0000	1.16
+++ gold/expression.cc	1 Oct 2010 10:05:10 -0000
@@ -76,9 +76,8 @@ uint64_t
 Expression::eval(const Symbol_table* symtab, const Layout* layout,
 		 bool check_assertions)
 {
-  Output_section* dummy;
   return this->eval_maybe_dot(symtab, layout, check_assertions,
-			      false, 0, NULL, &dummy, NULL);
+			      false, 0, NULL, NULL, NULL);
 }
 
 // Evaluate an expression which may refer to the dot symbol.
@@ -115,7 +114,8 @@ Expression::eval_maybe_dot(const Symbol_
 
   // We assume the value is absolute, and only set this to a section
   // if we find a section relative reference.
-  *result_section_pointer = NULL;
+  if (result_section_pointer != NULL)
+    *result_section_pointer = NULL;
   eei.result_section_pointer = result_section_pointer;
 
   eei.result_alignment_pointer = result_alignment_pointer;
@@ -181,7 +181,8 @@ Symbol_expression::value(const Expressio
       return 0;
     }
 
-  *eei->result_section_pointer = sym->output_section();
+  if (eei->result_section_pointer != NULL)
+    *eei->result_section_pointer = sym->output_section();
 
   if (parameters->target().get_size() == 32)
     return eei->symtab->get_sized_symbol<32>(sym)->value();
@@ -217,7 +218,8 @@ Dot_expression::value(const Expression_e
 		   "SECTIONS clause"));
       return 0;
     }
-  *eei->result_section_pointer = eei->dot_section;
+  if (eei->result_section_pointer != NULL)
+    *eei->result_section_pointer = eei->dot_section;
   return eei->dot_value;
 }
 
@@ -406,7 +408,8 @@ class Binary_expression : public Express
 					 &right_alignment);		\
       if (KEEP_RIGHT && left_section == NULL && right_section != NULL)	\
 	{								\
-	  *eei->result_section_pointer = right_section;			\
+	  if (eei->result_section_pointer != NULL)			\
+	    *eei->result_section_pointer = right_section;		\
 	  if (eei->result_alignment_pointer != NULL)			\
 	    *eei->result_alignment_pointer = right_alignment;		\
 	}								\
@@ -414,7 +417,8 @@ class Binary_expression : public Express
 	       && left_section != NULL					\
 	       && right_section == NULL)				\
 	{								\
-	  *eei->result_section_pointer = left_section;			\
+	  if (eei->result_section_pointer != NULL)			\
+	    *eei->result_section_pointer = left_section;		\
 	  if (eei->result_alignment_pointer != NULL)			\
 	    *eei->result_alignment_pointer = right_alignment;		\
 	}								\
@@ -602,7 +606,10 @@ class Max_expression : public Binary_exp
     uint64_t right_alignment;
     uint64_t right = this->right_value(eei, &right_section, &right_alignment);
     if (left_section == right_section)
-      *eei->result_section_pointer = left_section;
+      {
+	if (eei->result_section_pointer != NULL)
+	  *eei->result_section_pointer = left_section;
+      }
     else if ((left_section != NULL || right_section != NULL)
 	     && parameters->options().relocatable())
       gold_warning(_("max applied to section relative value"));
@@ -650,7 +657,10 @@ class Min_expression : public Binary_exp
     uint64_t right_alignment;
     uint64_t right = this->right_value(eei, &right_section, &right_alignment);
     if (left_section == right_section)
-      *eei->result_section_pointer = left_section;
+      {
+	if (eei->result_section_pointer != NULL)
+	  *eei->result_section_pointer = left_section;
+      }
     else if ((left_section != NULL || right_section != NULL)
 	     && parameters->options().relocatable())
       gold_warning(_("min applied to section relative value"));
@@ -756,10 +766,10 @@ class Absolute_expression : public Unary
   uint64_t
   value(const Expression_eval_info* eei)
   {
-    Output_section* dummy;
-    uint64_t ret = this->arg_value(eei, &dummy);
+    uint64_t ret = this->arg_value(eei, NULL);
     // Force the value to be absolute.
-    *eei->result_section_pointer = NULL;
+    if (eei->result_section_pointer != NULL)
+      *eei->result_section_pointer = NULL;
     return ret;
   }
 
@@ -873,7 +883,8 @@ class Addr_expression : public Section_e
   value_from_output_section(const Expression_eval_info* eei,
 			    Output_section* os)
   {
-    *eei->result_section_pointer = os;
+    if (eei->result_section_pointer != NULL)
+      *eei->result_section_pointer = os;
     return os->address();
   }
 
@@ -1078,7 +1089,8 @@ class Loadaddr_expression : public Secti
       return os->load_address();
     else
       {
-	*eei->result_section_pointer = os;
+	if (eei->result_section_pointer != NULL)
+	  *eei->result_section_pointer = os;
 	return os->address();
       }
   }
@@ -1220,10 +1232,10 @@ Segment_start_expression::value(const Ex
     return parameters->options().Tbss();
   else
     {
-      Output_section* dummy;
-      uint64_t ret = this->arg_value(eei, &dummy);
+      uint64_t ret = this->arg_value(eei, NULL);
       // Force the value to be absolute.
-      *eei->result_section_pointer = NULL;
+      if (eei->result_section_pointer != NULL)
+        *eei->result_section_pointer = NULL;
       return ret;
     }
 }
Index: gold/script-sections.cc
===================================================================
RCS file: /cvs/src/src/gold/script-sections.cc,v
retrieving revision 1.42
diff -u -3 -p -r1.42 script-sections.cc
--- gold/script-sections.cc	16 Sep 2010 15:52:15 -0000	1.42
+++ gold/script-sections.cc	1 Oct 2010 10:05:11 -0000
@@ -656,9 +656,8 @@ class Sections_element_dot_assignment : 
     // We ignore the section of the result because outside of an
     // output section definition the dot symbol is always considered
     // to be absolute.
-    Output_section* dummy;
     *dot_value = this->val_->eval_with_dot(symtab, layout, true, *dot_value,
-					   NULL, &dummy, NULL);
+					   NULL, NULL, NULL);
   }
 
   // Update the dot symbol while setting section addresses.
@@ -667,9 +666,8 @@ class Sections_element_dot_assignment : 
 			uint64_t* dot_value, uint64_t* dot_alignment,
 			uint64_t* load_address)
   {
-    Output_section* dummy;
     *dot_value = this->val_->eval_with_dot(symtab, layout, false, *dot_value,
-					   NULL, &dummy, dot_alignment);
+					   NULL, NULL, dot_alignment);
     *load_address = *dot_value;
   }
 
@@ -980,10 +978,9 @@ Output_data_expression::do_write(Output_
 void
 Output_data_expression::do_write_to_buffer(unsigned char* buf)
 {
-  Output_section* dummy;
   uint64_t val = this->val_->eval_with_dot(this->symtab_, this->layout_,
 					   true, this->dot_value_,
-					   this->dot_section_, &dummy, NULL);
+					   this->dot_section_, NULL, NULL);
 
   if (parameters->target().is_big_endian())
     this->endian_write_to_buffer<true>(val, buf);
@@ -2052,18 +2049,15 @@ Output_section_definition::finalize_symb
       uint64_t address = *dot_value;
       if (this->address_ != NULL)
 	{
-	  Output_section* dummy;
 	  address = this->address_->eval_with_dot(symtab, layout, true,
 						  *dot_value, NULL,
-						  &dummy, NULL);
+						  NULL, NULL);
 	}
       if (this->align_ != NULL)
 	{
-	  Output_section* dummy;
 	  uint64_t align = this->align_->eval_with_dot(symtab, layout, true,
-						       *dot_value,
-						       NULL,
-						       &dummy, NULL);
+						       *dot_value, NULL,
+						       NULL, NULL);
 	  address = align_address(address, align);
 	}
       *dot_value = address;
@@ -2131,9 +2125,8 @@ Output_section_definition::set_section_a
         address = *dot_value;
       else
         {
-          Output_section* dummy;
           address = this->address_->eval_with_dot(symtab, layout, true,
-                                                  *dot_value, NULL, &dummy,
+                                                  *dot_value, NULL, NULL,
                                                   dot_alignment);
         }
     }
@@ -2178,11 +2171,9 @@ Output_section_definition::set_section_a
     this->evaluated_load_address_ = address;
   else
     {
-      Output_section* dummy;
       uint64_t laddr =
 	this->load_address_->eval_with_dot(symtab, layout, true, *dot_value,
-					   this->output_section_, &dummy,
-					   NULL);
+					   this->output_section_, NULL, NULL);
       if (this->output_section_ != NULL)
         this->output_section_->set_load_address(laddr);
       this->evaluated_load_address_ = laddr;

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