Blame SOURCES/binutils-gold-8-byte-note-segments.patch

13ae24
diff -rup binutils.orig/gold/layout.cc binutils-2.30/gold/layout.cc
13ae24
--- binutils.orig/gold/layout.cc	2018-10-09 15:24:05.987282736 +0100
13ae24
+++ binutils-2.30/gold/layout.cc	2018-10-09 16:08:29.445946736 +0100
13ae24
@@ -2052,12 +2052,15 @@ Layout::attach_allocated_section_to_segm
13ae24
   // segment.
13ae24
   if (os->type() == elfcpp::SHT_NOTE)
13ae24
     {
13ae24
+      uint64_t os_align = os->addralign();
13ae24
+
13ae24
       // See if we already have an equivalent PT_NOTE segment.
13ae24
       for (p = this->segment_list_.begin();
13ae24
 	   p != segment_list_.end();
13ae24
 	   ++p)
13ae24
 	{
13ae24
 	  if ((*p)->type() == elfcpp::PT_NOTE
13ae24
+	      && (*p)->align() == os_align
13ae24
 	      && (((*p)->flags() & elfcpp::PF_W)
13ae24
 		  == (seg_flags & elfcpp::PF_W)))
13ae24
 	    {
13ae24
@@ -2071,6 +2074,7 @@ Layout::attach_allocated_section_to_segm
13ae24
 	  Output_segment* oseg = this->make_output_segment(elfcpp::PT_NOTE,
13ae24
 							   seg_flags);
13ae24
 	  oseg->add_output_section_to_nonload(os, seg_flags);
13ae24
+	  oseg->set_align(os_align);
13ae24
 	}
13ae24
     }
13ae24
 
13ae24
@@ -3171,6 +3175,10 @@ Layout::create_note(const char* name, in
13ae24
 #else
13ae24
   const int size = 32;
13ae24
 #endif
13ae24
+  // The NT_GNU_PROPERTY_TYPE_0 note conforms to gABI.
13ae24
+  const int addralign = ((note_type == elfcpp::NT_GNU_PROPERTY_TYPE_0
13ae24
+			 ? parameters->target().get_size()
13ae24
+			 : size) / 8);
13ae24
 
13ae24
   // The contents of the .note section.
13ae24
   size_t namesz = strlen(name) + 1;
13ae24
@@ -3234,7 +3242,7 @@ Layout::create_note(const char* name, in
13ae24
     return NULL;
13ae24
 
13ae24
   Output_section_data* posd = new Output_data_const_buffer(buffer, notehdrsz,
13ae24
-							   size / 8,
13ae24
+							   addralign,
13ae24
 							   "** note header");
13ae24
   os->add_output_section_data(posd);
13ae24
 
13ae24
@@ -3692,6 +3700,11 @@ Layout::segment_precedes(const Output_se
13ae24
     {
13ae24
       if (type1 != type2)
13ae24
 	return type1 < type2;
13ae24
+      uint64_t align1 = seg1->align();
13ae24
+      uint64_t align2 = seg2->align();
13ae24
+      // Place segments with larger alignments first.
13ae24
+      if (align1 != align2)
13ae24
+	return align1 > align2;
13ae24
       gold_assert(flags1 != flags2
13ae24
 		  || this->script_options_->saw_phdrs_clause());
13ae24
       return flags1 < flags2;
13ae24
diff -rup binutils.orig/gold/output.cc binutils-2.30/gold/output.cc
13ae24
--- binutils.orig/gold/output.cc	2018-10-09 15:24:05.986282744 +0100
13ae24
+++ binutils-2.30/gold/output.cc	2018-10-09 16:09:03.749670846 +0100
13ae24
@@ -4107,6 +4107,7 @@ Output_segment::Output_segment(elfcpp::E
13ae24
   : vaddr_(0),
13ae24
     paddr_(0),
13ae24
     memsz_(0),
13ae24
+    align_(0),
13ae24
     max_align_(0),
13ae24
     min_p_align_(0),
13ae24
     offset_(0),
13ae24
diff -rup binutils.orig/gold/output.h binutils-2.30/gold/output.h
13ae24
--- binutils.orig/gold/output.h	2018-10-09 15:24:05.984282760 +0100
13ae24
+++ binutils-2.30/gold/output.h	2018-10-09 16:09:45.665333727 +0100
13ae24
@@ -4676,6 +4676,16 @@ class Output_segment
13ae24
   offset() const
13ae24
   { return this->offset_; }
13ae24
 
13ae24
+  // Return the segment alignment.
13ae24
+  uint64_t
13ae24
+  align() const
13ae24
+  { return this->align_; }
13ae24
+
13ae24
+  // Set the segment alignment.
13ae24
+  void
13ae24
+  set_align(uint64_t align)
13ae24
+  { this->align_ = align; }
13ae24
+
13ae24
   // Whether this is a segment created to hold large data sections.
13ae24
   bool
13ae24
   is_large_data_segment() const
13ae24
@@ -4898,6 +4908,8 @@ class Output_segment
13ae24
   uint64_t paddr_;
13ae24
   // The size of the segment in memory.
13ae24
   uint64_t memsz_;
13ae24
+  // The segment alignment.
13ae24
+  uint64_t align_;
13ae24
   // The maximum section alignment.  The is_max_align_known_ field
13ae24
   // indicates whether this has been finalized.
13ae24
   uint64_t max_align_;