From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 51B16385040E for ; Thu, 13 Oct 2022 10:11:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 51B16385040E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=irq.a4lg.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=irq.a4lg.com Received: from [127.0.0.1] (localhost [127.0.0.1]) by mail-sender-0.a4lg.com (Postfix) with ESMTPSA id 886DA300089; Thu, 13 Oct 2022 10:11:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=irq.a4lg.com; s=2017s01; t=1665655908; bh=GkJQikCF32h2V9zqWrnMHdc/Gj+3QuL/3Vy7HdcXOiM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Mime-Version:Content-Transfer-Encoding; b=ajpQyznewSMBnPrBTrmttU79UWbdoIGghtUJ4/nVQz/rh9Hj9gWnci8tJ1mKcNovu 2ZwtTo06l3aDEiB+B5OpUvgqi0r2q3F3dCL79PfdwRgfXs5kDIG71hraYkI3jLUiPq wMgeivEIYx0OZee0H+OMH21rjMTg5hcYY+dx6Dow= From: Tsukasa OI To: Tsukasa OI , Tom de Vries , Nick Clifton Cc: binutils@sourceware.org Subject: [PATCH] include: Declare getopt function on old GNU libc Date: Thu, 13 Oct 2022 10:11:41 +0000 Message-Id: <8ab93d7a617ad480dd786210f46db0e5aa07d1ac.1665655719.git.research_trasio@irq.a4lg.com> In-Reply-To: <6e4defd8-b02b-9084-afe6-ba22fe75e3d7@irq.a4lg.com> References: <6e4defd8-b02b-9084-afe6-ba22fe75e3d7@irq.a4lg.com> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,GIT_PATCH_0,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On GNU libc <= 2.25, includes with __need_getopt macro defined. That is intended to be a part of GNU libc but actually includes include/getopt.h in this project. If HAVE_DECL_GETOPT is defined to 1 and include/getopt.h is included from GNU libc's , declaration of getopt is suppressed, causing errors on getopt callers. This issue is possibly hidden so long because there are not so many true getopt callers in Binutils, GDB and GCC. Still, this issue needs to be fixed for following components: - Binutils: gprofng (not currently affected due to the configuration script but will be) - GDB (sim): M32C simulator - GDB (sim): RL78 simulator To avoid not defining proper getopt declaration, we have to check __need_getopt macro to detect this include path. With this commit, even if HAVE_DECL_GETOPT is 1, getopt is declared if: - The standard C library is GNU libc and - __need_getopt macro is defined ( includes to declare getopt function). include/ChangeLog: * getopt.h: Detect special include path on GNU libc 2.25 or older to prevent not declaring getopt function when necessary. --- include/getopt.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/include/getopt.h b/include/getopt.h index d8103f97483..e941b811ace 100644 --- a/include/getopt.h +++ b/include/getopt.h @@ -104,7 +104,14 @@ struct option declaration without arguments. If it is 0, we checked and failed to find the declaration so provide a fully prototyped one. If it is 1, we found it so don't provide any declaration at all. */ -#if !HAVE_DECL_GETOPT +/* On GNU libc <= 2,25, includes with __need_getopt + macro defined. That is intended to be a part of GNU libc + but actually includes THIS getopt.h. If HAVE_DECL_GETOPT is + defined to 1 and this file is included from GNU libc's , + declaration of getopt is suppressed, causing errors on getopt callers. + To avoid not defining proper getopt declaration, we have to check + __need_getopt macro when built with GNU libc to detect this include path. */ +#if !HAVE_DECL_GETOPT || (defined (__GNU_LIBRARY__) && defined (__need_getopt)) #if defined (__GNU_LIBRARY__) || defined (HAVE_DECL_GETOPT) /* Many other libraries have conflicting prototypes for getopt, with differences in the consts, in unistd.h. To avoid compilation base-commit: 927b2f4caf46e5ca49684c9a52a9786425c60fa2 -- 2.34.1