From 683f205402a99cfc8cea46c83ce9b46a42616d42 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sat, 16 Dec 2023 12:40:10 +0100 Subject: All kinds of stuff MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- common.h | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 108 insertions(+), 3 deletions(-) (limited to 'common.h') diff --git a/common.h b/common.h index b9b7174..446f438 100644 --- a/common.h +++ b/common.h @@ -1,23 +1,68 @@ /* See LICENSE file for copyright and license details. */ #ifdef REQUIRE_FLEXABLE_OR_NPARAMS -# if defined(__clang__) || defined(__GNUC__) +# if defined(__clang__) # define LIBSYSCALLS_FLEXABLE_OR_NPARAMS_ +# pragma clang diagnostic ignored "-Wgnu-flexible-array-initializer" +# elif defined(__GNUC__) +# define LIBSYSCALLS_FLEXABLE_OR_NPARAMS_ +# pragma GCC diagnostic ignored "-Wpedantic" # else # define LIBSYSCALLS_FLEXABLE_OR_NPARAMS_ NPARAMS # warning Setting LIBSYSCALLS_FLEXABLE_OR_NPARAMS_ to NPARAMS as it is not known that the compiler supports static allocation of structs with flexible arrays # endif #endif +#ifdef REQUIRE_FLEXABLE_OR_NFIELDS +# if defined(__clang__) +# define LIBSYSCALLS_FLEXABLE_OR_NFIELDS_ +# pragma clang diagnostic ignored "-Wgnu-flexible-array-initializer" +# elif defined(__GNUC__) +# define LIBSYSCALLS_FLEXABLE_OR_NFIELDS_ +# pragma GCC diagnostic ignored "-Wpedantic" +# else +# define LIBSYSCALLS_FLEXABLE_OR_NFIELDS_ NFIELDS +# warning Setting LIBSYSCALLS_FLEXABLE_OR_NFIELDS_ to NFIELDS as it is not known that the compiler supports static allocation of structs with flexible arrays +# endif +#endif #include "libsyscalls.h" +#include #include #include +#include +#include +#include + + +#if defined(__clang__) +/* We expect the user to use -Weverything */ +# pragma clang diagnostic ignored "-Wimplicit-fallthrough" /* we use GCC's fall though comments */ +# pragma clang diagnostic ignored "-Wcovered-switch-default" /* the user may input something invalid due to version differences */ +# pragma clang diagnostic ignored "-Wc++98-compat" /* don't care about C++, especially not for internal code */ +# pragma clang diagnostic ignored "-Wgnu-zero-variadic-macro-arguments" /* TODO how does that make sense in C23? */ +# pragma clang diagnostic ignored "-Wunsafe-buffer-usage" /* clang doesn't know what it is doing */ +# pragma clang diagnostic ignored "-Wvla" /* we prefer VLA over alloca (easier to support), and we are careful */ +#elif defined(__GNUC__) +/* We expect the user to use -Wall -Wextra mand maybe some other flags */ +# pragma GCC diagnostic ignored "-Wnonnull-compare" /* why should I trust that the user is using the same compiler? */ +# pragma GCC diagnostic ignored "-Winline" /* it's just a preference, up to the compiler to decide */ +#endif -#define COMMA , + +#if defined(__GNUC__) +# define PURE_FUNCTION __attribute__((__pure__)) +#else +# define PURE_FUNCTION +#endif +#define COMMA , + #define MISALIGNMENT(ADDR, ALIGN) (((ADDR) - ((ADDR) % (uintptr_t)(ALIGN))) % (uintptr_t)(ALIGN)) #define ALIGN_BUF(BUF, ALIGN) (&(BUF)[(size_t)MISALIGNMENT((uintptr_t)(char *)(BUF), (ALIGN))]) #define ELEMSOF(ARR) (sizeof(ARR) / sizeof *(ARR)) +#define MAX(A, B) ((A) > (B) ? (A) : (B)) +#define LOWEST_BIT(X) ((X) & ~((X) - 1)) +#define POST_HIGHEST_OF_CONSECUTIVELY_BITS(X) ((X) + LOWEST_BIT(X)) struct libsyscalls_symbol_printer_data { @@ -26,6 +71,61 @@ struct libsyscalls_symbol_printer_data { char buf[]; }; +enum endian { + Big, + Little +}; + + +#define LIST_ARCH_SPECS(X, D) /* byte intptr size_t endian sign */\ + X(LIBSYSCALLS_ARCH_ALPHA_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_ALPHA_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_AMD64, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_AMD64_X32, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ + /* + X(LIBSYSCALLS_ARCH_ARM_OABI_LE, 8, TODO, TODO, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_ARM_OABI_BE, 8, TODO, TODO, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_ARM_EABI_LE, 8, TODO, TODO, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_ARM_EABI_BE, 8, TODO, TODO, Big, TWOS_COMPLEMENT) D\ + */\ + X(LIBSYSCALLS_ARCH_IA64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_IA64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_IA64_P32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_IA64_P32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_M68K, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MICROBLAZE_32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MICROBLAZE_32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MICROBLAZE_64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MICROBLAZE_64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MIPS_O32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MIPS_O32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MIPS_N32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MIPS_N32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MIPS_N64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_MIPS_N64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_PARISC_32, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_PARISC_64, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_32_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_32_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_NOSPU_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_NOSPU_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_SPU_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_POWERPC_SPU_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_S390_32, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_S390_64, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_SH_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_SH_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_SPARC_32, 8, 32, 32, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_SPARC_64_LE, 8, 64, 64, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_SPARC_64_BE, 8, 64, 64, Big, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_I386, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_XTENSA_LE, 8, 32, 32, Little, TWOS_COMPLEMENT) D\ + X(LIBSYSCALLS_ARCH_XTENSA_BE, 8, 32, 32, Big, TWOS_COMPLEMENT) + /* Don't forget to update SUPPORTED_ARCHES in Makefile */ + /* TODO (alignment) means that it is missing in libsyscalls_get_integer_alignment.c and must also be added thither */ + #include "generated/oses.h" #include "generated/arches.h" @@ -47,9 +147,14 @@ LIST_OSES(X,) #endif +#define COUNT_LIST_(...) 1 +#define COUNT_LIST(LIST_MACRO) (LIST_MACRO(COUNT_LIST_,, +,)) + +#define COUNT_ARGS(...) (0 __VA_OPT__(+ COUNT_ARGS_1(__VA_ARGS__))) #define COUNT_ARG_PAIRS(...) (0 __VA_OPT__(+ COUNT_ARG_PAIRS_1(__VA_ARGS__))) -/* mk/generate.mk reads these two lines, do not format them as multiline macros! */ +/* mk/generate.mk reads these three lines, do not format them as multiline macros! */ +#define COUNT_ARGS_1(x, ...) 1 __VA_OPT__(+ COUNT_ARGS_2(__VA_ARGS__)) #define COUNT_ARG_PAIRS_1(x1, x2, ...) 1 __VA_OPT__(+ COUNT_ARG_PAIRS_2(__VA_ARGS__)) #define PARAMS_BUILD_TYPES_1(x, A, ...) LIBSYSCALLS_TYPE_##A __VA_OPT__(, PARAMS_BUILD_TYPES_2(__VA_ARGS__)) -- cgit v1.2.3-70-g09d2