From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7896) id 3A2B43858D32; Sat, 29 Oct 2022 05:42:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3A2B43858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1667022136; bh=hXiI+z9DE40dAsm1cwJHQ+0d8pATxS5QrufLX383Fhw=; h=From:To:Subject:Date:From; b=gshV8gHGsEQjrkYx2DefiY7CNP1oCUlyocDJL1a5qmF/4Z2leMxfN1HXqZt/xwO0B McHvW72OmorBoXLpKcLJ1LtL4AbDx3d83wKnXsymhIzNa2B511atN98VSshNs69yN1 sIud9tTAVXvBaVpoAI0/H+bbos/+1hXx7kwFoKhs= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Tsukasa OI To: gdb-cvs@sourceware.org Subject: [binutils-gdb] sim, sim/{m32c,ppc,rl78}: Use getopt_long X-Act-Checkin: binutils-gdb X-Git-Author: Tsukasa OI X-Git-Refname: refs/heads/master X-Git-Oldrev: bb94ac4f95dd11c87d84eea533fe4f3218a48583 X-Git-Newrev: dd6c5a9217002033149a92bc48999370c451d025 Message-Id: <20221029054216.3A2B43858D32@sourceware.org> Date: Sat, 29 Oct 2022 05:42:15 +0000 (GMT) List-Id: https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3Ddd6c5a921700= 2033149a92bc48999370c451d025 commit dd6c5a9217002033149a92bc48999370c451d025 Author: Tsukasa OI Date: Mon Oct 17 15:47:23 2022 +0000 sim, sim/{m32c,ppc,rl78}: Use getopt_long =20 Because of a Libiberty hack, getopt on GNU libc (2.25 or earlier) is currently unusable on sim, causing a regression on CentOS 7. =20 This is caused as follows: =20 1. If HAVE_DECL_GETOPT is defined (getopt declaration with known proto= type 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 d= ue 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. =20 Getting rid of "include/getopt.h" (e.g. renaming this header file) is t= he 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 =3D NULL; int is_header =3D 0; int ch; + static const struct option longopts[] =3D { { 0 } }; lf *standard_out =3D lf_open ("-", "stdout", lf_omit_references, lf_is_text, "igen"); =20 @@ -1162,8 +1163,9 @@ main (int argc, char **argv, char **envp) printf (" -t output itable\n"); } =20 - while ((ch =3D 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 =3D 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)) !=3D -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 . */ #include #include #include +#include =20 #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 =3D 0; #endif + static const struct option longopts[] =3D { { 0 } }; =20 setbuf (stdout, 0); =20 in_gdb =3D 0; =20 - while ((o =3D getopt (argc, argv, "tc:vdm:C")) !=3D -1) + while ((o =3D getopt_long (argc, argv, "tc:vdm:C", longopts, NULL)) + !=3D -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 =3D lf_include_references; spreg_table *sprs =3D NULL; + static const struct option longopts[] =3D { { 0 } }; char *real_file_name =3D NULL; int is_header =3D 0; int ch; @@ -284,8 +285,9 @@ main(int argc, printf("-L Suppress cpp line numbering in output files\n"); } =20 - - while ((ch =3D getopt(argc, argv, "hLsn:r:p:")) !=3D -1) { + while ((ch =3D getopt_long (argc, argv, "hLsn:r:p:", longopts, NULL)) + !=3D -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 =3D NULL; insn_table *instructions =3D NULL; table_include *includes =3D NULL; + static const struct option longopts[] =3D { { 0 } }; char *real_file_name =3D NULL; int is_header =3D 0; int ch; @@ -390,9 +391,11 @@ main(int argc, printf(" -f output support functions\n"); } =20 - while ((ch =3D getopt(argc, argv, - "F:EI:RSLJT:CB:H:N:o:k:i:n:hc:d:m:s:t:f:")) - !=3D -1) { + while ( + (ch =3D getopt_long (argc, argv, "F:EI:RSLJT:CB:H:N:o:k:i:n:hc:d:m:s= :t:f:", + longopts, NULL)) + !=3D -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[] =3D { { 0 } }; =20 xmalloc_set_program_name (argv[0]); =20 - while ((o =3D getopt (argc, argv, "tvdr:D:M:")) !=3D -1) + while ((o =3D getopt_long (argc, argv, "tvdr:D:M:", longopts, NULL)) + !=3D -1) { switch (o) {