void* DynamicLibrary::SearchForAddressOfSymbol(const char *symbolName) {
  SmartScopedLock<true> Lock(*SymbolsMutex);

  // First check symbols added via AddSymbol().
  if (ExplicitSymbols.isConstructed()) {
    StringMap<void *>::iterator i = ExplicitSymbols->find(symbolName);

    if (i != ExplicitSymbols->end())
      return i->second;
  }

#if HAVE_DLFCN_H
  // Now search the libraries.
  if (OpenedHandles) {
    for (DenseSet<void *>::iterator I = OpenedHandles->begin(),
         E = OpenedHandles->end(); I != E; ++I) {
      //lt_ptr ptr = lt_dlsym(*I, symbolName);
      void *ptr = dlsym(*I, symbolName);
      if (ptr) {
        return ptr;
      }
    }
  }
#endif

  if (void *Result = llvm::SearchForAddressOfSpecialSymbol(symbolName))
    return Result;

// This macro returns the address of a well-known, explicit symbol
#define EXPLICIT_SYMBOL(SYM) \
   if (!strcmp(symbolName, #SYM)) return &SYM

// On linux we have a weird situation. The stderr/out/in symbols are both
// macros and global variables because of standards requirements. So, we
// boldly use the EXPLICIT_SYMBOL macro without checking for a #define first.
#if defined(__linux__) and !defined(__ANDROID__) and !defined(__ELLCC__)
  {
    EXPLICIT_SYMBOL(stderr);
    EXPLICIT_SYMBOL(stdout);
    EXPLICIT_SYMBOL(stdin);
  }
#else
  // For everything else, we want to check to make sure the symbol isn't defined
  // as a macro before using EXPLICIT_SYMBOL.
  {
#ifndef stdin
    EXPLICIT_SYMBOL(stdin);
#endif
#ifndef stdout
    EXPLICIT_SYMBOL(stdout);
#endif
#ifndef stderr
    EXPLICIT_SYMBOL(stderr);
#endif
  }
#endif
#undef EXPLICIT_SYMBOL

  return nullptr;
}
Exemple #2
0
/// Return the type returned by DtoUnpaddedStruct called on a value of the
/// specified type.
/// Union types will get expanded into a struct, with a type for each member.
LLType* DtoUnpaddedStructType(Type* dty) {
    assert(dty->ty == Tstruct);

    typedef llvm::DenseMap<Type*, llvm::StructType*> CacheT;
    static llvm::ManagedStatic<CacheT> cache;
    CacheT::iterator it = cache->find(dty);
    if (it != cache->end())
        return it->second;

    TypeStruct* sty = static_cast<TypeStruct*>(dty);
    VarDeclarations& fields = sty->sym->fields;

    std::vector<LLType*> types;
    types.reserve(fields.dim);

    for (unsigned i = 0; i < fields.dim; i++) {
        LLType* fty;
        if (fields[i]->type->ty == Tstruct) {
            // Nested structs are the only members that can contain padding
            fty = DtoUnpaddedStructType(fields[i]->type);
        } else {
            fty = DtoType(fields[i]->type);
        }
        types.push_back(fty);
    }
    LLStructType* Ty = LLStructType::get(gIR->context(), types);
    cache->insert(std::make_pair(dty, Ty));
    return Ty;
}
Exemple #3
0
LDSymbol* LDSymbol::Null() {
  // lazy initialization
  if (g_NullSymbol->resolveInfo() == NULL) {
    g_NullSymbol->setResolveInfo(*ResolveInfo::Null());
    g_NullSymbol->setFragmentRef(FragmentRef::Create(*g_NullSymbolFragment, 0));
    ResolveInfo::Null()->setSymPtr(&*g_NullSymbol);
  }
  return &*g_NullSymbol;
}
Exemple #4
0
/// Create - create a fragment reference for a given fragment.
///
/// @param pFrag - the given fragment
/// @param pOffset - the offset, can be larger than the fragment, but can not
///                  be larger than the section size.
/// @return if the offset is legal, return the fragment reference. Otherwise,
/// return NULL.
FragmentRef* FragmentRef::Create(Fragment& pFrag, uint64_t pOffset) {
  int64_t offset = pOffset;
  Fragment* frag = &pFrag;

  while (frag != NULL) {
    offset -= frag->size();
    if (offset <= 0)
      break;
    frag = frag->getNextNode();
  }
  if ((frag != NULL) && (frag->size() != 0)) {
    if (offset == 0)
      frag = frag->getNextNode();
    else
      offset += frag->size();
  }

  if (frag == NULL)
    return Null();

  FragmentRef* result = g_FragRefFactory->allocate();
  new (result) FragmentRef(*frag, offset);

  return result;
}
Exemple #5
0
namespace mcld {

typedef GCFactory<NameSpec, MCLD_SYMBOLS_PER_INPUT> NameSpecFactory;
static llvm::ManagedStatic<NameSpecFactory> g_NameSpecFactory;

//===----------------------------------------------------------------------===//
// NameSpec
//===----------------------------------------------------------------------===//
NameSpec::NameSpec() {
}

NameSpec::NameSpec(const std::string& pName, bool pAsNeeded)
    : InputToken(InputToken::NameSpec, pName, pAsNeeded) {
}

NameSpec::~NameSpec() {
}

NameSpec* NameSpec::create(const std::string& pName, bool pAsNeeded) {
  NameSpec* result = g_NameSpecFactory->allocate();
  new (result) NameSpec(pName, pAsNeeded);
  return result;
}

void NameSpec::destroy(NameSpec*& pNameSpec) {
  g_NameSpecFactory->destroy(pNameSpec);
  g_NameSpecFactory->deallocate(pNameSpec);
  pNameSpec = NULL;
}

void NameSpec::clear() {
  g_NameSpecFactory->clear();
}

}  // namespace mcld
namespace mcld {

typedef GCFactory<SectionData, MCLD_SECTIONS_PER_INPUT> SectDataFactory;

static llvm::ManagedStatic<SectDataFactory> g_SectDataFactory;

//===----------------------------------------------------------------------===//
// SectionData
//===----------------------------------------------------------------------===//
SectionData::SectionData() : m_pSection(NULL) {
}

SectionData::SectionData(LDSection& pSection) : m_pSection(&pSection) {
}

SectionData* SectionData::Create(LDSection& pSection) {
  SectionData* result = g_SectDataFactory->allocate();
  new (result) SectionData(pSection);
  return result;
}

void SectionData::Destroy(SectionData*& pSection) {
  pSection->~SectionData();
  g_SectDataFactory->deallocate(pSection);
  pSection = NULL;
}

void SectionData::Clear() {
  g_SectDataFactory->clear();
}

}  // namespace mcld
Exemple #7
0
namespace mcld {

typedef GCFactory<StrToken, MCLD_SYMBOLS_PER_INPUT> StrTokenFactory;
static llvm::ManagedStatic<StrTokenFactory> g_StrTokenFactory;

//===----------------------------------------------------------------------===//
// StrToken
//===----------------------------------------------------------------------===//
StrToken::StrToken() : m_Kind(Unknown) {
}

StrToken::StrToken(Kind pKind, const std::string& pString)
    : m_Kind(pKind), m_Name(pString) {
}

StrToken::~StrToken() {
}

StrToken* StrToken::create(const std::string& pString) {
  StrToken* result = g_StrTokenFactory->allocate();
  new (result) StrToken(String, pString);
  return result;
}

void StrToken::destroy(StrToken*& pStrToken) {
  g_StrTokenFactory->destroy(pStrToken);
  g_StrTokenFactory->deallocate(pStrToken);
  pStrToken = NULL;
}

void StrToken::clear() {
  g_StrTokenFactory->clear();
}

}  // namespace mcld
Exemple #8
0
void
SBDebugger::Initialize ()
{
    Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));

    if (log)
        log->Printf ("SBDebugger::Initialize ()");

    g_debugger_lifetime->Initialize(llvm::make_unique<SystemInitializerFull>(), LoadPlugin);
}
Exemple #9
0
LDSection* LDSection::Create(const std::string& pName,
                             LDFileFormat::Kind pKind,
                             uint32_t pType,
                             uint32_t pFlag,
                             uint64_t pSize,
                             uint64_t pAddr) {
  LDSection* result = g_SectFactory->allocate();
  new (result) LDSection(pName, pKind, pType, pFlag, pSize, pAddr);
  return result;
}
Exemple #10
0
  DebugPrintEnabler(unsigned PassNumber) {
#ifndef NDEBUG
    OldDebugFlag = llvm::DebugFlag;
    if (llvm::DebugFlag)
      return;
    if (DebugPassNumbers->empty())
      return;
    // Enable debug printing if the pass number matches
    // one of the pass numbers provided as a command line option.
    for (auto DebugPassNumber : *DebugPassNumbers) {
      if (DebugPassNumber == PassNumber) {
        llvm::DebugFlag = true;
        return;
      }
    }
#endif
  }
Exemple #11
0
namespace mcld {

typedef GCFactory<RelocData, MCLD_SECTIONS_PER_INPUT> RelocDataFactory;

static llvm::ManagedStatic<RelocDataFactory> g_RelocDataFactory;

//===----------------------------------------------------------------------===//
// RelocData
//===----------------------------------------------------------------------===//
RelocData::RelocData() : m_pSection(NULL) {
}

RelocData::RelocData(LDSection& pSection) : m_pSection(&pSection) {
}

RelocData* RelocData::Create(LDSection& pSection) {
  RelocData* result = g_RelocDataFactory->allocate();
  new (result) RelocData(pSection);
  return result;
}

void RelocData::Destroy(RelocData*& pSection) {
  pSection->~RelocData();
  g_RelocDataFactory->deallocate(pSection);
  pSection = NULL;
}

void RelocData::Clear() {
  g_RelocDataFactory->clear();
}

RelocData& RelocData::append(Relocation& pRelocation) {
  m_Relocations.push_back(&pRelocation);
  return *this;
}

Relocation& RelocData::remove(Relocation& pRelocation) {
  iterator iter(pRelocation);
  Relocation* rel = m_Relocations.remove(iter);
  return *rel;
}

}  // namespace mcld
namespace mcld {

typedef GCFactory<StringList, MCLD_SYMBOLS_PER_INPUT> StringListFactory;
static llvm::ManagedStatic<StringListFactory> g_StringListFactory;

//===----------------------------------------------------------------------===//
// StringList
//===----------------------------------------------------------------------===//
StringList::StringList() {
}

StringList::~StringList() {
}

void StringList::push_back(StrToken* pToken) {
  m_Tokens.push_back(pToken);
}

void StringList::dump() const {
  for (const_iterator it = begin(), ie = end(); it != ie; ++it)
    mcld::outs() << (*it)->name() << "\t";
  mcld::outs() << "\n";
}

StringList* StringList::create() {
  StringList* result = g_StringListFactory->allocate();
  new (result) StringList();
  return result;
}

void StringList::destroy(StringList*& pStringList) {
  g_StringListFactory->destroy(pStringList);
  g_StringListFactory->deallocate(pStringList);
  pStringList = NULL;
}

void StringList::clear() {
  g_StringListFactory->clear();
}

}  // namespace mcld
Exemple #13
0
FragOperand* FragOperand::create(Fragment& pFragment) {
  FragOperand* result = g_FragOperandFactory->allocate();
  new (result) FragOperand(pFragment);
  return result;
}
Exemple #14
0
void SectDescOperand::clear() {
  g_SectDescOperandFactory->clear();
}
Exemple #15
0
void SectDescOperand::destroy(SectDescOperand*& pOperand) {
  g_SectDescOperandFactory->destroy(pOperand);
  g_SectDescOperandFactory->deallocate(pOperand);
  pOperand = NULL;
}
Exemple #16
0
SectDescOperand* SectDescOperand::create(
    const SectionMap::Output* pOutputDesc) {
  SectDescOperand* result = g_SectDescOperandFactory->allocate();
  new (result) SectDescOperand(pOutputDesc);
  return result;
}
Exemple #17
0
void EhFrame::Clear()
{
  g_EhFrameFactory->clear();
}
Exemple #18
0
void EhFrame::Destroy(EhFrame*& pSection)
{
  pSection->~EhFrame();
  g_EhFrameFactory->deallocate(pSection);
  pSection = NULL;
}
Exemple #19
0
void IntOperand::destroy(IntOperand*& pOperand) {
  g_IntOperandFactory->destroy(pOperand);
  g_IntOperandFactory->deallocate(pOperand);
  pOperand = NULL;
}
Exemple #20
0
void SymOperand::clear() {
  g_SymOperandFactory->clear();
}
Exemple #21
0
SymOperand* SymOperand::create(const std::string& pName) {
  SymOperand* result = g_SymOperandFactory->allocate();
  new (result) SymOperand(pName);
  return result;
}
Exemple #22
0
void FragOperand::destroy(FragOperand*& pOperand) {
  g_FragOperandFactory->destroy(pOperand);
  g_FragOperandFactory->deallocate(pOperand);
  pOperand = NULL;
}
Exemple #23
0
void FragOperand::clear() {
  g_FragOperandFactory->clear();
}
Exemple #24
0
RelocData* RelocData::Create(LDSection& pSection) {
  RelocData* result = g_RelocDataFactory->allocate();
  new (result) RelocData(pSection);
  return result;
}
Exemple #25
0
void SymOperand::destroy(SymOperand*& pOperand) {
  g_SymOperandFactory->destroy(pOperand);
  g_SymOperandFactory->deallocate(pOperand);
  pOperand = NULL;
}
Exemple #26
0
void RelocData::Destroy(RelocData*& pSection) {
  pSection->~RelocData();
  g_RelocDataFactory->deallocate(pSection);
  pSection = NULL;
}
Exemple #27
0
IntOperand* IntOperand::create(uint64_t pValue) {
  IntOperand* result = g_IntOperandFactory->allocate();
  new (result) IntOperand(pValue);
  return result;
}
Exemple #28
0
void RelocData::Clear() {
  g_RelocDataFactory->clear();
}
Exemple #29
0
void IntOperand::clear() {
  g_IntOperandFactory->clear();
}
Exemple #30
0
EhFrame* EhFrame::Create(LDSection& pSection)
{
  EhFrame* result = g_EhFrameFactory->allocate();
  new (result) EhFrame(pSection);
  return result;
}