before people dismiss this as a Gentoo-specific issue, the code fails with 
Redhat and Debian toolchains as well.  tested gcc 3.4.5, 4.0.3, and a snap of 
4.1.x dated 20060120.

we were playing with arrays of pointers to weak functions in a utility program 
when we noticed the code started crashing whenever built with a Gentoo 
hardened toolchain.  Gentoo vanilla toolchains would produce code that ran 
nicely and as expected.  tracing it back, the references to the undefined 
weak functions were not being set to NULL as they should have been.  then we 
reproduced the issue with a Gentoo vanilla toolchain by simply building the 
test code as a PIE.  i'm not sure if this is an issue in gcc or glibc ldso or 
a bug at all (i'm pretty sure it's a bug), so i'm starting with gcc :)

ive attached the test code we are playing with ... here's some example runs on 
my Gentoo amd64 box:
$ gcc-4.1.0-beta20060120 -pie -fPIE weak-test.c -DOK1 && ./a.out
this should be null: (nil)
$ gcc-4.1.0-beta20060120 -pie -fPIE weak-test.c -DOK2 && ./a.out
this should be null: (nil)
this should be null: (nil)
$ gcc-4.1.0-beta20060120 -pie -fPIE weak-test.c -DBROKEN && ./a.out
this should be null: 0xe23bc395000
$ gcc-4.1.0-beta20060120 weak-test.c -DBROKEN && ./a.out
this should be null: (nil)
-mike
#include <stdio.h>

extern int undef_func (void) __attribute__((weak));
int (*ptr_to_func)(void) = undef_func;

int main()
{
#ifdef BROKEN
	printf("this should be null: %p\n", ptr_to_func);
#endif
#ifdef OK1
	printf("this should be null: %p\n", undef_func);
#endif
#ifdef OK2
	printf("this should be null: %p\n", undef_func);
	printf("this should be null: %p\n", ptr_to_func);
#endif
	return 0;
}

Reply via email to