[BusyBox] uClibc: Can i exclude libgcc.a?

Manuel Novoa III mnovoa3 at bellsouth.net
Sun Jan 21 16:22:12 UTC 2001


On Sun, 21 Jan 2001, Wataru Nishida wrote:
> On trial, I omitted the "-lgcc" option.
> 
> $ gcc -s -nostdlib -luClibc /usr/lib/crt0.o hello.c -o hello
> /usr/lib/libuClibc.so: undefined reference to `__umoddi3'
> /usr/lib/libuClibc.so: undefined reference to `__udivdi3'
> collect2: ld returned 1 exit status
> 
> ld complained that there are no __umoddi3() and __udivdi3() functions.
> i found that there are "unsigned long long % and /" operations
> in stdlib/strto_ll.c and misc/internals/ulltostr.c.
> Then, I modified stdlib/Makefile and misc/internals/Makefile to
> exclude the two object files, and rebuilt libuClibc.
> 
(stuff omitted)
>
> NOTE: this command line does not include "-lgcc", but link
> succeeds and it works fine. The code size is now 1.9 KB.
> It's 1380 bytes reduction!
> 
> I want to know whether there are any other essential codes for uClibc
> in libgcc.a.

I can say that on i386, no.  libgcc.a is only used for __udivdi3 and __umoddi3.
Also, I just checked and these functions don't depend on anything else in
libgcc.a.

size _udivdi3.o _umoddi3.o
   text	   data	    bss	    dec	    hex	filename
    564	      0	      0	    564	    234	_udivdi3.o
    661	      0	      0	    661	    295	_umoddi3.o

nm -s _udivdi3.o
00000000 r __clz_tab
00000000 T __udivdi3

nm -s _umoddi3.o
_umoddi3.o:
00000000 r __clz_tab
00000000 T __umoddi3

This problem only comes up in the shared uClibc version.   If you link
staticly, libgcc.a doesn't get pulled in.  In the shared case though, the
linker sees that these two functions are used by the shared library and
includes them in executable.

Thank you for catching this.  ;-)

Erik, one way to work around this would be to add an option in Config for
selectively supporting "long long".  I think a better approach though would be
to extract these functions from libgcc.a and add them to libuClibc.so.1; they
aren't needed for the static lib.  We still want to keep libgcc.a in the args
gcc-uClibc passes to gcc though, in case anything else is needed in the user
application.

(a couple of minutes later)

Erik, I just verified that this approach works fine.  A small modification the
the main Makefile should do it.  Something in the shared lib section like
@(cd tmp ; ar -x  `gcc -print-libgcc-file-name` _umoddi3.o _udivdi3.o)
but this should be arch-dependent.  Other archs my require other object files
as well.  What do you get for arm if in the uClibc dir you do

mkdir tmp
cd tmp
ar -x ../libc.a
ld -r -o test *.o ../crt0.o
nm -s test | grep " U " | grep -v " main$"

 Manuel





More information about the busybox mailing list