Linker: Weak symbol preferred over strong in static lib
The arm gcc linker seems to prefer weak symbols over strong symbols, in case both are in the same static library.
This was checked for the Windows versions 4.7.4 20130913 and 4.8.4 20140526.
The following example shall show that the MinGW gcc (version 4.8.1) and the arm gcc behave differently in that concern:
We build a library with just two functions with the same name, but one of them is defined to have a weak symbol. The function is called from the main.c which is linked with the library. Normally, the strong version of both symbols should be chosen. This can be checked by analyzing the disassembly. If bar() calls weak(), the weak symbol was chosen and otherwise the strong symbol was chosen.
I found, that MinGW chooses the strong symbol but the arm-gcc chooses the weak one.
Is this a bug, or do I misunderstand something?
== Makefile ==
----- BEGIN -----
# TC = armgcc_
TC =
all:
$(TC)gcc -c bar.c
$(TC)gcc -c foo.c
$(TC)ar rvs libbar.a foo.o bar.o
$(TC)gcc main.c -L. -lbar -o test.exe
----- END -----
== bar.c ==
----- BEGIN -----
void strong();
void bar()
{
strong();
}
----- END -----
== foo.c ==
----- BEGIN -----
void weak();
__attribute_
{
weak();
}
----- END -----
== main.c ==
----- BEGIN -----
void bar();
void main()
{
bar();
}
void weak(){}
void strong (){}
----- END -----
Question information
- Language:
- English Edit question
- Status:
- Solved
- Assignee:
- No assignee Edit question
- Solved by:
- Lars Rademacher
- Solved:
- Last query:
- Last reply: