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