10 extern int optind, opterr, optopt;
12 static struct option long_options[] =
14 {"verbose", no_argument, 0, 'V'},
15 {"quiet", no_argument, 0, 'Q'},
16 {"shady", no_argument, 0, 'S'},
17 {"print", no_argument, 0, 'p'},
18 {"help", no_argument, 0, 'h'},
19 {"outfile", required_argument, 0, 'o'},
20 {"filter", required_argument, 0, 'f'},
21 {"dry", no_argument, 0, 'n'},
22 {"strip", no_argument, 0, 's'},
26 /* This array must parallel long_options[] */
28 const char *descriptions[sizeof(long_options)/sizeof(long_options[0])] = {
29 "print verbose output",
30 "suppress errors and warnings",
31 "patch ABS symbols whose values coincide with section starts and ends",
32 "print the symbol table (if specified, only -V is allowed)",
34 "specify an output file (if not provided, input file is modified)",
35 "specify a symbol-filter file",
36 "dry run (perform all calculations but do not modify the ELF file)",
37 "strip debug sections, if they are present"
44 "\tsoslim file1 [file2 file3 ... fileN] [-Ldir1 -Ldir2 ... -LdirN] "
48 fprintf(stdout, "options:\n");
49 struct option *opt = long_options;
50 const char **desc = descriptions;
52 fprintf(stdout, "\t-%c/--%-15s %s\n",
61 int get_options(int argc, char **argv,
91 /* getopt_long stores the option index here. */
94 c = getopt_long (argc, argv,
98 /* Detect the end of the options. */
102 INFO ("option -%c with value `%s'\n", c, (optarg ?: "(null)"));
105 #define SET_STRING_OPTION(name) do { \
107 *name = strdup(optarg); \
112 /* If this option set a flag, do nothing else now. */
113 if (long_options[option_index].flag != 0)
115 INFO ("option %s", long_options[option_index].name);
117 INFO (" with arg %s", optarg);
120 case 'p': *print_symtab = 1; break;
121 case 'h': print_help(); exit(1); break;
122 case 'V': *verbose = 1; break;
123 case 'Q': *quiet = 1; break;
124 case 'S': *shady = 1; break;
125 case 'n': *dry_run = 1; break;
126 case 's': *strip_debug = 1; break;
127 case 'o': SET_STRING_OPTION(outfile); break;
128 case 'f': SET_STRING_OPTION(symsfile); break;
130 /* getopt_long already printed an error message. */
133 #undef SET_STRING_OPTION
136 FAILIF(1, "Unknown option");