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