LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SearchForAddressOfSpecialSymbol.cpp
Go to the documentation of this file.
1 //===- SearchForAddressOfSpecialSymbol.cpp - Function addresses -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file pulls the addresses of certain symbols out of the linker. It must
11 // include as few header files as possible because it declares the symbols as
12 // void*, which would conflict with the actual symbol type if any header
13 // declared it.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #include <string.h>
18 
19 // Must declare the symbols in the global namespace.
20 static void *DoSearch(const char* symbolName) {
21 #define EXPLICIT_SYMBOL(SYM) \
22  extern void *SYM; if (!strcmp(symbolName, #SYM)) return &SYM
23 
24  // If this is darwin, it has some funky issues, try to solve them here. Some
25  // important symbols are marked 'private external' which doesn't allow
26  // SearchForAddressOfSymbol to find them. As such, we special case them here,
27  // there is only a small handful of them.
28 
29 #ifdef __APPLE__
30  {
31  // __eprintf is sometimes used for assert() handling on x86.
32  //
33  // FIXME: Currently disabled when using Clang, as we don't always have our
34  // runtime support libraries available.
35 #ifndef __clang__
36 #ifdef __i386__
37  EXPLICIT_SYMBOL(__eprintf);
38 #endif
39 #endif
40  }
41 #endif
42 
43 #ifdef __CYGWIN__
44  {
45  EXPLICIT_SYMBOL(_alloca);
46  EXPLICIT_SYMBOL(__main);
47  }
48 #endif
49 
50 #undef EXPLICIT_SYMBOL
51  return 0;
52 }
53 
54 namespace llvm {
55 void *SearchForAddressOfSpecialSymbol(const char* symbolName) {
56  return DoSearch(symbolName);
57 }
58 } // namespace llvm
#define EXPLICIT_SYMBOL(SYM)
void * SearchForAddressOfSpecialSymbol(const char *symbolName)
static void * DoSearch(const char *symbolName)