From d54fdeb5ae114461f589a593faafec39c42b1cb0 Mon Sep 17 00:00:00 2001 From: Leandro Pereira Date: Thu, 30 Sep 2021 21:17:09 -0700 Subject: [PATCH] Fix building with Glibc 2.34 Glibc 2.34 now defines SIGSTKSZ to a function call, so we can't use static_assert() anymore. Do the assertion only once now, during startup, in a constructor function. Fixes #318. --- src/lib/lwan-coro.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/lib/lwan-coro.c b/src/lib/lwan-coro.c index 081b42686..39af42c0f 100644 --- a/src/lib/lwan-coro.c +++ b/src/lib/lwan-coro.c @@ -62,22 +62,30 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); #define CORO_BUMP_PTR_ALLOC_SIZE 1024 -static_assert(DEFAULT_BUFFER_SIZE < CORO_STACK_SIZE, - "Request buffer fits inside coroutine stack"); - #if (!defined(NDEBUG) && defined(MAP_STACK)) || defined(__OpenBSD__) /* As an exploit mitigation, OpenBSD requires any stacks to be allocated via * mmap(... MAP_STACK ...). * * Also enable this on debug builds to catch stack overflows while testing * (MAP_STACK exists in Linux, but it's a no-op). */ - #define ALLOCATE_STACK_WITH_MMAP +#endif -static_assert((CORO_STACK_SIZE % PAGE_SIZE) == 0, - "Coroutine stack size is a multiple of page size"); -static_assert((CORO_STACK_SIZE >= PAGE_SIZE), - "Coroutine stack size is at least a page long"); +#ifndef NDEBUG +__attribute__((constructor)) static void assert_sizes_are_sane(void) +{ + /* This is done in runtime rather than during compilation time because + * in Glibc >= 2.34, SIGSTKSZ is defined as sysconf(_SC_MINSIGSTKSZ). */ + + /* Request buffer fits inside coroutine stack */ + assert(DEFAULT_BUFFER_SIZE < CORO_STACK_SIZE); +#ifdef ALLOCATE_STACK_WITH_MMAP + /* Coroutine stack size is a multiple of page size */ + assert((CORO_STACK_SIZE % PAGE_SIZE) == 0); + /* Coroutine stack size is at least a page long */ + assert((CORO_STACK_SIZE >= PAGE_SIZE)); +#endif +} #endif typedef void (*defer1_func)(void *data);