I have encountered a need for manually generating the mangled name of an arbitrary C++ function. The only way I currently know how to do this is to generate a dummy C++ source file, compile it, and look at the output. This approach is so ugly that I would like for it never to see the light of day. The c++filt tool generates demangled C++ names given the mangled ones, which is the opposite of what I want to do. Does anyone know how to "run c++filt in reverse"? Thanks, --Patrick -- If I'm not here, I've gone out to find myself. If I get back before I return, please keep me here.
On Feb 15, 2011, at 3:10 AM, Patrick Simmons wrote:> I have encountered a need for manually generating the mangled name of an > arbitrary C++ function. The only way I currently know how to do this is > to generate a dummy C++ source file, compile it, and look at the > output. This approach is so ugly that I would like for it never to see > the light of day. The c++filt tool generates demangled C++ names given > the mangled ones, which is the opposite of what I want to do. Does > anyone know how to "run c++filt in reverse"?It's not so simple. Assuming you limit yourself to the ABI used by the GNU compiler, there is still an awful lot of information needed in the most general case. See: http://www.codesourcery.com/public/cxx-abi/abi.html#mangling for the mangling scheme (although the actual GCC implementation sometimes deviates from that for less common cases). If you're only dealing with non-local named functions and types plus ordinary type composition and exclude function templates (or at least, function templates with dependent expressions in the signature), it's probably not too hard (i.e., just a day or a few days work) to code up a mangler. If more is needed (local types, decltype, lambdas, etc.), it gets messier quite quickly. Daveed
On 15.02.2011, at 16:41, David Vandevoorde wrote:> > On Feb 15, 2011, at 3:10 AM, Patrick Simmons wrote: > >> I have encountered a need for manually generating the mangled name of an >> arbitrary C++ function. The only way I currently know how to do this is >> to generate a dummy C++ source file, compile it, and look at the >> output. This approach is so ugly that I would like for it never to see >> the light of day. The c++filt tool generates demangled C++ names given >> the mangled ones, which is the opposite of what I want to do. Does >> anyone know how to "run c++filt in reverse"? > > It's not so simple. Assuming you limit yourself to the ABI used by the GNU compiler, there is still an awful lot of information needed in the most general case. See: > > http://www.codesourcery.com/public/cxx-abi/abi.html#mangling > > for the mangling scheme (although the actual GCC implementation sometimes deviates from that for less common cases). > > If you're only dealing with non-local named functions and types plus ordinary type composition and exclude function templates (or at least, function templates with dependent expressions in the signature), it's probably not too hard (i.e., just a day or a few days work) to code up a mangler. If more is needed (local types, decltype, lambdas, etc.), it gets messier quite quickly. > > DaveedClang contains a mangler. You just have to extract the code into a standalone tool. Sebastian
On 15 February 2011 08:10, Patrick Simmons <simmon12 at illinois.edu> wrote:> I have encountered a need for manually generating the mangled name of an > arbitrary C++ function. The only way I currently know how to do this is > to generate a dummy C++ source file, compile it, and look at the > output. This approach is so ugly that I would like for it never to see > the light of day. The c++filt tool generates demangled C++ names given > the mangled ones, which is the opposite of what I want to do. Does > anyone know how to "run c++filt in reverse"? >It would be lovely to have a declspec that adds an additional user given to label routines if required. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110218/77952018/attachment.html>