OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Mar 29, 2024 12:48 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Does libc++ require a C standard library?
PostPosted: Fri Sep 14, 2018 5:03 pm 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2293
Location: USA (and Australia)
I'm trying to port libc++ and libc++abi from LLVM to my OS. I doesn't build because many of the headers #include_next the same header. For example, stddef.h has #include_next <stddef.h>.

I've tried searching their docs, but can't find anything. I've read on mailing lists people are saying it's trying to import the compiler's headers (so it knows the definition of things such as size_t), while others say the C++ standard library depends on the C standard library.

Has anyone has success porting libc++ that may clear this up?

If all I need to do is define a few arch/OS specific constants, I'm fine with creating blank dummy headers and then implementing what's missing.

But, I will rethink my approach (such as port newlib) if the end result will be reimplementing the C standard library.

_________________
My OS is Perception.


Top
 Profile  
 
 Post subject: Re: Does libc++ require a C standard library?
PostPosted: Fri Sep 14, 2018 6:45 pm 
Offline
Member
Member

Joined: Tue Apr 03, 2018 2:44 pm
Posts: 36
I recently did the same thing, so hopefully I can help. LLVM's libc++ does depend on libc. I actually documented most of what I need to implement in my libc earlier this year.

Quote:
If all I need to do is define a few arch/OS specific constants, I'm fine with creating blank dummy headers and then implementing what's missing.


Basically that's what I did. There's a whole lot of things that must be defined (looking at you wchar.h), but if you just want to get up and running you can just write stubs (return 0/nullptr where appropriate). I haven't yet found a use for wcsncmp, wcsxfrm, wcscspn, wcslen, wcsspn, wcswtfhwmnylttrscniaddhr, but as long as the linker sees the definition, libc++ is happy. EDIT: Actually spoke too soon, you can even get away with omitting the definitions and just have declarations for a fair bit of that stuff.

As far as the arch/OS specific constants, that's more of a minefield that I'm currently navigating. You can see in an older file (Warning: read on an empty stomach) that I really had to carefully pick and choose definitions, looking through each header and determine the right combination of things to define just to get going, even masquerading as Windows for some parts like -D_LIBCPP_USING_WIN32_RANDOM. To be clear: that was *very* hacky and disgusting and I know more experienced members will rightfully call me out on it; part of the major overhaul I'm doing is to perform that correctly this time.

_________________
Image is my operating system.

"...not because [it is] easy, but because [it is] hard; because that goal will serve to organize and measure the best of [my] energies and skills..."


Top
 Profile  
 
 Post subject: Re: Does libc++ require a C standard library?
PostPosted: Sat Sep 15, 2018 6:04 pm 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2293
Location: USA (and Australia)
Thanks for the response. I think I might take your approach and stub out the C standard library headers and attempt to build libc++ and see what the linker complains is missing.

This will help me:
http://www.schweikhardt.net/identifiers.html
https://www-s.acm.illinois.edu/webmonke ... index.html

_________________
My OS is Perception.


Top
 Profile  
 
 Post subject: Re: Does libc++ require a C standard library?
PostPosted: Sun Sep 16, 2018 6:32 am 
Offline
Member
Member

Joined: Tue Apr 03, 2018 2:44 pm
Posts: 36
I'd go ahead and download the latest C11 or C17 standard drafts, and warm up your ctrl-c/v keys. Annex B at the end of the document has a list of every single function prototype and macro you'll need, organized per file.

_________________
Image is my operating system.

"...not because [it is] easy, but because [it is] hard; because that goal will serve to organize and measure the best of [my] energies and skills..."


Top
 Profile  
 
 Post subject: Re: Does libc++ require a C standard library?
PostPosted: Sun Sep 16, 2018 6:54 am 
Offline
Member
Member
User avatar

Joined: Mon Jun 05, 2006 11:00 pm
Posts: 2293
Location: USA (and Australia)
Awesome! Thanks!

_________________
My OS is Perception.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 96 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group