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