mirror of
https://gitlab.freedesktop.org/libbsd/libbsd.git
synced 2025-10-27 19:10:23 +01:00
Force setproctitle() into .init_array section
The GNU .init_array support is an extension over the standard System V ABI .init_array support, which passes the main() arguments to the init function. This support comes in three parts. First the dynamic linker (from glibc) needs to support it. Then function pointers need to be placed in the section, for example by using __attribute__((constructor)), that the compiler (gcc or clang for example) might place in section .ctors and the linker (from binutils) will move to .init_array on the output object, or by placing them directly into .init_array by the compiler when compiling. If this does not happen and the function pointers end up in .ctors, then they will not get passed the main() arguments, which we do really need in this case. But this relies on recent binutils or gcc having native .init_array support, and not having it disabled through --disable-initfini-array. To guarantee we get the correct behaviour, let's just place the function pointer in the .init_array section directly, so we only require a recent enough glibc. Fixes: https://bugs.freedesktop.org/show_bug.cgi?id=65029
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright © 2010 William Ahern
|
||||
* Copyright © 2012 Guillem Jover <guillem@hadrons.org>
|
||||
* Copyright © 2012-2013 Guillem Jover <guillem@hadrons.org>
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the
|
||||
@@ -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,14 @@ spt_init(int argc, char *argv[], char *envp[])
|
||||
SPT.end = end;
|
||||
}
|
||||
|
||||
/*
|
||||
* Force spt_init() function into the .init_array section instead of expecting
|
||||
* either the compiler to place constructors there or the linker to move them
|
||||
* 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
|
||||
|
||||
Reference in New Issue
Block a user