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