From 54f874565716766d6453ff050d78c70ea326d89a Mon Sep 17 00:00:00 2001 From: Victor Westerhuis Date: Fri, 26 Nov 2021 20:01:18 +0100 Subject: [PATCH] build: Enable .init_array support when building with LTO Because these symbols are not otherwise referenced, GCC would like to remove them. Signed-off-by: Guillem Jover --- configure.ac | 2 +- src/setproctitle_ctor.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 645a95b..806b7d3 100644 --- a/configure.ac +++ b/configure.ac @@ -175,7 +175,7 @@ AC_CACHE_CHECK( [[ static int rc = 1; 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"), __used__)) = init; int main() { return rc; } ]] )], diff --git a/src/setproctitle_ctor.c b/src/setproctitle_ctor.c index 2c5b6d0..f25dbfc 100644 --- a/src/setproctitle_ctor.c +++ b/src/setproctitle_ctor.c @@ -49,4 +49,4 @@ * move them from .ctors to .init_array. */ void (*libbsd_init_func)(int argc, char *argv[], char *envp[]) - __attribute__((__section__(".init_array"))) = setproctitle_init; + __attribute__((__section__(".init_array"), __used__)) = setproctitle_init;