Does libc++ require a C standard library?

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
AndrewAPrice
Member
Member
Posts: 2303
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Does libc++ require a C standard library?

Post by AndrewAPrice »

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.
pat
Member
Member
Posts: 36
Joined: Tue Apr 03, 2018 2:44 pm
Libera.chat IRC: patv

Re: Does libc++ require a C standard library?

Post by pat »

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.
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..."
User avatar
AndrewAPrice
Member
Member
Posts: 2303
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Does libc++ require a C standard library?

Post by AndrewAPrice »

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.
pat
Member
Member
Posts: 36
Joined: Tue Apr 03, 2018 2:44 pm
Libera.chat IRC: patv

Re: Does libc++ require a C standard library?

Post by pat »

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..."
User avatar
AndrewAPrice
Member
Member
Posts: 2303
Joined: Mon Jun 05, 2006 11:00 pm
Location: USA (and Australia)

Re: Does libc++ require a C standard library?

Post by AndrewAPrice »

Awesome! Thanks!
My OS is Perception.
Post Reply