Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Oct 2020 11:23:01 -0600
From:      Warner Losh <imp@bsdimp.com>
To:        kamalp@acm.org
Cc:        "freebsd-arm@freebsd.org" <freebsd-arm@freebsd.org>
Subject:   Re: generic q on freebsd
Message-ID:  <CANCZdfoaZYnsb6str64ezF0O4ORSQG%2BqMh9r0%2B42GqEQjBThOg@mail.gmail.com>
In-Reply-To: <CAK=yUGJG=oVfy7XfnMkXB6XRBjbYhaVR8Zdv7R5wGqKjB=425Q@mail.gmail.com>
References:  <CAK=yUGJG=oVfy7XfnMkXB6XRBjbYhaVR8Zdv7R5wGqKjB=425Q@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Oct 6, 2020, 11:03 AM Kamal R. Prasad <kamalpr@gmail.com> wrote:

> hello,
>
> i am curious if it is possible to compile c++ code inside the freebsd
> kernel.
>


Possible? Yes, with restrictions. Easy? No.

There are a number of restrictions on doing this. There is no C++ runtime
support provided in stock FreeBSD. You have to write your own, or find
someone else that has published theirs. And the code is likely to be
compiler dependent. People have done it and talked or blogged about it.

Generally, if you don't use exceptions, templates, RTTI, expressions that
result in the automatic allocation of objects, have large objects (> 1k) on
the stack, etc, it may be possible. I tried it in the 90s and had to write
just a few routines to make simple classes work, but there's a lot of
dragons here and very little C++ code is written these days w/o reference
to the standard libraries, which aren't present in the kernel.

Some googling turns up:
https://github.com/adamlsd/libcpp.ko from 6 years ago
https://lists.freebsd.org/pipermail/freebsd-arch/2018-June/019069.html has
some details from 2 years ago about command line args you might need.

Many have tried. Few have succeeded. Those that have write all their code
to conform to a subset of the language. Few have had success moving C++
code for other purposes into the kernel, though if it was written using the
proposed (but never ratified) eC++ (embedded subset), then chances are
greater.

Good luck

Warner



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfoaZYnsb6str64ezF0O4ORSQG%2BqMh9r0%2B42GqEQjBThOg>