forked from OSchip/llvm-project
parent
6a272cdc83
commit
09358d247a
|
@ -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
|
||||
|
|
|
@ -28,6 +28,7 @@ add_llvm_library(lldDriver
|
|||
lldHexagonELFTarget
|
||||
lldMipsELFTarget
|
||||
lldX86ELFTarget
|
||||
lldExampleSubTarget
|
||||
lldX86_64ELFTarget
|
||||
lldCore
|
||||
lldNative
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -9,3 +9,5 @@ add_llvm_library(lldX86_64ELFTarget
|
|||
LLVMObject
|
||||
LLVMSupport
|
||||
)
|
||||
|
||||
add_subdirectory(ExampleSubTarget)
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
add_llvm_library(lldExampleSubTarget
|
||||
ExampleLinkingContext.cpp
|
||||
ExampleTargetHandler.cpp
|
||||
LINK_LIBS
|
||||
lldX86_64ELFTarget
|
||||
)
|
|
@ -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);
|
||||
}
|
|
@ -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
|
|
@ -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));
|
||||
}
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue