Search code examples
c++gcc4.7freestanding

C++ freestanding features


What are the features that I can use in c++ freestanding environment? I am developing a little kernel (for my own pleasure) and I know that I can't use the whole stdlib library, but what else ? when I tried to use the new and delete operators it compiled without troubles but the linker said

undefined reference to `operator new[](unsigned long)
undefined reference to `operator delete[](void*)'

I link with -lgcc and -lsupc++ options. I know that exception handling is disable in freestanding but I am a little bit surprised that new and delete are also. So what can I use and what can I not?


Solution

  • What are the features that I can use in c++ freestanding environment?

    Much of freestanding implementations is implementation defined:

    [intro.compliance] ... A freestanding implementation is one in which execution may take place without the benefit of an operating system, and has an implementation-defined set of libraries that includes certain language-support libraries

    [intro.multithread] ... Under a freestanding implementation, it is implementation-defined whether a program can have more than one thread of execution.

    [basic.start.main] It is implementation-defined whether a program in a freestanding environment is required to define a main function. [ Note: In a freestanding environment, start-up and termination is implementation-defined; start- up contains the execution of constructors for objects of namespace scope with static storage duration; termination contains the execution of destructors for objects with static storage duration. — end note ]

    [using.headers] C ++ headers for freestanding implementations

    <ciso646>
    <cstddef>
    <cfloat>
    <limits>
    <climits>
    <cstdint>
    <cstdlib>
    <new>
    <typeinfo>
    <exception>
    <initializer_list>
    <cstdalign>
    <cstdarg>
    <cstdbool>
    <atomic>
    

    [compliance] The supplied version of the header <cstdlib> shall declare at least the functions abort, atexit, at_quick_- exit, exit, and quick_exit (18.5). The other headers listed in this table shall meet the same requirements as for a hosted implementation.

    Note that malloc/free are not listed in the required functions of <cstdlib>.


    As far as your linker error is concerned, neither freestanding, nor hosted implementation is required to provide those overloads:

    [replacement.functions] A C ++ program may provide the definition for any of twelve dynamic memory allocation function signatures declared in header <new>

    In practice, since a free standing environment cannot depend on an OS, and malloc is usually implemented using features provided by an OS, it is unlikely to have free store memory management features in a freestanding environment. Conversely, a hosted environment requires free store memory management to implement the features of the standard library.