Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Declare getopt function on older GNU libc #73

Closed
wants to merge 1 commit into from

Conversation

a4lg
Copy link
Owner

@a4lg a4lg commented Oct 13, 2022

@a4lg a4lg force-pushed the include-getopt-fix-on-old-glibc branch 3 times, most recently from 810a22f to 5a0c7bd Compare October 17, 2022 04:35
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).

include/ChangeLog:

	* getopt.h: Detect special include path on GNU libc 2.25 or older
	to prevent not declaring getopt function when necessary.
@a4lg a4lg force-pushed the include-getopt-fix-on-old-glibc branch from 5a0c7bd to 7aeadcb Compare October 18, 2022 08:20
@a4lg a4lg closed this Oct 18, 2022
@a4lg a4lg deleted the include-getopt-fix-on-old-glibc branch October 18, 2022 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant