1 /* Parse options for the GNU linker.
2 Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GLD, the Gnu Linker.
7 GLD is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GLD is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GLD; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
24 #include "libiberty.h"
41 #ifndef PATH_SEPARATOR
42 #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__))
43 #define PATH_SEPARATOR ';'
45 #define PATH_SEPARATOR ':'
49 /* Somewhere above, sys/stat.h got included . . . . */
50 #if !defined(S_ISDIR) && defined(S_IFDIR)
51 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
54 /* Omit args to avoid the possibility of clashing with a system header
55 that might disagree about consts. */
56 unsigned long strtoul ();
58 static void set_default_dirlist
PARAMS ((char *dirlist_ptr
));
59 static void set_section_start
PARAMS ((char *sect
, char *valstr
));
60 static void help
PARAMS ((void));
62 /* Non-zero if we are processing a --defsym from the command line. */
63 int parsing_defsym
= 0;
65 /* Codes used for the long options with no short synonyms. 150 isn't
66 special; it's just an arbitrary non-ASCII char value. */
68 #define OPTION_ASSERT 150
69 #define OPTION_CALL_SHARED (OPTION_ASSERT + 1)
70 #define OPTION_CREF (OPTION_CALL_SHARED + 1)
71 #define OPTION_DEFSYM (OPTION_CREF + 1)
72 #define OPTION_DEMANGLE (OPTION_DEFSYM + 1)
73 #define OPTION_DYNAMIC_LINKER (OPTION_DEMANGLE + 1)
74 #define OPTION_EB (OPTION_DYNAMIC_LINKER + 1)
75 #define OPTION_EL (OPTION_EB + 1)
76 #define OPTION_EMBEDDED_RELOCS (OPTION_EL + 1)
77 #define OPTION_EXPORT_DYNAMIC (OPTION_EMBEDDED_RELOCS + 1)
78 #define OPTION_HELP (OPTION_EXPORT_DYNAMIC + 1)
79 #define OPTION_IGNORE (OPTION_HELP + 1)
80 #define OPTION_MAP (OPTION_IGNORE + 1)
81 #define OPTION_NO_DEMANGLE (OPTION_MAP + 1)
82 #define OPTION_NO_KEEP_MEMORY (OPTION_NO_DEMANGLE + 1)
83 #define OPTION_NO_WARN_MISMATCH (OPTION_NO_KEEP_MEMORY + 1)
84 #define OPTION_NOINHIBIT_EXEC (OPTION_NO_WARN_MISMATCH + 1)
85 #define OPTION_NON_SHARED (OPTION_NOINHIBIT_EXEC + 1)
86 #define OPTION_NO_WHOLE_ARCHIVE (OPTION_NON_SHARED + 1)
87 #define OPTION_OFORMAT (OPTION_NO_WHOLE_ARCHIVE + 1)
88 #define OPTION_RELAX (OPTION_OFORMAT + 1)
89 #define OPTION_RETAIN_SYMBOLS_FILE (OPTION_RELAX + 1)
90 #define OPTION_RPATH (OPTION_RETAIN_SYMBOLS_FILE + 1)
91 #define OPTION_RPATH_LINK (OPTION_RPATH + 1)
92 #define OPTION_SHARED (OPTION_RPATH_LINK + 1)
93 #define OPTION_SONAME (OPTION_SHARED + 1)
94 #define OPTION_SORT_COMMON (OPTION_SONAME + 1)
95 #define OPTION_STATS (OPTION_SORT_COMMON + 1)
96 #define OPTION_SYMBOLIC (OPTION_STATS + 1)
97 #define OPTION_TASK_LINK (OPTION_SYMBOLIC + 1)
98 #define OPTION_TBSS (OPTION_TASK_LINK + 1)
99 #define OPTION_TDATA (OPTION_TBSS + 1)
100 #define OPTION_TTEXT (OPTION_TDATA + 1)
101 #define OPTION_TRADITIONAL_FORMAT (OPTION_TTEXT + 1)
102 #define OPTION_UR (OPTION_TRADITIONAL_FORMAT + 1)
103 #define OPTION_VERBOSE (OPTION_UR + 1)
104 #define OPTION_VERSION (OPTION_VERBOSE + 1)
105 #define OPTION_VERSION_SCRIPT (OPTION_VERSION + 1)
106 #define OPTION_VERSION_EXPORTS_SECTION (OPTION_VERSION_SCRIPT + 1)
107 #define OPTION_WARN_COMMON (OPTION_VERSION_EXPORTS_SECTION + 1)
108 #define OPTION_WARN_CONSTRUCTORS (OPTION_WARN_COMMON + 1)
109 #define OPTION_WARN_MULTIPLE_GP (OPTION_WARN_CONSTRUCTORS + 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)
124 /* The long options. This structure is used for both the option
125 parsing and the help text. */
129 /* The long option information. */
131 /* The short option with the same meaning ('\0' if none). */
133 /* The name of the argument (NULL if none). */
135 /* The documentation string. If this is NULL, this is a synonym for
136 the previous option. */
140 /* Use one dash before long option name. */
142 /* Use two dashes before long option name. */
144 /* Don't mention this option in --help output. */
149 static const struct ld_option ld_options
[] =
151 { {NULL
, required_argument
, NULL
, '\0'},
152 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"),
154 { {"architecture", required_argument
, NULL
, 'A'},
155 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES
},
156 { {"format", required_argument
, NULL
, 'b'},
157 'b', N_("TARGET"), N_("Specify target for following input files"), TWO_DASHES
},
158 { {"mri-script", required_argument
, NULL
, 'c'},
159 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES
},
160 { {"dc", no_argument
, NULL
, 'd'},
161 'd', NULL
, N_("Force common symbols to be defined"), ONE_DASH
},
162 { {"dp", no_argument
, NULL
, 'd'},
163 '\0', NULL
, NULL
, ONE_DASH
},
164 { {"entry", required_argument
, NULL
, 'e'},
165 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES
},
166 { {"export-dynamic", no_argument
, NULL
, OPTION_EXPORT_DYNAMIC
},
167 'E', NULL
, N_("Export all dynamic symbols"), TWO_DASHES
},
168 { {"EB", no_argument
, NULL
, OPTION_EB
},
169 '\0', NULL
, N_("Link big-endian objects"), ONE_DASH
},
170 { {"EL", no_argument
, NULL
, OPTION_EL
},
171 '\0', NULL
, N_("Link little-endian objects"), ONE_DASH
},
172 { {"auxiliary", required_argument
, NULL
, 'f'},
173 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"),
175 { {"filter", required_argument
, NULL
, 'F'},
176 'F', N_("SHLIB"), N_("Filter for shared object symbol table"), TWO_DASHES
},
177 { {NULL
, no_argument
, NULL
, '\0'},
178 'g', NULL
, N_("Ignored"), ONE_DASH
},
179 { {"gpsize", required_argument
, NULL
, 'G'},
180 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"),
182 { {"soname", required_argument
, NULL
, OPTION_SONAME
},
183 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH
},
184 { {"library", required_argument
, NULL
, 'l'},
185 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES
},
186 { {"library-path", required_argument
, NULL
, 'L'},
187 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"), TWO_DASHES
},
188 { {NULL
, required_argument
, NULL
, '\0'},
189 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH
},
190 { {"print-map", no_argument
, NULL
, 'M'},
191 'M', NULL
, N_("Print map file on standard output"), TWO_DASHES
},
192 { {"nmagic", no_argument
, NULL
, 'n'},
193 'n', NULL
, N_("Do not page align data"), TWO_DASHES
},
194 { {"omagic", no_argument
, NULL
, 'N'},
195 'N', NULL
, N_("Do not page align data, do not make text readonly"),
197 { {"output", required_argument
, NULL
, 'o'},
198 'o', N_("FILE"), N_("Set output file name"), TWO_DASHES
},
199 { {NULL
, required_argument
, NULL
, '\0'},
200 'O', NULL
, N_("Optimize output file"), ONE_DASH
},
201 { {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
202 '\0', NULL
, N_("Ignored for SVR4 compatibility"), ONE_DASH
},
203 { {"relocateable", no_argument
, NULL
, 'r'},
204 'r', NULL
, N_("Generate relocateable output"), TWO_DASHES
},
205 { {NULL
, no_argument
, NULL
, '\0'},
206 'i', NULL
, NULL
, ONE_DASH
},
207 { {"just-symbols", required_argument
, NULL
, 'R'},
208 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"),
210 { {"strip-all", no_argument
, NULL
, 's'},
211 's', NULL
, N_("Strip all symbols"), TWO_DASHES
},
212 { {"strip-debug", no_argument
, NULL
, 'S'},
213 'S', NULL
, N_("Strip debugging symbols"), TWO_DASHES
},
214 { {"trace", no_argument
, NULL
, 't'},
215 't', NULL
, N_("Trace file opens"), TWO_DASHES
},
216 { {"script", required_argument
, NULL
, 'T'},
217 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES
},
218 { {"undefined", required_argument
, NULL
, 'u'},
219 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"), TWO_DASHES
},
220 { {"Ur", no_argument
, NULL
, OPTION_UR
},
221 '\0', NULL
, N_("Build global constructor/destructor tables"), ONE_DASH
},
222 { {"version", no_argument
, NULL
, OPTION_VERSION
},
223 'v', NULL
, N_("Print version information"), TWO_DASHES
},
224 { {NULL
, no_argument
, NULL
, '\0'},
225 'V', NULL
, N_("Print version and emulation information"), ONE_DASH
},
226 { {"discard-all", no_argument
, NULL
, 'x'},
227 'x', NULL
, N_("Discard all local symbols"), TWO_DASHES
},
228 { {"discard-locals", no_argument
, NULL
, 'X'},
229 'X', NULL
, N_("Discard temporary local symbols"), TWO_DASHES
},
230 { {"trace-symbol", required_argument
, NULL
, 'y'},
231 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES
},
232 { {NULL
, required_argument
, NULL
, '\0'},
233 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"), ONE_DASH
},
234 { {NULL
, required_argument
, NULL
, '\0'},
235 'z', N_("KEYWORD"), N_("Ignored for Solaris compatibility"), ONE_DASH
},
236 { {"start-group", no_argument
, NULL
, '('},
237 '(', NULL
, N_("Start a group"), TWO_DASHES
},
238 { {"end-group", no_argument
, NULL
, ')'},
239 ')', NULL
, N_("End a group"), TWO_DASHES
},
240 { {"assert", required_argument
, NULL
, OPTION_ASSERT
},
241 '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH
},
242 { {"Bdynamic", no_argument
, NULL
, OPTION_CALL_SHARED
},
243 '\0', NULL
, N_("Link against shared libraries"), ONE_DASH
},
244 { {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
245 '\0', NULL
, NULL
, ONE_DASH
},
246 { {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
247 '\0', NULL
, NULL
, ONE_DASH
},
248 { {"Bstatic", no_argument
, NULL
, OPTION_NON_SHARED
},
249 '\0', NULL
, N_("Do not link against shared libraries"), ONE_DASH
},
250 { {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
251 '\0', NULL
, NULL
, ONE_DASH
},
252 { {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
253 '\0', NULL
, NULL
, ONE_DASH
},
254 { {"static", no_argument
, NULL
, OPTION_NON_SHARED
},
255 '\0', NULL
, NULL
, ONE_DASH
},
256 { {"Bsymbolic", no_argument
, NULL
, OPTION_SYMBOLIC
},
257 '\0', NULL
, N_("Bind global references locally"), ONE_DASH
},
258 { {"check-sections", no_argument
, NULL
, OPTION_CHECK_SECTIONS
},
259 '\0', NULL
, N_("Check section addresses for overlaps (default)"), TWO_DASHES
},
260 { {"no-check-sections", no_argument
, NULL
, OPTION_NO_CHECK_SECTIONS
},
261 '\0', NULL
, N_("Do not check section addresses for overlaps"),
263 { {"cref", no_argument
, NULL
, OPTION_CREF
},
264 '\0', NULL
, N_("Output cross reference table"), TWO_DASHES
},
265 { {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
266 '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES
},
267 { {"demangle", no_argument
, NULL
, OPTION_DEMANGLE
},
268 '\0', NULL
, N_("Demangle symbol names"), TWO_DASHES
},
269 { {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
270 '\0', N_("PROGRAM"), N_("Set the dynamic linker to use"), TWO_DASHES
},
271 { {"embedded-relocs", no_argument
, NULL
, OPTION_EMBEDDED_RELOCS
},
272 '\0', NULL
, N_("Generate embedded relocs"), TWO_DASHES
},
273 { {"force-exe-suffix", no_argument
, NULL
, OPTION_FORCE_EXE_SUFFIX
},
274 '\0', NULL
, N_("Force generation of file with .exe suffix"), TWO_DASHES
},
275 { {"gc-sections", no_argument
, NULL
, OPTION_GC_SECTIONS
},
276 '\0', NULL
, N_("Remove unused sections (on some targets)"),
278 { {"no-gc-sections", no_argument
, NULL
, OPTION_NO_GC_SECTIONS
},
279 '\0', NULL
, N_("Don't remove unused sections (default)"),
281 { {"help", no_argument
, NULL
, OPTION_HELP
},
282 '\0', NULL
, N_("Print option help"), TWO_DASHES
},
283 { {"Map", required_argument
, NULL
, OPTION_MAP
},
284 '\0', N_("FILE"), N_("Write a map file"), ONE_DASH
},
285 { {"no-demangle", no_argument
, NULL
, OPTION_NO_DEMANGLE
},
286 '\0', NULL
, N_("Do not demangle symbol names"), TWO_DASHES
},
287 { {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
288 '\0', NULL
, N_("Use less memory and more disk I/O"), TWO_DASHES
},
289 { {"no-undefined", no_argument
, NULL
, OPTION_NO_UNDEFINED
},
290 '\0', NULL
, N_("Allow no undefined symbols"), TWO_DASHES
},
291 { {"no-warn-mismatch", no_argument
, NULL
, OPTION_NO_WARN_MISMATCH
},
292 '\0', NULL
, N_("Don't warn about mismatched input files"), TWO_DASHES
},
293 { {"no-whole-archive", no_argument
, NULL
, OPTION_NO_WHOLE_ARCHIVE
},
294 '\0', NULL
, N_("Turn off --whole-archive"), TWO_DASHES
},
295 { {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
296 '\0', NULL
, N_("Create an output file even if errors occur"), TWO_DASHES
},
297 { {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
298 '\0', NULL
, NULL
, NO_HELP
},
299 { {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
300 '\0', N_("TARGET"), N_("Specify target of output file"), TWO_DASHES
},
301 { {"qmagic", no_argument
, NULL
, OPTION_IGNORE
},
302 '\0', NULL
, N_("Ignored for Linux compatibility"), ONE_DASH
},
303 { {"relax", no_argument
, NULL
, OPTION_RELAX
},
304 '\0', NULL
, N_("Relax branches on certain targets"), TWO_DASHES
},
305 { {"retain-symbols-file", required_argument
, NULL
,
306 OPTION_RETAIN_SYMBOLS_FILE
},
307 '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES
},
308 { {"rpath", required_argument
, NULL
, OPTION_RPATH
},
309 '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH
},
310 { {"rpath-link", required_argument
, NULL
, OPTION_RPATH_LINK
},
311 '\0', N_("PATH"), N_("Set link time shared library search path"), ONE_DASH
},
312 { {"shared", no_argument
, NULL
, OPTION_SHARED
},
313 '\0', NULL
, N_("Create a shared library"), ONE_DASH
},
314 { {"Bshareable", no_argument
, NULL
, OPTION_SHARED
}, /* FreeBSD. */
315 '\0', NULL
, NULL
, ONE_DASH
},
316 { {"sort-common", no_argument
, NULL
, OPTION_SORT_COMMON
},
317 '\0', NULL
, N_("Sort common symbols by size"), TWO_DASHES
},
318 { {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
319 '\0', NULL
, NULL
, NO_HELP
},
320 { {"split-by-file", no_argument
, NULL
, OPTION_SPLIT_BY_FILE
},
321 '\0', NULL
, N_("Split output sections for each file"), TWO_DASHES
},
322 { {"split-by-reloc", required_argument
, NULL
, OPTION_SPLIT_BY_RELOC
},
323 '\0', N_("COUNT"), N_("Split output sections every COUNT relocs"), TWO_DASHES
},
324 { {"stats", no_argument
, NULL
, OPTION_STATS
},
325 '\0', NULL
, N_("Print memory usage statistics"), TWO_DASHES
},
326 { {"task-link", required_argument
, NULL
, OPTION_TASK_LINK
},
327 '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES
},
328 { {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
329 '\0', NULL
, N_("Use same format as native linker"), TWO_DASHES
},
330 { {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
331 '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH
},
332 { {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
333 '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH
},
334 { {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
335 '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH
},
336 { {"verbose", no_argument
, NULL
, OPTION_VERBOSE
},
337 '\0', NULL
, N_("Output lots of information during link"), TWO_DASHES
},
338 { {"dll-verbose", no_argument
, NULL
, OPTION_VERBOSE
}, /* Linux. */
339 '\0', NULL
, NULL
, NO_HELP
},
340 { {"version-script", required_argument
, NULL
, OPTION_VERSION_SCRIPT
},
341 '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES
},
342 { {"version-exports-section", required_argument
, NULL
,
343 OPTION_VERSION_EXPORTS_SECTION
},
344 '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using SYMBOL as the version."),
346 { {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
347 '\0', NULL
, N_("Warn about duplicate common symbols"), TWO_DASHES
},
348 { {"warn-constructors", no_argument
, NULL
, OPTION_WARN_CONSTRUCTORS
},
349 '\0', NULL
, N_("Warn if global constructors/destructors are seen"),
351 { {"warn-multiple-gp", no_argument
, NULL
, OPTION_WARN_MULTIPLE_GP
},
352 '\0', NULL
, N_("Warn if the multiple GP values are used"), TWO_DASHES
},
353 { {"warn-once", no_argument
, NULL
, OPTION_WARN_ONCE
},
354 '\0', NULL
, N_("Warn only once per undefined symbol"), TWO_DASHES
},
355 { {"warn-section-align", no_argument
, NULL
, OPTION_WARN_SECTION_ALIGN
},
356 '\0', NULL
, N_("Warn if start of section changes due to alignment"),
358 { {"whole-archive", no_argument
, NULL
, OPTION_WHOLE_ARCHIVE
},
359 '\0', NULL
, N_("Include all objects from following archives"), TWO_DASHES
},
360 { {"wrap", required_argument
, NULL
, OPTION_WRAP
},
361 '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES
},
362 { {"mpc860c0", optional_argument
, NULL
, OPTION_MPC860C0
},
363 '\0', N_("[=WORDS]"), N_("Modify problematic branches in last WORDS (1-10, default 5) words of a page"), TWO_DASHES
}
366 #define OPTION_COUNT ((int) (sizeof ld_options / sizeof ld_options[0]))
368 /* Test "string" for containing a string of digits that form a number
369 between "min" and "max". The return value is the number or "err". */
371 int is_num( char *string
, int min
, int max
, int err
)
375 for ( ; *string
; ++string
)
377 if (!isdigit(*string
))
382 result
= result
* 10 + (*string
- '0');
384 if (result
< min
|| result
> max
)
391 parse_args (argc
, argv
)
397 char *default_dirlist
= NULL
;
398 char shortopts
[OPTION_COUNT
* 3 + 2];
399 struct option longopts
[OPTION_COUNT
+ 1];
402 /* Starting the short option string with '-' is for programs that
403 expect options and other ARGV-elements in any order and that care about
404 the ordering of the two. We describe each non-option ARGV-element
405 as if it were the argument of an option with character code 1. */
409 for (i
= 0; i
< OPTION_COUNT
; i
++)
411 if (ld_options
[i
].shortopt
!= '\0')
413 shortopts
[is
] = ld_options
[i
].shortopt
;
415 if (ld_options
[i
].opt
.has_arg
== required_argument
416 || ld_options
[i
].opt
.has_arg
== optional_argument
)
420 if (ld_options
[i
].opt
.has_arg
== optional_argument
)
427 if (ld_options
[i
].opt
.name
!= NULL
)
429 longopts
[il
] = ld_options
[i
].opt
;
433 shortopts
[is
] = '\0';
434 longopts
[il
].name
= NULL
;
436 /* The -G option is ambiguous on different platforms. Sometimes it
437 specifies the largest data size to put into the small data
438 section. Sometimes it is equivalent to --shared. Unfortunately,
439 the first form takes an argument, while the second does not.
441 We need to permit the --shared form because on some platforms,
442 such as Solaris, gcc -shared will pass -G to the linker.
444 To permit either usage, we look through the argument list. If we
445 find -G not followed by a number, we change it into --shared.
446 This will work for most normal cases. */
447 for (i
= 1; i
< argc
; i
++)
448 if (strcmp (argv
[i
], "-G") == 0
450 || ! isdigit ((unsigned char) argv
[i
+ 1][0])))
451 argv
[i
] = (char *) "--shared";
453 /* Because we permit long options to start with a single dash, and
454 we have a --library option, and the -l option is conventionally
455 used with an immediately following argument, we can have bad
456 results if somebody tries to use -l with a library whose name
457 happens to start with "ibrary", as in -li. We avoid problems by
458 simply turning -l into --library. This means that users will
459 have to use two dashes in order to use --library, which is OK
460 since that's how it is documented.
462 FIXME: It's possible that this problem can arise for other short
463 options as well, although the user does always have the recourse
464 of adding a space between the option and the argument. */
465 for (i
= 1; i
< argc
; i
++)
467 if (argv
[i
][0] == '-'
469 && argv
[i
][2] != '\0')
473 n
= (char *) xmalloc (strlen (argv
[i
]) + 20);
474 sprintf (n
, "--library=%s", argv
[i
] + 2);
485 /* Using last_optind lets us avoid calling ldemul_parse_args
486 multiple times on a single option, which would lead to
487 confusion in the internal static variables maintained by
488 getopt. This could otherwise happen for an argument like
489 -nx, in which the -n is parsed as a single option, and we
490 loop around to pick up the -x. */
491 if (optind
!= last_optind
)
493 if (ldemul_parse_args (argc
, argv
))
495 last_optind
= optind
;
498 /* getopt_long_only is like getopt_long, but '-' as well as '--'
499 can indicate a long option. */
500 optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
508 case 1: /* File name. */
509 lang_add_input_file (optarg
, lang_input_file_is_file_enum
,
516 /* For HP/UX compatibility. Actually -a shared should mean
517 ``use only shared libraries'' but, then, we don't
518 currently support shared libraries on HP/UX anyhow. */
519 if (strcmp (optarg
, "archive") == 0)
520 config
.dynamic_link
= false;
521 else if (strcmp (optarg
, "shared") == 0
522 || strcmp (optarg
, "default") == 0)
523 config
.dynamic_link
= true;
525 einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg
);
528 /* FIXME: We just ignore these, but we should handle them. */
529 if (strcmp (optarg
, "definitions") == 0)
531 else if (strcmp (optarg
, "nodefinitions") == 0)
533 else if (strcmp (optarg
, "nosymbolic") == 0)
535 else if (strcmp (optarg
, "pure-text") == 0)
538 einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg
);
541 ldfile_add_arch (optarg
);
544 lang_add_target (optarg
);
547 ldfile_open_command_file (optarg
);
548 parser_input
= input_mri_script
;
551 case OPTION_CALL_SHARED
:
552 config
.dynamic_link
= true;
554 case OPTION_NON_SHARED
:
555 config
.dynamic_link
= false;
558 command_line
.cref
= true;
559 link_info
.notice_all
= true;
562 command_line
.force_common_definition
= true;
566 lex_redirect (optarg
);
567 parser_input
= input_defsym
;
573 case OPTION_DEMANGLE
:
576 case OPTION_DYNAMIC_LINKER
:
577 command_line
.interpreter
= optarg
;
580 command_line
.endian
= ENDIAN_BIG
;
583 command_line
.endian
= ENDIAN_LITTLE
;
585 case OPTION_EMBEDDED_RELOCS
:
586 command_line
.embedded_relocs
= true;
588 case OPTION_EXPORT_DYNAMIC
:
589 case 'E': /* HP/UX compatibility. */
590 command_line
.export_dynamic
= true;
593 lang_add_entry (optarg
, true);
596 if (command_line
.auxiliary_filters
== NULL
)
598 command_line
.auxiliary_filters
=
599 (char **) xmalloc (2 * sizeof (char *));
600 command_line
.auxiliary_filters
[0] = optarg
;
601 command_line
.auxiliary_filters
[1] = NULL
;
609 for (p
= command_line
.auxiliary_filters
; *p
!= NULL
; p
++)
611 command_line
.auxiliary_filters
=
612 (char **) xrealloc (command_line
.auxiliary_filters
,
613 (c
+ 2) * sizeof (char *));
614 command_line
.auxiliary_filters
[c
] = optarg
;
615 command_line
.auxiliary_filters
[c
+ 1] = NULL
;
619 command_line
.filter_shlib
= optarg
;
621 case OPTION_FORCE_EXE_SUFFIX
:
622 command_line
.force_exe_suffix
= true;
627 g_switch_value
= strtoul (optarg
, &end
, 0);
629 einfo (_("%P%F: invalid number `%s'\n"), optarg
);
635 case OPTION_GC_SECTIONS
:
636 command_line
.gc_sections
= true;
643 ldfile_add_library_path (optarg
, true);
646 lang_add_input_file (optarg
, lang_input_file_is_l_enum
,
650 config
.map_filename
= "-";
653 /* Ignore. Was handled in a pre-parse. */
656 config
.map_filename
= optarg
;
659 config
.text_read_only
= false;
660 config
.magic_demand_paged
= false;
661 config
.dynamic_link
= false;
664 config
.magic_demand_paged
= false;
665 config
.dynamic_link
= false;
667 case OPTION_NO_DEMANGLE
:
670 case OPTION_NO_GC_SECTIONS
:
671 command_line
.gc_sections
= false;
673 case OPTION_NO_KEEP_MEMORY
:
674 link_info
.keep_memory
= false;
676 case OPTION_NO_UNDEFINED
:
677 link_info
.no_undefined
= true;
679 case OPTION_NO_WARN_MISMATCH
:
680 command_line
.warn_mismatch
= false;
682 case OPTION_NOINHIBIT_EXEC
:
683 force_make_executable
= true;
685 case OPTION_NO_WHOLE_ARCHIVE
:
686 whole_archive
= false;
689 /* FIXME "-O<non-digits> <value>" used to set the address of
690 section <non-digits>. Was this for compatibility with
691 something, or can we create a new option to do that
692 (with a syntax similar to -defsym)?
693 getopt can't handle two args to an option without kludges. */
695 /* Enable optimizations of output files. */
696 link_info
.optimize
= strtoul (optarg
, NULL
, 0) ? true : false;
699 lang_add_output (optarg
, 0);
702 lang_add_output_format (optarg
, (char *) NULL
, (char *) NULL
, 0);
706 link_info
.relocateable
= true;
707 config
.build_constructors
= false;
708 config
.magic_demand_paged
= false;
709 config
.text_read_only
= false;
710 config
.dynamic_link
= false;
713 /* The GNU linker traditionally uses -R to mean to include
714 only the symbols from a file. The Solaris linker uses -R
715 to set the path used by the runtime linker to find
716 libraries. This is the GNU linker -rpath argument. We
717 try to support both simultaneously by checking the file
718 named. If it is a directory, rather than a regular file,
719 we assume -rpath was meant. */
723 if (stat (optarg
, &s
) >= 0
724 && ! S_ISDIR (s
.st_mode
))
726 lang_add_input_file (optarg
,
727 lang_input_file_is_symbols_only_enum
,
734 if (command_line
.rpath
== NULL
)
735 command_line
.rpath
= buystring (optarg
);
738 size_t rpath_len
= strlen (command_line
.rpath
);
739 size_t optarg_len
= strlen (optarg
);
741 char *cp
= command_line
.rpath
;
743 /* First see whether OPTARG is already in the path. */
747 while (optarg
[idx
] != '\0' && optarg
[idx
] == cp
[idx
])
749 if (optarg
[idx
] == '\0'
750 && (cp
[idx
] == '\0' || cp
[idx
] == ':'))
755 cp
= strchr (cp
, ':');
763 buf
= xmalloc (rpath_len
+ optarg_len
+ 2);
764 sprintf (buf
, "%s:%s", command_line
.rpath
, optarg
);
765 free (command_line
.rpath
);
766 command_line
.rpath
= buf
;
770 case OPTION_RPATH_LINK
:
771 if (command_line
.rpath_link
== NULL
)
772 command_line
.rpath_link
= buystring (optarg
);
777 buf
= xmalloc (strlen (command_line
.rpath_link
)
780 sprintf (buf
, "%s:%s", command_line
.rpath_link
, optarg
);
781 free (command_line
.rpath_link
);
782 command_line
.rpath_link
= buf
;
786 command_line
.relax
= true;
788 case OPTION_RETAIN_SYMBOLS_FILE
:
789 add_keepsyms_file (optarg
);
792 link_info
.strip
= strip_debugger
;
795 link_info
.strip
= strip_all
;
798 if (config
.has_shared
)
799 link_info
.shared
= true;
801 einfo (_("%P%F: -shared not supported\n"));
803 case 'h': /* Used on Solaris. */
805 command_line
.soname
= optarg
;
807 case OPTION_SORT_COMMON
:
808 config
.sort_common
= true;
813 case OPTION_SYMBOLIC
:
814 link_info
.symbolic
= true;
820 ldfile_open_command_file (optarg
);
821 parser_input
= input_script
;
825 set_section_start (".bss", optarg
);
828 set_section_start (".data", optarg
);
831 set_section_start (".text", optarg
);
833 case OPTION_TRADITIONAL_FORMAT
:
834 link_info
.traditional_format
= true;
836 case OPTION_TASK_LINK
:
837 link_info
.task_link
= true;
838 /* Fall through - do an implied -r option. */
840 link_info
.relocateable
= true;
841 config
.build_constructors
= true;
842 config
.magic_demand_paged
= false;
843 config
.text_read_only
= false;
844 config
.dynamic_link
= false;
847 ldlang_add_undef (optarg
);
851 version_printed
= true;
852 trace_file_tries
= true;
856 version_printed
= true;
860 version_printed
= true;
863 /* This output is intended to follow the GNU standards document. */
864 printf ("GNU ld %s\n", ld_program_version
);
865 printf (_("Copyright 1997 Free Software Foundation, Inc.\n"));
867 This program is free software; you may redistribute it under the terms of\n\
868 the GNU General Public License. This program has absolutely no warranty.\n"));
870 ld_emulation_xfer_type
**ptr
= ld_emulations
;
872 printf (_(" Supported emulations:\n"));
875 printf (" %s\n", (*ptr
)->emulation_name
);
881 case OPTION_VERSION_SCRIPT
:
882 /* This option indicates a small script that only specifies
883 version information. Read it, but don't assume that
884 we've seen a linker script. */
886 boolean hold_had_script
;
888 hold_had_script
= had_script
;
889 ldfile_open_command_file (optarg
);
890 had_script
= hold_had_script
;
891 parser_input
= input_version_script
;
895 case OPTION_VERSION_EXPORTS_SECTION
:
896 /* This option records a version symbol to be applied to the
897 symbols listed for export to be found in the object files
898 .exports sections. */
899 command_line
.version_exports_section
= optarg
;
901 case OPTION_WARN_COMMON
:
902 config
.warn_common
= true;
904 case OPTION_WARN_CONSTRUCTORS
:
905 config
.warn_constructors
= true;
907 case OPTION_WARN_MULTIPLE_GP
:
908 config
.warn_multiple_gp
= true;
910 case OPTION_WARN_ONCE
:
911 config
.warn_once
= true;
913 case OPTION_WARN_SECTION_ALIGN
:
914 config
.warn_section_align
= true;
916 case OPTION_WHOLE_ARCHIVE
:
917 whole_archive
= true;
923 link_info
.discard
= discard_l
;
926 link_info
.discard
= discard_all
;
929 if (strncmp (optarg
, "P,", 2) == 0)
931 default_dirlist
= xstrdup (optarg
);
937 /* We accept and ignore this option for Solaris
938 compatibility. Actually, on Solaris, optarg is not
939 ignored. Someday we should handle it correctly. FIXME. */
941 case OPTION_SPLIT_BY_RELOC
:
942 config
.split_by_reloc
= atoi (optarg
);
944 case OPTION_SPLIT_BY_FILE
:
945 config
.split_by_file
= true;
947 case OPTION_CHECK_SECTIONS
:
948 command_line
.check_section_addresses
= true;
950 case OPTION_NO_CHECK_SECTIONS
:
951 command_line
.check_section_addresses
= false;
957 _("%s: may not nest groups (--help for usage)\n"),
968 _("%s: group ended before it began (--help for usage)\n"),
975 case OPTION_MPC860C0
:
976 link_info
.mpc860c0
= 20; /* default value (in bytes) */
981 words
= is_num (optarg
, 1, 10, 0);
984 fprintf (stderr
, _("Invalid argument to option \"mpc860c0\"\n"));
987 link_info
.mpc860c0
= words
* 4; /* convert words to bytes */
989 command_line
.relax
= true;
997 if (default_dirlist
!= NULL
)
998 set_default_dirlist (default_dirlist
);
1002 /* Add the (colon-separated) elements of DIRLIST_PTR to the
1003 library search path. */
1006 set_default_dirlist (dirlist_ptr
)
1013 p
= strchr (dirlist_ptr
, PATH_SEPARATOR
);
1016 if (*dirlist_ptr
!= '\0')
1017 ldfile_add_library_path (dirlist_ptr
, true);
1020 dirlist_ptr
= p
+ 1;
1025 set_section_start (sect
, valstr
)
1026 char *sect
, *valstr
;
1029 unsigned long val
= strtoul (valstr
, &end
, 16);
1031 einfo (_("%P%F: invalid hex number `%s'\n"), valstr
);
1032 lang_section_start (sect
, exp_intop (val
));
1035 /* Print help messages for the options. */
1041 const char **targets
, **pp
;
1043 printf (_("Usage: %s [options] file...\n"), program_name
);
1045 printf (_("Options:\n"));
1046 for (i
= 0; i
< OPTION_COUNT
; i
++)
1048 if (ld_options
[i
].doc
!= NULL
)
1062 if (ld_options
[j
].shortopt
!= '\0'
1063 && ld_options
[j
].control
!= NO_HELP
)
1065 printf ("%s-%c", comma
? ", " : "", ld_options
[j
].shortopt
);
1066 len
+= (comma
? 2 : 0) + 2;
1067 if (ld_options
[j
].arg
!= NULL
)
1069 if (ld_options
[j
].opt
.has_arg
!= optional_argument
)
1074 printf ("%s", _(ld_options
[j
].arg
));
1075 len
+= strlen (_(ld_options
[j
].arg
));
1081 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1086 if (ld_options
[j
].opt
.name
!= NULL
1087 && ld_options
[j
].control
!= NO_HELP
)
1091 ld_options
[j
].control
== TWO_DASHES
? "-" : "",
1092 ld_options
[j
].opt
.name
);
1093 len
+= ((comma
? 2 : 0)
1095 + (ld_options
[j
].control
== TWO_DASHES
? 1 : 0)
1096 + strlen (ld_options
[j
].opt
.name
));
1097 if (ld_options
[j
].arg
!= NULL
)
1099 printf (" %s", _(ld_options
[j
].arg
));
1100 len
+= 1 + strlen (_(ld_options
[j
].arg
));
1106 while (j
< OPTION_COUNT
&& ld_options
[j
].doc
== NULL
);
1114 for (; len
< 30; len
++)
1117 printf ("%s\n", _(ld_options
[i
].doc
));
1121 /* xgettext:c-format */
1122 printf (_("%s: supported targets:"), program_name
);
1123 targets
= bfd_target_list ();
1124 for (pp
= targets
; *pp
!= NULL
; pp
++)
1125 printf (" %s", *pp
);
1129 /* xgettext:c-format */
1130 printf (_("%s: supported emulations: "), program_name
);
1131 ldemul_list_emulations (stdout
);
1134 /* xgettext:c-format */
1135 printf (_("%s: emulation specific options:\n"), program_name
);
1136 ldemul_list_emulation_options (stdout
);
1139 printf (_("\nReport bugs to bug-gnu-utils@gnu.org\n"));