From d13adebe1ab7c6c7f6c7d2633851a2f47a596556 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 24 Dec 2020 09:34:13 +0000 Subject: [PATCH] uxutils.c: move some definitions into a header file. If the autoconf/ifdef system ends up taking the trivial branch through all the Arm-architecture ifdefs, then we define the always-fail version of getauxval as a 'static inline' function, and then (because none of our desired HWCAP_FOO values is defined at all) never call it. This leads to a compiler warning because we defined a static function and never called it - i.e. at the default -Werror, a build failure. Of course it's perfectly sensible to define a static inline function that never gets called! Header files do it all the time, and nobody is expected to ensure that if they include a header file then they take care to refer to every static inline function it defines. But if the definition is in the _source_ file rather than a header file, then clang (in particular on macOS) will give a warning. So the easy solution is to move the inline definitions of getauxval into a header file, which suppresses the warning without requiring me to faff about with further ifdefs to make the definitions conditional on at least one use. --- unix/uxutils.c | 30 ++---------------------------- unix/uxutils.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 unix/uxutils.h diff --git a/unix/uxutils.c b/unix/uxutils.c index 467e5bcc..4a63ac86 100644 --- a/unix/uxutils.c +++ b/unix/uxutils.c @@ -1,36 +1,10 @@ #include "putty.h" #include "ssh.h" +#include "uxutils.h" + #if defined __arm__ || defined __aarch64__ -#ifdef HAVE_SYS_TYPES_H -#include -#endif - -#ifdef HAVE_SYS_AUXV_H -#include -#endif - -#ifdef HAVE_ASM_HWCAP_H -#include -#endif - -#if defined HAVE_GETAUXVAL -/* No code needed: getauxval has just the API we want already */ -#elif defined HAVE_ELF_AUX_INFO -/* Implement the simple getauxval API in terms of FreeBSD elf_aux_info */ -static inline u_long getauxval(int which) -{ - u_long toret; - if (elf_aux_info(which, &toret, sizeof(toret)) != 0) - return 0; /* elf_aux_info didn't work */ - return toret; -} -#else -/* Implement a stub getauxval which returns no capabilities */ -static inline u_long getauxval(int which) { return 0; } -#endif - bool platform_aes_hw_available(void) { #if defined HWCAP_AES diff --git a/unix/uxutils.h b/unix/uxutils.h new file mode 100644 index 00000000..4e8dc808 --- /dev/null +++ b/unix/uxutils.h @@ -0,0 +1,45 @@ +/* + * uxutils.h: header included only by uxutils.c. + * + * The only reason this is a header file instead of a source file is + * so that I can define 'static inline' functions which may or may not + * be used, without provoking a compiler warning when I turn out not + * to use them in the subsequent source file. + */ + +#ifndef PUTTY_UXUTILS_H +#define PUTTY_UXUTILS_H + +#if defined __arm__ || defined __aarch64__ + +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#ifdef HAVE_SYS_AUXV_H +#include +#endif + +#ifdef HAVE_ASM_HWCAP_H +#include +#endif + +#if defined HAVE_GETAUXVAL +/* No code needed: getauxval has just the API we want already */ +#elif defined HAVE_ELF_AUX_INFO +/* Implement the simple getauxval API in terms of FreeBSD elf_aux_info */ +static inline u_long getauxval(int which) +{ + u_long toret; + if (elf_aux_info(which, &toret, sizeof(toret)) != 0) + return 0; /* elf_aux_info didn't work */ + return toret; +} +#else +/* Implement a stub getauxval which returns no capabilities */ +static inline u_long getauxval(int which) { return 0; } +#endif + +#endif /* defined __arm__ || defined __aarch64__ */ + +#endif /* PUTTY_UXUTILS_H */