views:

142

answers:

1

Some background:

As a personal project, I've been developing a kernel in c++. Things are going well, in fact I have very good support for much of c++ available in kernel land (I've implemented nearly the entire libc and libstdc++).

One of the more difficult and compiler specific things is RTTI and exception support. For now I'm disabling exceptions entirely, but RTTI is something I want since things like dynamic_cast can be very useful. To make this work, I have a basic implementation of std::type_info which matches what g++ expects and then I link to g++'s libsupc++.a and libgcc_eh.a. This works great. RTTI works like a champ!

The question:

I've been toying with some optimization options and would like to someday have -mregparm as a compile time choice. Obviously this being a kernel and having to interact with assembly code, there are certain functions which don't play nice with not having the parameters on the stack. To solve this, I use the following macro:

#define asmlinkage  attribute((regparm(0)))

Once again, this works very well. The problem is that when you do a dynamic_cast. The compile emits calls to some implicitly defined internal functions (defined in the support libraries previously mentioned) and does so respecting the -mregparm flag. Of course since I linked to the system's support libraries, they may or may not (they don't in my case) have a compatible calling convention...leading to a nice pretty kernel panic. Since these functions are implicit (no prototype in any of my files) and they have long, mangled names, it is (nearly) impossible to add my asmlinkage attribute to them.

There are 3 possible solutions which come to mind.

  1. forget about supporting -mregparm's all together.
  2. recompile those 2 support libs with the same flags as the kernel. This might be annoying and slightly impractical (I don't know if they can be cleanly isolated from the gcc build and toolchain upgrades could be very painful), but should work.
  3. somehow make the compiler ignore -mregparm when calling code found in a particular .a/.o file.

Is option 3 possible? My gut feeling is no, but I figured that I would ask since there are a few g++ gurus on here :-).

+1  A: 

You are probably best going with options 1 or 2 (1 is clearly easier). To my knowledge g++ has no specific switch for option 3.