From patchwork Thu Oct 13 10:11:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tsukasa OI X-Patchwork-Id: 2013 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp187700wrs; Thu, 13 Oct 2022 03:11:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6YEcGSzHVfTGrz1qohhbYSRFgP6hbewlRteBUyawdM1w3QaAqw/wxLMLb1HcFNTFsNh95w X-Received: by 2002:a05:6402:1910:b0:458:8b32:4752 with SMTP id e16-20020a056402191000b004588b324752mr31215448edz.302.1665655919265; Thu, 13 Oct 2022 03:11:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665655919; cv=none; d=google.com; s=arc-20160816; b=H7mqLh9C6GZ1lPvH8DQXCRfyI7pp9kEF21jMoCS6X+J0tPxtEA0Q/MEIE7nKvzMmWK VnL/ChCfPUE8a9WDZ7EtQ1b2fFoUzgwbnlOY2KOGBdgOP/ZaR1PtqPBaDWcVc4q/BOGY RIiVPb6Erv9w0IKh8d9w1/kjU5UgqtCEqNCqjUI6FWOrvU/m0mT3XKCxt/mhSLHb6Iax E/BB1l9HqzA4SPbEaBquc33KGtGlbuLvgxKAUiwPun+lV2MMvZiAJSwX4JBapMu3mG5N hUzq7p9k/L1z+eGdKZOx8p03E/mvVR1NSL1DuEVVO15FwNPUZ6/VDp7KOSbKVIRBdT9I xC2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=GkJQikCF32h2V9zqWrnMHdc/Gj+3QuL/3Vy7HdcXOiM=; b=CmhKhv1qmO8+yUrWlIBtaHef7uFDeJTHgcq2/fHsTwHasmyPoobOn4AE9tJ6GG0S91 KOdeExSykVEPDfTI/dMR5CN88miI0Gw8G22LGASukcW6cBnIo5U6L1y7MI5JGCwaAELk nxetRCzeCKh5qb/2gJf9qw6lMdtTXFagLELRM8ibplsjpKRpXqgbfwxou9fgjROGKL0T 0FM0rlAC8qWBW8O/cVh7VYdfRpEZ+o6Jyyqj1z7Y18/WXDtc2NOgnWSei7MhNLWnk6hv 7UXuDjdbDPzf3+YNGjkBmtr/zR3eaowGOzlMkZ7aH6Iw7lOalcDgV0LjPR1nTtvoUEEK 1onA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=plHSsG5q; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e14-20020a17090658ce00b0078dc5e684cbsi10877041ejs.462.2022.10.13.03.11.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 03:11:59 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=plHSsG5q; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 565E6382E290 for ; Thu, 13 Oct 2022 10:11:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 565E6382E290 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1665655918; bh=GkJQikCF32h2V9zqWrnMHdc/Gj+3QuL/3Vy7HdcXOiM=; 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=plHSsG5qzi3poFx4fsPp6dWYnnWoeONJWyCsf+B/vH29OYYqCNDA0Uv5m5GxHnbJJ LZQTuJt/Ts0ZrPDbtnun81IuXM/nYvwwuGJVu/PcOYhExDy6ZyB43qScRhs2KrEy9J KcKtXXP1cfloLxAMClwpjbLZYFyoDqbDKVnXspBc= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org 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 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) To: Tsukasa OI , Tom de Vries , Nick Clifton 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 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tsukasa OI via Binutils From: Tsukasa OI Reply-To: Tsukasa OI Cc: binutils@sourceware.org Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746566821387775937?= X-GMAIL-MSGID: =?utf-8?q?1746566821387775937?= 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(-) base-commit: 927b2f4caf46e5ca49684c9a52a9786425c60fa2 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