system.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. // system.h -- general definitions for gold -*- C++ -*-
  2. // Copyright (C) 2006-2015 Free Software Foundation, Inc.
  3. // Written by Ian Lance Taylor <iant@google.com>.
  4. // This file is part of gold.
  5. // This program is free software; you can redistribute it and/or modify
  6. // it under the terms of the GNU General Public License as published by
  7. // the Free Software Foundation; either version 3 of the License, or
  8. // (at your option) any later version.
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. // MA 02110-1301, USA.
  17. #ifndef SYSTEM_H
  18. #define SYSTEM_H 1
  19. #ifndef ENABLE_NLS
  20. // The Solaris version of locale.h always includes libintl.h. If we
  21. // have been configured with --disable-nls then ENABLE_NLS will not
  22. // be defined and the dummy definitions of bindtextdomain (et al)
  23. // below will conflict with the definitions in libintl.h. So we
  24. // define these values to prevent the bogus inclusion of libintl.h.
  25. # define _LIBINTL_H
  26. # define _LIBGETTEXT_H
  27. #endif
  28. #ifdef ENABLE_NLS
  29. // On some systems, things go awry when <libintl.h> comes after <clocale>.
  30. # include <libintl.h>
  31. # include <clocale>
  32. # define _(String) gettext (String)
  33. # ifdef gettext_noop
  34. # define N_(String) gettext_noop (String)
  35. # else
  36. # define N_(String) (String)
  37. # endif
  38. #else
  39. // Include <clocale> first to avoid conflicts with these macros.
  40. # include <clocale>
  41. # define gettext(Msgid) (Msgid)
  42. # define dgettext(Domainname, Msgid) (Msgid)
  43. # define dcgettext(Domainname, Msgid, Category) (Msgid)
  44. # define textdomain(Domainname) do {} while (0) /* nothing */
  45. # define bindtextdomain(Domainname, Dirname) do {} while (0) /* nothing */
  46. # define _(String) (String)
  47. # define N_(String) (String)
  48. #endif
  49. // Figure out how to get a hash set and a hash map.
  50. #if defined(HAVE_UNORDERED_SET) && defined(HAVE_UNORDERED_MAP)
  51. #include <unordered_set>
  52. #include <unordered_map>
  53. // We need a template typedef here.
  54. #define Unordered_set std::unordered_set
  55. #define Unordered_map std::unordered_map
  56. #define Unordered_multimap std::unordered_multimap
  57. #define reserve_unordered_map(map, n) ((map)->rehash(n))
  58. #elif defined(HAVE_TR1_UNORDERED_SET) && defined(HAVE_TR1_UNORDERED_MAP) \
  59. && defined(HAVE_TR1_UNORDERED_MAP_REHASH)
  60. #include <tr1/unordered_set>
  61. #include <tr1/unordered_map>
  62. // We need a template typedef here.
  63. #define Unordered_set std::tr1::unordered_set
  64. #define Unordered_map std::tr1::unordered_map
  65. #define Unordered_multimap std::tr1::unordered_multimap
  66. #define reserve_unordered_map(map, n) ((map)->rehash(n))
  67. #ifndef HAVE_TR1_HASH_OFF_T
  68. // The library does not support hashes of off_t values. Add support
  69. // here. This is likely to be specific to libstdc++. This issue
  70. // arises with GCC 4.1.x when compiling in 32-bit mode with a 64-bit
  71. // off_t type.
  72. namespace std { namespace tr1 {
  73. template<>
  74. struct hash<off_t> : public std::unary_function<off_t, std::size_t>
  75. {
  76. std::size_t
  77. operator()(off_t val) const
  78. { return static_cast<std::size_t>(val); }
  79. };
  80. } } // Close namespaces.
  81. #endif // !defined(HAVE_TR1_HASH_OFF_T)
  82. #elif defined(HAVE_EXT_HASH_MAP) && defined(HAVE_EXT_HASH_SET)
  83. #include <ext/hash_map>
  84. #include <ext/hash_set>
  85. #include <string>
  86. #define Unordered_set __gnu_cxx::hash_set
  87. #define Unordered_map __gnu_cxx::hash_map
  88. #define Unordered_multimap __gnu_cxx::hash_multimap
  89. namespace __gnu_cxx
  90. {
  91. template<>
  92. struct hash<std::string>
  93. {
  94. size_t
  95. operator()(std::string s) const
  96. { return __stl_hash_string(s.c_str()); }
  97. };
  98. template<typename T>
  99. struct hash<T*>
  100. {
  101. size_t
  102. operator()(T* p) const
  103. { return reinterpret_cast<size_t>(p); }
  104. };
  105. }
  106. #define reserve_unordered_map(map, n) ((map)->resize(n))
  107. #else
  108. // The fallback is to just use set and map.
  109. #include <set>
  110. #include <map>
  111. #define Unordered_set std::set
  112. #define Unordered_map std::map
  113. #define Unordered_multimap std::multimap
  114. #define reserve_unordered_map(map, n)
  115. #endif
  116. #ifndef HAVE_PREAD
  117. extern "C" ssize_t pread(int, void*, size_t, off_t);
  118. #endif
  119. #ifndef HAVE_FTRUNCATE
  120. extern "C" int ftruncate(int, off_t);
  121. #endif
  122. #ifndef HAVE_FFSLL
  123. extern "C" int ffsll(long long);
  124. #endif
  125. #if !HAVE_DECL_MEMMEM
  126. extern "C" void *memmem(const void *, size_t, const void *, size_t);
  127. #endif
  128. #if !HAVE_DECL_STRNDUP
  129. extern "C" char *strndup(const char *, size_t);
  130. #endif
  131. #endif // !defined(SYSTEM_H)