mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-07 11:29:54 +00:00
[Object][ELF] Add a maximum alignment. This is used by createELFObjectFile to create a properly aligned reader.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171520 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Object/ELF.h"
|
||||
#include "llvm/Support/MathExtras.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
@@ -22,16 +23,37 @@ ObjectFile *ObjectFile::createELFObjectFile(MemoryBuffer *Object) {
|
||||
std::pair<unsigned char, unsigned char> Ident = getElfArchType(Object);
|
||||
error_code ec;
|
||||
|
||||
std::size_t MaxAlignment =
|
||||
1ULL << CountTrailingZeros_64(uintptr_t(Object->getBufferStart()));
|
||||
|
||||
if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB)
|
||||
return new ELFObjectFile<support::little, false>(Object, ec);
|
||||
if (MaxAlignment >= 4)
|
||||
return new ELFObjectFile<support::little, 4, false>(Object, ec);
|
||||
else if (MaxAlignment >= 2)
|
||||
return new ELFObjectFile<support::little, 2, false>(Object, ec);
|
||||
else
|
||||
llvm_unreachable("Invalid alignment for ELF file!");
|
||||
else if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2MSB)
|
||||
return new ELFObjectFile<support::big, false>(Object, ec);
|
||||
if (MaxAlignment >= 4)
|
||||
return new ELFObjectFile<support::big, 4, false>(Object, ec);
|
||||
else if (MaxAlignment >= 2)
|
||||
return new ELFObjectFile<support::big, 2, false>(Object, ec);
|
||||
else
|
||||
llvm_unreachable("Invalid alignment for ELF file!");
|
||||
else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2MSB)
|
||||
return new ELFObjectFile<support::big, true>(Object, ec);
|
||||
if (MaxAlignment >= 8)
|
||||
return new ELFObjectFile<support::big, 8, true>(Object, ec);
|
||||
else if (MaxAlignment >= 2)
|
||||
return new ELFObjectFile<support::big, 2, true>(Object, ec);
|
||||
else
|
||||
llvm_unreachable("Invalid alignment for ELF file!");
|
||||
else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2LSB) {
|
||||
ELFObjectFile<support::little, true> *result =
|
||||
new ELFObjectFile<support::little, true>(Object, ec);
|
||||
return result;
|
||||
if (MaxAlignment >= 8)
|
||||
return new ELFObjectFile<support::little, 8, true>(Object, ec);
|
||||
else if (MaxAlignment >= 2)
|
||||
return new ELFObjectFile<support::little, 2, true>(Object, ec);
|
||||
else
|
||||
llvm_unreachable("Invalid alignment for ELF file!");
|
||||
}
|
||||
|
||||
report_fatal_error("Buffer is not an ELF object file!");
|
||||
|
Reference in New Issue
Block a user