From 4d7dac47f9db98f51bdc2c05f81f34158f613a6f Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 28 Sep 2019 11:02:53 -0600 Subject: [PATCH] libs/symtab/Makefile and tools/mksymtab.c: Ensure that the generated symbol table name same as the configuration option. --- libs/symtab/Makefile | 4 +--- tools/mksymtab.c | 42 +++++++++++++++++++++++++++++++----------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/libs/symtab/Makefile b/libs/symtab/Makefile index 83723ccbab..99ab61ec15 100644 --- a/libs/symtab/Makefile +++ b/libs/symtab/Makefile @@ -82,9 +82,7 @@ $(MKSYMTAB): symtab.c : $(CSVFILES) $(MKSYMTAB) $(Q) rm -f tmp.csv $@ $(Q) cat $(CSVFILES) | LC_ALL=C sort >tmp.csv - $(Q) $(MKSYMTAB) tmp.csv $@ - $(Q) echo >>$@ - $(Q) echo >>$@ 'int g_nsymbols = NSYMBOLS;' + $(Q) $(MKSYMTAB) tmp.csv $@ $(CONFIG_EXECFUNCS_SYMTAB_ARRAY) $(CONFIG_EXECFUNCS_NSYMBOLS_VAR) else all: diff --git a/tools/mksymtab.c b/tools/mksymtab.c index ddac7fda07..287d014353 100644 --- a/tools/mksymtab.c +++ b/tools/mksymtab.c @@ -52,6 +52,7 @@ #define MAX_HEADER_FILES 500 #define SYMTAB_NAME "g_symtab" +#define NSYMBOLS_NAME "g_nsymbols" /**************************************************************************** * Private Types @@ -70,11 +71,13 @@ static int nhdrfiles; static void show_usage(const char *progname) { - fprintf(stderr, "USAGE: %s \n\n", progname); + fprintf(stderr, "USAGE: %s [symtab-name] [nsymbols-name]\n\n", progname); fprintf(stderr, "Where:\n\n"); - fprintf(stderr, " : The path to the input CSV file\n"); - fprintf(stderr, " : The path to the output symbol table file\n"); - fprintf(stderr, " -d : Enable debug output\n"); + fprintf(stderr, " : The path to the input CSV file\n"); + fprintf(stderr, " : The path to the output symbol table file\n"); + fprintf(stderr, " [symtab-name] : The name for the symbol table variable\n"); + fprintf(stderr, " [nsymbols-name]: The name for the symbol count variable\n"); + fprintf(stderr, " -d : Enable debug output\n"); exit(EXIT_FAILURE); } @@ -118,7 +121,9 @@ static void add_hdrfile(const char *hdrfile) int main(int argc, char **argv, char **envp) { char *csvpath; + char *sympath; char *symtab; + char *nsymbols; char *nextterm; char *finalterm; char *ptr; @@ -130,7 +135,9 @@ int main(int argc, char **argv, char **envp) /* Parse command line options */ - g_debug = false; + symtab = SYMTAB_NAME; + nsymbols = NSYMBOLS_NAME; + g_debug = false; while ((ch = getopt(argc, argv, ":d")) > 0) { @@ -169,9 +176,21 @@ int main(int argc, char **argv, char **envp) show_usage(argv[0]); } - symtab = argv[optind]; + sympath = argv[optind]; optind++; + if (optind < argc) + { + symtab = argv[optind]; + optind++; + } + + if (optind < argc) + { + nsymbols = argv[optind]; + optind++; + } + if (optind < argc) { fprintf(stderr, "Unexpected garbage at the end of the line\n"); @@ -189,7 +208,7 @@ int main(int argc, char **argv, char **envp) /* Open the Symbol table file for writing */ - outstream = fopen(symtab, "w"); + outstream = fopen(sympath, "w"); if (!outstream) { fprintf(stderr, "open %s failed: %s\n", csvpath, strerror(errno)); @@ -220,10 +239,10 @@ int main(int argc, char **argv, char **envp) /* Output up-front file boilerplate */ - fprintf(outstream, "/* %s: Auto-generated symbol table. Do not edit */\n\n", symtab); + fprintf(outstream, "/* %s: Auto-generated symbol table. Do not edit */\n\n", sympath); fprintf(outstream, "#include \n"); fprintf(outstream, "#include \n"); - fprintf(outstream, "#include \n\n"); + fprintf(outstream, "#include \n\n"); /* Output all of the require header files */ @@ -234,7 +253,7 @@ int main(int argc, char **argv, char **envp) /* Now the symbol table itself */ - fprintf(outstream, "\nconst struct symtab_s %s[] =\n", SYMTAB_NAME); + fprintf(outstream, "\nconst struct symtab_s %s[] =\n", symtab); fprintf(outstream, "{\n"); /* Parse each line in the CVS file */ @@ -280,7 +299,8 @@ int main(int argc, char **argv, char **envp) } fprintf(outstream, "%s};\n\n", finalterm); - fprintf(outstream, "#define NSYMBOLS (sizeof(%s) / sizeof (struct symtab_s))\n", SYMTAB_NAME); + fprintf(outstream, "#define NSYMBOLS (sizeof(%s) / sizeof (struct symtab_s))\n", symtab); + fprintf(outstream, "int %s = NSYMBOLS;\n", nsymbols); /* Close the CSV and symbol table files and exit */