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

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