Add Example Sub Target.

llvm-svn: 230594
This commit is contained in:
Michael J. Spencer 2015-02-26 00:48:10 +00:00
parent 6a272cdc83
commit 09358d247a
10 changed files with 165 additions and 0 deletions

View File

@ -27,6 +27,7 @@ LLVM_TARGET(ARM)
LLVM_TARGET(Hexagon)
LLVM_TARGET(Mips)
LLVM_TARGET(X86)
LLVM_TARGET(Example)
LLVM_TARGET(X86_64)
#undef LLVM_TARGET

View File

@ -28,6 +28,7 @@ add_llvm_library(lldDriver
lldHexagonELFTarget
lldMipsELFTarget
lldX86ELFTarget
lldExampleSubTarget
lldX86_64ELFTarget
lldCore
lldNative

View File

@ -353,6 +353,7 @@ GnuLdDriver::createELFLinkingContext(llvm::Triple triple) {
LLVM_TARGET(Hexagon)
LLVM_TARGET(Mips)
LLVM_TARGET(X86)
LLVM_TARGET(Example)
LLVM_TARGET(X86_64)
#undef LLVM_TARGET
return nullptr;

View File

@ -9,3 +9,5 @@ add_llvm_library(lldX86_64ELFTarget
LLVMObject
LLVMSupport
)
add_subdirectory(ExampleSubTarget)

View File

@ -0,0 +1,6 @@
add_llvm_library(lldExampleSubTarget
ExampleLinkingContext.cpp
ExampleTargetHandler.cpp
LINK_LIBS
lldX86_64ELFTarget
)

View File

@ -0,0 +1,36 @@
//===- lib/ReaderWriter/ELF/X86_64/ExampleTarget/ExampleLinkingContext.cpp ----===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "ExampleLinkingContext.h"
#include "ExampleTargetHandler.h"
using namespace lld;
using namespace elf;
std::unique_ptr<ELFLinkingContext>
ExampleLinkingContext::create(llvm::Triple triple) {
if (triple.getVendorName() == "example")
return llvm::make_unique<ExampleLinkingContext>(triple);
return nullptr;
}
ExampleLinkingContext::ExampleLinkingContext(llvm::Triple triple)
: X86_64LinkingContext(triple, std::unique_ptr<TargetHandlerBase>(
new ExampleTargetHandler(*this))) {
_outputELFType = llvm::ELF::ET_LOPROC;
}
StringRef ExampleLinkingContext::entrySymbolName() const {
return "_start";
}
void ExampleLinkingContext::addPasses(PassManager &p) {
ELFLinkingContext::addPasses(p);
}

View File

@ -0,0 +1,31 @@
//===- lib/ReaderWriter/ELF/X86_64/ExampleTarget/ExampleLinkingContext.h --===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLD_READER_WRITER_ELF_X86_64_EXAMPLE_TARGET_EXAMPLE_LINKING_CONTEXT
#define LLD_READER_WRITER_ELF_X86_64_EXAMPLE_TARGET_EXAMPLE_LINKING_CONTEXT
#include "../X86_64LinkingContext.h"
#include "../X86_64TargetHandler.h"
namespace lld {
namespace elf {
class ExampleLinkingContext final : public X86_64LinkingContext {
public:
static std::unique_ptr<ELFLinkingContext> create(llvm::Triple);
ExampleLinkingContext(llvm::Triple triple);
StringRef entrySymbolName() const override;
void addPasses(PassManager &) override;
};
} // end namespace elf
} // end namespace lld
#endif

View File

@ -0,0 +1,24 @@
//===- lib/ReaderWriter/ELF/X86_64/ExampleTarget/ExampleTargetHandler.cpp -===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "ExampleTargetHandler.h"
#include "ExampleLinkingContext.h"
#include "../X86_64ExecutableWriter.h"
using namespace lld;
using namespace elf;
ExampleTargetHandler::ExampleTargetHandler(ExampleLinkingContext &c)
: X86_64TargetHandler(c), _exampleContext(c) {}
std::unique_ptr<Writer> ExampleTargetHandler::getWriter() {
return std::unique_ptr<Writer>(
new X86_64ExecutableWriter(_exampleContext, *_x86_64TargetLayout));
}

View File

@ -0,0 +1,31 @@
//===- lib/ReaderWriter/ELF/X86_64/ExampleTarget/ExampleTargetHandler.h ---===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLD_READER_WRITER_ELF_X86_64_EXAMPLE_TARGET_EXAMPLE_TARGET_HANDLER_H
#define LLD_READER_WRITER_ELF_X86_64_EXAMPLE_TARGET_EXAMPLE_TARGET_HANDLER_H
#include "../X86_64TargetHandler.h"
namespace lld {
namespace elf {
class ExampleLinkingContext;
class ExampleTargetHandler final : public X86_64TargetHandler {
public:
ExampleTargetHandler(ExampleLinkingContext &c);
std::unique_ptr<Writer> getWriter() override;
private:
ExampleLinkingContext &_exampleContext;
};
} // end namespace elf
} // end namespace lld
#endif

View File

@ -0,0 +1,32 @@
# Check that the Example Target is actually used.
# RUN: yaml2obj -format=elf %s -o %t.o
# RUN: lld -flavor gnu -target x86_64-example-freebsd9 %t.o -o %t.exe
# RUN: llvm-readobj -file-headers %t.exe | FileCheck %s
#
# CHECK: Type: 0xFF00
# object
FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
OSABI: ELFOSABI_GNU
Type: ET_REL
Machine: EM_X86_64
Sections:
- Name: .text
Type: SHT_PROGBITS
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
AddressAlign: 0x0000000000000010
Content: 554889E5B864000000C745FC000000005DC366666666662E0F1F840000000000554889E531C05DC3
Symbols:
Local:
- Name: .text
Type: STT_SECTION
Section: .text
Global:
- Name: _start
Type: STT_FUNC
Section: .text
Size: 0x0000000000000000