// gold.h -- general definitions for gold -*- C++ -*-
-// Copyright 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
+// Copyright 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
// Written by Ian Lance Taylor <iant@google.com>.
// This file is part of gold.
#define Unordered_set std::set
#define Unordered_map std::map
-#define Unordered_map std::multimap
+#define Unordered_multimap std::multimap
#define reserve_unordered_map(map, n)
return strncmp(prefix, str, strlen(prefix)) == 0;
}
+const char* const cident_section_start_prefix = "__start_";
+const char* const cident_section_stop_prefix = "__stop_";
+
+// Returns true if the name is a valid C identifier
+inline bool
+is_cident(const char* name)
+{
+ return (name[strspn(name,
+ ("0123456789"
+ "ABCDEFGHIJKLMNOPWRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "_"))]
+ == '\0');
+}
+
+// We sometimes need to hash strings. Ideally we should use std::tr1::hash or
+// __gnu_cxx::hash on some systems but there is no guarantee that either
+// one is available. For portability, we define simple string hash functions.
+
+template<typename Char_type>
+inline size_t
+string_hash(const Char_type* s, size_t length)
+{
+ // This is the hash function used by the dynamic linker for
+ // DT_GNU_HASH entries. I compared this to a Fowler/Noll/Vo hash
+ // for a C++ program with 385,775 global symbols. This hash
+ // function was very slightly worse. However, it is much faster to
+ // compute. Overall wall clock time was a win.
+ const unsigned char* p = reinterpret_cast<const unsigned char*>(s);
+ size_t h = 5381;
+ for (size_t i = 0; i < length * sizeof(Char_type); ++i)
+ h = h * 33 + *p++;
+ return h;
+}
+
+// Same as above except we expect the string to be zero terminated.
+
+template<typename Char_type>
+inline size_t
+string_hash(const Char_type* s)
+{
+ const unsigned char* p = reinterpret_cast<const unsigned char*>(s);
+ size_t h = 5381;
+ for (size_t i = 0; s[i] != 0; ++i)
+ {
+ for (size_t j = 0; j < sizeof(Char_type); j++)
+ h = h * 33 + *p++;
+ }
+
+ return h;
+}
+
+// Return whether STRING contains a wildcard character. This is used
+// to speed up matching.
+
+inline bool
+is_wildcard_string(const char* s)
+{
+ return strpbrk(s, "?*[") != NULL;
+}
+
} // End namespace gold.
#endif // !defined(GOLD_GOLD_H)