https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98634
Bug ID: 98634
Summary: gcc 4.8.5 - 9.3.0 on target x86_64, when compile a exe
and linking with a so, and exe's source file extern a
var, the final exe has the var with the same name with
the one in the so file
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: zuogang at huawei dot com
Target Milestone: ---
during linking some externed var are added into the final exe file
step to reproduce :
zoge@123:/mnt/f/test$ gcc -c -fPIC share.c -o share.o
zoge@123:/mnt/f/test$ gcc share.o -shared -o libshare.so
zoge@123:/mnt/f/test$ gcc ./test-share.c ./libshare.so
zoge@123:/mnt/f/test$ readelf -s -W ./a.out | grep aaa
6: 0000000000004028 4 OBJECT GLOBAL DEFAULT 24 aaa
62: 0000000000004028 4 OBJECT GLOBAL DEFAULT 24 aaa
zoge@123:/mnt/f/test$
zoge@123:/mnt/f/test$ cat share.c
#include <stdio.h>
int aaa=123;
void hello()
{
printf("Hello world!\n");
}
zoge@123:/mnt/f/test$ cat test-share.c
extern int aaa;
int main()
{
return aaa;
}
zoge@123:/mnt/f/test$