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