public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Tsukasa OI <a4lg@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] sim, sim/{m32c,ppc,rl78}: Use getopt_long
Date: Sat, 29 Oct 2022 05:42:15 +0000 (GMT)	[thread overview]
Message-ID: <20221029054216.3A2B43858D32@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=dd6c5a9217002033149a92bc48999370c451d025

commit dd6c5a9217002033149a92bc48999370c451d025
Author: Tsukasa OI <research_trasio@irq.a4lg.com>
Date:   Mon Oct 17 15:47:23 2022 +0000

    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 <unistd.h> includes <getopt.h> with a
        special purpose macro defined to declare only getopt function but due
        to include path (not tested while configuration), it causes <unistd.h>
        to include Libiberty's "include/getopt.h".
    3.  If both 1. and 2. are satisfied, despite that <unistd.h> tries to
        declare getopt by including <getopt.h>, "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/.

Diff:
---
 sim/igen/igen.c | 6 ++++--
 sim/m32c/main.c | 5 ++++-
 sim/ppc/dgen.c  | 6 ++++--
 sim/ppc/igen.c  | 9 ++++++---
 sim/rl78/main.c | 4 +++-
 5 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/sim/igen/igen.c b/sim/igen/igen.c
index ba856401fa9..b0a07743c24 100644
--- a/sim/igen/igen.c
+++ b/sim/igen/igen.c
@@ -989,6 +989,7 @@ main (int argc, char **argv, char **envp)
   char *real_file_name = NULL;
   int is_header = 0;
   int ch;
+  static const struct option longopts[] = { { 0 } };
   lf *standard_out =
     lf_open ("-", "stdout", lf_omit_references, lf_is_text, "igen");
 
@@ -1162,8 +1163,9 @@ main (int argc, char **argv, char **envp)
       printf ("  -t <output-file>      output itable\n");
     }
 
-  while ((ch = getopt (argc, argv,
-		       "B:D:F:G:H:I:M:N:P:T:W:o:k:i:n:hc:d:e:m:r:s:t:f:x"))
+  while ((ch = getopt_long (argc, argv,
+			    "B:D:F:G:H:I:M:N:P:T:W:o:k:i:n:hc:d:e:m:r:s:t:f:x",
+			    longopts, NULL))
 	 != -1)
     {
 #if 0  /* For debugging.  */
diff --git a/sim/m32c/main.c b/sim/m32c/main.c
index 958ca27ab2b..5ed912ae7bc 100644
--- a/sim/m32c/main.c
+++ b/sim/m32c/main.c
@@ -29,6 +29,7 @@ along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <setjmp.h>
 #include <signal.h>
 #include <sys/types.h>
+#include <getopt.h>
 
 #ifdef HAVE_SYS_SOCKET_H
 #ifdef HAVE_NETINET_IN_H
@@ -135,12 +136,14 @@ main (int argc, char **argv)
 #ifdef HAVE_networking
   char *console_port_s = 0;
 #endif
+  static const struct option longopts[] = { { 0 } };
 
   setbuf (stdout, 0);
 
   in_gdb = 0;
 
-  while ((o = getopt (argc, argv, "tc:vdm:C")) != -1)
+  while ((o = getopt_long (argc, argv, "tc:vdm:C", longopts, NULL))
+	 != -1)
     switch (o)
       {
       case 't':
diff --git a/sim/ppc/dgen.c b/sim/ppc/dgen.c
index a1c1d56e8dc..caafe07a6aa 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 27b48638276..445afb9ee00 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-file>      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
diff --git a/sim/rl78/main.c b/sim/rl78/main.c
index c9459c7bc78..ea6ddaaa6c3 100644
--- a/sim/rl78/main.c
+++ b/sim/rl78/main.c
@@ -64,10 +64,12 @@ main (int argc, char **argv)
   int save_trace;
   bfd *prog;
   int rc;
+  static const struct option longopts[] = { { 0 } };
 
   xmalloc_set_program_name (argv[0]);
 
-  while ((o = getopt (argc, argv, "tvdr:D:M:")) != -1)
+  while ((o = getopt_long (argc, argv, "tvdr:D:M:", longopts, NULL))
+	 != -1)
     {
       switch (o)
 	{

                 reply	other threads:[~2022-10-29  5:42 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221029054216.3A2B43858D32@sourceware.org \
    --to=a4lg@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).