[U-Boot-Users] Can't get strong symbol to override weak one

Ben Warren biggerbadderben at gmail.com
Fri Jun 13 07:38:25 CEST 2008


Hello,


On Tue, Jun 10, 2008 at 10:55 PM, Ben Warren <biggerbadderben at gmail.com> wrote:
> Hi,
>
> Not specifically U-boot related, but hopefully a smart person here can help.
>
> I have a weak symbol defined as:
> int cpu_eth_init(bd_t *bis) __attribute((weak, alias("__def_eth_init")));  (1)
>
> I've created a new file in cpu/mpc83xx that includes a real
> implementation of the function:
> int cpu_eth_init(bd_t *bis)  (2)
>
> Using objdump, I've verified that this function is making it into
> libmpc8xxx.a, however it doesn't get linked into the final U-boot
> executable.  System.map shows cpu_eth_init at the same address as
> __def_eth_init.
>
> If I change (1) to:
> extern int cpu_eth_init(bd_t *bis), (2) gets linked in OK.  Of course,
> that's not what I want to do.
>
> I've tried changing the order of the archives that get linked together
> by ld, but nothing seems to work.  Since I don't really know what I'm
> doing, I guess that shouldn't be surprising.
>
> Any help would be appreciated.
>
> thanks,
> Ben
>
I've played around a bit more and found that if I move my function to
an existing file containing functions called from elsewhere, my code
gets linked in.  Further research shows that a 'feature' of ld is that
it won't pull in a module that only has symbols that have already been
resolved, even if the previously found version is weak.

Mike F, please correct me if I'm wrong but that's what I gather from a
conversion I found you having with the binutils mailing list:

http://sourceware.org/ml/binutils/2008-01/msg00302.html

IMHO, developers should be able to write board and cpu code to
override weak symbols in libraries/drivers without having to worry
about whether the intention was obeyed or not.  ld has a switch
'--whole-archive', that will pull in an entire archive, not just the
modules that are referenced elsewhere with strong linkage.

I propose to wrap both the 'board/$(BOARDDIR)/lib$(BOARD).a' and
'cpu/$(CPU)/lib$(CPU).a' arguments to ld in
--whole-module/--no-whole-module in order to accomplish this goal.  We
definitely don't want to do this across the board because image size
will increase quite a bit due to unused code.  I believe that the
board and cpu code, though, should be mostly free of cruft.  If not,
it should be restructured with appropriate CONFIGs, either in
Makefiles or C code.

thoughts?

regards,
Ben




More information about the U-Boot mailing list