gas/testsuite/
[deliverable/binutils-gdb.git] / gold / symtab.h
index 1ee3131d8f662ca50f5f7a90c1bc317154b37afb..043fb50f2288c3e2930f96f268a65f651f3915fd 100644 (file)
@@ -38,6 +38,7 @@
 namespace gold
 {
 
+class Mapfile;
 class Object;
 class Relobj;
 template<int size, bool big_endian>
@@ -78,7 +79,9 @@ class Symbol
     // section.
     IN_OUTPUT_SEGMENT,
     // Symbol value is constant.
-    CONSTANT
+    IS_CONSTANT,
+    // Symbol is undefined.
+    IS_UNDEFINED
   };
 
   // When the source is IN_OUTPUT_SEGMENT, we need to describe what
@@ -390,7 +393,7 @@ class Symbol
   {
     bool is_ordinary;
     if (this->source_ != FROM_OBJECT)
-      return true;
+      return this->source_ != IS_UNDEFINED;
     unsigned int shndx = this->shndx(&is_ordinary);
     return (is_ordinary
            ? shndx != elfcpp::SHN_UNDEF
@@ -409,30 +412,26 @@ class Symbol
   is_undefined() const
   {
     bool is_ordinary;
-    return (this->source_ == FROM_OBJECT
-           && this->shndx(&is_ordinary) == elfcpp::SHN_UNDEF
-           && is_ordinary);
+    return ((this->source_ == FROM_OBJECT
+            && this->shndx(&is_ordinary) == elfcpp::SHN_UNDEF
+            && is_ordinary)
+           || this->source_ == IS_UNDEFINED);
   }
 
   // Return whether this is a weak undefined symbol.
   bool
   is_weak_undefined() const
-  {
-    bool is_ordinary;
-    return (this->source_ == FROM_OBJECT
-            && this->binding() == elfcpp::STB_WEAK
-            && this->shndx(&is_ordinary) == elfcpp::SHN_UNDEF
-           && is_ordinary);
-  }
+  { return this->is_undefined() && this->binding() == elfcpp::STB_WEAK; }
 
   // Return whether this is an absolute symbol.
   bool
   is_absolute() const
   {
     bool is_ordinary;
-    return (this->source_ == FROM_OBJECT
-           && this->shndx(&is_ordinary) == elfcpp::SHN_ABS
-           && !is_ordinary);
+    return ((this->source_ == FROM_OBJECT
+            && this->shndx(&is_ordinary) == elfcpp::SHN_ABS
+            && !is_ordinary)
+           || this->source_ == IS_CONSTANT);
   }
 
   // Return whether this is a common symbol.
@@ -467,12 +466,36 @@ class Symbol
     // is preemptible.
     gold_assert(!this->is_undefined());
 
-    return (this->visibility_ != elfcpp::STV_INTERNAL
-            && this->visibility_ != elfcpp::STV_HIDDEN
-            && this->visibility_ != elfcpp::STV_PROTECTED
-            && !this->is_forced_local_
-            && parameters->options().shared()
-           && !parameters->options().Bsymbolic());
+    // If a symbol does not have default visibility, it can not be
+    // seen outside this link unit and therefore is not preemptible.
+    if (this->visibility_ != elfcpp::STV_DEFAULT)
+      return false;
+
+    // If this symbol has been forced to be a local symbol by a
+    // version script, then it is not visible outside this link unit
+    // and is not preemptible.
+    if (this->is_forced_local_)
+      return false;
+
+    // If we are not producing a shared library, then nothing is
+    // preemptible.
+    if (!parameters->options().shared())
+      return false;
+
+    // If the user used -Bsymbolic, then nothing is preemptible.
+    if (parameters->options().Bsymbolic())
+      return false;
+
+    // If the user used -Bsymbolic-functions, then functions are not
+    // preemptible.  We explicitly check for not being STT_OBJECT,
+    // rather than for being STT_FUNC, because that is what the GNU
+    // linker does.
+    if (this->type() != elfcpp::STT_OBJECT
+       && parameters->options().Bsymbolic_functions())
+      return false;
+
+    // Otherwise the symbol is preemptible.
+    return true;
   }
 
   // Return true if this symbol is a function that needs a PLT entry.
@@ -554,6 +577,48 @@ class Symbol
     return false;
   }
 
+  // Whether we should use the PLT offset associated with a symbol for
+  // a relocation.  IS_NON_PIC_REFERENCE is true if this is a non-PIC
+  // reloc--the same set of relocs for which we would pass NON_PIC_REF
+  // to the needs_dynamic_reloc function.
+
+  bool
+  use_plt_offset(bool is_non_pic_reference) const
+  {
+    // If the symbol doesn't have a PLT offset, then naturally we
+    // don't want to use it.
+    if (!this->has_plt_offset())
+      return false;
+
+    // If we are going to generate a dynamic relocation, then we will
+    // wind up using that, so no need to use the PLT entry.
+    if (this->needs_dynamic_reloc(FUNCTION_CALL
+                                 | (is_non_pic_reference
+                                    ? NON_PIC_REF
+                                    : 0)))
+      return false;
+
+    // If the symbol is from a dynamic object, we need to use the PLT
+    // entry.
+    if (this->is_from_dynobj())
+      return true;
+
+    // If we are generating a shared object, and this symbol is
+    // undefined or preemptible, we need to use the PLT entry.
+    if (parameters->options().shared()
+       && (this->is_undefined() || this->is_preemptible()))
+      return true;
+
+    // If this is a weak undefined symbol, we need to use the PLT
+    // entry; the symbol may be defined by a library loaded at
+    // runtime.
+    if (this->is_weak_undefined())
+      return true;
+
+    // Otherwise we can use the regular definition.
+    return false;
+  }
+
   // Given a direct absolute static relocation against
   // the global symbol, where a dynamic relocation is needed, this
   // function returns whether a relative dynamic relocation can be used.
@@ -640,25 +705,35 @@ class Symbol
   // index rather than a special code.
   template<int size, bool big_endian>
   void
-  init_base(const char *name, const char* version, Object* object,
-           const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
-           bool is_ordinary);
+  init_base_object(const char *name, const char* version, Object* object,
+                  const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
+                  bool is_ordinary);
 
   // Initialize fields for an Output_data.
   void
-  init_base(const char* name, Output_data*, elfcpp::STT, elfcpp::STB,
-           elfcpp::STV, unsigned char nonvis, bool offset_is_from_end);
+  init_base_output_data(const char* name, const char* version, Output_data*,
+                       elfcpp::STT, elfcpp::STB, elfcpp::STV,
+                       unsigned char nonvis, bool offset_is_from_end);
 
   // Initialize fields for an Output_segment.
   void
-  init_base(const char* name, Output_segment* os, elfcpp::STT type,
-           elfcpp::STB binding, elfcpp::STV visibility,
-           unsigned char nonvis, Segment_offset_base offset_base);
+  init_base_output_segment(const char* name, const char* version,
+                          Output_segment* os, elfcpp::STT type,
+                          elfcpp::STB binding, elfcpp::STV visibility,
+                          unsigned char nonvis,
+                          Segment_offset_base offset_base);
 
   // Initialize fields for a constant.
   void
-  init_base(const char* name, elfcpp::STT type, elfcpp::STB binding,
-           elfcpp::STV visibility, unsigned char nonvis);
+  init_base_constant(const char* name, const char* version, elfcpp::STT type,
+                    elfcpp::STB binding, elfcpp::STV visibility,
+                    unsigned char nonvis);
+
+  // Initialize fields for an undefined symbol.
+  void
+  init_base_undefined(const char* name, const char* version, elfcpp::STT type,
+                     elfcpp::STB binding, elfcpp::STV visibility,
+                     unsigned char nonvis);
 
   // Override existing symbol.
   template<int size, bool big_endian>
@@ -670,6 +745,10 @@ class Symbol
   void
   override_base_with_special(const Symbol* from);
 
+  // Override symbol version.
+  void
+  override_version(const char* version);
+
   // Allocate a common symbol by giving it a location in the output
   // file.
   void
@@ -814,26 +893,34 @@ class Sized_symbol : public Symbol
   // index rather than a special code.
   template<bool big_endian>
   void
-  init(const char *name, const char* version, Object* object,
-       const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
-       bool is_ordinary);
+  init_object(const char *name, const char* version, Object* object,
+             const elfcpp::Sym<size, big_endian>&, unsigned int st_shndx,
+             bool is_ordinary);
 
   // Initialize fields for an Output_data.
   void
-  init(const char* name, Output_data*, Value_type value, Size_type symsize,
-       elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis,
-       bool offset_is_from_end);
+  init_output_data(const char* name, const char* version, Output_data*,
+                  Value_type value, Size_type symsize, elfcpp::STT,
+                  elfcpp::STB, elfcpp::STV, unsigned char nonvis,
+                  bool offset_is_from_end);
 
   // Initialize fields for an Output_segment.
   void
-  init(const char* name, Output_segment*, Value_type value, Size_type symsize,
-       elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis,
-       Segment_offset_base offset_base);
+  init_output_segment(const char* name, const char* version, Output_segment*,
+                     Value_type value, Size_type symsize, elfcpp::STT,
+                     elfcpp::STB, elfcpp::STV, unsigned char nonvis,
+                     Segment_offset_base offset_base);
 
   // Initialize fields for a constant.
   void
-  init(const char* name, Value_type value, Size_type symsize,
-       elfcpp::STT, elfcpp::STB, elfcpp::STV, unsigned char nonvis);
+  init_constant(const char* name, const char* version, Value_type value,
+               Size_type symsize, elfcpp::STT, elfcpp::STB, elfcpp::STV,
+               unsigned char nonvis);
+
+  // Initialize fields for an undefined symbol.
+  void
+  init_undefined(const char* name, const char* version, elfcpp::STT,
+                elfcpp::STB, elfcpp::STV, unsigned char nonvis);
 
   // Override existing symbol.
   template<bool big_endian>
@@ -1041,14 +1128,16 @@ class Symbol_table
   // the symbol table.  SYMS is the symbols, SYMNDX_OFFSET is the
   // offset in the symbol table of the first symbol, SYM_NAMES is
   // their names, SYM_NAME_SIZE is the size of SYM_NAMES.  This sets
-  // SYMPOINTERS to point to the symbols in the symbol table.
+  // SYMPOINTERS to point to the symbols in the symbol table.  It sets
+  // *DEFINED to the number of defined symbols.
   template<int size, bool big_endian>
   void
   add_from_relobj(Sized_relobj<size, big_endian>* relobj,
                  const unsigned char* syms, size_t count,
                  size_t symndx_offset, const char* sym_names,
                  size_t sym_name_size,
-                 typename Sized_relobj<size, big_endian>::Symbols*);
+                 typename Sized_relobj<size, big_endian>::Symbols*,
+                 size_t* defined);
 
   // Add COUNT dynamic symbols from the dynamic object DYNOBJ to the
   // symbol table.  SYMS is the symbols.  SYM_NAMES is their names.
@@ -1060,7 +1149,9 @@ class Symbol_table
                  const unsigned char* syms, size_t count,
                  const char* sym_names, size_t sym_name_size,
                  const unsigned char* versym, size_t versym_size,
-                 const std::vector<const char*>*);
+                 const std::vector<const char*>*,
+                 typename Sized_relobj<size, big_endian>::Symbols*,
+                 size_t* defined);
 
   // Define a special symbol based on an Output_data.  It is a
   // multiple definition error if this symbol is already defined.
@@ -1133,7 +1224,7 @@ class Symbol_table
 
   // Allocate the common symbols
   void
-  allocate_commons(Layout*);
+  allocate_commons(Layout*, Mapfile*);
 
   // Add a warning for symbol NAME in object OBJ.  WARNING is the text
   // of the warning.
@@ -1160,6 +1251,11 @@ class Symbol_table
   void
   detect_odr_violations(const Task*, const char* output_file_name) const;
 
+  // Add any undefined symbols named on the command line to the symbol
+  // table.
+  void
+  add_undefined_symbols_from_command_line();
+
   // SYM is defined using a COPY reloc.  Return the dynamic object
   // where the original definition was found.
   Dynobj*
@@ -1238,8 +1334,7 @@ class Symbol_table
 
   template<int size, bool big_endian>
   void
-  resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from,
-          const char* version);
+  resolve(Sized_symbol<size>* to, const Sized_symbol<size>* from);
 
   // Record that a symbol is forced to be local by a version script.
   void
@@ -1316,15 +1411,21 @@ class Symbol_table
     elfcpp::STV visibility, unsigned char nonvis,
     bool only_if_ref, bool force_override);
 
+  // Add any undefined symbols named on the command line to the symbol
+  // table, sized version.
+  template<int size>
+  void
+  do_add_undefined_symbols_from_command_line();
+
   // Allocate the common symbols, sized version.
   template<int size>
   void
-  do_allocate_commons(Layout*);
+  do_allocate_commons(Layout*, Mapfile*);
 
   // Allocate the common symbols from one list.
   template<int size>
   void
-  do_allocate_commons_list(Layout*, bool is_tls, Commons_type*);
+  do_allocate_commons_list(Layout*, bool is_tls, Commons_type*, Mapfile*);
 
   // Implement detect_odr_violations.
   template<int size, bool big_endian>
This page took 0.035018 seconds and 4 git commands to generate.