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 // __eprintf is sometimes used for assert() handling on x86. 32218885Sdim // 33218885Sdim // FIXME: Currently disabled when using Clang, as we don't always have our 34218885Sdim // runtime support libraries available. 35218885Sdim#ifndef __clang__ 36218885Sdim#ifdef __i386__ 37218885Sdim EXPLICIT_SYMBOL(__eprintf); 38218885Sdim#endif 39218885Sdim#endif 40218885Sdim } 41218885Sdim#endif 42218885Sdim 43218885Sdim#ifdef __CYGWIN__ 44218885Sdim { 45218885Sdim EXPLICIT_SYMBOL(_alloca); 46218885Sdim EXPLICIT_SYMBOL(__main); 47218885Sdim } 48218885Sdim#endif 49218885Sdim 50218885Sdim#undef EXPLICIT_SYMBOL 51218885Sdim return 0; 52218885Sdim} 53218885Sdim 54218885Sdimnamespace llvm { 55218885Sdimvoid *SearchForAddressOfSpecialSymbol(const char* symbolName) { 56218885Sdim return DoSearch(symbolName); 57218885Sdim} 58218885Sdim} // namespace llvm 59