blob: c23e3f6656cd5fad8e824f23af4ee75307e32905 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
//===- lib/ReaderWriter/ELF/FileCommon.cpp --------------------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#include "ELFFile.h"
#include "FileCommon.h"
using namespace llvm::ELF;
namespace lld {
namespace elf {
static const char *elf32_expected = "ELF32 expected, but got ELF64";
static const char *elf64_expected = "ELF64 expected, but got ELF32";
static const char *le_expected =
"Little endian files are expected, but got a big endian file.";
static const char *be_expected =
"Big endian files are expected, but got a little endian file.";
template <>
std::error_code checkCompatibility<ELF32LE>(unsigned char size,
unsigned char endian) {
if (size == ELFCLASS64)
return make_dynamic_error_code(elf32_expected);
if (endian == ELFDATA2MSB)
return make_dynamic_error_code(le_expected);
return std::error_code();
}
template <>
std::error_code checkCompatibility<ELF32BE>(unsigned char size,
unsigned char endian) {
if (size == ELFCLASS64)
return make_dynamic_error_code(elf32_expected);
if (endian == ELFDATA2LSB)
return make_dynamic_error_code(be_expected);
return std::error_code();
}
template <>
std::error_code checkCompatibility<ELF64LE>(unsigned char size,
unsigned char endian) {
if (size == ELFCLASS32)
return make_dynamic_error_code(elf64_expected);
if (endian == ELFDATA2MSB)
return make_dynamic_error_code(le_expected);
return std::error_code();
}
template <>
std::error_code checkCompatibility<ELF64BE>(unsigned char size,
unsigned char endian) {
if (size == ELFCLASS32)
return make_dynamic_error_code(elf64_expected);
if (endian == ELFDATA2LSB)
return make_dynamic_error_code(be_expected);
return std::error_code();
}
} // end namespace elf
} // end namespace lld
|