-
Notifications
You must be signed in to change notification settings - Fork 2
include_getopt_fix_on_old_glibc
- Status: Rejected / Withdrawn (because it is too "hacky")
- Branch:
include-getopt-fix-on-old-glibc - Tracking PR: #73 (view Pull Request and Diff)
- Mailing List:
- PATCH v1 (2022-10-13)
My commit 340aa4f6872c (part of Clang: Suppress warnings if built with Clang (sim)) is reported to break CentOS (7) build.
It took a while to figure out but I finally found a cause.
This issue is reproduced by make all-sim with (for example):
--target=m32c-unknown-elf--target=rl78-unknown-elf
The reason I initially could not reproduce issue is because this bug only occurs on GNU libc 2.25 or before.
On GNU libc 2.25 or before, <unistd.h> includes <getopt.h> with __need_getopt macro defined (to declare getopt function).
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_getoptmacro is defined (<unistd.h>includes<getopt.h>to declaregetoptfunction).