public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Brian Dessent <brian@dessent.net>
To: Ron Kreymborg <ron@jennaron.com.au>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Mangle functions
Date: Mon, 28 Jan 2008 18:12:00 -0000	[thread overview]
Message-ID: <479D203C.DE9E6CDE@dessent.net> (raw)
In-Reply-To: <000501c86069$07d63310$17829930$@com.au>

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

      parent reply	other threads:[~2008-01-28  0:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-28 10:22 Ron Kreymborg
2008-01-28 17:22 ` Daniel Lohmann
2008-01-28 19:23   ` Andrew Haley
2008-01-28 19:25     ` Ron Kreymborg
2008-01-29  0:54       ` Daniel Lohmann
     [not found]         ` <000301c86303$3be6eae0$b3b4c0a0$@com.au>
2008-01-31 17:51           ` Daniel Lohmann
2008-01-28 18:12 ` Brian Dessent [this message]

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=479D203C.DE9E6CDE@dessent.net \
    --to=brian@dessent.net \
    --cc=gcc-help@gcc.gnu.org \
    --cc=ron@jennaron.com.au \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).