mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-01 15:11:24 +00:00
f4ccd11075
This compiles with no changes to clang/lld/lldb with MSVC and includes overloads to various functions which are used by those projects and llvm which have OwningPtr's as parameters. This should allow out of tree projects some time to move. There are also no changes to libs/Target, which should help out of tree targets have time to move, if necessary. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@203083 91177308-0d34-0410-b5e6-96231b3b80d8
86 lines
3.1 KiB
C++
86 lines
3.1 KiB
C++
//===- 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.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// Part of the ELFObjectFile class implementation.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "llvm/Object/ELFObjectFile.h"
|
|
#include "llvm/Support/MathExtras.h"
|
|
|
|
namespace llvm {
|
|
using namespace object;
|
|
|
|
ErrorOr<ObjectFile *> ObjectFile::createELFObjectFile(MemoryBuffer *Obj,
|
|
bool BufferOwned) {
|
|
std::pair<unsigned char, unsigned char> Ident = getElfArchType(Obj);
|
|
std::size_t MaxAlignment =
|
|
1ULL << countTrailingZeros(uintptr_t(Obj->getBufferStart()));
|
|
|
|
error_code EC;
|
|
std::unique_ptr<ObjectFile> R;
|
|
if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB)
|
|
#if !LLVM_IS_UNALIGNED_ACCESS_FAST
|
|
if (MaxAlignment >= 4)
|
|
R.reset(new ELFObjectFile<ELFType<support::little, 4, false> >(
|
|
Obj, EC, BufferOwned));
|
|
else
|
|
#endif
|
|
if (MaxAlignment >= 2)
|
|
R.reset(new ELFObjectFile<ELFType<support::little, 2, false> >(
|
|
Obj, EC, BufferOwned));
|
|
else
|
|
llvm_unreachable("Invalid alignment for ELF file!");
|
|
else if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2MSB)
|
|
#if !LLVM_IS_UNALIGNED_ACCESS_FAST
|
|
if (MaxAlignment >= 4)
|
|
R.reset(new ELFObjectFile<ELFType<support::big, 4, false> >(Obj, EC,
|
|
BufferOwned));
|
|
else
|
|
#endif
|
|
if (MaxAlignment >= 2)
|
|
R.reset(new ELFObjectFile<ELFType<support::big, 2, false> >(Obj, EC,
|
|
BufferOwned));
|
|
else
|
|
llvm_unreachable("Invalid alignment for ELF file!");
|
|
else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2MSB)
|
|
#if !LLVM_IS_UNALIGNED_ACCESS_FAST
|
|
if (MaxAlignment >= 8)
|
|
R.reset(new ELFObjectFile<ELFType<support::big, 8, true> >(Obj, EC,
|
|
BufferOwned));
|
|
else
|
|
#endif
|
|
if (MaxAlignment >= 2)
|
|
R.reset(new ELFObjectFile<ELFType<support::big, 2, true> >(Obj, EC,
|
|
BufferOwned));
|
|
else
|
|
llvm_unreachable("Invalid alignment for ELF file!");
|
|
else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2LSB) {
|
|
#if !LLVM_IS_UNALIGNED_ACCESS_FAST
|
|
if (MaxAlignment >= 8)
|
|
R.reset(new ELFObjectFile<ELFType<support::little, 8, true> >(
|
|
Obj, EC, BufferOwned));
|
|
else
|
|
#endif
|
|
if (MaxAlignment >= 2)
|
|
R.reset(new ELFObjectFile<ELFType<support::little, 2, true> >(
|
|
Obj, EC, BufferOwned));
|
|
else
|
|
llvm_unreachable("Invalid alignment for ELF file!");
|
|
}
|
|
else
|
|
report_fatal_error("Buffer is not an ELF object file!");
|
|
|
|
if (EC)
|
|
return EC;
|
|
return R.release();
|
|
}
|
|
|
|
} // end namespace llvm
|