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][patch] Fix non-PIC warning to print only when building position-independent output


This patch renames check_non_pic to check_dynamic_reloc, and in the
case of an unsupported dynamic relocation, prints the hint to
"recompile with -fPIC" only when actually building a
position-independent output file. Under normal circumstances (after
yesterday's patch to close the bug where an unsatisfied data reference
could trigger this), we should never actually try to generated an
unsupported dynamic relocation when building a
non-position-independent file -- non-PIC references to dynamic objects
generally will be transformed into COPY relocations (for data) or
route through the PLT (for code). If we ever do hit this case in a
non-position-independent link, however, I hope it'll be the compiler's
fault, and we shouldn't print a message that implies that -fPIC is
actually required. (Maybe we should print something instead about a
possible bug in the compiler or assembly code?)

Compiles clean with --enable-targets=all. Tested on x86_64.

OK?

-cary


	* powerpc.cc (Target_powerpc::issued_unsupp_reloc_error_): Renamed,
	was issued_non_pic_error_.
	(Target_powerpc::check_dynamic_reloc): Renamed, was check_non_pic.
	Mention "-fPIC" only if building position-independent output.
	* sparc.cc (Target_sparc::issued_unsupp_reloc_error_): Renamed,
	was issued_non_pic_error_.
	(Target_sparc::check_dynamic_reloc): Renamed, was check_non_pic.
	Mention "-fPIC" only if building position-independent output.
	* x86_64.cc (Target_x86_64::issued_unsupp_reloc_error_): Renamed,
	was issued_non_pic_error_.
	(Target_x86_64::check_dynamic_reloc): Renamed, was check_non_pic.
	Mention "-fPIC" only if building position-independent output.


Index: powerpc.cc
===================================================================
RCS file: /cvs/src/src/gold/powerpc.cc,v
retrieving revision 1.11
diff -u -p -r1.11 powerpc.cc
--- powerpc.cc	24 Mar 2009 04:50:32 -0000	1.11
+++ powerpc.cc	25 Mar 2009 23:41:12 -0000
@@ -165,7 +165,7 @@ class Target_powerpc : public Sized_targ
   {
   public:
     Scan()
-      : issued_non_pic_error_(false)
+      : issued_unsupp_reloc_error_(false)
     { }

     inline void
@@ -200,10 +200,10 @@ class Target_powerpc : public Sized_targ
 		      Target_powerpc* target);

     void
-    check_non_pic(Relobj*, unsigned int r_type);
+    check_dynamic_reloc(Relobj*, unsigned int r_type);

     // Whether we have issued an error about a non-PIC compilation.
-    bool issued_non_pic_error_;
+    bool issued_unsupp_reloc_error_;
   };

   // The class which implements relocation.
@@ -1013,7 +1013,7 @@ Target_powerpc<size, big_endian>::Scan::

 template<int size, bool big_endian>
 void
-Target_powerpc<size, big_endian>::Scan::check_non_pic(Relobj* object,
+Target_powerpc<size, big_endian>::Scan::check_dynamic_reloc(Relobj* object,
 						      unsigned int r_type)
 {
   gold_assert(r_type != elfcpp::R_POWERPC_NONE);
@@ -1092,11 +1092,14 @@ Target_powerpc<size, big_endian>::Scan::
   // This prevents us from issuing more than one error per reloc
   // section.  But we can still wind up issuing more than one
   // error per object file.
-  if (this->issued_non_pic_error_)
+  if (this->issued_unsupp_reloc_error_)
     return;
-  object->error(_("requires unsupported dynamic reloc; "
-		  "recompile with -fPIC"));
-  this->issued_non_pic_error_ = true;
+  if (parameters->options().output_is_position_independent())
+    object->error(_("requires unsupported dynamic reloc; "
+                    "recompile with -fPIC"));
+  else
+    object->error(_("requires unsupported dynamic reloc"));
+  this->issued_unsupp_reloc_error_ = true;
   return;
 }

@@ -1134,7 +1137,7 @@ Target_powerpc<size, big_endian>::Scan::
         {
           Reloc_section* rela_dyn = target->rela_dyn_section(layout);

-	  check_non_pic(object, r_type);
+	  check_dynamic_reloc(object, r_type);
           if (lsym.get_st_type() != elfcpp::STT_SECTION)
             {
               unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
@@ -1313,7 +1316,7 @@ Target_powerpc<size, big_endian>::Scan::
               {
                 Reloc_section* rela_dyn = target->rela_dyn_section(layout);

-		check_non_pic(object, r_type);
+		check_dynamic_reloc(object, r_type);
 		if (gsym->is_from_dynobj()
 		    || gsym->is_undefined()
 		    || gsym->is_preemptible())
@@ -1356,7 +1359,7 @@ Target_powerpc<size, big_endian>::Scan::
 	    else
 	      {
 		Reloc_section* rela_dyn = target->rela_dyn_section(layout);
-		check_non_pic(object, r_type);
+		check_dynamic_reloc(object, r_type);
 		rela_dyn->add_global(gsym, r_type, output_section, object,
 				     data_shndx, reloc.get_r_offset(),
 				     reloc.get_r_addend());
Index: sparc.cc
===================================================================
RCS file: /cvs/src/src/gold/sparc.cc,v
retrieving revision 1.15
diff -u -p -r1.15 sparc.cc
--- sparc.cc	24 Mar 2009 04:50:32 -0000	1.15
+++ sparc.cc	25 Mar 2009 23:41:12 -0000
@@ -175,7 +175,7 @@ class Target_sparc : public Sized_target
   {
   public:
     Scan()
-      : issued_non_pic_error_(false)
+      : issued_unsupp_reloc_error_(false)
     { }

     inline void
@@ -210,10 +210,10 @@ class Target_sparc : public Sized_target
 		      Target_sparc* target);

     void
-    check_non_pic(Relobj*, unsigned int r_type);
+    check_dynamic_reloc(Relobj*, unsigned int r_type);

     // Whether we have issued an error about a non-PIC compilation.
-    bool issued_non_pic_error_;
+    bool issued_unsupp_reloc_error_;
   };

   // The class which implements relocation.
@@ -1509,7 +1509,7 @@ Target_sparc<size, big_endian>::Scan::un

 template<int size, bool big_endian>
 void
-Target_sparc<size, big_endian>::Scan::check_non_pic(Relobj* object,
unsigned int r_type)
+Target_sparc<size, big_endian>::Scan::check_dynamic_reloc(Relobj*
object, unsigned int r_type)
 {
   gold_assert(r_type != elfcpp::R_SPARC_NONE);

@@ -1587,11 +1587,14 @@ Target_sparc<size, big_endian>::Scan::ch
   // This prevents us from issuing more than one error per reloc
   // section.  But we can still wind up issuing more than one
   // error per object file.
-  if (this->issued_non_pic_error_)
+  if (this->issued_unsupp_reloc_error_)
     return;
-  object->error(_("requires unsupported dynamic reloc; "
-		  "recompile with -fPIC"));
-  this->issued_non_pic_error_ = true;
+  if (parameters->options().output_is_position_independent())
+    object->error(_("requires unsupported dynamic reloc; "
+                    "recompile with -fPIC"));
+  else
+    object->error(_("requires unsupported dynamic reloc"));
+  this->issued_unsupp_reloc_error_ = true;
   return;
 }

@@ -1669,7 +1672,7 @@ Target_sparc<size, big_endian>::Scan::lo
         {
           Reloc_section* rela_dyn = target->rela_dyn_section(layout);

-	  check_non_pic(object, r_type);
+	  check_dynamic_reloc(object, r_type);
           if (lsym.get_st_type() != elfcpp::STT_SECTION)
             {
               unsigned int r_sym = elfcpp::elf_r_sym<size>(reloc.get_r_info());
@@ -1984,7 +1987,7 @@ Target_sparc<size, big_endian>::Scan::gl
 	    else
 	      {
 		Reloc_section* rela_dyn = target->rela_dyn_section(layout);
-		check_non_pic(object, r_type);
+		check_dynamic_reloc(object, r_type);
 		rela_dyn->add_global(gsym, orig_r_type, output_section, object,
 				     data_shndx, reloc.get_r_offset(),
 				     reloc.get_r_addend());
@@ -2050,7 +2053,7 @@ Target_sparc<size, big_endian>::Scan::gl
               {
                 Reloc_section* rela_dyn = target->rela_dyn_section(layout);

-		check_non_pic(object, r_type);
+		check_dynamic_reloc(object, r_type);
 		if (gsym->is_from_dynobj()
 		    || gsym->is_undefined()
 		    || gsym->is_preemptible())
Index: x86_64.cc
===================================================================
RCS file: /cvs/src/src/gold/x86_64.cc,v
retrieving revision 1.80
diff -u -p -r1.80 x86_64.cc
--- x86_64.cc	24 Mar 2009 00:31:29 -0000	1.80
+++ x86_64.cc	25 Mar 2009 23:41:12 -0000
@@ -172,7 +172,7 @@ class Target_x86_64 : public Target_free
   {
   public:
     Scan()
-      : issued_non_pic_error_(false)
+      : issued_unsupp_reloc_error_(false)
     { }

     inline void
@@ -202,10 +202,10 @@ class Target_x86_64 : public Target_free
 			     Symbol*);

     void
-    check_non_pic(Relobj*, unsigned int r_type);
+    check_dynamic_reloc(Relobj*, unsigned int r_type);

     // Whether we have issued an error about a non-PIC compilation.
-    bool issued_non_pic_error_;
+    bool issued_unsupp_reloc_error_;
   };

   // The class which implements relocation.
@@ -951,7 +951,7 @@ Target_x86_64::Scan::unsupported_reloc_l
 // error even if the section is not read-only.

 void
-Target_x86_64::Scan::check_non_pic(Relobj* object, unsigned int r_type)
+Target_x86_64::Scan::check_dynamic_reloc(Relobj* object, unsigned int r_type)
 {
   switch (r_type)
     {
@@ -972,11 +972,14 @@ Target_x86_64::Scan::check_non_pic(Relob
       // This prevents us from issuing more than one error per reloc
       // section.  But we can still wind up issuing more than one
       // error per object file.
-      if (this->issued_non_pic_error_)
+      if (this->issued_unsupp_reloc_error_)
         return;
-      object->error(_("requires unsupported dynamic reloc; "
-                      "recompile with -fPIC"));
-      this->issued_non_pic_error_ = true;
+      if (parameters->options().output_is_position_independent())
+        object->error(_("requires unsupported dynamic reloc; "
+                        "recompile with -fPIC"));
+      else
+        object->error(_("requires unsupported dynamic reloc"));
+      this->issued_unsupp_reloc_error_ = true;
       return;

     case elfcpp::R_X86_64_NONE:
@@ -1034,7 +1037,7 @@ Target_x86_64::Scan::local(const General
       // because that is always a 64-bit relocation.
       if (parameters->options().output_is_position_independent())
         {
-          this->check_non_pic(object, r_type);
+          this->check_dynamic_reloc(object, r_type);

           Reloc_section* rela_dyn = target->rela_dyn_section(layout);
 	  unsigned int r_sym = elfcpp::elf_r_sym<64>(reloc.get_r_info());
@@ -1105,7 +1108,7 @@ Target_x86_64::Scan::local(const General
                       object->local_got_offset(r_sym, GOT_TYPE_STANDARD), 0);
                 else
                   {
-                    this->check_non_pic(object, r_type);
+                    this->check_dynamic_reloc(object, r_type);

                     gold_assert(lsym.get_st_type() != elfcpp::STT_SECTION);
                     rela_dyn->add_local(
@@ -1322,7 +1325,7 @@ Target_x86_64::Scan::global(const Genera
               }
             else
               {
-                this->check_non_pic(object, r_type);
+                this->check_dynamic_reloc(object, r_type);
                 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
                 rela_dyn->add_global(gsym, r_type, output_section, object,
                                      data_shndx, reloc.get_r_offset(),
@@ -1353,7 +1356,7 @@ Target_x86_64::Scan::global(const Genera
               }
             else
               {
-                this->check_non_pic(object, r_type);
+                this->check_dynamic_reloc(object, r_type);
                 Reloc_section* rela_dyn = target->rela_dyn_section(layout);
                 rela_dyn->add_global(gsym, r_type, output_section, object,
                                      data_shndx, reloc.get_r_offset(),


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