* lexsup.c (parse_args): Use symbolic numbers for long options.

Fix misunderstanding in -Y and -call_shared et al.
This commit is contained in:
David MacKenzie
1994-02-25 04:08:55 +00:00
parent b3cefbc393
commit d5b79a89b9
2 changed files with 77 additions and 51 deletions

View File

@ -10,6 +10,9 @@ Thu Feb 24 16:47:33 1994 Ian Lance Taylor (ian@cygnus.com)
Thu Feb 24 12:27:07 1994 David J. Mackenzie (djm@rtl.cygnus.com) Thu Feb 24 12:27:07 1994 David J. Mackenzie (djm@rtl.cygnus.com)
* lexsup.c (parse_args): Use symbolic numbers for long options.
Fix misunderstanding in -Y and -call_shared et al.
Use getopt instead of lex and yacc to parse the command line. Use getopt instead of lex and yacc to parse the command line.
* ld.texinfo (Options): Document changes to option syntax. * ld.texinfo (Options): Document changes to option syntax.

View File

@ -50,38 +50,57 @@ parse_args (argc, argv)
the ordering of the two. We describe each non-option ARGV-element the ordering of the two. We describe each non-option ARGV-element
as if it were the argument of an option with character code 1. */ as if it were the argument of an option with character code 1. */
const char *shortopts = "-A:B::b:cde:F::G:giL:l:Mm:NnO:o:R:rSsT:tu:VvXxy:"; const char *shortopts = "-A:B::b:cde:F::G:giL:l:Mm:NnO:o:R:rSsT:tu:VvXxY:y:";
static struct option longopts[] = /* 150 isn't special; it's just an arbitrary non-ASCII char value. */
{
{"call_shared", no_argument, NULL, 158}, static struct option longopts[] = {
#define OPTION_CALL_SHARED 150
{"call_shared", no_argument, NULL, OPTION_CALL_SHARED},
{"dc", no_argument, NULL, 'd'}, {"dc", no_argument, NULL, 'd'},
{"defsym", required_argument, NULL, 160}, #define OPTION_DEFSYM 151
{"dn", no_argument, NULL, 158}, {"defsym", required_argument, NULL, OPTION_DEFSYM},
{"dn", no_argument, NULL, OPTION_CALL_SHARED},
{"dp", no_argument, NULL, 'd'}, {"dp", no_argument, NULL, 'd'},
{"EB", no_argument, NULL, 150}, #define OPTION_EB 152
{"EL", no_argument, NULL, 151}, {"EB", no_argument, NULL, OPTION_EB},
#define OPTION_EL 153
{"EL", no_argument, NULL, OPTION_EL},
{"format", required_argument, NULL, 'b'}, {"format", required_argument, NULL, 'b'},
{"help", no_argument, NULL, 164}, #define OPTION_HELP 154
{"Map", required_argument, NULL, 152}, {"help", no_argument, NULL, OPTION_HELP},
{"no-keep-memory", no_argument, NULL, 168}, #define OPTION_MAP 155
{"noinhibit-exec", no_argument, NULL, 169}, {"Map", required_argument, NULL, OPTION_MAP},
{"noinhibit_exec", no_argument, NULL, 169}, #define OPTION_NO_KEEP_MEMORY 156
{"non_shared", no_argument, NULL, 158}, {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY},
{"oformat", required_argument, NULL, 172}, #define OPTION_NOINHIBIT_EXEC 157
{"Qy", no_argument, NULL, 158}, {"noinhibit-exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
{"relax", no_argument, NULL, 173}, {"noinhibit_exec", no_argument, NULL, OPTION_NOINHIBIT_EXEC},
{"retain-symbols-file", no_argument, NULL, 174}, {"non_shared", no_argument, NULL, OPTION_CALL_SHARED},
{"sort-common", no_argument, NULL, 175}, #define OPTION_OFORMAT 158
{"sort_common", no_argument, NULL, 175}, {"oformat", required_argument, NULL, OPTION_OFORMAT},
{"stats", no_argument, NULL, 176}, {"Qy", no_argument, NULL, OPTION_CALL_SHARED},
{"Tbss", required_argument, NULL, 154}, #define OPTION_RELAX 159
{"Tdata", required_argument, NULL, 155}, {"relax", no_argument, NULL, OPTION_RELAX},
{"Ttext", required_argument, NULL, 156}, #define OPTION_RETAIN_SYMBOLS_FILE 160
{"Ur", no_argument, NULL, 157}, {"retain-symbols-file", no_argument, NULL, OPTION_RETAIN_SYMBOLS_FILE},
{"version", no_argument, NULL, 178}, #define OPTION_SORT_COMMON 161
{"warn-common", no_argument, NULL, 177}, {"sort-common", no_argument, NULL, OPTION_SORT_COMMON},
{"YP,", required_argument, NULL, 158}, {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
#define OPTION_STATS 162
{"stats", no_argument, NULL, OPTION_STATS},
#define OPTION_TBSS 163
{"Tbss", required_argument, NULL, OPTION_TBSS},
#define OPTION_TDATA 164
{"Tdata", required_argument, NULL, OPTION_TDATA},
#define OPTION_TTEXT 165
{"Ttext", required_argument, NULL, OPTION_TTEXT},
#define OPTION_UR 166
{"Ur", no_argument, NULL, OPTION_UR},
#define OPTION_VERSION 167
{"version", no_argument, NULL, OPTION_VERSION},
#define OPTION_WARN_COMMON 168
{"warn-common", no_argument, NULL, OPTION_WARN_COMMON},
{NULL, no_argument, NULL, 0} {NULL, no_argument, NULL, 0}
}; };
@ -89,8 +108,9 @@ parse_args (argc, argv)
{ {
/* getopt_long_only is like getopt_long, but '-' as well as '--' can /* getopt_long_only is like getopt_long, but '-' as well as '--' can
indicate a long option. */ indicate a long option. */
int optc = getopt_long_only (argc, argv, shortopts, longopts, int longind;
(int *) NULL); int optc = getopt_long_only (argc, argv, shortopts, longopts, &longind);
if (optc == -1) if (optc == -1)
break; break;
@ -117,23 +137,23 @@ parse_args (argc, argv)
parser_input = input_mri_script; parser_input = input_mri_script;
yyparse (); yyparse ();
break; break;
case 158: /* call_shared, dn, non_shared, Qy, YP */ case OPTION_CALL_SHARED:
set_default_dirlist (optarg); set_default_dirlist ((char *) longopts[longind].name);
break; break;
case 'd': case 'd':
command_line.force_common_definition = true; command_line.force_common_definition = true;
break; break;
case 160: /* defsym */ case OPTION_DEFSYM:
lex_redirect (optarg); lex_redirect (optarg);
parser_input = input_defsym; parser_input = input_defsym;
yyparse (); yyparse ();
break; break;
case 150: /* EB */ case OPTION_EB:
/* FIXME: This is currently ignored. It means /* FIXME: This is currently ignored. It means
``produce a big-endian object file''. It could ``produce a big-endian object file''. It could
be used to select an output format. */ be used to select an output format. */
break; break;
case 151: /* EL */ case OPTION_EL:
/* FIXME: This is currently ignored. It means /* FIXME: This is currently ignored. It means
``produce a little-endian object file''. It could ``produce a little-endian object file''. It could
be used to select an output format. */ be used to select an output format. */
@ -155,7 +175,7 @@ parse_args (argc, argv)
case 'g': case 'g':
/* Ignore. */ /* Ignore. */
break; break;
case 164: /* help */ case OPTION_HELP:
help (); help ();
xexit (0); xexit (0);
break; break;
@ -172,7 +192,7 @@ parse_args (argc, argv)
case 'm': case 'm':
/* Ignore. Was handled in a pre-parse. */ /* Ignore. Was handled in a pre-parse. */
break; break;
case 152: /* Map */ case OPTION_MAP:
write_map = true; write_map = true;
config.map_filename = optarg; config.map_filename = optarg;
break; break;
@ -183,10 +203,10 @@ parse_args (argc, argv)
case 'n': case 'n':
config.magic_demand_paged = false; config.magic_demand_paged = false;
break; break;
case 168: /* no-keep-memory */ case OPTION_NO_KEEP_MEMORY:
link_info.keep_memory = false; link_info.keep_memory = false;
break; break;
case 169: /* noinhibit-exec */ case OPTION_NOINHIBIT_EXEC:
force_make_executable = true; force_make_executable = true;
break; break;
case 'O': case 'O':
@ -200,7 +220,7 @@ parse_args (argc, argv)
case 'o': case 'o':
lang_add_output (optarg, 0); lang_add_output (optarg, 0);
break; break;
case 172: /* oformat */ case OPTION_OFORMAT:
lang_add_output_format (optarg, 0); lang_add_output_format (optarg, 0);
break; break;
case 'r': case 'r':
@ -214,10 +234,10 @@ parse_args (argc, argv)
lang_input_file_is_symbols_only_enum, lang_input_file_is_symbols_only_enum,
(char *) NULL); (char *) NULL);
break; break;
case 173: /* relax */ case OPTION_RELAX:
command_line.relax = true; command_line.relax = true;
break; break;
case 174: /* retain-symbols-file */ case OPTION_RETAIN_SYMBOLS_FILE:
add_keepsyms_file (optarg); add_keepsyms_file (optarg);
break; break;
case 'S': case 'S':
@ -226,10 +246,10 @@ parse_args (argc, argv)
case 's': case 's':
link_info.strip = strip_all; link_info.strip = strip_all;
break; break;
case 175: /* sort-common */ case OPTION_SORT_COMMON:
config.sort_common = true; config.sort_common = true;
break; break;
case 176: /* stats */ case OPTION_STATS:
config.stats = true; config.stats = true;
break; break;
case 't': case 't':
@ -240,16 +260,16 @@ parse_args (argc, argv)
parser_input = input_script; parser_input = input_script;
yyparse (); yyparse ();
break; break;
case 154: /* Tbss */ case OPTION_TBSS:
set_section_start (".bss", optarg); set_section_start (".bss", optarg);
break; break;
case 155: /* Tdata */ case OPTION_TDATA:
set_section_start (".data", optarg); set_section_start (".data", optarg);
break; break;
case 156: /* Ttext */ case OPTION_TTEXT:
set_section_start (".text", optarg); set_section_start (".text", optarg);
break; break;
case 157: /* Ur */ case OPTION_UR:
link_info.relocateable = true; link_info.relocateable = true;
config.build_constructors = true; config.build_constructors = true;
config.magic_demand_paged = false; config.magic_demand_paged = false;
@ -267,11 +287,11 @@ parse_args (argc, argv)
ldversion (0); ldversion (0);
version_printed = true; version_printed = true;
break; break;
case 178: /* version */ case OPTION_VERSION:
ldversion (0); ldversion (0);
version_printed = true; version_printed = true;
break; break;
case 177: /* warn-common */ case OPTION_WARN_COMMON:
config.warn_common = true; config.warn_common = true;
break; break;
case 'X': case 'X':
@ -280,6 +300,9 @@ parse_args (argc, argv)
case 'x': case 'x':
link_info.discard = discard_all; link_info.discard = discard_all;
break; break;
case 'Y':
set_default_dirlist (optarg);
break;
case 'y': case 'y':
add_ysym (optarg); add_ysym (optarg);
break; break;
@ -317,6 +340,6 @@ set_section_start (sect, valstr)
char *end; char *end;
unsigned long val = strtoul (valstr, &end, 16); unsigned long val = strtoul (valstr, &end, 16);
if (*end) if (*end)
einfo ("%P%F: invalid hex number `%s'", valstr); einfo ("%P%F: invalid hex number `%s'\n", valstr);
lang_section_start (sect, exp_intop (val)); lang_section_start (sect, exp_intop (val));
} }