1 /* Parse options for the GNU linker.
2 Copyright (C) 1991, 92, 93, 94 Free Software Foundation, Inc.
4 This file is part of GLD, the Gnu Linker.
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GLD is distributed in the hope that it will be useful,
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.
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
37 /* Omit args to avoid the possibility of clashing with a system header
38 that might disagree about consts. */
39 unsigned long strtoul ();
41 static void set_default_dirlist
PARAMS ((char *dirlist_ptr
));
42 static void set_section_start
PARAMS ((char *sect
, char *valstr
));
45 parse_args (argc
, argv
)
49 /* Starting the short option string with '-' is for programs that
50 expect options and other ARGV-elements in any order and that care about
51 the ordering of the two. We describe each non-option ARGV-element
52 as if it were the argument of an option with character code 1. */
54 const char *shortopts
= "-A:B::b:cde:F::G:giL:l:Mm:NnO:o:R:rSsT:tu:VvXxY:y:";
56 /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
58 static struct option longopts
[] = {
59 #define OPTION_CALL_SHARED 150
60 #define OPTION_NON_SHARED 151
61 {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
62 {"dc", no_argument
, NULL
, 'd'},
63 #define OPTION_DEFSYM 152
64 {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
65 {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
66 {"dp", no_argument
, NULL
, 'd'},
67 {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
69 {"EB", no_argument
, NULL
, OPTION_EB
},
71 {"EL", no_argument
, NULL
, OPTION_EL
},
72 {"format", required_argument
, NULL
, 'b'},
73 #define OPTION_HELP 155
74 {"help", no_argument
, NULL
, OPTION_HELP
},
75 #define OPTION_MAP 156
76 {"Map", required_argument
, NULL
, OPTION_MAP
},
77 #define OPTION_NO_KEEP_MEMORY 157
78 {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
79 #define OPTION_NOINHIBIT_EXEC 158
80 {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
81 {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
82 {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
83 #define OPTION_OFORMAT 159
84 {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
85 #define OPTION_IGNORE 160
86 {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
87 #define OPTION_RELAX 161
88 {"relax", no_argument
, NULL
, OPTION_RELAX
},
89 #define OPTION_RETAIN_SYMBOLS_FILE 162
90 {"retain-symbols-file", no_argument
, NULL
, OPTION_RETAIN_SYMBOLS_FILE
},
91 #define OPTION_SORT_COMMON 163
92 {"sort-common", no_argument
, NULL
, OPTION_SORT_COMMON
},
93 {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
94 #define OPTION_STATS 164
95 {"stats", no_argument
, NULL
, OPTION_STATS
},
96 #define OPTION_TBSS 165
97 {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
98 #define OPTION_TDATA 166
99 {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
100 #define OPTION_TTEXT 167
101 {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
102 #define OPTION_UR 168
103 {"Ur", no_argument
, NULL
, OPTION_UR
},
104 #define OPTION_VERSION 169
105 {"version", no_argument
, NULL
, OPTION_VERSION
},
106 #define OPTION_WARN_COMMON 170
107 {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
108 {NULL
, no_argument
, NULL
, 0}
113 /* getopt_long_only is like getopt_long, but '-' as well as '--' can
114 indicate a long option. */
116 int optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
125 case 1: /* File name. */
126 lang_add_input_file (optarg
, lang_input_file_is_file_enum
,
133 ldfile_add_arch (optarg
);
139 lang_add_target (optarg
);
142 ldfile_open_command_file (optarg
);
143 parser_input
= input_mri_script
;
146 case OPTION_CALL_SHARED
:
147 config
.dynamic_link
= true;
149 case OPTION_NON_SHARED
:
150 config
.dynamic_link
= false;
153 command_line
.force_common_definition
= true;
156 lex_redirect (optarg
);
157 parser_input
= input_defsym
;
161 /* FIXME: This is currently ignored. It means
162 ``produce a big-endian object file''. It could
163 be used to select an output format. */
166 /* FIXME: This is currently ignored. It means
167 ``produce a little-endian object file''. It could
168 be used to select an output format. */
171 lang_add_entry (optarg
, 1);
179 g_switch_value
= strtoul (optarg
, &end
, 0);
181 einfo ("%P%F: invalid number `%s'\n", optarg
);
192 ldfile_add_library_path (optarg
, true);
195 lang_add_input_file (optarg
, lang_input_file_is_l_enum
,
199 config
.map_filename
= "-";
202 /* Ignore. Was handled in a pre-parse. */
205 config
.map_filename
= optarg
;
208 config
.text_read_only
= false;
209 config
.magic_demand_paged
= false;
212 config
.magic_demand_paged
= false;
214 case OPTION_NO_KEEP_MEMORY
:
215 link_info
.keep_memory
= false;
217 case OPTION_NOINHIBIT_EXEC
:
218 force_make_executable
= true;
221 /* FIXME "-O<non-digits> <value>" used to set the address of
222 section <non-digits>. Was this for compatibility with
223 something, or can we create a new option to do that
224 (with a syntax similar to -defsym)?
225 getopt can't handle two args to an option without kludges. */
226 set_default_dirlist (optarg
);
229 lang_add_output (optarg
, 0);
232 lang_add_output_format (optarg
, 0);
235 link_info
.relocateable
= true;
236 config
.build_constructors
= false;
237 config
.magic_demand_paged
= false;
238 config
.text_read_only
= false;
239 config
.dynamic_link
= false;
242 lang_add_input_file (optarg
,
243 lang_input_file_is_symbols_only_enum
,
247 command_line
.relax
= true;
249 case OPTION_RETAIN_SYMBOLS_FILE
:
250 add_keepsyms_file (optarg
);
253 link_info
.strip
= strip_debugger
;
256 link_info
.strip
= strip_all
;
258 case OPTION_SORT_COMMON
:
259 config
.sort_common
= true;
268 ldfile_open_command_file (optarg
);
269 parser_input
= input_script
;
273 set_section_start (".bss", optarg
);
276 set_section_start (".data", optarg
);
279 set_section_start (".text", optarg
);
282 link_info
.relocateable
= true;
283 config
.build_constructors
= true;
284 config
.magic_demand_paged
= false;
285 config
.text_read_only
= false;
286 config
.dynamic_link
= false;
289 ldlang_add_undef (optarg
);
293 version_printed
= true;
294 trace_file_tries
= true;
298 version_printed
= true;
302 version_printed
= true;
304 case OPTION_WARN_COMMON
:
305 config
.warn_common
= true;
308 link_info
.discard
= discard_l
;
311 link_info
.discard
= discard_all
;
314 set_default_dirlist (optarg
);
323 /* Add the (colon-separated) elements of DIRLIST_PTR to the
324 library search path. */
327 set_default_dirlist (dirlist_ptr
)
334 p
= strchr (dirlist_ptr
, ':');
338 ldfile_add_library_path (dirlist_ptr
, true);
347 set_section_start (sect
, valstr
)
351 unsigned long val
= strtoul (valstr
, &end
, 16);
353 einfo ("%P%F: invalid hex number `%s'\n", valstr
);
354 lang_section_start (sect
, exp_intop (val
));