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

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