diff --git a/src/setproctitle.c b/src/setproctitle.c index 60b6484..9e4fab8 100644 --- a/src/setproctitle.c +++ b/src/setproctitle.c @@ -129,7 +129,7 @@ spt_copyargs(int argc, char *argv[]) return 0; } -static void __attribute__((constructor)) +static void spt_init(int argc, char *argv[], char *envp[]) { char *base, *end, *nul, *tmp; @@ -186,6 +186,11 @@ spt_init(int argc, char *argv[], char *envp[]) SPT.end = end; } +/* Force spt_init function into the .init_array section instead of expecting + * the linker to move it from .ctors to .init_array. */ +void (*spt_init_func)(int argc, char *argv[], char *envp[]) + __attribute__((section (".init_array"))) = spt_init; + #ifndef SPT_MAXTITLE #define SPT_MAXTITLE 255 #endif