LLVM  4.0.0
ELFObjectFile.cpp
Go to the documentation of this file.
1 //===- ELFObjectFile.cpp - ELF object file implementation -------*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Part of the ELFObjectFile class implementation.
11 //
12 //===----------------------------------------------------------------------===//
13 
16 
17 namespace llvm {
18 using namespace object;
19 
21  : ObjectFile(Type, Source) {}
22 
25  std::pair<unsigned char, unsigned char> Ident =
27  std::size_t MaxAlignment =
28  1ULL << countTrailingZeros(uintptr_t(Obj.getBufferStart()));
29 
30  if (MaxAlignment < 2)
32 
33  std::error_code EC;
34  std::unique_ptr<ObjectFile> R;
35  if (Ident.first == ELF::ELFCLASS32) {
36  if (Ident.second == ELF::ELFDATA2LSB)
37  R.reset(new ELFObjectFile<ELFType<support::little, false>>(Obj, EC));
38  else if (Ident.second == ELF::ELFDATA2MSB)
39  R.reset(new ELFObjectFile<ELFType<support::big, false>>(Obj, EC));
40  else
42  } else if (Ident.first == ELF::ELFCLASS64) {
43  if (Ident.second == ELF::ELFDATA2LSB)
44  R.reset(new ELFObjectFile<ELFType<support::little, true>>(Obj, EC));
45  else if (Ident.second == ELF::ELFDATA2MSB)
46  R.reset(new ELFObjectFile<ELFType<support::big, true>>(Obj, EC));
47  else
49  } else {
51  }
52 
53  if (EC)
54  return EC;
55  return std::move(R);
56 }
57 
59  switch (getEMachine()) {
60  case ELF::EM_MIPS: {
62  unsigned PlatformFlags;
63  getPlatformFlags(PlatformFlags);
64 
65  switch (PlatformFlags & ELF::EF_MIPS_ARCH) {
67  break;
69  Features.AddFeature("mips2");
70  break;
72  Features.AddFeature("mips3");
73  break;
75  Features.AddFeature("mips4");
76  break;
78  Features.AddFeature("mips5");
79  break;
81  Features.AddFeature("mips32");
82  break;
84  Features.AddFeature("mips64");
85  break;
87  Features.AddFeature("mips32r2");
88  break;
90  Features.AddFeature("mips64r2");
91  break;
93  Features.AddFeature("mips32r6");
94  break;
96  Features.AddFeature("mips64r6");
97  break;
98  default:
99  llvm_unreachable("Unknown EF_MIPS_ARCH value");
100  }
101 
102  switch (PlatformFlags & ELF::EF_MIPS_MACH) {
104  // No feature associated with this value.
105  break;
107  Features.AddFeature("cnmips");
108  break;
109  default:
110  llvm_unreachable("Unknown EF_MIPS_ARCH value");
111  }
112 
113  if (PlatformFlags & ELF::EF_MIPS_ARCH_ASE_M16)
114  Features.AddFeature("mips16");
115  if (PlatformFlags & ELF::EF_MIPS_MICROMIPS)
116  Features.AddFeature("micromips");
117 
118  return Features;
119  }
120  default:
121  return SubtargetFeatures();
122  }
123 }
124 
125 } // end namespace llvm
Represents either an error or a value T.
Definition: ErrorOr.h:68
virtual uint16_t getEMachine() const =0
SubtargetFeatures getFeatures() const override
This class is the base class for all object file types.
Definition: ObjectFile.h:178
const char * getBufferStart() const
Definition: MemoryBuffer.h:173
static ErrorOr< std::unique_ptr< ObjectFile > > createELFObjectFile(MemoryBufferRef Object)
void AddFeature(StringRef String, bool Enable=true)
Adding Features.
std::pair< unsigned char, unsigned char > getElfArchType(StringRef Object)
Definition: Object/ELF.h:28
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
Definition: MathExtras.h:111
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:45
virtual std::error_code getPlatformFlags(unsigned &Result) const
Returns platform-specific object flags, if any.
Definition: ObjectFile.h:270
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
StringRef getBuffer() const
Definition: MemoryBuffer.h:169
SubtargetFeatures - Manages the enabling and disabling of subtarget specific features.
ELFObjectFileBase(unsigned int Type, MemoryBufferRef Source)
const FeatureBitset Features