diff options
author | Meador Inge <meadori@codesourcery.com> | 2012-06-25 14:48:43 +0000 |
---|---|---|
committer | Meador Inge <meadori@codesourcery.com> | 2012-06-25 14:48:43 +0000 |
commit | fc2fb711e8c4879673a79588b063f5a92b922830 (patch) | |
tree | 125806f69f4715e44114a308a3a877297fac0575 /llvm/lib/Support/Path.cpp | |
parent | 6bbb5140cc09397a4951084098e0bf76a7ef62d9 (diff) | |
download | llvm-fc2fb711e8c4879673a79588b063f5a92b922830.zip llvm-fc2fb711e8c4879673a79588b063f5a92b922830.tar.gz llvm-fc2fb711e8c4879673a79588b063f5a92b922830.tar.bz2 |
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.
llvm-svn: 159138
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r-- | llvm/lib/Support/Path.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index dcddeda..db4a56b 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/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; |