compile newlib into .so

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
mcheung63
Member
Member
Posts: 175
Joined: Thu Jun 22, 2006 8:33 am
Location: Hong Kong
Contact:

compile newlib into .so

Post by mcheung63 »

Hi
i can only compile newlib in .a , how to compile it in .so (shared lib)?
Which option i need to apply for configure?

thanks
from Peter ([email protected])
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post by jnc100 »

Are you using a toolchain that can produce shared executables? Does libtool work? Do you have a dynamic linker? If so, newlib should build shared libraries anyway. Otherwise, there's always the --enable-shared option.

Regards,
John.
User avatar
mcheung63
Member
Member
Posts: 175
Joined: Thu Jun 22, 2006 8:33 am
Location: Hong Kong
Contact:

Post by mcheung63 »

thank you for the response

But i still cannot build a .so from newlib, i searched arround the google, some people said it is not possible to build a shared lib for embedded platform such as arm, but for i386, it should be possible to build a .so

Any other hints?

thanks
from Peter
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

If you're still having problems with it, I could suggest a way to do it... (just thought of it!)

Code: Select all

#!/bin/bash
mkdir tmp
cd tmp
ar x ../libc.a
gcc -G --shared -o libc.so <put flags here> *.o
cp libc.so ../
cd ..
rm -Rf tmp
In a bash script should do it?
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post by jnc100 »

ELF shared libraries are usually position-independent code whereas static libraries are not - they just have their relocations resolved at link time. They are not only linked differently, but compiled differently in that you need to use a different relocation type (e.g. GOT relative or jump via the PLT) and generally the basic code emitted to call/access data through these relocations is different than what is used in static linking. Therefore, you need to also recompile every source file with the -fpic option too. The libtool script is very handy here.

Newlib does not support shared libraries on many targets, simply because it assumes shared library support not to exist on these targets. 'Support' for a shared library requires far more than just a cross compiler that can emit position-independent code and GOT/PLT relative relocations, you also need a dynamic linker, which is part of the operating system, to fixup all the GOT entries.

As the OP is presumably writing their own operating system (as they're posting to this forum) you still need to be able to answer yes to each of the questions I asked previously to get shared libraries to work. Actually, a dynamic linker isn't that hard, provided you read the required reading.

Regards,
John.
Post Reply