SearchForAddressOfSpecialSymbol.cpp revision 218885
1218885Sdim//===- SearchForAddressOfSpecialSymbol.cpp - Function addresses -*- C++ -*-===// 2218885Sdim// 3218885Sdim// The LLVM Compiler Infrastructure 4218885Sdim// 5218885Sdim// This file is distributed under the University of Illinois Open Source 6218885Sdim// License. See LICENSE.TXT for details. 7218885Sdim// 8218885Sdim//===----------------------------------------------------------------------===// 9218885Sdim// 10218885Sdim// This file pulls the addresses of certain symbols out of the linker. It must 11218885Sdim// include as few header files as possible because it declares the symbols as 12218885Sdim// void*, which would conflict with the actual symbol type if any header 13218885Sdim// declared it. 14218885Sdim// 15218885Sdim//===----------------------------------------------------------------------===// 16218885Sdim 17218885Sdim#include <string.h> 18218885Sdim 19218885Sdim// Must declare the symbols in the global namespace. 20218885Sdimstatic void *DoSearch(const char* symbolName) { 21218885Sdim#define EXPLICIT_SYMBOL(SYM) \ 22218885Sdim extern void *SYM; if (!strcmp(symbolName, #SYM)) return &SYM 23218885Sdim 24218885Sdim // If this is darwin, it has some funky issues, try to solve them here. Some 25218885Sdim // important symbols are marked 'private external' which doesn't allow 26218885Sdim // SearchForAddressOfSymbol to find them. As such, we special case them here, 27218885Sdim // there is only a small handful of them. 28218885Sdim 29218885Sdim#ifdef __APPLE__ 30218885Sdim { 31218885Sdim EXPLICIT_SYMBOL(__ashldi3); 32218885Sdim EXPLICIT_SYMBOL(__ashrdi3); 33218885Sdim EXPLICIT_SYMBOL(__cmpdi2); 34218885Sdim EXPLICIT_SYMBOL(__divdi3); 35218885Sdim EXPLICIT_SYMBOL(__fixdfdi); 36218885Sdim EXPLICIT_SYMBOL(__fixsfdi); 37218885Sdim EXPLICIT_SYMBOL(__fixunsdfdi); 38218885Sdim EXPLICIT_SYMBOL(__fixunssfdi); 39218885Sdim EXPLICIT_SYMBOL(__floatdidf); 40218885Sdim EXPLICIT_SYMBOL(__floatdisf); 41218885Sdim EXPLICIT_SYMBOL(__lshrdi3); 42218885Sdim EXPLICIT_SYMBOL(__moddi3); 43218885Sdim EXPLICIT_SYMBOL(__udivdi3); 44218885Sdim EXPLICIT_SYMBOL(__umoddi3); 45218885Sdim 46218885Sdim // __eprintf is sometimes used for assert() handling on x86. 47218885Sdim // 48218885Sdim // FIXME: Currently disabled when using Clang, as we don't always have our 49218885Sdim // runtime support libraries available. 50218885Sdim#ifndef __clang__ 51218885Sdim#ifdef __i386__ 52218885Sdim EXPLICIT_SYMBOL(__eprintf); 53218885Sdim#endif 54218885Sdim#endif 55218885Sdim } 56218885Sdim#endif 57218885Sdim 58218885Sdim#ifdef __CYGWIN__ 59218885Sdim { 60218885Sdim EXPLICIT_SYMBOL(_alloca); 61218885Sdim EXPLICIT_SYMBOL(__main); 62218885Sdim } 63218885Sdim#endif 64218885Sdim 65218885Sdim#undef EXPLICIT_SYMBOL 66218885Sdim return 0; 67218885Sdim} 68218885Sdim 69218885Sdimnamespace llvm { 70218885Sdimvoid *SearchForAddressOfSpecialSymbol(const char* symbolName) { 71218885Sdim return DoSearch(symbolName); 72218885Sdim} 73218885Sdim} // namespace llvm 74