Add output_type to bfd_link_info
[deliverable/binutils-gdb.git] / ld / lexsup.c
1 /* Parse options for the GNU linker.
2 Copyright (C) 1991-2015 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 #include "sysdep.h"
22 #include "bfd.h"
23 #include "bfdver.h"
24 #include "libiberty.h"
25 #include <stdio.h>
26 #include <string.h>
27 #include "safe-ctype.h"
28 #include "getopt.h"
29 #include "bfdlink.h"
30 #include "ld.h"
31 #include "ldmain.h"
32 #include "ldmisc.h"
33 #include "ldexp.h"
34 #include "ldlang.h"
35 #include <ldgram.h>
36 #include "ldlex.h"
37 #include "ldfile.h"
38 #include "ldver.h"
39 #include "ldemul.h"
40 #include "demangle.h"
41 #ifdef ENABLE_PLUGINS
42 #include "plugin.h"
43 #endif /* ENABLE_PLUGINS */
44
45 #ifndef PATH_SEPARATOR
46 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
47 #define PATH_SEPARATOR ';'
48 #else
49 #define PATH_SEPARATOR ':'
50 #endif
51 #endif
52
53 /* Somewhere above, sys/stat.h got included . . . . */
54 #if !defined(S_ISDIR) && defined(S_IFDIR)
55 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
56 #endif
57
58 static void set_default_dirlist (char *);
59 static void set_section_start (char *, char *);
60 static void set_segment_start (const char *, char *);
61 static void help (void);
62
63 /* The long options. This structure is used for both the option
64 parsing and the help text. */
65
66 enum control_enum {
67 /* Use one dash before long option name. */
68 ONE_DASH,
69 /* Use two dashes before long option name. */
70 TWO_DASHES,
71 /* Only accept two dashes before the long option name.
72 This is an overloading of the use of this enum, since originally it
73 was only intended to tell the --help display function how to display
74 the long option name. This feature was added in order to resolve
75 the confusion about the -omagic command line switch. Is it setting
76 the output file name to "magic" or is it setting the NMAGIC flag on
77 the output ? It has been decided that it is setting the output file
78 name, and that if you want to set the NMAGIC flag you should use -N
79 or --omagic. */
80 EXACTLY_TWO_DASHES,
81 /* Don't mention this option in --help output. */
82 NO_HELP
83 };
84
85 struct ld_option
86 {
87 /* The long option information. */
88 struct option opt;
89 /* The short option with the same meaning ('\0' if none). */
90 char shortopt;
91 /* The name of the argument (NULL if none). */
92 const char *arg;
93 /* The documentation string. If this is NULL, this is a synonym for
94 the previous option. */
95 const char *doc;
96 enum control_enum control;
97 };
98
99 static const struct ld_option ld_options[] =
100 {
101 { {NULL, required_argument, NULL, '\0'},
102 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
103 ONE_DASH },
104 { {"architecture", required_argument, NULL, 'A'},
105 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES },
106 { {"format", required_argument, NULL, 'b'},
107 'b', N_("TARGET"), N_("Specify target for following input files"),
108 TWO_DASHES },
109 { {"mri-script", required_argument, NULL, 'c'},
110 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES },
111 { {"dc", no_argument, NULL, 'd'},
112 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
113 { {"dp", no_argument, NULL, 'd'},
114 '\0', NULL, NULL, ONE_DASH },
115 { {"entry", required_argument, NULL, 'e'},
116 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
117 { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
118 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES },
119 { {"no-export-dynamic", no_argument, NULL, OPTION_NO_EXPORT_DYNAMIC},
120 '\0', NULL, N_("Undo the effect of --export-dynamic"), TWO_DASHES },
121 { {"EB", no_argument, NULL, OPTION_EB},
122 '\0', NULL, N_("Link big-endian objects"), ONE_DASH },
123 { {"EL", no_argument, NULL, OPTION_EL},
124 '\0', NULL, N_("Link little-endian objects"), ONE_DASH },
125 { {"auxiliary", required_argument, NULL, 'f'},
126 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
127 TWO_DASHES },
128 { {"filter", required_argument, NULL, 'F'},
129 'F', N_("SHLIB"), N_("Filter for shared object symbol table"),
130 TWO_DASHES },
131 { {NULL, no_argument, NULL, '\0'},
132 'g', NULL, N_("Ignored"), ONE_DASH },
133 { {"gpsize", required_argument, NULL, 'G'},
134 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
135 TWO_DASHES },
136 { {"soname", required_argument, NULL, OPTION_SONAME},
137 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH },
138 { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
139 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"),
140 TWO_DASHES },
141 { {"library", required_argument, NULL, 'l'},
142 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES },
143 { {"library-path", required_argument, NULL, 'L'},
144 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"),
145 TWO_DASHES },
146 { {"sysroot=<DIRECTORY>", required_argument, NULL, OPTION_SYSROOT},
147 '\0', NULL, N_("Override the default sysroot location"), TWO_DASHES },
148 { {NULL, required_argument, NULL, '\0'},
149 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH },
150 { {"print-map", no_argument, NULL, 'M'},
151 'M', NULL, N_("Print map file on standard output"), TWO_DASHES },
152 { {"nmagic", no_argument, NULL, 'n'},
153 'n', NULL, N_("Do not page align data"), TWO_DASHES },
154 { {"omagic", no_argument, NULL, 'N'},
155 'N', NULL, N_("Do not page align data, do not make text readonly"),
156 EXACTLY_TWO_DASHES },
157 { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC},
158 '\0', NULL, N_("Page align data, make text readonly"),
159 EXACTLY_TWO_DASHES },
160 { {"output", required_argument, NULL, 'o'},
161 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES },
162 { {NULL, required_argument, NULL, '\0'},
163 'O', NULL, N_("Optimize output file"), ONE_DASH },
164 #ifdef ENABLE_PLUGINS
165 { {"plugin", required_argument, NULL, OPTION_PLUGIN},
166 '\0', N_("PLUGIN"), N_("Load named plugin"), ONE_DASH },
167 { {"plugin-opt", required_argument, NULL, OPTION_PLUGIN_OPT},
168 '\0', N_("ARG"), N_("Send arg to last-loaded plugin"), ONE_DASH },
169 { {"flto", optional_argument, NULL, OPTION_IGNORE},
170 '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
171 ONE_DASH },
172 { {"flto-partition=", required_argument, NULL, OPTION_IGNORE},
173 '\0', NULL, N_("Ignored for GCC LTO option compatibility"),
174 ONE_DASH },
175 #endif /* ENABLE_PLUGINS */
176 { {"fuse-ld=", required_argument, NULL, OPTION_IGNORE},
177 '\0', NULL, N_("Ignored for GCC linker option compatibility"),
178 ONE_DASH },
179 { {"map-whole-files", optional_argument, NULL, OPTION_IGNORE},
180 '\0', NULL, N_("Ignored for gold option compatibility"),
181 TWO_DASHES },
182 { {"no-map-whole-files", optional_argument, NULL, OPTION_IGNORE},
183 '\0', NULL, N_("Ignored for gold option compatibility"),
184 TWO_DASHES },
185 { {"Qy", no_argument, NULL, OPTION_IGNORE},
186 '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH },
187 { {"emit-relocs", no_argument, NULL, 'q'},
188 'q', NULL, "Generate relocations in final output", TWO_DASHES },
189 { {"relocatable", no_argument, NULL, 'r'},
190 'r', NULL, N_("Generate relocatable output"), TWO_DASHES },
191 { {NULL, no_argument, NULL, '\0'},
192 'i', NULL, NULL, ONE_DASH },
193 { {"just-symbols", required_argument, NULL, 'R'},
194 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
195 TWO_DASHES },
196 { {"strip-all", no_argument, NULL, 's'},
197 's', NULL, N_("Strip all symbols"), TWO_DASHES },
198 { {"strip-debug", no_argument, NULL, 'S'},
199 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES },
200 { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED},
201 '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES },
202 { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED},
203 '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES },
204 { {"trace", no_argument, NULL, 't'},
205 't', NULL, N_("Trace file opens"), TWO_DASHES },
206 { {"script", required_argument, NULL, 'T'},
207 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
208 { {"default-script", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
209 '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES },
210 { {"dT", required_argument, NULL, OPTION_DEFAULT_SCRIPT},
211 '\0', NULL, NULL, ONE_DASH },
212 { {"undefined", required_argument, NULL, 'u'},
213 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"),
214 TWO_DASHES },
215 { {"require-defined", required_argument, NULL, OPTION_REQUIRE_DEFINED_SYMBOL},
216 '\0', N_("SYMBOL"), N_("Require SYMBOL be defined in the final output"),
217 TWO_DASHES },
218 { {"unique", optional_argument, NULL, OPTION_UNIQUE},
219 '\0', N_("[=SECTION]"),
220 N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES },
221 { {"Ur", no_argument, NULL, OPTION_UR},
222 '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH },
223 { {"version", no_argument, NULL, OPTION_VERSION},
224 'v', NULL, N_("Print version information"), TWO_DASHES },
225 { {NULL, no_argument, NULL, '\0'},
226 'V', NULL, N_("Print version and emulation information"), ONE_DASH },
227 { {"discard-all", no_argument, NULL, 'x'},
228 'x', NULL, N_("Discard all local symbols"), TWO_DASHES },
229 { {"discard-locals", no_argument, NULL, 'X'},
230 'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES },
231 { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE},
232 '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES },
233 { {"trace-symbol", required_argument, NULL, 'y'},
234 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES },
235 { {NULL, required_argument, NULL, '\0'},
236 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"),
237 ONE_DASH },
238 { {"start-group", no_argument, NULL, '('},
239 '(', NULL, N_("Start a group"), TWO_DASHES },
240 { {"end-group", no_argument, NULL, ')'},
241 ')', NULL, N_("End a group"), TWO_DASHES },
242 { {"accept-unknown-input-arch", no_argument, NULL,
243 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH},
244 '\0', NULL,
245 N_("Accept input files whose architecture cannot be determined"),
246 TWO_DASHES },
247 { {"no-accept-unknown-input-arch", no_argument, NULL,
248 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH},
249 '\0', NULL, N_("Reject input files whose architecture is unknown"),
250 TWO_DASHES },
251
252 /* The next two options are deprecated because of their similarity to
253 --as-needed and --no-as-needed. They have been replaced by
254 --copy-dt-needed-entries and --no-copy-dt-needed-entries. */
255 { {"add-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
256 '\0', NULL, NULL, NO_HELP },
257 { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
258 '\0', NULL, NULL, NO_HELP },
259
260 { {"as-needed", no_argument, NULL, OPTION_ADD_DT_NEEDED_FOR_REGULAR},
261 '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"),
262 TWO_DASHES },
263 { {"no-as-needed", no_argument, NULL, OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR},
264 '\0', NULL, N_("Always set DT_NEEDED for dynamic libraries mentioned on\n"
265 " the command line"),
266 TWO_DASHES },
267 { {"assert", required_argument, NULL, OPTION_ASSERT},
268 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
269 { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
270 '\0', NULL, N_("Link against shared libraries"), ONE_DASH },
271 { {"dy", no_argument, NULL, OPTION_CALL_SHARED},
272 '\0', NULL, NULL, ONE_DASH },
273 { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
274 '\0', NULL, NULL, ONE_DASH },
275 { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
276 '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH },
277 { {"dn", no_argument, NULL, OPTION_NON_SHARED},
278 '\0', NULL, NULL, ONE_DASH },
279 { {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
280 '\0', NULL, NULL, ONE_DASH },
281 { {"static", no_argument, NULL, OPTION_NON_SHARED},
282 '\0', NULL, NULL, ONE_DASH },
283 { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
284 '\0', NULL, N_("Bind global references locally"), ONE_DASH },
285 { {"Bsymbolic-functions", no_argument, NULL, OPTION_SYMBOLIC_FUNCTIONS},
286 '\0', NULL, N_("Bind global function references locally"), ONE_DASH },
287 { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS},
288 '\0', NULL, N_("Check section addresses for overlaps (default)"),
289 TWO_DASHES },
290 { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS},
291 '\0', NULL, N_("Do not check section addresses for overlaps"),
292 TWO_DASHES },
293 { {"copy-dt-needed-entries", no_argument, NULL,
294 OPTION_ADD_DT_NEEDED_FOR_DYNAMIC},
295 '\0', NULL, N_("Copy DT_NEEDED links mentioned inside DSOs that follow"),
296 TWO_DASHES },
297 { {"no-copy-dt-needed-entries", no_argument, NULL,
298 OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC},
299 '\0', NULL, N_("Do not copy DT_NEEDED links mentioned inside DSOs that follow"),
300 TWO_DASHES },
301
302 { {"cref", no_argument, NULL, OPTION_CREF},
303 '\0', NULL, N_("Output cross reference table"), TWO_DASHES },
304 { {"defsym", required_argument, NULL, OPTION_DEFSYM},
305 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES },
306 { {"demangle", optional_argument, NULL, OPTION_DEMANGLE},
307 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"),
308 TWO_DASHES },
309 { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
310 '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES},
311 { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL},
312 '\0', NULL, N_("Treat warnings as errors"),
313 TWO_DASHES },
314 { {"no-fatal-warnings", no_argument, NULL, OPTION_NO_WARN_FATAL},
315 '\0', NULL, N_("Do not treat warnings as errors (default)"),
316 TWO_DASHES },
317 { {"fini", required_argument, NULL, OPTION_FINI},
318 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH },
319 { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX},
320 '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES},
321 { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS},
322 '\0', NULL, N_("Remove unused sections (on some targets)"),
323 TWO_DASHES },
324 { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
325 '\0', NULL, N_("Don't remove unused sections (default)"),
326 TWO_DASHES },
327 { {"print-gc-sections", no_argument, NULL, OPTION_PRINT_GC_SECTIONS},
328 '\0', NULL, N_("List removed unused sections on stderr"),
329 TWO_DASHES },
330 { {"no-print-gc-sections", no_argument, NULL, OPTION_NO_PRINT_GC_SECTIONS},
331 '\0', NULL, N_("Do not list removed unused sections"),
332 TWO_DASHES },
333 { {"hash-size=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE},
334 '\0', NULL, N_("Set default hash table size close to <NUMBER>"),
335 TWO_DASHES },
336 { {"help", no_argument, NULL, OPTION_HELP},
337 '\0', NULL, N_("Print option help"), TWO_DASHES },
338 { {"init", required_argument, NULL, OPTION_INIT},
339 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH },
340 { {"Map", required_argument, NULL, OPTION_MAP},
341 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH },
342 { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON},
343 '\0', NULL, N_("Do not define Common storage"), TWO_DASHES },
344 { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE },
345 '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES },
346 { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
347 '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES },
348 { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED},
349 '\0', NULL, N_("Do not allow unresolved references in object files"),
350 TWO_DASHES },
351 { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED},
352 '\0', NULL, N_("Allow unresolved references in shared libraries"),
353 TWO_DASHES },
354 { {"no-allow-shlib-undefined", no_argument, NULL,
355 OPTION_NO_ALLOW_SHLIB_UNDEFINED},
356 '\0', NULL, N_("Do not allow unresolved references in shared libs"),
357 TWO_DASHES },
358 { {"allow-multiple-definition", no_argument, NULL,
359 OPTION_ALLOW_MULTIPLE_DEFINITION},
360 '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES },
361 { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION},
362 '\0', NULL, N_("Disallow undefined version"), TWO_DASHES },
363 { {"default-symver", no_argument, NULL, OPTION_DEFAULT_SYMVER},
364 '\0', NULL, N_("Create default symbol version"), TWO_DASHES },
365 { {"default-imported-symver", no_argument, NULL,
366 OPTION_DEFAULT_IMPORTED_SYMVER},
367 '\0', NULL, N_("Create default symbol version for imported symbols"),
368 TWO_DASHES },
369 { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
370 '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
371 { {"no-warn-search-mismatch", no_argument, NULL,
372 OPTION_NO_WARN_SEARCH_MISMATCH},
373 '\0', NULL, N_("Don't warn on finding an incompatible library"),
374 TWO_DASHES},
375 { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
376 '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES },
377 { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
378 '\0', NULL, N_("Create an output file even if errors occur"),
379 TWO_DASHES },
380 { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
381 '\0', NULL, NULL, NO_HELP },
382 { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB},
383 '\0', NULL, N_("Only use library directories specified on\n"
384 " the command line"),
385 ONE_DASH },
386 { {"oformat", required_argument, NULL, OPTION_OFORMAT},
387 '\0', N_("TARGET"), N_("Specify target of output file"),
388 EXACTLY_TWO_DASHES },
389 { {"print-output-format", no_argument, NULL, OPTION_PRINT_OUTPUT_FORMAT},
390 '\0', NULL, N_("Print default output format"), TWO_DASHES },
391 { {"print-sysroot", no_argument, NULL, OPTION_PRINT_SYSROOT},
392 '\0', NULL, N_("Print current sysroot"), TWO_DASHES },
393 { {"qmagic", no_argument, NULL, OPTION_IGNORE},
394 '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
395 { {"reduce-memory-overheads", no_argument, NULL,
396 OPTION_REDUCE_MEMORY_OVERHEADS},
397 '\0', NULL, N_("Reduce memory overheads, possibly taking much longer"),
398 TWO_DASHES },
399 { {"relax", no_argument, NULL, OPTION_RELAX},
400 '\0', NULL, N_("Reduce code size by using target specific optimizations"), TWO_DASHES },
401 { {"no-relax", no_argument, NULL, OPTION_NO_RELAX},
402 '\0', NULL, N_("Do not use relaxation techniques to reduce code size"), TWO_DASHES },
403 { {"retain-symbols-file", required_argument, NULL,
404 OPTION_RETAIN_SYMBOLS_FILE},
405 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES },
406 { {"rpath", required_argument, NULL, OPTION_RPATH},
407 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH },
408 { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK},
409 '\0', N_("PATH"), N_("Set link time shared library search path"),
410 ONE_DASH },
411 { {"shared", no_argument, NULL, OPTION_SHARED},
412 '\0', NULL, N_("Create a shared library"), ONE_DASH },
413 { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */
414 '\0', NULL, NULL, ONE_DASH },
415 { {"pie", no_argument, NULL, OPTION_PIE},
416 '\0', NULL, N_("Create a position independent executable"), ONE_DASH },
417 { {"pic-executable", no_argument, NULL, OPTION_PIE},
418 '\0', NULL, NULL, TWO_DASHES },
419 { {"sort-common", optional_argument, NULL, OPTION_SORT_COMMON},
420 '\0', N_("[=ascending|descending]"),
421 N_("Sort common symbols by alignment [in specified order]"),
422 TWO_DASHES },
423 { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
424 '\0', NULL, NULL, NO_HELP },
425 { {"sort-section", required_argument, NULL, OPTION_SORT_SECTION},
426 '\0', N_("name|alignment"),
427 N_("Sort sections by name or maximum alignment"), TWO_DASHES },
428 { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS},
429 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"),
430 TWO_DASHES },
431 { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE},
432 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"),
433 TWO_DASHES },
434 { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC},
435 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"),
436 TWO_DASHES },
437 { {"stats", no_argument, NULL, OPTION_STATS},
438 '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES },
439 { {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
440 '\0', NULL, N_("Display target specific options"), TWO_DASHES },
441 { {"task-link", required_argument, NULL, OPTION_TASK_LINK},
442 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
443 { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
444 '\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
445 { {"section-start", required_argument, NULL, OPTION_SECTION_START},
446 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"),
447 TWO_DASHES },
448 { {"Tbss", required_argument, NULL, OPTION_TBSS},
449 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
450 { {"Tdata", required_argument, NULL, OPTION_TDATA},
451 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH },
452 { {"Ttext", required_argument, NULL, OPTION_TTEXT},
453 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH },
454 { {"Ttext-segment", required_argument, NULL, OPTION_TTEXT_SEGMENT},
455 '\0', N_("ADDRESS"), N_("Set address of text segment"), ONE_DASH },
456 { {"Trodata-segment", required_argument, NULL, OPTION_TRODATA_SEGMENT},
457 '\0', N_("ADDRESS"), N_("Set address of rodata segment"), ONE_DASH },
458 { {"Tldata-segment", required_argument, NULL, OPTION_TLDATA_SEGMENT},
459 '\0', N_("ADDRESS"), N_("Set address of ldata segment"), ONE_DASH },
460 { {"unresolved-symbols=<method>", required_argument, NULL,
461 OPTION_UNRESOLVED_SYMBOLS},
462 '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n"
463 " ignore-all, report-all, ignore-in-object-files,\n"
464 " ignore-in-shared-libs"),
465 TWO_DASHES },
466 { {"verbose", optional_argument, NULL, OPTION_VERBOSE},
467 '\0', N_("[=NUMBER]"),
468 N_("Output lots of information during link"), TWO_DASHES },
469 { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */
470 '\0', NULL, NULL, NO_HELP },
471 { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
472 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
473 { {"version-exports-section", required_argument, NULL,
474 OPTION_VERSION_EXPORTS_SECTION },
475 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n"
476 " SYMBOL as the version."),
477 TWO_DASHES },
478 { {"dynamic-list-data", no_argument, NULL, OPTION_DYNAMIC_LIST_DATA},
479 '\0', NULL, N_("Add data symbols to dynamic list"), TWO_DASHES },
480 { {"dynamic-list-cpp-new", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_NEW},
481 '\0', NULL, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES },
482 { {"dynamic-list-cpp-typeinfo", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_TYPEINFO},
483 '\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES },
484 { {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST},
485 '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES },
486 { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
487 '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
488 { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
489 '\0', NULL, N_("Warn if global constructors/destructors are seen"),
490 TWO_DASHES },
491 { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
492 '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
493 { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
494 '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
495 { {"warn-orphan", no_argument, NULL, OPTION_WARN_ORPHAN},
496 '\0', NULL, N_("Warn if any orphan sections are encountered"), TWO_DASHES },
497 { {"no-warn-orphan", no_argument, NULL, OPTION_NO_WARN_ORPHAN},
498 '\0', NULL, N_("Do not warn if orphan sections are encountered (default)"), TWO_DASHES },
499 { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
500 '\0', NULL, N_("Warn if start of section changes due to alignment"),
501 TWO_DASHES },
502 { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_SHARED_TEXTREL},
503 '\0', NULL, N_("Warn if shared object has DT_TEXTREL"),
504 TWO_DASHES },
505 { {"warn-alternate-em", no_argument, NULL, OPTION_WARN_ALTERNATE_EM},
506 '\0', NULL, N_("Warn if an object has alternate ELF machine code"),
507 TWO_DASHES },
508 { {"warn-unresolved-symbols", no_argument, NULL,
509 OPTION_WARN_UNRESOLVED_SYMBOLS},
510 '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES },
511 { {"error-unresolved-symbols", no_argument, NULL,
512 OPTION_ERROR_UNRESOLVED_SYMBOLS},
513 '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES },
514 { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
515 '\0', NULL, N_("Include all objects from following archives"),
516 TWO_DASHES },
517 { {"wrap", required_argument, NULL, OPTION_WRAP},
518 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES },
519 { {"ignore-unresolved-symbol", required_argument, NULL,
520 OPTION_IGNORE_UNRESOLVED_SYMBOL},
521 '\0', N_("SYMBOL"),
522 N_("Unresolved SYMBOL will not cause an error or warning"), TWO_DASHES },
523 { {"push-state", no_argument, NULL, OPTION_PUSH_STATE},
524 '\0', NULL, N_("Push state of flags governing input file handling"),
525 TWO_DASHES },
526 { {"pop-state", no_argument, NULL, OPTION_POP_STATE},
527 '\0', NULL, N_("Pop state of flags governing input file handling"),
528 TWO_DASHES },
529 { {"print-memory-usage", no_argument, NULL, OPTION_PRINT_MEMORY_USAGE},
530 '\0', NULL, N_("Report target memory usage"), TWO_DASHES },
531 };
532
533 #define OPTION_COUNT ARRAY_SIZE (ld_options)
534
535 void
536 parse_args (unsigned argc, char **argv)
537 {
538 unsigned i;
539 int is, il, irl;
540 int ingroup = 0;
541 char *default_dirlist = NULL;
542 char *shortopts;
543 struct option *longopts;
544 struct option *really_longopts;
545 int last_optind;
546 enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
547
548 shortopts = (char *) xmalloc (OPTION_COUNT * 3 + 2);
549 longopts = (struct option *)
550 xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
551 really_longopts = (struct option *)
552 malloc (sizeof (*really_longopts) * (OPTION_COUNT + 1));
553
554 /* Starting the short option string with '-' is for programs that
555 expect options and other ARGV-elements in any order and that care about
556 the ordering of the two. We describe each non-option ARGV-element
557 as if it were the argument of an option with character code 1. */
558 shortopts[0] = '-';
559 is = 1;
560 il = 0;
561 irl = 0;
562 for (i = 0; i < OPTION_COUNT; i++)
563 {
564 if (ld_options[i].shortopt != '\0')
565 {
566 shortopts[is] = ld_options[i].shortopt;
567 ++is;
568 if (ld_options[i].opt.has_arg == required_argument
569 || ld_options[i].opt.has_arg == optional_argument)
570 {
571 shortopts[is] = ':';
572 ++is;
573 if (ld_options[i].opt.has_arg == optional_argument)
574 {
575 shortopts[is] = ':';
576 ++is;
577 }
578 }
579 }
580 if (ld_options[i].opt.name != NULL)
581 {
582 if (ld_options[i].control == EXACTLY_TWO_DASHES)
583 {
584 really_longopts[irl] = ld_options[i].opt;
585 ++irl;
586 }
587 else
588 {
589 longopts[il] = ld_options[i].opt;
590 ++il;
591 }
592 }
593 }
594 shortopts[is] = '\0';
595 longopts[il].name = NULL;
596 really_longopts[irl].name = NULL;
597
598 ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts);
599
600 /* The -G option is ambiguous on different platforms. Sometimes it
601 specifies the largest data size to put into the small data
602 section. Sometimes it is equivalent to --shared. Unfortunately,
603 the first form takes an argument, while the second does not.
604
605 We need to permit the --shared form because on some platforms,
606 such as Solaris, gcc -shared will pass -G to the linker.
607
608 To permit either usage, we look through the argument list. If we
609 find -G not followed by a number, we change it into --shared.
610 This will work for most normal cases. */
611 for (i = 1; i < argc; i++)
612 if (strcmp (argv[i], "-G") == 0
613 && (i + 1 >= argc
614 || ! ISDIGIT (argv[i + 1][0])))
615 argv[i] = (char *) "--shared";
616
617 /* Because we permit long options to start with a single dash, and
618 we have a --library option, and the -l option is conventionally
619 used with an immediately following argument, we can have bad
620 results if somebody tries to use -l with a library whose name
621 happens to start with "ibrary", as in -li. We avoid problems by
622 simply turning -l into --library. This means that users will
623 have to use two dashes in order to use --library, which is OK
624 since that's how it is documented.
625
626 FIXME: It's possible that this problem can arise for other short
627 options as well, although the user does always have the recourse
628 of adding a space between the option and the argument. */
629 for (i = 1; i < argc; i++)
630 {
631 if (argv[i][0] == '-'
632 && argv[i][1] == 'l'
633 && argv[i][2] != '\0')
634 {
635 char *n;
636
637 n = (char *) xmalloc (strlen (argv[i]) + 20);
638 sprintf (n, "--library=%s", argv[i] + 2);
639 argv[i] = n;
640 }
641 }
642
643 last_optind = -1;
644 while (1)
645 {
646 int longind;
647 int optc;
648 static unsigned int defsym_count;
649
650 /* Using last_optind lets us avoid calling ldemul_parse_args
651 multiple times on a single option, which would lead to
652 confusion in the internal static variables maintained by
653 getopt. This could otherwise happen for an argument like
654 -nx, in which the -n is parsed as a single option, and we
655 loop around to pick up the -x. */
656 if (optind != last_optind)
657 if (ldemul_parse_args (argc, argv))
658 continue;
659
660 /* getopt_long_only is like getopt_long, but '-' as well as '--'
661 can indicate a long option. */
662 opterr = 0;
663 last_optind = optind;
664 optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
665 if (optc == '?')
666 {
667 optind = last_optind;
668 optc = getopt_long (argc, argv, "-", really_longopts, &longind);
669 }
670
671 if (ldemul_handle_option (optc))
672 continue;
673
674 if (optc == -1)
675 break;
676
677 switch (optc)
678 {
679 case '?':
680 einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]);
681 /* Fall through. */
682
683 default:
684 einfo (_("%P%F: use the --help option for usage information\n"));
685
686 case 1: /* File name. */
687 lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL);
688 break;
689
690 case OPTION_IGNORE:
691 break;
692 case 'a':
693 /* For HP/UX compatibility. Actually -a shared should mean
694 ``use only shared libraries'' but, then, we don't
695 currently support shared libraries on HP/UX anyhow. */
696 if (strcmp (optarg, "archive") == 0)
697 input_flags.dynamic = FALSE;
698 else if (strcmp (optarg, "shared") == 0
699 || strcmp (optarg, "default") == 0)
700 input_flags.dynamic = TRUE;
701 else
702 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg);
703 break;
704 case OPTION_ASSERT:
705 /* FIXME: We just ignore these, but we should handle them. */
706 if (strcmp (optarg, "definitions") == 0)
707 ;
708 else if (strcmp (optarg, "nodefinitions") == 0)
709 ;
710 else if (strcmp (optarg, "nosymbolic") == 0)
711 ;
712 else if (strcmp (optarg, "pure-text") == 0)
713 ;
714 else
715 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg);
716 break;
717 case 'A':
718 ldfile_add_arch (optarg);
719 break;
720 case 'b':
721 lang_add_target (optarg);
722 break;
723 case 'c':
724 ldfile_open_command_file (optarg);
725 parser_input = input_mri_script;
726 yyparse ();
727 break;
728 case OPTION_CALL_SHARED:
729 input_flags.dynamic = TRUE;
730 break;
731 case OPTION_NON_SHARED:
732 input_flags.dynamic = FALSE;
733 break;
734 case OPTION_CREF:
735 command_line.cref = TRUE;
736 link_info.notice_all = TRUE;
737 break;
738 case 'd':
739 command_line.force_common_definition = TRUE;
740 break;
741 case OPTION_DEFSYM:
742 lex_string = optarg;
743 lex_redirect (optarg, "--defsym", ++defsym_count);
744 parser_input = input_defsym;
745 yyparse ();
746 lex_string = NULL;
747 break;
748 case OPTION_DEMANGLE:
749 demangling = TRUE;
750 if (optarg != NULL)
751 {
752 enum demangling_styles style;
753
754 style = cplus_demangle_name_to_style (optarg);
755 if (style == unknown_demangling)
756 einfo (_("%F%P: unknown demangling style `%s'\n"),
757 optarg);
758
759 cplus_demangle_set_style (style);
760 }
761 break;
762 case 'I': /* Used on Solaris. */
763 case OPTION_DYNAMIC_LINKER:
764 command_line.interpreter = optarg;
765 break;
766 case OPTION_SYSROOT:
767 /* Already handled in ldmain.c. */
768 break;
769 case OPTION_EB:
770 command_line.endian = ENDIAN_BIG;
771 break;
772 case OPTION_EL:
773 command_line.endian = ENDIAN_LITTLE;
774 break;
775 case OPTION_EMBEDDED_RELOCS:
776 command_line.embedded_relocs = TRUE;
777 break;
778 case OPTION_EXPORT_DYNAMIC:
779 case 'E': /* HP/UX compatibility. */
780 link_info.export_dynamic = TRUE;
781 break;
782 case OPTION_NO_EXPORT_DYNAMIC:
783 link_info.export_dynamic = FALSE;
784 break;
785 case 'e':
786 lang_add_entry (optarg, TRUE);
787 break;
788 case 'f':
789 if (command_line.auxiliary_filters == NULL)
790 {
791 command_line.auxiliary_filters = (char **)
792 xmalloc (2 * sizeof (char *));
793 command_line.auxiliary_filters[0] = optarg;
794 command_line.auxiliary_filters[1] = NULL;
795 }
796 else
797 {
798 int c;
799 char **p;
800
801 c = 0;
802 for (p = command_line.auxiliary_filters; *p != NULL; p++)
803 ++c;
804 command_line.auxiliary_filters = (char **)
805 xrealloc (command_line.auxiliary_filters,
806 (c + 2) * sizeof (char *));
807 command_line.auxiliary_filters[c] = optarg;
808 command_line.auxiliary_filters[c + 1] = NULL;
809 }
810 break;
811 case 'F':
812 command_line.filter_shlib = optarg;
813 break;
814 case OPTION_FORCE_EXE_SUFFIX:
815 command_line.force_exe_suffix = TRUE;
816 break;
817 case 'G':
818 {
819 char *end;
820 g_switch_value = strtoul (optarg, &end, 0);
821 if (*end)
822 einfo (_("%P%F: invalid number `%s'\n"), optarg);
823 }
824 break;
825 case 'g':
826 /* Ignore. */
827 break;
828 case OPTION_GC_SECTIONS:
829 link_info.gc_sections = TRUE;
830 break;
831 case OPTION_PRINT_GC_SECTIONS:
832 link_info.print_gc_sections = TRUE;
833 break;
834 case OPTION_HELP:
835 help ();
836 xexit (0);
837 break;
838 case 'L':
839 ldfile_add_library_path (optarg, TRUE);
840 break;
841 case 'l':
842 lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL);
843 break;
844 case 'M':
845 config.map_filename = "-";
846 break;
847 case 'm':
848 /* Ignore. Was handled in a pre-parse. */
849 break;
850 case OPTION_MAP:
851 config.map_filename = optarg;
852 break;
853 case 'N':
854 config.text_read_only = FALSE;
855 config.magic_demand_paged = FALSE;
856 input_flags.dynamic = FALSE;
857 break;
858 case OPTION_NO_OMAGIC:
859 config.text_read_only = TRUE;
860 config.magic_demand_paged = TRUE;
861 /* NB/ Does not set input_flags.dynamic to TRUE.
862 Use --call-shared or -Bdynamic for this. */
863 break;
864 case 'n':
865 config.magic_demand_paged = FALSE;
866 input_flags.dynamic = FALSE;
867 break;
868 case OPTION_NO_DEFINE_COMMON:
869 command_line.inhibit_common_definition = TRUE;
870 break;
871 case OPTION_NO_DEMANGLE:
872 demangling = FALSE;
873 break;
874 case OPTION_NO_GC_SECTIONS:
875 link_info.gc_sections = FALSE;
876 break;
877 case OPTION_NO_PRINT_GC_SECTIONS:
878 link_info.print_gc_sections = FALSE;
879 break;
880 case OPTION_NO_KEEP_MEMORY:
881 link_info.keep_memory = FALSE;
882 break;
883 case OPTION_NO_UNDEFINED:
884 link_info.unresolved_syms_in_objects
885 = how_to_report_unresolved_symbols;
886 break;
887 case OPTION_ALLOW_SHLIB_UNDEFINED:
888 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
889 break;
890 case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
891 link_info.unresolved_syms_in_shared_libs
892 = how_to_report_unresolved_symbols;
893 break;
894 case OPTION_UNRESOLVED_SYMBOLS:
895 if (strcmp (optarg, "ignore-all") == 0)
896 {
897 link_info.unresolved_syms_in_objects = RM_IGNORE;
898 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
899 }
900 else if (strcmp (optarg, "report-all") == 0)
901 {
902 link_info.unresolved_syms_in_objects
903 = how_to_report_unresolved_symbols;
904 link_info.unresolved_syms_in_shared_libs
905 = how_to_report_unresolved_symbols;
906 }
907 else if (strcmp (optarg, "ignore-in-object-files") == 0)
908 {
909 link_info.unresolved_syms_in_objects = RM_IGNORE;
910 link_info.unresolved_syms_in_shared_libs
911 = how_to_report_unresolved_symbols;
912 }
913 else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
914 {
915 link_info.unresolved_syms_in_objects
916 = how_to_report_unresolved_symbols;
917 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
918 }
919 else
920 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg);
921 break;
922 case OPTION_WARN_UNRESOLVED_SYMBOLS:
923 how_to_report_unresolved_symbols = RM_GENERATE_WARNING;
924 if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR)
925 link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING;
926 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)
927 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING;
928 break;
929
930 case OPTION_ERROR_UNRESOLVED_SYMBOLS:
931 how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
932 if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING)
933 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
934 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING)
935 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
936 break;
937 case OPTION_ALLOW_MULTIPLE_DEFINITION:
938 link_info.allow_multiple_definition = TRUE;
939 break;
940 case OPTION_NO_UNDEFINED_VERSION:
941 link_info.allow_undefined_version = FALSE;
942 break;
943 case OPTION_DEFAULT_SYMVER:
944 link_info.create_default_symver = TRUE;
945 break;
946 case OPTION_DEFAULT_IMPORTED_SYMVER:
947 link_info.default_imported_symver = TRUE;
948 break;
949 case OPTION_NO_WARN_MISMATCH:
950 command_line.warn_mismatch = FALSE;
951 break;
952 case OPTION_NO_WARN_SEARCH_MISMATCH:
953 command_line.warn_search_mismatch = FALSE;
954 break;
955 case OPTION_NOINHIBIT_EXEC:
956 force_make_executable = TRUE;
957 break;
958 case OPTION_NOSTDLIB:
959 config.only_cmd_line_lib_dirs = TRUE;
960 break;
961 case OPTION_NO_WHOLE_ARCHIVE:
962 input_flags.whole_archive = FALSE;
963 break;
964 case 'O':
965 /* FIXME "-O<non-digits> <value>" used to set the address of
966 section <non-digits>. Was this for compatibility with
967 something, or can we create a new option to do that
968 (with a syntax similar to -defsym)?
969 getopt can't handle two args to an option without kludges. */
970
971 /* Enable optimizations of output files. */
972 link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE;
973 break;
974 case 'o':
975 lang_add_output (optarg, 0);
976 break;
977 case OPTION_OFORMAT:
978 lang_add_output_format (optarg, NULL, NULL, 0);
979 break;
980 case OPTION_PRINT_SYSROOT:
981 if (*ld_sysroot)
982 puts (ld_sysroot);
983 xexit (0);
984 break;
985 case OPTION_PRINT_OUTPUT_FORMAT:
986 command_line.print_output_format = TRUE;
987 break;
988 #ifdef ENABLE_PLUGINS
989 case OPTION_PLUGIN:
990 plugin_opt_plugin (optarg);
991 break;
992 case OPTION_PLUGIN_OPT:
993 if (plugin_opt_plugin_arg (optarg))
994 einfo(_("%P%F: bad -plugin-opt option\n"));
995 break;
996 #endif /* ENABLE_PLUGINS */
997 case 'q':
998 link_info.emitrelocations = TRUE;
999 break;
1000 case 'i':
1001 case 'r':
1002 if (optind == last_optind)
1003 /* This can happen if the user put "-rpath,a" on the command
1004 line. (Or something similar. The comma is important).
1005 Getopt becomes confused and thinks that this is a -r option
1006 but it cannot parse the text after the -r so it refuses to
1007 increment the optind counter. Detect this case and issue
1008 an error message here. We cannot just make this a warning,
1009 increment optind, and continue because getopt is too confused
1010 and will seg-fault the next time around. */
1011 einfo(_("%P%F: unrecognised option: %s\n"), argv[optind]);
1012
1013 if (bfd_link_pic (&link_info))
1014 einfo (_("%P%F: -r and %s may not be used together\n"),
1015 bfd_link_dll (&link_info) ? "-shared" : "-pie");
1016
1017 link_info.type = type_relocatable;
1018 config.build_constructors = FALSE;
1019 config.magic_demand_paged = FALSE;
1020 config.text_read_only = FALSE;
1021 input_flags.dynamic = FALSE;
1022 break;
1023 case 'R':
1024 /* The GNU linker traditionally uses -R to mean to include
1025 only the symbols from a file. The Solaris linker uses -R
1026 to set the path used by the runtime linker to find
1027 libraries. This is the GNU linker -rpath argument. We
1028 try to support both simultaneously by checking the file
1029 named. If it is a directory, rather than a regular file,
1030 we assume -rpath was meant. */
1031 {
1032 struct stat s;
1033
1034 if (stat (optarg, &s) >= 0
1035 && ! S_ISDIR (s.st_mode))
1036 {
1037 lang_add_input_file (optarg,
1038 lang_input_file_is_symbols_only_enum,
1039 NULL);
1040 break;
1041 }
1042 }
1043 /* Fall through. */
1044 case OPTION_RPATH:
1045 if (command_line.rpath == NULL)
1046 command_line.rpath = xstrdup (optarg);
1047 else
1048 {
1049 size_t rpath_len = strlen (command_line.rpath);
1050 size_t optarg_len = strlen (optarg);
1051 char *buf;
1052 char *cp = command_line.rpath;
1053
1054 /* First see whether OPTARG is already in the path. */
1055 do
1056 {
1057 if (strncmp (optarg, cp, optarg_len) == 0
1058 && (cp[optarg_len] == 0
1059 || cp[optarg_len] == config.rpath_separator))
1060 /* We found it. */
1061 break;
1062
1063 /* Not yet found. */
1064 cp = strchr (cp, config.rpath_separator);
1065 if (cp != NULL)
1066 ++cp;
1067 }
1068 while (cp != NULL);
1069
1070 if (cp == NULL)
1071 {
1072 buf = (char *) xmalloc (rpath_len + optarg_len + 2);
1073 sprintf (buf, "%s%c%s", command_line.rpath,
1074 config.rpath_separator, optarg);
1075 free (command_line.rpath);
1076 command_line.rpath = buf;
1077 }
1078 }
1079 break;
1080 case OPTION_RPATH_LINK:
1081 if (command_line.rpath_link == NULL)
1082 command_line.rpath_link = xstrdup (optarg);
1083 else
1084 {
1085 char *buf;
1086
1087 buf = (char *) xmalloc (strlen (command_line.rpath_link)
1088 + strlen (optarg)
1089 + 2);
1090 sprintf (buf, "%s%c%s", command_line.rpath_link,
1091 config.rpath_separator, optarg);
1092 free (command_line.rpath_link);
1093 command_line.rpath_link = buf;
1094 }
1095 break;
1096 case OPTION_NO_RELAX:
1097 DISABLE_RELAXATION;
1098 break;
1099 case OPTION_RELAX:
1100 ENABLE_RELAXATION;
1101 break;
1102 case OPTION_RETAIN_SYMBOLS_FILE:
1103 add_keepsyms_file (optarg);
1104 break;
1105 case 'S':
1106 link_info.strip = strip_debugger;
1107 break;
1108 case 's':
1109 link_info.strip = strip_all;
1110 break;
1111 case OPTION_STRIP_DISCARDED:
1112 link_info.strip_discarded = TRUE;
1113 break;
1114 case OPTION_NO_STRIP_DISCARDED:
1115 link_info.strip_discarded = FALSE;
1116 break;
1117 case OPTION_SHARED:
1118 if (config.has_shared)
1119 {
1120 if (bfd_link_relocatable (&link_info))
1121 einfo (_("%P%F: -r and -shared may not be used together\n"));
1122
1123 link_info.type = type_dll;
1124 link_info.pic = TRUE;
1125 /* When creating a shared library, the default
1126 behaviour is to ignore any unresolved references. */
1127 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1128 link_info.unresolved_syms_in_objects = RM_IGNORE;
1129 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1130 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
1131 }
1132 else
1133 einfo (_("%P%F: -shared not supported\n"));
1134 break;
1135 case OPTION_PIE:
1136 if (config.has_shared)
1137 {
1138 if (bfd_link_relocatable (&link_info))
1139 einfo (_("%P%F: -r and -pie may not be used together\n"));
1140
1141 link_info.type = type_executable;
1142 link_info.pic = TRUE;
1143 }
1144 else
1145 einfo (_("%P%F: -pie not supported\n"));
1146 break;
1147 case 'h': /* Used on Solaris. */
1148 case OPTION_SONAME:
1149 if (optarg[0] == '\0' && command_line.soname
1150 && command_line.soname[0])
1151 einfo (_("%P: SONAME must not be empty string; keeping previous one\n"));
1152 else
1153 command_line.soname = optarg;
1154 break;
1155 case OPTION_SORT_COMMON:
1156 if (optarg == NULL
1157 || strcmp (optarg, N_("descending")) == 0)
1158 config.sort_common = sort_descending;
1159 else if (strcmp (optarg, N_("ascending")) == 0)
1160 config.sort_common = sort_ascending;
1161 else
1162 einfo (_("%P%F: invalid common section sorting option: %s\n"),
1163 optarg);
1164 break;
1165 case OPTION_SORT_SECTION:
1166 if (strcmp (optarg, N_("name")) == 0)
1167 sort_section = by_name;
1168 else if (strcmp (optarg, N_("alignment")) == 0)
1169 sort_section = by_alignment;
1170 else
1171 einfo (_("%P%F: invalid section sorting option: %s\n"),
1172 optarg);
1173 break;
1174 case OPTION_STATS:
1175 config.stats = TRUE;
1176 break;
1177 case OPTION_SYMBOLIC:
1178 command_line.symbolic = symbolic;
1179 break;
1180 case OPTION_SYMBOLIC_FUNCTIONS:
1181 command_line.symbolic = symbolic_functions;
1182 break;
1183 case 't':
1184 trace_files = TRUE;
1185 break;
1186 case 'T':
1187 previous_script_handle = saved_script_handle;
1188 ldfile_open_command_file (optarg);
1189 parser_input = input_script;
1190 yyparse ();
1191 previous_script_handle = NULL;
1192 break;
1193 case OPTION_DEFAULT_SCRIPT:
1194 command_line.default_script = optarg;
1195 break;
1196 case OPTION_SECTION_START:
1197 {
1198 char *optarg2;
1199 char *sec_name;
1200 int len;
1201
1202 /* Check for <something>=<somthing>... */
1203 optarg2 = strchr (optarg, '=');
1204 if (optarg2 == NULL)
1205 einfo (_("%P%F: invalid argument to option"
1206 " \"--section-start\"\n"));
1207
1208 optarg2++;
1209
1210 /* So far so good. Are all the args present? */
1211 if ((*optarg == '\0') || (*optarg2 == '\0'))
1212 einfo (_("%P%F: missing argument(s) to option"
1213 " \"--section-start\"\n"));
1214
1215 /* We must copy the section name as set_section_start
1216 doesn't do it for us. */
1217 len = optarg2 - optarg;
1218 sec_name = (char *) xmalloc (len);
1219 memcpy (sec_name, optarg, len - 1);
1220 sec_name[len - 1] = 0;
1221
1222 /* Then set it... */
1223 set_section_start (sec_name, optarg2);
1224 }
1225 break;
1226 case OPTION_TARGET_HELP:
1227 /* Mention any target specific options. */
1228 ldemul_list_emulation_options (stdout);
1229 exit (0);
1230 case OPTION_TBSS:
1231 set_segment_start (".bss", optarg);
1232 break;
1233 case OPTION_TDATA:
1234 set_segment_start (".data", optarg);
1235 break;
1236 case OPTION_TTEXT:
1237 set_segment_start (".text", optarg);
1238 break;
1239 case OPTION_TTEXT_SEGMENT:
1240 set_segment_start (".text-segment", optarg);
1241 break;
1242 case OPTION_TRODATA_SEGMENT:
1243 set_segment_start (".rodata-segment", optarg);
1244 break;
1245 case OPTION_TLDATA_SEGMENT:
1246 set_segment_start (".ldata-segment", optarg);
1247 break;
1248 case OPTION_TRADITIONAL_FORMAT:
1249 link_info.traditional_format = TRUE;
1250 break;
1251 case OPTION_TASK_LINK:
1252 link_info.task_link = TRUE;
1253 /* Fall through - do an implied -r option. */
1254 case OPTION_UR:
1255 if (bfd_link_pic (&link_info))
1256 einfo (_("%P%F: -r and %s may not be used together\n"),
1257 bfd_link_dll (&link_info) ? "-shared" : "-pie");
1258
1259 link_info.type = type_relocatable;
1260 config.build_constructors = TRUE;
1261 config.magic_demand_paged = FALSE;
1262 config.text_read_only = FALSE;
1263 input_flags.dynamic = FALSE;
1264 break;
1265 case 'u':
1266 ldlang_add_undef (optarg, TRUE);
1267 break;
1268 case OPTION_REQUIRE_DEFINED_SYMBOL:
1269 ldlang_add_require_defined (optarg);
1270 break;
1271 case OPTION_UNIQUE:
1272 if (optarg != NULL)
1273 lang_add_unique (optarg);
1274 else
1275 config.unique_orphan_sections = TRUE;
1276 break;
1277 case OPTION_VERBOSE:
1278 ldversion (1);
1279 version_printed = TRUE;
1280 verbose = TRUE;
1281 overflow_cutoff_limit = -2;
1282 if (optarg != NULL)
1283 {
1284 char *end;
1285 int level ATTRIBUTE_UNUSED = strtoul (optarg, &end, 0);
1286 if (*end)
1287 einfo (_("%P%F: invalid number `%s'\n"), optarg);
1288 #ifdef ENABLE_PLUGINS
1289 report_plugin_symbols = level > 1;
1290 #endif /* ENABLE_PLUGINS */
1291 }
1292 break;
1293 case 'v':
1294 ldversion (0);
1295 version_printed = TRUE;
1296 break;
1297 case 'V':
1298 ldversion (1);
1299 version_printed = TRUE;
1300 break;
1301 case OPTION_VERSION:
1302 ldversion (2);
1303 xexit (0);
1304 break;
1305 case OPTION_VERSION_SCRIPT:
1306 /* This option indicates a small script that only specifies
1307 version information. Read it, but don't assume that
1308 we've seen a linker script. */
1309 {
1310 FILE *hold_script_handle;
1311
1312 hold_script_handle = saved_script_handle;
1313 ldfile_open_command_file (optarg);
1314 saved_script_handle = hold_script_handle;
1315 parser_input = input_version_script;
1316 yyparse ();
1317 }
1318 break;
1319 case OPTION_VERSION_EXPORTS_SECTION:
1320 /* This option records a version symbol to be applied to the
1321 symbols listed for export to be found in the object files
1322 .exports sections. */
1323 command_line.version_exports_section = optarg;
1324 break;
1325 case OPTION_DYNAMIC_LIST_DATA:
1326 command_line.dynamic_list = dynamic_list_data;
1327 if (command_line.symbolic == symbolic)
1328 command_line.symbolic = symbolic_unset;
1329 break;
1330 case OPTION_DYNAMIC_LIST_CPP_TYPEINFO:
1331 lang_append_dynamic_list_cpp_typeinfo ();
1332 if (command_line.dynamic_list != dynamic_list_data)
1333 command_line.dynamic_list = dynamic_list;
1334 if (command_line.symbolic == symbolic)
1335 command_line.symbolic = symbolic_unset;
1336 break;
1337 case OPTION_DYNAMIC_LIST_CPP_NEW:
1338 lang_append_dynamic_list_cpp_new ();
1339 if (command_line.dynamic_list != dynamic_list_data)
1340 command_line.dynamic_list = dynamic_list;
1341 if (command_line.symbolic == symbolic)
1342 command_line.symbolic = symbolic_unset;
1343 break;
1344 case OPTION_DYNAMIC_LIST:
1345 /* This option indicates a small script that only specifies
1346 a dynamic list. Read it, but don't assume that we've
1347 seen a linker script. */
1348 {
1349 FILE *hold_script_handle;
1350
1351 hold_script_handle = saved_script_handle;
1352 ldfile_open_command_file (optarg);
1353 saved_script_handle = hold_script_handle;
1354 parser_input = input_dynamic_list;
1355 yyparse ();
1356 }
1357 if (command_line.dynamic_list != dynamic_list_data)
1358 command_line.dynamic_list = dynamic_list;
1359 if (command_line.symbolic == symbolic)
1360 command_line.symbolic = symbolic_unset;
1361 break;
1362 case OPTION_WARN_COMMON:
1363 config.warn_common = TRUE;
1364 break;
1365 case OPTION_WARN_CONSTRUCTORS:
1366 config.warn_constructors = TRUE;
1367 break;
1368 case OPTION_WARN_FATAL:
1369 config.fatal_warnings = TRUE;
1370 break;
1371 case OPTION_NO_WARN_FATAL:
1372 config.fatal_warnings = FALSE;
1373 break;
1374 case OPTION_WARN_MULTIPLE_GP:
1375 config.warn_multiple_gp = TRUE;
1376 break;
1377 case OPTION_WARN_ONCE:
1378 config.warn_once = TRUE;
1379 break;
1380 case OPTION_WARN_ORPHAN:
1381 config.warn_orphan = TRUE;
1382 break;
1383 case OPTION_NO_WARN_ORPHAN:
1384 config.warn_orphan = FALSE;
1385 break;
1386 case OPTION_WARN_SECTION_ALIGN:
1387 config.warn_section_align = TRUE;
1388 break;
1389 case OPTION_WARN_SHARED_TEXTREL:
1390 link_info.warn_shared_textrel = TRUE;
1391 break;
1392 case OPTION_WARN_ALTERNATE_EM:
1393 link_info.warn_alternate_em = TRUE;
1394 break;
1395 case OPTION_WHOLE_ARCHIVE:
1396 input_flags.whole_archive = TRUE;
1397 break;
1398 case OPTION_ADD_DT_NEEDED_FOR_DYNAMIC:
1399 input_flags.add_DT_NEEDED_for_dynamic = TRUE;
1400 break;
1401 case OPTION_NO_ADD_DT_NEEDED_FOR_DYNAMIC:
1402 input_flags.add_DT_NEEDED_for_dynamic = FALSE;
1403 break;
1404 case OPTION_ADD_DT_NEEDED_FOR_REGULAR:
1405 input_flags.add_DT_NEEDED_for_regular = TRUE;
1406 break;
1407 case OPTION_NO_ADD_DT_NEEDED_FOR_REGULAR:
1408 input_flags.add_DT_NEEDED_for_regular = FALSE;
1409 break;
1410 case OPTION_WRAP:
1411 add_wrap (optarg);
1412 break;
1413 case OPTION_IGNORE_UNRESOLVED_SYMBOL:
1414 add_ignoresym (&link_info, optarg);
1415 break;
1416 case OPTION_DISCARD_NONE:
1417 link_info.discard = discard_none;
1418 break;
1419 case 'X':
1420 link_info.discard = discard_l;
1421 break;
1422 case 'x':
1423 link_info.discard = discard_all;
1424 break;
1425 case 'Y':
1426 if (CONST_STRNEQ (optarg, "P,"))
1427 optarg += 2;
1428 if (default_dirlist != NULL)
1429 free (default_dirlist);
1430 default_dirlist = xstrdup (optarg);
1431 break;
1432 case 'y':
1433 add_ysym (optarg);
1434 break;
1435 case OPTION_SPARE_DYNAMIC_TAGS:
1436 link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
1437 break;
1438 case OPTION_SPLIT_BY_RELOC:
1439 if (optarg != NULL)
1440 config.split_by_reloc = strtoul (optarg, NULL, 0);
1441 else
1442 config.split_by_reloc = 32768;
1443 break;
1444 case OPTION_SPLIT_BY_FILE:
1445 if (optarg != NULL)
1446 config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
1447 else
1448 config.split_by_file = 1;
1449 break;
1450 case OPTION_CHECK_SECTIONS:
1451 command_line.check_section_addresses = 1;
1452 break;
1453 case OPTION_NO_CHECK_SECTIONS:
1454 command_line.check_section_addresses = 0;
1455 break;
1456 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
1457 command_line.accept_unknown_input_arch = TRUE;
1458 break;
1459 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
1460 command_line.accept_unknown_input_arch = FALSE;
1461 break;
1462 case '(':
1463 lang_enter_group ();
1464 ingroup++;
1465 break;
1466 case ')':
1467 if (! ingroup)
1468 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1469
1470 lang_leave_group ();
1471 ingroup--;
1472 break;
1473
1474 case OPTION_INIT:
1475 link_info.init_function = optarg;
1476 break;
1477
1478 case OPTION_FINI:
1479 link_info.fini_function = optarg;
1480 break;
1481
1482 case OPTION_REDUCE_MEMORY_OVERHEADS:
1483 link_info.reduce_memory_overheads = TRUE;
1484 if (config.hash_table_size == 0)
1485 config.hash_table_size = 1021;
1486 break;
1487
1488 case OPTION_HASH_SIZE:
1489 {
1490 bfd_size_type new_size;
1491
1492 new_size = strtoul (optarg, NULL, 0);
1493 if (new_size)
1494 config.hash_table_size = new_size;
1495 else
1496 einfo (_("%P%X: --hash-size needs a numeric argument\n"));
1497 }
1498 break;
1499
1500 case OPTION_PUSH_STATE:
1501 input_flags.pushed = xmemdup (&input_flags,
1502 sizeof (input_flags),
1503 sizeof (input_flags));
1504 break;
1505
1506 case OPTION_POP_STATE:
1507 if (input_flags.pushed == NULL)
1508 einfo (_("%P%F: no state pushed before popping\n"));
1509 else
1510 {
1511 struct lang_input_statement_flags *oldp = input_flags.pushed;
1512 memcpy (&input_flags, oldp, sizeof (input_flags));
1513 free (oldp);
1514 }
1515 break;
1516
1517 case OPTION_PRINT_MEMORY_USAGE:
1518 command_line.print_memory_usage = TRUE;
1519 break;
1520 }
1521 }
1522
1523 if (command_line.soname && command_line.soname[0] == '\0')
1524 {
1525 einfo (_("%P: SONAME must not be empty string; ignored\n"));
1526 command_line.soname = NULL;
1527 }
1528
1529 while (ingroup)
1530 {
1531 lang_leave_group ();
1532 ingroup--;
1533 }
1534
1535 if (default_dirlist != NULL)
1536 {
1537 set_default_dirlist (default_dirlist);
1538 free (default_dirlist);
1539 }
1540
1541 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1542 /* FIXME: Should we allow emulations a chance to set this ? */
1543 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
1544
1545 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1546 /* FIXME: Should we allow emulations a chance to set this ? */
1547 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
1548
1549 if (bfd_link_relocatable (&link_info)
1550 && command_line.check_section_addresses < 0)
1551 command_line.check_section_addresses = 0;
1552
1553 /* We may have -Bsymbolic, -Bsymbolic-functions, --dynamic-list-data,
1554 --dynamic-list-cpp-new, --dynamic-list-cpp-typeinfo and
1555 --dynamic-list FILE. -Bsymbolic and -Bsymbolic-functions are
1556 for shared libraries. -Bsymbolic overrides all others and vice
1557 versa. */
1558 switch (command_line.symbolic)
1559 {
1560 case symbolic_unset:
1561 break;
1562 case symbolic:
1563 /* -Bsymbolic is for shared library only. */
1564 if (bfd_link_dll (&link_info))
1565 {
1566 link_info.symbolic = TRUE;
1567 /* Should we free the unused memory? */
1568 link_info.dynamic_list = NULL;
1569 command_line.dynamic_list = dynamic_list_unset;
1570 }
1571 break;
1572 case symbolic_functions:
1573 /* -Bsymbolic-functions is for shared library only. */
1574 if (bfd_link_dll (&link_info))
1575 command_line.dynamic_list = dynamic_list_data;
1576 break;
1577 }
1578
1579 switch (command_line.dynamic_list)
1580 {
1581 case dynamic_list_unset:
1582 break;
1583 case dynamic_list_data:
1584 link_info.dynamic_data = TRUE;
1585 case dynamic_list:
1586 link_info.dynamic = TRUE;
1587 break;
1588 }
1589
1590 if (!bfd_link_dll (&link_info))
1591 {
1592 if (command_line.filter_shlib)
1593 einfo (_("%P%F: -F may not be used without -shared\n"));
1594 if (command_line.auxiliary_filters)
1595 einfo (_("%P%F: -f may not be used without -shared\n"));
1596 }
1597
1598 /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols). I
1599 don't see how else this can be handled, since in this case we
1600 must preserve all externally visible symbols. */
1601 if (bfd_link_relocatable (&link_info) && link_info.strip == strip_all)
1602 {
1603 link_info.strip = strip_debugger;
1604 if (link_info.discard == discard_sec_merge)
1605 link_info.discard = discard_all;
1606 }
1607 }
1608
1609 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1610 library search path. */
1611
1612 static void
1613 set_default_dirlist (char *dirlist_ptr)
1614 {
1615 char *p;
1616
1617 while (1)
1618 {
1619 p = strchr (dirlist_ptr, PATH_SEPARATOR);
1620 if (p != NULL)
1621 *p = '\0';
1622 if (*dirlist_ptr != '\0')
1623 ldfile_add_library_path (dirlist_ptr, TRUE);
1624 if (p == NULL)
1625 break;
1626 dirlist_ptr = p + 1;
1627 }
1628 }
1629
1630 static void
1631 set_section_start (char *sect, char *valstr)
1632 {
1633 const char *end;
1634 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1635 if (*end)
1636 einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
1637 lang_section_start (sect, exp_intop (val), NULL);
1638 }
1639
1640 static void
1641 set_segment_start (const char *section, char *valstr)
1642 {
1643 const char *name;
1644 const char *end;
1645 segment_type *seg;
1646
1647 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1648 if (*end)
1649 einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
1650 /* If we already have an entry for this segment, update the existing
1651 value. */
1652 name = section + 1;
1653 for (seg = segments; seg; seg = seg->next)
1654 if (strcmp (seg->name, name) == 0)
1655 {
1656 seg->value = val;
1657 return;
1658 }
1659 /* There was no existing value so we must create a new segment
1660 entry. */
1661 seg = (segment_type *) stat_alloc (sizeof (*seg));
1662 seg->name = name;
1663 seg->value = val;
1664 seg->used = FALSE;
1665 /* Add it to the linked list of segments. */
1666 seg->next = segments;
1667 segments = seg;
1668 /* Historically, -Ttext and friends set the base address of a
1669 particular section. For backwards compatibility, we still do
1670 that. If a SEGMENT_START directive is seen, the section address
1671 assignment will be disabled. */
1672 lang_section_start (section, exp_intop (val), seg);
1673 }
1674
1675 static void
1676 elf_shlib_list_options (FILE *file)
1677 {
1678 fprintf (file, _("\
1679 --audit=AUDITLIB Specify a library to use for auditing\n"));
1680 fprintf (file, _("\
1681 -Bgroup Selects group name lookup rules for DSO\n"));
1682 fprintf (file, _("\
1683 --disable-new-dtags Disable new dynamic tags\n"));
1684 fprintf (file, _("\
1685 --enable-new-dtags Enable new dynamic tags\n"));
1686 fprintf (file, _("\
1687 --eh-frame-hdr Create .eh_frame_hdr section\n"));
1688 fprintf (file, _("\
1689 --exclude-libs=LIBS Make all symbols in LIBS hidden\n"));
1690 fprintf (file, _("\
1691 --hash-style=STYLE Set hash style to sysv, gnu or both\n"));
1692 fprintf (file, _("\
1693 -P AUDITLIB, --depaudit=AUDITLIB\n" "\
1694 Specify a library to use for auditing dependencies\n"));
1695 fprintf (file, _("\
1696 -z combreloc Merge dynamic relocs into one section and sort\n"));
1697 fprintf (file, _("\
1698 -z nocombreloc Don't merge dynamic relocs into one section\n"));
1699 fprintf (file, _("\
1700 -z global Make symbols in DSO available for subsequently\n\
1701 loaded objects\n"));
1702 fprintf (file, _("\
1703 -z initfirst Mark DSO to be initialized first at runtime\n"));
1704 fprintf (file, _("\
1705 -z interpose Mark object to interpose all DSOs but executable\n"));
1706 fprintf (file, _("\
1707 -z lazy Mark object lazy runtime binding (default)\n"));
1708 fprintf (file, _("\
1709 -z loadfltr Mark object requiring immediate process\n"));
1710 fprintf (file, _("\
1711 -z nocopyreloc Don't create copy relocs\n"));
1712 fprintf (file, _("\
1713 -z nodefaultlib Mark object not to use default search paths\n"));
1714 fprintf (file, _("\
1715 -z nodelete Mark DSO non-deletable at runtime\n"));
1716 fprintf (file, _("\
1717 -z nodlopen Mark DSO not available to dlopen\n"));
1718 fprintf (file, _("\
1719 -z nodump Mark DSO not available to dldump\n"));
1720 fprintf (file, _("\
1721 -z now Mark object non-lazy runtime binding\n"));
1722 fprintf (file, _("\
1723 -z origin Mark object requiring immediate $ORIGIN\n\
1724 processing at runtime\n"));
1725 fprintf (file, _("\
1726 -z relro Create RELRO program header\n"));
1727 fprintf (file, _("\
1728 -z norelro Don't create RELRO program header\n"));
1729 fprintf (file, _("\
1730 -z stacksize=SIZE Set size of stack segment\n"));
1731 fprintf (file, _("\
1732 -z text Treat DT_TEXTREL in shared object as error\n"));
1733 fprintf (file, _("\
1734 -z notext Don't treat DT_TEXTREL in shared object as error\n"));
1735 fprintf (file, _("\
1736 -z textoff Don't treat DT_TEXTREL in shared object as error\n"));
1737 }
1738
1739 static void
1740 elf_static_list_options (FILE *file)
1741 {
1742 fprintf (file, _("\
1743 --build-id[=STYLE] Generate build ID note\n"));
1744 fprintf (file, _("\
1745 --compress-debug-sections=[none|zlib|zlib-gnu|zlib-gabi]\n\
1746 Compress DWARF debug sections using zlib\n"));
1747 fprintf (file, _("\
1748 -z common-page-size=SIZE Set common page size to SIZE\n"));
1749 fprintf (file, _("\
1750 -z max-page-size=SIZE Set maximum page size to SIZE\n"));
1751 fprintf (file, _("\
1752 -z defs Report unresolved symbols in object files.\n"));
1753 fprintf (file, _("\
1754 -z muldefs Allow multiple definitions\n"));
1755 fprintf (file, _("\
1756 -z execstack Mark executable as requiring executable stack\n"));
1757 fprintf (file, _("\
1758 -z noexecstack Mark executable as not requiring executable stack\n"));
1759 }
1760
1761 static void
1762 elf_plt_unwind_list_options (FILE *file)
1763 {
1764 fprintf (file, _("\
1765 --ld-generated-unwind-info Generate exception handling info for PLT\n\
1766 --no-ld-generated-unwind-info\n\
1767 Don't generate exception handling info for PLT\n"));
1768 }
1769
1770 static void
1771 ld_list_options (FILE *file, bfd_boolean elf, bfd_boolean shlib,
1772 bfd_boolean plt_unwind)
1773 {
1774 if (!elf)
1775 return;
1776 printf (_("ELF emulations:\n"));
1777 if (plt_unwind)
1778 elf_plt_unwind_list_options (file);
1779 elf_static_list_options (file);
1780 if (shlib)
1781 elf_shlib_list_options (file);
1782 }
1783
1784 \f
1785 /* Print help messages for the options. */
1786
1787 static void
1788 help (void)
1789 {
1790 unsigned i;
1791 const char **targets, **pp;
1792 int len;
1793
1794 printf (_("Usage: %s [options] file...\n"), program_name);
1795
1796 printf (_("Options:\n"));
1797 for (i = 0; i < OPTION_COUNT; i++)
1798 {
1799 if (ld_options[i].doc != NULL)
1800 {
1801 bfd_boolean comma;
1802 unsigned j;
1803
1804 printf (" ");
1805
1806 comma = FALSE;
1807 len = 2;
1808
1809 j = i;
1810 do
1811 {
1812 if (ld_options[j].shortopt != '\0'
1813 && ld_options[j].control != NO_HELP)
1814 {
1815 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
1816 len += (comma ? 2 : 0) + 2;
1817 if (ld_options[j].arg != NULL)
1818 {
1819 if (ld_options[j].opt.has_arg != optional_argument)
1820 {
1821 printf (" ");
1822 ++len;
1823 }
1824 printf ("%s", _(ld_options[j].arg));
1825 len += strlen (_(ld_options[j].arg));
1826 }
1827 comma = TRUE;
1828 }
1829 ++j;
1830 }
1831 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1832
1833 j = i;
1834 do
1835 {
1836 if (ld_options[j].opt.name != NULL
1837 && ld_options[j].control != NO_HELP)
1838 {
1839 int two_dashes =
1840 (ld_options[j].control == TWO_DASHES
1841 || ld_options[j].control == EXACTLY_TWO_DASHES);
1842
1843 printf ("%s-%s%s",
1844 comma ? ", " : "",
1845 two_dashes ? "-" : "",
1846 ld_options[j].opt.name);
1847 len += ((comma ? 2 : 0)
1848 + 1
1849 + (two_dashes ? 1 : 0)
1850 + strlen (ld_options[j].opt.name));
1851 if (ld_options[j].arg != NULL)
1852 {
1853 printf (" %s", _(ld_options[j].arg));
1854 len += 1 + strlen (_(ld_options[j].arg));
1855 }
1856 comma = TRUE;
1857 }
1858 ++j;
1859 }
1860 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1861
1862 if (len >= 30)
1863 {
1864 printf ("\n");
1865 len = 0;
1866 }
1867
1868 for (; len < 30; len++)
1869 putchar (' ');
1870
1871 printf ("%s\n", _(ld_options[i].doc));
1872 }
1873 }
1874 printf (_(" @FILE"));
1875 for (len = strlen (" @FILE"); len < 30; len++)
1876 putchar (' ');
1877 printf (_("Read options from FILE\n"));
1878
1879 /* Note: Various tools (such as libtool) depend upon the
1880 format of the listings below - do not change them. */
1881 /* xgettext:c-format */
1882 printf (_("%s: supported targets:"), program_name);
1883 targets = bfd_target_list ();
1884 for (pp = targets; *pp != NULL; pp++)
1885 printf (" %s", *pp);
1886 free (targets);
1887 printf ("\n");
1888
1889 /* xgettext:c-format */
1890 printf (_("%s: supported emulations: "), program_name);
1891 ldemul_list_emulations (stdout);
1892 printf ("\n");
1893
1894 /* xgettext:c-format */
1895 printf (_("%s: emulation specific options:\n"), program_name);
1896 ld_list_options (stdout, ELF_LIST_OPTIONS, ELF_SHLIB_LIST_OPTIONS,
1897 ELF_PLT_UNWIND_LIST_OPTIONS);
1898 ldemul_list_emulation_options (stdout);
1899 printf ("\n");
1900
1901 if (REPORT_BUGS_TO[0])
1902 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
1903 }
This page took 0.07174 seconds and 5 git commands to generate.