diff options
author | dim <dim@FreeBSD.org> | 2015-12-30 11:46:15 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2015-12-30 11:46:15 +0000 |
commit | e194cd6d03d91631334d9d5e55b506036f423cc8 (patch) | |
tree | fcfbb4df56a744f4ddc6122c50521dd3f1c5e196 /unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp | |
parent | 1f8fab1f5d4699e0d1676fd4e5150ed8635f5035 (diff) | |
download | FreeBSD-src-e194cd6d03d91631334d9d5e55b506036f423cc8.zip FreeBSD-src-e194cd6d03d91631334d9d5e55b506036f423cc8.tar.gz |
Vendor import of llvm trunk r256633:
https://llvm.org/svn/llvm-project/llvm/trunk@256633
Diffstat (limited to 'unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp')
-rw-r--r-- | unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp b/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp new file mode 100644 index 0000000..a37177c --- /dev/null +++ b/unittests/ExecutionEngine/Orc/ObjectLinkingLayerTest.cpp @@ -0,0 +1,94 @@ +//===-- ObjectLinkingLayerTest.cpp - Unit tests for object linking layer --===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "llvm/ExecutionEngine/ExecutionEngine.h" +#include "llvm/ExecutionEngine/SectionMemoryManager.h" +#include "llvm/ExecutionEngine/Orc/CompileUtils.h" +#include "llvm/ExecutionEngine/Orc/LambdaResolver.h" +#include "llvm/ExecutionEngine/Orc/ObjectLinkingLayer.h" +#include "llvm/IR/Constants.h" +#include "llvm/IR/LLVMContext.h" +#include "gtest/gtest.h" + +using namespace llvm; +using namespace llvm::orc; + +namespace { + +TEST(ObjectLinkingLayerTest, TestSetProcessAllSections) { + + class SectionMemoryManagerWrapper : public SectionMemoryManager { + public: + SectionMemoryManagerWrapper(bool &DebugSeen) : DebugSeen(DebugSeen) {} + uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment, + unsigned SectionID, + StringRef SectionName, + bool IsReadOnly) override { + if (SectionName == ".debug_str") + DebugSeen = true; + return SectionMemoryManager::allocateDataSection(Size, Alignment, + SectionID, + SectionName, + IsReadOnly); + } + private: + bool DebugSeen; + }; + + ObjectLinkingLayer<> ObjLayer; + + auto M = llvm::make_unique<Module>("", getGlobalContext()); + M->setTargetTriple("x86_64-unknown-linux-gnu"); + Type *Int32Ty = IntegerType::get(getGlobalContext(), 32); + GlobalVariable *GV = + new GlobalVariable(*M, Int32Ty, false, GlobalValue::ExternalLinkage, + ConstantInt::get(Int32Ty, 42), "foo"); + + GV->setSection(".debug_str"); + + std::unique_ptr<TargetMachine> TM( + EngineBuilder().selectTarget(Triple(M->getTargetTriple()), "", "", + SmallVector<std::string, 1>())); + if (!TM) + return; + + auto OwningObj = SimpleCompiler(*TM)(*M); + std::vector<object::ObjectFile*> Objs; + Objs.push_back(OwningObj.getBinary()); + + bool DebugSectionSeen = false; + SectionMemoryManagerWrapper SMMW(DebugSectionSeen); + auto Resolver = + createLambdaResolver( + [](const std::string &Name) { + return RuntimeDyld::SymbolInfo(nullptr); + }, + [](const std::string &Name) { + return RuntimeDyld::SymbolInfo(nullptr); + }); + + { + // Test with ProcessAllSections = false (the default). + auto H = ObjLayer.addObjectSet(Objs, &SMMW, &*Resolver); + EXPECT_EQ(DebugSectionSeen, false) + << "Unexpected debug info section"; + ObjLayer.removeObjectSet(H); + } + + { + // Test with ProcessAllSections = true. + ObjLayer.setProcessAllSections(true); + auto H = ObjLayer.addObjectSet(Objs, &SMMW, &*Resolver); + EXPECT_EQ(DebugSectionSeen, true) + << "Expected debug info section not seen"; + ObjLayer.removeObjectSet(H); + } +} + +} |