Issue metadata
Sign in to add a comment
|
preinit_array entries in binaries causing crash |
||||||||||||||||||||
Issue description
$ cat preinit.c
#include <stdio.h>
static void
preinit_0 (void)
{
printf ("preinit array 0\n");
}
static void
preinit_1 (void)
{
printf ("preinit array 1\n");
}
static void
preinit_2 (void)
{
printf ("preinit array 2\n");
}
void (*const preinit_array []) (void)
__attribute__ ((section (".preinit_array"),
aligned (sizeof (void *)))) =
{
&preinit_0,
&preinit_1,
&preinit_2
};
int
main (void)
{
return 0;
}
$ gcc preinit.c
$ ./a.out
Segmentation fault
# Outside the chroot:
$ ./a.out
preinit array 0
preinit array 1
preinit array 2
Note that the binary built inside the chroot runs fine outside the chroot.
This indicates that the issue is somewhere in glibc (ld.so or libc.so).
The compiler and linker in the chroot seem to be fine.
,
Jun 1 2018
The test is from "ld/testsuite/ld-elf/preinit.c" in the binutils repo, and is present in latest upstream ToT. I'm not sure what modern compilers do with constructors, but this is supposed to be working.
,
Jun 1 2018
is this showing up anywhere besides the test? is the test new? ie: why are we seeing this now if we have not changed binutils?
,
Jun 4 2018
I don't know of any case outside of the binutils testsuite. The issue is in the dynamic loader or glibc. The same binary linked by binutils inside chroot runs fine outside chroot, and a binary linked outside the chroot by system binutils has problem executing inside the chroot.
,
Jun 4 2018
The issue is triggered by the "glibc-2.23-file-mangle.patch" that we locally apply in sys-libc/glibc ebuild. If I comment out that patch, the executable loads and runs fine. The patch changes some printf related functions to use "_IO_JUMPS_SET" instead of "_IO_JUMPS". Presumably, that has issues when printf is called from a function in preinit_array. I did confirm that in the testcase above, the preinit_0() function does get called. It's the printf that segfaults. So presumably, preinit_array functionality is not completely broken, just calling printf and friends from a preinit function is.
,
Jun 4 2018
so, that patch was added for security reasons. So, it looks there is nothing for us to fix? yunlian@ is this patch included in the version of glibc that you are testing?
,
Jun 4 2018
NO, as the patch says, upstream has a different fix for glibc 2.24 and newer. |
|||||||||||||||||||||
►
Sign in to add a comment |
|||||||||||||||||||||
Comment 1 by vapier@chromium.org
, Jun 1 2018