-
Notifications
You must be signed in to change notification settings - Fork 118
Implement basic C++ support for userspace #307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| set(ARCH_USERSPACE_COMPILE_OPTIONS -Wall -Werror -std=gnu11 -gdwarf-4 -O0 -static -nostdinc -fno-builtin -nostdlib -fno-stack-protector -fno-common -mapcs -marm -Werror=implicit-function-declaration -Wno-error=unused-variable -fno-stack-clash-protection) | ||
| set(ARCH_USERSPACE_COMPILE_OPTIONS_C -Wall -Werror -std=gnu11 -gdwarf-4 -O0 -static -nostdinc -fno-builtin -nostdlib -fno-stack-protector -fno-common -mapcs -marm -Werror=implicit-function-declaration -Wno-error=unused-variable -fno-stack-clash-protection) | ||
| set(ARCH_USERSPACE_COMPILE_OPTIONS_CXX -Wall -Werror -std=gnu11 -gdwarf-4 -O0 -static -nostdinc -fno-builtin -nostdlib -fno-stack-protector -fno-common -mapcs -marm -Wno-error=unused-variable -fno-stack-clash-protection) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use CMake generator expressions to conditionally define compiler flags depending on the programming language. No need to duplicate all those compiler options. At the very least the common options should be separated out into a single variable that is then used by the others so they don't have to be duplicated.
4df0b73
Also, there's a separate -nostdlib++/-nostdinc++ compiler/linker option for C++
https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C++ standard library headers do not use the .h file extension. The C++ version of the C stddef.h header is called cstddef.
The C++ headers should also include the C library headers and use the type definitions from there, not re-define their own types.
|
|
||
| void *operator new(std::size_t size) | ||
| { | ||
| return nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably assert instead if it's not implemented.
|
See 31b76cc for global C++ constructor/destructor support. |
|
this would need some cleanup before it is merged. i'm also not sure we really need it... |
These changes allow for userspace tests written in C++. These tests can include and use any header in userspace/libc, as well as in the newly created userspace/libcpp. Standard C++ features like throw do not (yet) work, as they depend on ABI support functions like __cxa_throw, which are not implemented.
The changes do, however, add overload stubs for new, new[], delete, and delete[]. These can be implemented once SWEB supports the heap and functions like malloc.
Note: There is still room for improvement when including libc headers anywhere in userspace/libcpp. Currently, relative include paths must be used.