OSDev.org
https://forum.osdev.org/

Does libc++ require a C standard library?
https://forum.osdev.org/viewtopic.php?f=1&t=33185
Page 1 of 1

Author:  AndrewAPrice [ Fri Sep 14, 2018 5:03 pm ]
Post subject:  Does libc++ require a C standard library?

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.

Author:  pat [ Fri Sep 14, 2018 6:45 pm ]
Post subject:  Re: Does libc++ require a C standard library?

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.

Author:  AndrewAPrice [ Sat Sep 15, 2018 6:04 pm ]
Post subject:  Re: Does libc++ require a C standard library?

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

Author:  pat [ Sun Sep 16, 2018 6:32 am ]
Post subject:  Re: Does libc++ require a C standard library?

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.

Author:  AndrewAPrice [ Sun Sep 16, 2018 6:54 am ]
Post subject:  Re: Does libc++ require a C standard library?

Awesome! Thanks!

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/