Compatibility between ARM GCC and ARM's ARMLINK tools

Asked by zivbenzuk@yahoo.com

Hi, I wonder if it is possible to build a native library using the ARM GCC tool chain for Cortex M3 and link it later with libraries built with ARM Keil compiler & linker (ARMLINK)?

If yes then which GCC compiler flags should we use?
And which additional GCC libraries should we link (and in which order) together with the Keil libraries to create working build?

Thanks for the help!

Question information

Language:
English Edit question
Status:
Answered
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
chengbin (can-finner) said :
#1

Thanks for using the tool chain and report this issue to us.

> Hi, I wonder if it is possible to build a native library using the ARM GCC
> tool chain for Cortex M3 and link it later with libraries built with ARM
> Keil compiler & linker (ARMLINK)?
Yes, it's possible.

> If yes then which GCC compiler flags should we use?
This depends on what options you have used with armcc.
arm-none-eabi-gcc has different assumptions comparing to armcc.

For example, arm-none-eabi-gcc assumes that wchar_t is 4 bytes type,
while armcc assumes it is 2 bytes type by default.
These kind of different assumptions result in different ARM_attributes in
object file, and prevent armlink from linking gcc's object files with armcc's
object files.

For following example I created:

/*****lib.c*****/
double lib_div(double a, double b)
{
    return a / b;
}

There are two ways to compile it with gcc and link it in keil project:

Way 1:
If you use "--wchar32" when compiling with armcc, you can compile lib.c with
gcc by following commands with no special options:
$ arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -O2 -c lib.c -o lib.obj
$ arm-none-eabi-ar cru lib.lib lib.obj

Then link lib.lib directly with armlink by adding it in keil project(either in Keil IDE
or your makefile).

Way 2:
If you don't use "--wchar32" when compiling with armcc(default to --wchar16),
you need to compile lib.c with gcc by following commands:
$ arm-none-eabi-gcc -fshort-wchar -mcpu=cortex-m4 -mthumb -O2 -c lib.c -o lib.obj
$ arm-none-eabi-ar cru lib.lib lib.obj

Then link lib.lib directly with armlink, just as in way 1.

The wchar_t is the only case need to care in this example. There might be
something else, like "integer type for enumeration"/"signed, unsigned char".

> And which additional GCC libraries should we link (and in which order)
> together with the Keil libraries to create working build?
This depends on what library function you have used in gcc generated library.
If you used specific functions which are not provided by armcc, then you have
to link libraries providing them.
Normally, I don't think this is a serious issue, because:
1, ARM library should support c standard functions, you can call it in gcc
   generated library, and let armlink resolve symbol reference against arm
   library;
2, Most helper functions defined in libgcc.a should be named as "__aeabi_*",
   which are reserved by ARM EABI standard. These functions should be
   implemented in ARM library too and you don't need to link libgcc.a;

If there are some special functions which is not provided in ARM library, you
may firstly try to implement it in an alternative way. Though I think it rarely
happens.

Hope this could be help and please let us know if you have any question.

BTW, I created the example on cortex-m4 board, it should work on cortex-m3
too.

Can you help with this problem?

Provide an answer of your own, or ask zivbenzuk@yahoo.com for more information if necessary.

To post a message you must log in.