Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* Parse options for the GNU linker. |
a2b64bed | 2 | Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, |
92f01d61 | 3 | 2001, 2002, 2003, 2004, 2005, 2006, 2007 |
252b5132 RH |
4 | Free Software Foundation, Inc. |
5 | ||
f96b4a7b | 6 | This file is part of the GNU Binutils. |
252b5132 | 7 | |
f96b4a7b | 8 | This program is free software; you can redistribute it and/or modify |
53b2a62f | 9 | it under the terms of the GNU General Public License as published by |
f96b4a7b NC |
10 | the Free Software Foundation; either version 3 of the License, or |
11 | (at your option) any later version. | |
252b5132 | 12 | |
f96b4a7b | 13 | This program is distributed in the hope that it will be useful, |
53b2a62f NC |
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. | |
252b5132 | 17 | |
53b2a62f | 18 | You should have received a copy of the GNU General Public License |
f96b4a7b NC |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
21 | MA 02110-1301, USA. */ | |
252b5132 | 22 | |
3db64b00 | 23 | #include "sysdep.h" |
252b5132 | 24 | #include "bfd.h" |
c428fa83 | 25 | #include "bfdver.h" |
252b5132 RH |
26 | #include "libiberty.h" |
27 | #include <stdio.h> | |
28 | #include <string.h> | |
3882b010 | 29 | #include "safe-ctype.h" |
252b5132 RH |
30 | #include "getopt.h" |
31 | #include "bfdlink.h" | |
32 | #include "ld.h" | |
33 | #include "ldmain.h" | |
34 | #include "ldmisc.h" | |
35 | #include "ldexp.h" | |
36 | #include "ldlang.h" | |
df2a7313 | 37 | #include <ldgram.h> |
252b5132 RH |
38 | #include "ldlex.h" |
39 | #include "ldfile.h" | |
40 | #include "ldver.h" | |
41 | #include "ldemul.h" | |
28c309a2 | 42 | #include "demangle.h" |
252b5132 RH |
43 | |
44 | #ifndef PATH_SEPARATOR | |
45 | #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__)) | |
46 | #define PATH_SEPARATOR ';' | |
47 | #else | |
48 | #define PATH_SEPARATOR ':' | |
49 | #endif | |
50 | #endif | |
51 | ||
5cc18311 | 52 | /* Somewhere above, sys/stat.h got included . . . . */ |
252b5132 RH |
53 | #if !defined(S_ISDIR) && defined(S_IFDIR) |
54 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) | |
55 | #endif | |
56 | ||
1579bae1 AM |
57 | static void set_default_dirlist (char *); |
58 | static void set_section_start (char *, char *); | |
ba916c8a | 59 | static void set_segment_start (const char *, char *); |
1579bae1 | 60 | static void help (void); |
252b5132 RH |
61 | |
62 | /* Non-zero if we are processing a --defsym from the command line. */ | |
63 | int parsing_defsym = 0; | |
64 | ||
65 | /* Codes used for the long options with no short synonyms. 150 isn't | |
66 | special; it's just an arbitrary non-ASCII char value. */ | |
560e09e9 NC |
67 | enum option_values |
68 | { | |
69 | OPTION_ASSERT = 150, | |
70 | OPTION_CALL_SHARED, | |
71 | OPTION_CREF, | |
72 | OPTION_DEFSYM, | |
73 | OPTION_DEMANGLE, | |
74 | OPTION_DYNAMIC_LINKER, | |
e2243057 | 75 | OPTION_SYSROOT, |
560e09e9 NC |
76 | OPTION_EB, |
77 | OPTION_EL, | |
78 | OPTION_EMBEDDED_RELOCS, | |
79 | OPTION_EXPORT_DYNAMIC, | |
80 | OPTION_HELP, | |
81 | OPTION_IGNORE, | |
82 | OPTION_MAP, | |
83 | OPTION_NO_DEMANGLE, | |
84 | OPTION_NO_KEEP_MEMORY, | |
85 | OPTION_NO_WARN_MISMATCH, | |
fe7929ce | 86 | OPTION_NO_WARN_SEARCH_MISMATCH, |
560e09e9 NC |
87 | OPTION_NOINHIBIT_EXEC, |
88 | OPTION_NON_SHARED, | |
89 | OPTION_NO_WHOLE_ARCHIVE, | |
90 | OPTION_OFORMAT, | |
91 | OPTION_RELAX, | |
92 | OPTION_RETAIN_SYMBOLS_FILE, | |
93 | OPTION_RPATH, | |
94 | OPTION_RPATH_LINK, | |
95 | OPTION_SHARED, | |
96 | OPTION_SONAME, | |
97 | OPTION_SORT_COMMON, | |
bcaa7b3e | 98 | OPTION_SORT_SECTION, |
560e09e9 NC |
99 | OPTION_STATS, |
100 | OPTION_SYMBOLIC, | |
d8cf8b51 | 101 | OPTION_SYMBOLIC_FUNCTIONS, |
560e09e9 NC |
102 | OPTION_TASK_LINK, |
103 | OPTION_TBSS, | |
104 | OPTION_TDATA, | |
105 | OPTION_TTEXT, | |
106 | OPTION_TRADITIONAL_FORMAT, | |
107 | OPTION_UR, | |
108 | OPTION_VERBOSE, | |
109 | OPTION_VERSION, | |
110 | OPTION_VERSION_SCRIPT, | |
111 | OPTION_VERSION_EXPORTS_SECTION, | |
55255dae | 112 | OPTION_DYNAMIC_LIST, |
40b36307 | 113 | OPTION_DYNAMIC_LIST_CPP_NEW, |
55255dae | 114 | OPTION_DYNAMIC_LIST_CPP_TYPEINFO, |
40b36307 | 115 | OPTION_DYNAMIC_LIST_DATA, |
560e09e9 NC |
116 | OPTION_WARN_COMMON, |
117 | OPTION_WARN_CONSTRUCTORS, | |
118 | OPTION_WARN_FATAL, | |
119 | OPTION_WARN_MULTIPLE_GP, | |
120 | OPTION_WARN_ONCE, | |
121 | OPTION_WARN_SECTION_ALIGN, | |
122 | OPTION_SPLIT_BY_RELOC, | |
123 | OPTION_SPLIT_BY_FILE , | |
124 | OPTION_WHOLE_ARCHIVE, | |
e56f61be L |
125 | OPTION_ADD_NEEDED, |
126 | OPTION_NO_ADD_NEEDED, | |
4a43e768 AM |
127 | OPTION_AS_NEEDED, |
128 | OPTION_NO_AS_NEEDED, | |
560e09e9 NC |
129 | OPTION_WRAP, |
130 | OPTION_FORCE_EXE_SUFFIX, | |
131 | OPTION_GC_SECTIONS, | |
132 | OPTION_NO_GC_SECTIONS, | |
c17d87de NC |
133 | OPTION_PRINT_GC_SECTIONS, |
134 | OPTION_NO_PRINT_GC_SECTIONS, | |
2d643429 | 135 | OPTION_HASH_SIZE, |
560e09e9 NC |
136 | OPTION_CHECK_SECTIONS, |
137 | OPTION_NO_CHECK_SECTIONS, | |
560e09e9 NC |
138 | OPTION_NO_UNDEFINED, |
139 | OPTION_INIT, | |
140 | OPTION_FINI, | |
141 | OPTION_SECTION_START, | |
142 | OPTION_UNIQUE, | |
143 | OPTION_TARGET_HELP, | |
144 | OPTION_ALLOW_SHLIB_UNDEFINED, | |
145 | OPTION_NO_ALLOW_SHLIB_UNDEFINED, | |
146 | OPTION_ALLOW_MULTIPLE_DEFINITION, | |
147 | OPTION_NO_UNDEFINED_VERSION, | |
3e3b46e5 | 148 | OPTION_DEFAULT_SYMVER, |
fc0e6df6 | 149 | OPTION_DEFAULT_IMPORTED_SYMVER, |
560e09e9 NC |
150 | OPTION_DISCARD_NONE, |
151 | OPTION_SPARE_DYNAMIC_TAGS, | |
152 | OPTION_NO_DEFINE_COMMON, | |
153 | OPTION_NOSTDLIB, | |
154 | OPTION_NO_OMAGIC, | |
155 | OPTION_STRIP_DISCARDED, | |
156 | OPTION_NO_STRIP_DISCARDED, | |
157 | OPTION_ACCEPT_UNKNOWN_INPUT_ARCH, | |
158 | OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH, | |
159 | OPTION_PIE, | |
160 | OPTION_UNRESOLVED_SYMBOLS, | |
161 | OPTION_WARN_UNRESOLVED_SYMBOLS, | |
35835446 | 162 | OPTION_ERROR_UNRESOLVED_SYMBOLS, |
8fdd7217 | 163 | OPTION_WARN_SHARED_TEXTREL, |
14be8564 L |
164 | OPTION_REDUCE_MEMORY_OVERHEADS, |
165 | OPTION_DEFAULT_SCRIPT | |
560e09e9 | 166 | }; |
252b5132 RH |
167 | |
168 | /* The long options. This structure is used for both the option | |
169 | parsing and the help text. */ | |
170 | ||
b79e8c78 NC |
171 | struct ld_option |
172 | { | |
252b5132 RH |
173 | /* The long option information. */ |
174 | struct option opt; | |
175 | /* The short option with the same meaning ('\0' if none). */ | |
176 | char shortopt; | |
177 | /* The name of the argument (NULL if none). */ | |
178 | const char *arg; | |
179 | /* The documentation string. If this is NULL, this is a synonym for | |
180 | the previous option. */ | |
181 | const char *doc; | |
e47d05ad KH |
182 | enum { |
183 | /* Use one dash before long option name. */ | |
184 | ONE_DASH, | |
185 | /* Use two dashes before long option name. */ | |
186 | TWO_DASHES, | |
e4897a32 NC |
187 | /* Only accept two dashes before the long option name. |
188 | This is an overloading of the use of this enum, since originally it | |
189 | was only intended to tell the --help display function how to display | |
190 | the long option name. This feature was added in order to resolve | |
191 | the confusion about the -omagic command line switch. Is it setting | |
192 | the output file name to "magic" or is it setting the NMAGIC flag on | |
193 | the output ? It has been decided that it is setting the output file | |
194 | name, and that if you want to set the NMAGIC flag you should use -N | |
195 | or --omagic. */ | |
196 | EXACTLY_TWO_DASHES, | |
e47d05ad KH |
197 | /* Don't mention this option in --help output. */ |
198 | NO_HELP | |
199 | } control; | |
252b5132 RH |
200 | }; |
201 | ||
b79e8c78 NC |
202 | static const struct ld_option ld_options[] = |
203 | { | |
252b5132 | 204 | { {NULL, required_argument, NULL, '\0'}, |
6feb9908 AM |
205 | 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"), |
206 | ONE_DASH }, | |
252b5132 | 207 | { {"architecture", required_argument, NULL, 'A'}, |
6feb9908 | 208 | 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES }, |
252b5132 | 209 | { {"format", required_argument, NULL, 'b'}, |
6feb9908 AM |
210 | 'b', N_("TARGET"), N_("Specify target for following input files"), |
211 | TWO_DASHES }, | |
252b5132 | 212 | { {"mri-script", required_argument, NULL, 'c'}, |
6feb9908 | 213 | 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES }, |
252b5132 | 214 | { {"dc", no_argument, NULL, 'd'}, |
6feb9908 | 215 | 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH }, |
252b5132 | 216 | { {"dp", no_argument, NULL, 'd'}, |
6feb9908 | 217 | '\0', NULL, NULL, ONE_DASH }, |
252b5132 | 218 | { {"entry", required_argument, NULL, 'e'}, |
6feb9908 | 219 | 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES }, |
252b5132 | 220 | { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC}, |
6feb9908 | 221 | 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES }, |
252b5132 | 222 | { {"EB", no_argument, NULL, OPTION_EB}, |
6feb9908 | 223 | '\0', NULL, N_("Link big-endian objects"), ONE_DASH }, |
252b5132 | 224 | { {"EL", no_argument, NULL, OPTION_EL}, |
6feb9908 | 225 | '\0', NULL, N_("Link little-endian objects"), ONE_DASH }, |
252b5132 | 226 | { {"auxiliary", required_argument, NULL, 'f'}, |
6feb9908 AM |
227 | 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"), |
228 | TWO_DASHES }, | |
252b5132 | 229 | { {"filter", required_argument, NULL, 'F'}, |
6feb9908 AM |
230 | 'F', N_("SHLIB"), N_("Filter for shared object symbol table"), |
231 | TWO_DASHES }, | |
252b5132 | 232 | { {NULL, no_argument, NULL, '\0'}, |
6feb9908 | 233 | 'g', NULL, N_("Ignored"), ONE_DASH }, |
252b5132 | 234 | { {"gpsize", required_argument, NULL, 'G'}, |
6feb9908 AM |
235 | 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"), |
236 | TWO_DASHES }, | |
252b5132 | 237 | { {"soname", required_argument, NULL, OPTION_SONAME}, |
6feb9908 | 238 | 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH }, |
506eee22 | 239 | { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER}, |
6feb9908 AM |
240 | 'I', N_("PROGRAM"), N_("Set PROGRAM as the dynamic linker to use"), |
241 | TWO_DASHES }, | |
252b5132 | 242 | { {"library", required_argument, NULL, 'l'}, |
6feb9908 | 243 | 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES }, |
252b5132 | 244 | { {"library-path", required_argument, NULL, 'L'}, |
6feb9908 AM |
245 | 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"), |
246 | TWO_DASHES }, | |
e2243057 RS |
247 | { {"sysroot=<DIRECTORY>", required_argument, NULL, OPTION_SYSROOT}, |
248 | '\0', NULL, N_("Override the default sysroot location"), TWO_DASHES }, | |
252b5132 | 249 | { {NULL, required_argument, NULL, '\0'}, |
6feb9908 | 250 | 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH }, |
252b5132 | 251 | { {"print-map", no_argument, NULL, 'M'}, |
6feb9908 | 252 | 'M', NULL, N_("Print map file on standard output"), TWO_DASHES }, |
252b5132 | 253 | { {"nmagic", no_argument, NULL, 'n'}, |
6feb9908 | 254 | 'n', NULL, N_("Do not page align data"), TWO_DASHES }, |
252b5132 | 255 | { {"omagic", no_argument, NULL, 'N'}, |
6feb9908 AM |
256 | 'N', NULL, N_("Do not page align data, do not make text readonly"), |
257 | EXACTLY_TWO_DASHES }, | |
63fd3b82 | 258 | { {"no-omagic", no_argument, NULL, OPTION_NO_OMAGIC}, |
6feb9908 AM |
259 | '\0', NULL, N_("Page align data, make text readonly"), |
260 | EXACTLY_TWO_DASHES }, | |
252b5132 | 261 | { {"output", required_argument, NULL, 'o'}, |
6feb9908 | 262 | 'o', N_("FILE"), N_("Set output file name"), EXACTLY_TWO_DASHES }, |
252b5132 | 263 | { {NULL, required_argument, NULL, '\0'}, |
6feb9908 | 264 | 'O', NULL, N_("Optimize output file"), ONE_DASH }, |
252b5132 | 265 | { {"Qy", no_argument, NULL, OPTION_IGNORE}, |
6feb9908 | 266 | '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH }, |
a712da20 | 267 | { {"emit-relocs", no_argument, NULL, 'q'}, |
6feb9908 | 268 | 'q', NULL, "Generate relocations in final output", TWO_DASHES }, |
1049f94e | 269 | { {"relocatable", no_argument, NULL, 'r'}, |
6feb9908 | 270 | 'r', NULL, N_("Generate relocatable output"), TWO_DASHES }, |
252b5132 | 271 | { {NULL, no_argument, NULL, '\0'}, |
6feb9908 | 272 | 'i', NULL, NULL, ONE_DASH }, |
252b5132 | 273 | { {"just-symbols", required_argument, NULL, 'R'}, |
6feb9908 AM |
274 | 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"), |
275 | TWO_DASHES }, | |
252b5132 | 276 | { {"strip-all", no_argument, NULL, 's'}, |
6feb9908 | 277 | 's', NULL, N_("Strip all symbols"), TWO_DASHES }, |
252b5132 | 278 | { {"strip-debug", no_argument, NULL, 'S'}, |
6feb9908 | 279 | 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES }, |
d5cd3933 | 280 | { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED}, |
6feb9908 | 281 | '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES }, |
d5cd3933 | 282 | { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED}, |
6feb9908 | 283 | '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES }, |
252b5132 | 284 | { {"trace", no_argument, NULL, 't'}, |
6feb9908 | 285 | 't', NULL, N_("Trace file opens"), TWO_DASHES }, |
252b5132 | 286 | { {"script", required_argument, NULL, 'T'}, |
6feb9908 | 287 | 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES }, |
14be8564 L |
288 | { {"default-script", required_argument, NULL, OPTION_DEFAULT_SCRIPT}, |
289 | '\0', N_("FILE"), N_("Read default linker script"), TWO_DASHES }, | |
290 | { {"dT", required_argument, NULL, OPTION_DEFAULT_SCRIPT}, | |
291 | '\0', NULL, NULL, ONE_DASH }, | |
252b5132 | 292 | { {"undefined", required_argument, NULL, 'u'}, |
6feb9908 AM |
293 | 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"), |
294 | TWO_DASHES }, | |
577a0623 | 295 | { {"unique", optional_argument, NULL, OPTION_UNIQUE}, |
6feb9908 AM |
296 | '\0', N_("[=SECTION]"), |
297 | N_("Don't merge input [SECTION | orphan] sections"), TWO_DASHES }, | |
252b5132 | 298 | { {"Ur", no_argument, NULL, OPTION_UR}, |
6feb9908 | 299 | '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH }, |
252b5132 | 300 | { {"version", no_argument, NULL, OPTION_VERSION}, |
6feb9908 | 301 | 'v', NULL, N_("Print version information"), TWO_DASHES }, |
252b5132 | 302 | { {NULL, no_argument, NULL, '\0'}, |
6feb9908 | 303 | 'V', NULL, N_("Print version and emulation information"), ONE_DASH }, |
252b5132 | 304 | { {"discard-all", no_argument, NULL, 'x'}, |
6feb9908 | 305 | 'x', NULL, N_("Discard all local symbols"), TWO_DASHES }, |
252b5132 | 306 | { {"discard-locals", no_argument, NULL, 'X'}, |
6feb9908 | 307 | 'X', NULL, N_("Discard temporary local symbols (default)"), TWO_DASHES }, |
f5fa8ca2 | 308 | { {"discard-none", no_argument, NULL, OPTION_DISCARD_NONE}, |
6feb9908 | 309 | '\0', NULL, N_("Don't discard any local symbols"), TWO_DASHES }, |
252b5132 | 310 | { {"trace-symbol", required_argument, NULL, 'y'}, |
6feb9908 | 311 | 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES }, |
252b5132 | 312 | { {NULL, required_argument, NULL, '\0'}, |
6feb9908 AM |
313 | 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"), |
314 | ONE_DASH }, | |
252b5132 | 315 | { {"start-group", no_argument, NULL, '('}, |
6feb9908 | 316 | '(', NULL, N_("Start a group"), TWO_DASHES }, |
252b5132 | 317 | { {"end-group", no_argument, NULL, ')'}, |
6feb9908 AM |
318 | ')', NULL, N_("End a group"), TWO_DASHES }, |
319 | { {"accept-unknown-input-arch", no_argument, NULL, | |
320 | OPTION_ACCEPT_UNKNOWN_INPUT_ARCH}, | |
321 | '\0', NULL, | |
322 | N_("Accept input files whose architecture cannot be determined"), | |
323 | TWO_DASHES }, | |
324 | { {"no-accept-unknown-input-arch", no_argument, NULL, | |
325 | OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH}, | |
326 | '\0', NULL, N_("Reject input files whose architecture is unknown"), | |
327 | TWO_DASHES }, | |
8fdd7217 NC |
328 | { {"add-needed", no_argument, NULL, OPTION_ADD_NEEDED}, |
329 | '\0', NULL, N_("Set DT_NEEDED tags for DT_NEEDED entries in\n" | |
330 | "\t\t\t\tfollowing dynamic libs"), TWO_DASHES }, | |
331 | { {"no-add-needed", no_argument, NULL, OPTION_NO_ADD_NEEDED}, | |
332 | '\0', NULL, N_("Do not set DT_NEEDED tags for DT_NEEDED entries\n" | |
333 | "\t\t\t\tin following dynamic libs"), TWO_DASHES }, | |
334 | { {"as-needed", no_argument, NULL, OPTION_AS_NEEDED}, | |
335 | '\0', NULL, N_("Only set DT_NEEDED for following dynamic libs if used"), | |
336 | TWO_DASHES }, | |
337 | { {"no-as-needed", no_argument, NULL, OPTION_NO_AS_NEEDED}, | |
338 | '\0', NULL, N_("Always set DT_NEEDED for following dynamic libs"), | |
339 | TWO_DASHES }, | |
252b5132 | 340 | { {"assert", required_argument, NULL, OPTION_ASSERT}, |
6feb9908 | 341 | '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH }, |
252b5132 | 342 | { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED}, |
6feb9908 | 343 | '\0', NULL, N_("Link against shared libraries"), ONE_DASH }, |
252b5132 | 344 | { {"dy", no_argument, NULL, OPTION_CALL_SHARED}, |
6feb9908 | 345 | '\0', NULL, NULL, ONE_DASH }, |
252b5132 | 346 | { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, |
6feb9908 | 347 | '\0', NULL, NULL, ONE_DASH }, |
252b5132 | 348 | { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED}, |
6feb9908 | 349 | '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH }, |
252b5132 | 350 | { {"dn", no_argument, NULL, OPTION_NON_SHARED}, |
6feb9908 | 351 | '\0', NULL, NULL, ONE_DASH }, |
252b5132 | 352 | { {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, |
6feb9908 | 353 | '\0', NULL, NULL, ONE_DASH }, |
252b5132 | 354 | { {"static", no_argument, NULL, OPTION_NON_SHARED}, |
6feb9908 | 355 | '\0', NULL, NULL, ONE_DASH }, |
252b5132 | 356 | { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC}, |
6feb9908 | 357 | '\0', NULL, N_("Bind global references locally"), ONE_DASH }, |
d8cf8b51 | 358 | { {"Bsymbolic-functions", no_argument, NULL, OPTION_SYMBOLIC_FUNCTIONS}, |
40b36307 | 359 | '\0', NULL, N_("Bind global function references locally"), ONE_DASH }, |
252b5132 | 360 | { {"check-sections", no_argument, NULL, OPTION_CHECK_SECTIONS}, |
6feb9908 AM |
361 | '\0', NULL, N_("Check section addresses for overlaps (default)"), |
362 | TWO_DASHES }, | |
252b5132 | 363 | { {"no-check-sections", no_argument, NULL, OPTION_NO_CHECK_SECTIONS}, |
6feb9908 AM |
364 | '\0', NULL, N_("Do not check section addresses for overlaps"), |
365 | TWO_DASHES }, | |
252b5132 | 366 | { {"cref", no_argument, NULL, OPTION_CREF}, |
6feb9908 | 367 | '\0', NULL, N_("Output cross reference table"), TWO_DASHES }, |
252b5132 | 368 | { {"defsym", required_argument, NULL, OPTION_DEFSYM}, |
6feb9908 | 369 | '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES }, |
28c309a2 | 370 | { {"demangle", optional_argument, NULL, OPTION_DEMANGLE}, |
6feb9908 AM |
371 | '\0', N_("[=STYLE]"), N_("Demangle symbol names [using STYLE]"), |
372 | TWO_DASHES }, | |
252b5132 | 373 | { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS}, |
6feb9908 | 374 | '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES}, |
8fdd7217 NC |
375 | { {"fatal-warnings", no_argument, NULL, OPTION_WARN_FATAL}, |
376 | '\0', NULL, N_("Treat warnings as errors"), | |
377 | TWO_DASHES }, | |
3dbf70a2 | 378 | { {"fini", required_argument, NULL, OPTION_FINI}, |
6feb9908 | 379 | '\0', N_("SYMBOL"), N_("Call SYMBOL at unload-time"), ONE_DASH }, |
252b5132 | 380 | { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX}, |
6feb9908 | 381 | '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES}, |
252b5132 | 382 | { {"gc-sections", no_argument, NULL, OPTION_GC_SECTIONS}, |
6feb9908 AM |
383 | '\0', NULL, N_("Remove unused sections (on some targets)"), |
384 | TWO_DASHES }, | |
252b5132 | 385 | { {"no-gc-sections", no_argument, NULL, OPTION_NO_GC_SECTIONS}, |
6feb9908 AM |
386 | '\0', NULL, N_("Don't remove unused sections (default)"), |
387 | TWO_DASHES }, | |
c17d87de NC |
388 | { {"print-gc-sections", no_argument, NULL, OPTION_PRINT_GC_SECTIONS}, |
389 | '\0', NULL, N_("List removed unused sections on stderr"), | |
390 | TWO_DASHES }, | |
391 | { {"no-print-gc-sections", no_argument, NULL, OPTION_NO_PRINT_GC_SECTIONS}, | |
392 | '\0', NULL, N_("Do not list removed unused sections"), | |
393 | TWO_DASHES }, | |
2d643429 | 394 | { {"hash-size=<NUMBER>", required_argument, NULL, OPTION_HASH_SIZE}, |
6feb9908 AM |
395 | '\0', NULL, N_("Set default hash table size close to <NUMBER>"), |
396 | TWO_DASHES }, | |
252b5132 | 397 | { {"help", no_argument, NULL, OPTION_HELP}, |
6feb9908 | 398 | '\0', NULL, N_("Print option help"), TWO_DASHES }, |
3dbf70a2 | 399 | { {"init", required_argument, NULL, OPTION_INIT}, |
6feb9908 | 400 | '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH }, |
252b5132 | 401 | { {"Map", required_argument, NULL, OPTION_MAP}, |
6feb9908 | 402 | '\0', N_("FILE"), N_("Write a map file"), ONE_DASH }, |
4818e05f | 403 | { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON}, |
6feb9908 | 404 | '\0', NULL, N_("Do not define Common storage"), TWO_DASHES }, |
252b5132 | 405 | { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE }, |
6feb9908 | 406 | '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES }, |
252b5132 | 407 | { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY}, |
6feb9908 | 408 | '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES }, |
252b5132 | 409 | { {"no-undefined", no_argument, NULL, OPTION_NO_UNDEFINED}, |
6feb9908 AM |
410 | '\0', NULL, N_("Do not allow unresolved references in object files"), |
411 | TWO_DASHES }, | |
b79e8c78 | 412 | { {"allow-shlib-undefined", no_argument, NULL, OPTION_ALLOW_SHLIB_UNDEFINED}, |
6feb9908 AM |
413 | '\0', NULL, N_("Allow unresolved references in shared libaries"), |
414 | TWO_DASHES }, | |
415 | { {"no-allow-shlib-undefined", no_argument, NULL, | |
416 | OPTION_NO_ALLOW_SHLIB_UNDEFINED}, | |
417 | '\0', NULL, N_("Do not allow unresolved references in shared libs"), | |
418 | TWO_DASHES }, | |
419 | { {"allow-multiple-definition", no_argument, NULL, | |
420 | OPTION_ALLOW_MULTIPLE_DEFINITION}, | |
421 | '\0', NULL, N_("Allow multiple definitions"), TWO_DASHES }, | |
31941635 | 422 | { {"no-undefined-version", no_argument, NULL, OPTION_NO_UNDEFINED_VERSION}, |
6feb9908 | 423 | '\0', NULL, N_("Disallow undefined version"), TWO_DASHES }, |
3e3b46e5 PB |
424 | { {"default-symver", no_argument, NULL, OPTION_DEFAULT_SYMVER}, |
425 | '\0', NULL, N_("Create default symbol version"), TWO_DASHES }, | |
fc0e6df6 PB |
426 | { {"default-imported-symver", no_argument, NULL, |
427 | OPTION_DEFAULT_IMPORTED_SYMVER}, | |
428 | '\0', NULL, N_("Create default symbol version for imported symbols"), | |
429 | TWO_DASHES }, | |
252b5132 | 430 | { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH}, |
6feb9908 | 431 | '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES}, |
fe7929ce AM |
432 | { {"no-warn-search-mismatch", no_argument, NULL, |
433 | OPTION_NO_WARN_SEARCH_MISMATCH}, | |
434 | '\0', NULL, N_("Don't warn on finding an incompatible library"), | |
435 | TWO_DASHES}, | |
252b5132 | 436 | { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE}, |
6feb9908 | 437 | '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES }, |
252b5132 | 438 | { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC}, |
6feb9908 AM |
439 | '\0', NULL, N_("Create an output file even if errors occur"), |
440 | TWO_DASHES }, | |
252b5132 | 441 | { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC}, |
6feb9908 | 442 | '\0', NULL, NULL, NO_HELP }, |
361b220e | 443 | { {"nostdlib", no_argument, NULL, OPTION_NOSTDLIB}, |
6feb9908 AM |
444 | '\0', NULL, N_("Only use library directories specified on\n" |
445 | "\t\t\t\tthe command line"), ONE_DASH }, | |
252b5132 | 446 | { {"oformat", required_argument, NULL, OPTION_OFORMAT}, |
6feb9908 AM |
447 | '\0', N_("TARGET"), N_("Specify target of output file"), |
448 | EXACTLY_TWO_DASHES }, | |
252b5132 | 449 | { {"qmagic", no_argument, NULL, OPTION_IGNORE}, |
6feb9908 AM |
450 | '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH }, |
451 | { {"reduce-memory-overheads", no_argument, NULL, | |
452 | OPTION_REDUCE_MEMORY_OVERHEADS}, | |
453 | '\0', NULL, N_("Reduce memory overheads, possibly taking much longer"), | |
454 | TWO_DASHES }, | |
252b5132 | 455 | { {"relax", no_argument, NULL, OPTION_RELAX}, |
6feb9908 | 456 | '\0', NULL, N_("Relax branches on certain targets"), TWO_DASHES }, |
252b5132 | 457 | { {"retain-symbols-file", required_argument, NULL, |
6feb9908 AM |
458 | OPTION_RETAIN_SYMBOLS_FILE}, |
459 | '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES }, | |
252b5132 | 460 | { {"rpath", required_argument, NULL, OPTION_RPATH}, |
6feb9908 | 461 | '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH }, |
252b5132 | 462 | { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK}, |
6feb9908 AM |
463 | '\0', N_("PATH"), N_("Set link time shared library search path"), |
464 | ONE_DASH }, | |
252b5132 | 465 | { {"shared", no_argument, NULL, OPTION_SHARED}, |
6feb9908 | 466 | '\0', NULL, N_("Create a shared library"), ONE_DASH }, |
252b5132 | 467 | { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */ |
6feb9908 | 468 | '\0', NULL, NULL, ONE_DASH }, |
36af4a4e | 469 | { {"pie", no_argument, NULL, OPTION_PIE}, |
6feb9908 | 470 | '\0', NULL, N_("Create a position independent executable"), ONE_DASH }, |
36af4a4e | 471 | { {"pic-executable", no_argument, NULL, OPTION_PIE}, |
6feb9908 | 472 | '\0', NULL, NULL, TWO_DASHES }, |
252b5132 | 473 | { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON}, |
6feb9908 | 474 | '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES }, |
252b5132 | 475 | { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON}, |
6feb9908 | 476 | '\0', NULL, NULL, NO_HELP }, |
bcaa7b3e L |
477 | { {"sort-section", required_argument, NULL, OPTION_SORT_SECTION}, |
478 | '\0', N_("name|alignment"), | |
479 | N_("Sort sections by name or maximum alignment"), TWO_DASHES }, | |
db6751f2 | 480 | { {"spare-dynamic-tags", required_argument, NULL, OPTION_SPARE_DYNAMIC_TAGS}, |
6feb9908 AM |
481 | '\0', N_("COUNT"), N_("How many tags to reserve in .dynamic section"), |
482 | TWO_DASHES }, | |
a854a4a7 | 483 | { {"split-by-file", optional_argument, NULL, OPTION_SPLIT_BY_FILE}, |
6feb9908 AM |
484 | '\0', N_("[=SIZE]"), N_("Split output sections every SIZE octets"), |
485 | TWO_DASHES }, | |
a854a4a7 | 486 | { {"split-by-reloc", optional_argument, NULL, OPTION_SPLIT_BY_RELOC}, |
6feb9908 AM |
487 | '\0', N_("[=COUNT]"), N_("Split output sections every COUNT relocs"), |
488 | TWO_DASHES }, | |
252b5132 | 489 | { {"stats", no_argument, NULL, OPTION_STATS}, |
6feb9908 | 490 | '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES }, |
ea20a7da | 491 | { {"target-help", no_argument, NULL, OPTION_TARGET_HELP}, |
6feb9908 | 492 | '\0', NULL, N_("Display target specific options"), TWO_DASHES }, |
252b5132 | 493 | { {"task-link", required_argument, NULL, OPTION_TASK_LINK}, |
6feb9908 | 494 | '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES }, |
252b5132 | 495 | { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT}, |
6feb9908 | 496 | '\0', NULL, N_("Use same format as native linker"), TWO_DASHES }, |
176355da | 497 | { {"section-start", required_argument, NULL, OPTION_SECTION_START}, |
6feb9908 AM |
498 | '\0', N_("SECTION=ADDRESS"), N_("Set address of named section"), |
499 | TWO_DASHES }, | |
252b5132 | 500 | { {"Tbss", required_argument, NULL, OPTION_TBSS}, |
6feb9908 | 501 | '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH }, |
252b5132 | 502 | { {"Tdata", required_argument, NULL, OPTION_TDATA}, |
6feb9908 | 503 | '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH }, |
252b5132 | 504 | { {"Ttext", required_argument, NULL, OPTION_TTEXT}, |
6feb9908 AM |
505 | '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH }, |
506 | { {"unresolved-symbols=<method>", required_argument, NULL, | |
507 | OPTION_UNRESOLVED_SYMBOLS}, | |
508 | '\0', NULL, N_("How to handle unresolved symbols. <method> is:\n" | |
509 | "\t\t\t\tignore-all, report-all, ignore-in-object-files,\n" | |
510 | "\t\t\t\tignore-in-shared-libs"), TWO_DASHES }, | |
252b5132 | 511 | { {"verbose", no_argument, NULL, OPTION_VERBOSE}, |
6feb9908 | 512 | '\0', NULL, N_("Output lots of information during link"), TWO_DASHES }, |
252b5132 | 513 | { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */ |
6feb9908 | 514 | '\0', NULL, NULL, NO_HELP }, |
252b5132 | 515 | { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT }, |
6feb9908 | 516 | '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES }, |
252b5132 RH |
517 | { {"version-exports-section", required_argument, NULL, |
518 | OPTION_VERSION_EXPORTS_SECTION }, | |
6feb9908 AM |
519 | '\0', N_("SYMBOL"), N_("Take export symbols list from .exports, using\n" |
520 | "\t\t\t\tSYMBOL as the version."), TWO_DASHES }, | |
40b36307 L |
521 | { {"dynamic-list-data", no_argument, NULL, OPTION_DYNAMIC_LIST_DATA}, |
522 | '\0', NULL, N_("Add data symbols to dynamic list"), TWO_DASHES }, | |
523 | { {"dynamic-list-cpp-new", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_NEW}, | |
524 | '\0', NULL, N_("Use C++ operator new/delete dynamic list"), TWO_DASHES }, | |
55255dae L |
525 | { {"dynamic-list-cpp-typeinfo", no_argument, NULL, OPTION_DYNAMIC_LIST_CPP_TYPEINFO}, |
526 | '\0', NULL, N_("Use C++ typeinfo dynamic list"), TWO_DASHES }, | |
527 | { {"dynamic-list", required_argument, NULL, OPTION_DYNAMIC_LIST}, | |
528 | '\0', N_("FILE"), N_("Read dynamic list"), TWO_DASHES }, | |
252b5132 | 529 | { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON}, |
6feb9908 | 530 | '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES }, |
252b5132 | 531 | { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS}, |
6feb9908 AM |
532 | '\0', NULL, N_("Warn if global constructors/destructors are seen"), |
533 | TWO_DASHES }, | |
252b5132 | 534 | { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP}, |
6feb9908 | 535 | '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES }, |
252b5132 | 536 | { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE}, |
6feb9908 | 537 | '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES }, |
252b5132 | 538 | { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN}, |
6feb9908 AM |
539 | '\0', NULL, N_("Warn if start of section changes due to alignment"), |
540 | TWO_DASHES }, | |
8fdd7217 NC |
541 | { {"warn-shared-textrel", no_argument, NULL, OPTION_WARN_SHARED_TEXTREL}, |
542 | '\0', NULL, N_("Warn if shared object has DT_TEXTREL"), | |
543 | TWO_DASHES }, | |
6feb9908 AM |
544 | { {"warn-unresolved-symbols", no_argument, NULL, |
545 | OPTION_WARN_UNRESOLVED_SYMBOLS}, | |
560e09e9 | 546 | '\0', NULL, N_("Report unresolved symbols as warnings"), TWO_DASHES }, |
6feb9908 AM |
547 | { {"error-unresolved-symbols", no_argument, NULL, |
548 | OPTION_ERROR_UNRESOLVED_SYMBOLS}, | |
560e09e9 | 549 | '\0', NULL, N_("Report unresolved symbols as errors"), TWO_DASHES }, |
252b5132 | 550 | { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE}, |
6feb9908 AM |
551 | '\0', NULL, N_("Include all objects from following archives"), |
552 | TWO_DASHES }, | |
252b5132 | 553 | { {"wrap", required_argument, NULL, OPTION_WRAP}, |
6feb9908 | 554 | '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES }, |
252b5132 RH |
555 | }; |
556 | ||
e4897a32 | 557 | #define OPTION_COUNT ARRAY_SIZE (ld_options) |
252b5132 | 558 | |
252b5132 | 559 | void |
1579bae1 | 560 | parse_args (unsigned argc, char **argv) |
252b5132 | 561 | { |
e4897a32 NC |
562 | unsigned i; |
563 | int is, il, irl; | |
252b5132 RH |
564 | int ingroup = 0; |
565 | char *default_dirlist = NULL; | |
3bcf5557 AM |
566 | char *shortopts; |
567 | struct option *longopts; | |
568 | struct option *really_longopts; | |
252b5132 | 569 | int last_optind; |
560e09e9 | 570 | enum report_method how_to_report_unresolved_symbols = RM_GENERATE_ERROR; |
252b5132 | 571 | |
1579bae1 AM |
572 | shortopts = xmalloc (OPTION_COUNT * 3 + 2); |
573 | longopts = xmalloc (sizeof (*longopts) * (OPTION_COUNT + 1)); | |
574 | really_longopts = xmalloc (sizeof (*really_longopts) * (OPTION_COUNT + 1)); | |
3bcf5557 | 575 | |
252b5132 RH |
576 | /* Starting the short option string with '-' is for programs that |
577 | expect options and other ARGV-elements in any order and that care about | |
578 | the ordering of the two. We describe each non-option ARGV-element | |
579 | as if it were the argument of an option with character code 1. */ | |
580 | shortopts[0] = '-'; | |
581 | is = 1; | |
582 | il = 0; | |
e4897a32 | 583 | irl = 0; |
252b5132 RH |
584 | for (i = 0; i < OPTION_COUNT; i++) |
585 | { | |
586 | if (ld_options[i].shortopt != '\0') | |
587 | { | |
588 | shortopts[is] = ld_options[i].shortopt; | |
589 | ++is; | |
590 | if (ld_options[i].opt.has_arg == required_argument | |
591 | || ld_options[i].opt.has_arg == optional_argument) | |
592 | { | |
593 | shortopts[is] = ':'; | |
594 | ++is; | |
595 | if (ld_options[i].opt.has_arg == optional_argument) | |
596 | { | |
597 | shortopts[is] = ':'; | |
598 | ++is; | |
599 | } | |
600 | } | |
601 | } | |
602 | if (ld_options[i].opt.name != NULL) | |
603 | { | |
e4897a32 NC |
604 | if (ld_options[i].control == EXACTLY_TWO_DASHES) |
605 | { | |
606 | really_longopts[irl] = ld_options[i].opt; | |
607 | ++irl; | |
608 | } | |
609 | else | |
610 | { | |
611 | longopts[il] = ld_options[i].opt; | |
612 | ++il; | |
613 | } | |
252b5132 RH |
614 | } |
615 | } | |
616 | shortopts[is] = '\0'; | |
617 | longopts[il].name = NULL; | |
e4897a32 | 618 | really_longopts[irl].name = NULL; |
252b5132 | 619 | |
3bcf5557 AM |
620 | ldemul_add_options (is, &shortopts, il, &longopts, irl, &really_longopts); |
621 | ||
252b5132 RH |
622 | /* The -G option is ambiguous on different platforms. Sometimes it |
623 | specifies the largest data size to put into the small data | |
624 | section. Sometimes it is equivalent to --shared. Unfortunately, | |
625 | the first form takes an argument, while the second does not. | |
626 | ||
627 | We need to permit the --shared form because on some platforms, | |
628 | such as Solaris, gcc -shared will pass -G to the linker. | |
629 | ||
630 | To permit either usage, we look through the argument list. If we | |
631 | find -G not followed by a number, we change it into --shared. | |
632 | This will work for most normal cases. */ | |
633 | for (i = 1; i < argc; i++) | |
634 | if (strcmp (argv[i], "-G") == 0 | |
635 | && (i + 1 >= argc | |
3882b010 | 636 | || ! ISDIGIT (argv[i + 1][0]))) |
252b5132 RH |
637 | argv[i] = (char *) "--shared"; |
638 | ||
639 | /* Because we permit long options to start with a single dash, and | |
640 | we have a --library option, and the -l option is conventionally | |
641 | used with an immediately following argument, we can have bad | |
642 | results if somebody tries to use -l with a library whose name | |
643 | happens to start with "ibrary", as in -li. We avoid problems by | |
644 | simply turning -l into --library. This means that users will | |
645 | have to use two dashes in order to use --library, which is OK | |
646 | since that's how it is documented. | |
647 | ||
648 | FIXME: It's possible that this problem can arise for other short | |
649 | options as well, although the user does always have the recourse | |
650 | of adding a space between the option and the argument. */ | |
651 | for (i = 1; i < argc; i++) | |
652 | { | |
653 | if (argv[i][0] == '-' | |
654 | && argv[i][1] == 'l' | |
655 | && argv[i][2] != '\0') | |
656 | { | |
657 | char *n; | |
658 | ||
1579bae1 | 659 | n = xmalloc (strlen (argv[i]) + 20); |
252b5132 RH |
660 | sprintf (n, "--library=%s", argv[i] + 2); |
661 | argv[i] = n; | |
662 | } | |
663 | } | |
664 | ||
665 | last_optind = -1; | |
666 | while (1) | |
667 | { | |
89894c62 | 668 | int longind; |
252b5132 RH |
669 | int optc; |
670 | ||
671 | /* Using last_optind lets us avoid calling ldemul_parse_args | |
672 | multiple times on a single option, which would lead to | |
673 | confusion in the internal static variables maintained by | |
674 | getopt. This could otherwise happen for an argument like | |
675 | -nx, in which the -n is parsed as a single option, and we | |
676 | loop around to pick up the -x. */ | |
677 | if (optind != last_optind) | |
89894c62 AM |
678 | if (ldemul_parse_args (argc, argv)) |
679 | continue; | |
252b5132 RH |
680 | |
681 | /* getopt_long_only is like getopt_long, but '-' as well as '--' | |
682 | can indicate a long option. */ | |
0fc3347a | 683 | opterr = 0; |
89894c62 | 684 | last_optind = optind; |
252b5132 | 685 | optc = getopt_long_only (argc, argv, shortopts, longopts, &longind); |
0fc3347a NC |
686 | if (optc == '?') |
687 | { | |
89894c62 AM |
688 | optind = last_optind; |
689 | optc = getopt_long (argc, argv, "-", really_longopts, &longind); | |
0fc3347a | 690 | } |
b7ed8fad | 691 | |
3bcf5557 AM |
692 | if (ldemul_handle_option (optc)) |
693 | continue; | |
694 | ||
252b5132 RH |
695 | if (optc == -1) |
696 | break; | |
0fc3347a | 697 | |
252b5132 RH |
698 | switch (optc) |
699 | { | |
0fc3347a | 700 | case '?': |
89894c62 | 701 | einfo (_("%P: unrecognized option '%s'\n"), argv[last_optind]); |
058a363d BE |
702 | /* Fall through. */ |
703 | ||
252b5132 | 704 | default: |
210a7bd1 NC |
705 | einfo (_("%P%F: use the --help option for usage information\n")); |
706 | ||
252b5132 | 707 | case 1: /* File name. */ |
1579bae1 | 708 | lang_add_input_file (optarg, lang_input_file_is_file_enum, NULL); |
252b5132 RH |
709 | break; |
710 | ||
711 | case OPTION_IGNORE: | |
712 | break; | |
713 | case 'a': | |
714 | /* For HP/UX compatibility. Actually -a shared should mean | |
1579bae1 AM |
715 | ``use only shared libraries'' but, then, we don't |
716 | currently support shared libraries on HP/UX anyhow. */ | |
252b5132 | 717 | if (strcmp (optarg, "archive") == 0) |
b34976b6 | 718 | config.dynamic_link = FALSE; |
252b5132 RH |
719 | else if (strcmp (optarg, "shared") == 0 |
720 | || strcmp (optarg, "default") == 0) | |
b34976b6 | 721 | config.dynamic_link = TRUE; |
252b5132 RH |
722 | else |
723 | einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg); | |
724 | break; | |
725 | case OPTION_ASSERT: | |
726 | /* FIXME: We just ignore these, but we should handle them. */ | |
727 | if (strcmp (optarg, "definitions") == 0) | |
728 | ; | |
729 | else if (strcmp (optarg, "nodefinitions") == 0) | |
730 | ; | |
731 | else if (strcmp (optarg, "nosymbolic") == 0) | |
732 | ; | |
733 | else if (strcmp (optarg, "pure-text") == 0) | |
734 | ; | |
735 | else | |
736 | einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg); | |
737 | break; | |
738 | case 'A': | |
739 | ldfile_add_arch (optarg); | |
740 | break; | |
741 | case 'b': | |
742 | lang_add_target (optarg); | |
743 | break; | |
744 | case 'c': | |
745 | ldfile_open_command_file (optarg); | |
746 | parser_input = input_mri_script; | |
747 | yyparse (); | |
748 | break; | |
749 | case OPTION_CALL_SHARED: | |
b34976b6 | 750 | config.dynamic_link = TRUE; |
252b5132 RH |
751 | break; |
752 | case OPTION_NON_SHARED: | |
b34976b6 | 753 | config.dynamic_link = FALSE; |
252b5132 RH |
754 | break; |
755 | case OPTION_CREF: | |
b34976b6 AM |
756 | command_line.cref = TRUE; |
757 | link_info.notice_all = TRUE; | |
252b5132 RH |
758 | break; |
759 | case 'd': | |
b34976b6 | 760 | command_line.force_common_definition = TRUE; |
252b5132 RH |
761 | break; |
762 | case OPTION_DEFSYM: | |
763 | lex_string = optarg; | |
764 | lex_redirect (optarg); | |
765 | parser_input = input_defsym; | |
766 | parsing_defsym = 1; | |
767 | yyparse (); | |
768 | parsing_defsym = 0; | |
769 | lex_string = NULL; | |
770 | break; | |
771 | case OPTION_DEMANGLE: | |
b34976b6 | 772 | demangling = TRUE; |
28c309a2 NC |
773 | if (optarg != NULL) |
774 | { | |
775 | enum demangling_styles style; | |
5cc18311 | 776 | |
28c309a2 | 777 | style = cplus_demangle_name_to_style (optarg); |
5cc18311 | 778 | if (style == unknown_demangling) |
28c309a2 NC |
779 | einfo (_("%F%P: unknown demangling style `%s'"), |
780 | optarg); | |
5cc18311 | 781 | |
28c309a2 | 782 | cplus_demangle_set_style (style); |
e47d05ad | 783 | } |
252b5132 | 784 | break; |
506eee22 | 785 | case 'I': /* Used on Solaris. */ |
252b5132 RH |
786 | case OPTION_DYNAMIC_LINKER: |
787 | command_line.interpreter = optarg; | |
788 | break; | |
e2243057 RS |
789 | case OPTION_SYSROOT: |
790 | /* Already handled in ldmain.c. */ | |
791 | break; | |
252b5132 RH |
792 | case OPTION_EB: |
793 | command_line.endian = ENDIAN_BIG; | |
794 | break; | |
795 | case OPTION_EL: | |
796 | command_line.endian = ENDIAN_LITTLE; | |
797 | break; | |
798 | case OPTION_EMBEDDED_RELOCS: | |
b34976b6 | 799 | command_line.embedded_relocs = TRUE; |
252b5132 RH |
800 | break; |
801 | case OPTION_EXPORT_DYNAMIC: | |
802 | case 'E': /* HP/UX compatibility. */ | |
b34976b6 | 803 | link_info.export_dynamic = TRUE; |
252b5132 RH |
804 | break; |
805 | case 'e': | |
b34976b6 | 806 | lang_add_entry (optarg, TRUE); |
252b5132 RH |
807 | break; |
808 | case 'f': | |
809 | if (command_line.auxiliary_filters == NULL) | |
810 | { | |
1579bae1 | 811 | command_line.auxiliary_filters = xmalloc (2 * sizeof (char *)); |
252b5132 RH |
812 | command_line.auxiliary_filters[0] = optarg; |
813 | command_line.auxiliary_filters[1] = NULL; | |
814 | } | |
815 | else | |
816 | { | |
817 | int c; | |
818 | char **p; | |
819 | ||
820 | c = 0; | |
821 | for (p = command_line.auxiliary_filters; *p != NULL; p++) | |
822 | ++c; | |
1579bae1 AM |
823 | command_line.auxiliary_filters |
824 | = xrealloc (command_line.auxiliary_filters, | |
825 | (c + 2) * sizeof (char *)); | |
252b5132 RH |
826 | command_line.auxiliary_filters[c] = optarg; |
827 | command_line.auxiliary_filters[c + 1] = NULL; | |
828 | } | |
829 | break; | |
830 | case 'F': | |
831 | command_line.filter_shlib = optarg; | |
832 | break; | |
833 | case OPTION_FORCE_EXE_SUFFIX: | |
b34976b6 | 834 | command_line.force_exe_suffix = TRUE; |
252b5132 RH |
835 | break; |
836 | case 'G': | |
837 | { | |
838 | char *end; | |
839 | g_switch_value = strtoul (optarg, &end, 0); | |
840 | if (*end) | |
841 | einfo (_("%P%F: invalid number `%s'\n"), optarg); | |
842 | } | |
843 | break; | |
844 | case 'g': | |
845 | /* Ignore. */ | |
846 | break; | |
847 | case OPTION_GC_SECTIONS: | |
57316bff | 848 | link_info.gc_sections = TRUE; |
252b5132 | 849 | break; |
c17d87de NC |
850 | case OPTION_PRINT_GC_SECTIONS: |
851 | link_info.print_gc_sections = TRUE; | |
852 | break; | |
252b5132 RH |
853 | case OPTION_HELP: |
854 | help (); | |
855 | xexit (0); | |
856 | break; | |
857 | case 'L': | |
b34976b6 | 858 | ldfile_add_library_path (optarg, TRUE); |
252b5132 RH |
859 | break; |
860 | case 'l': | |
1579bae1 | 861 | lang_add_input_file (optarg, lang_input_file_is_l_enum, NULL); |
252b5132 RH |
862 | break; |
863 | case 'M': | |
864 | config.map_filename = "-"; | |
865 | break; | |
866 | case 'm': | |
867 | /* Ignore. Was handled in a pre-parse. */ | |
868 | break; | |
869 | case OPTION_MAP: | |
870 | config.map_filename = optarg; | |
871 | break; | |
872 | case 'N': | |
b34976b6 AM |
873 | config.text_read_only = FALSE; |
874 | config.magic_demand_paged = FALSE; | |
875 | config.dynamic_link = FALSE; | |
252b5132 | 876 | break; |
63fd3b82 | 877 | case OPTION_NO_OMAGIC: |
b34976b6 AM |
878 | config.text_read_only = TRUE; |
879 | config.magic_demand_paged = TRUE; | |
880 | /* NB/ Does not set dynamic_link to TRUE. | |
63fd3b82 NC |
881 | Use --call-shared or -Bdynamic for this. */ |
882 | break; | |
252b5132 | 883 | case 'n': |
b34976b6 AM |
884 | config.magic_demand_paged = FALSE; |
885 | config.dynamic_link = FALSE; | |
252b5132 | 886 | break; |
4818e05f | 887 | case OPTION_NO_DEFINE_COMMON: |
b34976b6 | 888 | command_line.inhibit_common_definition = TRUE; |
4818e05f | 889 | break; |
252b5132 | 890 | case OPTION_NO_DEMANGLE: |
b34976b6 | 891 | demangling = FALSE; |
252b5132 RH |
892 | break; |
893 | case OPTION_NO_GC_SECTIONS: | |
57316bff | 894 | link_info.gc_sections = FALSE; |
252b5132 | 895 | break; |
c17d87de NC |
896 | case OPTION_NO_PRINT_GC_SECTIONS: |
897 | link_info.print_gc_sections = FALSE; | |
898 | break; | |
252b5132 | 899 | case OPTION_NO_KEEP_MEMORY: |
b34976b6 | 900 | link_info.keep_memory = FALSE; |
252b5132 RH |
901 | break; |
902 | case OPTION_NO_UNDEFINED: | |
6feb9908 AM |
903 | link_info.unresolved_syms_in_objects |
904 | = how_to_report_unresolved_symbols; | |
252b5132 | 905 | break; |
b79e8c78 | 906 | case OPTION_ALLOW_SHLIB_UNDEFINED: |
560e09e9 | 907 | link_info.unresolved_syms_in_shared_libs = RM_IGNORE; |
b79e8c78 | 908 | break; |
ae9a127f | 909 | case OPTION_NO_ALLOW_SHLIB_UNDEFINED: |
6feb9908 AM |
910 | link_info.unresolved_syms_in_shared_libs |
911 | = how_to_report_unresolved_symbols; | |
ae9a127f | 912 | break; |
560e09e9 NC |
913 | case OPTION_UNRESOLVED_SYMBOLS: |
914 | if (strcmp (optarg, "ignore-all") == 0) | |
915 | { | |
916 | link_info.unresolved_syms_in_objects = RM_IGNORE; | |
917 | link_info.unresolved_syms_in_shared_libs = RM_IGNORE; | |
918 | } | |
919 | else if (strcmp (optarg, "report-all") == 0) | |
920 | { | |
6feb9908 AM |
921 | link_info.unresolved_syms_in_objects |
922 | = how_to_report_unresolved_symbols; | |
923 | link_info.unresolved_syms_in_shared_libs | |
924 | = how_to_report_unresolved_symbols; | |
560e09e9 NC |
925 | } |
926 | else if (strcmp (optarg, "ignore-in-object-files") == 0) | |
927 | { | |
928 | link_info.unresolved_syms_in_objects = RM_IGNORE; | |
6feb9908 AM |
929 | link_info.unresolved_syms_in_shared_libs |
930 | = how_to_report_unresolved_symbols; | |
560e09e9 NC |
931 | } |
932 | else if (strcmp (optarg, "ignore-in-shared-libs") == 0) | |
933 | { | |
6feb9908 AM |
934 | link_info.unresolved_syms_in_objects |
935 | = how_to_report_unresolved_symbols; | |
560e09e9 NC |
936 | link_info.unresolved_syms_in_shared_libs = RM_IGNORE; |
937 | } | |
938 | else | |
939 | einfo (_("%P%F: bad --unresolved-symbols option: %s\n"), optarg); | |
940 | break; | |
941 | case OPTION_WARN_UNRESOLVED_SYMBOLS: | |
942 | how_to_report_unresolved_symbols = RM_GENERATE_WARNING; | |
943 | if (link_info.unresolved_syms_in_objects == RM_GENERATE_ERROR) | |
944 | link_info.unresolved_syms_in_objects = RM_GENERATE_WARNING; | |
945 | if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_ERROR) | |
946 | link_info.unresolved_syms_in_shared_libs = RM_GENERATE_WARNING; | |
947 | break; | |
6feb9908 | 948 | |
560e09e9 NC |
949 | case OPTION_ERROR_UNRESOLVED_SYMBOLS: |
950 | how_to_report_unresolved_symbols = RM_GENERATE_ERROR; | |
951 | if (link_info.unresolved_syms_in_objects == RM_GENERATE_WARNING) | |
952 | link_info.unresolved_syms_in_objects = RM_GENERATE_ERROR; | |
953 | if (link_info.unresolved_syms_in_shared_libs == RM_GENERATE_WARNING) | |
954 | link_info.unresolved_syms_in_shared_libs = RM_GENERATE_ERROR; | |
6feb9908 | 955 | break; |
aa713662 | 956 | case OPTION_ALLOW_MULTIPLE_DEFINITION: |
b34976b6 | 957 | link_info.allow_multiple_definition = TRUE; |
aa713662 | 958 | break; |
31941635 | 959 | case OPTION_NO_UNDEFINED_VERSION: |
b34976b6 | 960 | link_info.allow_undefined_version = FALSE; |
31941635 | 961 | break; |
3e3b46e5 PB |
962 | case OPTION_DEFAULT_SYMVER: |
963 | link_info.create_default_symver = TRUE; | |
964 | break; | |
fc0e6df6 PB |
965 | case OPTION_DEFAULT_IMPORTED_SYMVER: |
966 | link_info.default_imported_symver = TRUE; | |
967 | break; | |
252b5132 | 968 | case OPTION_NO_WARN_MISMATCH: |
b34976b6 | 969 | command_line.warn_mismatch = FALSE; |
252b5132 | 970 | break; |
fe7929ce AM |
971 | case OPTION_NO_WARN_SEARCH_MISMATCH: |
972 | command_line.warn_search_mismatch = FALSE; | |
973 | break; | |
252b5132 | 974 | case OPTION_NOINHIBIT_EXEC: |
b34976b6 | 975 | force_make_executable = TRUE; |
252b5132 | 976 | break; |
361b220e | 977 | case OPTION_NOSTDLIB: |
b34976b6 | 978 | config.only_cmd_line_lib_dirs = TRUE; |
361b220e | 979 | break; |
252b5132 | 980 | case OPTION_NO_WHOLE_ARCHIVE: |
b34976b6 | 981 | whole_archive = FALSE; |
252b5132 RH |
982 | break; |
983 | case 'O': | |
984 | /* FIXME "-O<non-digits> <value>" used to set the address of | |
985 | section <non-digits>. Was this for compatibility with | |
986 | something, or can we create a new option to do that | |
987 | (with a syntax similar to -defsym)? | |
988 | getopt can't handle two args to an option without kludges. */ | |
989 | ||
990 | /* Enable optimizations of output files. */ | |
b34976b6 | 991 | link_info.optimize = strtoul (optarg, NULL, 0) ? TRUE : FALSE; |
252b5132 RH |
992 | break; |
993 | case 'o': | |
5cc18311 | 994 | lang_add_output (optarg, 0); |
252b5132 RH |
995 | break; |
996 | case OPTION_OFORMAT: | |
1579bae1 | 997 | lang_add_output_format (optarg, NULL, NULL, 0); |
252b5132 | 998 | break; |
a712da20 | 999 | case 'q': |
b34976b6 | 1000 | link_info.emitrelocations = TRUE; |
a712da20 | 1001 | break; |
8c5ff972 | 1002 | case 'i': |
252b5132 | 1003 | case 'r': |
210a7bd1 NC |
1004 | if (optind == last_optind) |
1005 | /* This can happen if the user put "-rpath,a" on the command | |
1006 | line. (Or something similar. The comma is important). | |
1007 | Getopt becomes confused and thinks that this is a -r option | |
1008 | but it cannot parse the text after the -r so it refuses to | |
1009 | increment the optind counter. Detect this case and issue | |
1010 | an error message here. We cannot just make this a warning, | |
1011 | increment optind, and continue because getopt is too confused | |
1012 | and will seg-fault the next time around. */ | |
1013 | einfo(_("%P%F: bad -rpath option\n")); | |
b7a26f91 | 1014 | |
1049f94e | 1015 | link_info.relocatable = TRUE; |
b34976b6 AM |
1016 | config.build_constructors = FALSE; |
1017 | config.magic_demand_paged = FALSE; | |
1018 | config.text_read_only = FALSE; | |
1019 | config.dynamic_link = FALSE; | |
252b5132 RH |
1020 | break; |
1021 | case 'R': | |
1022 | /* The GNU linker traditionally uses -R to mean to include | |
1023 | only the symbols from a file. The Solaris linker uses -R | |
1024 | to set the path used by the runtime linker to find | |
1025 | libraries. This is the GNU linker -rpath argument. We | |
1026 | try to support both simultaneously by checking the file | |
1027 | named. If it is a directory, rather than a regular file, | |
1028 | we assume -rpath was meant. */ | |
1029 | { | |
1030 | struct stat s; | |
1031 | ||
1032 | if (stat (optarg, &s) >= 0 | |
1033 | && ! S_ISDIR (s.st_mode)) | |
1034 | { | |
1035 | lang_add_input_file (optarg, | |
1036 | lang_input_file_is_symbols_only_enum, | |
1579bae1 | 1037 | NULL); |
252b5132 RH |
1038 | break; |
1039 | } | |
1040 | } | |
1041 | /* Fall through. */ | |
1042 | case OPTION_RPATH: | |
1043 | if (command_line.rpath == NULL) | |
d1b2b2dc | 1044 | command_line.rpath = xstrdup (optarg); |
252b5132 RH |
1045 | else |
1046 | { | |
1047 | size_t rpath_len = strlen (command_line.rpath); | |
1048 | size_t optarg_len = strlen (optarg); | |
1049 | char *buf; | |
1050 | char *cp = command_line.rpath; | |
1051 | ||
1052 | /* First see whether OPTARG is already in the path. */ | |
1053 | do | |
1054 | { | |
c76308d2 RS |
1055 | if (strncmp (optarg, cp, optarg_len) == 0 |
1056 | && (cp[optarg_len] == 0 | |
1057 | || cp[optarg_len] == config.rpath_separator)) | |
252b5132 RH |
1058 | /* We found it. */ |
1059 | break; | |
1060 | ||
1061 | /* Not yet found. */ | |
c76308d2 | 1062 | cp = strchr (cp, config.rpath_separator); |
252b5132 RH |
1063 | if (cp != NULL) |
1064 | ++cp; | |
1065 | } | |
1066 | while (cp != NULL); | |
1067 | ||
1068 | if (cp == NULL) | |
1069 | { | |
1070 | buf = xmalloc (rpath_len + optarg_len + 2); | |
c76308d2 RS |
1071 | sprintf (buf, "%s%c%s", command_line.rpath, |
1072 | config.rpath_separator, optarg); | |
252b5132 RH |
1073 | free (command_line.rpath); |
1074 | command_line.rpath = buf; | |
1075 | } | |
1076 | } | |
1077 | break; | |
1078 | case OPTION_RPATH_LINK: | |
1079 | if (command_line.rpath_link == NULL) | |
d1b2b2dc | 1080 | command_line.rpath_link = xstrdup (optarg); |
252b5132 RH |
1081 | else |
1082 | { | |
1083 | char *buf; | |
1084 | ||
1085 | buf = xmalloc (strlen (command_line.rpath_link) | |
1086 | + strlen (optarg) | |
1087 | + 2); | |
c76308d2 RS |
1088 | sprintf (buf, "%s%c%s", command_line.rpath_link, |
1089 | config.rpath_separator, optarg); | |
252b5132 RH |
1090 | free (command_line.rpath_link); |
1091 | command_line.rpath_link = buf; | |
1092 | } | |
1093 | break; | |
1094 | case OPTION_RELAX: | |
b34976b6 | 1095 | command_line.relax = TRUE; |
252b5132 RH |
1096 | break; |
1097 | case OPTION_RETAIN_SYMBOLS_FILE: | |
1098 | add_keepsyms_file (optarg); | |
1099 | break; | |
1100 | case 'S': | |
1101 | link_info.strip = strip_debugger; | |
1102 | break; | |
1103 | case 's': | |
1104 | link_info.strip = strip_all; | |
1105 | break; | |
d5cd3933 AM |
1106 | case OPTION_STRIP_DISCARDED: |
1107 | link_info.strip_discarded = TRUE; | |
1108 | break; | |
1109 | case OPTION_NO_STRIP_DISCARDED: | |
1110 | link_info.strip_discarded = FALSE; | |
1111 | break; | |
252b5132 RH |
1112 | case OPTION_SHARED: |
1113 | if (config.has_shared) | |
560e09e9 NC |
1114 | { |
1115 | link_info.shared = TRUE; | |
1116 | /* When creating a shared library, the default | |
1117 | behaviour is to ignore any unresolved references. */ | |
1118 | if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) | |
1119 | link_info.unresolved_syms_in_objects = RM_IGNORE; | |
1120 | if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET) | |
1121 | link_info.unresolved_syms_in_shared_libs = RM_IGNORE; | |
1122 | } | |
252b5132 RH |
1123 | else |
1124 | einfo (_("%P%F: -shared not supported\n")); | |
1125 | break; | |
36af4a4e JJ |
1126 | case OPTION_PIE: |
1127 | if (config.has_shared) | |
1128 | { | |
1129 | link_info.shared = TRUE; | |
1130 | link_info.pie = TRUE; | |
1131 | } | |
1132 | else | |
1133 | einfo (_("%P%F: -pie not supported\n")); | |
1134 | break; | |
252b5132 RH |
1135 | case 'h': /* Used on Solaris. */ |
1136 | case OPTION_SONAME: | |
1137 | command_line.soname = optarg; | |
1138 | break; | |
1139 | case OPTION_SORT_COMMON: | |
b34976b6 | 1140 | config.sort_common = TRUE; |
252b5132 | 1141 | break; |
bcaa7b3e L |
1142 | case OPTION_SORT_SECTION: |
1143 | if (strcmp (optarg, N_("name")) == 0) | |
1144 | sort_section = by_name; | |
1145 | else if (strcmp (optarg, N_("alignment")) == 0) | |
1146 | sort_section = by_alignment; | |
1147 | else | |
1148 | einfo (_("%P%F: invalid section sorting option: %s\n"), | |
1149 | optarg); | |
1150 | break; | |
252b5132 | 1151 | case OPTION_STATS: |
b34976b6 | 1152 | config.stats = TRUE; |
252b5132 RH |
1153 | break; |
1154 | case OPTION_SYMBOLIC: | |
d8cf8b51 L |
1155 | command_line.symbolic = symbolic; |
1156 | break; | |
1157 | case OPTION_SYMBOLIC_FUNCTIONS: | |
1158 | command_line.symbolic = symbolic_functions; | |
252b5132 RH |
1159 | break; |
1160 | case 't': | |
b34976b6 | 1161 | trace_files = TRUE; |
252b5132 RH |
1162 | break; |
1163 | case 'T': | |
1164 | ldfile_open_command_file (optarg); | |
1165 | parser_input = input_script; | |
1166 | yyparse (); | |
1167 | break; | |
14be8564 L |
1168 | case OPTION_DEFAULT_SCRIPT: |
1169 | command_line.default_script = optarg; | |
1170 | break; | |
176355da NC |
1171 | case OPTION_SECTION_START: |
1172 | { | |
1173 | char *optarg2; | |
227aeb07 AM |
1174 | char *sec_name; |
1175 | int len; | |
176355da NC |
1176 | |
1177 | /* Check for <something>=<somthing>... */ | |
1178 | optarg2 = strchr (optarg, '='); | |
1179 | if (optarg2 == NULL) | |
6feb9908 AM |
1180 | einfo (_("%P%F: invalid argument to option" |
1181 | " \"--section-start\"\n")); | |
176355da | 1182 | |
e47d05ad | 1183 | optarg2++; |
5cc18311 | 1184 | |
176355da NC |
1185 | /* So far so good. Are all the args present? */ |
1186 | if ((*optarg == '\0') || (*optarg2 == '\0')) | |
6feb9908 AM |
1187 | einfo (_("%P%F: missing argument(s) to option" |
1188 | " \"--section-start\"\n")); | |
176355da | 1189 | |
227aeb07 AM |
1190 | /* We must copy the section name as set_section_start |
1191 | doesn't do it for us. */ | |
1192 | len = optarg2 - optarg; | |
1193 | sec_name = xmalloc (len); | |
1194 | memcpy (sec_name, optarg, len - 1); | |
1195 | sec_name[len - 1] = 0; | |
176355da NC |
1196 | |
1197 | /* Then set it... */ | |
227aeb07 | 1198 | set_section_start (sec_name, optarg2); |
176355da NC |
1199 | } |
1200 | break; | |
ea20a7da CC |
1201 | case OPTION_TARGET_HELP: |
1202 | /* Mention any target specific options. */ | |
b7a26f91 KH |
1203 | ldemul_list_emulation_options (stdout); |
1204 | exit (0); | |
252b5132 | 1205 | case OPTION_TBSS: |
ba916c8a | 1206 | set_segment_start (".bss", optarg); |
252b5132 RH |
1207 | break; |
1208 | case OPTION_TDATA: | |
ba916c8a | 1209 | set_segment_start (".data", optarg); |
252b5132 RH |
1210 | break; |
1211 | case OPTION_TTEXT: | |
ba916c8a | 1212 | set_segment_start (".text", optarg); |
252b5132 RH |
1213 | break; |
1214 | case OPTION_TRADITIONAL_FORMAT: | |
b34976b6 | 1215 | link_info.traditional_format = TRUE; |
252b5132 RH |
1216 | break; |
1217 | case OPTION_TASK_LINK: | |
b34976b6 | 1218 | link_info.task_link = TRUE; |
252b5132 RH |
1219 | /* Fall through - do an implied -r option. */ |
1220 | case OPTION_UR: | |
1049f94e | 1221 | link_info.relocatable = TRUE; |
b34976b6 AM |
1222 | config.build_constructors = TRUE; |
1223 | config.magic_demand_paged = FALSE; | |
1224 | config.text_read_only = FALSE; | |
1225 | config.dynamic_link = FALSE; | |
252b5132 RH |
1226 | break; |
1227 | case 'u': | |
1228 | ldlang_add_undef (optarg); | |
1229 | break; | |
a854a4a7 | 1230 | case OPTION_UNIQUE: |
577a0623 AM |
1231 | if (optarg != NULL) |
1232 | lang_add_unique (optarg); | |
1233 | else | |
b34976b6 | 1234 | config.unique_orphan_sections = TRUE; |
a854a4a7 | 1235 | break; |
252b5132 RH |
1236 | case OPTION_VERBOSE: |
1237 | ldversion (1); | |
b34976b6 AM |
1238 | version_printed = TRUE; |
1239 | trace_file_tries = TRUE; | |
8aae64e6 | 1240 | overflow_cutoff_limit = -2; |
252b5132 RH |
1241 | break; |
1242 | case 'v': | |
1243 | ldversion (0); | |
b34976b6 | 1244 | version_printed = TRUE; |
252b5132 RH |
1245 | break; |
1246 | case 'V': | |
1247 | ldversion (1); | |
b34976b6 | 1248 | version_printed = TRUE; |
252b5132 RH |
1249 | break; |
1250 | case OPTION_VERSION: | |
d32820f2 | 1251 | ldversion (2); |
252b5132 RH |
1252 | xexit (0); |
1253 | break; | |
1254 | case OPTION_VERSION_SCRIPT: | |
1255 | /* This option indicates a small script that only specifies | |
1579bae1 AM |
1256 | version information. Read it, but don't assume that |
1257 | we've seen a linker script. */ | |
252b5132 | 1258 | { |
b7a26f91 | 1259 | FILE *hold_script_handle; |
252b5132 | 1260 | |
b9a8de1e | 1261 | hold_script_handle = saved_script_handle; |
252b5132 | 1262 | ldfile_open_command_file (optarg); |
b9a8de1e | 1263 | saved_script_handle = hold_script_handle; |
252b5132 RH |
1264 | parser_input = input_version_script; |
1265 | yyparse (); | |
1266 | } | |
1267 | break; | |
1268 | case OPTION_VERSION_EXPORTS_SECTION: | |
1269 | /* This option records a version symbol to be applied to the | |
1270 | symbols listed for export to be found in the object files | |
1271 | .exports sections. */ | |
1272 | command_line.version_exports_section = optarg; | |
1273 | break; | |
40b36307 | 1274 | case OPTION_DYNAMIC_LIST_DATA: |
d8cf8b51 L |
1275 | command_line.dynamic_list = dynamic_list_data; |
1276 | if (command_line.symbolic == symbolic) | |
1277 | command_line.symbolic = symbolic_unset; | |
40b36307 | 1278 | break; |
55255dae L |
1279 | case OPTION_DYNAMIC_LIST_CPP_TYPEINFO: |
1280 | lang_append_dynamic_list_cpp_typeinfo (); | |
d8cf8b51 L |
1281 | if (command_line.dynamic_list != dynamic_list_data) |
1282 | command_line.dynamic_list = dynamic_list; | |
1283 | if (command_line.symbolic == symbolic) | |
1284 | command_line.symbolic = symbolic_unset; | |
40b36307 L |
1285 | break; |
1286 | case OPTION_DYNAMIC_LIST_CPP_NEW: | |
1287 | lang_append_dynamic_list_cpp_new (); | |
d8cf8b51 L |
1288 | if (command_line.dynamic_list != dynamic_list_data) |
1289 | command_line.dynamic_list = dynamic_list; | |
1290 | if (command_line.symbolic == symbolic) | |
1291 | command_line.symbolic = symbolic_unset; | |
55255dae L |
1292 | break; |
1293 | case OPTION_DYNAMIC_LIST: | |
1294 | /* This option indicates a small script that only specifies | |
1295 | a dynamic list. Read it, but don't assume that we've | |
1296 | seen a linker script. */ | |
1297 | { | |
1298 | FILE *hold_script_handle; | |
1299 | ||
1300 | hold_script_handle = saved_script_handle; | |
1301 | ldfile_open_command_file (optarg); | |
1302 | saved_script_handle = hold_script_handle; | |
1303 | parser_input = input_dynamic_list; | |
1304 | yyparse (); | |
1305 | } | |
d8cf8b51 L |
1306 | if (command_line.dynamic_list != dynamic_list_data) |
1307 | command_line.dynamic_list = dynamic_list; | |
1308 | if (command_line.symbolic == symbolic) | |
1309 | command_line.symbolic = symbolic_unset; | |
55255dae | 1310 | break; |
252b5132 | 1311 | case OPTION_WARN_COMMON: |
b34976b6 | 1312 | config.warn_common = TRUE; |
252b5132 RH |
1313 | break; |
1314 | case OPTION_WARN_CONSTRUCTORS: | |
b34976b6 | 1315 | config.warn_constructors = TRUE; |
252b5132 | 1316 | break; |
7ce691ae | 1317 | case OPTION_WARN_FATAL: |
b34976b6 | 1318 | config.fatal_warnings = TRUE; |
7ce691ae | 1319 | break; |
252b5132 | 1320 | case OPTION_WARN_MULTIPLE_GP: |
b34976b6 | 1321 | config.warn_multiple_gp = TRUE; |
252b5132 RH |
1322 | break; |
1323 | case OPTION_WARN_ONCE: | |
b34976b6 | 1324 | config.warn_once = TRUE; |
252b5132 RH |
1325 | break; |
1326 | case OPTION_WARN_SECTION_ALIGN: | |
b34976b6 | 1327 | config.warn_section_align = TRUE; |
252b5132 | 1328 | break; |
8fdd7217 NC |
1329 | case OPTION_WARN_SHARED_TEXTREL: |
1330 | link_info.warn_shared_textrel = TRUE; | |
1331 | break; | |
252b5132 | 1332 | case OPTION_WHOLE_ARCHIVE: |
b34976b6 | 1333 | whole_archive = TRUE; |
252b5132 | 1334 | break; |
e56f61be L |
1335 | case OPTION_ADD_NEEDED: |
1336 | add_needed = TRUE; | |
1337 | break; | |
1338 | case OPTION_NO_ADD_NEEDED: | |
1339 | add_needed = FALSE; | |
1340 | break; | |
4a43e768 AM |
1341 | case OPTION_AS_NEEDED: |
1342 | as_needed = TRUE; | |
1343 | break; | |
1344 | case OPTION_NO_AS_NEEDED: | |
1345 | as_needed = FALSE; | |
1346 | break; | |
252b5132 RH |
1347 | case OPTION_WRAP: |
1348 | add_wrap (optarg); | |
1349 | break; | |
f5fa8ca2 JJ |
1350 | case OPTION_DISCARD_NONE: |
1351 | link_info.discard = discard_none; | |
1352 | break; | |
252b5132 RH |
1353 | case 'X': |
1354 | link_info.discard = discard_l; | |
1355 | break; | |
1356 | case 'x': | |
1357 | link_info.discard = discard_all; | |
1358 | break; | |
1359 | case 'Y': | |
0112cd26 | 1360 | if (CONST_STRNEQ (optarg, "P,")) |
252b5132 | 1361 | optarg += 2; |
5ed6aba4 NC |
1362 | if (default_dirlist != NULL) |
1363 | free (default_dirlist); | |
252b5132 RH |
1364 | default_dirlist = xstrdup (optarg); |
1365 | break; | |
1366 | case 'y': | |
1367 | add_ysym (optarg); | |
1368 | break; | |
db6751f2 JJ |
1369 | case OPTION_SPARE_DYNAMIC_TAGS: |
1370 | link_info.spare_dynamic_tags = strtoul (optarg, NULL, 0); | |
1371 | break; | |
252b5132 | 1372 | case OPTION_SPLIT_BY_RELOC: |
a854a4a7 AM |
1373 | if (optarg != NULL) |
1374 | config.split_by_reloc = strtoul (optarg, NULL, 0); | |
1375 | else | |
1376 | config.split_by_reloc = 32768; | |
5cc18311 | 1377 | break; |
252b5132 | 1378 | case OPTION_SPLIT_BY_FILE: |
a854a4a7 AM |
1379 | if (optarg != NULL) |
1380 | config.split_by_file = bfd_scan_vma (optarg, NULL, 0); | |
1381 | else | |
1382 | config.split_by_file = 1; | |
5cc18311 | 1383 | break; |
252b5132 | 1384 | case OPTION_CHECK_SECTIONS: |
b34976b6 | 1385 | command_line.check_section_addresses = TRUE; |
252b5132 RH |
1386 | break; |
1387 | case OPTION_NO_CHECK_SECTIONS: | |
b34976b6 | 1388 | command_line.check_section_addresses = FALSE; |
252b5132 | 1389 | break; |
312b768e NC |
1390 | case OPTION_ACCEPT_UNKNOWN_INPUT_ARCH: |
1391 | command_line.accept_unknown_input_arch = TRUE; | |
1392 | break; | |
1393 | case OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH: | |
1394 | command_line.accept_unknown_input_arch = FALSE; | |
1395 | break; | |
252b5132 RH |
1396 | case '(': |
1397 | if (ingroup) | |
210a7bd1 NC |
1398 | einfo (_("%P%F: may not nest groups (--help for usage)\n")); |
1399 | ||
252b5132 RH |
1400 | lang_enter_group (); |
1401 | ingroup = 1; | |
1402 | break; | |
1403 | case ')': | |
1404 | if (! ingroup) | |
210a7bd1 NC |
1405 | einfo (_("%P%F: group ended before it began (--help for usage)\n")); |
1406 | ||
252b5132 RH |
1407 | lang_leave_group (); |
1408 | ingroup = 0; | |
1409 | break; | |
3dbf70a2 MM |
1410 | |
1411 | case OPTION_INIT: | |
1412 | link_info.init_function = optarg; | |
1413 | break; | |
5cc18311 | 1414 | |
3dbf70a2 MM |
1415 | case OPTION_FINI: |
1416 | link_info.fini_function = optarg; | |
1417 | break; | |
2d643429 | 1418 | |
35835446 | 1419 | case OPTION_REDUCE_MEMORY_OVERHEADS: |
c0f00686 | 1420 | link_info.reduce_memory_overheads = TRUE; |
2d643429 NC |
1421 | if (config.hash_table_size == 0) |
1422 | config.hash_table_size = 1021; | |
35835446 | 1423 | break; |
2d643429 NC |
1424 | |
1425 | case OPTION_HASH_SIZE: | |
1426 | { | |
1427 | bfd_size_type new_size; | |
1428 | ||
1429 | new_size = strtoul (optarg, NULL, 0); | |
1430 | if (new_size) | |
1431 | config.hash_table_size = new_size; | |
1432 | else | |
1433 | einfo (_("%P%X: --hash-size needs a numeric argument\n")); | |
1434 | } | |
1435 | break; | |
252b5132 RH |
1436 | } |
1437 | } | |
1438 | ||
1439 | if (ingroup) | |
1440 | lang_leave_group (); | |
1441 | ||
1442 | if (default_dirlist != NULL) | |
5ed6aba4 NC |
1443 | { |
1444 | set_default_dirlist (default_dirlist); | |
1445 | free (default_dirlist); | |
1446 | } | |
560e09e9 NC |
1447 | |
1448 | if (link_info.unresolved_syms_in_objects == RM_NOT_YET_SET) | |
1449 | /* FIXME: Should we allow emulations a chance to set this ? */ | |
1450 | link_info.unresolved_syms_in_objects = how_to_report_unresolved_symbols; | |
6feb9908 | 1451 | |
560e09e9 NC |
1452 | if (link_info.unresolved_syms_in_shared_libs == RM_NOT_YET_SET) |
1453 | /* FIXME: Should we allow emulations a chance to set this ? */ | |
1454 | link_info.unresolved_syms_in_shared_libs = how_to_report_unresolved_symbols; | |
252b5132 RH |
1455 | } |
1456 | ||
1457 | /* Add the (colon-separated) elements of DIRLIST_PTR to the | |
1458 | library search path. */ | |
1459 | ||
1460 | static void | |
1579bae1 | 1461 | set_default_dirlist (char *dirlist_ptr) |
252b5132 RH |
1462 | { |
1463 | char *p; | |
1464 | ||
1465 | while (1) | |
1466 | { | |
1467 | p = strchr (dirlist_ptr, PATH_SEPARATOR); | |
1468 | if (p != NULL) | |
1469 | *p = '\0'; | |
1470 | if (*dirlist_ptr != '\0') | |
b34976b6 | 1471 | ldfile_add_library_path (dirlist_ptr, TRUE); |
252b5132 RH |
1472 | if (p == NULL) |
1473 | break; | |
1474 | dirlist_ptr = p + 1; | |
1475 | } | |
1476 | } | |
1477 | ||
1478 | static void | |
1579bae1 | 1479 | set_section_start (char *sect, char *valstr) |
252b5132 | 1480 | { |
93697284 AM |
1481 | const char *end; |
1482 | bfd_vma val = bfd_scan_vma (valstr, &end, 16); | |
252b5132 RH |
1483 | if (*end) |
1484 | einfo (_("%P%F: invalid hex number `%s'\n"), valstr); | |
ba916c8a | 1485 | lang_section_start (sect, exp_intop (val), NULL); |
252b5132 | 1486 | } |
ba916c8a MM |
1487 | |
1488 | static void | |
1489 | set_segment_start (const char *section, char *valstr) | |
1490 | { | |
1491 | const char *name; | |
1492 | const char *end; | |
1493 | segment_type *seg; | |
1494 | ||
1495 | bfd_vma val = bfd_scan_vma (valstr, &end, 16); | |
1496 | if (*end) | |
1497 | einfo (_("%P%F: invalid hex number `%s'\n"), valstr); | |
1498 | /* If we already have an entry for this segment, update the existing | |
1499 | value. */ | |
1500 | name = section + 1; | |
1501 | for (seg = segments; seg; seg = seg->next) | |
1502 | if (strcmp (seg->name, name) == 0) | |
1503 | { | |
1504 | seg->value = val; | |
1505 | return; | |
1506 | } | |
1507 | /* There was no existing value so we must create a new segment | |
1508 | entry. */ | |
1509 | seg = stat_alloc (sizeof (*seg)); | |
1510 | seg->name = name; | |
1511 | seg->value = val; | |
1512 | seg->used = FALSE; | |
1513 | /* Add it to the linked list of segments. */ | |
1514 | seg->next = segments; | |
1515 | segments = seg; | |
1516 | /* Historically, -Ttext and friends set the base address of a | |
1517 | particular section. For backwards compatibility, we still do | |
1518 | that. If a SEGMENT_START directive is seen, the section address | |
1519 | assignment will be disabled. */ | |
1520 | lang_section_start (section, exp_intop (val), seg); | |
1521 | } | |
1522 | ||
252b5132 RH |
1523 | \f |
1524 | /* Print help messages for the options. */ | |
1525 | ||
1526 | static void | |
1579bae1 | 1527 | help (void) |
252b5132 | 1528 | { |
e4897a32 | 1529 | unsigned i; |
252b5132 | 1530 | const char **targets, **pp; |
a55ff675 | 1531 | int len; |
252b5132 RH |
1532 | |
1533 | printf (_("Usage: %s [options] file...\n"), program_name); | |
1534 | ||
1535 | printf (_("Options:\n")); | |
1536 | for (i = 0; i < OPTION_COUNT; i++) | |
1537 | { | |
1538 | if (ld_options[i].doc != NULL) | |
1539 | { | |
b34976b6 | 1540 | bfd_boolean comma; |
e4897a32 | 1541 | unsigned j; |
252b5132 RH |
1542 | |
1543 | printf (" "); | |
1544 | ||
b34976b6 | 1545 | comma = FALSE; |
252b5132 RH |
1546 | len = 2; |
1547 | ||
1548 | j = i; | |
1549 | do | |
1550 | { | |
1551 | if (ld_options[j].shortopt != '\0' | |
1552 | && ld_options[j].control != NO_HELP) | |
1553 | { | |
1554 | printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt); | |
1555 | len += (comma ? 2 : 0) + 2; | |
1556 | if (ld_options[j].arg != NULL) | |
1557 | { | |
1558 | if (ld_options[j].opt.has_arg != optional_argument) | |
1559 | { | |
1560 | printf (" "); | |
1561 | ++len; | |
1562 | } | |
1563 | printf ("%s", _(ld_options[j].arg)); | |
1564 | len += strlen (_(ld_options[j].arg)); | |
1565 | } | |
b34976b6 | 1566 | comma = TRUE; |
252b5132 RH |
1567 | } |
1568 | ++j; | |
1569 | } | |
1570 | while (j < OPTION_COUNT && ld_options[j].doc == NULL); | |
1571 | ||
1572 | j = i; | |
1573 | do | |
1574 | { | |
1575 | if (ld_options[j].opt.name != NULL | |
1576 | && ld_options[j].control != NO_HELP) | |
1577 | { | |
e4897a32 NC |
1578 | int two_dashes = |
1579 | (ld_options[j].control == TWO_DASHES | |
1580 | || ld_options[j].control == EXACTLY_TWO_DASHES); | |
b7a26f91 | 1581 | |
252b5132 RH |
1582 | printf ("%s-%s%s", |
1583 | comma ? ", " : "", | |
e4897a32 | 1584 | two_dashes ? "-" : "", |
252b5132 RH |
1585 | ld_options[j].opt.name); |
1586 | len += ((comma ? 2 : 0) | |
1587 | + 1 | |
e4897a32 | 1588 | + (two_dashes ? 1 : 0) |
252b5132 RH |
1589 | + strlen (ld_options[j].opt.name)); |
1590 | if (ld_options[j].arg != NULL) | |
1591 | { | |
1592 | printf (" %s", _(ld_options[j].arg)); | |
1593 | len += 1 + strlen (_(ld_options[j].arg)); | |
1594 | } | |
b34976b6 | 1595 | comma = TRUE; |
252b5132 RH |
1596 | } |
1597 | ++j; | |
1598 | } | |
1599 | while (j < OPTION_COUNT && ld_options[j].doc == NULL); | |
1600 | ||
1601 | if (len >= 30) | |
1602 | { | |
1603 | printf ("\n"); | |
1604 | len = 0; | |
1605 | } | |
1606 | ||
1607 | for (; len < 30; len++) | |
1608 | putchar (' '); | |
1609 | ||
1610 | printf ("%s\n", _(ld_options[i].doc)); | |
1611 | } | |
1612 | } | |
a55ff675 MM |
1613 | printf (_(" @FILE")); |
1614 | for (len = strlen (" @FILE"); len < 30; len++) | |
1615 | putchar (' '); | |
1616 | printf (_("Read options from FILE\n")); | |
252b5132 | 1617 | |
f75692fe NC |
1618 | /* Note: Various tools (such as libtool) depend upon the |
1619 | format of the listings below - do not change them. */ | |
252b5132 | 1620 | /* xgettext:c-format */ |
f75692fe | 1621 | printf (_("%s: supported targets:"), program_name); |
252b5132 RH |
1622 | targets = bfd_target_list (); |
1623 | for (pp = targets; *pp != NULL; pp++) | |
1624 | printf (" %s", *pp); | |
1625 | free (targets); | |
1626 | printf ("\n"); | |
1627 | ||
1628 | /* xgettext:c-format */ | |
f75692fe | 1629 | printf (_("%s: supported emulations: "), program_name); |
252b5132 RH |
1630 | ldemul_list_emulations (stdout); |
1631 | printf ("\n"); | |
1632 | ||
1633 | /* xgettext:c-format */ | |
1634 | printf (_("%s: emulation specific options:\n"), program_name); | |
1635 | ldemul_list_emulation_options (stdout); | |
1636 | printf ("\n"); | |
c20f4f8c | 1637 | |
92f01d61 JM |
1638 | if (REPORT_BUGS_TO[0]) |
1639 | printf (_("Report bugs to %s\n"), REPORT_BUGS_TO); | |
252b5132 | 1640 | } |