18
18
*
19
19
*/
20
20
21
+ #include <getopt.h>
21
22
#include <stdbool.h>
22
23
#include <stdio.h>
23
24
#include <stdlib.h>
@@ -71,7 +72,7 @@ static unsigned char best_table_len[256];
71
72
static void usage (void )
72
73
{
73
74
fprintf (stderr , "Usage: kallsyms [--all-symbols] [--absolute-percpu] "
74
- "[--base-relative] < in.map > out.S\n" );
75
+ "[--base-relative] in.map > out.S\n" );
75
76
exit (1 );
76
77
}
77
78
@@ -310,12 +311,19 @@ static void shrink_table(void)
310
311
}
311
312
}
312
313
313
- static void read_map (FILE * in )
314
+ static void read_map (const char * in )
314
315
{
316
+ FILE * fp ;
315
317
struct sym_entry * sym ;
316
318
317
- while (!feof (in )) {
318
- sym = read_symbol (in );
319
+ fp = fopen (in , "r" );
320
+ if (!fp ) {
321
+ perror (in );
322
+ exit (1 );
323
+ }
324
+
325
+ while (!feof (fp )) {
326
+ sym = read_symbol (fp );
319
327
if (!sym )
320
328
continue ;
321
329
@@ -326,12 +334,15 @@ static void read_map(FILE *in)
326
334
table = realloc (table , sizeof (* table ) * table_size );
327
335
if (!table ) {
328
336
fprintf (stderr , "out of memory\n" );
337
+ fclose (fp );
329
338
exit (1 );
330
339
}
331
340
}
332
341
333
342
table [table_cnt ++ ] = sym ;
334
343
}
344
+
345
+ fclose (fp );
335
346
}
336
347
337
348
static void output_label (const char * label )
@@ -762,22 +773,26 @@ static void record_relative_base(void)
762
773
763
774
int main (int argc , char * * argv )
764
775
{
765
- if (argc >= 2 ) {
766
- int i ;
767
- for (i = 1 ; i < argc ; i ++ ) {
768
- if (strcmp (argv [i ], "--all-symbols" ) == 0 )
769
- all_symbols = 1 ;
770
- else if (strcmp (argv [i ], "--absolute-percpu" ) == 0 )
771
- absolute_percpu = 1 ;
772
- else if (strcmp (argv [i ], "--base-relative" ) == 0 )
773
- base_relative = 1 ;
774
- else
775
- usage ();
776
- }
777
- } else if (argc != 1 )
776
+ while (1 ) {
777
+ static struct option long_options [] = {
778
+ {"all-symbols" , no_argument , & all_symbols , 1 },
779
+ {"absolute-percpu" , no_argument , & absolute_percpu , 1 },
780
+ {"base-relative" , no_argument , & base_relative , 1 },
781
+ {},
782
+ };
783
+
784
+ int c = getopt_long (argc , argv , "" , long_options , NULL );
785
+
786
+ if (c == -1 )
787
+ break ;
788
+ if (c != 0 )
789
+ usage ();
790
+ }
791
+
792
+ if (optind >= argc )
778
793
usage ();
779
794
780
- read_map (stdin );
795
+ read_map (argv [ optind ] );
781
796
shrink_table ();
782
797
if (absolute_percpu )
783
798
make_percpus_absolute ();
0 commit comments