Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Vitaly_B_Intel
Employee
1,637 Views

warning: cannot find entry symbol _start - while compiling to .so

Hello I am running Linux Ubuntu and am compiling using icpc (intel compiler), I want to get a shared library so I used the command:

icpc -o myShared.so -std=c++11 -shared -DSTDC_HEADERS -D __cplusplus=201103L -fpermissive -DPT_XX_DEV -fexceptions -frtti -DANDROID -w -fstack-protector -fPIE -fPIC -pie -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security -I/home/admins/aaa/include -I/home/admins/bbb/include a.cpp b.cpp c.cpp $(LIBS)

while libs is a list of shared and static libraries used, 

the interesting thing that if I delete $(LIBS) I am getting the same warning, so in my opinion it probably means that it doesn't link at all....

the warning is:

ld: warning: cannot find entry symbol _start; defaulting to 0000000000007040

I read about this warning in previous topics, and I discovered that this warning connected to the entry point of the program, but as far as I understand - there shouldn't be entry point in shared library.

Does anyone have an idea how to resolve it?

Thank you very much!

0 Kudos
4 Replies
1,637 Views

Hi Vitaly,

You should not use -pie when generating shared library.

PIE: position-independent executable

PIC: position-independent code (shared library)

See below to help you understand the issue:

(Note: -shared and -fPIC/-fPIE should be used together, -pie and -fPIE/-fPIC should be used together)

$ cat temp.c
#include <stdio.h>
int main() {printf("hello\n");return 0;}
$ icc temp.c -shared -fPIC -o out
$ file out
out: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, not stripped
$ ./out
Segmentation fault (core dumped)
$ icc temp.c -pie -fPIC -o out
$ file out
out: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, not stripped
$ ./out
hello
$ icc temp.c -shared -fPIE -o out -pie
ld: warning: cannot find entry symbol _start; defaulting to 0000000000000690
$ file out
out: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), not stripped
$ ./out
-bash: ./out: /lib/ld64.so.1: bad ELF interpreter: No such file or directory
$

When -pie is used, it will generate a executable in fact, which can run, so, "main" is required as entry point. -pie will told the compiler to generate an executable, and -shared will told the compiler to generate shared library, you are using these options together and it is a conflict. (Note: I've tried with GCC and it seems like there are some differences, but normally, -pie and -shared is a conflict, with ICC, when -pie is used before or after -shared, it will always take effect, with gcc, it seems the order matters, but the key point is that, using -pie and -shared together is incorrect.)

Thanks,

Shenghong

TimP
Black Belt
1,637 Views

In my installations, gcc 5.2 (the current release but newer than the default version) doesn't support -pie, while gcc 6.0 (which I built from trunk) does.  Thanks to Shenghong for beginning to explain these options.

Vitaly_B_Intel
Employee
1,637 Views

It solved my problem.

thank you for your help!

Kittur_G_Intel
Employee
1,637 Views

Nice to know and this was a good question :)

_Kittur

Reply