]>
Commit | Line | Data |
---|---|---|
d4e5e3c3 | 1 | /* Parse options for the GNU linker. |
8bc8f4bc TT |
2 | Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 1998 |
3 | Free Software Foundation, Inc. | |
d4e5e3c3 DM |
4 | |
5 | This file is part of GLD, the Gnu Linker. | |
6 | ||
7 | GLD is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GLD is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
8bc8f4bc TT |
18 | along with GLD; see the file COPYING. If not, write to the Free |
19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
d4e5e3c3 DM |
21 | |
22 | #include "bfd.h" | |
23 | #include "sysdep.h" | |
9cfdc91a | 24 | #include "libiberty.h" |
d4e5e3c3 DM |
25 | #include <stdio.h> |
26 | #include <string.h> | |
22d3533c | 27 | #include <ctype.h> |
d4e5e3c3 DM |
28 | #include "getopt.h" |
29 | #include "bfdlink.h" | |
d4e5e3c3 DM |
30 | #include "ld.h" |
31 | #include "ldmain.h" | |
32 | #include "ldmisc.h" | |
33 | #include "ldexp.h" | |
34 | #include "ldlang.h" | |
35 | #include "ldgram.h" | |
36 | #include "ldlex.h" | |
37 | #include "ldfile.h" | |
4725fb48 | 38 | #include "ldver.h" |
5753006b | 39 | #include "ldemul.h" |
d4e5e3c3 | 40 | |
8bc8f4bc TT |
41 | #ifndef PATH_SEPARATOR |
42 | #if defined (__MSDOS__) || (defined (_WIN32) && ! defined (__CYGWIN32__)) | |
43 | #define PATH_SEPARATOR ';' | |
44 | #else | |
45 | #define PATH_SEPARATOR ':' | |
46 | #endif | |
47 | #endif | |
48 | ||
809ee7e0 ILT |
49 | /* Somewhere above, sys/stat.h got included . . . . */ |
50 | #if !defined(S_ISDIR) && defined(S_IFDIR) | |
51 | #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) | |
52 | #endif | |
53 | ||
d4e5e3c3 DM |
54 | /* Omit args to avoid the possibility of clashing with a system header |
55 | that might disagree about consts. */ | |
56 | unsigned long strtoul (); | |
57 | ||
58 | static void set_default_dirlist PARAMS ((char *dirlist_ptr)); | |
59 | static void set_section_start PARAMS ((char *sect, char *valstr)); | |
1ffec9e6 | 60 | static void help PARAMS ((void)); |
d4e5e3c3 | 61 | |
630f4ac9 ILT |
62 | /* Non-zero if we are processing a --defsym from the command line. */ |
63 | int parsing_defsym = 0; | |
de71eb77 | 64 | |
1ffec9e6 ILT |
65 | /* Codes used for the long options with no short synonyms. 150 isn't |
66 | special; it's just an arbitrary non-ASCII char value. */ | |
d5b79a89 | 67 | |
5753006b ILT |
68 | #define OPTION_ASSERT 150 |
69 | #define OPTION_CALL_SHARED (OPTION_ASSERT + 1) | |
9cfdc91a ILT |
70 | #define OPTION_CREF (OPTION_CALL_SHARED + 1) |
71 | #define OPTION_DEFSYM (OPTION_CREF + 1) | |
7fb9ca5f ILT |
72 | #define OPTION_DYNAMIC_LINKER (OPTION_DEFSYM + 1) |
73 | #define OPTION_EB (OPTION_DYNAMIC_LINKER + 1) | |
bec7a138 | 74 | #define OPTION_EL (OPTION_EB + 1) |
5753006b | 75 | #define OPTION_EMBEDDED_RELOCS (OPTION_EL + 1) |
de71eb77 SC |
76 | #define OPTION_EXPORT_DYNAMIC (OPTION_EMBEDDED_RELOCS + 1) |
77 | #define OPTION_HELP (OPTION_EXPORT_DYNAMIC + 1) | |
bec7a138 ILT |
78 | #define OPTION_IGNORE (OPTION_HELP + 1) |
79 | #define OPTION_MAP (OPTION_IGNORE + 1) | |
80 | #define OPTION_NO_KEEP_MEMORY (OPTION_MAP + 1) | |
8bc8f4bc TT |
81 | #define OPTION_NO_WARN_MISMATCH (OPTION_NO_KEEP_MEMORY + 1) |
82 | #define OPTION_NOINHIBIT_EXEC (OPTION_NO_WARN_MISMATCH + 1) | |
bec7a138 | 83 | #define OPTION_NON_SHARED (OPTION_NOINHIBIT_EXEC + 1) |
3c8deccc ILT |
84 | #define OPTION_NO_WHOLE_ARCHIVE (OPTION_NON_SHARED + 1) |
85 | #define OPTION_OFORMAT (OPTION_NO_WHOLE_ARCHIVE + 1) | |
bec7a138 ILT |
86 | #define OPTION_RELAX (OPTION_OFORMAT + 1) |
87 | #define OPTION_RETAIN_SYMBOLS_FILE (OPTION_RELAX + 1) | |
809ee7e0 | 88 | #define OPTION_RPATH (OPTION_RETAIN_SYMBOLS_FILE + 1) |
3c8deccc ILT |
89 | #define OPTION_RPATH_LINK (OPTION_RPATH + 1) |
90 | #define OPTION_SHARED (OPTION_RPATH_LINK + 1) | |
809ee7e0 ILT |
91 | #define OPTION_SONAME (OPTION_SHARED + 1) |
92 | #define OPTION_SORT_COMMON (OPTION_SONAME + 1) | |
229ba4b3 SC |
93 | #define OPTION_STATS (OPTION_SORT_COMMON + 1) |
94 | #define OPTION_SYMBOLIC (OPTION_STATS + 1) | |
8bc8f4bc TT |
95 | #define OPTION_TASK_LINK (OPTION_SYMBOLIC + 1) |
96 | #define OPTION_TBSS (OPTION_TASK_LINK + 1) | |
bec7a138 ILT |
97 | #define OPTION_TDATA (OPTION_TBSS + 1) |
98 | #define OPTION_TTEXT (OPTION_TDATA + 1) | |
99 | #define OPTION_TRADITIONAL_FORMAT (OPTION_TTEXT + 1) | |
100 | #define OPTION_UR (OPTION_TRADITIONAL_FORMAT + 1) | |
de71eb77 SC |
101 | #define OPTION_VERBOSE (OPTION_UR + 1) |
102 | #define OPTION_VERSION (OPTION_VERBOSE + 1) | |
8bc8f4bc TT |
103 | #define OPTION_VERSION_SCRIPT (OPTION_VERSION + 1) |
104 | #define OPTION_WARN_COMMON (OPTION_VERSION_SCRIPT + 1) | |
80fd1f45 | 105 | #define OPTION_WARN_CONSTRUCTORS (OPTION_WARN_COMMON + 1) |
4b7d2399 ILT |
106 | #define OPTION_WARN_MULTIPLE_GP (OPTION_WARN_CONSTRUCTORS + 1) |
107 | #define OPTION_WARN_ONCE (OPTION_WARN_MULTIPLE_GP + 1) | |
8bc8f4bc TT |
108 | #define OPTION_WARN_SECTION_ALIGN (OPTION_WARN_ONCE + 1) |
109 | #define OPTION_SPLIT_BY_RELOC (OPTION_WARN_SECTION_ALIGN + 1) | |
de71eb77 SC |
110 | #define OPTION_SPLIT_BY_FILE (OPTION_SPLIT_BY_RELOC + 1) |
111 | #define OPTION_WHOLE_ARCHIVE (OPTION_SPLIT_BY_FILE + 1) | |
e3d73386 | 112 | #define OPTION_WRAP (OPTION_WHOLE_ARCHIVE + 1) |
9cfdc91a | 113 | #define OPTION_FORCE_EXE_SUFFIX (OPTION_WRAP + 1) |
229ba4b3 | 114 | |
1ffec9e6 ILT |
115 | /* The long options. This structure is used for both the option |
116 | parsing and the help text. */ | |
117 | ||
118 | struct ld_option | |
119 | { | |
120 | /* The long option information. */ | |
121 | struct option opt; | |
122 | /* The short option with the same meaning ('\0' if none). */ | |
123 | char shortopt; | |
124 | /* The name of the argument (NULL if none). */ | |
125 | const char *arg; | |
126 | /* The documentation string. If this is NULL, this is a synonym for | |
127 | the previous option. */ | |
128 | const char *doc; | |
129 | enum | |
130 | { | |
131 | /* Use one dash before long option name. */ | |
132 | ONE_DASH, | |
133 | /* Use two dashes before long option name. */ | |
134 | TWO_DASHES, | |
135 | /* Don't mention this option in --help output. */ | |
136 | NO_HELP | |
137 | } control; | |
138 | }; | |
139 | ||
140 | static const struct ld_option ld_options[] = | |
141 | { | |
142 | { {NULL, required_argument, NULL, '\0'}, | |
8bc8f4bc | 143 | 'a', N_("KEYWORD"), N_("Shared library control for HP/UX compatibility"), |
1ffec9e6 ILT |
144 | ONE_DASH }, |
145 | { {"architecture", required_argument, NULL, 'A'}, | |
8bc8f4bc | 146 | 'A', N_("ARCH"), N_("Set architecture") , TWO_DASHES }, |
1ffec9e6 | 147 | { {"format", required_argument, NULL, 'b'}, |
8bc8f4bc | 148 | 'b', N_("TARGET"), N_("Specify target for following input files"), TWO_DASHES }, |
1ffec9e6 | 149 | { {"mri-script", required_argument, NULL, 'c'}, |
8bc8f4bc | 150 | 'c', N_("FILE"), N_("Read MRI format linker script"), TWO_DASHES }, |
1ffec9e6 | 151 | { {"dc", no_argument, NULL, 'd'}, |
8bc8f4bc | 152 | 'd', NULL, N_("Force common symbols to be defined"), ONE_DASH }, |
1ffec9e6 ILT |
153 | { {"dp", no_argument, NULL, 'd'}, |
154 | '\0', NULL, NULL, ONE_DASH }, | |
155 | { {"entry", required_argument, NULL, 'e'}, | |
8bc8f4bc | 156 | 'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES }, |
1ffec9e6 | 157 | { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC}, |
8bc8f4bc TT |
158 | 'E', NULL, N_("Export all dynamic symbols"), TWO_DASHES }, |
159 | { {"auxiliary", required_argument, NULL, 'f'}, | |
160 | 'f', N_("SHLIB"), N_("Auxiliary filter for shared object symbol table"), | |
161 | TWO_DASHES }, | |
162 | { {"filter", required_argument, NULL, 'F'}, | |
163 | 'F', N_("SHLIB"), N_("Filter for shared object symbol table"), TWO_DASHES }, | |
6799c638 | 164 | { {NULL, no_argument, NULL, '\0'}, |
8bc8f4bc | 165 | 'g', NULL, N_("Ignored"), ONE_DASH }, |
1ffec9e6 | 166 | { {"gpsize", required_argument, NULL, 'G'}, |
8bc8f4bc | 167 | 'G', N_("SIZE"), N_("Small data size (if no size, same as --shared)"), |
1ffec9e6 | 168 | TWO_DASHES }, |
1ffec9e6 | 169 | { {"soname", required_argument, NULL, OPTION_SONAME}, |
8bc8f4bc | 170 | 'h', N_("FILENAME"), N_("Set internal name of shared library"), ONE_DASH }, |
1ffec9e6 | 171 | { {"library", required_argument, NULL, 'l'}, |
8bc8f4bc | 172 | 'l', N_("LIBNAME"), N_("Search for library LIBNAME"), TWO_DASHES }, |
1ffec9e6 | 173 | { {"library-path", required_argument, NULL, 'L'}, |
8bc8f4bc | 174 | 'L', N_("DIRECTORY"), N_("Add DIRECTORY to library search path"), TWO_DASHES }, |
1ffec9e6 | 175 | { {NULL, required_argument, NULL, '\0'}, |
8bc8f4bc | 176 | 'm', N_("EMULATION"), N_("Set emulation"), ONE_DASH }, |
1ffec9e6 | 177 | { {"print-map", no_argument, NULL, 'M'}, |
8bc8f4bc | 178 | 'M', NULL, N_("Print map file on standard output"), TWO_DASHES }, |
1ffec9e6 | 179 | { {"nmagic", no_argument, NULL, 'n'}, |
8bc8f4bc | 180 | 'n', NULL, N_("Do not page align data"), TWO_DASHES }, |
1ffec9e6 | 181 | { {"omagic", no_argument, NULL, 'N'}, |
8bc8f4bc | 182 | 'N', NULL, N_("Do not page align data, do not make text readonly"), |
1ffec9e6 ILT |
183 | TWO_DASHES }, |
184 | { {"output", required_argument, NULL, 'o'}, | |
8bc8f4bc | 185 | 'o', N_("FILE"), N_("Set output file name"), TWO_DASHES }, |
1ffec9e6 | 186 | { {NULL, required_argument, NULL, '\0'}, |
8bc8f4bc | 187 | 'O', NULL, N_("Ignored"), ONE_DASH }, |
1ffec9e6 | 188 | { {"relocateable", no_argument, NULL, 'r'}, |
8bc8f4bc | 189 | 'r', NULL, N_("Generate relocateable output"), TWO_DASHES }, |
1ffec9e6 ILT |
190 | { {NULL, no_argument, NULL, '\0'}, |
191 | 'i', NULL, NULL, ONE_DASH }, | |
192 | { {"just-symbols", required_argument, NULL, 'R'}, | |
8bc8f4bc | 193 | 'R', N_("FILE"), N_("Just link symbols (if directory, same as --rpath)"), |
1ffec9e6 ILT |
194 | TWO_DASHES }, |
195 | { {"strip-all", no_argument, NULL, 's'}, | |
8bc8f4bc | 196 | 's', NULL, N_("Strip all symbols"), TWO_DASHES }, |
1ffec9e6 | 197 | { {"strip-debug", no_argument, NULL, 'S'}, |
8bc8f4bc | 198 | 'S', NULL, N_("Strip debugging symbols"), TWO_DASHES }, |
1ffec9e6 | 199 | { {"trace", no_argument, NULL, 't'}, |
8bc8f4bc | 200 | 't', NULL, N_("Trace file opens"), TWO_DASHES }, |
1ffec9e6 | 201 | { {"script", required_argument, NULL, 'T'}, |
8bc8f4bc | 202 | 'T', N_("FILE"), N_("Read linker script"), TWO_DASHES }, |
1ffec9e6 | 203 | { {"undefined", required_argument, NULL, 'u'}, |
8bc8f4bc | 204 | 'u', N_("SYMBOL"), N_("Start with undefined reference to SYMBOL"), TWO_DASHES }, |
1ffec9e6 | 205 | { {"version", no_argument, NULL, OPTION_VERSION}, |
8bc8f4bc | 206 | 'v', NULL, N_("Print version information"), TWO_DASHES }, |
1ffec9e6 | 207 | { {NULL, no_argument, NULL, '\0'}, |
8bc8f4bc | 208 | 'V', NULL, N_("Print version and emulation information"), ONE_DASH }, |
1ffec9e6 | 209 | { {"discard-all", no_argument, NULL, 'x'}, |
8bc8f4bc | 210 | 'x', NULL, N_("Discard all local symbols"), TWO_DASHES }, |
1ffec9e6 | 211 | { {"discard-locals", no_argument, NULL, 'X'}, |
8bc8f4bc | 212 | 'X', NULL, N_("Discard temporary local symbols"), TWO_DASHES }, |
1ffec9e6 | 213 | { {"trace-symbol", required_argument, NULL, 'y'}, |
8bc8f4bc | 214 | 'y', N_("SYMBOL"), N_("Trace mentions of SYMBOL"), TWO_DASHES }, |
1ffec9e6 | 215 | { {NULL, required_argument, NULL, '\0'}, |
8bc8f4bc | 216 | 'Y', N_("PATH"), N_("Default search path for Solaris compatibility"), ONE_DASH }, |
1ffec9e6 | 217 | { {NULL, required_argument, NULL, '\0'}, |
8bc8f4bc | 218 | 'z', N_("KEYWORD"), N_("Ignored for Solaris compatibility"), ONE_DASH }, |
1ffec9e6 | 219 | { {"start-group", no_argument, NULL, '('}, |
8bc8f4bc | 220 | '(', NULL, N_("Start a group"), TWO_DASHES }, |
1ffec9e6 | 221 | { {"end-group", no_argument, NULL, ')'}, |
8bc8f4bc | 222 | ')', NULL, N_("End a group"), TWO_DASHES }, |
1ffec9e6 | 223 | { {"assert", required_argument, NULL, OPTION_ASSERT}, |
8bc8f4bc | 224 | '\0', N_("KEYWORD"), N_("Ignored for SunOS compatibility"), ONE_DASH }, |
1ffec9e6 | 225 | { {"Bdynamic", no_argument, NULL, OPTION_CALL_SHARED}, |
8bc8f4bc | 226 | '\0', NULL, N_("Link against shared libraries"), ONE_DASH }, |
1ffec9e6 ILT |
227 | { {"dy", no_argument, NULL, OPTION_CALL_SHARED}, |
228 | '\0', NULL, NULL, ONE_DASH }, | |
6799c638 ILT |
229 | { {"call_shared", no_argument, NULL, OPTION_CALL_SHARED}, |
230 | '\0', NULL, NULL, ONE_DASH }, | |
1ffec9e6 | 231 | { {"Bstatic", no_argument, NULL, OPTION_NON_SHARED}, |
8bc8f4bc | 232 | '\0', NULL, N_("Do not link against shared libraries"), ONE_DASH }, |
1ffec9e6 ILT |
233 | { {"dn", no_argument, NULL, OPTION_NON_SHARED}, |
234 | '\0', NULL, NULL, ONE_DASH }, | |
235 | { {"non_shared", no_argument, NULL, OPTION_NON_SHARED}, | |
236 | '\0', NULL, NULL, ONE_DASH }, | |
237 | { {"static", no_argument, NULL, OPTION_NON_SHARED}, | |
238 | '\0', NULL, NULL, ONE_DASH }, | |
239 | { {"Bsymbolic", no_argument, NULL, OPTION_SYMBOLIC}, | |
8bc8f4bc | 240 | '\0', NULL, N_("Bind global references locally"), ONE_DASH }, |
9cfdc91a | 241 | { {"cref", no_argument, NULL, OPTION_CREF}, |
8bc8f4bc | 242 | '\0', NULL, N_("Output cross reference table"), TWO_DASHES }, |
1ffec9e6 | 243 | { {"defsym", required_argument, NULL, OPTION_DEFSYM}, |
8bc8f4bc | 244 | '\0', N_("SYMBOL=EXPRESSION"), N_("Define a symbol"), TWO_DASHES }, |
1ffec9e6 | 245 | { {"dynamic-linker", required_argument, NULL, OPTION_DYNAMIC_LINKER}, |
8bc8f4bc | 246 | '\0', N_("PROGRAM"), N_("Set the dynamic linker to use"), TWO_DASHES }, |
1ffec9e6 | 247 | { {"EB", no_argument, NULL, OPTION_EB}, |
8bc8f4bc | 248 | '\0', NULL, N_("Link big-endian objects"), ONE_DASH }, |
1ffec9e6 | 249 | { {"EL", no_argument, NULL, OPTION_EL}, |
8bc8f4bc | 250 | '\0', NULL, N_("Link little-endian objects"), ONE_DASH }, |
1ffec9e6 | 251 | { {"embedded-relocs", no_argument, NULL, OPTION_EMBEDDED_RELOCS}, |
8bc8f4bc | 252 | '\0', NULL, N_("Generate embedded relocs"), TWO_DASHES}, |
9cfdc91a | 253 | { {"force-exe-suffix", no_argument, NULL, OPTION_FORCE_EXE_SUFFIX}, |
8bc8f4bc | 254 | '\0', NULL, N_("Force generation of file with .exe suffix"), TWO_DASHES}, |
1ffec9e6 | 255 | { {"help", no_argument, NULL, OPTION_HELP}, |
8bc8f4bc | 256 | '\0', NULL, N_("Print option help"), TWO_DASHES }, |
1ffec9e6 | 257 | { {"Map", required_argument, NULL, OPTION_MAP}, |
8bc8f4bc | 258 | '\0', N_("FILE"), N_("Write a map file"), ONE_DASH }, |
1ffec9e6 | 259 | { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY}, |
8bc8f4bc TT |
260 | '\0', NULL, N_("Use less memory and more disk I/O"), TWO_DASHES }, |
261 | { {"no-warn-mismatch", no_argument, NULL, OPTION_NO_WARN_MISMATCH}, | |
262 | '\0', NULL, N_("Don't warn about mismatched input files"), TWO_DASHES}, | |
1ffec9e6 | 263 | { {"no-whole-archive", no_argument, NULL, OPTION_NO_WHOLE_ARCHIVE}, |
8bc8f4bc | 264 | '\0', NULL, N_("Turn off --whole-archive"), TWO_DASHES }, |
1ffec9e6 | 265 | { {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC}, |
8bc8f4bc | 266 | '\0', NULL, N_("Create an output file even if errors occur"), TWO_DASHES }, |
1ffec9e6 ILT |
267 | { {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC}, |
268 | '\0', NULL, NULL, NO_HELP }, | |
269 | { {"oformat", required_argument, NULL, OPTION_OFORMAT}, | |
8bc8f4bc | 270 | '\0', N_("TARGET"), N_("Specify target of output file"), TWO_DASHES }, |
1ffec9e6 | 271 | { {"qmagic", no_argument, NULL, OPTION_IGNORE}, |
8bc8f4bc | 272 | '\0', NULL, N_("Ignored for Linux compatibility"), ONE_DASH }, |
1ffec9e6 | 273 | { {"Qy", no_argument, NULL, OPTION_IGNORE}, |
8bc8f4bc | 274 | '\0', NULL, N_("Ignored for SVR4 compatibility"), ONE_DASH }, |
1ffec9e6 | 275 | { {"relax", no_argument, NULL, OPTION_RELAX}, |
8bc8f4bc | 276 | '\0', NULL, N_("Relax branches on certain targets"), TWO_DASHES }, |
1ffec9e6 ILT |
277 | { {"retain-symbols-file", required_argument, NULL, |
278 | OPTION_RETAIN_SYMBOLS_FILE}, | |
8bc8f4bc | 279 | '\0', N_("FILE"), N_("Keep only symbols listed in FILE"), TWO_DASHES }, |
1ffec9e6 | 280 | { {"rpath", required_argument, NULL, OPTION_RPATH}, |
8bc8f4bc | 281 | '\0', N_("PATH"), N_("Set runtime shared library search path"), ONE_DASH }, |
1ffec9e6 | 282 | { {"rpath-link", required_argument, NULL, OPTION_RPATH_LINK}, |
8bc8f4bc | 283 | '\0', N_("PATH"), N_("Set link time shared library search path"), ONE_DASH }, |
1ffec9e6 | 284 | { {"shared", no_argument, NULL, OPTION_SHARED}, |
8bc8f4bc | 285 | '\0', NULL, N_("Create a shared library"), ONE_DASH }, |
1ffec9e6 ILT |
286 | { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD. */ |
287 | '\0', NULL, NULL, ONE_DASH }, | |
288 | { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON}, | |
8bc8f4bc | 289 | '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES }, |
1ffec9e6 ILT |
290 | { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON}, |
291 | '\0', NULL, NULL, NO_HELP }, | |
292 | { {"split-by-file", no_argument, NULL, OPTION_SPLIT_BY_FILE}, | |
8bc8f4bc | 293 | '\0', NULL, N_("Split output sections for each file"), TWO_DASHES }, |
1ffec9e6 | 294 | { {"split-by-reloc", required_argument, NULL, OPTION_SPLIT_BY_RELOC}, |
8bc8f4bc | 295 | '\0', N_("COUNT"), N_("Split output sections every COUNT relocs"), TWO_DASHES }, |
1ffec9e6 | 296 | { {"stats", no_argument, NULL, OPTION_STATS}, |
8bc8f4bc TT |
297 | '\0', NULL, N_("Print memory usage statistics"), TWO_DASHES }, |
298 | { {"task-link", required_argument, NULL, OPTION_TASK_LINK}, | |
299 | '\0', N_("SYMBOL"), N_("Do task level linking"), TWO_DASHES }, | |
1ffec9e6 | 300 | { {"traditional-format", no_argument, NULL, OPTION_TRADITIONAL_FORMAT}, |
8bc8f4bc | 301 | '\0', NULL, N_("Use same format as native linker"), TWO_DASHES }, |
1ffec9e6 | 302 | { {"Tbss", required_argument, NULL, OPTION_TBSS}, |
8bc8f4bc | 303 | '\0', N_("ADDRESS"), N_("Set address of .bss section"), ONE_DASH }, |
1ffec9e6 | 304 | { {"Tdata", required_argument, NULL, OPTION_TDATA}, |
8bc8f4bc | 305 | '\0', N_("ADDRESS"), N_("Set address of .data section"), ONE_DASH }, |
1ffec9e6 | 306 | { {"Ttext", required_argument, NULL, OPTION_TTEXT}, |
8bc8f4bc | 307 | '\0', N_("ADDRESS"), N_("Set address of .text section"), ONE_DASH }, |
1ffec9e6 | 308 | { {"Ur", no_argument, NULL, OPTION_UR}, |
8bc8f4bc | 309 | '\0', NULL, N_("Build global constructor/destructor tables"), ONE_DASH }, |
1ffec9e6 | 310 | { {"verbose", no_argument, NULL, OPTION_VERBOSE}, |
8bc8f4bc | 311 | '\0', NULL, N_("Output lots of information during link"), TWO_DASHES }, |
9cfdc91a | 312 | { {"dll-verbose", no_argument, NULL, OPTION_VERBOSE}, /* Linux. */ |
1ffec9e6 | 313 | '\0', NULL, NULL, NO_HELP }, |
8bc8f4bc TT |
314 | { {"version-script", required_argument, NULL, OPTION_VERSION_SCRIPT }, |
315 | '\0', N_("FILE"), N_("Read version information script"), TWO_DASHES }, | |
1ffec9e6 | 316 | { {"warn-common", no_argument, NULL, OPTION_WARN_COMMON}, |
8bc8f4bc | 317 | '\0', NULL, N_("Warn about duplicate common symbols"), TWO_DASHES }, |
1ffec9e6 | 318 | { {"warn-constructors", no_argument, NULL, OPTION_WARN_CONSTRUCTORS}, |
8bc8f4bc | 319 | '\0', NULL, N_("Warn if global constructors/destructors are seen"), |
1ffec9e6 ILT |
320 | TWO_DASHES }, |
321 | { {"warn-multiple-gp", no_argument, NULL, OPTION_WARN_MULTIPLE_GP}, | |
8bc8f4bc | 322 | '\0', NULL, N_("Warn if the multiple GP values are used"), TWO_DASHES }, |
1ffec9e6 | 323 | { {"warn-once", no_argument, NULL, OPTION_WARN_ONCE}, |
8bc8f4bc TT |
324 | '\0', NULL, N_("Warn only once per undefined symbol"), TWO_DASHES }, |
325 | { {"warn-section-align", no_argument, NULL, OPTION_WARN_SECTION_ALIGN}, | |
326 | '\0', NULL, N_("Warn if start of section changes due to alignment"), | |
327 | TWO_DASHES }, | |
1ffec9e6 | 328 | { {"whole-archive", no_argument, NULL, OPTION_WHOLE_ARCHIVE}, |
8bc8f4bc | 329 | '\0', NULL, N_("Include all objects from following archives"), TWO_DASHES }, |
1ffec9e6 | 330 | { {"wrap", required_argument, NULL, OPTION_WRAP}, |
8bc8f4bc | 331 | '\0', N_("SYMBOL"), N_("Use wrapper functions for SYMBOL"), TWO_DASHES } |
1ffec9e6 ILT |
332 | }; |
333 | ||
8bc8f4bc | 334 | #define OPTION_COUNT ((int) (sizeof ld_options / sizeof ld_options[0])) |
1ffec9e6 ILT |
335 | |
336 | void | |
337 | parse_args (argc, argv) | |
338 | int argc; | |
339 | char **argv; | |
340 | { | |
341 | int i, is, il; | |
342 | int ingroup = 0; | |
343 | char *default_dirlist = NULL; | |
bf7198b3 | 344 | char shortopts[OPTION_COUNT * 3 + 2]; |
1ffec9e6 | 345 | struct option longopts[OPTION_COUNT + 1]; |
8bc8f4bc | 346 | int last_optind; |
1ffec9e6 ILT |
347 | |
348 | /* Starting the short option string with '-' is for programs that | |
349 | expect options and other ARGV-elements in any order and that care about | |
350 | the ordering of the two. We describe each non-option ARGV-element | |
351 | as if it were the argument of an option with character code 1. */ | |
352 | shortopts[0] = '-'; | |
353 | is = 1; | |
354 | il = 0; | |
355 | for (i = 0; i < OPTION_COUNT; i++) | |
356 | { | |
357 | if (ld_options[i].shortopt != '\0') | |
358 | { | |
359 | shortopts[is] = ld_options[i].shortopt; | |
360 | ++is; | |
bf7198b3 ILT |
361 | if (ld_options[i].opt.has_arg == required_argument |
362 | || ld_options[i].opt.has_arg == optional_argument) | |
1ffec9e6 ILT |
363 | { |
364 | shortopts[is] = ':'; | |
365 | ++is; | |
bf7198b3 ILT |
366 | if (ld_options[i].opt.has_arg == optional_argument) |
367 | { | |
368 | shortopts[is] = ':'; | |
369 | ++is; | |
370 | } | |
1ffec9e6 ILT |
371 | } |
372 | } | |
373 | if (ld_options[i].opt.name != NULL) | |
374 | { | |
375 | longopts[il] = ld_options[i].opt; | |
376 | ++il; | |
377 | } | |
378 | } | |
379 | shortopts[is] = '\0'; | |
380 | longopts[il].name = NULL; | |
d4e5e3c3 | 381 | |
22d3533c ILT |
382 | /* The -G option is ambiguous on different platforms. Sometimes it |
383 | specifies the largest data size to put into the small data | |
384 | section. Sometimes it is equivalent to --shared. Unfortunately, | |
385 | the first form takes an argument, while the second does not. | |
386 | ||
387 | We need to permit the --shared form because on some platforms, | |
388 | such as Solaris, gcc -shared will pass -G to the linker. | |
389 | ||
390 | To permit either usage, we look through the argument list. If we | |
391 | find -G not followed by a number, we change it into --shared. | |
392 | This will work for most normal cases. */ | |
393 | for (i = 1; i < argc; i++) | |
394 | if (strcmp (argv[i], "-G") == 0 | |
395 | && (i + 1 >= argc | |
8bc8f4bc | 396 | || ! isdigit ((unsigned char) argv[i + 1][0]))) |
22d3533c ILT |
397 | argv[i] = (char *) "--shared"; |
398 | ||
8bc8f4bc | 399 | last_optind = -1; |
d4e5e3c3 DM |
400 | while (1) |
401 | { | |
402 | /* getopt_long_only is like getopt_long, but '-' as well as '--' can | |
403 | indicate a long option. */ | |
d5b79a89 | 404 | int longind; |
5753006b ILT |
405 | int optc; |
406 | ||
8bc8f4bc TT |
407 | /* Using last_optind lets us avoid calling ldemul_parse_args |
408 | multiple times on a single option, which would lead to | |
409 | confusion in the internal static variables maintained by | |
410 | getopt. This could otherwise happen for an argument like | |
411 | -nx, in which the -n is parsed as a single option, and we | |
412 | loop around to pick up the -x. */ | |
413 | if (optind != last_optind) | |
414 | { | |
415 | if (ldemul_parse_args (argc, argv)) | |
416 | continue; | |
417 | last_optind = optind; | |
418 | } | |
5753006b ILT |
419 | |
420 | optc = getopt_long_only (argc, argv, shortopts, longopts, &longind); | |
d5b79a89 | 421 | |
d4e5e3c3 DM |
422 | if (optc == -1) |
423 | break; | |
d4e5e3c3 DM |
424 | switch (optc) |
425 | { | |
426 | default: | |
427 | xexit (1); | |
428 | case 1: /* File name. */ | |
429 | lang_add_input_file (optarg, lang_input_file_is_file_enum, | |
430 | (char *) NULL); | |
431 | break; | |
432 | ||
2a9fa50c ILT |
433 | case OPTION_IGNORE: |
434 | break; | |
de71eb77 SC |
435 | case 'a': |
436 | /* For HP/UX compatibility. Actually -a shared should mean | |
437 | ``use only shared libraries'' but, then, we don't | |
438 | currently support shared libraries on HP/UX anyhow. */ | |
439 | if (strcmp (optarg, "archive") == 0) | |
440 | config.dynamic_link = false; | |
441 | else if (strcmp (optarg, "shared") == 0 | |
442 | || strcmp (optarg, "default") == 0) | |
443 | config.dynamic_link = true; | |
444 | else | |
8bc8f4bc | 445 | einfo (_("%P%F: unrecognized -a option `%s'\n"), optarg); |
de71eb77 | 446 | break; |
5753006b | 447 | case OPTION_ASSERT: |
3c8deccc | 448 | /* FIXME: We just ignore these, but we should handle them. */ |
5753006b ILT |
449 | if (strcmp (optarg, "definitions") == 0) |
450 | ; | |
451 | else if (strcmp (optarg, "nodefinitions") == 0) | |
452 | ; | |
453 | else if (strcmp (optarg, "nosymbolic") == 0) | |
454 | ; | |
455 | else if (strcmp (optarg, "pure-text") == 0) | |
3c8deccc | 456 | ; |
5753006b | 457 | else |
8bc8f4bc | 458 | einfo (_("%P%F: unrecognized -assert option `%s'\n"), optarg); |
5753006b | 459 | break; |
d4e5e3c3 DM |
460 | case 'A': |
461 | ldfile_add_arch (optarg); | |
462 | break; | |
d4e5e3c3 DM |
463 | case 'b': |
464 | lang_add_target (optarg); | |
465 | break; | |
466 | case 'c': | |
467 | ldfile_open_command_file (optarg); | |
468 | parser_input = input_mri_script; | |
469 | yyparse (); | |
470 | break; | |
d5b79a89 | 471 | case OPTION_CALL_SHARED: |
2a9fa50c ILT |
472 | config.dynamic_link = true; |
473 | break; | |
474 | case OPTION_NON_SHARED: | |
475 | config.dynamic_link = false; | |
d4e5e3c3 | 476 | break; |
9cfdc91a ILT |
477 | case OPTION_CREF: |
478 | command_line.cref = true; | |
479 | link_info.notice_all = true; | |
480 | break; | |
d4e5e3c3 DM |
481 | case 'd': |
482 | command_line.force_common_definition = true; | |
483 | break; | |
d5b79a89 | 484 | case OPTION_DEFSYM: |
630f4ac9 | 485 | lex_string = optarg; |
d4e5e3c3 DM |
486 | lex_redirect (optarg); |
487 | parser_input = input_defsym; | |
630f4ac9 | 488 | parsing_defsym = 1; |
d4e5e3c3 | 489 | yyparse (); |
630f4ac9 ILT |
490 | parsing_defsym = 0; |
491 | lex_string = NULL; | |
d4e5e3c3 | 492 | break; |
7fb9ca5f ILT |
493 | case OPTION_DYNAMIC_LINKER: |
494 | command_line.interpreter = optarg; | |
495 | break; | |
d5b79a89 | 496 | case OPTION_EB: |
86037281 | 497 | command_line.endian = ENDIAN_BIG; |
d4e5e3c3 | 498 | break; |
d5b79a89 | 499 | case OPTION_EL: |
86037281 | 500 | command_line.endian = ENDIAN_LITTLE; |
d4e5e3c3 | 501 | break; |
de71eb77 SC |
502 | case OPTION_EMBEDDED_RELOCS: |
503 | command_line.embedded_relocs = true; | |
504 | break; | |
505 | case OPTION_EXPORT_DYNAMIC: | |
90ba7e65 | 506 | case 'E': /* HP/UX compatibility. */ |
de71eb77 SC |
507 | command_line.export_dynamic = true; |
508 | break; | |
d4e5e3c3 | 509 | case 'e': |
3c8deccc | 510 | lang_add_entry (optarg, true); |
d4e5e3c3 | 511 | break; |
8bc8f4bc TT |
512 | case 'f': |
513 | if (command_line.auxiliary_filters == NULL) | |
514 | { | |
515 | command_line.auxiliary_filters = | |
516 | (char **) xmalloc (2 * sizeof (char *)); | |
517 | command_line.auxiliary_filters[0] = optarg; | |
518 | command_line.auxiliary_filters[1] = NULL; | |
519 | } | |
520 | else | |
521 | { | |
522 | int c; | |
523 | char **p; | |
524 | ||
525 | c = 0; | |
526 | for (p = command_line.auxiliary_filters; *p != NULL; p++) | |
527 | ++c; | |
528 | command_line.auxiliary_filters = | |
529 | (char **) xrealloc (command_line.auxiliary_filters, | |
530 | (c + 2) * sizeof (char *)); | |
531 | command_line.auxiliary_filters[c] = optarg; | |
532 | command_line.auxiliary_filters[c + 1] = NULL; | |
533 | } | |
534 | break; | |
d4e5e3c3 | 535 | case 'F': |
8bc8f4bc | 536 | command_line.filter_shlib = optarg; |
d4e5e3c3 | 537 | break; |
9cfdc91a ILT |
538 | case OPTION_FORCE_EXE_SUFFIX: |
539 | command_line.force_exe_suffix = true; | |
540 | break; | |
d4e5e3c3 DM |
541 | case 'G': |
542 | { | |
543 | char *end; | |
544 | g_switch_value = strtoul (optarg, &end, 0); | |
545 | if (*end) | |
8bc8f4bc | 546 | einfo (_("%P%F: invalid number `%s'\n"), optarg); |
d4e5e3c3 DM |
547 | } |
548 | break; | |
549 | case 'g': | |
550 | /* Ignore. */ | |
551 | break; | |
d5b79a89 | 552 | case OPTION_HELP: |
d4e5e3c3 DM |
553 | help (); |
554 | xexit (0); | |
555 | break; | |
556 | case 'L': | |
0cd82d00 | 557 | ldfile_add_library_path (optarg, true); |
d4e5e3c3 DM |
558 | break; |
559 | case 'l': | |
560 | lang_add_input_file (optarg, lang_input_file_is_l_enum, | |
561 | (char *) NULL); | |
562 | break; | |
563 | case 'M': | |
564 | config.map_filename = "-"; | |
565 | break; | |
566 | case 'm': | |
567 | /* Ignore. Was handled in a pre-parse. */ | |
568 | break; | |
d5b79a89 | 569 | case OPTION_MAP: |
d4e5e3c3 DM |
570 | config.map_filename = optarg; |
571 | break; | |
572 | case 'N': | |
573 | config.text_read_only = false; | |
574 | config.magic_demand_paged = false; | |
3c8deccc | 575 | config.dynamic_link = false; |
d4e5e3c3 DM |
576 | break; |
577 | case 'n': | |
578 | config.magic_demand_paged = false; | |
3c8deccc | 579 | config.dynamic_link = false; |
d4e5e3c3 | 580 | break; |
d5b79a89 | 581 | case OPTION_NO_KEEP_MEMORY: |
d4e5e3c3 DM |
582 | link_info.keep_memory = false; |
583 | break; | |
8bc8f4bc TT |
584 | case OPTION_NO_WARN_MISMATCH: |
585 | command_line.warn_mismatch = false; | |
586 | break; | |
d5b79a89 | 587 | case OPTION_NOINHIBIT_EXEC: |
d4e5e3c3 DM |
588 | force_make_executable = true; |
589 | break; | |
3c8deccc ILT |
590 | case OPTION_NO_WHOLE_ARCHIVE: |
591 | whole_archive = false; | |
592 | break; | |
d4e5e3c3 DM |
593 | case 'O': |
594 | /* FIXME "-O<non-digits> <value>" used to set the address of | |
595 | section <non-digits>. Was this for compatibility with | |
596 | something, or can we create a new option to do that | |
597 | (with a syntax similar to -defsym)? | |
598 | getopt can't handle two args to an option without kludges. */ | |
d4e5e3c3 DM |
599 | break; |
600 | case 'o': | |
601 | lang_add_output (optarg, 0); | |
602 | break; | |
d5b79a89 | 603 | case OPTION_OFORMAT: |
86037281 | 604 | lang_add_output_format (optarg, (char *) NULL, (char *) NULL, 0); |
d4e5e3c3 | 605 | break; |
3e1fd33d | 606 | case 'i': |
d4e5e3c3 DM |
607 | case 'r': |
608 | link_info.relocateable = true; | |
609 | config.build_constructors = false; | |
610 | config.magic_demand_paged = false; | |
611 | config.text_read_only = false; | |
2a9fa50c | 612 | config.dynamic_link = false; |
d4e5e3c3 DM |
613 | break; |
614 | case 'R': | |
809ee7e0 ILT |
615 | /* The GNU linker traditionally uses -R to mean to include |
616 | only the symbols from a file. The Solaris linker uses -R | |
617 | to set the path used by the runtime linker to find | |
618 | libraries. This is the GNU linker -rpath argument. We | |
619 | try to support both simultaneously by checking the file | |
620 | named. If it is a directory, rather than a regular file, | |
621 | we assume -rpath was meant. */ | |
622 | { | |
623 | struct stat s; | |
624 | ||
625 | if (stat (optarg, &s) >= 0 | |
626 | && ! S_ISDIR (s.st_mode)) | |
627 | { | |
628 | lang_add_input_file (optarg, | |
629 | lang_input_file_is_symbols_only_enum, | |
630 | (char *) NULL); | |
631 | break; | |
632 | } | |
633 | } | |
634 | /* Fall through. */ | |
635 | case OPTION_RPATH: | |
636 | if (command_line.rpath == NULL) | |
637 | command_line.rpath = buystring (optarg); | |
638 | else | |
639 | { | |
640 | char *buf; | |
641 | ||
642 | buf = xmalloc (strlen (command_line.rpath) | |
643 | + strlen (optarg) | |
644 | + 2); | |
645 | sprintf (buf, "%s:%s", command_line.rpath, optarg); | |
646 | free (command_line.rpath); | |
647 | command_line.rpath = buf; | |
648 | } | |
d4e5e3c3 | 649 | break; |
3c8deccc ILT |
650 | case OPTION_RPATH_LINK: |
651 | if (command_line.rpath_link == NULL) | |
652 | command_line.rpath_link = buystring (optarg); | |
653 | else | |
654 | { | |
655 | char *buf; | |
656 | ||
657 | buf = xmalloc (strlen (command_line.rpath_link) | |
658 | + strlen (optarg) | |
659 | + 2); | |
660 | sprintf (buf, "%s:%s", command_line.rpath_link, optarg); | |
661 | free (command_line.rpath_link); | |
662 | command_line.rpath_link = buf; | |
663 | } | |
664 | break; | |
d5b79a89 | 665 | case OPTION_RELAX: |
d4e5e3c3 DM |
666 | command_line.relax = true; |
667 | break; | |
d5b79a89 | 668 | case OPTION_RETAIN_SYMBOLS_FILE: |
d4e5e3c3 DM |
669 | add_keepsyms_file (optarg); |
670 | break; | |
671 | case 'S': | |
672 | link_info.strip = strip_debugger; | |
673 | break; | |
674 | case 's': | |
675 | link_info.strip = strip_all; | |
676 | break; | |
db770dfa ILT |
677 | case OPTION_SHARED: |
678 | link_info.shared = true; | |
679 | break; | |
5753006b | 680 | case 'h': /* Used on Solaris. */ |
809ee7e0 ILT |
681 | case OPTION_SONAME: |
682 | command_line.soname = optarg; | |
683 | break; | |
d5b79a89 | 684 | case OPTION_SORT_COMMON: |
d4e5e3c3 DM |
685 | config.sort_common = true; |
686 | break; | |
d5b79a89 | 687 | case OPTION_STATS: |
d4e5e3c3 DM |
688 | config.stats = true; |
689 | break; | |
4551e108 ILT |
690 | case OPTION_SYMBOLIC: |
691 | link_info.symbolic = true; | |
692 | break; | |
d4e5e3c3 DM |
693 | case 't': |
694 | trace_files = true; | |
695 | break; | |
696 | case 'T': | |
697 | ldfile_open_command_file (optarg); | |
698 | parser_input = input_script; | |
699 | yyparse (); | |
700 | break; | |
d5b79a89 | 701 | case OPTION_TBSS: |
d4e5e3c3 DM |
702 | set_section_start (".bss", optarg); |
703 | break; | |
d5b79a89 | 704 | case OPTION_TDATA: |
d4e5e3c3 DM |
705 | set_section_start (".data", optarg); |
706 | break; | |
d5b79a89 | 707 | case OPTION_TTEXT: |
d4e5e3c3 DM |
708 | set_section_start (".text", optarg); |
709 | break; | |
c96386c4 | 710 | case OPTION_TRADITIONAL_FORMAT: |
6799c638 | 711 | link_info.traditional_format = true; |
c96386c4 | 712 | break; |
8bc8f4bc TT |
713 | case OPTION_TASK_LINK: |
714 | link_info.task_link = true; | |
715 | /* Fall through - do an implied -r option. */ | |
d5b79a89 | 716 | case OPTION_UR: |
d4e5e3c3 DM |
717 | link_info.relocateable = true; |
718 | config.build_constructors = true; | |
719 | config.magic_demand_paged = false; | |
720 | config.text_read_only = false; | |
2a9fa50c | 721 | config.dynamic_link = false; |
d4e5e3c3 DM |
722 | break; |
723 | case 'u': | |
724 | ldlang_add_undef (optarg); | |
725 | break; | |
de71eb77 | 726 | case OPTION_VERBOSE: |
d4e5e3c3 DM |
727 | ldversion (1); |
728 | version_printed = true; | |
729 | trace_file_tries = true; | |
730 | break; | |
731 | case 'v': | |
732 | ldversion (0); | |
733 | version_printed = true; | |
734 | break; | |
de71eb77 SC |
735 | case 'V': |
736 | ldversion (1); | |
737 | version_printed = true; | |
738 | break; | |
d5b79a89 | 739 | case OPTION_VERSION: |
9cfdc91a ILT |
740 | /* This output is intended to follow the GNU standards document. */ |
741 | printf ("GNU ld %s\n", ld_program_version); | |
8bc8f4bc TT |
742 | printf (_("Copyright 1997 Free Software Foundation, Inc.\n")); |
743 | printf (_("\ | |
9cfdc91a | 744 | This program is free software; you may redistribute it under the terms of\n\ |
8bc8f4bc | 745 | the GNU General Public License. This program has absolutely no warranty.\n")); |
9cfdc91a ILT |
746 | { |
747 | ld_emulation_xfer_type **ptr = ld_emulations; | |
748 | ||
8bc8f4bc | 749 | printf (_(" Supported emulations:\n")); |
9cfdc91a ILT |
750 | while (*ptr) |
751 | { | |
752 | printf (" %s\n", (*ptr)->emulation_name); | |
753 | ptr++; | |
754 | } | |
755 | } | |
756 | xexit (0); | |
d4e5e3c3 | 757 | break; |
8bc8f4bc TT |
758 | case OPTION_VERSION_SCRIPT: |
759 | /* This option indicates a small script that only specifies | |
760 | version information. Read it, but don't assume that | |
761 | we've seen a linker script. */ | |
762 | { | |
763 | boolean hold_had_script; | |
764 | ||
765 | hold_had_script = had_script; | |
766 | ldfile_open_command_file (optarg); | |
767 | had_script = hold_had_script; | |
768 | parser_input = input_version_script; | |
769 | yyparse (); | |
770 | } | |
771 | break; | |
d5b79a89 | 772 | case OPTION_WARN_COMMON: |
d4e5e3c3 DM |
773 | config.warn_common = true; |
774 | break; | |
80fd1f45 ILT |
775 | case OPTION_WARN_CONSTRUCTORS: |
776 | config.warn_constructors = true; | |
777 | break; | |
4b7d2399 ILT |
778 | case OPTION_WARN_MULTIPLE_GP: |
779 | config.warn_multiple_gp = true; | |
780 | break; | |
809ee7e0 ILT |
781 | case OPTION_WARN_ONCE: |
782 | config.warn_once = true; | |
783 | break; | |
8bc8f4bc TT |
784 | case OPTION_WARN_SECTION_ALIGN: |
785 | config.warn_section_align = true; | |
786 | break; | |
de71eb77 SC |
787 | case OPTION_WHOLE_ARCHIVE: |
788 | whole_archive = true; | |
789 | break; | |
e3d73386 | 790 | case OPTION_WRAP: |
0f5898cc | 791 | add_wrap (optarg); |
e3d73386 | 792 | break; |
d4e5e3c3 DM |
793 | case 'X': |
794 | link_info.discard = discard_l; | |
795 | break; | |
796 | case 'x': | |
797 | link_info.discard = discard_all; | |
798 | break; | |
d5b79a89 | 799 | case 'Y': |
5753006b ILT |
800 | if (strncmp (optarg, "P,", 2) == 0) |
801 | optarg += 2; | |
9cfdc91a | 802 | default_dirlist = xstrdup (optarg); |
d5b79a89 | 803 | break; |
d4e5e3c3 DM |
804 | case 'y': |
805 | add_ysym (optarg); | |
806 | break; | |
22d3533c ILT |
807 | case 'z': |
808 | /* We accept and ignore this option for Solaris | |
809 | compatibility. Actually, on Solaris, optarg is not | |
810 | ignored. Someday we should handle it correctly. FIXME. */ | |
811 | break; | |
de71eb77 SC |
812 | case OPTION_SPLIT_BY_RELOC: |
813 | config.split_by_reloc = atoi (optarg); | |
814 | break; | |
815 | case OPTION_SPLIT_BY_FILE: | |
816 | config.split_by_file = true; | |
817 | break; | |
db770dfa ILT |
818 | case '(': |
819 | if (ingroup) | |
820 | { | |
821 | fprintf (stderr, | |
8bc8f4bc | 822 | _("%s: may not nest groups (--help for usage)\n"), |
db770dfa ILT |
823 | program_name); |
824 | xexit (1); | |
825 | } | |
826 | lang_enter_group (); | |
827 | ingroup = 1; | |
828 | break; | |
829 | case ')': | |
830 | if (! ingroup) | |
831 | { | |
832 | fprintf (stderr, | |
8bc8f4bc | 833 | _("%s: group ended before it began (--help for usage)\n"), |
db770dfa ILT |
834 | program_name); |
835 | xexit (1); | |
836 | } | |
837 | lang_leave_group (); | |
838 | ingroup = 0; | |
839 | break; | |
229ba4b3 | 840 | |
d4e5e3c3 DM |
841 | } |
842 | } | |
db770dfa ILT |
843 | |
844 | if (ingroup) | |
845 | lang_leave_group (); | |
5753006b ILT |
846 | |
847 | if (default_dirlist != NULL) | |
848 | set_default_dirlist (default_dirlist); | |
849 | ||
d4e5e3c3 DM |
850 | } |
851 | ||
852 | /* Add the (colon-separated) elements of DIRLIST_PTR to the | |
853 | library search path. */ | |
854 | ||
855 | static void | |
856 | set_default_dirlist (dirlist_ptr) | |
857 | char *dirlist_ptr; | |
858 | { | |
859 | char *p; | |
860 | ||
861 | while (1) | |
862 | { | |
8bc8f4bc | 863 | p = strchr (dirlist_ptr, PATH_SEPARATOR); |
d4e5e3c3 | 864 | if (p != NULL) |
9cfdc91a ILT |
865 | *p = '\0'; |
866 | if (*dirlist_ptr != '\0') | |
0cd82d00 | 867 | ldfile_add_library_path (dirlist_ptr, true); |
d4e5e3c3 DM |
868 | if (p == NULL) |
869 | break; | |
d4e5e3c3 DM |
870 | dirlist_ptr = p + 1; |
871 | } | |
872 | } | |
873 | ||
874 | static void | |
875 | set_section_start (sect, valstr) | |
876 | char *sect, *valstr; | |
877 | { | |
878 | char *end; | |
879 | unsigned long val = strtoul (valstr, &end, 16); | |
880 | if (*end) | |
8bc8f4bc | 881 | einfo (_("%P%F: invalid hex number `%s'\n"), valstr); |
d4e5e3c3 DM |
882 | lang_section_start (sect, exp_intop (val)); |
883 | } | |
229ba4b3 | 884 | \f |
1ffec9e6 ILT |
885 | /* Print help messages for the options. */ |
886 | ||
887 | static void | |
888 | help () | |
889 | { | |
890 | int i; | |
891 | const char **targets, **pp; | |
892 | ||
8bc8f4bc | 893 | printf (_("Usage: %s [options] file...\n"), program_name); |
1ffec9e6 | 894 | |
8bc8f4bc | 895 | printf (_("Options:\n")); |
1ffec9e6 ILT |
896 | for (i = 0; i < OPTION_COUNT; i++) |
897 | { | |
898 | if (ld_options[i].doc != NULL) | |
899 | { | |
900 | boolean comma; | |
901 | int len; | |
902 | int j; | |
903 | ||
904 | printf (" "); | |
905 | ||
906 | comma = false; | |
907 | len = 2; | |
908 | ||
909 | j = i; | |
910 | do | |
911 | { | |
912 | if (ld_options[j].shortopt != '\0' | |
913 | && ld_options[j].control != NO_HELP) | |
914 | { | |
915 | printf ("%s-%c", comma ? ", " : "", ld_options[j].shortopt); | |
916 | len += (comma ? 2 : 0) + 2; | |
917 | if (ld_options[j].arg != NULL) | |
918 | { | |
bf7198b3 ILT |
919 | if (ld_options[j].opt.has_arg != optional_argument) |
920 | { | |
921 | printf (" "); | |
922 | ++len; | |
923 | } | |
8bc8f4bc TT |
924 | printf ("%s", _(ld_options[j].arg)); |
925 | len += strlen (_(ld_options[j].arg)); | |
1ffec9e6 ILT |
926 | } |
927 | comma = true; | |
928 | } | |
929 | ++j; | |
930 | } | |
931 | while (j < OPTION_COUNT && ld_options[j].doc == NULL); | |
932 | ||
933 | j = i; | |
934 | do | |
935 | { | |
936 | if (ld_options[j].opt.name != NULL | |
937 | && ld_options[j].control != NO_HELP) | |
938 | { | |
939 | printf ("%s-%s%s", | |
940 | comma ? ", " : "", | |
941 | ld_options[j].control == TWO_DASHES ? "-" : "", | |
942 | ld_options[j].opt.name); | |
943 | len += ((comma ? 2 : 0) | |
944 | + 1 | |
945 | + (ld_options[j].control == TWO_DASHES ? 1 : 0) | |
946 | + strlen (ld_options[j].opt.name)); | |
947 | if (ld_options[j].arg != NULL) | |
948 | { | |
8bc8f4bc TT |
949 | printf (" %s", _(ld_options[j].arg)); |
950 | len += 1 + strlen (_(ld_options[j].arg)); | |
1ffec9e6 ILT |
951 | } |
952 | comma = true; | |
953 | } | |
954 | ++j; | |
955 | } | |
956 | while (j < OPTION_COUNT && ld_options[j].doc == NULL); | |
957 | ||
958 | if (len >= 30) | |
959 | { | |
960 | printf ("\n"); | |
961 | len = 0; | |
962 | } | |
963 | ||
964 | for (; len < 30; len++) | |
965 | putchar (' '); | |
966 | ||
8bc8f4bc | 967 | printf ("%s\n", _(ld_options[i].doc)); |
1ffec9e6 ILT |
968 | } |
969 | } | |
970 | ||
8bc8f4bc | 971 | printf (_("%s: supported targets:"), program_name); |
1ffec9e6 ILT |
972 | targets = bfd_target_list (); |
973 | for (pp = targets; *pp != NULL; pp++) | |
974 | printf (" %s", *pp); | |
975 | free (targets); | |
976 | printf ("\n"); | |
977 | ||
8bc8f4bc | 978 | printf (_("%s: supported emulations: "), program_name); |
1ffec9e6 ILT |
979 | ldemul_list_emulations (stdout); |
980 | printf ("\n"); | |
8bc8f4bc | 981 | printf (_("\nReport bugs to [email protected]\n")); |
1ffec9e6 | 982 | } |