get_mangled_names.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// Copyright (c) 2008, Google Inc. 227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// All rights reserved. 327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// 427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// Redistribution and use in source and binary forms, with or without 527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// modification, are permitted provided that the following conditions are 627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// met: 727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// 827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// * Redistributions of source code must retain the above copyright 927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// notice, this list of conditions and the following disclaimer. 1027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// * Redistributions in binary form must reproduce the above 1127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// copyright notice, this list of conditions and the following disclaimer 1227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// in the documentation and/or other materials provided with the 1327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// distribution. 1427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// * Neither the name of Google Inc. nor the names of its 1527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// contributors may be used to endorse or promote products derived from 1627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// this software without specific prior written permission. 1727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// 1827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// 3027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// --- 3127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// Author: Craig Silverstein (opensource@google.com) 3227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi 3327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// When you are porting perftools to a new compiler or architecture 343473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi// (win64 vs win32) for instance, you'll need to change the mangled 353473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi// symbol names for operator new and friends at the top of 363473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi// patch_functions.cc. This file helps you do that. 373473846f64f5b28e1cbeb70ef5867073fc93159eTakeshi Aimi// 3827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// It does this by defining these functions with the proper signature. 3927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// All you need to do is compile this file and the run dumpbin on it. 4027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// (See http://msdn.microsoft.com/en-us/library/5x49w699.aspx for more 4127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// on dumpbin). To do this in MSVC, use the MSVC commandline shell: 4227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// http://msdn.microsoft.com/en-us/library/ms235639(VS.80).aspx) 4327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// 4427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// The run: 4527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// cl /c get_mangled_names.cc 4627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// dumpbin /symbols get_mangled_names.obj 4727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// 4827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// It will print out the mangled (and associated unmangled) names of 4927ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi// the 8 symbols you need to put at the top of patch_functions.cc 5027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi 5127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <sys/types.h> // for size_t 5227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi#include <new> // for nothrow_t 5327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi 5427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshistatic char m; // some dummy memory so new doesn't return NULL. 5527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi 5627ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshivoid* operator new(size_t size) { return &m; } 5727ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshivoid operator delete(void* p) throw() { } 5827ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshivoid* operator new[](size_t size) { return &m; } 592272ee27d9022d173b6eab45c409b3c3f57f30ecTakeshi Aimivoid operator delete[](void* p) throw() { } 6027ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi 6127ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshivoid* operator new(size_t size, const std::nothrow_t&) throw() { return &m; } 6227ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshivoid operator delete(void* p, const std::nothrow_t&) throw() { } 6327ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshivoid* operator new[](size_t size, const std::nothrow_t&) throw() { return &m; } 6427ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshivoid operator delete[](void* p, const std::nothrow_t&) throw() { } 6527ed8ad2db653f6ac07dcf8bcc05e2409c8bb024aimitakeshi