Protect C language extensions with two leading and trailing underscores

This should make their usage safer against user macros.
This commit is contained in:
Guillem Jover 2018-06-18 00:36:44 +02:00
parent c2d9d84088
commit 574c7a1365
6 changed files with 15 additions and 12 deletions

View File

@ -87,7 +87,7 @@ AC_CACHE_CHECK(
[[ [[
static int rc = 1; static int rc = 1;
static void init(int argc) { if (argc == 1) rc = 0; } static void init(int argc) { if (argc == 1) rc = 0; }
void (*init_func)(int argc) __attribute__((section(".init_array"))) = init; void (*init_func)(int argc) __attribute__((__section__(".init_array"))) = init;
int main() { return rc; } int main() { return rc; }
]] ]]
)], )],

View File

@ -86,9 +86,9 @@
#endif #endif
#if LIBBSD_GCC_VERSION >= 0x0405 #if LIBBSD_GCC_VERSION >= 0x0405
#define LIBBSD_DEPRECATED(x) __attribute__((deprecated(x))) #define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__(x)))
#elif LIBBSD_GCC_VERSION >= 0x0301 #elif LIBBSD_GCC_VERSION >= 0x0301
#define LIBBSD_DEPRECATED(x) __attribute__((deprecated)) #define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__))
#else #else
#define LIBBSD_DEPRECATED(x) #define LIBBSD_DEPRECATED(x)
#endif #endif
@ -137,7 +137,7 @@
#if 0 #if 0
#ifndef __unused #ifndef __unused
# if LIBBSD_GCC_VERSION >= 0x0300 # if LIBBSD_GCC_VERSION >= 0x0300
# define __unused __attribute__((unused)) # define __unused __attribute__((__unused__))
# else # else
# define __unused # define __unused
# endif # endif
@ -146,7 +146,7 @@
#ifndef __printflike #ifndef __printflike
# if LIBBSD_GCC_VERSION >= 0x0300 # if LIBBSD_GCC_VERSION >= 0x0300
# define __printflike(x, y) __attribute((format(printf, (x), (y)))) # define __printflike(x, y) __attribute((__format__(__printf__, (x), (y))))
# else # else
# define __printflike(x, y) # define __printflike(x, y)
# endif # endif
@ -202,7 +202,7 @@
#ifndef __containerof #ifndef __containerof
# if LIBBSD_GCC_VERSION >= 0x0301 # if LIBBSD_GCC_VERSION >= 0x0301
# define __containerof(x, s, m) ({ \ # define __containerof(x, s, m) ({ \
const volatile __typeof(((s *)0)->m) *__x = (x); \ const volatile __typeof__(((s *)0)->m) *__x = (x); \
__DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m)); \ __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m)); \
}) })
# else # else

View File

@ -6,7 +6,7 @@
#include <string.h> #include <string.h>
__attribute__((weak)) void __attribute__((__weak__)) void
__explicit_bzero_hook(void *buf, size_t len) __explicit_bzero_hook(void *buf, size_t len)
{ {
} }

View File

@ -29,5 +29,5 @@
#define libbsd_link_warning(symbol, msg) \ #define libbsd_link_warning(symbol, msg) \
static const char libbsd_emit_link_warning_##symbol[] \ static const char libbsd_emit_link_warning_##symbol[] \
__attribute__((used,section(".gnu.warning." #symbol))) = msg; __attribute__((__used__,__section__(".gnu.warning." #symbol))) = msg;
#endif #endif

View File

@ -287,9 +287,12 @@ __asm__(".symver setproctitle_impl,setproctitle@@LIBBSD_0.5");
* for code linking against that version, and change the default to use the * for code linking against that version, and change the default to use the
* new version, so that new code depends on the implemented version. */ * new version, so that new code depends on the implemented version. */
#ifdef HAVE_TYPEOF #ifdef HAVE_TYPEOF
extern typeof(setproctitle_impl) setproctitle_stub __attribute__((alias("setproctitle_impl"))); extern __typeof__(setproctitle_impl)
setproctitle_stub
__attribute__((__alias__("setproctitle_impl")));
#else #else
void setproctitle_stub(const char *fmt, ...) void
__attribute__((alias("setproctitle_impl"))); setproctitle_stub(const char *fmt, ...)
__attribute__((__alias__("setproctitle_impl")));
#endif #endif
__asm__(".symver setproctitle_stub,setproctitle@LIBBSD_0.2"); __asm__(".symver setproctitle_stub,setproctitle@LIBBSD_0.2");

View File

@ -49,4 +49,4 @@
* move them from .ctors to .init_array. * move them from .ctors to .init_array.
*/ */
void (*libbsd_init_func)(int argc, char *argv[], char *envp[]) void (*libbsd_init_func)(int argc, char *argv[], char *envp[])
__attribute__((section(".init_array"))) = setproctitle_init; __attribute__((__section__(".init_array"))) = setproctitle_init;