🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.help
Article #521

name mangler

#521
From: Paul Vaughan
Date: Mon, 01 Apr 1991 20:07
58 lines
2950 bytes
Several people including myself have asked for a name mangler. Michael
Tiemann has replied that such a thing exists in the g++ file
cplus-method.c, but I haven't figured out any way to use that just
yet.  I've been looking into the problem a bit and have come to a
sticky question: Exactly what input strings should a name mangler
accept?


Michael's mangling function is called as part of the process of
compiling code and is oriented very strongly for this purpose. It
appears to accept any legal function declaration (or a start of a
definition) of the current context in parse tree form.  Any types
mentioned must have been declared, default argument expressions are
admitted, explicit type declarations (i.e. void foo(struct Bar);) etc.
are allowed. This makes for a very complex grammar for function
declarations--for instance, it subsumes the expression grammar of C++.

I looked into the way that gdb handles name mangling. It avoids the
issue by only doing name demangling. That is, when you type in a C++
function name (not a complete declaration) like "foo" to set a
breakpoint, it looks through all symbols that start with foo,
demangles any matches and compares the demangled base name (the
demangler has an option to return only the base name, instead of a
full declaration with argument specs) against the given base name. (As
an aside, this code doesn't quite work for ordinary functions in gdb
3.6, and I don't understand how it is intended to work when a function
is overloaded).

The reason I wanted a name mangler was in connection with dynamic
linking. I'd like to be able to specify a full declaration (but not in
any context of typedefed names, and without the return type) and get
out the mangled symbol.  For instance,


"foo(Foo, Bar*, int, int)"

would give 

"_foo__FG3FooP3Barii"

for g++-1.39

I'm wondering, is this even feasible? Would it be necessary to have
built up the context of typedef'ed names? Suppose that certain
restrictions to the input format of unmangled names, such as
prohibiting

	foo(Foo, struct Bar*, int, int)

were in effect. Then would there a exist a 1:1 mapping between legal
mangled and unmangled names?

Does anyone have a specification for the mangler that is simpler than
ferreting it out of the demangler in cplus-dem.cc?

How many people would be interested in having a bison grammar based
mangler and demangler?
Technical Details
Message-ID: <9104012007.AA09595@puma.cad.mcc.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!tut.cis.ohio-state.edu!unreplyable!garbage

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!zaphod.mps.ohio-state.edu!magnus.acs.ohio-state.edu!tut.cis.ohio-state.edu!unreplyable!garbage
From: vaughan%cadillac.cad.mcc.com@MCC.COM (Paul Vaughan)
Newsgroups: gnu.g++.help,comp.lang.c++
Subject: name mangler
Message-ID: <9104012007.AA09595@puma.cad.mcc.com>
Date: 1 Apr 91 20:07:11 GMT
Sender: daemon@tut.cis.ohio-state.edu
Followup-To: gnu.g++.help
Organization: Gatewayed from the GNU Project mailing list help-g++@prep.ai.mit.edu
Lines: 58