58725c
diff -rup ../binutils-2.27/gold/aarch64.cc gold/aarch64.cc
58725c
--- ../binutils-2.27/gold/aarch64.cc	2016-09-26 11:22:18.728811436 +0100
58725c
+++ gold/aarch64.cc	2016-11-03 15:05:31.000000000 +0000
58725c
@@ -6026,6 +6026,23 @@ Target_aarch64<size, big_endian>::Scan::
58725c
       }
58725c
       break;
58725c
 
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G0:        // 263
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G0_NC:     // 264
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G1:        // 265
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G1_NC:     // 266
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G2:        // 267
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G2_NC:     // 268
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G3:        // 269
58725c
+    case elfcpp::R_AARCH64_MOVW_SABS_G0:        // 270
58725c
+    case elfcpp::R_AARCH64_MOVW_SABS_G1:        // 271
58725c
+    case elfcpp::R_AARCH64_MOVW_SABS_G2:        // 272
58725c
+      if (parameters->options().output_is_position_independent())
58725c
+	{
58725c
+	  gold_error(_("%s: unsupported reloc %u in pos independent link."),
58725c
+		     object->name().c_str(), r_type);
58725c
+	}
58725c
+      break;
58725c
+
58725c
     case elfcpp::R_AARCH64_LD_PREL_LO19:        // 273
58725c
     case elfcpp::R_AARCH64_ADR_PREL_LO21:       // 274
58725c
     case elfcpp::R_AARCH64_ADR_PREL_PG_HI21:    // 275
58725c
@@ -6311,6 +6328,23 @@ Target_aarch64<size, big_endian>::Scan::
58725c
 	}
58725c
       break;
58725c
 
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G0:        // 263
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G0_NC:     // 264
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G1:        // 265
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G1_NC:     // 266
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G2:        // 267
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G2_NC:     // 268
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G3:        // 269
58725c
+    case elfcpp::R_AARCH64_MOVW_SABS_G0:        // 270
58725c
+    case elfcpp::R_AARCH64_MOVW_SABS_G1:        // 271
58725c
+    case elfcpp::R_AARCH64_MOVW_SABS_G2:        // 272
58725c
+      if (parameters->options().output_is_position_independent())
58725c
+	{
58725c
+	  gold_error(_("%s: unsupported reloc %u in pos independent link."),
58725c
+		     object->name().c_str(), r_type);
58725c
+	}
58725c
+      break;
58725c
+
58725c
     case elfcpp::R_AARCH64_LD_PREL_LO19:        // 273
58725c
     case elfcpp::R_AARCH64_ADR_PREL_LO21:       // 274
58725c
     case elfcpp::R_AARCH64_ADR_PREL_PG_HI21:    // 275
58725c
@@ -6993,6 +7027,23 @@ Target_aarch64<size, big_endian>::Reloca
58725c
 	view, object, psymval, addend, address, reloc_property);
58725c
       break;
58725c
 
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G0:
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G0_NC:
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G1:
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G1_NC:
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G2:
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G2_NC:
58725c
+    case elfcpp::R_AARCH64_MOVW_UABS_G3:
58725c
+      reloc_status = Reloc::template rela_general<32>(
58725c
+	view, object, psymval, addend, reloc_property);
58725c
+      break;
58725c
+    case elfcpp::R_AARCH64_MOVW_SABS_G0:
58725c
+    case elfcpp::R_AARCH64_MOVW_SABS_G1:
58725c
+    case elfcpp::R_AARCH64_MOVW_SABS_G2:
58725c
+      reloc_status = Reloc::movnz(view, psymval->value(object, addend),
58725c
+				  reloc_property);
58725c
+      break;
58725c
+
58725c
     case elfcpp::R_AARCH64_LD_PREL_LO19:
58725c
       reloc_status = Reloc::template pcrela_general<32>(
58725c
 	  view, object, psymval, addend, address, reloc_property);
58725c
@@ -8075,7 +8126,7 @@ Target_aarch64<size, big_endian>::is_err
58725c
     typename elfcpp::Swap<32,big_endian>::Valtype insn2)
58725c
 {
58725c
   uint32_t rt;
58725c
-  uint32_t rt2;
58725c
+  uint32_t rt2 = 0;
58725c
   uint32_t rn;
58725c
   uint32_t rm;
58725c
   uint32_t ra;
58725c
diff -rup ../binutils-2.27/gold/aarch64-reloc.def gold/aarch64-reloc.def
58725c
--- ../binutils-2.27/gold/aarch64-reloc.def	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/aarch64-reloc.def	2016-11-03 14:38:22.000000000 +0000
58725c
@@ -43,6 +43,20 @@ ARD(PREL32                       , STATI
58725c
 ARD(PREL16                       , STATIC ,  DATA       ,   Y,  -1,   15,16               ,    0,0  , Symbol::RELATIVE_REF ,                         DATA  )
58725c
 // Above is from Table 4-6, Data relocations, 257-262.
58725c
 
58725c
+ARD(MOVW_UABS_G0                 , STATIC ,  AARCH64    ,   Y,   0,    0,16               ,    0,15 , Symbol::ABSOLUTE_REF ,                         MOVW  )
58725c
+ARD(MOVW_UABS_G0_NC              , STATIC ,  AARCH64    ,   Y,   0,    0,0                ,    0,15 , Symbol::ABSOLUTE_REF ,                         MOVW  )
58725c
+ARD(MOVW_UABS_G1                 , STATIC ,  AARCH64    ,   Y,   0,    0,32               ,   16,31 , Symbol::ABSOLUTE_REF ,                         MOVW  )
58725c
+ARD(MOVW_UABS_G1_NC              , STATIC ,  AARCH64    ,   Y,   0,    0,0                ,   16,31 , Symbol::ABSOLUTE_REF ,                         MOVW  )
58725c
+ARD(MOVW_UABS_G2                 , STATIC ,  AARCH64    ,   Y,   0,    0,48               ,   32,47 , Symbol::ABSOLUTE_REF ,                         MOVW  )
58725c
+ARD(MOVW_UABS_G2_NC              , STATIC ,  AARCH64    ,   Y,   0,    0,0                ,   32,47 , Symbol::ABSOLUTE_REF ,                         MOVW  )
58725c
+ARD(MOVW_UABS_G3                 , STATIC ,  AARCH64    ,   Y,   0,    0,0                ,   48,63 , Symbol::ABSOLUTE_REF ,                         MOVW  )
58725c
+// Above is from Table 4-7, Group relocations to create a 16-, 32-, 48-, or 64-bit unsigned data value or address inline.
58725c
+
58725c
+ARD(MOVW_SABS_G0                 , STATIC ,  AARCH64    ,   Y,   0,   16,16               ,    0,15 , Symbol::ABSOLUTE_REF ,                         MOVW  )
58725c
+ARD(MOVW_SABS_G1                 , STATIC ,  AARCH64    ,   Y,   0,   32,32               ,   16,31 , Symbol::ABSOLUTE_REF ,                         MOVW  )
58725c
+ARD(MOVW_SABS_G2                 , STATIC ,  AARCH64    ,   Y,   0,   48,48               ,   32,47 , Symbol::ABSOLUTE_REF ,                         MOVW  )
58725c
+// Above is from Table 4-8, Group relocations to create a 16, 32, 48, or 64 bit signed data or offset value inline.
58725c
+
58725c
 ARD(LD_PREL_LO19		 , STATIC ,  AARCH64    ,   Y,  -1,   20,20		  ,    2,20 , Symbol::RELATIVE_REF , 			     LDST  )
58725c
 ARD(ADR_PREL_LO21		 , STATIC ,  AARCH64    ,   Y,  -1,   20,20		  ,    0,20 , Symbol::RELATIVE_REF , 			     ADR   )
58725c
 ARD(ADR_PREL_PG_HI21             , STATIC ,  AARCH64    ,   Y,  -1,   32,32               ,   12,32 , Symbol::RELATIVE_REF ,                         ADRP  )
58725c
diff -rup ../binutils-2.27/gold/aarch64-reloc-property.cc gold/aarch64-reloc-property.cc
58725c
--- ../binutils-2.27/gold/aarch64-reloc-property.cc	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/aarch64-reloc-property.cc	2016-11-03 15:05:32.000000000 +0000
58725c
@@ -59,17 +59,51 @@ template<>
58725c
 bool
58725c
 rvalue_checkup<0, 0>(int64_t) { return true; }
58725c
 
58725c
+namespace
58725c
+{
58725c
+
58725c
 template<int L, int U>
58725c
-uint64_t
58725c
-rvalue_bit_select(uint64_t x)
58725c
+class Rvalue_bit_select_impl
58725c
 {
58725c
-  if (U == 63) return x >> L;
58725c
-  return (x & (((uint64_t)1 << (U+1)) - 1)) >> L;
58725c
-}
58725c
+public:
58725c
+  static uint64_t
58725c
+  calc(uint64_t x)
58725c
+  {
58725c
+    return (x & ((1ULL << (U+1)) - 1)) >> L;
58725c
+  }
58725c
+};
58725c
+
58725c
+template<int L>
58725c
+class Rvalue_bit_select_impl<L, 63>
58725c
+{
58725c
+public:
58725c
+  static uint64_t
58725c
+  calc(uint64_t x)
58725c
+  {
58725c
+    return x >> L;
58725c
+  }
58725c
+};
58725c
 
58725c
+// By our convention, L=U=0 means that the whole value should be retrieved.
58725c
 template<>
58725c
+class Rvalue_bit_select_impl<0, 0>
58725c
+{
58725c
+public:
58725c
+  static uint64_t
58725c
+  calc(uint64_t x)
58725c
+  {
58725c
+    return x;
58725c
+  }
58725c
+};
58725c
+
58725c
+} // End anonymous namespace.
58725c
+
58725c
+template<int L, int U>
58725c
 uint64_t
58725c
-rvalue_bit_select<0, 0>(uint64_t x) { return x; }
58725c
+rvalue_bit_select(uint64_t x)
58725c
+{
58725c
+  return Rvalue_bit_select_impl<L, U>::calc(x);
58725c
+}
58725c
 
58725c
 AArch64_reloc_property::AArch64_reloc_property(
58725c
     unsigned int code,
58725c
diff -rup ../binutils-2.27/gold/arm.cc gold/arm.cc
58725c
--- ../binutils-2.27/gold/arm.cc	2016-09-26 11:22:18.629810833 +0100
58725c
+++ gold/arm.cc	2016-11-03 15:05:33.000000000 +0000
58725c
@@ -2128,8 +2128,36 @@ class Target_arm : public Sized_target<3
58725c
       stub_tables_(), stub_factory_(Stub_factory::get_instance()),
58725c
       should_force_pic_veneer_(false),
58725c
       arm_input_section_map_(), attributes_section_data_(NULL),
58725c
-      fix_cortex_a8_(false), cortex_a8_relocs_info_()
58725c
-  { }
58725c
+      fix_cortex_a8_(false), cortex_a8_relocs_info_(),
58725c
+      target1_reloc_(elfcpp::R_ARM_ABS32),
58725c
+      // This can be any reloc type but usually is R_ARM_GOT_PREL.
58725c
+      target2_reloc_(elfcpp::R_ARM_GOT_PREL)
58725c
+  {
58725c
+    if (parameters->options().user_set_target1_rel())
58725c
+      {
58725c
+	// FIXME: This is not strictly compatible with ld, which allows both
58725c
+	// --target1-abs and --target-rel to be given.
58725c
+	if (parameters->options().user_set_target1_abs())
58725c
+	  gold_error(_("Cannot use both --target1-abs and --target1-rel."));
58725c
+	else
58725c
+	  this->target1_reloc_ = elfcpp::R_ARM_REL32;
58725c
+      }
58725c
+    // We don't need to handle --target1-abs because target1_reloc_ is set
58725c
+    // to elfcpp::R_ARM_ABS32 in the member initializer list.
58725c
+
58725c
+    if (parameters->options().user_set_target2())
58725c
+      {
58725c
+	const char* target2 = parameters->options().target2();
58725c
+	if (strcmp(target2, "rel") == 0)
58725c
+	  this->target2_reloc_ = elfcpp::R_ARM_REL32;
58725c
+	else if (strcmp(target2, "abs") == 0)
58725c
+	  this->target2_reloc_ = elfcpp::R_ARM_ABS32;
58725c
+	else if (strcmp(target2, "got-rel") == 0)
58725c
+	  this->target2_reloc_ = elfcpp::R_ARM_GOT_PREL;
58725c
+	else
58725c
+	  gold_unreachable();
58725c
+      }
58725c
+  }
58725c
 
58725c
   // Whether we force PCI branch veneers.
58725c
   bool
58725c
@@ -2391,8 +2419,8 @@ class Target_arm : public Sized_target<3
58725c
   rel_irelative_section(Layout*);
58725c
 
58725c
   // Map platform-specific reloc types
58725c
-  static unsigned int
58725c
-  get_real_reloc_type(unsigned int r_type);
58725c
+  unsigned int
58725c
+  get_real_reloc_type(unsigned int r_type) const;
58725c
 
58725c
   //
58725c
   // Methods to support stub-generations.
58725c
@@ -3002,6 +3030,11 @@ class Target_arm : public Sized_target<3
58725c
   bool fix_cortex_a8_;
58725c
   // Map addresses to relocs for Cortex-A8 erratum.
58725c
   Cortex_a8_relocs_info cortex_a8_relocs_info_;
58725c
+  // What R_ARM_TARGET1 maps to. It can be R_ARM_REL32 or R_ARM_ABS32.
58725c
+  unsigned int target1_reloc_;
58725c
+  // What R_ARM_TARGET2 maps to. It should be one of R_ARM_REL32, R_ARM_ABS32
58725c
+  // and R_ARM_GOT_PREL.
58725c
+  unsigned int target2_reloc_;
58725c
 };
58725c
 
58725c
 template<bool big_endian>
58725c
@@ -6639,6 +6672,80 @@ Arm_relobj<big_endian>::do_relocate_sect
58725c
 	      section_address,
58725c
 	      section_size);
58725c
 	}
58725c
+	// BE8 swapping
58725c
+	if (parameters->options().be8())
58725c
+	  {
58725c
+	    section_size_type  span_start, span_end;
58725c
+	    elfcpp::Shdr<32, big_endian>
58725c
+	      shdr(pshdrs + i * elfcpp::Elf_sizes<32>::shdr_size);
58725c
+	    Mapping_symbol_position section_start(i, 0);
58725c
+	    typename Mapping_symbols_info::const_iterator p =
58725c
+	      this->mapping_symbols_info_.lower_bound(section_start);
58725c
+	    unsigned char* view = (*pviews)[i].view;
58725c
+	    Arm_address view_address = (*pviews)[i].address;
58725c
+	    section_size_type view_size = (*pviews)[i].view_size;
58725c
+	    while (p != this->mapping_symbols_info_.end()
58725c
+		   && p->first.first == i)
58725c
+	      {
58725c
+		typename Mapping_symbols_info::const_iterator next =
58725c
+		  this->mapping_symbols_info_.upper_bound(p->first);
58725c
+
58725c
+		// Only swap arm or thumb code.
58725c
+		if ((p->second == 'a') || (p->second == 't'))
58725c
+		  {
58725c
+		    Output_section* os = this->output_section(i);
58725c
+		    gold_assert(os != NULL);
58725c
+		    Arm_address section_address =
58725c
+		      this->simple_input_section_output_address(i, os);
58725c
+		    span_start = convert_to_section_size_type(p->first.second);
58725c
+		    if (next != this->mapping_symbols_info_.end()
58725c
+		        && next->first.first == i)
58725c
+		      span_end =
58725c
+			convert_to_section_size_type(next->first.second);
58725c
+		    else
58725c
+		      span_end =
58725c
+			convert_to_section_size_type(shdr.get_sh_size());
58725c
+		    unsigned char* section_view =
58725c
+		      view + (section_address - view_address);
58725c
+		    uint64_t section_size = this->section_size(i);
58725c
+
58725c
+		    gold_assert(section_address >= view_address
58725c
+				&& ((section_address + section_size)
58725c
+				    <= (view_address + view_size)));
58725c
+
58725c
+		    // Set Output view for swapping
58725c
+		    unsigned char *oview = section_view + span_start;
58725c
+		    unsigned int index = 0;
58725c
+		    if (p->second == 'a')
58725c
+		      {
58725c
+			while (index + 3 < (span_end - span_start))
58725c
+			  {
58725c
+			    typedef typename elfcpp::Swap<32, big_endian>
58725c
+						     ::Valtype Valtype;
58725c
+			    Valtype* wv =
58725c
+			      reinterpret_cast<Valtype*>(oview+index);
58725c
+			    uint32_t val = elfcpp::Swap<32, false>::readval(wv);
58725c
+			    elfcpp::Swap<32, true>::writeval(wv, val);
58725c
+			    index += 4;
58725c
+			  }
58725c
+		      }
58725c
+		    else if (p->second == 't')
58725c
+		      {
58725c
+		        while (index + 1 < (span_end - span_start))
58725c
+			  {
58725c
+			    typedef typename elfcpp::Swap<16, big_endian>
58725c
+						     ::Valtype Valtype;
58725c
+			    Valtype* wv =
58725c
+			      reinterpret_cast<Valtype*>(oview+index);
58725c
+			    uint16_t val = elfcpp::Swap<16, false>::readval(wv);
58725c
+			    elfcpp::Swap<16, true>::writeval(wv, val);
58725c
+			    index += 2;
58725c
+			   }
58725c
+		      }
58725c
+	          }
58725c
+	        p = next;
58725c
+	      }
58725c
+	  }
58725c
     }
58725c
 }
58725c
 
58725c
@@ -7785,7 +7892,18 @@ Output_data_plt_arm_standard<big_endian>
58725c
   const size_t num_first_plt_words = (sizeof(first_plt_entry)
58725c
 				      / sizeof(first_plt_entry[0]));
58725c
   for (size_t i = 0; i < num_first_plt_words - 1; i++)
58725c
-    elfcpp::Swap<32, big_endian>::writeval(pov + i * 4, first_plt_entry[i]);
58725c
+    {
58725c
+      if (parameters->options().be8())
58725c
+	{
58725c
+	  elfcpp::Swap<32, false>::writeval(pov + i * 4,
58725c
+					    first_plt_entry[i]);
58725c
+	}
58725c
+      else
58725c
+	{
58725c
+	  elfcpp::Swap<32, big_endian>::writeval(pov + i * 4,
58725c
+						 first_plt_entry[i]);
58725c
+	}
58725c
+    }
58725c
   // Last word in first PLT entry is &GOT[0] - .
58725c
   elfcpp::Swap<32, big_endian>::writeval(pov + 16,
58725c
 					 got_address - (plt_address + 16));
58725c
@@ -7846,11 +7964,21 @@ Output_data_plt_arm_short<big_endian>::d
58725c
     gold_error(_("PLT offset too large, try linking with --long-plt"));
58725c
 
58725c
   uint32_t plt_insn0 = plt_entry[0] | ((offset >> 20) & 0xff);
58725c
-  elfcpp::Swap<32, big_endian>::writeval(pov, plt_insn0);
58725c
   uint32_t plt_insn1 = plt_entry[1] | ((offset >> 12) & 0xff);
58725c
-  elfcpp::Swap<32, big_endian>::writeval(pov + 4, plt_insn1);
58725c
   uint32_t plt_insn2 = plt_entry[2] | (offset & 0xfff);
58725c
-  elfcpp::Swap<32, big_endian>::writeval(pov + 8, plt_insn2);
58725c
+
58725c
+  if (parameters->options().be8())
58725c
+    {
58725c
+      elfcpp::Swap<32, false>::writeval(pov, plt_insn0);
58725c
+      elfcpp::Swap<32, false>::writeval(pov + 4, plt_insn1);
58725c
+      elfcpp::Swap<32, false>::writeval(pov + 8, plt_insn2);
58725c
+    }
58725c
+  else
58725c
+    {
58725c
+      elfcpp::Swap<32, big_endian>::writeval(pov, plt_insn0);
58725c
+      elfcpp::Swap<32, big_endian>::writeval(pov + 4, plt_insn1);
58725c
+      elfcpp::Swap<32, big_endian>::writeval(pov + 8, plt_insn2);
58725c
+    }
58725c
 }
58725c
 
58725c
 // This class generates long (16-byte) entries, for arbitrary displacements.
58725c
@@ -7906,13 +8034,24 @@ Output_data_plt_arm_long<big_endian>::do
58725c
 		    - (plt_address + plt_offset + 8));
58725c
 
58725c
   uint32_t plt_insn0 = plt_entry[0] | (offset >> 28);
58725c
-  elfcpp::Swap<32, big_endian>::writeval(pov, plt_insn0);
58725c
   uint32_t plt_insn1 = plt_entry[1] | ((offset >> 20) & 0xff);
58725c
-  elfcpp::Swap<32, big_endian>::writeval(pov + 4, plt_insn1);
58725c
   uint32_t plt_insn2 = plt_entry[2] | ((offset >> 12) & 0xff);
58725c
-  elfcpp::Swap<32, big_endian>::writeval(pov + 8, plt_insn2);
58725c
   uint32_t plt_insn3 = plt_entry[3] | (offset & 0xfff);
58725c
-  elfcpp::Swap<32, big_endian>::writeval(pov + 12, plt_insn3);
58725c
+
58725c
+  if (parameters->options().be8())
58725c
+    {
58725c
+      elfcpp::Swap<32, false>::writeval(pov, plt_insn0);
58725c
+      elfcpp::Swap<32, false>::writeval(pov + 4, plt_insn1);
58725c
+      elfcpp::Swap<32, false>::writeval(pov + 8, plt_insn2);
58725c
+      elfcpp::Swap<32, false>::writeval(pov + 12, plt_insn3);
58725c
+    }
58725c
+  else
58725c
+    {
58725c
+      elfcpp::Swap<32, big_endian>::writeval(pov, plt_insn0);
58725c
+      elfcpp::Swap<32, big_endian>::writeval(pov + 4, plt_insn1);
58725c
+      elfcpp::Swap<32, big_endian>::writeval(pov + 8, plt_insn2);
58725c
+      elfcpp::Swap<32, big_endian>::writeval(pov + 12, plt_insn3);
58725c
+    }
58725c
 }
58725c
 
58725c
 // Write out the PLT.  This uses the hand-coded instructions above,
58725c
@@ -8414,7 +8553,7 @@ Target_arm<big_endian>::Scan::local(Symb
58725c
   if (is_discarded)
58725c
     return;
58725c
 
58725c
-  r_type = get_real_reloc_type(r_type);
58725c
+  r_type = target->get_real_reloc_type(r_type);
58725c
 
58725c
   // A local STT_GNU_IFUNC symbol may require a PLT entry.
58725c
   bool is_ifunc = lsym.get_st_type() == elfcpp::STT_GNU_IFUNC;
58725c
@@ -8820,7 +8959,7 @@ Target_arm<big_endian>::Scan::global(Sym
58725c
       && this->reloc_needs_plt_for_ifunc(object, r_type))
58725c
     target->make_plt_entry(symtab, layout, gsym);
58725c
 
58725c
-  r_type = get_real_reloc_type(r_type);
58725c
+  r_type = target->get_real_reloc_type(r_type);
58725c
   switch (r_type)
58725c
     {
58725c
     case elfcpp::R_ARM_NONE:
58725c
@@ -9446,7 +9585,7 @@ Target_arm<big_endian>::Relocate::reloca
58725c
 
58725c
   const elfcpp::Rel<32, big_endian> rel(preloc);
58725c
   unsigned int r_type = elfcpp::elf_r_type<32>(rel.get_r_info());
58725c
-  r_type = get_real_reloc_type(r_type);
58725c
+  r_type = target->get_real_reloc_type(r_type);
58725c
   const Arm_reloc_property* reloc_property =
58725c
     arm_reloc_property_table->get_implemented_static_reloc_property(r_type);
58725c
   if (reloc_property == NULL)
58725c
@@ -10156,7 +10295,9 @@ Target_arm<big_endian>::Classify_reloc::
58725c
     unsigned int r_type,
58725c
     Relobj* object)
58725c
 {
58725c
-  r_type = get_real_reloc_type(r_type);
58725c
+  Target_arm<big_endian>* arm_target =
58725c
+      Target_arm<big_endian>::default_target();
58725c
+  r_type = arm_target->get_real_reloc_type(r_type);
58725c
   const Arm_reloc_property* arp =
58725c
       arm_reloc_property_table->get_implemented_static_reloc_property(r_type);
58725c
   if (arp != NULL)
58725c
@@ -10580,17 +10721,15 @@ Target_arm<big_endian>::do_dynsym_value(
58725c
 //
58725c
 template<bool big_endian>
58725c
 unsigned int
58725c
-Target_arm<big_endian>::get_real_reloc_type(unsigned int r_type)
58725c
+Target_arm<big_endian>::get_real_reloc_type(unsigned int r_type) const
58725c
 {
58725c
   switch (r_type)
58725c
     {
58725c
     case elfcpp::R_ARM_TARGET1:
58725c
-      // This is either R_ARM_ABS32 or R_ARM_REL32;
58725c
-      return elfcpp::R_ARM_ABS32;
58725c
+      return this->target1_reloc_;
58725c
 
58725c
     case elfcpp::R_ARM_TARGET2:
58725c
-      // This can be any reloc type but usually is R_ARM_GOT_PREL
58725c
-      return elfcpp::R_ARM_GOT_PREL;
58725c
+      return this->target2_reloc_;
58725c
 
58725c
     default:
58725c
       return r_type;
58725c
@@ -10683,7 +10822,14 @@ Target_arm<big_endian>::do_adjust_elf_he
58725c
     e_ident[elfcpp::EI_OSABI] = 0;
58725c
   e_ident[elfcpp::EI_ABIVERSION] = 0;
58725c
 
58725c
-  // FIXME: Do EF_ARM_BE8 adjustment.
58725c
+  // Do EF_ARM_BE8 adjustment.
58725c
+  if (parameters->options().be8() && !big_endian)
58725c
+    gold_error("BE8 images only valid in big-endian mode.");
58725c
+  if (parameters->options().be8())
58725c
+    {
58725c
+      flags |= elfcpp::EF_ARM_BE8;
58725c
+      this->set_processor_specific_flags(flags);
58725c
+    }
58725c
 
58725c
   // If we're working in EABI_VER5, set the hard/soft float ABI flags
58725c
   // as appropriate.
58725c
diff -rup ../binutils-2.27/gold/configure gold/configure
58725c
--- ../binutils-2.27/gold/configure	2016-09-26 11:22:19.027813254 +0100
58725c
+++ gold/configure	2016-11-03 14:38:22.000000000 +0000
58725c
@@ -609,6 +609,7 @@ GOLD_LDFLAGS
58725c
 WARN_CXXFLAGS
58725c
 WARN_WRITE_STRINGS
58725c
 NO_WERROR
58725c
+WARN_CFLAGS_FOR_BUILD
58725c
 WARN_CFLAGS
58725c
 IFUNC_STATIC_FALSE
58725c
 IFUNC_STATIC_TRUE
58725c
@@ -6723,8 +6724,12 @@ fi
58725c
 # Set the 'development' global.
58725c
 . $srcdir/../bfd/development.sh
58725c
 
58725c
+# Set acp_cpp_for_build variable
58725c
+ac_cpp_for_build="$CC_FOR_BUILD -E $CPPFLAGS_FOR_BUILD"
58725c
+
58725c
 # Default set of GCC warnings to enable.
58725c
 GCC_WARN_CFLAGS="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
58725c
+GCC_WARN_CFLAGS_FOR_BUILD="-W -Wall -Wstrict-prototypes -Wmissing-prototypes"
58725c
 
58725c
 # Add -Wshadow if the compiler is a sufficiently recent version of GCC.
58725c
 cat confdefs.h - <<_ACEOF >conftest.$ac_ext
58725c
@@ -6769,6 +6774,36 @@ fi
58725c
 rm -f conftest*
58725c
 
58725c
 
58725c
+# Verify CC_FOR_BUILD to be compatible with waring flags
58725c
+
58725c
+# Add -Wshadow if the compiler is a sufficiently recent version of GCC.
58725c
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
58725c
+/* end confdefs.h.  */
58725c
+__GNUC__
58725c
+_ACEOF
58725c
+if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
58725c
+  $EGREP "^[0-3]$" >/dev/null 2>&1; then :
58725c
+
58725c
+else
58725c
+  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wshadow"
58725c
+fi
58725c
+rm -f conftest*
58725c
+
58725c
+
58725c
+# Add -Wstack-usage if the compiler is a sufficiently recent version of GCC.
58725c
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
58725c
+/* end confdefs.h.  */
58725c
+__GNUC__
58725c
+_ACEOF
58725c
+if (eval "$ac_cpp_for_build conftest.$ac_ext") 2>&5 |
58725c
+  $EGREP "^[0-4]$" >/dev/null 2>&1; then :
58725c
+
58725c
+else
58725c
+  GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wstack-usage=262144"
58725c
+fi
58725c
+rm -f conftest*
58725c
+
58725c
+
58725c
 # Check whether --enable-werror was given.
58725c
 if test "${enable_werror+set}" = set; then :
58725c
   enableval=$enable_werror; case "${enableval}" in
58725c
@@ -6784,6 +6819,7 @@ case "${host}" in
58725c
   *-*-mingw32*)
58725c
     if test "${GCC}" = yes -a -z "${ERROR_ON_WARNING}" ; then
58725c
       GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Wno-format"
58725c
+      GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Wno-format"
58725c
     fi
58725c
     ;;
58725c
   *) ;;
58725c
@@ -6797,25 +6833,32 @@ fi
58725c
 NO_WERROR=
58725c
 if test "${ERROR_ON_WARNING}" = yes ; then
58725c
     GCC_WARN_CFLAGS="$GCC_WARN_CFLAGS -Werror"
58725c
+    GCC_WARN_CFLAGS_FOR_BUILD="$GCC_WARN_CFLAGS_FOR_BUILD -Werror"
58725c
     NO_WERROR="-Wno-error"
58725c
 fi
58725c
 
58725c
 if test "${GCC}" = yes ; then
58725c
   WARN_CFLAGS="${GCC_WARN_CFLAGS}"
58725c
+  WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}"
58725c
 fi
58725c
 
58725c
 # Check whether --enable-build-warnings was given.
58725c
 if test "${enable_build_warnings+set}" = set; then :
58725c
   enableval=$enable_build_warnings; case "${enableval}" in
58725c
-  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}";;
58725c
+  yes)	WARN_CFLAGS="${GCC_WARN_CFLAGS}"
58725c
+        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD}";;
58725c
   no)	if test "${GCC}" = yes ; then
58725c
 	  WARN_CFLAGS="-w"
58725c
+      WARN_CFLAGS_FOR_BUILD="-w"
58725c
 	fi;;
58725c
   ,*)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
58725c
-        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}";;
58725c
+        WARN_CFLAGS="${GCC_WARN_CFLAGS} ${t}"
58725c
+        WARN_CFLAGS_FOR_BUILD="${GCC_WARN_CFLAGS_FOR_BUILD} ${t}";;
58725c
   *,)   t=`echo "${enableval}" | sed -e "s/,/ /g"`
58725c
-        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}";;
58725c
-  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`;;
58725c
+        WARN_CFLAGS="${t} ${GCC_WARN_CFLAGS}"
58725c
+        WARN_CFLAGS_FOR_BUILD="${t} ${GCC_WARN_CFLAGS_FOR_BUILD}";;
58725c
+  *)    WARN_CFLAGS=`echo "${enableval}" | sed -e "s/,/ /g"`
58725c
+        WARN_CFLAGS_FOR_BUILD=`echo "${enableval}" | sed -e "s/,/ /g"`;;
58725c
 esac
58725c
 fi
58725c
 
58725c
diff -rup ../binutils-2.27/gold/debug.h gold/debug.h
58725c
--- ../binutils-2.27/gold/debug.h	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/debug.h	2016-11-03 15:05:05.000000000 +0000
58725c
@@ -39,10 +39,11 @@ const int DEBUG_FILES = 0x4;
58725c
 const int DEBUG_RELAXATION = 0x8;
58725c
 const int DEBUG_INCREMENTAL = 0x10;
58725c
 const int DEBUG_LOCATION = 0x20;
58725c
+const int DEBUG_TARGET = 0x40;
58725c
 
58725c
 const int DEBUG_ALL = (DEBUG_TASK | DEBUG_SCRIPT | DEBUG_FILES
58725c
 		       | DEBUG_RELAXATION | DEBUG_INCREMENTAL
58725c
-		       | DEBUG_LOCATION);
58725c
+		       | DEBUG_LOCATION | DEBUG_TARGET);
58725c
 
58725c
 // Convert a debug string to the appropriate enum.
58725c
 inline int
58725c
@@ -57,6 +58,7 @@ debug_string_to_enum(const char* arg)
58725c
     { "relaxation", DEBUG_RELAXATION },
58725c
     { "incremental", DEBUG_INCREMENTAL },
58725c
     { "location", DEBUG_LOCATION },
58725c
+    { "target", DEBUG_TARGET },
58725c
     { "all", DEBUG_ALL }
58725c
   };
58725c
 
58725c
@@ -70,11 +72,11 @@ debug_string_to_enum(const char* arg)
58725c
 // Print a debug message if TYPE is enabled.  This is a macro so that
58725c
 // we only evaluate the arguments if necessary.
58725c
 
58725c
-#define gold_debug(TYPE, FORMAT, ...)				\
58725c
+#define gold_debug(TYPE, ...)					\
58725c
   do								\
58725c
     {								\
58725c
       if (is_debugging_enabled(TYPE))				\
58725c
-	parameters->errors()->debug(FORMAT, __VA_ARGS__);	\
58725c
+	parameters->errors()->debug(__VA_ARGS__);		\
58725c
     }								\
58725c
   while (0)
58725c
 
58725c
diff -rup ../binutils-2.27/gold/i386.cc gold/i386.cc
58725c
--- ../binutils-2.27/gold/i386.cc	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/i386.cc	2016-11-03 15:05:40.000000000 +0000
58725c
@@ -2794,8 +2794,11 @@ Target_i386::Relocate::relocate(const Re
58725c
 	   && r_type != elfcpp::R_386_PC32)
58725c
 	  || gsym == NULL
58725c
 	  || strcmp(gsym->name(), "___tls_get_addr") != 0)
58725c
-	gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
58725c
-			       _("missing expected TLS relocation"));
58725c
+	{
58725c
+	  gold_error_at_location(relinfo, relnum, rel.get_r_offset(),
58725c
+				 _("missing expected TLS relocation"));
58725c
+	  this->skip_call_tls_get_addr_ = false;
58725c
+	}
58725c
       else
58725c
 	{
58725c
 	  this->skip_call_tls_get_addr_ = false;
58725c
diff -rup ../binutils-2.27/gold/icf.cc gold/icf.cc
58725c
--- ../binutils-2.27/gold/icf.cc	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/icf.cc	2016-11-03 15:05:40.000000000 +0000
58725c
@@ -590,6 +590,7 @@ match_sections(unsigned int iteration_nu
58725c
                std::vector<unsigned int>* num_tracked_relocs,
58725c
                std::vector<unsigned int>* kept_section_id,
58725c
                const std::vector<Section_id>& id_section,
58725c
+	       const std::vector<uint64_t>& section_addraligns,
58725c
                std::vector<bool>* is_secn_or_group_unique,
58725c
                std::vector<std::string>* section_contents)
58725c
 {
58725c
@@ -630,13 +631,7 @@ match_sections(unsigned int iteration_nu
58725c
         {
58725c
           if ((*kept_section_id)[i] != i)
58725c
             {
58725c
-              // This section is already folded into something.  See
58725c
-              // if it should point to a different kept section.
58725c
-              unsigned int kept_section = (*kept_section_id)[i];
58725c
-              if (kept_section != (*kept_section_id)[kept_section])
58725c
-                {
58725c
-                  (*kept_section_id)[i] = (*kept_section_id)[kept_section];
58725c
-                }
58725c
+              // This section is already folded into something.
58725c
               continue;
58725c
             }
58725c
           this_secn_contents = get_section_contents(false, secn, i, NULL,
58725c
@@ -671,7 +666,25 @@ match_sections(unsigned int iteration_nu
58725c
                          this_secn_contents.c_str(),
58725c
                          this_secn_contents.length()) != 0)
58725c
                   continue;
58725c
-              (*kept_section_id)[i] = kept_section;
58725c
+
58725c
+	      // Check section alignment here.
58725c
+	      // The section with the larger alignment requirement
58725c
+	      // should be kept.  We assume alignment can only be 
58725c
+	      // zero or postive integral powers of two.
58725c
+	      uint64_t align_i = section_addraligns[i];
58725c
+	      uint64_t align_kept = section_addraligns[kept_section];
58725c
+	      if (align_i <= align_kept)
58725c
+		{
58725c
+		  (*kept_section_id)[i] = kept_section;
58725c
+		}
58725c
+	      else
58725c
+		{
58725c
+		  (*kept_section_id)[kept_section] = i;
58725c
+		  it->second = i;
58725c
+		  full_section_contents[kept_section].swap(
58725c
+		      full_section_contents[i]);
58725c
+		}
58725c
+
58725c
               converged = false;
58725c
               break;
58725c
             }
58725c
@@ -688,6 +701,26 @@ match_sections(unsigned int iteration_nu
58725c
         (*is_secn_or_group_unique)[i] = true;
58725c
     }
58725c
 
58725c
+  // If a section was folded into another section that was later folded
58725c
+  // again then the former has to be updated.
58725c
+  for (unsigned int i = 0; i < id_section.size(); i++)
58725c
+    {
58725c
+      // Find the end of the folding chain
58725c
+      unsigned int kept = i;
58725c
+      while ((*kept_section_id)[kept] != kept)
58725c
+        {
58725c
+          kept = (*kept_section_id)[kept];
58725c
+        }
58725c
+      // Update every element of the chain
58725c
+      unsigned int current = i;
58725c
+      while ((*kept_section_id)[current] != kept)
58725c
+        {
58725c
+          unsigned int next = (*kept_section_id)[current];
58725c
+          (*kept_section_id)[current] = kept;
58725c
+          current = next;
58725c
+        }
58725c
+    }
58725c
+
58725c
   return converged;
58725c
 }
58725c
 
58725c
@@ -719,6 +752,7 @@ Icf::find_identical_sections(const Input
58725c
 {
58725c
   unsigned int section_num = 0;
58725c
   std::vector<unsigned int> num_tracked_relocs;
58725c
+  std::vector<uint64_t> section_addraligns;
58725c
   std::vector<bool> is_secn_or_group_unique;
58725c
   std::vector<std::string> section_contents;
58725c
   const Target& target = parameters->target();
58725c
@@ -759,6 +793,7 @@ Icf::find_identical_sections(const Input
58725c
           this->section_id_[Section_id(*p, i)] = section_num;
58725c
           this->kept_section_id_.push_back(section_num);
58725c
           num_tracked_relocs.push_back(0);
58725c
+	  section_addraligns.push_back((*p)->section_addralign(i));
58725c
           is_secn_or_group_unique.push_back(false);
58725c
           section_contents.push_back("");
58725c
           section_num++;
58725c
@@ -779,8 +814,8 @@ Icf::find_identical_sections(const Input
58725c
       num_iterations++;
58725c
       converged = match_sections(num_iterations, symtab,
58725c
                                  &num_tracked_relocs, &this->kept_section_id_,
58725c
-                                 this->id_section_, &is_secn_or_group_unique,
58725c
-                                 &section_contents);
58725c
+                                 this->id_section_, section_addraligns,
58725c
+                                 &is_secn_or_group_unique, &section_contents);
58725c
     }
58725c
 
58725c
   if (parameters->options().print_icf_sections())
58725c
diff -rup ../binutils-2.27/gold/layout.cc gold/layout.cc
58725c
--- ../binutils-2.27/gold/layout.cc	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/layout.cc	2016-11-03 15:05:42.000000000 +0000
58725c
@@ -2135,7 +2135,7 @@ void
58725c
 Layout::create_notes()
58725c
 {
58725c
   this->create_gold_note();
58725c
-  this->create_executable_stack_info();
58725c
+  this->create_stack_segment();
58725c
   this->create_build_id();
58725c
 }
58725c
 
58725c
@@ -2785,7 +2785,7 @@ Layout::finalize(const Input_objects* in
58725c
       if (load_seg != NULL)
58725c
 	ehdr_start->set_output_segment(load_seg, Symbol::SEGMENT_START);
58725c
       else
58725c
-        ehdr_start->set_undefined();
58725c
+	ehdr_start->set_undefined();
58725c
     }
58725c
 
58725c
   // Set the file offsets of all the non-data sections we've seen so
58725c
@@ -2985,25 +2985,29 @@ Layout::create_gold_note()
58725c
 // executable.  Otherwise, if at least one input file a
58725c
 // .note.GNU-stack section, and some input file has no .note.GNU-stack
58725c
 // section, we use the target default for whether the stack should be
58725c
-// executable.  Otherwise, we don't generate a stack note.  When
58725c
-// generating a object file, we create a .note.GNU-stack section with
58725c
-// the appropriate marking.  When generating an executable or shared
58725c
-// library, we create a PT_GNU_STACK segment.
58725c
+// executable.  If -z stack-size was used to set a p_memsz value for
58725c
+// PT_GNU_STACK, we generate the segment regardless.  Otherwise, we
58725c
+// don't generate a stack note.  When generating a object file, we
58725c
+// create a .note.GNU-stack section with the appropriate marking.
58725c
+// When generating an executable or shared library, we create a
58725c
+// PT_GNU_STACK segment.
58725c
 
58725c
 void
58725c
-Layout::create_executable_stack_info()
58725c
+Layout::create_stack_segment()
58725c
 {
58725c
   bool is_stack_executable;
58725c
   if (parameters->options().is_execstack_set())
58725c
     {
58725c
       is_stack_executable = parameters->options().is_stack_executable();
58725c
       if (!is_stack_executable
58725c
-          && this->input_requires_executable_stack_
58725c
-          && parameters->options().warn_execstack())
58725c
+	  && this->input_requires_executable_stack_
58725c
+	  && parameters->options().warn_execstack())
58725c
 	gold_warning(_("one or more inputs require executable stack, "
58725c
-	               "but -z noexecstack was given"));
58725c
+		       "but -z noexecstack was given"));
58725c
     }
58725c
-  else if (!this->input_with_gnu_stack_note_)
58725c
+  else if (!this->input_with_gnu_stack_note_
58725c
+	   && (!parameters->options().user_set_stack_size()
58725c
+	       || parameters->options().relocatable()))
58725c
     return;
58725c
   else
58725c
     {
58725c
@@ -3032,7 +3036,12 @@ Layout::create_executable_stack_info()
58725c
       int flags = elfcpp::PF_R | elfcpp::PF_W;
58725c
       if (is_stack_executable)
58725c
 	flags |= elfcpp::PF_X;
58725c
-      this->make_output_segment(elfcpp::PT_GNU_STACK, flags);
58725c
+      Output_segment* seg =
58725c
+	this->make_output_segment(elfcpp::PT_GNU_STACK, flags);
58725c
+      seg->set_size(parameters->options().stack_size());
58725c
+      // BFD lets targets override this default alignment, but the only
58725c
+      // targets that do so are ones that Gold does not support so far.
58725c
+      seg->set_minimum_p_align(16);
58725c
     }
58725c
 }
58725c
 
58725c
@@ -3718,7 +3727,9 @@ Layout::set_segment_offsets(const Target
58725c
        p != this->segment_list_.end();
58725c
        ++p)
58725c
     {
58725c
-      if ((*p)->type() != elfcpp::PT_LOAD)
58725c
+      // PT_GNU_STACK was set up correctly when it was created.
58725c
+      if ((*p)->type() != elfcpp::PT_LOAD
58725c
+	  && (*p)->type() != elfcpp::PT_GNU_STACK)
58725c
 	(*p)->set_offset((*p)->type() == elfcpp::PT_GNU_RELRO
58725c
 			 ? increase_relro
58725c
 			 : 0);
58725c
diff -rup ../binutils-2.27/gold/layout.h gold/layout.h
58725c
--- ../binutils-2.27/gold/layout.h	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/layout.h	2016-11-03 15:05:12.000000000 +0000
58725c
@@ -1037,9 +1037,9 @@ class Layout
58725c
   void
58725c
   create_gold_note();
58725c
 
58725c
-  // Record whether the stack must be executable.
58725c
+  // Record whether the stack must be executable, and a user-supplied size.
58725c
   void
58725c
-  create_executable_stack_info();
58725c
+  create_stack_segment();
58725c
 
58725c
   // Create a build ID note if needed.
58725c
   void
58725c
diff -rup ../binutils-2.27/gold/Makefile.in gold/Makefile.in
58725c
--- ../binutils-2.27/gold/Makefile.in	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/Makefile.in	2016-11-03 14:38:22.000000000 +0000
58725c
@@ -87,8 +87,8 @@ subdir = .
58725c
 DIST_COMMON = NEWS README ChangeLog $(srcdir)/Makefile.in \
58725c
 	$(srcdir)/Makefile.am $(top_srcdir)/configure \
58725c
 	$(am__configure_deps) $(srcdir)/config.in \
58725c
-	$(srcdir)/../mkinstalldirs $(top_srcdir)/po/Make-in \
58725c
-	ftruncate.c pread.c mremap.c ffsll.c yyscript.h yyscript.c \
58725c
+	$(srcdir)/../mkinstalldirs $(top_srcdir)/po/Make-in ffsll.c \
58725c
+	mremap.c ftruncate.c pread.c yyscript.h yyscript.c \
58725c
 	$(srcdir)/../depcomp $(srcdir)/../ylwrap
58725c
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
58725c
 am__aclocal_m4_deps = $(top_srcdir)/../config/depstand.m4 \
58725c
@@ -409,6 +409,7 @@ TARGETOBJS = @TARGETOBJS@
58725c
 USE_NLS = @USE_NLS@
58725c
 VERSION = @VERSION@
58725c
 WARN_CFLAGS = @WARN_CFLAGS@
58725c
+WARN_CFLAGS_FOR_BUILD = @WARN_CFLAGS_FOR_BUILD@
58725c
 WARN_CXXFLAGS = @WARN_CXXFLAGS@
58725c
 WARN_WRITE_STRINGS = @WARN_WRITE_STRINGS@
58725c
 XGETTEXT = @XGETTEXT@
58725c
diff -rup ../binutils-2.27/gold/options.h gold/options.h
58725c
--- ../binutils-2.27/gold/options.h	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/options.h	2016-11-03 15:05:13.000000000 +0000
58725c
@@ -647,7 +647,7 @@ class General_options
58725c
   DEFINE_bool(apply_dynamic_relocs, options::TWO_DASHES, '\0', true,
58725c
 	      N_("Apply link-time values for dynamic relocations (default)"),
58725c
 	      N_("(aarch64 only) Do not apply link-time values "
58725c
-	         "for dynamic relocations"));
58725c
+		 "for dynamic relocations"));
58725c
 
58725c
   DEFINE_bool(as_needed, options::TWO_DASHES, '\0', false,
58725c
 	      N_("Only set DT_NEEDED for shared libraries if used"),
58725c
@@ -674,6 +674,9 @@ class General_options
58725c
   DEFINE_bool_alias(dn, Bdynamic, options::ONE_DASH, '\0',
58725c
 		    N_("alias for -Bstatic"), NULL, true);
58725c
 
58725c
+  DEFINE_bool(be8,options::TWO_DASHES, '\0', false,
58725c
+	      N_("Output BE8 format image"), NULL);
58725c
+
58725c
   DEFINE_bool(Bgroup, options::ONE_DASH, '\0', false,
58725c
 	      N_("Use group name lookup rules for shared library"), NULL);
58725c
 
58725c
@@ -1152,6 +1155,17 @@ class General_options
58725c
   DEFINE_string(sysroot, options::TWO_DASHES, '\0', "",
58725c
 		N_("Set target system root directory"), N_("DIR"));
58725c
 
58725c
+  DEFINE_bool(target1_rel, options::TWO_DASHES, '\0', false,
58725c
+	      N_("(ARM only) Force R_ARM_TARGET1 type to R_ARM_REL32"),
58725c
+	      NULL);
58725c
+  DEFINE_bool(target1_abs, options::TWO_DASHES, '\0', false,
58725c
+	      N_("(ARM only) Force R_ARM_TARGET1 type to R_ARM_ABS32"),
58725c
+	      NULL);
58725c
+  DEFINE_enum(target2, options::TWO_DASHES, '\0', NULL,
58725c
+	      N_("(ARM only) Set R_ARM_TARGET2 relocation type"),
58725c
+	      N_("[rel, abs, got-rel"),
58725c
+	      {"rel", "abs", "got-rel"});
58725c
+
58725c
   DEFINE_bool(trace, options::TWO_DASHES, 't', false,
58725c
 	      N_("Print the name of each input file"), NULL);
58725c
 
58725c
@@ -1293,7 +1307,7 @@ class General_options
58725c
 	      N_("Mark output as requiring executable stack"), NULL);
58725c
   DEFINE_bool(global, options::DASH_Z, '\0', false,
58725c
 	      N_("Make symbols in DSO available for subsequently loaded "
58725c
-	         "objects"), NULL);
58725c
+		 "objects"), NULL);
58725c
   DEFINE_bool(initfirst, options::DASH_Z, '\0', false,
58725c
 	      N_("Mark DSO to be initialized first at runtime"),
58725c
 	      NULL);
58725c
@@ -1339,6 +1353,8 @@ class General_options
58725c
   DEFINE_bool(relro, options::DASH_Z, '\0', DEFAULT_LD_Z_RELRO,
58725c
 	      N_("Where possible mark variables read-only after relocation"),
58725c
 	      N_("Don't mark variables read-only after relocation"));
58725c
+  DEFINE_uint64(stack_size, options::DASH_Z, '\0', 0,
58725c
+		N_("Set PT_GNU_STACK segment p_memsz to SIZE"), N_("SIZE"));
58725c
   DEFINE_bool(text, options::DASH_Z, '\0', false,
58725c
 	      N_("Do not permit relocations in read-only segments"),
58725c
 	      N_("Permit relocations in read-only segments (default)"));
58725c
diff -rup ../binutils-2.27/gold/output.cc gold/output.cc
58725c
--- ../binutils-2.27/gold/output.cc	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/output.cc	2016-11-03 15:05:44.000000000 +0000
58725c
@@ -4398,7 +4398,7 @@ Output_segment::set_section_addresses(co
58725c
   this->offset_ = orig_off;
58725c
 
58725c
   off_t off = 0;
58725c
-  uint64_t ret;
58725c
+  uint64_t ret = 0;
58725c
   for (int i = 0; i < static_cast<int>(ORDER_MAX); ++i)
58725c
     {
58725c
       if (i == static_cast<int>(ORDER_RELRO_LAST))
58725c
diff -rup ../binutils-2.27/gold/output.h gold/output.h
58725c
--- ../binutils-2.27/gold/output.h	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/output.h	2016-11-03 15:05:14.000000000 +0000
58725c
@@ -2499,7 +2499,7 @@ class Output_data_got : public Output_da
58725c
   // entry.
58725c
   bool
58725c
   add_local(Relobj* object, unsigned int sym_index, unsigned int got_type,
58725c
-            uint64_t addend);
58725c
+	    uint64_t addend);
58725c
 
58725c
   // Like add_local, but use the PLT offset of the local symbol if it
58725c
   // has one.
58725c
@@ -2643,7 +2643,7 @@ class Output_data_got : public Output_da
58725c
 
58725c
     // Create a local symbol entry plus addend.
58725c
     Got_entry(Relobj* object, unsigned int local_sym_index,
58725c
-        bool use_plt_or_tls_offset, uint64_t addend)
58725c
+	bool use_plt_or_tls_offset, uint64_t addend)
58725c
       : local_sym_index_(local_sym_index),
58725c
 	use_plt_or_tls_offset_(use_plt_or_tls_offset), addend_(addend)
58725c
     {
58725c
@@ -4796,6 +4796,13 @@ class Output_segment
58725c
       this->min_p_align_ = align;
58725c
   }
58725c
 
58725c
+  // Set the memory size of this segment.
58725c
+  void
58725c
+  set_size(uint64_t size)
58725c
+  {
58725c
+    this->memsz_ = size;
58725c
+  }
58725c
+
58725c
   // Set the offset of this segment based on the section.  This should
58725c
   // only be called for a non-PT_LOAD segment.
58725c
   void
58725c
diff -rup ../binutils-2.27/gold/powerpc.cc gold/powerpc.cc
58725c
--- ../binutils-2.27/gold/powerpc.cc	2016-09-26 11:22:18.717811369 +0100
58725c
+++ gold/powerpc.cc	2016-11-03 15:05:45.000000000 +0000
58725c
@@ -2439,9 +2439,8 @@ class Stub_control
58725c
   // the stubbed branches.
58725c
   Stub_control(int32_t size, bool no_size_errors)
58725c
     : state_(NO_GROUP), stub_group_size_(abs(size)),
58725c
-      stub14_group_size_(abs(size) >> 10),
58725c
       stubs_always_before_branch_(size < 0),
58725c
-      suppress_size_errors_(no_size_errors),
58725c
+      suppress_size_errors_(no_size_errors), group_size_(0),
58725c
       group_end_addr_(0), owner_(NULL), output_section_(NULL)
58725c
   {
58725c
   }
58725c
@@ -2479,24 +2478,28 @@ class Stub_control
58725c
 
58725c
   State state_;
58725c
   uint32_t stub_group_size_;
58725c
-  uint32_t stub14_group_size_;
58725c
   bool stubs_always_before_branch_;
58725c
   bool suppress_size_errors_;
58725c
+  // Current max size of group.  Starts at stub_group_size_ but is
58725c
+  // reduced to stub_group_size_/1024 on seeing a section with
58725c
+  // external conditional branches.
58725c
+  uint32_t group_size_;
58725c
   uint64_t group_end_addr_;
58725c
+  // owner_ and output_section_ specify the section to which stubs are
58725c
+  // attached.  The stubs are placed at the end of this section.
58725c
   const Output_section::Input_section* owner_;
58725c
   Output_section* output_section_;
58725c
 };
58725c
 
58725c
 // Return true iff input section can be handled by current stub
58725c
-// group.
58725c
+// group.  Sections are presented to this function in reverse order,
58725c
+// so the first section is the tail of the group.
58725c
 
58725c
 bool
58725c
 Stub_control::can_add_to_stub_group(Output_section* o,
58725c
 				    const Output_section::Input_section* i,
58725c
 				    bool has14)
58725c
 {
58725c
-  uint32_t group_size
58725c
-    = has14 ? this->stub14_group_size_ : this->stub_group_size_;
58725c
   bool whole_sec = o->order() == ORDER_INIT || o->order() == ORDER_FINI;
58725c
   uint64_t this_size;
58725c
   uint64_t start_addr = o->address();
58725c
@@ -2510,46 +2513,90 @@ Stub_control::can_add_to_stub_group(Outp
58725c
       start_addr += i->relobj()->output_section_offset(i->shndx());
58725c
       this_size = i->data_size();
58725c
     }
58725c
-  uint64_t end_addr = start_addr + this_size;
58725c
-  bool toobig = this_size > group_size;
58725c
 
58725c
-  if (toobig && !this->suppress_size_errors_)
58725c
+  uint32_t group_size = this->stub_group_size_;
58725c
+  if (has14)
58725c
+    this->group_size_ = group_size = group_size >> 10;
58725c
+
58725c
+  if (this_size > group_size && !this->suppress_size_errors_)
58725c
     gold_warning(_("%s:%s exceeds group size"),
58725c
 		 i->relobj()->name().c_str(),
58725c
 		 i->relobj()->section_name(i->shndx()).c_str());
58725c
 
58725c
-  if (this->state_ != HAS_STUB_SECTION
58725c
-      && (!whole_sec || this->output_section_ != o)
58725c
-      && (this->state_ == NO_GROUP
58725c
-	  || this->group_end_addr_ - end_addr < group_size))
58725c
-    {
58725c
-      this->owner_ = i;
58725c
-      this->output_section_ = o;
58725c
-    }
58725c
-
58725c
-  if (this->state_ == NO_GROUP)
58725c
-    {
58725c
-      this->state_ = FINDING_STUB_SECTION;
58725c
-      this->group_end_addr_ = end_addr;
58725c
-    }
58725c
-  else if (this->group_end_addr_ - start_addr < group_size)
58725c
-    ;
58725c
-  // Adding this section would make the group larger than GROUP_SIZE.
58725c
-  else if (this->state_ == FINDING_STUB_SECTION
58725c
-	   && !this->stubs_always_before_branch_
58725c
-	   && !toobig)
58725c
-    {
58725c
-      // But wait, there's more!  Input sections up to GROUP_SIZE
58725c
-      // bytes before the stub table can be handled by it too.
58725c
-      this->state_ = HAS_STUB_SECTION;
58725c
-      this->group_end_addr_ = end_addr;
58725c
+  gold_debug(DEBUG_TARGET, "maybe add%s %s:%s size=%#llx total=%#llx",
58725c
+	     has14 ? " 14bit" : "",
58725c
+	     i->relobj()->name().c_str(),
58725c
+	     i->relobj()->section_name(i->shndx()).c_str(),
58725c
+	     (long long) this_size,
58725c
+	     (long long) this->group_end_addr_ - start_addr);
58725c
+
58725c
+  uint64_t end_addr = start_addr + this_size;
58725c
+  if (this->state_ == HAS_STUB_SECTION)
58725c
+    {
58725c
+      // Can we add this section, which is before the stubs, to the
58725c
+      // group?
58725c
+      if (this->group_end_addr_ - start_addr <= this->group_size_)
58725c
+	return true;
58725c
     }
58725c
   else
58725c
     {
58725c
-      this->state_ = NO_GROUP;
58725c
-      return false;
58725c
+      // Stubs are added at the end of "owner_".
58725c
+      // The current section can always be the stub owner, except when
58725c
+      // whole_sec is true and the current section isn't the last of
58725c
+      // the pasted sections.  (This restriction for the whole_sec
58725c
+      // case is just to simplify the corner case mentioned in
58725c
+      // group_sections.)
58725c
+      // Note that "owner_" itself is not necessarily part of the
58725c
+      // group of sections served by these stubs!
58725c
+      if (!whole_sec || this->output_section_ != o)
58725c
+	{
58725c
+	  this->owner_ = i;
58725c
+	  this->output_section_ = o;
58725c
+	}
58725c
+
58725c
+      if (this->state_ == FINDING_STUB_SECTION)
58725c
+	{
58725c
+	  if (this->group_end_addr_ - start_addr <= this->group_size_)
58725c
+	    return true;
58725c
+	  // The group after the stubs has reached maximum size.
58725c
+	  // Now see about adding sections before the stubs to the
58725c
+	  // group.  If the current section has a 14-bit branch and
58725c
+	  // the group after the stubs exceeds group_size_ (because
58725c
+	  // they didn't have 14-bit branches), don't add sections
58725c
+	  // before the stubs:  The size of stubs for such a large
58725c
+	  // group may exceed the reach of a 14-bit branch.
58725c
+	  if (!this->stubs_always_before_branch_
58725c
+	      && this_size <= this->group_size_
58725c
+	      && this->group_end_addr_ - end_addr <= this->group_size_)
58725c
+	    {
58725c
+	      gold_debug(DEBUG_TARGET, "adding before stubs");
58725c
+	      this->state_ = HAS_STUB_SECTION;
58725c
+	      this->group_end_addr_ = end_addr;
58725c
+	      return true;
58725c
+	    }
58725c
+	}
58725c
+      else if (this->state_ == NO_GROUP)
58725c
+	{
58725c
+	  // Only here on very first use of Stub_control
58725c
+	  this->state_ = FINDING_STUB_SECTION;
58725c
+	  this->group_size_ = group_size;
58725c
+	  this->group_end_addr_ = end_addr;
58725c
+	  return true;
58725c
+	}
58725c
+      else
58725c
+	gold_unreachable();
58725c
     }
58725c
-  return true;
58725c
+
58725c
+  gold_debug(DEBUG_TARGET, "nope, didn't fit\n");
58725c
+
58725c
+  // The section fails to fit in the current group.  Set up a few
58725c
+  // things for the next group.  owner_ and output_section_ will be
58725c
+  // set later after we've retrieved those values for the current
58725c
+  // group.
58725c
+  this->state_ = FINDING_STUB_SECTION;
58725c
+  this->group_size_ = group_size;
58725c
+  this->group_end_addr_ = end_addr;
58725c
+  return false;
58725c
 }
58725c
 
58725c
 // Look over all the input sections, deciding where to place stubs.
58725c
@@ -2887,7 +2934,7 @@ Target_powerpc<size, big_endian>::do_rel
58725c
 	}
58725c
       this->stub_tables_.clear();
58725c
       this->stub_group_size_ = this->stub_group_size_ / 4 * 3;
58725c
-      gold_info(_("%s: stub group size is too large; retrying with %d"),
58725c
+      gold_info(_("%s: stub group size is too large; retrying with %#x"),
58725c
 		program_name, this->stub_group_size_);
58725c
       this->group_sections(layout, task, true);
58725c
     }
58725c
@@ -2982,7 +3029,13 @@ Target_powerpc<size, big_endian>::do_rel
58725c
 	      Stub_table<size, big_endian>* stub_table
58725c
 		= static_cast<Stub_table<size, big_endian>*>(
58725c
 		    i->relaxed_input_section());
58725c
-	      off += stub_table->set_address_and_size(os, off);
58725c
+	      Address stub_table_size = stub_table->set_address_and_size(os, off);
58725c
+	      off += stub_table_size;
58725c
+	      // After a few iterations, set current stub table size
58725c
+	      // as min size threshold, so later stub tables can only
58725c
+	      // grow in size.
58725c
+	      if (pass >= 4)
58725c
+		stub_table->set_min_size_threshold(stub_table_size);
58725c
 	    }
58725c
 	  else
58725c
 	    off += i->data_size();
58725c
@@ -3634,8 +3687,8 @@ class Stub_table : public Output_relaxed
58725c
       targ_(targ), plt_call_stubs_(), long_branch_stubs_(),
58725c
       orig_data_size_(owner->current_data_size()),
58725c
       plt_size_(0), last_plt_size_(0),
58725c
-      branch_size_(0), last_branch_size_(0), eh_frame_added_(false),
58725c
-      need_save_res_(false)
58725c
+      branch_size_(0), last_branch_size_(0), min_size_threshold_(0),
58725c
+      eh_frame_added_(false), need_save_res_(false)
58725c
   {
58725c
     this->set_output_section(output_section);
58725c
 
58725c
@@ -3726,6 +3779,11 @@ class Stub_table : public Output_relaxed
58725c
       off = align_address(off, this->stub_align());
58725c
     // Include original section size and alignment padding in size
58725c
     my_size += off - start_off;
58725c
+    // Ensure new size is always larger than min size
58725c
+    // threshold. Alignment requirement is included in "my_size", so
58725c
+    // increase "my_size" does not invalidate alignment.
58725c
+    if (my_size < this->min_size_threshold_)
58725c
+      my_size = this->min_size_threshold_;
58725c
     this->reset_address_and_file_offset();
58725c
     this->set_current_data_size(my_size);
58725c
     this->set_address_and_file_offset(os->address() + start_off,
58725c
@@ -3751,6 +3809,9 @@ class Stub_table : public Output_relaxed
58725c
   plt_size() const
58725c
   { return this->plt_size_; }
58725c
 
58725c
+  void set_min_size_threshold(Address min_size)
58725c
+  { this->min_size_threshold_ = min_size; }
58725c
+
58725c
   bool
58725c
   size_update()
58725c
   {
58725c
@@ -4015,6 +4076,13 @@ class Stub_table : public Output_relaxed
58725c
   section_size_type orig_data_size_;
58725c
   // size of stubs
58725c
   section_size_type plt_size_, last_plt_size_, branch_size_, last_branch_size_;
58725c
+  // Some rare cases cause (PR/20529) fluctuation in stub table
58725c
+  // size, which leads to an endless relax loop. This is to be fixed
58725c
+  // by, after the first few iterations, allowing only increase of
58725c
+  // stub table size. This variable sets the minimal possible size of
58725c
+  // a stub table, it is zero for the first few iterations, then
58725c
+  // increases monotonically.
58725c
+  Address min_size_threshold_;
58725c
   // Whether .eh_frame info has been created for this stub section.
58725c
   bool eh_frame_added_;
58725c
   // Set if this stub group needs a copy of out-of-line register
58725c
@@ -6024,7 +6092,7 @@ Target_powerpc<size, big_endian>::Scan::
58725c
 	  ppc_object->set_opd_discard(reloc.get_r_offset());
58725c
 	  break;
58725c
 	}
58725c
-      // Fall thru
58725c
+      // Fall through.
58725c
     case elfcpp::R_PPC64_UADDR64:
58725c
     case elfcpp::R_POWERPC_ADDR32:
58725c
     case elfcpp::R_POWERPC_UADDR32:
58725c
@@ -6131,7 +6199,7 @@ Target_powerpc<size, big_endian>::Scan::
58725c
 		      || gsym->is_preemptible())))
58725c
 	    target->make_plt_entry(symtab, layout, gsym);
58725c
 	}
58725c
-      // Fall thru
58725c
+      // Fall through.
58725c
 
58725c
     case elfcpp::R_PPC64_REL64:
58725c
     case elfcpp::R_POWERPC_REL32:
58725c
@@ -7521,6 +7589,7 @@ Target_powerpc<size, big_endian>::Reloca
58725c
       if (size != 64)
58725c
 	// R_PPC_TLSGD, R_PPC_TLSLD, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HI
58725c
 	break;
58725c
+      // Fall through.
58725c
     case elfcpp::R_POWERPC_TPREL16:
58725c
     case elfcpp::R_POWERPC_TPREL16_LO:
58725c
     case elfcpp::R_POWERPC_TPREL16_HI:
58725c
@@ -7544,6 +7613,7 @@ Target_powerpc<size, big_endian>::Reloca
58725c
 	// R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16, R_PPC_EMB_NADDR16_LO
58725c
 	// R_PPC_EMB_NADDR16_HI, R_PPC_EMB_NADDR16_HA, R_PPC_EMB_SDAI16
58725c
 	break;
58725c
+      // Fall through.
58725c
     case elfcpp::R_POWERPC_DTPREL16:
58725c
     case elfcpp::R_POWERPC_DTPREL16_LO:
58725c
     case elfcpp::R_POWERPC_DTPREL16_HI:
58725c
@@ -7572,6 +7642,7 @@ Target_powerpc<size, big_endian>::Reloca
58725c
     case elfcpp::R_POWERPC_ADDR14_BRTAKEN:
58725c
     case elfcpp::R_POWERPC_REL14_BRTAKEN:
58725c
       branch_bit = 1 << 21;
58725c
+      // Fall through.
58725c
     case elfcpp::R_POWERPC_ADDR14_BRNTAKEN:
58725c
     case elfcpp::R_POWERPC_REL14_BRNTAKEN:
58725c
       {
58725c
@@ -7936,6 +8007,7 @@ Target_powerpc<size, big_endian>::Reloca
58725c
 	  maybe_dq_reloc = true;
58725c
 	  break;
58725c
 	}
58725c
+      // Fall through.
58725c
     case elfcpp::R_POWERPC_ADDR16:
58725c
     case elfcpp::R_POWERPC_REL16:
58725c
     case elfcpp::R_PPC64_TOC16:
58725c
@@ -7970,6 +8042,7 @@ Target_powerpc<size, big_endian>::Reloca
58725c
       if (size == 32)
58725c
 	// R_PPC_EMB_MRKREF, R_PPC_EMB_RELST_LO, R_PPC_EMB_RELST_HA
58725c
 	goto unsupp;
58725c
+      // Fall through.
58725c
     case elfcpp::R_POWERPC_ADDR16_HI:
58725c
     case elfcpp::R_POWERPC_REL16_HI:
58725c
     case elfcpp::R_PPC64_TOC16_HI:
58725c
@@ -7990,6 +8063,7 @@ Target_powerpc<size, big_endian>::Reloca
58725c
       if (size == 32)
58725c
 	// R_PPC_EMB_RELSEC16, R_PPC_EMB_RELST_HI, R_PPC_EMB_BIT_FLD
58725c
 	goto unsupp;
58725c
+      // Fall through.
58725c
     case elfcpp::R_POWERPC_ADDR16_HA:
58725c
     case elfcpp::R_POWERPC_REL16_HA:
58725c
     case elfcpp::R_PPC64_TOC16_HA:
58725c
@@ -8012,6 +8086,7 @@ Target_powerpc<size, big_endian>::Reloca
58725c
       if (size == 32)
58725c
 	// R_PPC_EMB_NADDR16_LO
58725c
 	goto unsupp;
58725c
+      // Fall through.
58725c
     case elfcpp::R_PPC64_ADDR16_HIGHER:
58725c
     case elfcpp::R_PPC64_TPREL16_HIGHER:
58725c
       Reloc::addr16_hi2(view, value);
58725c
@@ -8021,6 +8096,7 @@ Target_powerpc<size, big_endian>::Reloca
58725c
       if (size == 32)
58725c
 	// R_PPC_EMB_NADDR16_HI
58725c
 	goto unsupp;
58725c
+      // Fall through.
58725c
     case elfcpp::R_PPC64_ADDR16_HIGHERA:
58725c
     case elfcpp::R_PPC64_TPREL16_HIGHERA:
58725c
       Reloc::addr16_ha2(view, value);
58725c
@@ -8030,6 +8106,7 @@ Target_powerpc<size, big_endian>::Reloca
58725c
       if (size == 32)
58725c
 	// R_PPC_EMB_NADDR16_HA
58725c
 	goto unsupp;
58725c
+      // Fall through.
58725c
     case elfcpp::R_PPC64_ADDR16_HIGHEST:
58725c
     case elfcpp::R_PPC64_TPREL16_HIGHEST:
58725c
       Reloc::addr16_hi3(view, value);
58725c
@@ -8039,6 +8116,7 @@ Target_powerpc<size, big_endian>::Reloca
58725c
       if (size == 32)
58725c
 	// R_PPC_EMB_SDAI16
58725c
 	goto unsupp;
58725c
+      // Fall through.
58725c
     case elfcpp::R_PPC64_ADDR16_HIGHESTA:
58725c
     case elfcpp::R_PPC64_TPREL16_HIGHESTA:
58725c
       Reloc::addr16_ha3(view, value);
58725c
@@ -8049,11 +8127,13 @@ Target_powerpc<size, big_endian>::Reloca
58725c
       if (size == 32)
58725c
 	// R_PPC_EMB_NADDR32, R_PPC_EMB_NADDR16
58725c
 	goto unsupp;
58725c
+      // Fall through.
58725c
     case elfcpp::R_PPC64_TPREL16_DS:
58725c
     case elfcpp::R_PPC64_TPREL16_LO_DS:
58725c
       if (size == 32)
58725c
 	// R_PPC_TLSGD, R_PPC_TLSLD
58725c
 	break;
58725c
+      // Fall through.
58725c
     case elfcpp::R_PPC64_ADDR16_DS:
58725c
     case elfcpp::R_PPC64_ADDR16_LO_DS:
58725c
     case elfcpp::R_PPC64_TOC16_DS:
58725c
diff -rup ../binutils-2.27/gold/resolve.cc gold/resolve.cc
58725c
--- ../binutils-2.27/gold/resolve.cc	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/resolve.cc	2016-11-03 15:05:47.000000000 +0000
58725c
@@ -193,6 +193,7 @@ symbol_to_bits(elfcpp::STB binding, bool
58725c
       // table.
58725c
       gold_error(_("invalid STB_LOCAL symbol in external symbols"));
58725c
       bits = global_flag;
58725c
+      break;
58725c
 
58725c
     default:
58725c
       // Any target which wants to handle STB_LOOS, etc., needs to
58725c
diff -rup ../binutils-2.27/gold/script.cc gold/script.cc
58725c
--- ../binutils-2.27/gold/script.cc	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/script.cc	2016-11-03 15:05:47.000000000 +0000
58725c
@@ -1755,6 +1755,7 @@ script_keyword_parsecodes[] =
58725c
   { "FLOAT", FLOAT },
58725c
   { "FORCE_COMMON_ALLOCATION", FORCE_COMMON_ALLOCATION },
58725c
   { "GROUP", GROUP },
58725c
+  { "HIDDEN", HIDDEN },
58725c
   { "HLL", HLL },
58725c
   { "INCLUDE", INCLUDE },
58725c
   { "INFO", INFO },
58725c
diff -rup ../binutils-2.27/gold/script-sections.cc gold/script-sections.cc
58725c
--- ../binutils-2.27/gold/script-sections.cc	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/script-sections.cc	2016-11-03 15:05:48.000000000 +0000
58725c
@@ -1503,7 +1503,7 @@ class Input_section_info
58725c
  private:
58725c
   // Input section, can be a relaxed section.
58725c
   Output_section::Input_section input_section_;
58725c
-  // Name of the section. 
58725c
+  // Name of the section.
58725c
   std::string section_name_;
58725c
   // Section size.
58725c
   uint64_t size_;
58725c
@@ -1545,7 +1545,7 @@ Input_section_sorter::get_init_priority(
58725c
   // GCC uses the following section names for the init_priority
58725c
   // attribute with numerical values 101 and 65535 inclusive. A
58725c
   // lower value means a higher priority.
58725c
-  // 
58725c
+  //
58725c
   // 1: .init_array.NNNN/.fini_array.NNNN: Where NNNN is the
58725c
   //    decimal numerical value of the init_priority attribute.
58725c
   //    The order of execution in .init_array is forward and
58725c
@@ -1666,7 +1666,7 @@ Output_section_element_input::set_sectio
58725c
   while (p != input_sections->end())
58725c
     {
58725c
       Relobj* relobj = p->relobj();
58725c
-      unsigned int shndx = p->shndx();      
58725c
+      unsigned int shndx = p->shndx();
58725c
       Input_section_info isi(*p);
58725c
 
58725c
       // Calling section_name and section_addralign is not very
58725c
@@ -1758,7 +1758,7 @@ Output_section_element_input::set_sectio
58725c
 
58725c
 	  uint64_t this_subalign = sis.addralign();
58725c
 	  if (!sis.is_input_section())
58725c
-	    sis.output_section_data()->finalize_data_size();	
58725c
+	    sis.output_section_data()->finalize_data_size();
58725c
 	  uint64_t data_size = sis.data_size();
58725c
 	  if (this_subalign < subalign)
58725c
 	    {
58725c
@@ -2029,7 +2029,7 @@ class Output_section_definition : public
58725c
   void
58725c
   set_section_vma(Expression* address)
58725c
   { this->address_ = address; }
58725c
-  
58725c
+
58725c
   void
58725c
   set_section_lma(Expression* address)
58725c
   { this->load_address_ = address; }
58725c
@@ -2037,7 +2037,7 @@ class Output_section_definition : public
58725c
   const std::string&
58725c
   get_section_name() const
58725c
   { return this->name_; }
58725c
-  
58725c
+
58725c
  private:
58725c
   static const char*
58725c
   script_section_type_name(Script_section_type);
58725c
@@ -2402,9 +2402,9 @@ Output_section_definition::set_section_a
58725c
   uint64_t old_load_address = *load_address;
58725c
 
58725c
   // If input section sorting is requested via --section-ordering-file or
58725c
-  // linker plugins, then do it here.  This is important because we want 
58725c
+  // linker plugins, then do it here.  This is important because we want
58725c
   // any sorting specified in the linker scripts, which will be done after
58725c
-  // this, to take precedence.  The final order of input sections is then 
58725c
+  // this, to take precedence.  The final order of input sections is then
58725c
   // guaranteed to be according to the linker script specification.
58725c
   if (this->output_section_ != NULL
58725c
       && this->output_section_->input_section_order_specified())
58725c
@@ -2495,7 +2495,7 @@ Output_section_definition::set_section_a
58725c
 	    // The LMA address was explicitly set to the given region.
58725c
 	    laddr = lma_region->get_current_address()->eval(symtab, layout,
58725c
 							    false);
58725c
-	  else 
58725c
+	  else
58725c
 	    {
58725c
 	      // We are not going to use the discovered lma_region, so
58725c
 	      // make sure that we do not update it in the code below.
58725c
@@ -2987,9 +2987,9 @@ Orphan_output_section::set_section_addre
58725c
   address = align_address(address, this->os_->addralign());
58725c
 
58725c
   // If input section sorting is requested via --section-ordering-file or
58725c
-  // linker plugins, then do it here.  This is important because we want 
58725c
+  // linker plugins, then do it here.  This is important because we want
58725c
   // any sorting specified in the linker scripts, which will be done after
58725c
-  // this, to take precedence.  The final order of input sections is then 
58725c
+  // this, to take precedence.  The final order of input sections is then
58725c
   // guaranteed to be according to the linker script specification.
58725c
   if (this->os_ != NULL
58725c
       && this->os_->input_section_order_specified())
58725c
@@ -3023,7 +3023,7 @@ Orphan_output_section::set_section_addre
58725c
     {
58725c
       uint64_t addralign = p->addralign();
58725c
       if (!p->is_input_section())
58725c
-	p->output_section_data()->finalize_data_size();	
58725c
+	p->output_section_data()->finalize_data_size();
58725c
       uint64_t size = p->data_size();
58725c
       address = align_address(address, addralign);
58725c
       this->os_->add_script_input_section(*p);
58725c
@@ -3605,7 +3605,7 @@ Output_segment*
58725c
 Script_sections::set_section_addresses(Symbol_table* symtab, Layout* layout)
58725c
 {
58725c
   gold_assert(this->saw_sections_clause_);
58725c
-	 
58725c
+
58725c
   // Implement ONLY_IF_RO/ONLY_IF_RW constraints.  These are a pain
58725c
   // for our representation.
58725c
   for (Sections_elements::iterator p = this->sections_elements_->begin();
58725c
@@ -3674,7 +3674,7 @@ Script_sections::set_section_addresses(S
58725c
       Output_section* os = (*p)->get_output_section();
58725c
 
58725c
       // Handle -Ttext, -Tdata and -Tbss options.  We do this by looking for
58725c
-      // the special sections by names and doing dot assignments. 
58725c
+      // the special sections by names and doing dot assignments.
58725c
       if (use_tsection_options
58725c
 	  && os != NULL
58725c
 	  && (os->flags() & elfcpp::SHF_ALLOC) != 0)
58725c
@@ -3703,7 +3703,7 @@ Script_sections::set_section_addresses(S
58725c
 
58725c
       (*p)->set_section_addresses(symtab, layout, &dot_value, &dot_alignment,
58725c
 				  &load_address);
58725c
-    } 
58725c
+    }
58725c
 
58725c
   if (this->phdrs_elements_ != NULL)
58725c
     {
58725c
@@ -3890,7 +3890,7 @@ Script_sections::create_segments(Layout*
58725c
   layout->get_allocated_sections(&sections);
58725c
 
58725c
   // Sort the sections by address.
58725c
-  std::stable_sort(sections.begin(), sections.end(), 
58725c
+  std::stable_sort(sections.begin(), sections.end(),
58725c
 		   Sort_output_sections(this->sections_elements_));
58725c
 
58725c
   this->create_note_and_tls_segments(layout, &sections);
58725c
@@ -4217,7 +4217,7 @@ Script_sections::attach_sections_using_p
58725c
   // Output sections in the script which do not list segments are
58725c
   // attached to the same set of segments as the immediately preceding
58725c
   // output section.
58725c
-  
58725c
+
58725c
   String_list* phdr_names = NULL;
58725c
   bool load_segments_only = false;
58725c
   for (Sections_elements::const_iterator p = this->sections_elements_->begin();
58725c
@@ -4262,7 +4262,7 @@ Script_sections::attach_sections_using_p
58725c
       // filtering.
58725c
       if (old_phdr_names != phdr_names)
58725c
 	load_segments_only = false;
58725c
-		
58725c
+
58725c
       // If this is an orphan section--one that was not explicitly
58725c
       // mentioned in the linker script--then it should not inherit
58725c
       // any segment type other than PT_LOAD.  Otherwise, e.g., the
58725c
@@ -4459,6 +4459,7 @@ Script_sections::release_segments()
58725c
 	   ++p)
58725c
 	(*p)->release_segment();
58725c
     }
58725c
+  this->segments_created_ = false;
58725c
 }
58725c
 
58725c
 // Print the SECTIONS clause to F for debugging.
58725c
diff -rup ../binutils-2.27/gold/sparc.cc gold/sparc.cc
58725c
--- ../binutils-2.27/gold/sparc.cc	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/sparc.cc	2016-11-03 15:05:48.000000000 +0000
58725c
@@ -2150,6 +2150,7 @@ Target_sparc<size, big_endian>::Scan::ch
58725c
 	case elfcpp::R_SPARC_RELATIVE:
58725c
 	case elfcpp::R_SPARC_IRELATIVE:
58725c
 	case elfcpp::R_SPARC_COPY:
58725c
+	case elfcpp::R_SPARC_32:
58725c
 	case elfcpp::R_SPARC_64:
58725c
 	case elfcpp::R_SPARC_GLOB_DAT:
58725c
 	case elfcpp::R_SPARC_JMP_SLOT:
58725c
@@ -2304,7 +2305,7 @@ Target_sparc<size, big_endian>::Scan::lo
58725c
 				       reloc.get_r_addend(), is_ifunc);
58725c
 	  break;
58725c
 	}
58725c
-      /* Fall through.  */
58725c
+      // Fall through.
58725c
 
58725c
     case elfcpp::R_SPARC_HIX22:
58725c
     case elfcpp::R_SPARC_LOX10:
58725c
@@ -2814,6 +2815,7 @@ Target_sparc<size, big_endian>::Scan::gl
58725c
 	  // and code transform the GOT load into an addition.
58725c
 	  break;
58725c
 	}
58725c
+      // Fall through.
58725c
     case elfcpp::R_SPARC_GOT10:
58725c
     case elfcpp::R_SPARC_GOT13:
58725c
     case elfcpp::R_SPARC_GOT22:
58725c
@@ -3353,6 +3355,7 @@ Target_sparc<size, big_endian>::Relocate
58725c
 	  gdop_valid = true;
58725c
 	  break;
58725c
 	}
58725c
+      // Fall through.
58725c
     case elfcpp::R_SPARC_GOT10:
58725c
     case elfcpp::R_SPARC_GOT13:
58725c
     case elfcpp::R_SPARC_GOT22:
58725c
@@ -3468,6 +3471,13 @@ Target_sparc<size, big_endian>::Relocate
58725c
       Reloc::lo10(view, object, psymval, addend);
58725c
       break;
58725c
 
58725c
+    case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
58725c
+      if (gdop_valid)
58725c
+	{
58725c
+	  Reloc::gdop_lox10(view, got_offset);
58725c
+	  break;
58725c
+	}
58725c
+      // Fall through.
58725c
     case elfcpp::R_SPARC_GOT10:
58725c
       Reloc::lo10(view, got_offset, addend);
58725c
       break;
58725c
@@ -3486,13 +3496,6 @@ Target_sparc<size, big_endian>::Relocate
58725c
 	}
58725c
       break;
58725c
 
58725c
-    case elfcpp::R_SPARC_GOTDATA_OP_LOX10:
58725c
-      if (gdop_valid)
58725c
-	{
58725c
-	  Reloc::gdop_lox10(view, got_offset);
58725c
-	  break;
58725c
-	}
58725c
-      /* Fall through.  */
58725c
     case elfcpp::R_SPARC_GOT13:
58725c
       Reloc::rela32_13(view, got_offset, addend);
58725c
       break;
58725c
@@ -3503,7 +3506,7 @@ Target_sparc<size, big_endian>::Relocate
58725c
 	  Reloc::gdop_hix22(view, got_offset);
58725c
 	  break;
58725c
 	}
58725c
-      /* Fall through.  */
58725c
+      // Fall through.
58725c
     case elfcpp::R_SPARC_GOT22:
58725c
       Reloc::hi22(view, got_offset, addend);
58725c
       break;
58725c
diff -rup ../binutils-2.27/gold/symtab.cc gold/symtab.cc
58725c
--- ../binutils-2.27/gold/symtab.cc	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/symtab.cc	2016-11-03 15:05:49.000000000 +0000
58725c
@@ -882,6 +882,7 @@ Symbol_table::define_default_version(Siz
58725c
 	;
58725c
       else if (pdef->second->is_from_dynobj()
58725c
 	       && sym->is_from_dynobj()
58725c
+	       && pdef->second->is_defined()
58725c
 	       && pdef->second->object() != sym->object())
58725c
         ;
58725c
       else
58725c
@@ -1325,6 +1326,9 @@ Symbol_table::add_from_relobj(
58725c
       res = this->add_from_object(relobj, name, name_key, ver, ver_key,
58725c
 				  is_default_version, *psym, st_shndx,
58725c
 				  is_ordinary, orig_st_shndx);
58725c
+
58725c
+      if (res == NULL)
58725c
+	continue;
58725c
       
58725c
       if (is_forced_local)
58725c
 	this->force_local(res);
58725c
@@ -1406,6 +1410,9 @@ Symbol_table::add_from_pluginobj(
58725c
 		              is_default_version, *sym, st_shndx,
58725c
 			      is_ordinary, st_shndx);
58725c
 
58725c
+  if (res == NULL)
58725c
+    return NULL;
58725c
+
58725c
   if (is_forced_local)
58725c
     this->force_local(res);
58725c
 
58725c
@@ -1602,6 +1609,9 @@ Symbol_table::add_from_dynobj(
58725c
 	    }
58725c
 	}
58725c
 
58725c
+      if (res == NULL)
58725c
+	continue;
58725c
+
58725c
       // Note that it is possible that RES was overridden by an
58725c
       // earlier object, in which case it can't be aliased here.
58725c
       if (st_shndx != elfcpp::SHN_UNDEF
58725c
@@ -1640,7 +1650,6 @@ Symbol_table::add_from_incrobj(
58725c
 
58725c
   Stringpool::Key ver_key = 0;
58725c
   bool is_default_version = false;
58725c
-  bool is_forced_local = false;
58725c
 
58725c
   Stringpool::Key name_key;
58725c
   name = this->namepool_.add(name, true, &name_key);
58725c
@@ -1650,9 +1659,6 @@ Symbol_table::add_from_incrobj(
58725c
 		              is_default_version, *sym, st_shndx,
58725c
 			      is_ordinary, st_shndx);
58725c
 
58725c
-  if (is_forced_local)
58725c
-    this->force_local(res);
58725c
-
58725c
   return res;
58725c
 }
58725c
 
58725c
diff -rup ../binutils-2.27/gold/tilegx.cc gold/tilegx.cc
58725c
--- ../binutils-2.27/gold/tilegx.cc	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/tilegx.cc	2016-11-03 15:05:50.000000000 +0000
58725c
@@ -4428,6 +4428,7 @@ Target_tilegx<size, big_endian>::Relocat
58725c
       psymval = &symval;
58725c
       always_apply_relocation = true;
58725c
       addend = 0;
58725c
+      // Fall through.
58725c
 
58725c
     // when under PIC mode, these relocations are deferred to rtld
58725c
     case elfcpp::R_TILEGX_IMM16_X0_HW0:
58725c
@@ -4618,6 +4619,7 @@ Target_tilegx<size, big_endian>::Relocat
58725c
                 got_type = GOT_TYPE_TLS_OFFSET;
58725c
                 have_got_offset = true;
58725c
               }
58725c
+	      // Fall through.
58725c
             do_update_value:
58725c
               if (have_got_offset) {
58725c
                 if (gsym != NULL) {
58725c
@@ -4647,10 +4649,8 @@ Target_tilegx<size, big_endian>::Relocat
58725c
               } // else if (opt_t == tls::TLSOPT_TO_LE)
58725c
                 //   both GD/IE are turned into LE, which
58725c
                 //   is absolute relocation.
58725c
-                //
58725c
-                //  |  go through
58725c
-                //  |
58725c
-                //  V
58725c
+                // Fall through.
58725c
+
58725c
             // LE
58725c
             //
58725c
             // tp
58725c
diff -rup ../binutils-2.27/gold/x86_64.cc gold/x86_64.cc
58725c
--- ../binutils-2.27/gold/x86_64.cc	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/x86_64.cc	2016-11-03 15:05:52.000000000 +0000
58725c
@@ -2361,7 +2361,7 @@ Target_x86_64<size>::Scan::check_non_pic
58725c
 	      && !gsym->is_undefined()
58725c
 	      && !gsym->is_preemptible()))
58725c
 	return;
58725c
-      /* Fall through.  */
58725c
+      // Fall through.
58725c
     case elfcpp::R_X86_64_32:
58725c
       // R_X86_64_32 is OK for x32.
58725c
       if (size == 32 && r_type == elfcpp::R_X86_64_32)
58725c
@@ -3505,6 +3505,7 @@ Target_x86_64<size>::Relocate::relocate(
58725c
   if (this->skip_call_tls_get_addr_)
58725c
     {
58725c
       if ((r_type != elfcpp::R_X86_64_PLT32
58725c
+	   && r_type != elfcpp::R_X86_64_GOTPCREL
58725c
 	   && r_type != elfcpp::R_X86_64_GOTPCRELX
58725c
 	   && r_type != elfcpp::R_X86_64_PLT32_BND
58725c
 	   && r_type != elfcpp::R_X86_64_PC32_BND
58725c
@@ -3514,6 +3515,7 @@ Target_x86_64<size>::Relocate::relocate(
58725c
 	{
58725c
 	  gold_error_at_location(relinfo, relnum, rela.get_r_offset(),
58725c
 				 _("missing expected TLS relocation"));
58725c
+	  this->skip_call_tls_get_addr_ = false;
58725c
 	}
58725c
       else
58725c
 	{
58725c
diff -rup ../binutils-2.27/gold/yyscript.y gold/yyscript.y
58725c
--- ../binutils-2.27/gold/yyscript.y	2016-08-03 08:36:53.000000000 +0100
58725c
+++ gold/yyscript.y	2016-11-03 15:05:59.000000000 +0000
58725c
@@ -137,6 +137,7 @@
58725c
 %token FORCE_COMMON_ALLOCATION
58725c
 %token GLOBAL		/* global */
58725c
 %token GROUP
58725c
+%token HIDDEN
58725c
 %token HLL
58725c
 %token INCLUDE
58725c
 %token INHIBIT_COMMON_ALLOCATION
58725c
@@ -864,6 +865,8 @@ assignment:
58725c
 	      Expression_ptr e = script_exp_binary_bitwise_or(s, $3);
58725c
 	      script_set_symbol(closure, $1.value, $1.length, e, 0, 0);
58725c
 	    }
58725c
+	| HIDDEN '(' string '=' parse_exp ')'
58725c
+	    { script_set_symbol(closure, $3.value, $3.length, $5, 0, 1); }
58725c
 	| PROVIDE '(' string '=' parse_exp ')'
58725c
 	    { script_set_symbol(closure, $3.value, $3.length, $5, 1, 0); }
58725c
 	| PROVIDE_HIDDEN '(' string '=' parse_exp ')'
58725c
diff -rup binutils.orig/gold/testsuite/pr18689.sh binutils-2.27/gold/testsuite/pr18689.sh
58725c
--- binutils.orig/gold/testsuite/pr18689.sh	2017-01-17 10:17:46.062813402 +0000
58725c
+++ gold/testsuite/pr18689.sh	2017-01-17 10:30:51.583556117 +0000
58725c
@@ -23,6 +23,6 @@
58725c
 
58725c
 set -e
58725c
 
58725c
-egrep -q "..debug_mac[ro|info][ ]+*" pr18689.stdout
58725c
+egrep -q "..debug_str[ ]+*" pr18689.stdout
58725c
 
58725c
 exit 0