From: Martin Dalecki <dalecki@evision-ventures.com>
To: "T. A." <tkhoadfdsaf@hotmail.com>
Cc: Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: C++ and the kernel
Date: Tue, 09 Apr 2002 11:54:20 +0200 [thread overview]
Message-ID: <3CB2BA4C.80200@evision-ventures.com> (raw)
In-Reply-To: <OE379mspgEOI7vDcPp200002a4c@hotmail.com>
T. A. wrote:
> Hi all,
>
> I am in the initial stages of writing some C++ wrapper classes for the
> kernel.
>
> So far my overloading of "new" works if I compile the module without
> exceptions (-fno-exceptions). This is fine for myself as I prefer checking
> for a NULL on a memory allocation error over handling an exception, plus the
> resulting code appears to be much more efficient without exceptions by a
> large order of magnitude. However I would like my C++ kernel support to
> include exception support if possible so those whom may want to use it,
This will turn out to be nearly impossible. Please note that
the exception mechanisms in C++ are basically a second function
return path and are therefore not desirable at all for the following reasons:
1. It's silly becouse we have already a return path and page fault based
exception mechanisms in kernel, which is far better suited for the purposes
of the kernel then the C++ semantics. (Remarkable the KDE people recognize
that C++ exceptions are not a good thing...)
2. It's changing the stack layout for the kernel functions, and there
are few of them which rely on a particular stack layout (namely the
scheduler and some *.S files - look out for the asmlinkage attribute...)
> besides which it may yet prove itself useful. However allowing exceptions
> in (if used apparently, via so far my overloading of "new") appears to put
> an undefined reference to throw and (I think) terminate into the resulting
> object file. Does someone know how I can resolve this?
Yes I know - PLEASE JUST FORGET ABOUT IT.
> I would like to add the ability for the wrapper classes' users to use
> static member functions as the module initiation and cleanup functions. For
> example:
>
> class my_module
> {
> public:
> static int load();
> static void unload();
> };
>
> And use my_module::load() as the init_module function and
> my_module::unload() as the cleanup_module function. The provided macros
> module_init and module_exit should do this for me however I've encountered a
> limitation in how gcc's "alias" feature is used. Apparently for C++ one
> must pass the mangled name of the function in question. Is there a gcc
> macro or function of some kind to do something like this:
>
> int init_module() __attribute__((alias(mangle_name("load__9my_module"))));
> int cleanup_module()
> __attribute__((alias(mangle_name("unload__9my_module"))));
I guess the above wouldn't work due to the games which the linkage scripts
play already on the init_module and cleanup_module function.
Maybe you would rather wan't to have a look at those scripts themself
and adjust them accordingly? (Possibly having a mangling tool at hand...)
> I need a function or macro like mangle_name above.
>
> Another issue that I currently have is that I haven't been able to
> figure out a way to get the module to properly initiate global objects.
> Like so:
>
> my_module mod1;
Well the "hidden C++" initializations you should propably forget
about - they are not desirable inside the kernel, becouse this
C++ mechanism is annihilating the expliciticity of the programm controll
flow of C.
> On a side note:
>
> So far C++'s use of the kernel headers has found a couple of areas in
> which possible bugs exists. In one header file the typedef ssize_t is used
> despite its definition not appearing in the source file or any of the
> included header files. I've also encountered negative numbers being
> assigned to unsigned numbers without a cast. And I've found completely
> unnecessary use of the C++ keyword "new" as variable names in some inlined
> functions.
>
> Would patches be welcomed for one or more of these issues?
Personally I would just like to have the ability to compile the
kernel with C++ just for the following two reaons:
1. C++ is a bit tighter on type checking, which would give better regreesions.
2. Modern GCC versions generate generally better code for C if compiled as C++
files, since the language gives tighter semantics to some constructs.
However I wouldn't for certainly like to see the kernel beeing transformed
in to C++. Expierence has shown over time that the chances for abuse of this
programming language are just too high. Language design idiocies like the
following come immediately in to mind:
1. Templates.
2. Runtime Type Information.
3. Operator overloading. This makes the language morphable which is killing
nearly the ability to understand code by reading it.
4. Syntactically hidden code paths
(exceptions, constructors with side effects, destructors which you never know
when they tis you...) make the readability even worser...
5. Instability of compiler implementations (ever wondered how many libstdc++ you
have on your linux system?)
next prev parent reply other threads:[~2002-04-09 10:56 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-04-09 10:16 C++ and the kernel T. A.
2002-04-09 9:54 ` Martin Dalecki [this message]
2002-04-09 12:10 ` Richard B. Johnson
2002-04-09 12:26 ` Dr. David Alan Gilbert
2002-04-09 13:28 ` Richard B. Johnson
2002-04-09 14:00 ` Chris Friesen
2002-04-09 13:55 ` Sean Neakums
2002-04-09 14:00 ` Alexander Viro
2002-04-09 14:02 ` Michael Clark
2002-04-09 14:30 ` Rik van Riel
2002-04-10 1:52 ` H. Peter Anvin
2002-04-09 17:17 ` T. A.
2002-04-09 21:51 ` J. Dow
2002-04-09 23:11 ` Rui Sousa
2002-04-09 17:27 ` T. A.
2002-04-09 11:29 ` Erik Mouw
2002-04-09 16:21 ` Kurt Wall
-- strict thread matches above, loose matches on Subject: below --
2002-04-09 16:45 Sau Dan Lee
2002-04-09 16:51 Sau Dan Lee
2002-04-09 16:58 ` Richard B. Johnson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3CB2BA4C.80200@evision-ventures.com \
--to=dalecki@evision-ventures.com \
--cc=linux-kernel@vger.kernel.org \
--cc=tkhoadfdsaf@hotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox