Nick Clifton 96e01b
diff -rcp ../binutils-2.22.52.0.4.orig/gold/layout.cc gold/layout.cc
Nick Clifton 96e01b
*** ../binutils-2.22.52.0.4.orig/gold/layout.cc	2012-08-14 09:38:36.359409453 +0100
Nick Clifton 96e01b
--- gold/layout.cc	2012-08-14 09:39:16.393410563 +0100
Nick Clifton 96e01b
*************** Layout::get_output_section(const char* n
Nick Clifton 96e01b
*** 749,754 ****
Nick Clifton 96e01b
--- 749,774 ----
Nick Clifton 96e01b
      }
Nick Clifton 96e01b
  }
Nick Clifton 96e01b
  
Nick Clifton 96e01b
+ // Returns TRUE iff NAME (an input section from RELOBJ) will
Nick Clifton 96e01b
+ // be mapped to an output section that should be KEPT.
Nick Clifton 96e01b
+ 
Nick Clifton 96e01b
+ bool
Nick Clifton 96e01b
+ Layout::keep_input_section(const Relobj* relobj, const char* name)
Nick Clifton 96e01b
+ {
Nick Clifton 96e01b
+   if (! this->script_options_->saw_sections_clause())
Nick Clifton 96e01b
+     return false;
Nick Clifton 96e01b
+ 
Nick Clifton 96e01b
+   Script_sections* ss = this->script_options_->script_sections();
Nick Clifton 96e01b
+   const char* file_name = relobj == NULL ? NULL : relobj->name().c_str();
Nick Clifton 96e01b
+   Output_section** output_section_slot;
Nick Clifton 96e01b
+   Script_sections::Section_type script_section_type;
Nick Clifton 96e01b
+   bool keep;
Nick Clifton 96e01b
+ 
Nick Clifton 96e01b
+   name = ss->output_section_name(file_name, name, &output_section_slot,
Nick Clifton 96e01b
+ 				 &script_section_type, &keep);
Nick Clifton 96e01b
+   return name != NULL && keep;
Nick Clifton 96e01b
+ }
Nick Clifton 96e01b
+ 
Nick Clifton 96e01b
  // Pick the output section to use for section NAME, in input file
Nick Clifton 96e01b
  // RELOBJ, with type TYPE and flags FLAGS.  RELOBJ may be NULL for a
Nick Clifton 96e01b
  // linker created section.  IS_INPUT_SECTION is true if we are
Nick Clifton 96e01b
*************** Layout::choose_output_section(const Relo
Nick Clifton 96e01b
*** 789,796 ****
Nick Clifton 96e01b
        Output_section** output_section_slot;
Nick Clifton 96e01b
        Script_sections::Section_type script_section_type;
Nick Clifton 96e01b
        const char* orig_name = name;
Nick Clifton 96e01b
        name = ss->output_section_name(file_name, name, &output_section_slot,
Nick Clifton 96e01b
! 				     &script_section_type);
Nick Clifton 96e01b
        if (name == NULL)
Nick Clifton 96e01b
  	{
Nick Clifton 96e01b
  	  gold_debug(DEBUG_SCRIPT, _("Unable to create output section '%s' "
Nick Clifton 96e01b
--- 809,818 ----
Nick Clifton 96e01b
        Output_section** output_section_slot;
Nick Clifton 96e01b
        Script_sections::Section_type script_section_type;
Nick Clifton 96e01b
        const char* orig_name = name;
Nick Clifton 96e01b
+       bool keep;
Nick Clifton 96e01b
        name = ss->output_section_name(file_name, name, &output_section_slot,
Nick Clifton 96e01b
! 				     &script_section_type, &keep);
Nick Clifton 96e01b
! 
Nick Clifton 96e01b
        if (name == NULL)
Nick Clifton 96e01b
  	{
Nick Clifton 96e01b
  	  gold_debug(DEBUG_SCRIPT, _("Unable to create output section '%s' "
Nick Clifton 96e01b
diff -rcp ../binutils-2.22.52.0.4.orig/gold/layout.h gold/layout.h
Nick Clifton 96e01b
*** ../binutils-2.22.52.0.4.orig/gold/layout.h	2012-08-14 09:38:52.579409903 +0100
Nick Clifton 96e01b
--- gold/layout.h	2012-08-14 09:39:16.403410563 +0100
Nick Clifton 96e01b
*************** class Layout
Nick Clifton 96e01b
*** 920,925 ****
Nick Clifton 96e01b
--- 920,930 ----
Nick Clifton 96e01b
    section_list() const
Nick Clifton 96e01b
    { return this->section_list_; }
Nick Clifton 96e01b
  
Nick Clifton 96e01b
+   // Returns TRUE iff NAME (an input section from RELOBJ) will
Nick Clifton 96e01b
+   // be mapped to an output section that should be KEPT.
Nick Clifton 96e01b
+   bool
Nick Clifton 96e01b
+   keep_input_section(const Relobj*, const char*);
Nick Clifton 96e01b
+   
Nick Clifton 96e01b
   private:
Nick Clifton 96e01b
    Layout(const Layout&);
Nick Clifton 96e01b
    Layout& operator=(const Layout&);
Nick Clifton 96e01b
diff -rcp ../binutils-2.22.52.0.4.orig/gold/object.cc gold/object.cc
Nick Clifton 96e01b
*** ../binutils-2.22.52.0.4.orig/gold/object.cc	2012-08-14 09:38:43.151409641 +0100
Nick Clifton 96e01b
--- gold/object.cc	2012-08-14 09:39:16.412410563 +0100
Nick Clifton 96e01b
*************** Sized_relobj_file<size, big_endian>::do_
Nick Clifton 96e01b
*** 1437,1442 ****
Nick Clifton 96e01b
--- 1437,1443 ----
Nick Clifton 96e01b
        if (is_gc_pass_one && parameters->options().gc_sections())
Nick Clifton 96e01b
  	{
Nick Clifton 96e01b
  	  if (this->is_section_name_included(name)
Nick Clifton 96e01b
+ 	      || layout->keep_input_section (this, name)
Nick Clifton 96e01b
  	      || shdr.get_sh_type() == elfcpp::SHT_INIT_ARRAY
Nick Clifton 96e01b
  	      || shdr.get_sh_type() == elfcpp::SHT_FINI_ARRAY)
Nick Clifton 96e01b
  	    {
Nick Clifton 96e01b
diff -rcp ../binutils-2.22.52.0.4.orig/gold/script-sections.cc gold/script-sections.cc
Nick Clifton 96e01b
*** ../binutils-2.22.52.0.4.orig/gold/script-sections.cc	2012-08-14 09:38:49.437409815 +0100
Nick Clifton 96e01b
--- gold/script-sections.cc	2012-08-14 09:39:16.413410563 +0100
Nick Clifton 96e01b
*************** class Sections_element
Nick Clifton 96e01b
*** 582,588 ****
Nick Clifton 96e01b
    // Output_section_definition.
Nick Clifton 96e01b
    virtual const char*
Nick Clifton 96e01b
    output_section_name(const char*, const char*, Output_section***,
Nick Clifton 96e01b
! 		      Script_sections::Section_type*)
Nick Clifton 96e01b
    { return NULL; }
Nick Clifton 96e01b
  
Nick Clifton 96e01b
    // Initialize OSP with an output section.
Nick Clifton 96e01b
--- 582,588 ----
Nick Clifton 96e01b
    // Output_section_definition.
Nick Clifton 96e01b
    virtual const char*
Nick Clifton 96e01b
    output_section_name(const char*, const char*, Output_section***,
Nick Clifton 96e01b
! 		      Script_sections::Section_type*, bool*)
Nick Clifton 96e01b
    { return NULL; }
Nick Clifton 96e01b
  
Nick Clifton 96e01b
    // Initialize OSP with an output section.
Nick Clifton 96e01b
*************** class Output_section_element
Nick Clifton 96e01b
*** 800,806 ****
Nick Clifton 96e01b
    // Return whether this element matches FILE_NAME and SECTION_NAME.
Nick Clifton 96e01b
    // The only real implementation is in Output_section_element_input.
Nick Clifton 96e01b
    virtual bool
Nick Clifton 96e01b
!   match_name(const char*, const char*) const
Nick Clifton 96e01b
    { return false; }
Nick Clifton 96e01b
  
Nick Clifton 96e01b
    // Set section addresses.  This includes applying assignments if the
Nick Clifton 96e01b
--- 800,806 ----
Nick Clifton 96e01b
    // Return whether this element matches FILE_NAME and SECTION_NAME.
Nick Clifton 96e01b
    // The only real implementation is in Output_section_element_input.
Nick Clifton 96e01b
    virtual bool
Nick Clifton 96e01b
!   match_name(const char*, const char*, bool *) const
Nick Clifton 96e01b
    { return false; }
Nick Clifton 96e01b
  
Nick Clifton 96e01b
    // Set section addresses.  This includes applying assignments if the
Nick Clifton 96e01b
*************** class Output_section_element_input : pub
Nick Clifton 96e01b
*** 1238,1247 ****
Nick Clifton 96e01b
      *dot_section = this->final_dot_section_;
Nick Clifton 96e01b
    }
Nick Clifton 96e01b
  
Nick Clifton 96e01b
!   // See whether we match FILE_NAME and SECTION_NAME as an input
Nick Clifton 96e01b
!   // section.
Nick Clifton 96e01b
    bool
Nick Clifton 96e01b
!   match_name(const char* file_name, const char* section_name) const;
Nick Clifton 96e01b
  
Nick Clifton 96e01b
    // Set the section address.
Nick Clifton 96e01b
    void
Nick Clifton 96e01b
--- 1238,1247 ----
Nick Clifton 96e01b
      *dot_section = this->final_dot_section_;
Nick Clifton 96e01b
    }
Nick Clifton 96e01b
  
Nick Clifton 96e01b
!   // See whether we match FILE_NAME and SECTION_NAME as an input section.
Nick Clifton 96e01b
!   // If we do then also indicate whether the section should be KEPT.
Nick Clifton 96e01b
    bool
Nick Clifton 96e01b
!   match_name(const char* file_name, const char* section_name, bool* keep) const;
Nick Clifton 96e01b
  
Nick Clifton 96e01b
    // Set the section address.
Nick Clifton 96e01b
    void
Nick Clifton 96e01b
*************** Output_section_element_input::match_file
Nick Clifton 96e01b
*** 1393,1407 ****
Nick Clifton 96e01b
    return true;
Nick Clifton 96e01b
  }
Nick Clifton 96e01b
  
Nick Clifton 96e01b
! // See whether we match FILE_NAME and SECTION_NAME.
Nick Clifton 96e01b
  
Nick Clifton 96e01b
  bool
Nick Clifton 96e01b
  Output_section_element_input::match_name(const char* file_name,
Nick Clifton 96e01b
! 					 const char* section_name) const
Nick Clifton 96e01b
  {
Nick Clifton 96e01b
    if (!this->match_file_name(file_name))
Nick Clifton 96e01b
      return false;
Nick Clifton 96e01b
  
Nick Clifton 96e01b
    // If there are no section name patterns, then we match.
Nick Clifton 96e01b
    if (this->input_section_patterns_.empty())
Nick Clifton 96e01b
      return true;
Nick Clifton 96e01b
--- 1393,1411 ----
Nick Clifton 96e01b
    return true;
Nick Clifton 96e01b
  }
Nick Clifton 96e01b
  
Nick Clifton 96e01b
! // See whether we match FILE_NAME and SECTION_NAME.  If we do then
Nick Clifton 96e01b
! // KEEP indicates whether the section should survive garbage collection.
Nick Clifton 96e01b
  
Nick Clifton 96e01b
  bool
Nick Clifton 96e01b
  Output_section_element_input::match_name(const char* file_name,
Nick Clifton 96e01b
! 					 const char* section_name,
Nick Clifton 96e01b
! 					 bool *keep) const
Nick Clifton 96e01b
  {
Nick Clifton 96e01b
    if (!this->match_file_name(file_name))
Nick Clifton 96e01b
      return false;
Nick Clifton 96e01b
  
Nick Clifton 96e01b
+   *keep = this->keep_;
Nick Clifton 96e01b
+ 
Nick Clifton 96e01b
    // If there are no section name patterns, then we match.
Nick Clifton 96e01b
    if (this->input_section_patterns_.empty())
Nick Clifton 96e01b
      return true;
Nick Clifton 96e01b
*************** class Output_section_definition : public
Nick Clifton 96e01b
*** 1861,1867 ****
Nick Clifton 96e01b
    // section name.
Nick Clifton 96e01b
    const char*
Nick Clifton 96e01b
    output_section_name(const char* file_name, const char* section_name,
Nick Clifton 96e01b
! 		      Output_section***, Script_sections::Section_type*);
Nick Clifton 96e01b
  
Nick Clifton 96e01b
    // Initialize OSP with an output section.
Nick Clifton 96e01b
    void
Nick Clifton 96e01b
--- 1865,1872 ----
Nick Clifton 96e01b
    // section name.
Nick Clifton 96e01b
    const char*
Nick Clifton 96e01b
    output_section_name(const char* file_name, const char* section_name,
Nick Clifton 96e01b
! 		      Output_section***, Script_sections::Section_type*,
Nick Clifton 96e01b
! 		      bool*);
Nick Clifton 96e01b
  
Nick Clifton 96e01b
    // Initialize OSP with an output section.
Nick Clifton 96e01b
    void
Nick Clifton 96e01b
*************** Output_section_definition::output_sectio
Nick Clifton 96e01b
*** 2146,2159 ****
Nick Clifton 96e01b
      const char* file_name,
Nick Clifton 96e01b
      const char* section_name,
Nick Clifton 96e01b
      Output_section*** slot,
Nick Clifton 96e01b
!     Script_sections::Section_type* psection_type)
Nick Clifton 96e01b
  {
Nick Clifton 96e01b
    // Ask each element whether it matches NAME.
Nick Clifton 96e01b
    for (Output_section_elements::const_iterator p = this->elements_.begin();
Nick Clifton 96e01b
         p != this->elements_.end();
Nick Clifton 96e01b
         ++p)
Nick Clifton 96e01b
      {
Nick Clifton 96e01b
!       if ((*p)->match_name(file_name, section_name))
Nick Clifton 96e01b
  	{
Nick Clifton 96e01b
  	  // We found a match for NAME, which means that it should go
Nick Clifton 96e01b
  	  // into this output section.
Nick Clifton 96e01b
--- 2151,2165 ----
Nick Clifton 96e01b
      const char* file_name,
Nick Clifton 96e01b
      const char* section_name,
Nick Clifton 96e01b
      Output_section*** slot,
Nick Clifton 96e01b
!     Script_sections::Section_type* psection_type,
Nick Clifton 96e01b
!     bool* keep)
Nick Clifton 96e01b
  {
Nick Clifton 96e01b
    // Ask each element whether it matches NAME.
Nick Clifton 96e01b
    for (Output_section_elements::const_iterator p = this->elements_.begin();
Nick Clifton 96e01b
         p != this->elements_.end();
Nick Clifton 96e01b
         ++p)
Nick Clifton 96e01b
      {
Nick Clifton 96e01b
!       if ((*p)->match_name(file_name, section_name, keep))
Nick Clifton 96e01b
  	{
Nick Clifton 96e01b
  	  // We found a match for NAME, which means that it should go
Nick Clifton 96e01b
  	  // into this output section.
Nick Clifton 96e01b
*************** Script_sections::output_section_name(
Nick Clifton 96e01b
*** 3365,3371 ****
Nick Clifton 96e01b
      const char* file_name,
Nick Clifton 96e01b
      const char* section_name,
Nick Clifton 96e01b
      Output_section*** output_section_slot,
Nick Clifton 96e01b
!     Script_sections::Section_type* psection_type)
Nick Clifton 96e01b
  {
Nick Clifton 96e01b
    for (Sections_elements::const_iterator p = this->sections_elements_->begin();
Nick Clifton 96e01b
         p != this->sections_elements_->end();
Nick Clifton 96e01b
--- 3371,3378 ----
Nick Clifton 96e01b
      const char* file_name,
Nick Clifton 96e01b
      const char* section_name,
Nick Clifton 96e01b
      Output_section*** output_section_slot,
Nick Clifton 96e01b
!     Script_sections::Section_type* psection_type,
Nick Clifton 96e01b
!     bool* keep)
Nick Clifton 96e01b
  {
Nick Clifton 96e01b
    for (Sections_elements::const_iterator p = this->sections_elements_->begin();
Nick Clifton 96e01b
         p != this->sections_elements_->end();
Nick Clifton 96e01b
*************** Script_sections::output_section_name(
Nick Clifton 96e01b
*** 3373,3379 ****
Nick Clifton 96e01b
      {
Nick Clifton 96e01b
        const char* ret = (*p)->output_section_name(file_name, section_name,
Nick Clifton 96e01b
  						  output_section_slot,
Nick Clifton 96e01b
! 						  psection_type);
Nick Clifton 96e01b
  
Nick Clifton 96e01b
        if (ret != NULL)
Nick Clifton 96e01b
  	{
Nick Clifton 96e01b
--- 3380,3386 ----
Nick Clifton 96e01b
      {
Nick Clifton 96e01b
        const char* ret = (*p)->output_section_name(file_name, section_name,
Nick Clifton 96e01b
  						  output_section_slot,
Nick Clifton 96e01b
! 						  psection_type, keep);
Nick Clifton 96e01b
  
Nick Clifton 96e01b
        if (ret != NULL)
Nick Clifton 96e01b
  	{
Nick Clifton 96e01b
diff -rcp ../binutils-2.22.52.0.4.orig/gold/script-sections.h gold/script-sections.h
Nick Clifton 96e01b
*** ../binutils-2.22.52.0.4.orig/gold/script-sections.h	2012-08-14 09:38:41.679409601 +0100
Nick Clifton 96e01b
--- gold/script-sections.h	2012-08-14 09:39:16.421410563 +0100
Nick Clifton 96e01b
*************** class Script_sections
Nick Clifton 96e01b
*** 163,172 ****
Nick Clifton 96e01b
    // PSCRIPT_SECTION_TYPE points to a location for returning the section
Nick Clifton 96e01b
    // type specified in script.  This can be SCRIPT_SECTION_TYPE_NONE if
Nick Clifton 96e01b
    // no type is specified.
Nick Clifton 96e01b
    const char*
Nick Clifton 96e01b
    output_section_name(const char* file_name, const char* section_name,
Nick Clifton 96e01b
  		      Output_section*** output_section_slot,
Nick Clifton 96e01b
! 		      Section_type* pscript_section_type);
Nick Clifton 96e01b
  
Nick Clifton 96e01b
    // Place a marker for an orphan output section into the SECTIONS
Nick Clifton 96e01b
    // clause.
Nick Clifton 96e01b
--- 163,174 ----
Nick Clifton 96e01b
    // PSCRIPT_SECTION_TYPE points to a location for returning the section
Nick Clifton 96e01b
    // type specified in script.  This can be SCRIPT_SECTION_TYPE_NONE if
Nick Clifton 96e01b
    // no type is specified.
Nick Clifton 96e01b
+   // *KEEP indicates whether the section should survive garbage collection.
Nick Clifton 96e01b
    const char*
Nick Clifton 96e01b
    output_section_name(const char* file_name, const char* section_name,
Nick Clifton 96e01b
  		      Output_section*** output_section_slot,
Nick Clifton 96e01b
! 		      Section_type* pscript_section_type,
Nick Clifton 96e01b
! 		      bool* keep);
Nick Clifton 96e01b
  
Nick Clifton 96e01b
    // Place a marker for an orphan output section into the SECTIONS
Nick Clifton 96e01b
    // clause.