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