llvm-6502/lib/System/SearchForAddressOfSpecialSymbol.cpp
Daniel Dunbar 7ca6e73e7f System: Don't reexport ___eprintf when building with Clang; this symbol isn't
used on Darwin anymore, and Clang might not always link with the library it is
currently found in.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@114165 91177308-0d34-0410-b5e6-96231b3b80d8
2010-09-17 04:25:24 +00:00

72 lines
2.1 KiB
C++

//===- SearchForAddressOfSpecialSymbol.cpp - Function addresses -*- C++ -*-===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file pulls the addresses of certain symbols out of the linker. It must
// include as few header files as possible because it declares the symbols as
// void*, which would conflict with the actual symbol type if any header
// declared it.
//
//===----------------------------------------------------------------------===//
#include <string.h>
// Must declare the symbols in the global namespace.
static void *DoSearch(const char* symbolName) {
#define EXPLICIT_SYMBOL(SYM) \
extern void *SYM; if (!strcmp(symbolName, #SYM)) return &SYM
// If this is darwin, it has some funky issues, try to solve them here. Some
// important symbols are marked 'private external' which doesn't allow
// SearchForAddressOfSymbol to find them. As such, we special case them here,
// there is only a small handful of them.
#ifdef __APPLE__
{
EXPLICIT_SYMBOL(__ashldi3);
EXPLICIT_SYMBOL(__ashrdi3);
EXPLICIT_SYMBOL(__cmpdi2);
EXPLICIT_SYMBOL(__divdi3);
// Clang doesn't always link against libgcc.a, which is the only thing which
// defines ___eprintf in the modern world. Just don't attempt to export this
// symbol when building with Clang.
#ifndef __clang__
EXPLICIT_SYMBOL(__eprintf);
#endif
EXPLICIT_SYMBOL(__fixdfdi);
EXPLICIT_SYMBOL(__fixsfdi);
EXPLICIT_SYMBOL(__fixunsdfdi);
EXPLICIT_SYMBOL(__fixunssfdi);
EXPLICIT_SYMBOL(__floatdidf);
EXPLICIT_SYMBOL(__floatdisf);
EXPLICIT_SYMBOL(__lshrdi3);
EXPLICIT_SYMBOL(__moddi3);
EXPLICIT_SYMBOL(__udivdi3);
EXPLICIT_SYMBOL(__umoddi3);
}
#endif
#ifdef __CYGWIN__
{
EXPLICIT_SYMBOL(_alloca);
EXPLICIT_SYMBOL(__main);
}
#endif
#undef EXPLICIT_SYMBOL
return 0;
}
namespace llvm {
void *SearchForAddressOfSpecialSymbol(const char* symbolName) {
return DoSearch(symbolName);
}
} // namespace llvm