1 // dwp.h -- general definitions for dwp.
3 // Copyright (C) 2012-2017 Free Software Foundation, Inc.
4 // Written by Cary Coutant <ccoutant@google.com>.
6 // This file is part of dwp, the DWARF packaging utility.
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the Free Software
20 // Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 // MA 02110-1301, USA.
33 #include <sys/types.h>
40 extern const char* program_name;
42 class General_options;
53 template<int size, bool big_endian>
56 // The size of a section if we are going to look at the contents.
57 typedef size_t section_size_type;
59 // An offset within a section when we are looking at the contents.
60 typedef ptrdiff_t section_offset_type;
63 is_prefix_of(const char* prefix, const char* str)
65 return strncmp(prefix, str, strlen(prefix)) == 0;
72 GOLD_OK = EXIT_SUCCESS,
73 GOLD_ERR = EXIT_FAILURE,
74 GOLD_FALLBACK = EXIT_FAILURE + 1
77 // This function is called to exit the program. Status is true to
78 // exit success (0) and false to exit failure (1).
80 gold_exit(Exit_status status) ATTRIBUTE_NORETURN;
82 // This function is called to emit an error message and then
83 // immediately exit with failure.
85 gold_fatal(const char* format, ...) ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF_1;
87 // This function is called to issue a warning.
89 gold_warning(const char* msg, ...) ATTRIBUTE_PRINTF_1;
91 // This function is called to print an informational message.
93 gold_info(const char* msg, ...) ATTRIBUTE_PRINTF_1;
95 #define gold_unreachable() \
96 (gold::do_gold_unreachable(__FILE__, __LINE__, \
97 static_cast<const char*>(__FUNCTION__)))
99 extern void do_gold_unreachable(const char*, int, const char*)
104 #define gold_assert(expr) ((void)(!(expr) ? gold_unreachable(), 0 : 0))
106 // Convert numeric types without unnoticed loss of precision.
107 template<typename To, typename From>
109 convert_types(const From from)
112 gold_assert(static_cast<From>(to) == from);
116 // A common case of convert_types<>: convert to section_size_type.
117 template<typename From>
118 inline section_size_type
119 convert_to_section_size_type(const From from)
120 { return convert_types<section_size_type, From>(from); }
122 }; // End namespace gold.
124 #endif // !defined(DWP_DWP_H)