[uClibc]Re: __uClibc_main's weaks for static linkage

Erik Andersen andersen at codepoet.org
Sat Mar 16 08:23:23 UTC 2002


On Fri Mar 15, 2002 at 11:46:07AM -0800, Stefan Soucek wrote:
> Hi,
> 
> I think I have tracked down uClibc's problem on our ARM no-mmu
[-------snip----------]
> $ arm-linux-nm hello.elf
> ...
> 00016a58 D _errno
> 000084a0 T _exit
>          w _fini               <-- not linked in
> 00016bb0 b _fixed_buffers
> 0000b58c t _fpadd_parts
> 0000c94c t _fpadd_parts
> 00016a5c D _h_errno
>          w _init               <-- not linked in
> 0000a690 T _ioctl
> ...
> 0000d120 T __gtsf2
>          w __h_errno_location  <-- __h_errno_location.o not linked in
> 0000c4cc T __ledf2
> ...
> 00008578 W pthread_attr_init
> 0000b068 W __errno_location    <-- __errno_location.o linked in
> 00016a54 D __exit_cleanup
> ...
> 
> The __h_errno_location, _init, _fini are not linked in, which right now
> causes some grief with static linking. In the flat file the missing

That simply means that the ELF linker has done the Right Thing(tm) 
for you.  According to the ELF specification:

    When the link editor searches archive libraries, it extracts
    archive members that contain definitions of undefined global
    symbols. The member's definition may be either a global or a
    weak symbol. The link editor does not extract archive members
    to resolve undefined weak symbols. Unresolved weak symbols
    have a zero value.

So far then, what you are seeing is correct...

> symbols are "magically" assigned relocation addresses which are
> bogus. When the app starts up and reaches
> 
> 	if (_fini && atexit) {
> 	    atexit (&_fini);
> 	}
> 
> or any other call to _fini(), _init(), __h_errno_location(), it upsets
> the system with a memory fault.

Based on this, elf2flt is clearly broken on (at least) arm then,
since you are seeing unresolved weak symbols which, instead of
being assigned zero values, are magically pointing to the great
bit-bucket in the sky.

> In the static linkage case the weaks need to be defined as indicated in
> __uClibc_main()'s comment further down. Having __USE_WEAK_ALIASES on
> solves the problem. I think the following diff seems general enough,

Nope, sorry, I don't buy this one.  I added that weak_alias junk
in a half-hearted effort at supportting old a.out toolchains.
Yes this will sortof work, but since we are using ELF this type
of evil hack is not necessry and the results will be far from
optimal.  Instead lets teach elf2flt to behave itself by zeroing
out all unresolved weaks,

 -Erik

--
Erik B. Andersen             http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--



More information about the uClibc mailing list