From dd6c5a9217002033149a92bc48999370c451d025 Mon Sep 17 00:00:00 2001 From: Tsukasa OI Date: Mon, 17 Oct 2022 15:47:23 +0000 Subject: sim, sim/{m32c,ppc,rl78}: Use getopt_long Because of a Libiberty hack, getopt on GNU libc (2.25 or earlier) is currently unusable on sim, causing a regression on CentOS 7. This is caused as follows: 1. If HAVE_DECL_GETOPT is defined (getopt declaration with known prototype is detected while configuration), a declaration of getopt in "include/getopt.h" is suppressed. The author started to define HAVE_DECL_GETOPT in sim with the commit 340aa4f6872c ("sim: Check known getopt definition existence"). 2. GNU libc (2.25 or earlier)'s includes with a special purpose macro defined to declare only getopt function but due to include path (not tested while configuration), it causes to include Libiberty's "include/getopt.h". 3. If both 1. and 2. are satisfied, despite that tries to declare getopt by including , "include/getopt.h" does not do so, causing getopt function undeclared. Getting rid of "include/getopt.h" (e.g. renaming this header file) is the best solution to avoid hacking but as a short-term solution, this commit replaces getopt with getopt_long under sim/. --- sim/ppc/dgen.c | 6 ++++-- sim/ppc/igen.c | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'sim/ppc') diff --git a/sim/ppc/dgen.c b/sim/ppc/dgen.c index a1c1d56..caafe07 100644 --- a/sim/ppc/dgen.c +++ b/sim/ppc/dgen.c @@ -271,6 +271,7 @@ main(int argc, { lf_file_references file_references = lf_include_references; spreg_table *sprs = NULL; + static const struct option longopts[] = { { 0 } }; char *real_file_name = NULL; int is_header = 0; int ch; @@ -284,8 +285,9 @@ main(int argc, printf("-L Suppress cpp line numbering in output files\n"); } - - while ((ch = getopt(argc, argv, "hLsn:r:p:")) != -1) { + while ((ch = getopt_long (argc, argv, "hLsn:r:p:", longopts, NULL)) + != -1) + { #if 0 /* For debugging. */ fprintf(stderr, "\t-%c %s\n", ch, ( optarg ? optarg : "")); #endif diff --git a/sim/ppc/igen.c b/sim/ppc/igen.c index 27b4863..445afb9 100644 --- a/sim/ppc/igen.c +++ b/sim/ppc/igen.c @@ -351,6 +351,7 @@ main(int argc, filter *filters = NULL; insn_table *instructions = NULL; table_include *includes = NULL; + static const struct option longopts[] = { { 0 } }; char *real_file_name = NULL; int is_header = 0; int ch; @@ -390,9 +391,11 @@ main(int argc, printf(" -f output support functions\n"); } - while ((ch = getopt(argc, argv, - "F:EI:RSLJT:CB:H:N:o:k:i:n:hc:d:m:s:t:f:")) - != -1) { + while ( + (ch = getopt_long (argc, argv, "F:EI:RSLJT:CB:H:N:o:k:i:n:hc:d:m:s:t:f:", + longopts, NULL)) + != -1) + { #if 0 /* For debugging. */ fprintf(stderr, "\t-%c %s\n", ch, (optarg ? optarg : "")); #endif -- cgit v1.1