public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: Tsukasa OI <research_trasio@irq.a4lg.com>,
	Nick Clifton <nickc@redhat.com>
Cc: binutils@sourceware.org, Mark Wielaard <mark@klomp.org>
Subject: Re: [PATCH] include: Declare getopt function on old GNU libc
Date: Thu, 13 Oct 2022 14:05:28 +0200	[thread overview]
Message-ID: <f68f3d33-8370-f051-baa9-8a6643ede838@suse.de> (raw)
In-Reply-To: <8ab93d7a617ad480dd786210f46db0e5aa07d1ac.1665655719.git.research_trasio@irq.a4lg.com>

On 10/13/22 12:11, Tsukasa OI wrote:
> On GNU libc <= 2.25, <unistd.h> includes <getopt.h> with __need_getopt macro
> defined.  That <getopt.h> is intended to be a part of GNU libc but
> <unistd.h> 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 <unistd.h>, 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 (<unistd.h> includes <getopt.h> to
>      declare getopt function).
> 

I've put this into the gdb try-buildbot, and it fixes the centos 
regression : 
https://builder.sourceware.org/buildbot/#/builders/118/builds/17 .

I didn't get emails to that effect for some reason, but visual 
inspection at https://builder.sourceware.org/ of the try build bots at 
gdb shows all green.

Thanks,
- Tom

> 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, <unistd.h> includes <getopt.h> with __need_getopt
> +   macro defined.  That <getopt.h> is intended to be a part of GNU libc
> +   but <unistd.h> actually includes THIS getopt.h.  If HAVE_DECL_GETOPT is
> +   defined to 1 and this file is included from GNU libc's <unistd.h>,
> +   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

      parent reply	other threads:[~2022-10-13 12:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1664095312.git.research_trasio@irq.a4lg.com>
     [not found] ` <cover.1665038297.git.research_trasio@irq.a4lg.com>
     [not found]   ` <a57b2a3460064a9adc95914ba21214c8dbfc2bbf.1665038297.git.research_trasio@irq.a4lg.com>
     [not found]     ` <7b235ccb-ab2e-cba0-3015-2eae5fe6a8a4@suse.de>
2022-10-13  9:50       ` [PATCH v3 4/5] sim: Check known getopt definition existence Tsukasa OI
2022-10-13 10:11         ` [PATCH] include: Declare getopt function on old GNU libc Tsukasa OI
2022-10-13 11:59           ` Pedro Alves
2022-10-16 13:12             ` Tsukasa OI
2022-10-17 11:52               ` Pedro Alves
2022-10-18 11:33                 ` Tsukasa OI
2022-10-13 12:05           ` Tom de Vries [this message]

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=f68f3d33-8370-f051-baa9-8a6643ede838@suse.de \
    --to=tdevries@suse.de \
    --cc=binutils@sourceware.org \
    --cc=mark@klomp.org \
    --cc=nickc@redhat.com \
    --cc=research_trasio@irq.a4lg.com \
    /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).