summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMeador Inge <meadori@codesourcery.com>2012-06-25 14:48:43 +0000
committerMeador Inge <meadori@codesourcery.com>2012-06-25 14:48:43 +0000
commitb935cd15142491bdee9baff00db8d63c18d402db (patch)
tree0e3f95fe7be88dada7974313552bb1570bd42b01 /lib
parenta0706a9ff4469b137ed6eea3f484a0152bab4c88 (diff)
downloadllvm-b935cd15142491bdee9baff00db8d63c18d402db.tar.gz
llvm-b935cd15142491bdee9baff00db8d63c18d402db.tar.bz2
llvm-b935cd15142491bdee9baff00db8d63c18d402db.tar.xz
PR13013: ELF Type identification fails for MSB type ELF files.
Fix 'sys::IdentifyFileType' to work with big and little endian byte orderings when reading the ELF object file type. Initial patch by Stefan Hepp. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159138 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Support/Path.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/lib/Support/Path.cpp b/lib/Support/Path.cpp
index dcddeda977..db4a56b692 100644
--- a/lib/Support/Path.cpp
+++ b/lib/Support/Path.cpp
@@ -60,8 +60,11 @@ sys::IdentifyFileType(const char *magic, unsigned length) {
case '\177':
if (magic[1] == 'E' && magic[2] == 'L' && magic[3] == 'F') {
- if (length >= 18 && magic[17] == 0)
- switch (magic[16]) {
+ bool Data2MSB = magic[5] == 2;
+ unsigned high = Data2MSB ? 16 : 17;
+ unsigned low = Data2MSB ? 17 : 16;
+ if (length >= 18 && magic[high] == 0)
+ switch (magic[low]) {
default: break;
case 1: return ELF_Relocatable_FileType;
case 2: return ELF_Executable_FileType;