[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

GCC -pie patch (kinda) ....



As some of you are aware, I've recently voluteered (or been voluteered depending on how you look at it) to work on correcting some of the more outstanding bugs with binutils, and gcc. I've been working on debugging the -pie issue with GCC which creates the following compiler errors

bc_nonshared.a(elf-init.oST): In function `__libc_csu_init':
elf-init.c:(.text+0x1c): undefined reference to `__init_array_start'
elf-init.c:(.text+0x26): undefined reference to `__init_array_end'
elf-init.c:(.text+0x44): undefined reference to `__init_array_end'
/opt/crosstool/gcc-4.1.1-glibc-2.3.6/m68k-unknown-linux-gnu/bin/../lib/gcc/m68k-unknown-linux-gnu/4.1.2/../../../../m68k-unknown-linux-gnu/lib/libc_nonshared.a(elf-init.oST): In function `__libc_csu_fini':
elf-init.c:(.text+0x6e): undefined reference to `__fini_array_end'
elf-init.c:(.text+0x76): undefined reference to `__fini_array_start'
elf-init.c:(.text+0x8a): undefined reference to `__fini_array_start'
collect2: ld returned 1 exit status

Right now, I've developed a no-op patch, but its just a fugly way to work around the problem, which I haven't fully idenified yet. The problem stems from glibc, from csu/elf-init.c

#ifdef HAVE_INITFINI_ARRAY
/* These magic symbols are provided by the linker.  */
extern void (*__preinit_array_start []) (void) attribute_hidden;
extern void (*__preinit_array_end []) (void) attribute_hidden;
extern void (*__init_array_start []) (void) attribute_hidden;
extern void (*__init_array_end []) (void) attribute_hidden;
extern void (*__fini_array_start []) (void) attribute_hidden;
extern void (*__fini_array_end []) (void) attribute_hidden;
#endif

/* These function symbols are provided for the .init/.fini section entry
     points automagically by the linker.  */
extern void _init (void);
extern void _fini (void);

HAVE_INITFINI_ARRAY is determined on the fly by autotools at compile time to tell if the linker supports ELF sections .init_array, .finit_array, and .preinit_array. From what I can tell by reading binutils linker scripts, this SHOULD be supported on any platform that has ELF support, but I can't determine it for sure (binutils linker scripts give me a headache).

It's possible that since we do not support TLS, our linker no longer supports these, in which case the proper course of action would be to fix it in glibc, otherwise, figure out why binutils isn't outputting these sections into the resulting binary files. My next course of action is to dive into the ELF specification (bleck), and figure out what, if anything these sections do, but its quite possible this task is over my head. In addition, by making -pie a no-op, we at least have a fix.

I'll post the no-op patch if its wanted, and if anyone has ANY idea where I should look, or any thoughts and suggestions, it would be greatly appericated.
Michael


Reply to: