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

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