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