This is the mail archive of the binutils-cvs@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]

[binutils-gdb] Make linker-created symbols relocatable where appropriate.


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=eb3908448bfe295e49bc7bd8a88b90deaa1ba95f

commit eb3908448bfe295e49bc7bd8a88b90deaa1ba95f
Author: Cary Coutant <ccoutant@gmail.com>
Date:   Wed Dec 21 16:21:23 2016 -0800

    Make linker-created symbols relocatable where appropriate.
    
    Linker-created symbols like __ehdr_start, __etext, __edata, and end
    should be relocatable, not absolute.
    
    gold/
    	* output.cc (Output_segment::first_section): Return NULL if there are
    	no sections in the segment.
    	* output.h (Output_segment::first_section_load_address): Assert that
    	first section is not NULL.
    	* symtab.cc (Symbol_table::sized_write_globals): Attach linker-created
    	segment-relative symbols to first section of the segment.

Diff:
---
 gold/ChangeLog | 9 +++++++++
 gold/output.cc | 2 +-
 gold/output.h  | 1 +
 gold/symtab.cc | 9 ++++++++-
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/gold/ChangeLog b/gold/ChangeLog
index c953031..ba74545 100644
--- a/gold/ChangeLog
+++ b/gold/ChangeLog
@@ -1,3 +1,12 @@
+2016-12-21  Cary Coutant  <ccoutant@gmail.com>
+
+	* output.cc (Output_segment::first_section): Return NULL if there are
+	no sections in the segment.
+	* output.h (Output_segment::first_section_load_address): Assert that
+	first section is not NULL.
+	* symtab.cc (Symbol_table::sized_write_globals): Attach linker-created
+	segment-relative symbols to first section of the segment.
+
 2016-12-21  Alan Modra  <amodra@gmail.com>
 
 	* arm.cc: Fix comment chars with high bit set.
diff --git a/gold/output.cc b/gold/output.cc
index cf934fb..64df3e8 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -4801,7 +4801,7 @@ Output_segment::first_section() const
 	    return (*p)->output_section();
 	}
     }
-  gold_unreachable();
+  return NULL;
 }
 
 // Return the number of Output_sections in an Output_segment.
diff --git a/gold/output.h b/gold/output.h
index 9083b5a..2b8f0c8 100644
--- a/gold/output.h
+++ b/gold/output.h
@@ -4741,6 +4741,7 @@ class Output_segment
   first_section_load_address() const
   {
     const Output_section* os = this->first_section();
+    gold_assert(os != NULL);
     return os->has_load_address() ? os->load_address() : os->address();
   }
 
diff --git a/gold/symtab.cc b/gold/symtab.cc
index 6865190..35989f0 100644
--- a/gold/symtab.cc
+++ b/gold/symtab.cc
@@ -3120,7 +3120,14 @@ Symbol_table::sized_write_globals(const Stringpool* sympool,
 	  break;
 
 	case Symbol::IN_OUTPUT_SEGMENT:
-	  shndx = elfcpp::SHN_ABS;
+	  {
+	    Output_segment* oseg = sym->output_segment();
+	    Output_section* osect = oseg->first_section();
+	    if (osect == NULL)
+	      shndx = elfcpp::SHN_ABS;
+	    else
+	      shndx = osect->out_shndx();
+	  }
 	  break;
 
 	case Symbol::IS_CONSTANT:


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