How to compile newlib as a shared library (.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
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

How to compile newlib as a shared library (.so) ?

Post by kemosparc »

Hi,

I have went through building newlib for my OS and followed the below tutorials from OSDev:

https://wiki.osdev.org/OS_Specific_Toolchain (OS Specific Toolchain)
https://wiki.osdev.org/Hosted_GCC_Cross-Compiler (Hosted Cross Compiler)
https://wiki.osdev.org/Porting_Newlib (Porting Newlib)
https://wiki.osdev.org/C_Library (C Library)

I was able to compile and generate executables for my OS against libc.a.

Now I would like to use the shared library approach (libc.so) to be able to load libc once and map it to different processes page tables.

I have searched the internet and OSDev for that but I was not able to find enough information to do that.

Please, if any one was able to do it or has any pointers or directions to documentation for that, I would appreciate sharing such information.

Thanks a lot,
Karim.
User avatar
iansjack
Member
Member
Posts: 4706
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How to compile newlib as a shared library (.so) ?

Post by iansjack »

The only way that I managed this was to do my own linking, having compiled with the -PIC option. It was not easy, and not perfect, so in the end I decided to write my own C library.
mallard
Member
Member
Posts: 280
Joined: Tue May 13, 2014 3:02 am
Location: Private, UK

Re: How to compile newlib as a shared library (.so) ?

Post by mallard »

I battled with the newlib build system for a fair while attempting this, before giving up and replacing it with a "simple" Makefile that achieves it. It's not all that difficult... I removed all the files dedicated to supporting other OSs and architectures.

Unfortunately, the "GNU" standard of using autotools/libtool for build systems is rediculously version-sensitive. If you need to make any changes to the build process and you don't have the exact same versions of tools that the original developer had, you're in a world of pain. It also doesn't help that Newlib's build (unless it's been changed very recently) depends on functionality that's been removed in newer versions of autotools ("Cygus trees"; Cygnus being the original developer of Newlib...).

You can see my Makefile here: https://github.com/mallardtheduck/osdev ... c/Makefile
And a similar one for the math library: https://github.com/mallardtheduck/osdev ... c/Makefile

(Obviously you'll need a fair amount of customisation for these to even think about working on another OS, but it mught be a helpful starting point...)
Image
kemosparc
Member
Member
Posts: 207
Joined: Tue Oct 29, 2013 1:13 pm

Re: How to compile newlib as a shared library (.so) ?

Post by kemosparc »

Thanks a lot,

Will try them out.

Karim.
Post Reply