This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Mangle functions


Ron Kreymborg wrote:

> My idea is a macro like:
> 
> #define CLASS_ISR(theclassname, themethodname) \
>  ISR(theclassname) ISR_ALIASOF(gcc_mangle(theclassname, themethodname)); \
>  void theclassname::themethodname(void)

As written this is impossible, since the mangling includes the number
and types of arguments.

> Inserting the mangled name by hand in the macro above produces the vector
> alias that allows gcc to link the external C vector name while the C++ code
> remains unaware of its existence outside the owning class:

I can invision a way to automate this, assuming you have a full featured
build environment (i.e. unix toolset.) First define gcc_mangle a macro
that simply expands to a unique identifier name.  For example

#define gcc_mangle(class, method, arg) \
    MANGLED_NAME_##class##_##method##_##arg

This works only for the case of one arg, if you want to support
arbitrary number of args you might have to get creative with the
macros.  It would also break if one of the args was a type like
std::string since that would be an invalid identifier.

Anyway the idea is that you then have an auto-generated header that will
fill in these definitions, e.g. for the above it would have generated:

#define MANGLED_NAME_CTimer0Interrupt___vector_16_void
"_ZN16CTimer0Interrupt11__vector_16Ev"

This header is generated by the build system, via a script that greps
all the source files for occurances of gcc_mangle and adds an entry to
the header for each one.  To get the actual contents of the mangled
string, you can use gcc itself:

$ cat >showmangling.sh <<EOF
#!/bin/sh

echo "struct $1 { void $2 ( $3 ); }; void $1::$2 ( $3 ) { };" \
   | gcc -x c++ -S - -o - \
   | awk '/^.globl/ { print $2; exit }'
EOF

$ ./showmangling.sh CTimer0Interrupt __vector_16 void
_ZN16CTimer0Interrupt11__vector_16Ev

So to sum up: your build system would need:

- a script that scans through a given set of source files for occurances
of gcc_mangle, and runs the above showmangling.sh (or equivalent) with
the macro's args, and appends the results in the form of a #define to
the generated header.
- makefile rules to ensure that the header depends on all source files
that include it, as well as a rule to regenerate the header.
- developers that can remember to always include the autogenerated
header in any file that uses the gcc_mangle (or whatever you call it)
macro.

This is not exactly pretty, but it at least allows you to handle this
automatically.

Brian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]