OSDN Git Service

PR 10980
[pf3gnuchains/pf3gnuchains3x.git] / gold / script.h
index 3397bf0..a7e0186 100644 (file)
@@ -45,6 +45,7 @@ class Symbol_table;
 class Layout;
 class Mapfile;
 class Input_argument;
+class Input_arguments;
 class Input_objects;
 class Input_group;
 class Input_file;
@@ -127,12 +128,32 @@ class Expression
 class Version_script_info
 {
  public:
+  // The languages which can be specified in a versionn script.
+  enum Language
+  {
+    LANGUAGE_C,                // No demangling.
+    LANGUAGE_CXX,      // C++ demangling.
+    LANGUAGE_JAVA,     // Java demangling.
+    LANGUAGE_COUNT
+  };
+
+  Version_script_info();
+
   ~Version_script_info();
 
   // Clear everything.
   void
   clear();
 
+  // Finalize the version control information.
+  void
+  finalize();
+
+  // Return whether the information is finalized.
+  bool
+  is_finalized() const
+  { return this->is_finalized_; }
+
   // Return whether any version were defined in the version script.
   bool
   empty() const
@@ -151,8 +172,6 @@ class Version_script_info
   { return this->get_symbol_version_helper(symbol, false, NULL); }
 
   // Return the names of versions defined in the version script.
-  // Strings are allocated out of the stringpool given in the
-  // constructor.
   std::vector<std::string>
   get_versions() const;
 
@@ -173,6 +192,10 @@ class Version_script_info
   struct Version_tree*
   allocate_version_tree();
 
+  // Build the lookup tables after all data have been read.
+  void
+  build_lookup_tables();
+
   // Print contents to the FILE.  This is for debugging.
   void
   print(FILE*) const;
@@ -181,13 +204,58 @@ class Version_script_info
   void
   print_expression_list(FILE* f, const Version_expression_list*) const;
 
-  bool get_symbol_version_helper(const char* symbol,
-                                bool check_global,
-                                std::string* pversion) const;
+  bool
+  get_symbol_version_helper(const char* symbol,
+                           bool check_global,
+                           std::string* pversion) const;
+
+  // Fast lookup information for a glob pattern.
+  struct Glob
+  {
+    Glob()
+      : pattern(NULL), version(NULL)
+    { }
+
+    Glob(const char* p, const Version_tree* v)
+      : pattern(p), version(v)
+    { }
+
+    // A pointer to the glob pattern.  The pattern itself lives in a
+    // Version_expression structure.
+    const char* pattern;
+    // The Version_tree we use if this pattern matches.
+    const Version_tree* version;
+  };
+
+  // Fast lookup information for a given language.
+
+  typedef Unordered_map<std::string, const Version_tree*> Exact;
+
+  struct Lookup
+  {
+    // A hash table of all exact match strings mapping to a
+    // Version_tree.
+    Exact exact;
+    // A vector of glob patterns mapping to Version_trees.
+    std::vector<Glob> globs;
+  };
 
-  std::vector<struct Version_dependency_list*> dependency_lists_;
-  std::vector<struct Version_expression_list*> expression_lists_;
-  std::vector<struct Version_tree*> version_trees_;
+  void
+  build_expression_list_lookup(const Version_expression_list*,
+                              const Version_tree*, Lookup**);
+
+  // All the version dependencies we allocate.
+  std::vector<Version_dependency_list*> dependency_lists_;
+  // All the version expressions we allocate.
+  std::vector<Version_expression_list*> expression_lists_;
+  // The list of versions.
+  std::vector<Version_tree*> version_trees_;
+  // Lookup information for global symbols, by language.
+  Lookup* globals_[LANGUAGE_COUNT];
+  // Lookup information for local symbols, by language.
+  Lookup* locals_[LANGUAGE_COUNT];
+  // Whether this has been finalized.
+  bool is_finalized_;
 };
 
 // This class manages assignments to symbols.  These can appear in
@@ -199,10 +267,10 @@ class Version_script_info
 class Symbol_assignment
 {
  public:
-  Symbol_assignment(const char* name, size_t namelen, Expression* val,
-                   bool provide, bool hidden)
-    : name_(name, namelen), val_(val), provide_(provide), hidden_(hidden),
-      sym_(NULL)
+  Symbol_assignment(const char* name, size_t namelen, bool is_defsym,
+                   Expression* val, bool provide, bool hidden)
+    : name_(name, namelen), val_(val), is_defsym_(is_defsym),
+      provide_(provide), hidden_(hidden), sym_(NULL)
   { }
 
   // Add the symbol to the symbol table.
@@ -245,6 +313,9 @@ class Symbol_assignment
   std::string name_;
   // Expression to assign to symbol.
   Expression* val_;
+  // True if this symbol is defined by a --defsym, false if it is
+  // defined in a linker script.
+  bool is_defsym_;
   // Whether the assignment should be provided (only set if there is
   // an undefined reference to the symbol.
   bool provide_;
@@ -297,8 +368,8 @@ class Script_options
 
   // Add a symbol to be defined.
   void
-  add_symbol_assignment(const char* name, size_t length, Expression* value,
-                       bool provide, bool hidden);
+  add_symbol_assignment(const char* name, size_t length, bool is_defsym,
+                       Expression* value, bool provide, bool hidden);
 
   // Add an assertion.
   void
@@ -382,6 +453,26 @@ class Script_options
   Script_sections script_sections_;
 };
 
+// Information about a script input that will persist during the whole linker
+// run. Needed only during an incremental build to retrieve the input files
+// added by this script.
+
+class Script_info
+{
+ public:
+  Script_info(Input_arguments* inputs)
+    : inputs_(inputs)
+  { }
+
+  // Returns the input files included because of this script.
+  Input_arguments*
+  inputs()
+  { return this->inputs_; }
+
+ private:
+  Input_arguments* inputs_;
+};
+
 // FILE was found as an argument on the command line, but was not
 // recognized as an ELF file.  Try to read it as a script.  Return
 // true if the file was handled.  This has to handle /usr/lib/libc.so
@@ -389,8 +480,8 @@ class Script_options
 // whether the function took over NEXT_BLOCKER.
 
 bool
-read_input_script(Workqueue*, const General_options&, Symbol_table*, Layout*,
-                 Dirsearch*, Input_objects*, Mapfile*, Input_group*,
+read_input_script(Workqueue*, Symbol_table*, Layout*, Dirsearch*, int,
+                 Input_objects*, Mapfile*, Input_group*,
                  const Input_argument*, Input_file*,
                  Task_token* next_blocker, bool* used_next_blocker);
 
@@ -398,7 +489,7 @@ read_input_script(Workqueue*, const General_options&, Symbol_table*, Layout*,
 // Read it as a script, and execute its contents immediately.
 
 bool
-read_commandline_script(const char* filename, Command_line*);
+read_commandline_script(const char* filename, Command_line* cmdline);
 
 // FILE was found as an argument to --version-script.  Read it as a
 // version script, and store its contents in
@@ -407,6 +498,14 @@ read_commandline_script(const char* filename, Command_line*);
 bool
 read_version_script(const char* filename, Command_line* cmdline);
 
+// FILENAME was found as an argument to --dynamic-list.  Read it as a
+// version script (actually, a versym_node from a version script), and
+// store its contents in DYNAMIC_LIST.
+
+bool
+read_dynamic_list(const char* filename, Command_line* cmdline,
+                  Script_options* dynamic_list);
+
 } // End namespace gold.
 
 #endif // !defined(GOLD_SCRIPT_H)