Skip to content

Conversation

@laurensmpm
Copy link

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.

Comment on lines -8 to +9
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)
Copy link
Contributor

@Woazboat Woazboat May 28, 2025

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

Copy link
Contributor

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;
Copy link
Contributor

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.

@Woazboat
Copy link
Contributor

See 31b76cc for global C++ constructor/destructor support.

@dgruss
Copy link
Member

dgruss commented Sep 8, 2025

this would need some cleanup before it is merged. i'm also not sure we really need it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants