llvm-project/lld/lib/ReaderWriter/ELF/ELFTargetInfo.cpp
Michael J. Spencer 64afcb4c6b Move everything over to TargetInfo.
I really would have liked to split this patch up, but it would greatly
complicate the lld-core and lld drivers having to deal with both
{Reader,Writer}Option and TargetInfo.

llvm-svn: 173217
2013-01-23 01:18:43 +00:00

89 lines
2.5 KiB
C++

//===- lib/ReaderWriter/ELF/ELFTargetInfo.cpp -----------------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "lld/ReaderWriter/ELFTargetInfo.h"
#include "lld/Core/LinkerOptions.h"
#include "llvm/ADT/Triple.h"
#include "llvm/Support/ELF.h"
namespace lld {
uint16_t ELFTargetInfo::getOutputType() const {
switch (_options._outputKind) {
case OutputKind::Executable:
return llvm::ELF::ET_EXEC;
case OutputKind::Relocatable:
return llvm::ELF::ET_REL;
case OutputKind::Shared:
return llvm::ELF::ET_DYN;
case OutputKind::Core:
return llvm::ELF::ET_CORE;
case OutputKind::SharedStubs:
case OutputKind::DebugSymbols:
case OutputKind::Bundle:
case OutputKind::Preload:
break;
}
llvm_unreachable("Unhandled OutputKind");
}
uint16_t ELFTargetInfo::getOutputMachine() const {
switch (getTriple().getArch()) {
case llvm::Triple::x86:
return llvm::ELF::EM_386;
case llvm::Triple::x86_64:
return llvm::ELF::EM_X86_64;
case llvm::Triple::hexagon:
return llvm::ELF::EM_HEXAGON;
case llvm::Triple::ppc:
return llvm::ELF::EM_PPC;
default:
llvm_unreachable("Unhandled arch");
}
}
class X86ELFTargetInfo LLVM_FINAL : public ELFTargetInfo {
public:
X86ELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {}
virtual uint64_t getPageSize() const { return 0x1000; }
};
class HexagonELFTargetInfo LLVM_FINAL : public ELFTargetInfo {
public:
HexagonELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {}
virtual uint64_t getPageSize() const { return 0x1000; }
};
class PPCELFTargetInfo LLVM_FINAL : public ELFTargetInfo {
public:
PPCELFTargetInfo(const LinkerOptions &lo) : ELFTargetInfo(lo) {}
virtual bool isLittleEndian() const { return false; }
virtual uint64_t getPageSize() const { return 0x1000; }
};
std::unique_ptr<ELFTargetInfo> ELFTargetInfo::create(const LinkerOptions &lo) {
switch (llvm::Triple(llvm::Triple::normalize(lo._target)).getArch()) {
case llvm::Triple::x86:
case llvm::Triple::x86_64:
return std::unique_ptr<ELFTargetInfo>(new X86ELFTargetInfo(lo));
case llvm::Triple::hexagon:
return std::unique_ptr<ELFTargetInfo>(new HexagonELFTargetInfo(lo));
case llvm::Triple::ppc:
return std::unique_ptr<ELFTargetInfo>(new PPCELFTargetInfo(lo));
default:
return std::unique_ptr<ELFTargetInfo>();
}
}
} // end namespace lld