parameters.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. // parameters.h -- general parameters for a link using gold -*- C++ -*-
  2. // Copyright (C) 2006-2022 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 GOLD_PARAMETERS_H
  18. #define GOLD_PARAMETERS_H
  19. namespace gold
  20. {
  21. class General_options;
  22. class Errors;
  23. class Timer;
  24. class Target;
  25. template<int size, bool big_endian>
  26. class Sized_target;
  27. class Set_parameters_target_once;
  28. // Here we define the Parameters class which simply holds simple
  29. // general parameters which apply to the entire link. We use a global
  30. // variable for this. The parameters class holds three types of data:
  31. // 1) An Errors struct. Any part of the code that wants to log an
  32. // error can use parameters->errors().
  33. // 2) A const General_options. These are the options as read on
  34. // the commandline.
  35. // 3) Target information, such as size and endian-ness. This is
  36. // available as soon as we've decided on the Target (after
  37. // parsing the first .o file).
  38. // 4) Whether we're doing a static link or not. This is set
  39. // after all inputs have been read and we know if any is a
  40. // dynamic library.
  41. class Parameters
  42. {
  43. public:
  44. Parameters();
  45. // These should be called as soon as they are known.
  46. void
  47. set_errors(Errors* errors);
  48. void
  49. set_timer(Timer* timer);
  50. void
  51. set_options(const General_options* options);
  52. void
  53. set_target(Target* target);
  54. void
  55. set_doing_static_link(bool doing_static_link);
  56. // Return the error object.
  57. Errors*
  58. errors() const
  59. { return this->errors_; }
  60. // Return the timer object.
  61. Timer*
  62. timer() const
  63. { return this->timer_; }
  64. // Whether the options are valid. This should not normally be
  65. // called, but it is needed by gold_exit.
  66. bool
  67. options_valid() const
  68. { return this->options_ != NULL; }
  69. // Return the options object.
  70. const General_options&
  71. options() const
  72. {
  73. gold_assert(this->options_valid());
  74. return *this->options_;
  75. }
  76. // Return whether the target field has been set.
  77. bool
  78. target_valid() const
  79. { return this->target_ != NULL; }
  80. // The target of the output file we are generating.
  81. const Target&
  82. target() const
  83. {
  84. gold_assert(this->target_valid());
  85. return *this->target_;
  86. }
  87. // The Sized_target of the output file. The caller must request the
  88. // right size and endianness.
  89. template<int size, bool big_endian>
  90. Sized_target<size, big_endian>*
  91. sized_target() const
  92. {
  93. gold_assert(this->target_valid());
  94. return static_cast<Sized_target<size, big_endian>*>(this->target_);
  95. }
  96. // Clear the target, for testing.
  97. void
  98. clear_target();
  99. // Return true if TARGET is compatible with the current target.
  100. bool
  101. is_compatible_target(const Target*) const;
  102. bool
  103. doing_static_link() const
  104. {
  105. gold_assert(this->doing_static_link_valid_);
  106. return this->doing_static_link_;
  107. }
  108. // This is just a copy of options().debug(). We make a copy so we
  109. // don't have to #include options.h in order to inline
  110. // is_debugging_enabled, below.
  111. int
  112. debug() const
  113. {
  114. // This can be called before the options are set up.
  115. if (!this->options_valid())
  116. return 0;
  117. return debug_;
  118. }
  119. // Return the name of the entry symbol.
  120. const char*
  121. entry() const;
  122. // A convenience routine for combining size and endianness. It also
  123. // checks the HAVE_TARGET_FOO configure options and dies if the
  124. // current target's size/endianness is not supported according to
  125. // HAVE_TARGET_FOO. Otherwise it returns this enum
  126. enum Target_size_endianness
  127. { TARGET_32_LITTLE, TARGET_32_BIG, TARGET_64_LITTLE, TARGET_64_BIG };
  128. Target_size_endianness
  129. size_and_endianness() const;
  130. // Set the incremental linking mode to INCREMENTAL_FULL. Used when
  131. // the linker determines that an incremental update is not possible.
  132. // Returns false if the incremental mode was INCREMENTAL_UPDATE,
  133. // indicating that the linker should exit if an update is not possible.
  134. bool
  135. set_incremental_full();
  136. // Return true if we need to prepare incremental linking information.
  137. bool
  138. incremental() const;
  139. // Return true if we are doing a full incremental link.
  140. bool
  141. incremental_full() const;
  142. // Return true if we are doing an incremental update.
  143. bool
  144. incremental_update() const;
  145. private:
  146. void
  147. set_target_once(Target*);
  148. void
  149. check_target_endianness();
  150. void
  151. check_rodata_segment();
  152. friend class Set_parameters_target_once;
  153. Errors* errors_;
  154. Timer* timer_;
  155. const General_options* options_;
  156. Target* target_;
  157. bool doing_static_link_valid_;
  158. bool doing_static_link_;
  159. int debug_;
  160. int incremental_mode_;
  161. Set_parameters_target_once* set_parameters_target_once_;
  162. };
  163. // This is a global variable.
  164. extern const Parameters* parameters;
  165. // We use free functions for these since they affect a global variable
  166. // that is internal to parameters.cc.
  167. extern void
  168. set_parameters_errors(Errors* errors);
  169. extern void
  170. set_parameters_timer(Timer* timer);
  171. extern void
  172. set_parameters_options(const General_options* options);
  173. extern void
  174. set_parameters_target(Target* target);
  175. extern void
  176. set_parameters_doing_static_link(bool doing_static_link);
  177. extern bool
  178. set_parameters_incremental_full();
  179. // Ensure that the target to be valid by using the default target if
  180. // necessary.
  181. extern void
  182. parameters_force_valid_target();
  183. // Clear the current target, for testing.
  184. extern void
  185. parameters_clear_target();
  186. // Return whether we are doing a particular debugging type. The
  187. // argument is one of the flags from debug.h.
  188. inline bool
  189. is_debugging_enabled(unsigned int type)
  190. { return (parameters->debug() & type) != 0; }
  191. } // End namespace gold.
  192. #endif // !defined(GOLD_PARAMETERS_H)