From: bert hubert Date: Wed, 2 Dec 2015 07:09:49 +0000 (+0100) Subject: fix up incbin, with the great help of Dale Weiler. Closes #2957. dnsdist works on... X-Git-Tag: dnsdist-1.0.0-alpha1~147 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b64de5fa85c3c8e6a3214703f7f3a8275d5a20b2;p=pdns fix up incbin, with the great help of Dale Weiler. Closes #2957. dnsdist works on our raspberries again! --- diff --git a/ext/incbin/incbin.h b/ext/incbin/incbin.h index dfc9d1ce5..7d600f1bd 100644 --- a/ext/incbin/incbin.h +++ b/ext/incbin/incbin.h @@ -12,6 +12,8 @@ #if defined(__SSE__) || defined(__neon__) # define INCBIN_ALIGNMENT 16 +#elif defined(__AVX__) +# define INCBIN_ALIGNMENT 32 #else # if ULONG_MAX == 0xffffffffu # define INCBIN_ALIGNMENT 4 @@ -20,12 +22,19 @@ # endif #endif -#define INCBIN_ALIGN __attribute__((aligned(INCBIN_ALIGNMENT))) +#ifndef _MSC_VER +# define INCBIN_ALIGN __attribute__((aligned(INCBIN_ALIGNMENT))) +#else +# define INCBIN_ALIGN __declspec(align(INCBIN_ALIGNMENT)) +#endif +/* INCBIN_CONST is used by incbin.c generated files */ #ifdef __cplusplus # define INCBIN_EXTERNAL extern "C" +# define INCBIN_CONST extern const #else # define INCBIN_EXTERNAL extern +# define INCBIN_CONST const #endif #ifdef __APPLE__ @@ -39,7 +48,17 @@ # define INCBIN_GLOBAL(NAME) ".global " #NAME "\n" # define INCBIN_INT ".int " # define INCBIN_MANGLE -# define INCBIN_TYPE(NAME) ".type " #NAME ", @object\n" +#if defined(__arm__) || /* GNU C & RealView */ defined(__arm) /* Diab (WindRiver) */ +# define INCBIN_TYPE(NAME) ".type " #NAME ", %object\n" +#else +# define INCBIN_TYPE(NAME) ".type " #NAME ", @object\n" +#endif +#endif + +#ifdef __ghs__ +# define INCBIN_MACRO "\tINCBIN" +#else +# define INCBIN_MACRO ".incbin" #endif #define INCBIN_STR(X) #X @@ -48,11 +67,11 @@ /** * @brief Externally reference binary data included in another translation unit. * - * Produces two external symbols that reference the binary data included in + * Produces three external symbols that reference the binary data included in * another translation unit. * * The symbol names are a concatenation of "g" before *NAME*; with "Data", as well - * as "Size" after. An example is provided below. + * as "End" and "Size" after. An example is provided below. * * @param NAME The name given for the binary data * @@ -60,24 +79,24 @@ * INCBIN_EXTERN(Foo); * * // Now you have the following symbols: - * // extern unsigned char gFooData[]; - * // extern const unsigned char gFooEnd; - * // extern unsigned int gFooSize; + * // extern const unsigned char gFooData[]; + * // extern const unsigned char *gFooEnd; + * // extern const unsigned int gFooSize; * @endcode */ #define INCBIN_EXTERN(NAME) \ INCBIN_EXTERNAL const INCBIN_ALIGN unsigned char g ## NAME ## Data[]; \ - INCBIN_EXTERNAL const INCBIN_ALIGN unsigned char g ## NAME ## End; \ + INCBIN_EXTERNAL const INCBIN_ALIGN unsigned char *g ## NAME ## End; \ INCBIN_EXTERNAL const unsigned int g ## NAME ## Size /** * @brief Include a binary file into the current translation unit. * - * Includes a binary file into the current translation unit, producing two symbols + * Includes a binary file into the current translation unit, producing three symbols * for objects that encode the data and size respectively. * * The symbol names are a concatenation of "g" before *NAME*; with "Data", as well - * as "Size" after. An example is provided below. + * as "End" and "Size" after. An example is provided below. * * @param NAME The name to associate with this binary data (as an identifier.) * @param FILENAME The file to include (as a string literal.) @@ -86,8 +105,9 @@ * INCBIN(Icon, "icon.png"); * * // Now you have the following symbols: - * // unsigned char gIconData[]; - * // unsigned int gIconSize; + * // const unsigned char gIconData[]; + * // const unsigned char *gIconEnd; + * // const unsigned int gIconSize; * @endcode * * @warning This must be used in global scope @@ -95,13 +115,17 @@ * To externally reference the data included by this in another translation unit * please @see INCBIN_EXTERN. */ +#ifdef _MSC_VER +#define INCBIN(NAME, FILENAME) \ + INCBIN_EXTERN(NAME) +#else #define INCBIN(NAME, FILENAME) \ __asm__(INCBIN_SECTION \ INCBIN_GLOBAL(g ## NAME ## Data) \ INCBIN_TYPE(g ## NAME ## Data) \ ".align " INCBIN_STRINGIZE(INCBIN_ALIGNMENT) "\n" \ INCBIN_MANGLE "g" #NAME "Data:\n" \ - ".incbin \"" FILENAME "\"\n" \ + INCBIN_MACRO " \"" FILENAME "\"\n" \ INCBIN_GLOBAL(g ## NAME ## End) \ INCBIN_TYPE(g ## NAME ## End) \ ".align 1\n" \ @@ -116,3 +140,4 @@ INCBIN_EXTERN(NAME) #endif +#endif