Page 1 of 1
warning: cannot find entry symbol _start for shared library
Posted: Sat Oct 17, 2015 8:49 pm
by rianquinn
I followed the instructions for creating a cross compiler from here:
http://wiki.osdev.org/GCC_Cross-Compiler
My target is "x86_64-elf". I used the following:
../gcc-5.2.0/configure --target=$TARGET --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ --without-headers --with-gmp=/usr/local/Cellar/gmp/6.0.0a/ --with-mpfr=/usr/local/Cellar/mpfr/3.1.3/ --with-mpc=/usr/local/Cellar/libmpc/1.0.3/
Everything compiles fine. When I attempt to use the resulting cross compiler to compile a simple hello world style shared library, I get the following:
ld: warning: cannot find entry symbol _start; defaulting to 00000000004000c0
The resulting file doesn't appear to be a shared library either. To compile the library, I used the following:
~/opt/cross/bin/x86_64-elf-gcc lib.c -shared -o lib.so
I also tried adding --enable-shared to gcc's configure script, but that didn't help. What am I missing? Seems to me that if ld is looking for _start, it's not actually compiling a library and instead is trying to compile an executable.
Thanks,
- Rian
Re: warning: cannot find entry symbol _start for shared libr
Posted: Sun Oct 18, 2015 12:15 am
by iansjack
~/opt/cross/bin/x86_64-elf-gcc lib.c -shared -o lib.so
Try including the -fpic option to produce position independent code (obviously a shared library needs to be position independent).
Re: warning: cannot find entry symbol _start for shared libr
Posted: Sun Oct 18, 2015 5:03 am
by rianquinn
Tried"-fpic" with no success either. I am compiling the the following example code:
Code: Select all
int myglob = 42;
int ml_util_func(int a)
{
return a + 1;
}
int ml_func(int a, int b)
{
int c = b + ml_util_func(a);
myglob += c;
return b + myglob;
}
Using my cross compiler, if I run readelf on the resulting .so, I don't get any dynamic sections, or relocations in the file. Using a pre-canned cross compiler meant for Linux (x86_64-pc-linux-gcc), I get what I would expect. I should also note that using the pre-canned compiler, I cannot compile the library without "-fpic" as it will complain (which makes sense). With my compiler, it seems to almost ignore "-fpic" as the output is no different.
- Rian
Re: warning: cannot find entry symbol _start for shared libr
Posted: Sun Oct 18, 2015 7:20 am
by rianquinn
Well I was able to get it to work. I think this might be a bug with GCC based on what I have found. If I compile and link manually, it works fine.
~/opt/cross/bin/x86_64-elf-gcc -c lib.c -fPIC
~/opt/cross/bin/x86_64-elf-ld -shared -fPIC lib.o -o lib.so
No more warnings about _start, and the resulting library has the relocation sections that you would expect. Since I plan to use cmake anyways, I think this solves my problem. It is pretty frustrating that gcc could not compile and link on it's own, and seemingly ignores the -shared and -fPIC options.
- Rian
Re: warning: cannot find entry symbol _start for shared libr
Posted: Mon Oct 19, 2015 7:45 am
by mariuszp
rianquinn wrote:Well I was able to get it to work. I think this might be a bug with GCC based on what I have found. If I compile and link manually, it works fine.
~/opt/cross/bin/x86_64-elf-gcc -c lib.c -fPIC
~/opt/cross/bin/x86_64-elf-ld -shared -fPIC lib.o -o lib.so
No more warnings about _start, and the resulting library has the relocation sections that you would expect. Since I plan to use cmake anyways, I think this solves my problem. It is pretty frustrating that gcc could not compile and link on it's own, and seemingly ignores the -shared and -fPIC options.
- Rian
GCC does not by default pass "-shared" to "ld" for some reason. There is a configuration option in the target header file (gcc/config/myos.h) in which you have to put:
Code: Select all
#undef LINK_SPEC
#define LINK_SPEC "\
%{shared:-shared} \
%{!shared: \
%{!static: \
%{rdynamic:-export-dynamic} \
-dynamic-linker /lib/glidixld.so} \
%{static:-static}}"
To allow "-static" etc to be passed (you might want to change your dynamic linker to something other than "/lib/glidixld.so"). You'll do this when building your OS specific toolchain, and since you're linking libraries, I'm assuming you're implementing some userspace, for which an OS specific toolchain is very useful. Read the wiki article "OS Specific Toolchain" and try doing that.
Re: warning: cannot find entry symbol _start for shared libr
Posted: Sat Oct 24, 2015 10:26 am
by rianquinn
To allow "-static" etc to be passed (you might want to change your dynamic linker to something other than "/lib/glidixld.so"). You'll do this when building your OS specific toolchain, and since you're linking libraries, I'm assuming you're implementing some userspace, for which an OS specific toolchain is very useful. Read the wiki article "OS Specific Toolchain" and try doing that.
[/quote]
Thanks a ton. That makes a lot more sense. Actually creating a modular hypervisor. Thanks again.