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