diff options
author | Rui Ueyama <ruiu@google.com> | 2014-09-11 22:34:32 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2014-09-11 22:34:32 +0000 |
commit | 5c69ff5cf5c9dc6a4517e37e0613b684164bcfba (patch) | |
tree | 7b416341022ba86ba80101499cc4dd4e8849c8a7 /llvm/lib/Support/Path.cpp | |
parent | f5e4f37cb67114cde73bea8befa0187b1c32b4c5 (diff) | |
download | bcm5719-llvm-5c69ff5cf5c9dc6a4517e37e0613b684164bcfba.tar.gz bcm5719-llvm-5c69ff5cf5c9dc6a4517e37e0613b684164bcfba.zip |
Support: Use llvm::COFF::BigObjMagic
Use llvm::COFF::BigObjMagic insetad of the string literal.
Also checks the version number.
llvm-svn: 217633
Diffstat (limited to 'llvm/lib/Support/Path.cpp')
-rw-r--r-- | llvm/lib/Support/Path.cpp | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp index 4d69b25f8fc..781c17c1879 100644 --- a/llvm/lib/Support/Path.cpp +++ b/llvm/lib/Support/Path.cpp @@ -11,9 +11,10 @@ // //===----------------------------------------------------------------------===// +#include "llvm/Support/COFF.h" +#include "llvm/Support/Endian.h" #include "llvm/Support/Errc.h" #include "llvm/Support/Path.h" -#include "llvm/Support/Endian.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Process.h" @@ -904,12 +905,19 @@ file_magic identify_magic(StringRef Magic) { // COFF bigobj or short import library file if (Magic[1] == (char)0x00 && Magic[2] == (char)0xff && Magic[3] == (char)0xff) { - const char BigobjMagic[] = - "\xc7\xa1\xba\xd1\xee\xba\xa9\x4b\xaf\x20\xfa\xf6\x6a\xa4\xdc\xb8"; - if (Magic.size() >= 28 && - memcmp(Magic.data() + 12, BigobjMagic, sizeof(BigobjMagic)) == 0) - return file_magic::coff_object; - return file_magic::coff_import_library; + size_t MinSize = offsetof(COFF::BigObjHeader, UUID) + sizeof(COFF::BigObjMagic); + if (Magic.size() < MinSize) + return file_magic::coff_import_library; + + int BigObjVersion = *reinterpret_cast<const support::ulittle16_t*>( + Magic.data() + offsetof(COFF::BigObjHeader, Version)); + if (BigObjVersion < COFF::BigObjHeader::MinBigObjectVersion) + return file_magic::coff_import_library; + + const char *Start = Magic.data() + offsetof(COFF::BigObjHeader, UUID); + if (memcmp(Start, COFF::BigObjMagic, sizeof(COFF::BigObjMagic)) != 0) + return file_magic::coff_import_library; + return file_magic::coff_object; } // Windows resource file const char Expected[] = { 0, 0, 0, 0, '\x20', 0, 0, 0, '\xff' }; |