summaryrefslogtreecommitdiffstats
path: root/lld/lib/ReaderWriter/ELF/FileCommon.cpp
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2015-04-14 04:53:57 +0000
committerRui Ueyama <ruiu@google.com>2015-04-14 04:53:57 +0000
commit7bda84d25e7e9acf40715b76c332dc5d581b515a (patch)
treebd99bb79ea8726a24faa31a09a7d9ba676f9a868 /lld/lib/ReaderWriter/ELF/FileCommon.cpp
parentacdee690c810a64610b1db689fc414bc16f63f98 (diff)
downloadbcm5719-llvm-7bda84d25e7e9acf40715b76c332dc5d581b515a.tar.gz
bcm5719-llvm-7bda84d25e7e9acf40715b76c332dc5d581b515a.zip
ELF: Remove ELFT and LinkingContext template parameters from ELFReader.
Previously, ELFReader takes three template arguments: EFLT, LinkingContextT and FileT. FileT is itself templated. So it was a bit complicated. Maybe too much. Most architectures don't actually need to be parameterized for ELFT. For example, x86 is always ELF32LE and x86-64 is ELF64LE. However, because ELFReader requires a ELFT argument, we needed to parameterize a class even if not needed. This patch removes the parameter from the class. So now we can de-templatize such classes (I didn't do that in this patch, though). This patch also removes ContextT parameter since it didn't have to be passed as a template argument. llvm-svn: 234853
Diffstat (limited to 'lld/lib/ReaderWriter/ELF/FileCommon.cpp')
-rw-r--r--lld/lib/ReaderWriter/ELF/FileCommon.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/lld/lib/ReaderWriter/ELF/FileCommon.cpp b/lld/lib/ReaderWriter/ELF/FileCommon.cpp
new file mode 100644
index 00000000000..e4a3e40282d
--- /dev/null
+++ b/lld/lib/ReaderWriter/ELF/FileCommon.cpp
@@ -0,0 +1,63 @@
+//===- 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 {
+
+template <>
+std::error_code checkCompatibility<ELF32LE>(unsigned char size,
+ unsigned char endian) {
+ if (size == ELFCLASS64)
+ return make_dynamic_error_code("ELF32 expected, but got ELF64");
+ if (endian == ELFDATA2MSB)
+ return make_dynamic_error_code(
+ "Little endian files are expected, but got a big endian file.");
+ 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, but got ELF64");
+ if (endian == ELFDATA2LSB)
+ return make_dynamic_error_code(
+ "Big endian files are expected, but got a little endian file.");
+ 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, but got ELF32");
+ if (endian == ELFDATA2MSB)
+ return make_dynamic_error_code(
+ "Little endian files are expected, but got a big endian file.");
+ 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, but got ELF32");
+ if (endian == ELFDATA2LSB)
+ return make_dynamic_error_code(
+ "Big endian files are expected, but got a little endian file.");
+ return std::error_code();
+}
+
+} // end namespace elf
+} // end namespace lld
OpenPOWER on IntegriCloud