llvm.org GIT mirror llvm / cf9142d
Support: Use llvm::COFF::BigObjMagic Use llvm::COFF::BigObjMagic insetad of the string literal. Also checks the version number. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@217633 91177308-0d34-0410-b5e6-96231b3b80d8 Rui Ueyama 5 years ago
2 changed file(s) with 16 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
1010 //
1111 //===----------------------------------------------------------------------===//
1212
13 #include "llvm/Support/COFF.h"
14 #include "llvm/Support/Endian.h"
1315 #include "llvm/Support/Errc.h"
1416 #include "llvm/Support/Path.h"
15 #include "llvm/Support/Endian.h"
1617 #include "llvm/Support/ErrorHandling.h"
1718 #include "llvm/Support/FileSystem.h"
1819 #include "llvm/Support/Process.h"
903904 // COFF bigobj or short import library file
904905 if (Magic[1] == (char)0x00 && Magic[2] == (char)0xff &&
905906 Magic[3] == (char)0xff) {
906 const char BigobjMagic[] =
907 "\xc7\xa1\xba\xd1\xee\xba\xa9\x4b\xaf\x20\xfa\xf6\x6a\xa4\xdc\xb8";
908 if (Magic.size() >= 28 &&
909 memcmp(Magic.data() + 12, BigobjMagic, sizeof(BigobjMagic)) == 0)
910 return file_magic::coff_object;
911 return file_magic::coff_import_library;
907 size_t MinSize = offsetof(COFF::BigObjHeader, UUID) + sizeof(COFF::BigObjMagic);
908 if (Magic.size() < MinSize)
909 return file_magic::coff_import_library;
910
911 int BigObjVersion = *reinterpret_cast(
912 Magic.data() + offsetof(COFF::BigObjHeader, Version));
913 if (BigObjVersion < COFF::BigObjHeader::MinBigObjectVersion)
914 return file_magic::coff_import_library;
915
916 const char *Start = Magic.data() + offsetof(COFF::BigObjHeader, UUID);
917 if (memcmp(Start, COFF::BigObjMagic, sizeof(COFF::BigObjMagic)) != 0)
918 return file_magic::coff_import_library;
919 return file_magic::coff_object;
912920 }
913921 // Windows resource file
914922 const char Expected[] = { 0, 0, 0, 0, '\x20', 0, 0, 0, '\xff' };
482482 const char archive[] = "!\x0A";
483483 const char bitcode[] = "\xde\xc0\x17\x0b";
484484 const char coff_object[] = "\x00\x00......";
485 const char coff_bigobj[] = "\x00\x00\xff\xff........"
485 const char coff_bigobj[] = "\x00\x00\xff\xff\x00\x02......"
486486 "\xc7\xa1\xba\xd1\xee\xba\xa9\x4b\xaf\x20\xfa\xf6\x6a\xa4\xdc\xb8";
487487 const char coff_import_library[] = "\x00\x00\xff\xff....";
488488 const char elf_relocatable[] = { 0x7f, 'E', 'L', 'F', 1, 2, 1, 0, 0,