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]

[PATHC, GOLD]: Allow evaluation without a result section


Hi Ian,

  This is a small tidy up patch for GOLD.  It allows the eval_with_dot()
  and eval_maybe_dot() methods to be called without the result_section
  and result_alignment parameters, if the caller is not interested in
  them.
  
  It allows several dummy local variables to be removed from the source
  code, but it does mean that the eval functions now include a small
  amount of extra processing when they check to see whether the
  result_section pointer is NULL.  (The code to check for a NULL
  result_alignment pointer was already present).

  Tested without any regressions on an i686-linux-gnu target.

  Is the patch OK to apply or is this not the right way to go about
  tidying up this bit of the code ?

Cheers
  Nick

gold/ChangeLog
2010-09-30  Nick Clifton  <nickc@redhat.com>

	* expression.c (eval): Remove dummy argument.
        (eval_maybe_dot): Check for result_section_pointer being NULL.
        (value): Likewise.
        (BINARY_EXPRESSION): Likewise.
        (arg_value): Provide a default value for the arg_section_pointer
        parameter.
        * script-sections.cc (finalize_symbols): Remove dummy argument.
        (set_section_addresses): Likewise.
        (do_write_to_buffer): Likewise.
        (finalize_symbols): Likewise.
        * script.h (eval_with_dot): Provide default values for
        result_section and result_alignment parameters.
        (eval_maybe_dot): Likewise.
        
Index: gold/expression.cc
===================================================================
RCS file: /cvs/src/src/gold/expression.cc,v
retrieving revision 1.16
diff -c -3 -p -r1.16 expression.cc
*** gold/expression.cc	8 Sep 2010 16:10:31 -0000	1.16
--- gold/expression.cc	30 Sep 2010 06:24:43 -0000
*************** uint64_t
*** 76,84 ****
  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);
  }
  
  // Evaluate an expression which may refer to the dot symbol.
--- 76,83 ----
  Expression::eval(const Symbol_table* symtab, const Layout* layout,
  		 bool check_assertions)
  {
    return this->eval_maybe_dot(symtab, layout, check_assertions,
! 			      false, 0, NULL);
  }
  
  // Evaluate an expression which may refer to the dot symbol.
*************** Expression::eval_maybe_dot(const Symbol_
*** 115,121 ****
  
    // We assume the value is absolute, and only set this to a section
    // if we find a section relative reference.
!   *result_section_pointer = NULL;
    eei.result_section_pointer = result_section_pointer;
  
    eei.result_alignment_pointer = result_alignment_pointer;
--- 114,121 ----
  
    // We assume the value is absolute, and only set this to a section
    // if we find a section relative reference.
!   if (result_section_pointer != NULL)
!     *result_section_pointer = NULL;
    eei.result_section_pointer = result_section_pointer;
  
    eei.result_alignment_pointer = result_alignment_pointer;
*************** Symbol_expression::value(const Expressio
*** 181,187 ****
        return 0;
      }
  
!   *eei->result_section_pointer = sym->output_section();
  
    if (parameters->target().get_size() == 32)
      return eei->symtab->get_sized_symbol<32>(sym)->value();
--- 181,188 ----
        return 0;
      }
  
!   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();
*************** Dot_expression::value(const Expression_e
*** 217,223 ****
  		   "SECTIONS clause"));
        return 0;
      }
!   *eei->result_section_pointer = eei->dot_section;
    return eei->dot_value;
  }
  
--- 218,225 ----
  		   "SECTIONS clause"));
        return 0;
      }
!   if (eei->result_section_pointer != NULL)
!     *eei->result_section_pointer = eei->dot_section;
    return eei->dot_value;
  }
  
*************** class Unary_expression : public Expressi
*** 247,253 ****
   protected:
    uint64_t
    arg_value(const Expression_eval_info* eei,
! 	    Output_section** arg_section_pointer) const
    {
      return this->arg_->eval_maybe_dot(eei->symtab, eei->layout,
  				      eei->check_assertions,
--- 249,255 ----
   protected:
    uint64_t
    arg_value(const Expression_eval_info* eei,
! 	    Output_section** arg_section_pointer = NULL) const
    {
      return this->arg_->eval_maybe_dot(eei->symtab, eei->layout,
  				      eei->check_assertions,
*************** class Binary_expression : public Express
*** 406,412 ****
  					 &right_alignment);		\
        if (KEEP_RIGHT && left_section == NULL && right_section != NULL)	\
  	{								\
! 	  *eei->result_section_pointer = right_section;			\
  	  if (eei->result_alignment_pointer != NULL)			\
  	    *eei->result_alignment_pointer = right_alignment;		\
  	}								\
--- 408,415 ----
  					 &right_alignment);		\
        if (KEEP_RIGHT && left_section == NULL && right_section != NULL)	\
  	{								\
! 	  if (eei->result_section_pointer != NULL)			\
! 	    *eei->result_section_pointer = right_section;		\
  	  if (eei->result_alignment_pointer != NULL)			\
  	    *eei->result_alignment_pointer = right_alignment;		\
  	}								\
*************** class Binary_expression : public Express
*** 414,420 ****
  	       && left_section != NULL					\
  	       && right_section == NULL)				\
  	{								\
! 	  *eei->result_section_pointer = left_section;			\
  	  if (eei->result_alignment_pointer != NULL)			\
  	    *eei->result_alignment_pointer = right_alignment;		\
  	}								\
--- 417,424 ----
  	       && left_section != NULL					\
  	       && right_section == NULL)				\
  	{								\
! 	  if (eei->result_section_pointer != NULL)			\
! 	    *eei->result_section_pointer = left_section;		\
  	  if (eei->result_alignment_pointer != NULL)			\
  	    *eei->result_alignment_pointer = right_alignment;		\
  	}								\
*************** class Max_expression : public Binary_exp
*** 602,608 ****
      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;
      else if ((left_section != NULL || right_section != NULL)
  	     && parameters->options().relocatable())
        gold_warning(_("max applied to section relative value"));
--- 606,615 ----
      uint64_t right_alignment;
      uint64_t right = this->right_value(eei, &right_section, &right_alignment);
      if (left_section == right_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"));
*************** class Min_expression : public Binary_exp
*** 650,656 ****
      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;
      else if ((left_section != NULL || right_section != NULL)
  	     && parameters->options().relocatable())
        gold_warning(_("min applied to section relative value"));
--- 657,666 ----
      uint64_t right_alignment;
      uint64_t right = this->right_value(eei, &right_section, &right_alignment);
      if (left_section == right_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"));
*************** class Absolute_expression : public Unary
*** 756,765 ****
    uint64_t
    value(const Expression_eval_info* eei)
    {
!     Output_section* dummy;
!     uint64_t ret = this->arg_value(eei, &dummy);
      // Force the value to be absolute.
!     *eei->result_section_pointer = NULL;
      return ret;
    }
  
--- 766,775 ----
    uint64_t
    value(const Expression_eval_info* eei)
    {
!     uint64_t ret = this->arg_value(eei);
      // Force the value to be absolute.
!     if (eei->result_section_pointer != NULL)
!       *eei->result_section_pointer = NULL;
      return ret;
    }
  
*************** class Addr_expression : public Section_e
*** 873,879 ****
    value_from_output_section(const Expression_eval_info* eei,
  			    Output_section* os)
    {
!     *eei->result_section_pointer = os;
      return os->address();
    }
  
--- 883,890 ----
    value_from_output_section(const Expression_eval_info* eei,
  			    Output_section* os)
    {
!     if (eei->result_section_pointer != NULL)
!       *eei->result_section_pointer = os;
      return os->address();
    }
  
*************** class Loadaddr_expression : public Secti
*** 1078,1084 ****
        return os->load_address();
      else
        {
! 	*eei->result_section_pointer = os;
  	return os->address();
        }
    }
--- 1089,1096 ----
        return os->load_address();
      else
        {
! 	if (eei->result_section_pointer != NULL)
! 	  *eei->result_section_pointer = os;
  	return os->address();
        }
    }
*************** Segment_start_expression::value(const Ex
*** 1220,1229 ****
      return parameters->options().Tbss();
    else
      {
!       Output_section* dummy;
!       uint64_t ret = this->arg_value(eei, &dummy);
        // Force the value to be absolute.
!       *eei->result_section_pointer = NULL;
        return ret;
      }
  }
--- 1232,1241 ----
      return parameters->options().Tbss();
    else
      {
!       uint64_t ret = this->arg_value(eei);
        // Force the value to be absolute.
!       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 -c -3 -p -r1.42 script-sections.cc
*** gold/script-sections.cc	16 Sep 2010 15:52:15 -0000	1.42
--- gold/script-sections.cc	30 Sep 2010 06:24:44 -0000
*************** class Sections_element_dot_assignment : 
*** 656,664 ****
      // 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);
    }
  
    // Update the dot symbol while setting section addresses.
--- 656,663 ----
      // We ignore the section of the result because outside of an
      // output section definition the dot symbol is always considered
      // to be absolute.
      *dot_value = this->val_->eval_with_dot(symtab, layout, true, *dot_value,
! 					   NULL);
    }
  
    // Update the dot symbol while setting section addresses.
*************** class Sections_element_dot_assignment : 
*** 667,675 ****
  			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);
      *load_address = *dot_value;
    }
  
--- 666,673 ----
  			uint64_t* dot_value, uint64_t* dot_alignment,
  			uint64_t* load_address)
    {
      *dot_value = this->val_->eval_with_dot(symtab, layout, false, *dot_value,
! 					   NULL, NULL, dot_alignment);
      *load_address = *dot_value;
    }
  
*************** class Output_section_element_dot_assignm
*** 843,849 ****
  		   uint64_t* dot_value, Output_section** dot_section)
    {
      *dot_value = this->val_->eval_with_dot(symtab, layout, true, *dot_value,
! 					   *dot_section, dot_section, NULL);
    }
  
    // Update the dot symbol while setting section addresses.
--- 841,847 ----
  		   uint64_t* dot_value, Output_section** dot_section)
    {
      *dot_value = this->val_->eval_with_dot(symtab, layout, true, *dot_value,
! 					   *dot_section, dot_section);
    }
  
    // Update the dot symbol while setting section addresses.
*************** Output_data_expression::do_write(Output_
*** 980,989 ****
  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);
  
    if (parameters->target().is_big_endian())
      this->endian_write_to_buffer<true>(val, buf);
--- 978,986 ----
  void
  Output_data_expression::do_write_to_buffer(unsigned char* buf)
  {
    uint64_t val = this->val_->eval_with_dot(this->symtab_, this->layout_,
  					   true, this->dot_value_,
! 					   this->dot_section_);
  
    if (parameters->target().is_big_endian())
      this->endian_write_to_buffer<true>(val, buf);
*************** class Output_section_element_fill : publ
*** 1133,1139 ****
      Output_section* fill_section;
      uint64_t fill_val = this->val_->eval_with_dot(symtab, layout, false,
  						  *dot_value, *dot_section,
! 						  &fill_section, NULL);
      if (fill_section != NULL)
        gold_warning(_("fill value is not absolute"));
      // FIXME: The GNU linker supports fill values of arbitrary length.
--- 1130,1136 ----
      Output_section* fill_section;
      uint64_t fill_val = this->val_->eval_with_dot(symtab, layout, false,
  						  *dot_value, *dot_section,
! 						  &fill_section);
      if (fill_section != NULL)
        gold_warning(_("fill value is not absolute"));
      // FIXME: The GNU linker supports fill values of arbitrary length.
*************** Output_section_definition::finalize_symb
*** 2052,2069 ****
        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);
  	}
        if (this->align_ != NULL)
  	{
- 	  Output_section* dummy;
  	  uint64_t align = this->align_->eval_with_dot(symtab, layout, true,
! 						       *dot_value,
! 						       NULL,
! 						       &dummy, NULL);
  	  address = align_address(address, align);
  	}
        *dot_value = address;
--- 2049,2061 ----
        uint64_t address = *dot_value;
        if (this->address_ != NULL)
  	{
  	  address = this->address_->eval_with_dot(symtab, layout, true,
! 						  *dot_value, NULL);
  	}
        if (this->align_ != NULL)
  	{
  	  uint64_t align = this->align_->eval_with_dot(symtab, layout, true,
! 						       *dot_value, NULL);
  	  address = align_address(address, align);
  	}
        *dot_value = address;
*************** Output_section_definition::set_section_a
*** 2131,2139 ****
          address = *dot_value;
        else
          {
-           Output_section* dummy;
            address = this->address_->eval_with_dot(symtab, layout, true,
!                                                   *dot_value, NULL, &dummy,
                                                    dot_alignment);
          }
      }
--- 2123,2130 ----
          address = *dot_value;
        else
          {
            address = this->address_->eval_with_dot(symtab, layout, true,
!                                                   *dot_value, NULL, NULL,
                                                    dot_alignment);
          }
      }
*************** Output_section_definition::set_section_a
*** 2150,2156 ****
      {
        Output_section* align_section;
        align = this->align_->eval_with_dot(symtab, layout, true, *dot_value,
! 					  NULL, &align_section, NULL);
        if (align_section != NULL)
  	gold_warning(_("alignment of section %s is not absolute"),
  		     this->name_.c_str());
--- 2141,2147 ----
      {
        Output_section* align_section;
        align = this->align_->eval_with_dot(symtab, layout, true, *dot_value,
! 					  NULL, &align_section);
        if (align_section != NULL)
  	gold_warning(_("alignment of section %s is not absolute"),
  		     this->name_.c_str());
*************** Output_section_definition::set_section_a
*** 2178,2188 ****
      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);
        if (this->output_section_ != NULL)
          this->output_section_->set_load_address(laddr);
        this->evaluated_load_address_ = laddr;
--- 2169,2177 ----
      this->evaluated_load_address_ = address;
    else
      {
        uint64_t laddr =
  	this->load_address_->eval_with_dot(symtab, layout, true, *dot_value,
! 					   this->output_section_);
        if (this->output_section_ != NULL)
          this->output_section_->set_load_address(laddr);
        this->evaluated_load_address_ = laddr;
*************** Output_section_definition::set_section_a
*** 2196,2202 ****
        Output_section* subalign_section;
        subalign = this->subalign_->eval_with_dot(symtab, layout, true,
  						*dot_value, NULL,
! 						&subalign_section, NULL);
        if (subalign_section != NULL)
  	gold_warning(_("subalign of section %s is not absolute"),
  		     this->name_.c_str());
--- 2185,2191 ----
        Output_section* subalign_section;
        subalign = this->subalign_->eval_with_dot(symtab, layout, true,
  						*dot_value, NULL,
! 						&subalign_section);
        if (subalign_section != NULL)
  	gold_warning(_("subalign of section %s is not absolute"),
  		     this->name_.c_str());
*************** Output_section_definition::set_section_a
*** 2210,2217 ****
        Output_section* fill_section;
        uint64_t fill_val = this->fill_->eval_with_dot(symtab, layout, true,
  						     *dot_value,
! 						     NULL, &fill_section,
! 						     NULL);
        if (fill_section != NULL)
  	gold_warning(_("fill of section %s is not absolute"),
  		     this->name_.c_str());
--- 2199,2205 ----
        Output_section* fill_section;
        uint64_t fill_val = this->fill_->eval_with_dot(symtab, layout, true,
  						     *dot_value,
! 						     NULL, &fill_section);
        if (fill_section != NULL)
  	gold_warning(_("fill of section %s is not absolute"),
  		     this->name_.c_str());
Index: gold/script.h
===================================================================
RCS file: /cvs/src/src/gold/script.h,v
retrieving revision 1.34
diff -c -3 -p -r1.34 script.h
*** gold/script.h	2 Aug 2010 13:34:33 -0000	1.34
--- gold/script.h	30 Sep 2010 06:24:44 -0000
*************** class Expression
*** 93,99 ****
    uint64_t
    eval_with_dot(const Symbol_table*, const Layout*, bool check_assertions,
  		uint64_t dot_value, Output_section* dot_section,
! 		Output_section** result_section, uint64_t* result_alignment);
  
    // Return the value of an expression which may or may not be
    // permitted to refer to the dot symbol, depending on
--- 93,100 ----
    uint64_t
    eval_with_dot(const Symbol_table*, const Layout*, bool check_assertions,
  		uint64_t dot_value, Output_section* dot_section,
! 		Output_section** result_section = NULL,
! 		uint64_t* result_alignment = NULL);
  
    // Return the value of an expression which may or may not be
    // permitted to refer to the dot symbol, depending on
*************** class Expression
*** 102,108 ****
    eval_maybe_dot(const Symbol_table*, const Layout*, bool check_assertions,
  		 bool is_dot_available, uint64_t dot_value,
  		 Output_section* dot_section,
! 		 Output_section** result_section, uint64_t* result_alignment);
  
    // Print the expression to the FILE.  This is for debugging.
    virtual void
--- 103,110 ----
    eval_maybe_dot(const Symbol_table*, const Layout*, bool check_assertions,
  		 bool is_dot_available, uint64_t dot_value,
  		 Output_section* dot_section,
! 		 Output_section** result_section = NULL,
! 		 uint64_t* result_alignment = NULL);
  
    // Print the expression to the FILE.  This is for debugging.
    virtual void

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