]> git.saurik.com Git - apple/ld64.git/blobdiff - src/ld/SymbolTable.h
ld64-242.tar.gz
[apple/ld64.git] / src / ld / SymbolTable.h
index f352a51c4c6bd8545858f50a7b98f9cffc5253f6..14c7a9e0077f45fc983d0a117f29f55424c4d0fd 100644 (file)
@@ -42,7 +42,7 @@
 #include <mach-o/dyld.h>
 
 #include <vector>
-#include <ext/hash_map>
+#include <unordered_map>
 
 #include "Options.h"
 #include "ld.hpp"
@@ -57,42 +57,41 @@ public:
        typedef uint32_t IndirectBindingSlot;
 
 private:
-       class CStringEquals {
-       public:
-               bool operator()(const char* left, const char* right) const { return (strcmp(left, right) == 0); }
-       };
-       typedef __gnu_cxx::hash_map<const char*, IndirectBindingSlot, __gnu_cxx::hash<const char*>, CStringEquals> NameToSlot;
+       typedef std::unordered_map<const char*, IndirectBindingSlot, CStringHash, CStringEquals> NameToSlot;
 
        class ContentFuncs {
        public:
                size_t  operator()(const ld::Atom*) const;
                bool    operator()(const ld::Atom* left, const ld::Atom* right) const;
        };
-       typedef __gnu_cxx::hash_map<const ld::Atom*, IndirectBindingSlot, ContentFuncs, ContentFuncs> ContentToSlot;
+       typedef std::unordered_map<const ld::Atom*, IndirectBindingSlot, ContentFuncs, ContentFuncs> ContentToSlot;
 
        class ReferencesHashFuncs {
        public:
                size_t  operator()(const ld::Atom*) const;
                bool    operator()(const ld::Atom* left, const ld::Atom* right) const;
        };
-       typedef __gnu_cxx::hash_map<const ld::Atom*, IndirectBindingSlot, ReferencesHashFuncs, ReferencesHashFuncs> ReferencesToSlot;
+       typedef std::unordered_map<const ld::Atom*, IndirectBindingSlot, ReferencesHashFuncs, ReferencesHashFuncs> ReferencesToSlot;
 
        class CStringHashFuncs {
        public:
                size_t  operator()(const ld::Atom*) const;
                bool    operator()(const ld::Atom* left, const ld::Atom* right) const;
        };
-       typedef __gnu_cxx::hash_map<const ld::Atom*, IndirectBindingSlot, CStringHashFuncs, CStringHashFuncs> CStringToSlot;
+       typedef std::unordered_map<const ld::Atom*, IndirectBindingSlot, CStringHashFuncs, CStringHashFuncs> CStringToSlot;
 
        class UTF16StringHashFuncs {
        public:
                size_t  operator()(const ld::Atom*) const;
                bool    operator()(const ld::Atom* left, const ld::Atom* right) const;
        };
-       typedef __gnu_cxx::hash_map<const ld::Atom*, IndirectBindingSlot, UTF16StringHashFuncs, UTF16StringHashFuncs> UTF16StringToSlot;
+       typedef std::unordered_map<const ld::Atom*, IndirectBindingSlot, UTF16StringHashFuncs, UTF16StringHashFuncs> UTF16StringToSlot;
 
        typedef std::map<IndirectBindingSlot, const char*> SlotToName;
-       typedef __gnu_cxx::hash_map<const char*, CStringToSlot*, __gnu_cxx::hash<const char*>, CStringEquals> NameToMap;
+       typedef std::unordered_map<const char*, CStringToSlot*, CStringHash, CStringEquals> NameToMap;
+    
+    typedef std::vector<const ld::Atom *> DuplicatedSymbolAtomList;
+    typedef std::map<const char *, DuplicatedSymbolAtomList * > DuplicateSymbols;
        
 public:
 
@@ -121,22 +120,30 @@ public:
        unsigned int            updateCount()                                           { return _indirectBindingTable.size(); }
        void                            undefines(std::vector<const char*>& undefines);
        void                            tentativeDefs(std::vector<const char*>& undefines);
+       void                            removeDeadAtoms();
        bool                            hasName(const char* name);
        bool                            hasExternalTentativeDefinitions()       { return _hasExternalTentativeDefinitions; }
        byNameIterator          begin()                                                         { return byNameIterator(_byNameTable.begin(),_indirectBindingTable); }
        byNameIterator          end()                                                           { return byNameIterator(_byNameTable.end(),_indirectBindingTable); }
        void                            printStatistics();
-       static const char*              demangle(const char* sym);
        
        // from ld::IndirectBindingTable
        virtual const char*                     indirectName(IndirectBindingSlot slot) const;
        virtual const ld::Atom*         indirectAtom(IndirectBindingSlot slot) const;
+    
+    // Prints the duplicated symbols to stderr and throws. Only valid to call if hasDuplicateSymbols() returns true.
+    void                checkDuplicateSymbols() const;
+
 
 private:
        bool                                    addByName(const ld::Atom& atom, bool ignoreDuplicates);
        bool                                    addByContent(const ld::Atom& atom);
        bool                                    addByReferences(const ld::Atom& atom);
        void                                    markCoalescedAway(const ld::Atom* atom);
+    
+    // Tracks duplicated symbols. Each call adds file to the list of files defining symbol.
+    // The file list is uniqued per symbol, so calling multiple times for the same symbol/file pair is permitted.
+    void                    addDuplicateSymbol(const char *symbol, const ld::Atom* atom);
 
        const Options&                                  _options;
        NameToSlot                                              _byNameTable;
@@ -154,7 +161,7 @@ private:
        std::vector<const ld::Atom*>&   _indirectBindingTable;
        bool                                                    _hasExternalTentativeDefinitions;
        
-       static bool                                             _s_doDemangle;
+    DuplicateSymbols                _duplicateSymbols;
 
 };