From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id U9aACu2BV2MAaBAAWB0awg (envelope-from ) for ; Tue, 25 Oct 2022 02:27:57 -0400 Received: by simark.ca (Postfix, from userid 112) id 19C4D1E112; Tue, 25 Oct 2022 02:27:57 -0400 (EDT) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=C9GRxxcC; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id A00B81E0D5 for ; Tue, 25 Oct 2022 02:27:56 -0400 (EDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6D979385803F for ; Tue, 25 Oct 2022 06:27:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6D979385803F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1666679273; bh=UT+bptGZhGOxuWmfbYTxodV7hHlMMokzq/tHcazIGWw=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=C9GRxxcC/uE2Zmt43hc8YoGtOmTWgLt0omCL6SiwXUqxl6BFa6wiMyBOsoZZVGUzz 7WCsGXP926JwrfQ6U3UdWmZR4iVH7SBgaYfq6VxN5xLqFuWK2f4s+PnCHZzPXPbyMc OceY7Dm2Pw+pzEiXgQTzsG/FdS6G/Fh4Yj0qZNsw= Received: from mail-sender-0.a4lg.com (mail-sender-0.a4lg.com [IPv6:2401:2500:203:30b:4000:6bfe:4757:0]) by sourceware.org (Postfix) with ESMTPS id 14A713858401 for ; Tue, 25 Oct 2022 06:27:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 14A713858401 Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id BA2A4300089; Tue, 25 Oct 2022 06:27:24 +0000 (UTC) To: Tsukasa OI , Tom de Vries , Andrew Burgess , Mike Frysinger , Pedro Alves Subject: [PATCH v2] sim, sim/{m32c,ppc,rl78}: Use getopt_long Date: Tue, 25 Oct 2022 06:27:22 +0000 Message-Id: <7ad71357e72129e5dc642a5233868b3aa81c484c.1666679042.git.research_trasio@irq.a4lg.com> In-Reply-To: <24e83e920d728237c4efe6f4720643d6fbbf1084.1666113214.git.research_trasio@irq.a4lg.com> References: <24e83e920d728237c4efe6f4720643d6fbbf1084.1666113214.git.research_trasio@irq.a4lg.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Tsukasa OI via Gdb-patches Reply-To: Tsukasa OI Cc: gdb-patches@sourceware.org Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" Because of Binutils/GCC 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 with known prototype is declared), 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 to declare getopt function (only, not getopt_long or getopt_long_only) but it causes to include Binutils/GCC'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 define one, causing getopt function unusable. 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/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..22cfd30ec43 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; + struct option dummy_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 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", + &dummy_longopts, NULL)) != -1) { #if 0 /* For debugging. */ diff --git a/sim/m32c/main.c b/sim/m32c/main.c index 958ca27ab2b..5560adea60a 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 #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 + struct option dummy_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", &dummy_longopts, NULL)) + != -1) switch (o) { case 't': diff --git a/sim/ppc/dgen.c b/sim/ppc/dgen.c index a1c1d56e8dc..da0b6446cfa 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; + struct option dummy_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:", &dummy_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..35d222df34b 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; + struct option dummy_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:", + &dummy_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..436f370a338 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; + struct option dummy_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:", &dummy_longopts, NULL)) + != -1) { switch (o) { base-commit: a5a0a4fd0ff536a8dbd532864cfc095a306b678c -- 2.37.2