2011-01-20 06:38:47 +00:00
|
|
|
//===- ELFObjectFile.cpp - ELF object file implementation -------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2012-02-12 06:12:10 +00:00
|
|
|
// Part of the ELFObjectFile class implementation.
|
2011-01-20 06:38:47 +00:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-08-08 22:27:13 +00:00
|
|
|
#include "llvm/Object/ELFObjectFile.h"
|
2013-01-04 20:36:28 +00:00
|
|
|
#include "llvm/Support/MathExtras.h"
|
2011-01-20 06:38:47 +00:00
|
|
|
|
2012-02-12 06:12:10 +00:00
|
|
|
namespace llvm {
|
|
|
|
using namespace object;
|
2011-09-08 20:52:17 +00:00
|
|
|
|
2014-08-19 18:44:46 +00:00
|
|
|
ELFObjectFileBase::ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source)
|
|
|
|
: ObjectFile(Type, Source) {}
|
2014-08-17 17:52:10 +00:00
|
|
|
|
2014-07-31 03:12:45 +00:00
|
|
|
ErrorOr<std::unique_ptr<ObjectFile>>
|
2014-08-19 18:44:46 +00:00
|
|
|
ObjectFile::createELFObjectFile(MemoryBufferRef Obj) {
|
2014-07-05 11:38:52 +00:00
|
|
|
std::pair<unsigned char, unsigned char> Ident =
|
2014-08-19 18:44:46 +00:00
|
|
|
getElfArchType(Obj.getBuffer());
|
2013-01-04 20:36:28 +00:00
|
|
|
std::size_t MaxAlignment =
|
2014-08-19 18:44:46 +00:00
|
|
|
1ULL << countTrailingZeros(uintptr_t(Obj.getBufferStart()));
|
2013-01-04 20:36:28 +00:00
|
|
|
|
2015-06-02 12:05:27 +00:00
|
|
|
if (MaxAlignment < 2)
|
|
|
|
return object_error::parse_failed;
|
|
|
|
|
2014-06-13 02:24:39 +00:00
|
|
|
std::error_code EC;
|
2014-03-06 05:51:42 +00:00
|
|
|
std::unique_ptr<ObjectFile> R;
|
2015-06-02 12:05:27 +00:00
|
|
|
if (Ident.first == ELF::ELFCLASS32) {
|
|
|
|
if (Ident.second == ELF::ELFDATA2LSB)
|
|
|
|
R.reset(new ELFObjectFile<ELFType<support::little, false>>(Obj, EC));
|
|
|
|
else if (Ident.second == ELF::ELFDATA2MSB)
|
|
|
|
R.reset(new ELFObjectFile<ELFType<support::big, false>>(Obj, EC));
|
|
|
|
else
|
2015-06-04 22:58:25 +00:00
|
|
|
return object_error::parse_failed;
|
2015-06-04 23:14:43 +00:00
|
|
|
} else if (Ident.first == ELF::ELFCLASS64) {
|
2015-06-02 12:05:27 +00:00
|
|
|
if (Ident.second == ELF::ELFDATA2LSB)
|
|
|
|
R.reset(new ELFObjectFile<ELFType<support::little, true>>(Obj, EC));
|
|
|
|
else if (Ident.second == ELF::ELFDATA2MSB)
|
|
|
|
R.reset(new ELFObjectFile<ELFType<support::big, true>>(Obj, EC));
|
|
|
|
else
|
2015-06-04 22:58:25 +00:00
|
|
|
return object_error::parse_failed;
|
2015-06-04 23:14:43 +00:00
|
|
|
} else {
|
|
|
|
return object_error::parse_failed;
|
2011-10-11 03:18:58 +00:00
|
|
|
}
|
2011-10-07 19:25:32 +00:00
|
|
|
|
2014-01-21 23:06:54 +00:00
|
|
|
if (EC)
|
|
|
|
return EC;
|
2014-07-31 03:12:45 +00:00
|
|
|
return std::move(R);
|
2011-09-08 20:52:17 +00:00
|
|
|
}
|
|
|
|
|
2016-06-16 09:17:03 +00:00
|
|
|
SubtargetFeatures ELFObjectFileBase::getFeatures() const {
|
|
|
|
switch (getEMachine()) {
|
|
|
|
case ELF::EM_MIPS: {
|
|
|
|
SubtargetFeatures Features;
|
|
|
|
unsigned PlatformFlags;
|
|
|
|
getPlatformFlags(PlatformFlags);
|
|
|
|
|
|
|
|
switch (PlatformFlags & ELF::EF_MIPS_ARCH) {
|
|
|
|
case ELF::EF_MIPS_ARCH_1:
|
|
|
|
break;
|
|
|
|
case ELF::EF_MIPS_ARCH_2:
|
|
|
|
Features.AddFeature("mips2");
|
|
|
|
break;
|
|
|
|
case ELF::EF_MIPS_ARCH_3:
|
|
|
|
Features.AddFeature("mips3");
|
|
|
|
break;
|
|
|
|
case ELF::EF_MIPS_ARCH_4:
|
|
|
|
Features.AddFeature("mips4");
|
|
|
|
break;
|
|
|
|
case ELF::EF_MIPS_ARCH_5:
|
|
|
|
Features.AddFeature("mips5");
|
|
|
|
break;
|
|
|
|
case ELF::EF_MIPS_ARCH_32:
|
|
|
|
Features.AddFeature("mips32");
|
|
|
|
break;
|
|
|
|
case ELF::EF_MIPS_ARCH_64:
|
|
|
|
Features.AddFeature("mips64");
|
|
|
|
break;
|
|
|
|
case ELF::EF_MIPS_ARCH_32R2:
|
|
|
|
Features.AddFeature("mips32r2");
|
|
|
|
break;
|
|
|
|
case ELF::EF_MIPS_ARCH_64R2:
|
|
|
|
Features.AddFeature("mips64r2");
|
|
|
|
break;
|
|
|
|
case ELF::EF_MIPS_ARCH_32R6:
|
|
|
|
Features.AddFeature("mips32r6");
|
|
|
|
break;
|
|
|
|
case ELF::EF_MIPS_ARCH_64R6:
|
|
|
|
Features.AddFeature("mips64r6");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown EF_MIPS_ARCH value");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (PlatformFlags & ELF::EF_MIPS_MACH) {
|
|
|
|
case ELF::EF_MIPS_MACH_NONE:
|
|
|
|
// No feature associated with this value.
|
|
|
|
break;
|
|
|
|
case ELF::EF_MIPS_MACH_OCTEON:
|
|
|
|
Features.AddFeature("cnmips");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
llvm_unreachable("Unknown EF_MIPS_ARCH value");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PlatformFlags & ELF::EF_MIPS_ARCH_ASE_M16)
|
|
|
|
Features.AddFeature("mips16");
|
|
|
|
if (PlatformFlags & ELF::EF_MIPS_MICROMIPS)
|
|
|
|
Features.AddFeature("micromips");
|
|
|
|
|
|
|
|
return Features;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return SubtargetFeatures();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-20 06:38:47 +00:00
|
|
|
} // end namespace llvm
|