[U-Boot] weak functions versus conditional compile

I have a quick question I would like the groups opinion on:
What is the rule-of-thumb for defining a function as weak versus using conditional compilation (or #defines)?
For example, I am doing some work on cleaning up the structure and design of the i386 / sc520 code. Specifically, some functionality such as interrupts, timers and CPU reset have more 'powerful' implementations in the sc520.
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?
Regards,
Graeme

On Monday 17 November 2008 16:17:54 Graeme Russ wrote:
I have a quick question I would like the groups opinion on:
What is the rule-of-thumb for defining a function as weak versus using conditional compilation (or #defines)?
For example, I am doing some work on cleaning up the structure and design of the i386 / sc520 code. Specifically, some functionality such as interrupts, timers and CPU reset have more 'powerful' implementations in the sc520.
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 ? -mike

Mike Frysinger vapier@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.
Haavard

On Wed, 2008-11-19 at 14:54 +0100, Haavard Skinnemoen wrote:
Mike Frysinger vapier@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.1... 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); }
participants (4)
-
Graeme Russ
-
Haavard Skinnemoen
-
Joakim Tjernlund
-
Mike Frysinger