blob: 2fcc3401c363a363a4a4a8e4e1b14f8cafba0eab [file] [log] [blame]
Jeffrey Yasskin62207542010-03-11 06:14:32 +00001//===- 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.
20static 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 EXPLICIT_SYMBOL(__ashldi3);
32 EXPLICIT_SYMBOL(__ashrdi3);
33 EXPLICIT_SYMBOL(__cmpdi2);
34 EXPLICIT_SYMBOL(__divdi3);
Daniel Dunbar7ca6e732010-09-17 04:25:24 +000035
36 // Clang doesn't always link against libgcc.a, which is the only thing which
37 // defines ___eprintf in the modern world. Just don't attempt to export this
38 // symbol when building with Clang.
39#ifndef __clang__
Jeffrey Yasskin62207542010-03-11 06:14:32 +000040 EXPLICIT_SYMBOL(__eprintf);
Daniel Dunbar7ca6e732010-09-17 04:25:24 +000041#endif
42
Jeffrey Yasskin62207542010-03-11 06:14:32 +000043 EXPLICIT_SYMBOL(__fixdfdi);
44 EXPLICIT_SYMBOL(__fixsfdi);
45 EXPLICIT_SYMBOL(__fixunsdfdi);
46 EXPLICIT_SYMBOL(__fixunssfdi);
47 EXPLICIT_SYMBOL(__floatdidf);
48 EXPLICIT_SYMBOL(__floatdisf);
49 EXPLICIT_SYMBOL(__lshrdi3);
50 EXPLICIT_SYMBOL(__moddi3);
51 EXPLICIT_SYMBOL(__udivdi3);
52 EXPLICIT_SYMBOL(__umoddi3);
53 }
54#endif
55
56#ifdef __CYGWIN__
57 {
58 EXPLICIT_SYMBOL(_alloca);
59 EXPLICIT_SYMBOL(__main);
60 }
61#endif
62
63#undef EXPLICIT_SYMBOL
64 return 0;
65}
66
67namespace llvm {
68void *SearchForAddressOfSpecialSymbol(const char* symbolName) {
69 return DoSearch(symbolName);
70}
71} // namespace llvm