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