[U-Boot] weak functions versus conditional compile

Joakim Tjernlund joakim.tjernlund at transmode.se
Wed Nov 19 15:18:29 CET 2008


On Wed, 2008-11-19 at 14:54 +0100, Haavard Skinnemoen wrote:
> Mike Frysinger <vapier at gentoo.org> wrote:
> > On Monday 17 November 2008 16:17:54 Graeme Russ wrote:
> > > Should I declare these functions as weak in the core i386 code and use a
> > > config #define to override or should I seperate the functions out into
> > > seperate source files and use conditional compilation?
> > 
> > i wonder if weak functions that are always satisfied and used unconditionally 
> > result in larger code, or if this is only a problem for people whose linkers 
> > lack lazy relaxation support ?
> 
> It's probably a problem with linkers that don't support --gc-sections,
> which is different from relaxation. Also, you definitely need to
> compile with -ffunction-sections, or the weak functions might end up in
> the same section as something linked unconditionally, which makes it
> impossible for the linker to remove them.

And you need to fix the relocation not to relocate NULL values, see
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/rs6000/eabi.asm?rev=1.13&content-type=text/x-cvsweb-markup
look for __eabi_uconvert.

For fun I once tried to rewrite these functions i C, not tested though:

void __eabi_convert(unsigned long *low, unsigned long *high,
		    unsigned long addend)
{
	unsigned long len = high - low, val;
	if (!len)
		return;
	low--;
	do {
		val = *++low;
		if (!val)
			continue;
		*low = val + addend;
	} while(--len);
}

void __eabi_uconvert(unsigned long *low, unsigned long *high,
		     unsigned long addend)
{
	unsigned long len = high - low, val, val2, *v2p;
	if (!len)
		return;
	low--;
	do {
		val = *++low;
		val += addend;
		v2p = (unsigned long *)val;
		*low = val;
		val2 = *v2p;
		val2 += addend;
		*v2p = val2;
	} while(--len);
}

void __eabi_uconvert_org(unsigned long *low, unsigned long *high,
		     unsigned long addend)
{
	unsigned long len = high - low, val, val2, *v2p;
	if (!len)
		return;
	low--;
	do {
		val = *++low;
		val += addend;
		v2p = (unsigned long *)val;
		val2 = *v2p;
		*low = val;
		val2 += addend;
		*v2p = val2;
	} while(--len);
}



More information about the U-Boot mailing list