dwp.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // dwp.h -- general definitions for dwp.
  2. // Copyright (C) 2012-2022 Free Software Foundation, Inc.
  3. // Written by Cary Coutant <ccoutant@google.com>.
  4. // This file is part of dwp, the DWARF packaging utility.
  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 DWP_DWP_H
  18. #define DWP_DWP_H 1
  19. #include "config.h"
  20. #include "ansidecl.h"
  21. #include <cstddef>
  22. #include <cstdlib>
  23. #include <cstring>
  24. #include <stdint.h>
  25. #include <sys/types.h>
  26. #include "system.h"
  27. namespace gold
  28. {
  29. extern const char* program_name;
  30. class General_options;
  31. class Command_line;
  32. class Dirsearch;
  33. class Input_objects;
  34. class Mapfile;
  35. class Symbol;
  36. class Symbol_table;
  37. class Layout;
  38. class Task;
  39. class Workqueue;
  40. class Output_file;
  41. template<int size, bool big_endian>
  42. struct Relocate_info;
  43. // The size of a section if we are going to look at the contents.
  44. typedef size_t section_size_type;
  45. // An offset within a section when we are looking at the contents.
  46. typedef ptrdiff_t section_offset_type;
  47. inline bool
  48. is_prefix_of(const char* prefix, const char* str)
  49. {
  50. return strncmp(prefix, str, strlen(prefix)) == 0;
  51. }
  52. // Exit status codes.
  53. enum Exit_status
  54. {
  55. GOLD_OK = EXIT_SUCCESS,
  56. GOLD_ERR = EXIT_FAILURE,
  57. GOLD_FALLBACK = EXIT_FAILURE + 1
  58. };
  59. // This function is called to exit the program. Status is true to
  60. // exit success (0) and false to exit failure (1).
  61. extern void
  62. gold_exit(Exit_status status) ATTRIBUTE_NORETURN;
  63. // This function is called to emit an error message and then
  64. // immediately exit with failure.
  65. extern void
  66. gold_fatal(const char* format, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1;
  67. // This function is called to issue a warning.
  68. extern void
  69. gold_warning(const char* msg, ...) ATTRIBUTE_PRINTF_1;
  70. // This function is called to print an informational message.
  71. extern void
  72. gold_info(const char* msg, ...) ATTRIBUTE_PRINTF_1;
  73. #define gold_unreachable() \
  74. (gold::do_gold_unreachable(__FILE__, __LINE__, \
  75. static_cast<const char*>(__FUNCTION__)))
  76. extern void do_gold_unreachable(const char*, int, const char*)
  77. ATTRIBUTE_NORETURN;
  78. // Assertion check.
  79. #define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0))
  80. // Convert numeric types without unnoticed loss of precision.
  81. template<typename To, typename From>
  82. inline To
  83. convert_types(const From from)
  84. {
  85. To to = from;
  86. gold_assert(static_cast<From>(to) == from);
  87. return to;
  88. }
  89. // A common case of convert_types<>: convert to section_size_type.
  90. template<typename From>
  91. inline section_size_type
  92. convert_to_section_size_type(const From from)
  93. { return convert_types<section_size_type, From>(from); }
  94. }; // End namespace gold.
  95. #endif // !defined(DWP_DWP_H)