[PATCH 0/2] Fix compilation errors

The two patches of this series each fix a compilation error found with buildroot for a RISC-V 64bits NOMMU static-only toolchain. Comments are welcome. Damien Le Moal (2): utils/getconf: Fix compilation error librt: avoid compilation error librt/clock_nanosleep.c | 5 +++-- utils/getconf.c | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) -- 2.26.2

In the main() function, all cases of the "switch (specs[i].num)" switch-case are all conditionally defined. Depending on the target environementi, none of them may endup being defined, resulting in the code block before the no-op default case to generate a "warning: statement will never be executed" compilation error. Avoid this by conditionally defining this code block with the macro DO_GETCONF_NAME which is itself defined if any of the switc cases is defined too. Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> --- utils/getconf.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/utils/getconf.c b/utils/getconf.c index 3dd3d75d9..b8d00f90f 100644 --- a/utils/getconf.c +++ b/utils/getconf.c @@ -1154,7 +1154,6 @@ environment SPEC.\n\n"); const char *spec = NULL; char buf[sizeof "POSIX_V6_LPBIG_OFFBIG"]; - char *argv0 = argv[0]; if (argc > 1 && strncmp (argv[1], "-v", 2) == 0) { if (argv[1][2] == '\0') @@ -1199,42 +1198,56 @@ environment SPEC.\n\n"); switch (specs[i].num) { +#undef DO_GETCONF_NAME #if !defined(_XBS5_ILP32_OFF32) && defined(_SC_XBS5_ILP32_OFF32) +#define DO_GETCONF_NAME case _SC_XBS5_ILP32_OFF32: #endif #if !defined(_XBS5_ILP32_OFFBIG) && defined(_SC_XBS5_ILP32_OFFBIG) +#define DO_GETCONF_NAME case _SC_XBS5_ILP32_OFFBIG: #endif #if !defined(_XBS5_LP64_OFF64) && defined(_SC_XBS5_LP64_OFF64) +#define DO_GETCONF_NAME case _SC_XBS5_LP64_OFF64: #endif #if !defined(_XBS5_LPBIG_OFFBIG) && defined(_SC_XBS5_LPBIG_OFFBIG) +#define DO_GETCONF_NAME case _SC_XBS5_LPBIG_OFFBIG: #endif #if !defined(_POSIX_V6_ILP32_OFF32) && defined(_SC_V6_ILP32_OFF32) +#define DO_GETCONF_NAME case _SC_V6_ILP32_OFF32: #endif #if !defined(_POSIX_V6_ILP32_OFFBIG) && defined(_SC_V6_ILP32_OFFBIG) +#define DO_GETCONF_NAME case _SC_V6_ILP32_OFFBIG: #endif #if !defined(_POSIX_V6_LP64_OFF64) && defined(_SC_V6_LP64_OFF64) +#define DO_GETCONF_NAME case _SC_V6_LP64_OFF64: #endif #if !defined(_POSIX_V6_LPBIG_OFFBIG) && defined(_SC_V6_LPBIG_OFFBIG) +#define DO_GETCONF_NAME case _SC_V6_LPBIG_OFFBIG: #endif #if !defined(_POSIX_V7_ILP32_OFF32) && defined(_SC_V7_ILP32_OFF32) +#define DO_GETCONF_NAME case _SC_V7_ILP32_OFF32: #endif #if !defined(_POSIX_V7_ILP32_OFFBIG) && defined(_SC_V7_ILP32_OFFBIG) +#define DO_GETCONF_NAME case _SC_V7_ILP32_OFFBIG: #endif #if !defined(_POSIX_V7_LP64_OFF64) && defined(_SC_V7_LP64_OFF64) +#define DO_GETCONF_NAME case _SC_V7_LP64_OFF64: #endif #if !defined(_POSIX_V7_LPBIG_OFFBIG) && defined(_SC_V7_LPBIG_OFFBIG) +#define DO_GETCONF_NAME case _SC_V7_LPBIG_OFFBIG: #endif +#ifdef DO_GETCONF_NAME { const char *args[argc + 3]; size_t spec_len = strlen (spec); @@ -1242,14 +1255,15 @@ environment SPEC.\n\n"); memcpy (mempcpy (mempcpy (getconf_name, getconf_dir, getconf_dirlen), "/", 1), spec, spec_len + 1); - args[0] = argv0; + args[0] = argv[0]; args[1] = "-v"; args[2] = spec; memcpy (&args[3], &argv[1], argc * sizeof (argv[1])); execv (getconf_name, (char * const *) args); error (4, errno, _("Couldn't execute %s"), getconf_name); } - default: +#endif + default: break; } } -- 2.26.2

For NOMMU builds, LIBC_CANCEL_ASYNC and LIBC_CANCEL_RESET are not defined. Prevent these macros from being visible by the compiler in clock_nanosleep() by replacing "if (SINGLE_THREAD_P) {" with the pre-compiler directive "#if defined(SINGLE_THREAD_P)". Signed-off-by: Damien Le Moal <damien.lemoal@wdc.com> --- librt/clock_nanosleep.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/librt/clock_nanosleep.c b/librt/clock_nanosleep.c index 4cf1e06b4..1515cf5b0 100644 --- a/librt/clock_nanosleep.c +++ b/librt/clock_nanosleep.c @@ -36,9 +36,9 @@ clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req, if (clock_id == CLOCK_PROCESS_CPUTIME_ID) clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED); - if (SINGLE_THREAD_P) +#if defined(SINGLE_THREAD_P) r = INTERNAL_SYSCALL (clock_nanosleep, err, 4, clock_id, flags, req, rem); - else +#else { int oldstate = LIBC_CANCEL_ASYNC (); @@ -47,6 +47,7 @@ clock_nanosleep (clockid_t clock_id, int flags, const struct timespec *req, LIBC_CANCEL_RESET (oldstate); } +#endif return (INTERNAL_SYSCALL_ERROR_P (r, err) ? INTERNAL_SYSCALL_ERRNO (r, err) : 0); -- 2.26.2

Hi Damien, thanks for the patches, both applied and pushed, best regards Waldemar Damien Le Moal wrote,
The two patches of this series each fix a compilation error found with buildroot for a RISC-V 64bits NOMMU static-only toolchain.
Comments are welcome.
Damien Le Moal (2): utils/getconf: Fix compilation error librt: avoid compilation error
librt/clock_nanosleep.c | 5 +++-- utils/getconf.c | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 5 deletions(-)
-- 2.26.2
participants (2)
-
Damien Le Moal
-
Waldemar Brodkorb