This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[GOLD] powerpc tls and got fixes


Fixes errors found in TLS handling by gcc's libgomp testsuite, and
various other problems.

	* powerpc.cc (Target_powerpc::Scan::local, global): Always emit
	dynamic relocs for GOT_TPREL got entries, without symbol if
	resolving locally.
	(Target_powerpc::do_gc_add_reference): Don't add for dynamic objects.
	(Target_powerpc::scan_relocs): Define _GLOBAL_OFFSET_TABLE_ early.
	(Target_powerpc::Relocate:relocate): REL32 reloc may be unaligned.

Index: gold/powerpc.cc
===================================================================
RCS file: /cvs/src/src/gold/powerpc.cc,v
retrieving revision 1.64
diff -u -p -r1.64 powerpc.cc
--- gold/powerpc.cc	16 Oct 2012 00:23:00 -0000	1.64
+++ gold/powerpc.cc	17 Oct 2012 11:59:14 -0000
@@ -3411,10 +3432,19 @@ Target_powerpc<size, big_endian>::Scan::
 	const tls::Tls_optimization tls_type = target->optimize_tls_ie(true);
 	if (tls_type == tls::TLSOPT_NONE)
 	  {
-	    Output_data_got_powerpc<size, big_endian>* got
-	      = target->got_section(symtab, layout);
 	    unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
-	    got->add_local_tls(object, r_sym, GOT_TYPE_TPREL);
+	    if (!object->local_has_got_offset(r_sym, GOT_TYPE_TPREL))
+	      {
+		Output_data_got_powerpc<size, big_endian>* got
+		  = target->got_section(symtab, layout);
+		unsigned int off = got->add_constant(0);
+		object->set_local_got_offset(r_sym, GOT_TYPE_TPREL, off);
+
+		Reloc_section* rela_dyn = target->rela_dyn_section(layout);
+		rela_dyn->add_symbolless_local_addend(object, r_sym,
+						      elfcpp::R_POWERPC_TPREL,
+						      got, off, 0);
+	      }
 	  }
 	else if (tls_type == tls::TLSOPT_TO_LE)
 	  {
@@ -3729,11 +3759,26 @@ Target_powerpc<size, big_endian>::Scan::
 	  }
 	else if (tls_type == tls::TLSOPT_TO_IE)
 	  {
-	    Output_data_got_powerpc<size, big_endian>* got
-	      = target->got_section(symtab, layout);
-	    got->add_global_with_rel(gsym, GOT_TYPE_TPREL,
-				     target->rela_dyn_section(layout),
-				     elfcpp::R_POWERPC_TPREL);
+	    if (!gsym->has_got_offset(GOT_TYPE_TPREL))
+	      {
+		Output_data_got_powerpc<size, big_endian>* got
+		  = target->got_section(symtab, layout);
+		Reloc_section* rela_dyn = target->rela_dyn_section(layout);
+		if (gsym->is_undefined()
+		    || gsym->is_from_dynobj())
+		  {
+		    got->add_global_with_rel(gsym, GOT_TYPE_TPREL, rela_dyn,
+					     elfcpp::R_POWERPC_TPREL);
+		  }
+		else
+		  {
+		    unsigned int off = got->add_constant(0);
+		    gsym->set_got_offset(GOT_TYPE_TPREL, off);
+		    unsigned int dynrel = elfcpp::R_POWERPC_TPREL;
+		    rela_dyn->add_symbolless_global_addend(gsym, dynrel,
+							   got, off, 0);
+		  }
+	      }
 	  }
 	else if (tls_type == tls::TLSOPT_TO_LE)
 	  {
@@ -3795,17 +3840,26 @@ Target_powerpc<size, big_endian>::Scan::
 	const tls::Tls_optimization tls_type = target->optimize_tls_ie(final);
 	if (tls_type == tls::TLSOPT_NONE)
 	  {
-	    Output_data_got_powerpc<size, big_endian>* got
-	      = target->got_section(symtab, layout);
-	    if (!gsym->final_value_is_known()
-		&& (gsym->is_from_dynobj()
-		    || gsym->is_undefined()
-		    || gsym->is_preemptible()))
-	      got->add_global_with_rel(gsym, GOT_TYPE_TPREL,
-				       target->rela_dyn_section(layout),
-				       elfcpp::R_POWERPC_TPREL);
-	    else
-	      got->add_global_tls(gsym, GOT_TYPE_TPREL);
+	    if (!gsym->has_got_offset(GOT_TYPE_TPREL))
+	      {
+		Output_data_got_powerpc<size, big_endian>* got
+		  = target->got_section(symtab, layout);
+		Reloc_section* rela_dyn = target->rela_dyn_section(layout);
+		if (gsym->is_undefined()
+		    || gsym->is_from_dynobj())
+		  {
+		    got->add_global_with_rel(gsym, GOT_TYPE_TPREL, rela_dyn,
+					     elfcpp::R_POWERPC_TPREL);
+		  }
+		else
+		  {
+		    unsigned int off = got->add_constant(0);
+		    gsym->set_got_offset(GOT_TYPE_TPREL, off);
+		    unsigned int dynrel = elfcpp::R_POWERPC_TPREL;
+		    rela_dyn->add_symbolless_global_addend(gsym, dynrel,
+							   got, off, 0);
+		  }
+	      }
 	  }
 	else if (tls_type == tls::TLSOPT_TO_LE)
 	  {
@@ -3902,7 +3956,9 @@ Target_powerpc<size, big_endian>::do_gc_
 {
   Powerpc_relobj<size, big_endian>* ppc_object
     = static_cast<Powerpc_relobj<size, big_endian>*>(dst_obj);
-  if (size == 64 && dst_shndx == ppc_object->opd_shndx())
+  if (size == 64
+      && !ppc_object->is_dynamic()
+      && dst_shndx == ppc_object->opd_shndx())
     {
       if (ppc_object->opd_valid())
 	{
@@ -3978,6 +4034,20 @@ Target_powerpc<size, big_endian>::scan_r
 
   if (size == 32)
     {
+      // Define a weak hidden _GLOBAL_OFFSET_TABLE_ to ensure it isn't
+      // seen as undefined when scanning relocs (and thus requires
+      // non-relative dynamic relocs).  The proper value will be
+      // updated later.
+      Symbol *gotsym = symtab->lookup("_GLOBAL_OFFSET_TABLE_", NULL);
+      if (gotsym != NULL && gotsym->is_undefined())
+	symtab->define_in_output_data("_GLOBAL_OFFSET_TABLE_", NULL,
+				      Symbol_table::PREDEFINED,
+				      this->got_section(symtab, layout), 0, 0,
+				      elfcpp::STT_OBJECT,
+				      elfcpp::STB_WEAK,
+				      elfcpp::STV_HIDDEN, 0,
+				      false, false);
+
       static Output_data_space* sdata;
 
       // Define _SDA_BASE_ at the start of the .sdata section.
@@ -4776,10 +4846,10 @@ Target_powerpc<size, big_endian>::Reloca
       break;
 
     case elfcpp::R_POWERPC_ADDR32:
-    case elfcpp::R_POWERPC_REL32:
       status = Reloc::addr32(view, value, overflow);
       break;
 
+    case elfcpp::R_POWERPC_REL32:
     case elfcpp::R_POWERPC_UADDR32:
       status = Reloc::addr32_u(view, value, overflow);
       break;

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]