diff options
| author | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:57:38 +0000 |
|---|---|---|
| committer | Dimitry Andric <dim@FreeBSD.org> | 2015-12-30 11:57:38 +0000 |
| commit | 5a5c549fe9a3fef595297bd21d36bed8409dc37d (patch) | |
| tree | a964c8f5ac85b7b641cac022c5f9bf4eed3d2b9b /lib/ReaderWriter/ELF/FileCommon.cpp | |
| parent | fb911942f1434f3d1750f83f25f5e42c80e60638 (diff) | |
Notes
Diffstat (limited to 'lib/ReaderWriter/ELF/FileCommon.cpp')
| -rw-r--r-- | lib/ReaderWriter/ELF/FileCommon.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/lib/ReaderWriter/ELF/FileCommon.cpp b/lib/ReaderWriter/ELF/FileCommon.cpp new file mode 100644 index 000000000000..c23e3f6656cd --- /dev/null +++ b/lib/ReaderWriter/ELF/FileCommon.cpp @@ -0,0 +1,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 |
