[LLVMdev] How to disable or override libgcc when linking?

2,115 views
Skip to first unread message

lia...@codeaurora.org

unread,
Oct 27, 2012, 10:13:24 PM10/27/12
to llv...@cs.uiuc.edu
Hi,

I'm using compiler-rt to build the library to replace libgcc. How can I
disable -lgcc being added and passed to the linker?

When I use:
"clang -ccc-gcc-name arm-cross-g++ hello.c -Lmypath -lmylib -v"

-lgcc is always added:
"...gcc/arm-none-linux-gnueabi/4.6.1/collect2 ... /tmp/hello-Pj9QxO.o
-lgcc ..."

How can I disable or override libgcc from the command line?

Thanks.
-Liang


_______________________________________________
LLVM Developers mailing list
LLV...@cs.uiuc.edu http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

Tim Northover

unread,
Oct 29, 2012, 7:21:20 AM10/29/12
to lia...@codeaurora.org, llv...@cs.uiuc.edu
Hi Liang,

> How can I disable or override libgcc from the command line?

I think the option you're looking for may be "-nostdlib". At least,
that will probably be part of the solution.

Tim.

lia...@codeaurora.org

unread,
Nov 15, 2012, 9:33:27 PM11/15/12
to llv...@cs.uiuc.edu
Hi,

I'm trying to link my objs with compiler-rt built runtime lib for arm.
According to the compiler-rt doc, it should be able to replace libgcc.
However, if I replace "-lgcc" with "compiler-rt.a" for a static linking,
gcc linker complains about undefined functions. Using "nm -g", I compared
the functions in libgcc and compiler-rt.full-arm.a and found there are
many missing functions in compiler-rt, such as "__aeabi_dcmpeq"
"__sync_lock_release_1" "_interwork_call_via_fp", etc.

Although I can use compiler-rt.a via using "-allow-multiple-definition" to
override libgcc, this is an ugly solution.

Anybody know how to fully replace libgcc with compiler-rt? Do I need to
link some other lib to totally replace libgcc when using compiler-rt, or
compiler-rt cannot fully replace libgcc yet? I know Apple is using
compiler-rt built runtime libs. How did they link?

David Chisnall

unread,
Nov 15, 2012, 9:39:18 PM11/15/12
to lia...@codeaurora.org, llv...@cs.uiuc.edu
My memory may be fuzzy, but I believe that those functions are required for ARMv6 support. On ARMv7 and newer they are not used. Apple only supports ARMv7 currently, and so they probably won't have encountered this problem. We're probably going to be adding some things to compiler-rt for FreeBSD on ARM over the next year, but if you get there and do it before us then we certainly won't complain...

David

Nick Kledzik

unread,
Nov 15, 2012, 11:00:48 PM11/15/12
to lia...@codeaurora.org, llv...@cs.uiuc.edu

On Nov 15, 2012, at 9:33 PM, lia...@codeaurora.org wrote:
> I'm trying to link my objs with compiler-rt built runtime lib for arm.
> According to the compiler-rt doc, it should be able to replace libgcc.
> However, if I replace "-lgcc" with "compiler-rt.a" for a static linking,
> gcc linker complains about undefined functions. Using "nm -g", I compared
> the functions in libgcc and compiler-rt.full-arm.a and found there are
> many missing functions in compiler-rt, such as "__aeabi_dcmpeq"
> "__sync_lock_release_1" "_interwork_call_via_fp", etc.
>
> Although I can use compiler-rt.a via using "-allow-multiple-definition" to
> override libgcc, this is an ugly solution.
>
> Anybody know how to fully replace libgcc with compiler-rt? Do I need to
> link some other lib to totally replace libgcc when using compiler-rt, or
> compiler-rt cannot fully replace libgcc yet? I know Apple is using
> compiler-rt built runtime libs. How did they link?

What compiler are you using? compiler-rt was designed to implement the support functions needed for clang. If you are compiling with gcc, then, yes you might find it relies on support functions not in libcompiler-rt.a.

-Nick

lia...@codeaurora.org

unread,
Nov 16, 2012, 1:55:49 PM11/16/12
to Nick Kledzik, lia...@codeaurora.org, llv...@cs.uiuc.edu
I'm using Clang, with arm-none-linux-gnueabi-g++ as a linker. Although
compiler-rt replaced libgcc, we still need other libs such as libc, libm,
etc. It seems libc is calling these missing functions.

Anton Korobeynikov

unread,
Nov 16, 2012, 2:21:42 PM11/16/12
to lia...@codeaurora.org, LLVM Developers Mailing List
> I'm using Clang, with arm-none-linux-gnueabi-g++ as a linker. Although
> compiler-rt replaced libgcc, we still need other libs such as libc, libm,
> etc. It seems libc is calling these missing functions.
If you compile libc with gcc, then yes, you might need arbitrary
functions from libgcc.

--
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University

lia...@codeaurora.org

unread,
Nov 16, 2012, 3:14:52 PM11/16/12
to Anton Korobeynikov, lia...@codeaurora.org, LLVM Developers Mailing List
So, you mean I should compile libc with clang and link with compiler-rt too?
But how can we expect a user of compiler-rt have a libc compiled in this
way? It's a part of gcc's src code... If compiler-rt is a complete lib, it
should also cover these functions, right?

BTW, if libc is compiled statically, shouldn't itself already contain all
functions it need? I just get confused now...

Anton Korobeynikov

unread,
Nov 16, 2012, 3:21:35 PM11/16/12
to lia...@codeaurora.org, LLVM Developers Mailing List
Hello

It seems you misses several points here...

> So, you mean I should compile libc with clang and link with compiler-rt too?
> But how can we expect a user of compiler-rt have a libc compiled in this
> way? It's a part of gcc's src code...
No it is not

> If compiler-rt is a complete lib, it should also cover these functions, right?
Yes and no. Yes - it should cover all library functions as defined by
ARM EABI. Right now it misses some, but the calls to them are not
generated by clang. No - in general it should not cover gcc's internal
functions. Though it can cover *some* functions which are important.

So, in your case we need to include _aeabi* and _sync* functions, yes.

lia...@codeaurora.org

unread,
Nov 16, 2012, 6:05:02 PM11/16/12
to Anton Korobeynikov, llv...@cs.uiuc.edu
Hi guys,

Thanks for all the info.

Then, if, besides compiler-rt, I also need some other libs, such as libm,
how do I link?

Here is an example of missing functions in compiler-rt when linking:
"-lstdc++ -lm --start-group -lcompiler-rt-armv7 -lgcc_eh -lc --end-group"
vs.
"-lstdc++ -lm --start-group -lgcc -lgcc_eh -lc --end-group"
...
tools/gcc-4.6.1-cs/arm-2011.09/bin/../arm-none-linux-gnueabi/libc/thumb2/usr/lib/libm.a(mpa.o):
In function `norm':
mpa.c:(.text+0xba): undefined reference to `__aeabi_dcmplt'

Does clang provide other replacing libs for them which don't depend on
those missing functions on libgcc? Or there are some other ways to link?
Currently I have to link with both compiler-rt and libgcc with
"--allow-multiple-definition" so that libgcc can cover the missing
functions in compiler-rt. But this is not a clean solution, and I have
trouble when linking thumb2 code with the arm libs in this way. Do you
have better ideas to use compiler-rt to replace libgcc for now?

Thanks!
-Liang

Anton Korobeynikov

unread,
Nov 16, 2012, 6:10:28 PM11/16/12
to lia...@codeaurora.org, LLVM Developers Mailing List
> Does clang provide other replacing libs for them which don't depend on
> those missing functions on libgcc? Or there are some other ways to link?
> Currently I have to link with both compiler-rt and libgcc with
> "--allow-multiple-definition" so that libgcc can cover the missing
> functions in compiler-rt. But this is not a clean solution, and I have
> trouble when linking thumb2 code with the arm libs in this way. Do you
> have better ideas to use compiler-rt to replace libgcc for now?
The proper solution is to provide missed functions into compiler_rt.

Zonr Chang

unread,
Jan 29, 2013, 9:41:54 AM1/29/13
to LLVM Developers Mailing List, lia...@codeaurora.org
Dear,
 
 
I just uploaded a patch to implement missing aeabi_{d,f}cmp* helper functions in compiler-rt. Please refer to http://llvm-reviews.chandlerc.com/D343
 
Could someone review this patch? Thanks in advance :)
 
 
Sincerely, 
Zonr
Reply all
Reply to author
Forward
0 new messages