2013-01-22 10:15:30 +08:00
|
|
|
//===- lib/ReaderWriter/MachO/MachOTargetInfo.cpp -------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "lld/ReaderWriter/MachOTargetInfo.h"
|
|
|
|
|
|
|
|
#include "lld/Core/LinkerOptions.h"
|
|
|
|
|
|
|
|
#include "llvm/ADT/Triple.h"
|
|
|
|
#include "llvm/Support/MachO.h"
|
|
|
|
|
|
|
|
namespace lld {
|
|
|
|
uint32_t MachOTargetInfo::getCPUType() const {
|
|
|
|
switch (getTriple().getArch()) {
|
|
|
|
case llvm::Triple::x86:
|
|
|
|
return llvm::MachO::CPUTypeI386;
|
|
|
|
case llvm::Triple::x86_64:
|
|
|
|
return llvm::MachO::CPUTypeX86_64;
|
|
|
|
case llvm::Triple::arm:
|
|
|
|
return llvm::MachO::CPUTypeARM;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown arch type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t MachOTargetInfo::getCPUSubType() const {
|
|
|
|
switch (getTriple().getArch()) {
|
|
|
|
case llvm::Triple::x86:
|
|
|
|
return llvm::MachO::CPUSubType_I386_ALL;
|
|
|
|
case llvm::Triple::x86_64:
|
|
|
|
return llvm::MachO::CPUSubType_X86_64_ALL;
|
|
|
|
case llvm::Triple::arm:
|
|
|
|
return llvm::MachO::CPUSubType_ARM_ALL;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown arch type");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-23 09:18:43 +08:00
|
|
|
bool MachOTargetInfo::addEntryPointLoadCommand() const {
|
|
|
|
switch (_options._outputKind) {
|
|
|
|
case OutputKind::Executable:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MachOTargetInfo::addUnixThreadLoadCommand() const {
|
|
|
|
switch (_options._outputKind) {
|
|
|
|
case OutputKind::Executable:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class GenericMachOTargetInfo LLVM_FINAL : public MachOTargetInfo {
|
2013-01-22 10:15:30 +08:00
|
|
|
public:
|
|
|
|
GenericMachOTargetInfo(const LinkerOptions &lo) : MachOTargetInfo(lo) {}
|
|
|
|
|
|
|
|
virtual uint64_t getPageSize() const { return 0x1000; }
|
|
|
|
virtual uint64_t getPageZeroSize() const { return getPageSize(); }
|
|
|
|
|
|
|
|
virtual StringRef getEntry() const {
|
2013-01-23 09:18:43 +08:00
|
|
|
if (_options._outputKind != OutputKind::Executable)
|
|
|
|
return "";
|
2013-01-22 10:15:30 +08:00
|
|
|
if (!_options._entrySymbol.empty())
|
|
|
|
return _options._entrySymbol;
|
|
|
|
return "_main";
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<MachOTargetInfo>
|
|
|
|
MachOTargetInfo::create(const LinkerOptions &lo) {
|
|
|
|
return std::unique_ptr<MachOTargetInfo>(new GenericMachOTargetInfo(lo));
|
|
|
|
}
|
|
|
|
} // end namespace lld
|