Linker: Weak symbol preferred over strong in static lib

Bug #1352766 reported by Lars Rademacher
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
GNU Arm Embedded Toolchain
Invalid
Undecided
Unassigned

Bug Description

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_4_8_q2\bin\arm-none-eabi-
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)) void bar()
{
    weak();
}
----- END -----

== main.c ==
----- BEGIN -----
void bar();

void main()
{
    bar();
}

void weak(){}

void strong (){}
----- END -----

Revision history for this message
Lars Rademacher (lars-rademacher-g) wrote :

Bug report was created because identified in this discussion:
https://answers.launchpad.net/gcc-arm-embedded/+question/251943

Revision history for this message
Joey Ye (jinyun-ye) wrote :
Changed in gcc-arm-embedded:
status: New → Invalid
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.