1 /* Parse options for the GNU linker.
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004
4 Free Software Foundation, Inc.
5
6 This file is part of GLD, the Gnu Linker.
7
8 GLD 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 2, or (at your option)
11 any later version.
12
13 GLD 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.
17
18 You should have received a copy of the GNU General Public License
19 along with GLD; see the file COPYING. If not, write to the Free
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
21 02111-1307, USA. */
22
23 #include "bfd.h"
24 #include "sysdep.h"
25 #include "libiberty.h"
26 #include <stdio.h>
27 #include <string.h>
28 #include "safe-ctype.h"
29 #include "getopt.h"
30 #include "bfdlink.h"
31 #include "ld.h"
32 #include "ldmain.h"
33 #include "ldmisc.h"
34 #include "ldexp.h"
35 #include "ldlang.h"
36 #include <ldgram.h>
37 #include "ldlex.h"
38 #include "ldfile.h"
39 #include "ldver.h"
40 #include "ldemul.h"
41 #include "demangle.h"
42
43 #ifndef PATH_SEPARATOR
44 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
45 #define PATH_SEPARATOR ';'
46 #else
47 #define PATH_SEPARATOR ':'
48 #endif
49 #endif
50
51 /* Somewhere above, sys/stat.h got included . . . . */
52 #if !defined(S_ISDIR) && defined(S_IFDIR)
53 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
54 #endif
55
56 static void set_default_dirlist (char *);
57 static void set_section_start (char *, char *);
58 static void help (void);
59
60 /* Non-zero if we are processing a --defsym from the command line. */
61 int parsing_defsym = 0;
62
63 /* Codes used for the long options with no short synonyms. 150 isn't
64 special; it's just an arbitrary non-ASCII char value. */
65 enum option_values
66 {
67 OPTION_ASSERT = 150,
68 OPTION_CALL_SHARED,
69 OPTION_CREF,
70 OPTION_DEFSYM,
71 OPTION_DEMANGLE,
72 OPTION_DYNAMIC_LINKER,
73 OPTION_EB,
74 OPTION_EL,
75 OPTION_EMBEDDED_RELOCS,
76 OPTION_EXPORT_DYNAMIC,
77 OPTION_HELP,
78 OPTION_IGNORE,
79 OPTION_MAP,
80 OPTION_NO_DEMANGLE,
81 OPTION_NO_KEEP_MEMORY,
82 OPTION_NO_WARN_MISMATCH,
83 OPTION_NOINHIBIT_EXEC,
84 OPTION_NON_SHARED,
85 OPTION_NO_WHOLE_ARCHIVE,
86 OPTION_OFORMAT,
87 OPTION_RELAX,
88 OPTION_RETAIN_SYMBOLS_FILE,
89 OPTION_RPATH,
90 OPTION_RPATH_LINK,
91 OPTION_SHARED,
92 OPTION_SONAME,
93 OPTION_SORT_COMMON,
94 OPTION_STATS,
95 OPTION_SYMBOLIC,
96 OPTION_TASK_LINK,
97 OPTION_TBSS,
98 OPTION_TDATA,
99 OPTION_TTEXT,
100 OPTION_TRADITIONAL_FORMAT,
101 OPTION_UR,
102 OPTION_VERBOSE,
103 OPTION_VERSION,
104 OPTION_VERSION_SCRIPT,
105 OPTION_VERSION_EXPORTS_SECTION,
106 OPTION_WARN_COMMON,
107 OPTION_WARN_CONSTRUCTORS,
108 OPTION_WARN_FATAL,
109 OPTION_WARN_MULTIPLE_GP,
110 OPTION_WARN_ONCE,
111 OPTION_WARN_SECTION_ALIGN,
112 OPTION_SPLIT_BY_RELOC,
113 OPTION_SPLIT_BY_FILE ,
114 OPTION_WHOLE_ARCHIVE,
115 OPTION_AS_NEEDED,
116 OPTION_NO_AS_NEEDED,
117 OPTION_WRAP,
118 OPTION_FORCE_EXE_SUFFIX,
119 OPTION_GC_SECTIONS,
120 OPTION_NO_GC_SECTIONS,
121 OPTION_CHECK_SECTIONS,
122 OPTION_NO_CHECK_SECTIONS,
123 OPTION_NO_UNDEFINED,
124 OPTION_INIT,
125 OPTION_FINI,
126 OPTION_SECTION_START,
127 OPTION_UNIQUE,
128 OPTION_TARGET_HELP,
129 OPTION_ALLOW_SHLIB_UNDEFINED,
130 OPTION_NO_ALLOW_SHLIB_UNDEFINED,
131 OPTION_ALLOW_MULTIPLE_DEFINITION,
132 OPTION_NO_UNDEFINED_VERSION,
133 OPTION_DISCARD_NONE,
134 OPTION_SPARE_DYNAMIC_TAGS,
135 OPTION_NO_DEFINE_COMMON,
136 OPTION_NOSTDLIB,
137 OPTION_NO_OMAGIC,
138 OPTION_STRIP_DISCARDED,
139 OPTION_NO_STRIP_DISCARDED,
140 OPTION_ACCEPT_UNKNOWN_INPUT_ARCH,
141 OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH,
142 OPTION_PIE,
143 OPTION_NOPIE,
144 OPTION_UNRESOLVED_SYMBOLS,
145 OPTION_WARN_UNRESOLVED_SYMBOLS,
146 OPTION_ERROR_UNRESOLVED_SYMBOLS
147 };
148
149 /* The long options. This structure is used for both the option
150 parsing and the help text. */
151
152 struct ld_option
153 {
154 /* The long option information. */
155 struct option opt;
156 /* The short option with the same meaning ('\0' if none). */
157 char shortopt;
158 /* The name of the argument (NULL if none). */
159 const char *arg;
160 /* The documentation string. If this is NULL, this is a synonym for
161 the previous option. */
162 const char *doc;
163 enum {
164 /* Use one dash before long option name. */
165 ONE_DASH,
166 /* Use two dashes before long option name. */
167 TWO_DASHES,
168 /* Only accept two dashes before the long option name.
169 This is an overloading of the use of this enum, since originally it
170 was only intended to tell the --help display function how to display
171 the long option name. This feature was added in order to resolve
172 the confusion about the -omagic command line switch. Is it setting
173 the output file name to "magic" or is it setting the NMAGIC flag on
174 the output ? It has been decided that it is setting the output file
175 name, and that if you want to set the NMAGIC flag you should use -N
176 or --omagic. */
177 EXACTLY_TWO_DASHES,
178 /* Don't mention this option in --help output. */
179 NO_HELP
180 } control;
181 };
182
183 static const struct ld_option ld_options[] =
184 {
185 { {NULL, required_argument, NULL, '\0'},
186 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
187 ONE_DASH },
188 { {"architecture", required_argument, NULL, 'A'},
189 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES },
190 { {"format", required_argument, NULL, 'b'},
191 'b', N_("TARGET"), N_("Specify target for following input files"), TWO_DASHES },
192 { {"mri-script", required_argument, NULL, 'c'},
193 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES },
194 { {"dc", no_argument, NULL, 'd'},
195 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
196 { {"dp", no_argument, NULL, 'd'},
197 '\0', NULL, NULL, ONE_DASH },
198 { {"entry", required_argument, NULL, 'e'},
199 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
200 { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
201 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES },
202 { {"EB", no_argument, NULL, OPTION_EB},
203 '\0', NULL, N_("Link big-endian objects"), ONE_DASH },
204 { {"EL", no_argument, NULL, OPTION_EL},
205 '\0', NULL, N_("Link little-endian objects"), ONE_DASH },
206 { {"auxiliary", required_argument, NULL, 'f'},
207 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
208 TWO_DASHES },
209 { {"filter", required_argument, NULL, 'F'},
210 'F', N_("SHLIB"), N_("Filter for shared object symbol table"), TWO_DASHES },
211 { {NULL, no_argument, NULL, '\0'},
212 'g', NULL, N_("Ignored"), ONE_DASH },
213 { {"gpsize", required_argument, NULL, 'G'},
214 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
215 TWO_DASHES },
216 { {"soname", required_argument, NULL, OPTION_SONAME},
217 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH },
218 { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER},
219 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"), TWO_DASHES },
220 { {"library", required_argument, NULL, 'l'},
221 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES },
222 { {"library-path", required_argument, NULL, 'L'},
223 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"), TWO_DASHES },
224 { {NULL, required_argument, NULL, '\0'},
225 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH },
226 { {"print-map", no_argument, NULL, 'M'},
227 'M', NULL, N_("Print map file on standard output"), TWO_DASHES },
228 { {"nmagic", no_argument, NULL, 'n'},
229 'n', NULL, N_("Do not page align data"), TWO_DASHES },
230 { {"omagic", no_argument, NULL, 'N'},
231 'N', NULL, N_("Do not page align data, do not make text readonly"),
232 EXACTLY_TWO_DASHES },
233 { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC},
234 '\0', NULL, N_("Page align data, make text readonly"), EXACTLY_TWO_DASHES },
235 { {"output", required_argument, NULL, 'o'},
236 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES },
237 { {NULL, required_argument, NULL, '\0'},
238 'O', NULL, N_("Optimize output file"), ONE_DASH },
239 { {"Qy", no_argument, NULL, OPTION_IGNORE},
240 '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH },
241 { {"emit-relocs", no_argument, NULL, 'q'},
242 'q', NULL, "Generate relocations in final output", TWO_DASHES },
243 { {"relocatable", no_argument, NULL, 'r'},
244 'r', NULL, N_("Generate relocatable output"), TWO_DASHES },
245 { {NULL, no_argument, NULL, '\0'},
246 'i', NULL, NULL, ONE_DASH },
247 { {"just-symbols", required_argument, NULL, 'R'},
248 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
249 TWO_DASHES },
250 { {"strip-all", no_argument, NULL, 's'},
251 's', NULL, N_("Strip all symbols"), TWO_DASHES },
252 { {"strip-debug", no_argument, NULL, 'S'},
253 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES },
254 { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED},
255 '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES },
256 { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED},
257 '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES },
258 { {"trace", no_argument, NULL, 't'},
259 't', NULL, N_("Trace file opens"), TWO_DASHES },
260 { {"script", required_argument, NULL, 'T'},
261 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES },
262 { {"undefined", required_argument, NULL, 'u'},
263 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"), TWO_DASHES },
264 { {"unique", optional_argument, NULL, OPTION_UNIQUE},
265 '\0', N_("[=SECTION]"), N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES },
266 { {"Ur", no_argument, NULL, OPTION_UR},
267 '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH },
268 { {"version", no_argument, NULL, OPTION_VERSION},
269 'v', NULL, N_("Print version information"), TWO_DASHES },
270 { {NULL, no_argument, NULL, '\0'},
271 'V', NULL, N_("Print version and emulation information"), ONE_DASH },
272 { {"discard-all", no_argument, NULL, 'x'},
273 'x', NULL, N_("Discard all local symbols"), TWO_DASHES },
274 { {"discard-locals", no_argument, NULL, 'X'},
275 'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES },
276 { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE},
277 '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES },
278 { {"trace-symbol", required_argument, NULL, 'y'},
279 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES },
280 { {NULL, required_argument, NULL, '\0'},
281 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"), ONE_DASH },
282 { {"Zmagic", no_argument, NULL, 'Z'},
283 'Z', NULL, N_("Do not page align got/plt, old style executable"),
284 EXACTLY_TWO_DASHES },
285 { {"start-group", no_argument, NULL, '('},
286 '(', NULL, N_("Start a group"), TWO_DASHES },
287 { {"end-group", no_argument, NULL, ')'},
288 ')', NULL, N_("End a group"), TWO_DASHES },
289 { {"accept-unknown-input-arch", no_argument, NULL, OPTION_ACCEPT_UNKNOWN_INPUT_ARCH},
290 '\0', NULL, N_("Accept input files whose architecture cannot be determined"), TWO_DASHES },
291 { {"no-accept-unknown-input-arch", no_argument, NULL, OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH},
292 '\0', NULL, N_("Reject input files whose architecture is unknown"), TWO_DASHES },
293 { {"assert", required_argument, NULL, OPTION_ASSERT},
294 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH },
295 { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED},
296 '\0', NULL, N_("Link against shared libraries"), ONE_DASH },
297 { {"dy", no_argument, NULL, OPTION_CALL_SHARED},
298 '\0', NULL, NULL, ONE_DASH },
299 { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
300 '\0', NULL, NULL, ONE_DASH },
301 { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED},
302 '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH },
303 { {"dn", no_argument, NULL, OPTION_NON_SHARED},
304 '\0', NULL, NULL, ONE_DASH },
305 { {"non_shared", no_argument, NULL, OPTION_NON_SHARED},
306 '\0', NULL, NULL, ONE_DASH },
307 { {"static", no_argument, NULL, OPTION_NON_SHARED},
308 '\0', NULL, NULL, ONE_DASH },
309 { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC},
310 '\0', NULL, N_("Bind global references locally"), ONE_DASH },
311 { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS},
312 '\0', NULL, N_("Check section addresses for overlaps (default)"), TWO_DASHES },
313 { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS},
314 '\0', NULL, N_("Do not check section addresses for overlaps"),
315 TWO_DASHES },
316 { {"cref", no_argument, NULL, OPTION_CREF},
317 '\0', NULL, N_("Output cross reference table"), TWO_DASHES },
318 { {"defsym", required_argument, NULL, OPTION_DEFSYM},
319 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES },
320 { {"demangle", optional_argument, NULL, OPTION_DEMANGLE},
321 '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"), TWO_DASHES },
322 { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS},
323 '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES},
324 { {"fini", required_argument, NULL, OPTION_FINI},
325 '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH },
326 { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX},
327 '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES},
328 { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS},
329 '\0', NULL, N_("Remove unused sections (on some targets)"),
330 TWO_DASHES },
331 { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS},
332 '\0', NULL, N_("Don't remove unused sections (default)"),
333 TWO_DASHES },
334 { {"help", no_argument, NULL, OPTION_HELP},
335 '\0', NULL, N_("Print option help"), TWO_DASHES },
336 { {"init", required_argument, NULL, OPTION_INIT},
337 '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH },
338 { {"Map", required_argument, NULL, OPTION_MAP},
339 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH },
340 { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON},
341 '\0', NULL, N_("Do not define Common storage"), TWO_DASHES },
342 { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE },
343 '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES },
344 { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
345 '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES },
346 { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED},
347 '\0', NULL, N_("Do not allow unresolved references in object files"), TWO_DASHES },
348 { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED},
349 '\0', NULL, N_("Allow unresolved references in shared libaries"), TWO_DASHES },
350 { {"no-allow-shlib-undefined", no_argument, NULL, OPTION_NO_ALLOW_SHLIB_UNDEFINED},
351 '\0', NULL, N_("Do not allow unresolved references in shared libs"), TWO_DASHES },
352 { {"allow-multiple-definition", no_argument, NULL, OPTION_ALLOW_MULTIPLE_DEFINITION},
353 '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES },
354 { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION},
355 '\0', NULL, N_("Disallow undefined version"), TWO_DASHES },
356 { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH},
357 '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES},
358 { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE},
359 '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES },
360 { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
361 '\0', NULL, N_("Create an output file even if errors occur"), TWO_DASHES },
362 { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
363 '\0', NULL, NULL, NO_HELP },
364 { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB},
365 '\0', NULL, N_("Only use library directories specified on\n\t\t\t\tthe command line"), ONE_DASH },
366 { {"oformat", required_argument, NULL, OPTION_OFORMAT},
367 '\0', N_("TARGET"), N_("Specify target of output file"), EXACTLY_TWO_DASHES },
368 { {"qmagic", no_argument, NULL, OPTION_IGNORE},
369 '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH },
370 { {"relax", no_argument, NULL, OPTION_RELAX},
371 '\0', NULL, N_("Relax branches on certain targets"), TWO_DASHES },
372 { {"retain-symbols-file", required_argument, NULL,
373 OPTION_RETAIN_SYMBOLS_FILE},
374 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES },
375 { {"rpath", required_argument, NULL, OPTION_RPATH},
376 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH },
377 { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK},
378 '\0', N_("PATH"), N_("Set link time shared library search path"), ONE_DASH },
379 { {"shared", no_argument, NULL, OPTION_SHARED},
380 '\0', NULL, N_("Create a shared library"), ONE_DASH },
381 { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */
382 '\0', NULL, NULL, ONE_DASH },
383 { {"pie", no_argument, NULL, OPTION_PIE},
384 '\0', NULL, N_("Create a position independent executable"), ONE_DASH },
385 { {"pic-executable", no_argument, NULL, OPTION_PIE},
386 '\0', NULL, NULL, TWO_DASHES },
387 { {"nopie", no_argument, NULL, OPTION_NOPIE},
388 '\0', NULL, N_("Do not create a position independent executable"), ONE_DASH },
389 { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON},
390 '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES },
391 { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
392 '\0', NULL, NULL, NO_HELP },
393 { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS},
394 '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"), TWO_DASHES },
395 { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE},
396 '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"), TWO_DASHES },
397 { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC},
398 '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"), TWO_DASHES },
399 { {"stats", no_argument, NULL, OPTION_STATS},
400 '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES },
401 { {"target-help", no_argument, NULL, OPTION_TARGET_HELP},
402 '\0', NULL, N_("Display target specific options"), TWO_DASHES },
403 { {"task-link", required_argument, NULL, OPTION_TASK_LINK},
404 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES },
405 { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT},
406 '\0', NULL, N_("Use same format as native linker"), TWO_DASHES },
407 { {"section-start", required_argument, NULL, OPTION_SECTION_START},
408 '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"), TWO_DASHES },
409 { {"Tbss", required_argument, NULL, OPTION_TBSS},
410 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH },
411 { {"Tdata", required_argument, NULL, OPTION_TDATA},
412 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH },
413 { {"Ttext", required_argument, NULL, OPTION_TTEXT},
414 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH },
415 { {"unresolved-symbols=<method>", required_argument, NULL, OPTION_UNRESOLVED_SYMBOLS},
416 '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n\t\t\t\tignore-all, report-all, ignore-in-object-files,\n\t\t\t\tignore-in-shared-libs"),
417 TWO_DASHES },
418 { {"verbose", no_argument, NULL, OPTION_VERBOSE},
419 '\0', NULL, N_("Output lots of information during link"), TWO_DASHES },
420 { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */
421 '\0', NULL, NULL, NO_HELP },
422 { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT },
423 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES },
424 { {"version-exports-section", required_argument, NULL,
425 OPTION_VERSION_EXPORTS_SECTION },
426 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n\t\t\t\tSYMBOL as the version."),
427 TWO_DASHES },
428 { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
429 '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES },
430 { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS},
431 '\0', NULL, N_("Warn if global constructors/destructors are seen"),
432 TWO_DASHES },
433 { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP},
434 '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES },
435 { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE},
436 '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES },
437 { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN},
438 '\0', NULL, N_("Warn if start of section changes due to alignment"),
439 TWO_DASHES },
440 { {"warn-unresolved-symbols", no_argument, NULL, OPTION_WARN_UNRESOLVED_SYMBOLS},
441 '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES },
442 { {"error-unresolved-symbols", no_argument, NULL, OPTION_ERROR_UNRESOLVED_SYMBOLS},
443 '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES },
444 { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL},
445 '\0', NULL, N_("Treat warnings as errors"),
446 TWO_DASHES },
447 { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE},
448 '\0', NULL, N_("Include all objects from following archives"), TWO_DASHES },
449 { {"as-needed", no_argument, NULL, OPTION_AS_NEEDED},
450 '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"), TWO_DASHES },
451 { {"no-as-needed", no_argument, NULL, OPTION_NO_AS_NEEDED},
452 '\0', NULL, N_("Always set DT_NEEDED for following dynamic libs"), TWO_DASHES },
453 { {"wrap", required_argument, NULL, OPTION_WRAP},
454 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES }
455 };
456
457 #define OPTION_COUNT ARRAY_SIZE (ld_options)
458
459 void
parse_args(unsigned argc,char ** argv)460 parse_args (unsigned argc, char **argv)
461 {
462 unsigned i;
463 int is, il, irl;
464 int ingroup = 0;
465 char *default_dirlist = NULL;
466 char *shortopts;
467 struct option *longopts;
468 struct option *really_longopts;
469 int last_optind;
470 enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
471
472 shortopts = xmalloc (OPTION_COUNT * 3 + 2);
473 longopts = xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1));
474 really_longopts = xmalloc (sizeof (*really_longopts) * (OPTION_COUNT + 1));
475
476 /* Starting the short option string with '-' is for programs that
477 expect options and other ARGV-elements in any order and that care about
478 the ordering of the two. We describe each non-option ARGV-element
479 as if it were the argument of an option with character code 1. */
480 shortopts[0] = '-';
481 is = 1;
482 il = 0;
483 irl = 0;
484 for (i = 0; i < OPTION_COUNT; i++)
485 {
486 if (ld_options[i].shortopt != '\0')
487 {
488 shortopts[is] = ld_options[i].shortopt;
489 ++is;
490 if (ld_options[i].opt.has_arg == required_argument
491 || ld_options[i].opt.has_arg == optional_argument)
492 {
493 shortopts[is] = ':';
494 ++is;
495 if (ld_options[i].opt.has_arg == optional_argument)
496 {
497 shortopts[is] = ':';
498 ++is;
499 }
500 }
501 }
502 if (ld_options[i].opt.name != NULL)
503 {
504 if (ld_options[i].control == EXACTLY_TWO_DASHES)
505 {
506 really_longopts[irl] = ld_options[i].opt;
507 ++irl;
508 }
509 else
510 {
511 longopts[il] = ld_options[i].opt;
512 ++il;
513 }
514 }
515 }
516 shortopts[is] = '\0';
517 longopts[il].name = NULL;
518 really_longopts[irl].name = NULL;
519
520 ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts);
521
522 /* The -G option is ambiguous on different platforms. Sometimes it
523 specifies the largest data size to put into the small data
524 section. Sometimes it is equivalent to --shared. Unfortunately,
525 the first form takes an argument, while the second does not.
526
527 We need to permit the --shared form because on some platforms,
528 such as Solaris, gcc -shared will pass -G to the linker.
529
530 To permit either usage, we look through the argument list. If we
531 find -G not followed by a number, we change it into --shared.
532 This will work for most normal cases. */
533 for (i = 1; i < argc; i++)
534 if (strcmp (argv[i], "-G") == 0
535 && (i + 1 >= argc
536 || ! ISDIGIT (argv[i + 1][0])))
537 argv[i] = (char *) "--shared";
538
539 /* Because we permit long options to start with a single dash, and
540 we have a --library option, and the -l option is conventionally
541 used with an immediately following argument, we can have bad
542 results if somebody tries to use -l with a library whose name
543 happens to start with "ibrary", as in -li. We avoid problems by
544 simply turning -l into --library. This means that users will
545 have to use two dashes in order to use --library, which is OK
546 since that's how it is documented.
547
548 FIXME: It's possible that this problem can arise for other short
549 options as well, although the user does always have the recourse
550 of adding a space between the option and the argument. */
551 for (i = 1; i < argc; i++)
552 {
553 if (argv[i][0] == '-'
554 && argv[i][1] == 'l'
555 && argv[i][2] != '\0')
556 {
557 char *n;
558
559 n = xmalloc (strlen (argv[i]) + 20);
560 sprintf (n, "--library=%s", argv[i] + 2);
561 argv[i] = n;
562 }
563 }
564
565 last_optind = -1;
566 while (1)
567 {
568 int longind;
569 int optc;
570
571 /* Using last_optind lets us avoid calling ldemul_parse_args
572 multiple times on a single option, which would lead to
573 confusion in the internal static variables maintained by
574 getopt. This could otherwise happen for an argument like
575 -nx, in which the -n is parsed as a single option, and we
576 loop around to pick up the -x. */
577 if (optind != last_optind)
578 if (ldemul_parse_args (argc, argv))
579 continue;
580
581 /* getopt_long_only is like getopt_long, but '-' as well as '--'
582 can indicate a long option. */
583 opterr = 0;
584 last_optind = optind;
585 optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
586 if (optc == '?')
587 {
588 optind = last_optind;
589 optc = getopt_long (argc, argv, "-", really_longopts, &longind);
590 }
591
592 if (ldemul_handle_option (optc))
593 continue;
594
595 if (optc == -1)
596 break;
597
598 switch (optc)
599 {
600 case '?':
601 einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]);
602 default:
603 einfo (_("%P%F: use the --help option for usage information\n"));
604
605 case 1: /* File name. */
606 lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL);
607 break;
608
609 case OPTION_IGNORE:
610 break;
611 case 'a':
612 /* For HP/UX compatibility. Actually -a shared should mean
613 ``use only shared libraries'' but, then, we don't
614 currently support shared libraries on HP/UX anyhow. */
615 if (strcmp (optarg, "archive") == 0)
616 config.dynamic_link = FALSE;
617 else if (strcmp (optarg, "shared") == 0
618 || strcmp (optarg, "default") == 0)
619 config.dynamic_link = TRUE;
620 else
621 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg);
622 break;
623 case OPTION_ASSERT:
624 /* FIXME: We just ignore these, but we should handle them. */
625 if (strcmp (optarg, "definitions") == 0)
626 ;
627 else if (strcmp (optarg, "nodefinitions") == 0)
628 ;
629 else if (strcmp (optarg, "nosymbolic") == 0)
630 ;
631 else if (strcmp (optarg, "pure-text") == 0)
632 ;
633 else
634 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg);
635 break;
636 case 'A':
637 ldfile_add_arch (optarg);
638 break;
639 case 'b':
640 lang_add_target (optarg);
641 break;
642 case 'c':
643 ldfile_open_command_file (optarg);
644 parser_input = input_mri_script;
645 yyparse ();
646 break;
647 case OPTION_CALL_SHARED:
648 config.dynamic_link = TRUE;
649 break;
650 case OPTION_NON_SHARED:
651 config.dynamic_link = FALSE;
652 break;
653 case OPTION_CREF:
654 command_line.cref = TRUE;
655 link_info.notice_all = TRUE;
656 break;
657 case 'd':
658 command_line.force_common_definition = TRUE;
659 break;
660 case OPTION_DEFSYM:
661 lex_string = optarg;
662 lex_redirect (optarg);
663 parser_input = input_defsym;
664 parsing_defsym = 1;
665 yyparse ();
666 parsing_defsym = 0;
667 lex_string = NULL;
668 break;
669 case OPTION_DEMANGLE:
670 demangling = TRUE;
671 if (optarg != NULL)
672 {
673 enum demangling_styles style;
674
675 style = cplus_demangle_name_to_style (optarg);
676 if (style == unknown_demangling)
677 einfo (_("%F%P: unknown demangling style `%s'"),
678 optarg);
679
680 cplus_demangle_set_style (style);
681 }
682 break;
683 case 'I': /* Used on Solaris. */
684 case OPTION_DYNAMIC_LINKER:
685 command_line.interpreter = optarg;
686 break;
687 case OPTION_EB:
688 command_line.endian = ENDIAN_BIG;
689 break;
690 case OPTION_EL:
691 command_line.endian = ENDIAN_LITTLE;
692 break;
693 case OPTION_EMBEDDED_RELOCS:
694 command_line.embedded_relocs = TRUE;
695 break;
696 case OPTION_EXPORT_DYNAMIC:
697 case 'E': /* HP/UX compatibility. */
698 link_info.export_dynamic = TRUE;
699 break;
700 case 'e':
701 lang_add_entry (optarg, TRUE);
702 break;
703 case 'f':
704 if (command_line.auxiliary_filters == NULL)
705 {
706 command_line.auxiliary_filters = xmalloc (2 * sizeof (char *));
707 command_line.auxiliary_filters[0] = optarg;
708 command_line.auxiliary_filters[1] = NULL;
709 }
710 else
711 {
712 int c;
713 char **p;
714
715 c = 0;
716 for (p = command_line.auxiliary_filters; *p != NULL; p++)
717 ++c;
718 command_line.auxiliary_filters
719 = xrealloc (command_line.auxiliary_filters,
720 (c + 2) * sizeof (char *));
721 command_line.auxiliary_filters[c] = optarg;
722 command_line.auxiliary_filters[c + 1] = NULL;
723 }
724 break;
725 case 'F':
726 command_line.filter_shlib = optarg;
727 break;
728 case OPTION_FORCE_EXE_SUFFIX:
729 command_line.force_exe_suffix = TRUE;
730 break;
731 case 'G':
732 {
733 char *end;
734 g_switch_value = strtoul (optarg, &end, 0);
735 if (*end)
736 einfo (_("%P%F: invalid number `%s'\n"), optarg);
737 }
738 break;
739 case 'g':
740 /* Ignore. */
741 break;
742 case OPTION_GC_SECTIONS:
743 command_line.gc_sections = TRUE;
744 break;
745 case OPTION_HELP:
746 help ();
747 xexit (0);
748 break;
749 case 'L':
750 ldfile_add_library_path (optarg, TRUE);
751 break;
752 case 'l':
753 lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL);
754 break;
755 case 'M':
756 config.map_filename = "-";
757 break;
758 case 'm':
759 /* Ignore. Was handled in a pre-parse. */
760 break;
761 case OPTION_MAP:
762 config.map_filename = optarg;
763 break;
764 case 'N':
765 config.text_read_only = FALSE;
766 config.magic_demand_paged = FALSE;
767 config.dynamic_link = FALSE;
768 break;
769 case OPTION_NO_OMAGIC:
770 config.text_read_only = TRUE;
771 config.magic_demand_paged = TRUE;
772 /* NB/ Does not set dynamic_link to TRUE.
773 Use --call-shared or -Bdynamic for this. */
774 break;
775 case 'n':
776 config.magic_demand_paged = FALSE;
777 config.dynamic_link = FALSE;
778 break;
779 case OPTION_NO_DEFINE_COMMON:
780 command_line.inhibit_common_definition = TRUE;
781 break;
782 case OPTION_NO_DEMANGLE:
783 demangling = FALSE;
784 break;
785 case OPTION_NO_GC_SECTIONS:
786 command_line.gc_sections = FALSE;
787 break;
788 case OPTION_NO_KEEP_MEMORY:
789 link_info.keep_memory = FALSE;
790 break;
791 case OPTION_NO_UNDEFINED:
792 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
793 break;
794 case OPTION_ALLOW_SHLIB_UNDEFINED:
795 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
796 break;
797 case OPTION_NO_ALLOW_SHLIB_UNDEFINED:
798 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
799 break;
800 case OPTION_UNRESOLVED_SYMBOLS:
801 if (strcmp (optarg, "ignore-all") == 0)
802 {
803 link_info.unresolved_syms_in_objects = RM_IGNORE;
804 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
805 }
806 else if (strcmp (optarg, "report-all") == 0)
807 {
808 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
809 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
810 }
811 else if (strcmp (optarg, "ignore-in-object-files") == 0)
812 {
813 link_info.unresolved_syms_in_objects = RM_IGNORE;
814 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
815 }
816 else if (strcmp (optarg, "ignore-in-shared-libs") == 0)
817 {
818 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
819 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
820 }
821 else
822 einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg);
823 break;
824 case OPTION_WARN_UNRESOLVED_SYMBOLS:
825 how_to_report_unresolved_symbols = RM_GENERATE_WARNING;
826 if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR)
827 link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING;
828 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR)
829 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING;
830 break;
831
832 case OPTION_ERROR_UNRESOLVED_SYMBOLS:
833 how_to_report_unresolved_symbols = RM_GENERATE_ERROR;
834 if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING)
835 link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR;
836 if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING)
837 link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR;
838 break;
839 case OPTION_ALLOW_MULTIPLE_DEFINITION:
840 link_info.allow_multiple_definition = TRUE;
841 break;
842 case OPTION_NO_UNDEFINED_VERSION:
843 link_info.allow_undefined_version = FALSE;
844 break;
845 case OPTION_NO_WARN_MISMATCH:
846 command_line.warn_mismatch = FALSE;
847 break;
848 case OPTION_NOINHIBIT_EXEC:
849 force_make_executable = TRUE;
850 break;
851 case OPTION_NOSTDLIB:
852 config.only_cmd_line_lib_dirs = TRUE;
853 break;
854 case OPTION_NO_WHOLE_ARCHIVE:
855 whole_archive = FALSE;
856 break;
857 case 'O':
858 /* FIXME "-O<non-digits> <value>" used to set the address of
859 section <non-digits>. Was this for compatibility with
860 something, or can we create a new option to do that
861 (with a syntax similar to -defsym)?
862 getopt can't handle two args to an option without kludges. */
863
864 /* Enable optimizations of output files. */
865 link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE;
866 break;
867 case 'o':
868 lang_add_output (optarg, 0);
869 break;
870 case OPTION_OFORMAT:
871 lang_add_output_format (optarg, NULL, NULL, 0);
872 break;
873 case 'q':
874 link_info.emitrelocations = TRUE;
875 break;
876 case 'i':
877 case 'r':
878 if (optind == last_optind)
879 /* This can happen if the user put "-rpath,a" on the command
880 line. (Or something similar. The comma is important).
881 Getopt becomes confused and thinks that this is a -r option
882 but it cannot parse the text after the -r so it refuses to
883 increment the optind counter. Detect this case and issue
884 an error message here. We cannot just make this a warning,
885 increment optind, and continue because getopt is too confused
886 and will seg-fault the next time around. */
887 einfo(_("%P%F: bad -rpath option\n"));
888
889 link_info.relocatable = TRUE;
890 config.build_constructors = FALSE;
891 config.magic_demand_paged = FALSE;
892 config.text_read_only = FALSE;
893 config.dynamic_link = FALSE;
894 break;
895 case 'R':
896 /* The GNU linker traditionally uses -R to mean to include
897 only the symbols from a file. The Solaris linker uses -R
898 to set the path used by the runtime linker to find
899 libraries. This is the GNU linker -rpath argument. We
900 try to support both simultaneously by checking the file
901 named. If it is a directory, rather than a regular file,
902 we assume -rpath was meant. */
903 {
904 struct stat s;
905
906 if (stat (optarg, &s) >= 0
907 && ! S_ISDIR (s.st_mode))
908 {
909 lang_add_input_file (optarg,
910 lang_input_file_is_symbols_only_enum,
911 NULL);
912 break;
913 }
914 }
915 /* Fall through. */
916 case OPTION_RPATH:
917 if (command_line.rpath == NULL)
918 command_line.rpath = xstrdup (optarg);
919 else
920 {
921 size_t rpath_len = strlen (command_line.rpath);
922 size_t optarg_len = strlen (optarg);
923 char *buf;
924 char *cp = command_line.rpath;
925
926 /* First see whether OPTARG is already in the path. */
927 do
928 {
929 size_t idx = 0;
930
931 while (optarg[idx] != '\0' && optarg[idx] == cp[idx])
932 ++idx;
933 if (optarg[idx] == '\0'
934 && (cp[idx] == '\0' || cp[idx] == ':'))
935 /* We found it. */
936 break;
937
938 /* Not yet found. */
939 cp = strchr (cp, ':');
940 if (cp != NULL)
941 ++cp;
942 }
943 while (cp != NULL);
944
945 if (cp == NULL)
946 {
947 buf = xmalloc (rpath_len + optarg_len + 2);
948 sprintf (buf, "%s:%s", command_line.rpath, optarg);
949 free (command_line.rpath);
950 command_line.rpath = buf;
951 }
952 }
953 break;
954 case OPTION_RPATH_LINK:
955 if (command_line.rpath_link == NULL)
956 command_line.rpath_link = xstrdup (optarg);
957 else
958 {
959 char *buf;
960
961 buf = xmalloc (strlen (command_line.rpath_link)
962 + strlen (optarg)
963 + 2);
964 sprintf (buf, "%s:%s", command_line.rpath_link, optarg);
965 free (command_line.rpath_link);
966 command_line.rpath_link = buf;
967 }
968 break;
969 case OPTION_RELAX:
970 command_line.relax = TRUE;
971 break;
972 case OPTION_RETAIN_SYMBOLS_FILE:
973 add_keepsyms_file (optarg);
974 break;
975 case 'S':
976 link_info.strip = strip_debugger;
977 break;
978 case 's':
979 link_info.strip = strip_all;
980 break;
981 case OPTION_STRIP_DISCARDED:
982 link_info.strip_discarded = TRUE;
983 break;
984 case OPTION_NO_STRIP_DISCARDED:
985 link_info.strip_discarded = FALSE;
986 break;
987 case OPTION_SHARED:
988 if (config.has_shared)
989 {
990 link_info.shared = TRUE;
991 link_info.pie = FALSE;
992 /* When creating a shared library, the default
993 behaviour is to ignore any unresolved references. */
994 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
995 link_info.unresolved_syms_in_objects = RM_IGNORE;
996 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
997 link_info.unresolved_syms_in_shared_libs = RM_IGNORE;
998 }
999 else
1000 einfo (_("%P%F: -shared not supported\n"));
1001 break;
1002 case OPTION_PIE:
1003 if (config.has_shared)
1004 {
1005 link_info.shared = TRUE;
1006 link_info.pie = TRUE;
1007 }
1008 else
1009 einfo (_("%P%F: -pie not supported\n"));
1010 break;
1011 case OPTION_NOPIE:
1012 if (config.has_shared)
1013 {
1014 link_info.shared = FALSE;
1015 link_info.pie = FALSE;
1016 }
1017 else
1018 einfo (_("%P%F: -nopie not supported\n"));
1019 break;
1020 case 'h': /* Used on Solaris. */
1021 case OPTION_SONAME:
1022 command_line.soname = optarg;
1023 break;
1024 case OPTION_SORT_COMMON:
1025 config.sort_common = TRUE;
1026 break;
1027 case OPTION_STATS:
1028 config.stats = TRUE;
1029 break;
1030 case OPTION_SYMBOLIC:
1031 link_info.symbolic = TRUE;
1032 break;
1033 case 't':
1034 trace_files = TRUE;
1035 break;
1036 case 'T':
1037 ldfile_open_command_file (optarg);
1038 parser_input = input_script;
1039 yyparse ();
1040 break;
1041 case OPTION_SECTION_START:
1042 {
1043 char *optarg2;
1044 char *sec_name;
1045 int len;
1046
1047 /* Check for <something>=<somthing>... */
1048 optarg2 = strchr (optarg, '=');
1049 if (optarg2 == NULL)
1050 einfo (_("%P%F: invalid argument to option \"--section-start\"\n"));
1051
1052 optarg2++;
1053
1054 /* So far so good. Are all the args present? */
1055 if ((*optarg == '\0') || (*optarg2 == '\0'))
1056 einfo (_("%P%F: missing argument(s) to option \"--section-start\"\n"));
1057
1058 /* We must copy the section name as set_section_start
1059 doesn't do it for us. */
1060 len = optarg2 - optarg;
1061 sec_name = xmalloc (len);
1062 memcpy (sec_name, optarg, len - 1);
1063 sec_name[len - 1] = 0;
1064
1065 /* Then set it... */
1066 set_section_start (sec_name, optarg2);
1067 }
1068 break;
1069 case OPTION_TARGET_HELP:
1070 /* Mention any target specific options. */
1071 ldemul_list_emulation_options (stdout);
1072 exit (0);
1073 case OPTION_TBSS:
1074 set_section_start (".bss", optarg);
1075 break;
1076 case OPTION_TDATA:
1077 set_section_start (".data", optarg);
1078 break;
1079 case OPTION_TTEXT:
1080 set_section_start (".text", optarg);
1081 break;
1082 case OPTION_TRADITIONAL_FORMAT:
1083 link_info.traditional_format = TRUE;
1084 break;
1085 case OPTION_TASK_LINK:
1086 link_info.task_link = TRUE;
1087 /* Fall through - do an implied -r option. */
1088 case OPTION_UR:
1089 link_info.relocatable = TRUE;
1090 config.build_constructors = TRUE;
1091 config.magic_demand_paged = FALSE;
1092 config.text_read_only = FALSE;
1093 config.dynamic_link = FALSE;
1094 break;
1095 case 'u':
1096 ldlang_add_undef (optarg);
1097 break;
1098 case OPTION_UNIQUE:
1099 if (optarg != NULL)
1100 lang_add_unique (optarg);
1101 else
1102 config.unique_orphan_sections = TRUE;
1103 break;
1104 case OPTION_VERBOSE:
1105 ldversion (1);
1106 version_printed = TRUE;
1107 trace_file_tries = TRUE;
1108 overflow_cutoff_limit = -2;
1109 break;
1110 case 'v':
1111 ldversion (0);
1112 version_printed = TRUE;
1113 break;
1114 case 'V':
1115 ldversion (1);
1116 version_printed = TRUE;
1117 break;
1118 case OPTION_VERSION:
1119 ldversion (2);
1120 xexit (0);
1121 break;
1122 case OPTION_VERSION_SCRIPT:
1123 /* This option indicates a small script that only specifies
1124 version information. Read it, but don't assume that
1125 we've seen a linker script. */
1126 {
1127 FILE *hold_script_handle;
1128
1129 hold_script_handle = saved_script_handle;
1130 ldfile_open_command_file (optarg);
1131 saved_script_handle = hold_script_handle;
1132 parser_input = input_version_script;
1133 yyparse ();
1134 }
1135 break;
1136 case OPTION_VERSION_EXPORTS_SECTION:
1137 /* This option records a version symbol to be applied to the
1138 symbols listed for export to be found in the object files
1139 .exports sections. */
1140 command_line.version_exports_section = optarg;
1141 break;
1142 case OPTION_WARN_COMMON:
1143 config.warn_common = TRUE;
1144 break;
1145 case OPTION_WARN_CONSTRUCTORS:
1146 config.warn_constructors = TRUE;
1147 break;
1148 case OPTION_WARN_FATAL:
1149 config.fatal_warnings = TRUE;
1150 break;
1151 case OPTION_WARN_MULTIPLE_GP:
1152 config.warn_multiple_gp = TRUE;
1153 break;
1154 case OPTION_WARN_ONCE:
1155 config.warn_once = TRUE;
1156 break;
1157 case OPTION_WARN_SECTION_ALIGN:
1158 config.warn_section_align = TRUE;
1159 break;
1160 case OPTION_WHOLE_ARCHIVE:
1161 whole_archive = TRUE;
1162 break;
1163 case OPTION_AS_NEEDED:
1164 as_needed = TRUE;
1165 break;
1166 case OPTION_NO_AS_NEEDED:
1167 as_needed = FALSE;
1168 break;
1169 case OPTION_WRAP:
1170 add_wrap (optarg);
1171 break;
1172 case OPTION_DISCARD_NONE:
1173 link_info.discard = discard_none;
1174 break;
1175 case 'X':
1176 link_info.discard = discard_l;
1177 break;
1178 case 'x':
1179 link_info.discard = discard_all;
1180 break;
1181 case 'Y':
1182 if (strncmp (optarg, "P,", 2) == 0)
1183 optarg += 2;
1184 if (default_dirlist != NULL)
1185 free (default_dirlist);
1186 default_dirlist = xstrdup (optarg);
1187 break;
1188 case 'y':
1189 add_ysym (optarg);
1190 break;
1191 case 'Z':
1192 config.data_bss_contig = TRUE;
1193 break;
1194 case OPTION_SPARE_DYNAMIC_TAGS:
1195 link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0);
1196 break;
1197 case OPTION_SPLIT_BY_RELOC:
1198 if (optarg != NULL)
1199 config.split_by_reloc = strtoul (optarg, NULL, 0);
1200 else
1201 config.split_by_reloc = 32768;
1202 break;
1203 case OPTION_SPLIT_BY_FILE:
1204 if (optarg != NULL)
1205 config.split_by_file = bfd_scan_vma (optarg, NULL, 0);
1206 else
1207 config.split_by_file = 1;
1208 break;
1209 case OPTION_CHECK_SECTIONS:
1210 command_line.check_section_addresses = TRUE;
1211 break;
1212 case OPTION_NO_CHECK_SECTIONS:
1213 command_line.check_section_addresses = FALSE;
1214 break;
1215 case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH:
1216 command_line.accept_unknown_input_arch = TRUE;
1217 break;
1218 case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH:
1219 command_line.accept_unknown_input_arch = FALSE;
1220 break;
1221 case '(':
1222 if (ingroup)
1223 einfo (_("%P%F: may not nest groups (--help for usage)\n"));
1224
1225 lang_enter_group ();
1226 ingroup = 1;
1227 break;
1228 case ')':
1229 if (! ingroup)
1230 einfo (_("%P%F: group ended before it began (--help for usage)\n"));
1231
1232 lang_leave_group ();
1233 ingroup = 0;
1234 break;
1235
1236 case OPTION_INIT:
1237 link_info.init_function = optarg;
1238 break;
1239
1240 case OPTION_FINI:
1241 link_info.fini_function = optarg;
1242 break;
1243 }
1244 }
1245
1246 if (ingroup)
1247 lang_leave_group ();
1248
1249 if (default_dirlist != NULL)
1250 {
1251 set_default_dirlist (default_dirlist);
1252 free (default_dirlist);
1253 }
1254
1255 if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET)
1256 /* FIXME: Should we allow emulations a chance to set this ? */
1257 link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols;
1258
1259 if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET)
1260 /* FIXME: Should we allow emulations a chance to set this ? */
1261 link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols;
1262 }
1263
1264 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1265 library search path. */
1266
1267 static void
set_default_dirlist(char * dirlist_ptr)1268 set_default_dirlist (char *dirlist_ptr)
1269 {
1270 char *p;
1271
1272 while (1)
1273 {
1274 p = strchr (dirlist_ptr, PATH_SEPARATOR);
1275 if (p != NULL)
1276 *p = '\0';
1277 if (*dirlist_ptr != '\0')
1278 ldfile_add_library_path (dirlist_ptr, TRUE);
1279 if (p == NULL)
1280 break;
1281 dirlist_ptr = p + 1;
1282 }
1283 }
1284
1285 static void
set_section_start(char * sect,char * valstr)1286 set_section_start (char *sect, char *valstr)
1287 {
1288 const char *end;
1289 bfd_vma val = bfd_scan_vma (valstr, &end, 16);
1290 if (*end)
1291 einfo (_("%P%F: invalid hex number `%s'\n"), valstr);
1292 lang_section_start (sect, exp_intop (val));
1293 }
1294
1295 /* Print help messages for the options. */
1296
1297 static void
help(void)1298 help (void)
1299 {
1300 unsigned i;
1301 const char **targets, **pp;
1302
1303 printf (_("Usage: %s [options] file...\n"), program_name);
1304
1305 printf (_("Options:\n"));
1306 for (i = 0; i < OPTION_COUNT; i++)
1307 {
1308 if (ld_options[i].doc != NULL)
1309 {
1310 bfd_boolean comma;
1311 int len;
1312 unsigned j;
1313
1314 printf (" ");
1315
1316 comma = FALSE;
1317 len = 2;
1318
1319 j = i;
1320 do
1321 {
1322 if (ld_options[j].shortopt != '\0'
1323 && ld_options[j].control != NO_HELP)
1324 {
1325 printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt);
1326 len += (comma ? 2 : 0) + 2;
1327 if (ld_options[j].arg != NULL)
1328 {
1329 if (ld_options[j].opt.has_arg != optional_argument)
1330 {
1331 printf (" ");
1332 ++len;
1333 }
1334 printf ("%s", _(ld_options[j].arg));
1335 len += strlen (_(ld_options[j].arg));
1336 }
1337 comma = TRUE;
1338 }
1339 ++j;
1340 }
1341 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1342
1343 j = i;
1344 do
1345 {
1346 if (ld_options[j].opt.name != NULL
1347 && ld_options[j].control != NO_HELP)
1348 {
1349 int two_dashes =
1350 (ld_options[j].control == TWO_DASHES
1351 || ld_options[j].control == EXACTLY_TWO_DASHES);
1352
1353 printf ("%s-%s%s",
1354 comma ? ", " : "",
1355 two_dashes ? "-" : "",
1356 ld_options[j].opt.name);
1357 len += ((comma ? 2 : 0)
1358 + 1
1359 + (two_dashes ? 1 : 0)
1360 + strlen (ld_options[j].opt.name));
1361 if (ld_options[j].arg != NULL)
1362 {
1363 printf (" %s", _(ld_options[j].arg));
1364 len += 1 + strlen (_(ld_options[j].arg));
1365 }
1366 comma = TRUE;
1367 }
1368 ++j;
1369 }
1370 while (j < OPTION_COUNT && ld_options[j].doc == NULL);
1371
1372 if (len >= 30)
1373 {
1374 printf ("\n");
1375 len = 0;
1376 }
1377
1378 for (; len < 30; len++)
1379 putchar (' ');
1380
1381 printf ("%s\n", _(ld_options[i].doc));
1382 }
1383 }
1384
1385 /* Note: Various tools (such as libtool) depend upon the
1386 format of the listings below - do not change them. */
1387 /* xgettext:c-format */
1388 printf (_("%s: supported targets:"), program_name);
1389 targets = bfd_target_list ();
1390 for (pp = targets; *pp != NULL; pp++)
1391 printf (" %s", *pp);
1392 free (targets);
1393 printf ("\n");
1394
1395 /* xgettext:c-format */
1396 printf (_("%s: supported emulations: "), program_name);
1397 ldemul_list_emulations (stdout);
1398 printf ("\n");
1399
1400 /* xgettext:c-format */
1401 printf (_("%s: emulation specific options:\n"), program_name);
1402 ldemul_list_emulation_options (stdout);
1403 printf ("\n");
1404
1405 printf (_("Report bugs to %s\n"), REPORT_BUGS_TO);
1406 }
1407