ld.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /* ld.h -- general linker header file
  2. Copyright (C) 1991-2022 Free Software Foundation, Inc.
  3. This file is part of the GNU Binutils.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  15. MA 02110-1301, USA. */
  16. #ifndef LD_H
  17. #define LD_H
  18. #ifndef SEEK_CUR
  19. #define SEEK_CUR 1
  20. #endif
  21. #ifndef SEEK_END
  22. #define SEEK_END 2
  23. #endif
  24. #ifndef ENABLE_NLS
  25. /* The Solaris version of locale.h always includes libintl.h. If we have
  26. been configured with --disable-nls then ENABLE_NLS will not be defined
  27. and the dummy definitions of bindtextdomain (et al) below will conflict
  28. with the defintions in libintl.h. So we define these values to prevent
  29. the bogus inclusion of libintl.h. */
  30. # define _LIBINTL_H
  31. # define _LIBGETTEXT_H
  32. #endif
  33. #include <locale.h>
  34. #ifdef ENABLE_NLS
  35. # include <libintl.h>
  36. # define _(String) gettext (String)
  37. # ifdef gettext_noop
  38. # define N_(String) gettext_noop (String)
  39. # else
  40. # define N_(String) (String)
  41. # endif
  42. #else
  43. # define gettext(Msgid) (Msgid)
  44. # define dgettext(Domainname, Msgid) (Msgid)
  45. # define dcgettext(Domainname, Msgid, Category) (Msgid)
  46. # define ngettext(Msgid1, Msgid2, n) \
  47. (n == 1 ? Msgid1 : Msgid2)
  48. # define dngettext(Domainname, Msgid1, Msgid2, n) \
  49. (n == 1 ? Msgid1 : Msgid2)
  50. # define dcngettext(Domainname, Msgid1, Msgid2, n, Category) \
  51. (n == 1 ? Msgid1 : Msgid2)
  52. # define textdomain(Domainname) do {} while (0)
  53. # define bindtextdomain(Domainname, Dirname) do {} while (0)
  54. # define _(String) (String)
  55. # define N_(String) (String)
  56. #endif
  57. /* Look in this environment name for the linker to pretend to be */
  58. #define EMULATION_ENVIRON "LDEMULATION"
  59. /* If in there look for the strings: */
  60. /* Look in this variable for a target format */
  61. #define TARGET_ENVIRON "GNUTARGET"
  62. /* Input sections which are put in a section of this name are actually
  63. discarded. */
  64. #define DISCARD_SECTION_NAME "/DISCARD/"
  65. /* A file name list. */
  66. typedef struct name_list
  67. {
  68. const char *name;
  69. struct name_list *next;
  70. }
  71. name_list;
  72. typedef enum {sort_none, sort_ascending, sort_descending} sort_order;
  73. /* A wildcard specification. */
  74. typedef enum
  75. {
  76. none, by_name, by_alignment, by_name_alignment, by_alignment_name,
  77. by_none, by_init_priority
  78. } sort_type;
  79. extern sort_type sort_section;
  80. struct wildcard_spec
  81. {
  82. const char *name;
  83. struct name_list *exclude_name_list;
  84. sort_type sorted;
  85. struct flag_info *section_flag_list;
  86. };
  87. struct wildcard_list
  88. {
  89. struct wildcard_list *next;
  90. struct wildcard_spec spec;
  91. };
  92. #define BYTE_SIZE (1)
  93. #define SHORT_SIZE (2)
  94. #define LONG_SIZE (4)
  95. #define QUAD_SIZE (8)
  96. enum endian_enum { ENDIAN_UNSET = 0, ENDIAN_BIG, ENDIAN_LITTLE };
  97. typedef struct
  98. {
  99. /* 1 => assign space to common symbols even if `relocatable_output'. */
  100. bool force_common_definition;
  101. /* If TRUE, build MIPS embedded PIC relocation tables in the output
  102. file. */
  103. bool embedded_relocs;
  104. /* If TRUE, force generation of a file with a .exe file. */
  105. bool force_exe_suffix;
  106. /* If TRUE, generate a cross reference report. */
  107. bool cref;
  108. /* If TRUE (which is the default), warn about mismatched input
  109. files. */
  110. bool warn_mismatch;
  111. /* Warn on attempting to open an incompatible library during a library
  112. search. */
  113. bool warn_search_mismatch;
  114. /* If non-zero check section addresses, once computed,
  115. for overlaps. Relocatable links only check when this is > 0. */
  116. signed char check_section_addresses;
  117. /* If TRUE allow the linking of input files in an unknown architecture
  118. assuming that the user knows what they are doing. This was the old
  119. behaviour of the linker. The new default behaviour is to reject such
  120. input files. */
  121. bool accept_unknown_input_arch;
  122. /* Name of the import library to generate. */
  123. char *out_implib_filename;
  124. /* If TRUE we'll just print the default output on stdout. */
  125. bool print_output_format;
  126. /* If set, display the target memory usage (per memory region). */
  127. bool print_memory_usage;
  128. /* Should we force section groups to be resolved? Controlled with
  129. --force-group-allocation on the command line or FORCE_GROUP_ALLOCATION
  130. in the linker script. */
  131. bool force_group_allocation;
  132. /* Big or little endian as set on command line. */
  133. enum endian_enum endian;
  134. /* Name of runtime interpreter to invoke. */
  135. char *interpreter;
  136. /* Name to give runtime library from the -soname argument. */
  137. char *soname;
  138. /* Runtime library search path from the -rpath argument. */
  139. char *rpath;
  140. /* Link time runtime library search path from the -rpath-link
  141. argument. */
  142. char *rpath_link;
  143. /* Name of shared object whose symbol table should be filtered with
  144. this shared object. From the --filter option. */
  145. char *filter_shlib;
  146. /* Name of shared object for whose symbol table this shared object
  147. is an auxiliary filter. From the --auxiliary option. */
  148. char **auxiliary_filters;
  149. /* A version symbol to be applied to the symbol names found in the
  150. .exports sections. */
  151. char *version_exports_section;
  152. /* Default linker script. */
  153. char *default_script;
  154. } args_type;
  155. extern args_type command_line;
  156. typedef int token_code_type;
  157. /* Different ways we can handle orphan sections. */
  158. enum orphan_handling_enum
  159. {
  160. /* The classic strategy, find a suitable section to place the orphan
  161. into. */
  162. orphan_handling_place = 0,
  163. /* Discard any orphan sections as though they were assign to the section
  164. /DISCARD/. */
  165. orphan_handling_discard,
  166. /* Find somewhere to place the orphan section, as with
  167. ORPHAN_HANDLING_PLACE, but also issue a warning. */
  168. orphan_handling_warn,
  169. /* Issue a fatal error if any orphan sections are found. */
  170. orphan_handling_error,
  171. };
  172. typedef struct
  173. {
  174. bool magic_demand_paged;
  175. bool make_executable;
  176. /* If TRUE, -shared is supported. */
  177. /* ??? A better way to do this is perhaps to define this in the
  178. ld_emulation_xfer_struct since this is really a target dependent
  179. parameter. */
  180. bool has_shared;
  181. /* If TRUE, build constructors. */
  182. bool build_constructors;
  183. /* If TRUE, warn about any constructors. */
  184. bool warn_constructors;
  185. /* If TRUE, warn about merging common symbols with others. */
  186. bool warn_common;
  187. /* If TRUE, only warn once about a particular undefined symbol. */
  188. bool warn_once;
  189. /* How should we deal with orphan sections. */
  190. enum orphan_handling_enum orphan_handling;
  191. /* If TRUE, warn if multiple global-pointers are needed (Alpha
  192. only). */
  193. bool warn_multiple_gp;
  194. /* If TRUE, warn if the starting address of an output section
  195. changes due to the alignment of an input section. */
  196. bool warn_section_align;
  197. /* If TRUE, warning messages are fatal */
  198. bool fatal_warnings;
  199. sort_order sort_common;
  200. bool text_read_only;
  201. bool stats;
  202. /* If set, orphan input sections will be mapped to separate output
  203. sections. */
  204. bool unique_orphan_sections;
  205. /* If set, only search library directories explicitly selected
  206. on the command line. */
  207. bool only_cmd_line_lib_dirs;
  208. /* If set, numbers and absolute symbols are simply treated as
  209. numbers everywhere. */
  210. bool sane_expr;
  211. /* If set, code and non-code sections should never be in one segment. */
  212. bool separate_code;
  213. /* The rpath separation character. Usually ':'. */
  214. char rpath_separator;
  215. char *map_filename;
  216. FILE *map_file;
  217. char *dependency_file;
  218. unsigned int split_by_reloc;
  219. bfd_size_type split_by_file;
  220. /* The size of the hash table to use. */
  221. unsigned long hash_table_size;
  222. /* If set, print discarded sections in map file output. */
  223. bool print_map_discarded;
  224. /* If set, emit the names and types of statically-linked variables
  225. into the CTF. */
  226. bool ctf_variables;
  227. /* If set, share only duplicated types in CTF, rather than sharing
  228. all types that are not in conflict. */
  229. bool ctf_share_duplicated;
  230. } ld_config_type;
  231. extern ld_config_type config;
  232. extern FILE * saved_script_handle;
  233. extern bool force_make_executable;
  234. extern int yyparse (void);
  235. extern void add_cref (const char *, bfd *, asection *, bfd_vma);
  236. extern bool handle_asneeded_cref (bfd *, enum notice_asneeded_action);
  237. extern void output_cref (FILE *);
  238. extern void check_nocrossrefs (void);
  239. extern void ld_abort (const char *, int, const char *) ATTRIBUTE_NORETURN;
  240. /* If gcc >= 2.6, we can give a function name, too. */
  241. #if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 6)
  242. #define __PRETTY_FUNCTION__ NULL
  243. #endif
  244. #undef abort
  245. #define abort() ld_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
  246. #endif