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

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