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