2
0

SearchForAddressOfSpecialSymbol.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #include <string.h>
  17. // Must declare the symbols in the global namespace.
  18. static void *DoSearch(const char* symbolName) {
  19. #define EXPLICIT_SYMBOL(SYM) \
  20. extern void *SYM; if (!strcmp(symbolName, #SYM)) return &SYM
  21. // If this is darwin, it has some funky issues, try to solve them here. Some
  22. // important symbols are marked 'private external' which doesn't allow
  23. // SearchForAddressOfSymbol to find them. As such, we special case them here,
  24. // there is only a small handful of them.
  25. #ifdef __APPLE__
  26. {
  27. // __eprintf is sometimes used for assert() handling on x86.
  28. //
  29. // FIXME: Currently disabled when using Clang, as we don't always have our
  30. // runtime support libraries available.
  31. #ifndef __clang__
  32. #ifdef __i386__
  33. EXPLICIT_SYMBOL(__eprintf);
  34. #endif
  35. #endif
  36. }
  37. #endif
  38. #ifdef __CYGWIN__
  39. {
  40. EXPLICIT_SYMBOL(_alloca);
  41. EXPLICIT_SYMBOL(__main);
  42. }
  43. #endif
  44. #undef EXPLICIT_SYMBOL
  45. return nullptr;
  46. }
  47. namespace llvm {
  48. void *SearchForAddressOfSpecialSymbol(const char* symbolName) {
  49. return DoSearch(symbolName);
  50. }
  51. } // namespace llvm