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 #define OPTION_CALL_SHARED 150
59 #define OPTION_DEFSYM (OPTION_CALL_SHARED + 1)
60 #define OPTION_DYNAMIC_LINKER (OPTION_DEFSYM + 1)
61 #define OPTION_EB (OPTION_DYNAMIC_LINKER + 1)
62 #define OPTION_EL (OPTION_EB + 1)
63 #define OPTION_HELP (OPTION_EL + 1)
64 #define OPTION_IGNORE (OPTION_HELP + 1)
65 #define OPTION_MAP (OPTION_IGNORE + 1)
66 #define OPTION_NO_KEEP_MEMORY (OPTION_MAP + 1)
67 #define OPTION_NOINHIBIT_EXEC (OPTION_NO_KEEP_MEMORY + 1)
68 #define OPTION_NON_SHARED (OPTION_NOINHIBIT_EXEC + 1)
69 #define OPTION_OFORMAT (OPTION_NON_SHARED + 1)
70 #define OPTION_RELAX (OPTION_OFORMAT + 1)
71 #define OPTION_RETAIN_SYMBOLS_FILE (OPTION_RELAX + 1)
72 #define OPTION_SORT_COMMON (OPTION_RETAIN_SYMBOLS_FILE + 1)
73 #define OPTION_STATS (OPTION_SORT_COMMON + 1)
74 #define OPTION_TBSS (OPTION_STATS + 1)
75 #define OPTION_TDATA (OPTION_TBSS + 1)
76 #define OPTION_TTEXT (OPTION_TDATA + 1)
77 #define OPTION_TRADITIONAL_FORMAT (OPTION_TTEXT + 1)
78 #define OPTION_UR (OPTION_TRADITIONAL_FORMAT + 1)
79 #define OPTION_VERSION (OPTION_UR + 1)
80 #define OPTION_WARN_COMMON (OPTION_VERSION + 1)
82 static struct option longopts
[] = {
83 {"call_shared", no_argument
, NULL
, OPTION_CALL_SHARED
},
84 {"dc", no_argument
, NULL
, 'd'},
85 {"defsym", required_argument
, NULL
, OPTION_DEFSYM
},
86 {"dn", no_argument
, NULL
, OPTION_NON_SHARED
},
87 {"dp", no_argument
, NULL
, 'd'},
88 {"dy", no_argument
, NULL
, OPTION_CALL_SHARED
},
89 {"dynamic-linker", required_argument
, NULL
, OPTION_DYNAMIC_LINKER
},
90 {"EB", no_argument
, NULL
, OPTION_EB
},
91 {"EL", no_argument
, NULL
, OPTION_EL
},
92 {"format", required_argument
, NULL
, 'b'},
93 {"help", no_argument
, NULL
, OPTION_HELP
},
94 {"Map", required_argument
, NULL
, OPTION_MAP
},
95 {"no-keep-memory", no_argument
, NULL
, OPTION_NO_KEEP_MEMORY
},
96 {"noinhibit-exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
97 {"noinhibit_exec", no_argument
, NULL
, OPTION_NOINHIBIT_EXEC
},
98 {"non_shared", no_argument
, NULL
, OPTION_NON_SHARED
},
99 {"oformat", required_argument
, NULL
, OPTION_OFORMAT
},
100 {"Qy", no_argument
, NULL
, OPTION_IGNORE
},
101 {"qmagic", no_argument
, NULL
, OPTION_IGNORE
}, /* Linux compatibility. */
102 {"relax", no_argument
, NULL
, OPTION_RELAX
},
103 {"retain-symbols-file", no_argument
, NULL
, OPTION_RETAIN_SYMBOLS_FILE
},
104 {"sort-common", no_argument
, NULL
, OPTION_SORT_COMMON
},
105 {"sort_common", no_argument
, NULL
, OPTION_SORT_COMMON
},
106 {"stats", no_argument
, NULL
, OPTION_STATS
},
107 {"Tbss", required_argument
, NULL
, OPTION_TBSS
},
108 {"Tdata", required_argument
, NULL
, OPTION_TDATA
},
109 {"Ttext", required_argument
, NULL
, OPTION_TTEXT
},
110 {"traditional-format", no_argument
, NULL
, OPTION_TRADITIONAL_FORMAT
},
111 {"Ur", no_argument
, NULL
, OPTION_UR
},
112 {"version", no_argument
, NULL
, OPTION_VERSION
},
113 {"warn-common", no_argument
, NULL
, OPTION_WARN_COMMON
},
114 {NULL
, no_argument
, NULL
, 0}
119 /* getopt_long_only is like getopt_long, but '-' as well as '--' can
120 indicate a long option. */
122 int optc
= getopt_long_only (argc
, argv
, shortopts
, longopts
, &longind
);
131 case 1: /* File name. */
132 lang_add_input_file (optarg
, lang_input_file_is_file_enum
,
139 ldfile_add_arch (optarg
);
145 lang_add_target (optarg
);
148 ldfile_open_command_file (optarg
);
149 parser_input
= input_mri_script
;
152 case OPTION_CALL_SHARED
:
153 config
.dynamic_link
= true;
155 case OPTION_NON_SHARED
:
156 config
.dynamic_link
= false;
159 command_line
.force_common_definition
= true;
162 lex_redirect (optarg
);
163 parser_input
= input_defsym
;
166 case OPTION_DYNAMIC_LINKER
:
167 command_line
.interpreter
= optarg
;
170 /* FIXME: This is currently ignored. It means
171 ``produce a big-endian object file''. It could
172 be used to select an output format. */
175 /* FIXME: This is currently ignored. It means
176 ``produce a little-endian object file''. It could
177 be used to select an output format. */
180 lang_add_entry (optarg
, 1);
188 g_switch_value
= strtoul (optarg
, &end
, 0);
190 einfo ("%P%F: invalid number `%s'\n", optarg
);
201 ldfile_add_library_path (optarg
, true);
204 lang_add_input_file (optarg
, lang_input_file_is_l_enum
,
208 config
.map_filename
= "-";
211 /* Ignore. Was handled in a pre-parse. */
214 config
.map_filename
= optarg
;
217 config
.text_read_only
= false;
218 config
.magic_demand_paged
= false;
221 config
.magic_demand_paged
= false;
223 case OPTION_NO_KEEP_MEMORY
:
224 link_info
.keep_memory
= false;
226 case OPTION_NOINHIBIT_EXEC
:
227 force_make_executable
= true;
230 /* FIXME "-O<non-digits> <value>" used to set the address of
231 section <non-digits>. Was this for compatibility with
232 something, or can we create a new option to do that
233 (with a syntax similar to -defsym)?
234 getopt can't handle two args to an option without kludges. */
235 set_default_dirlist (optarg
);
238 lang_add_output (optarg
, 0);
241 lang_add_output_format (optarg
, 0);
245 link_info
.relocateable
= true;
246 config
.build_constructors
= false;
247 config
.magic_demand_paged
= false;
248 config
.text_read_only
= false;
249 config
.dynamic_link
= false;
252 lang_add_input_file (optarg
,
253 lang_input_file_is_symbols_only_enum
,
257 command_line
.relax
= true;
259 case OPTION_RETAIN_SYMBOLS_FILE
:
260 add_keepsyms_file (optarg
);
263 link_info
.strip
= strip_debugger
;
266 link_info
.strip
= strip_all
;
268 case OPTION_SORT_COMMON
:
269 config
.sort_common
= true;
278 ldfile_open_command_file (optarg
);
279 parser_input
= input_script
;
283 set_section_start (".bss", optarg
);
286 set_section_start (".data", optarg
);
289 set_section_start (".text", optarg
);
291 case OPTION_TRADITIONAL_FORMAT
:
292 config
.traditional_format
= true;
295 link_info
.relocateable
= true;
296 config
.build_constructors
= true;
297 config
.magic_demand_paged
= false;
298 config
.text_read_only
= false;
299 config
.dynamic_link
= false;
302 ldlang_add_undef (optarg
);
306 version_printed
= true;
307 trace_file_tries
= true;
311 version_printed
= true;
315 version_printed
= true;
317 case OPTION_WARN_COMMON
:
318 config
.warn_common
= true;
321 link_info
.discard
= discard_l
;
324 link_info
.discard
= discard_all
;
327 set_default_dirlist (optarg
);
336 /* Add the (colon-separated) elements of DIRLIST_PTR to the
337 library search path. */
340 set_default_dirlist (dirlist_ptr
)
347 p
= strchr (dirlist_ptr
, ':');
351 ldfile_add_library_path (dirlist_ptr
, true);
360 set_section_start (sect
, valstr
)
364 unsigned long val
= strtoul (valstr
, &end
, 16);
366 einfo ("%P%F: invalid hex number `%s'\n", valstr
);
367 lang_section_start (sect
, exp_intop (val
));