Commit 54f874565716766d6453ff050d78c70ea326d89a

Victor Westerhuis 2021-11-26T20:01:18

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 <guillem@hadrons.org>

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;