Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7956 Discussions

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

Vitaly_B_Intel
Employee
4,610 Views

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
Shenghong_G_Intel
4,610 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

0 Kudos
TimP
Honored Contributor III
4,610 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.

0 Kudos
Vitaly_B_Intel
Employee
4,610 Views

It solved my problem.

thank you for your help!

0 Kudos
KitturGanesh
Employee
4,610 Views

Nice to know and this was a good question :)

_Kittur

0 Kudos
Reply