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