PR gold/12980
[deliverable/binutils-gdb.git] / gold / i386.cc
index 6c6c4b414894811d3542c3d3de33754fd888dc65..84b9f0724a590969c459193852e3c703dba162bd 100644 (file)
@@ -1985,9 +1985,24 @@ Target_i386::Scan::global(Symbol_table* symtab,
             // If this symbol is not fully resolved, we need to add a
             // GOT entry with a dynamic relocation.
             Reloc_section* rel_dyn = target->rel_dyn_section(layout);
+
+           // Use a GLOB_DAT rather than a RELATIVE reloc if:
+           //
+           // 1) The symbol may be defined in some other module.
+           //
+           // 2) We are building a shared library and this is a
+           // protected symbol; using GLOB_DAT means that the dynamic
+           // linker can use the address of the PLT in the main
+           // executable when appropriate so that function address
+           // comparisons work.
+           //
+           // 3) This is a STT_GNU_IFUNC symbol in position dependent
+           // code, again so that function address comparisons work.
             if (gsym->is_from_dynobj()
                 || gsym->is_undefined()
                 || gsym->is_preemptible()
+               || (gsym->visibility() == elfcpp::STV_PROTECTED
+                   && parameters->options().shared())
                || (gsym->type() == elfcpp::STT_GNU_IFUNC
                    && parameters->options().output_is_position_independent()))
               got->add_global_with_rel(gsym, GOT_TYPE_STANDARD,
@@ -2638,7 +2653,12 @@ Target_i386::Relocate::relocate_tls(const Relocate_info<32, false>* relinfo,
     case elfcpp::R_386_TLS_GD:           // Global-dynamic
       if (optimized_type == tls::TLSOPT_TO_LE)
        {
-         gold_assert(tls_segment != NULL);
+         if (tls_segment == NULL)
+           {
+             gold_assert(parameters->errors()->error_count() > 0
+                         || issue_undefined_symbol_error(gsym));
+             return;
+           }
          this->tls_gd_to_le(relinfo, relnum, tls_segment,
                             rel, r_type, value, view,
                             view_size);
@@ -2664,7 +2684,12 @@ Target_i386::Relocate::relocate_tls(const Relocate_info<32, false>* relinfo,
             }
           if (optimized_type == tls::TLSOPT_TO_IE)
            {
-              gold_assert(tls_segment != NULL);
+             if (tls_segment == NULL)
+               {
+                 gold_assert(parameters->errors()->error_count() > 0
+                             || issue_undefined_symbol_error(gsym));
+                 return;
+               }
              this->tls_gd_to_ie(relinfo, relnum, tls_segment, rel, r_type,
                                  got_offset, view, view_size);
               break;
@@ -2687,7 +2712,12 @@ Target_i386::Relocate::relocate_tls(const Relocate_info<32, false>* relinfo,
       this->local_dynamic_type_ = LOCAL_DYNAMIC_GNU;
       if (optimized_type == tls::TLSOPT_TO_LE)
         {
-         gold_assert(tls_segment != NULL);
+         if (tls_segment == NULL)
+           {
+             gold_assert(parameters->errors()->error_count() > 0
+                         || issue_undefined_symbol_error(gsym));
+             return;
+           }
          this->tls_desc_gd_to_le(relinfo, relnum, tls_segment,
                                  rel, r_type, value, view,
                                  view_size);
@@ -2722,7 +2752,12 @@ Target_i386::Relocate::relocate_tls(const Relocate_info<32, false>* relinfo,
             }
           if (optimized_type == tls::TLSOPT_TO_IE)
            {
-              gold_assert(tls_segment != NULL);
+             if (tls_segment == NULL)
+               {
+                 gold_assert(parameters->errors()->error_count() > 0
+                             || issue_undefined_symbol_error(gsym));
+                 return;
+               }
              this->tls_desc_gd_to_ie(relinfo, relnum, tls_segment, rel, r_type,
                                       got_offset, view, view_size);
               break;
@@ -2754,7 +2789,12 @@ Target_i386::Relocate::relocate_tls(const Relocate_info<32, false>* relinfo,
       this->local_dynamic_type_ = LOCAL_DYNAMIC_GNU;
       if (optimized_type == tls::TLSOPT_TO_LE)
        {
-          gold_assert(tls_segment != NULL);
+         if (tls_segment == NULL)
+           {
+             gold_assert(parameters->errors()->error_count() > 0
+                         || issue_undefined_symbol_error(gsym));
+             return;
+           }
          this->tls_ld_to_le(relinfo, relnum, tls_segment, rel, r_type,
                             value, view, view_size);
          break;
@@ -2785,7 +2825,12 @@ Target_i386::Relocate::relocate_tls(const Relocate_info<32, false>* relinfo,
          elfcpp::Shdr<32, false> shdr(relinfo->data_shdr);
          if ((shdr.get_sh_flags() & elfcpp::SHF_EXECINSTR) != 0)
            {
-             gold_assert(tls_segment != NULL);
+             if (tls_segment == NULL)
+               {
+                 gold_assert(parameters->errors()->error_count() > 0
+                             || issue_undefined_symbol_error(gsym));
+                 return;
+               }
              value -= tls_segment->memsz();
            }
        }
@@ -2797,7 +2842,12 @@ Target_i386::Relocate::relocate_tls(const Relocate_info<32, false>* relinfo,
     case elfcpp::R_386_TLS_IE_32:
       if (optimized_type == tls::TLSOPT_TO_LE)
        {
-          gold_assert(tls_segment != NULL);
+         if (tls_segment == NULL)
+           {
+             gold_assert(parameters->errors()->error_count() > 0
+                         || issue_undefined_symbol_error(gsym));
+             return;
+           }
          Target_i386::Relocate::tls_ie_to_le(relinfo, relnum, tls_segment,
                                              rel, r_type, value, view,
                                              view_size);
@@ -2841,7 +2891,12 @@ Target_i386::Relocate::relocate_tls(const Relocate_info<32, false>* relinfo,
       // have been created for this location, so do not apply it now.
       if (!parameters->options().shared())
         {
-          gold_assert(tls_segment != NULL);
+         if (tls_segment == NULL)
+           {
+             gold_assert(parameters->errors()->error_count() > 0
+                         || issue_undefined_symbol_error(gsym));
+             return;
+           }
           value -= tls_segment->memsz();
           Relocate_functions<32, false>::rel32(view, value);
         }
@@ -2852,7 +2907,12 @@ Target_i386::Relocate::relocate_tls(const Relocate_info<32, false>* relinfo,
       // have been created for this location, so do not apply it now.
       if (!parameters->options().shared())
         {
-          gold_assert(tls_segment != NULL);
+         if (tls_segment == NULL)
+           {
+             gold_assert(parameters->errors()->error_count() > 0
+                         || issue_undefined_symbol_error(gsym));
+             return;
+           }
           value = tls_segment->memsz() - value;
           Relocate_functions<32, false>::rel32(view, value);
         }
This page took 0.026339 seconds and 4 git commands to generate.