How to disable or override libgcc when linking?

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

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.

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?

Thanks.
-Liang

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

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

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.

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.

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...

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.

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

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.

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 :slight_smile:

Sincerely,
Zonr