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