llvm.org GIT mirror llvm / b2489ff
Revert "Replace trivial use of external rc.exe by writing our own .res file." This reverts commit d4c7e9fc63c10dbab0c30186ef8575474a704496. This is done in order to address the failure of CrWinClangLLD etc. bots. These throw an error of "side-by-side configuration is incorrect" during compilation, which sounds suspiciously related to these manifest changes. Revert "Switch external cvtres.exe for llvm's own resource library." This reverts commit 71fe8ef283a9dab9a3f21432c98466cbc23990d1. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306618 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Beckmann 3 years ago
5 changed file(s) with 32 addition(s) and 58 deletion(s). Raw diff Collapse all Expand all
4343 static const char ClGlObjMagic[] = {
4444 '\x38', '\xfe', '\xb3', '\x0c', '\xa5', '\xd9', '\xab', '\x4d',
4545 '\xac', '\x9b', '\xd6', '\xb6', '\x22', '\x26', '\x53', '\xc2',
46 };
47
48 // The signature bytes that start a .res file.
49 static const char WinResMagic[] = {
50 '\x00', '\x00', '\x00', '\x00', '\x20', '\x00', '\x00', '\x00',
51 '\xff', '\xff', '\x00', '\x00', '\xff', '\xff', '\x00', '\x00',
5246 };
5347
5448 // Sizes in bytes of various things in the COFF format.
4242 #include
4343
4444 namespace llvm {
45
4546 namespace object {
4647
4748 class WindowsResource;
4849
49 const size_t WIN_RES_MAGIC_SIZE = 16;
50 const size_t WIN_RES_NULL_ENTRY_SIZE = 16;
51 const uint32_t WIN_RES_HEADER_ALIGNMENT = 4;
52 const uint32_t WIN_RES_DATA_ALIGNMENT = 4;
53 const uint16_t WIN_RES_PURE_MOVEABLE = 0x0030;
54
55 struct WinResHeaderPrefix {
56 support::ulittle32_t DataSize;
57 support::ulittle32_t HeaderSize;
58 };
59
60 // Type and Name may each either be an integer ID or a string. This struct is
61 // only used in the case where they are both IDs.
62 struct WinResIDs {
63 uint16_t TypeFlag;
64 support::ulittle16_t TypeID;
65 uint16_t NameFlag;
66 support::ulittle16_t NameID;
67
68 void setType(uint16_t ID) {
69 TypeFlag = 0xffff;
70 TypeID = ID;
71 }
72
73 void setName(uint16_t ID) {
74 NameFlag = 0xffff;
75 NameID = ID;
76 }
77 };
78
79 struct WinResHeaderSuffix {
80 support::ulittle32_t DataVersion;
81 support::ulittle16_t MemoryFlags;
82 support::ulittle16_t Language;
83 support::ulittle32_t Version;
84 support::ulittle32_t Characteristics;
85 };
50 enum class Machine { UNKNOWN, ARM, X64, X86 };
8651
8752 class ResourceEntryRef {
8853 public:
10772
10873 Error loadNext();
10974
75 struct HeaderSuffix {
76 support::ulittle32_t DataVersion;
77 support::ulittle16_t MemoryFlags;
78 support::ulittle16_t Language;
79 support::ulittle32_t Version;
80 support::ulittle32_t Characteristics;
81 };
82
11083 BinaryStreamReader Reader;
11184 bool IsStringType;
11285 ArrayRef Type;
11487 bool IsStringName;
11588 ArrayRef Name;
11689 uint16_t NameID;
117 const WinResHeaderSuffix *Suffix = nullptr;
90 const HeaderSuffix *Suffix = nullptr;
11891 ArrayRef Data;
11992 const WindowsResource *OwningRes = nullptr;
12093 };
5050 return file_magic::coff_import_library;
5151 }
5252 // Windows resource file
53 if (Magic.size() >= sizeof(COFF::WinResMagic) &&
54 memcmp(Magic.data(), COFF::WinResMagic, sizeof(COFF::WinResMagic)) == 0)
53 if (startswith(Magic, "\0\0\0\0\x20\0\0\0\xFF"))
5554 return file_magic::windows_resource;
5655 // 0x0000 = COFF unknown machine type
5756 if (Magic[1] == 0)
3535 // 8-byte because it makes everyone happy.
3636 const uint32_t SECTION_ALIGNMENT = sizeof(uint64_t);
3737
38 static const size_t ResourceMagicSize = 16;
39
40 static const size_t NullEntrySize = 16;
41
3842 uint32_t WindowsResourceParser::TreeNode::StringCount = 0;
3943 uint32_t WindowsResourceParser::TreeNode::DataCount = 0;
4044
4145 WindowsResource::WindowsResource(MemoryBufferRef Source)
4246 : Binary(Binary::ID_WinRes, Source) {
43 size_t LeadingSize = WIN_RES_MAGIC_SIZE + WIN_RES_NULL_ENTRY_SIZE;
47 size_t LeadingSize = ResourceMagicSize + NullEntrySize;
4448 BBS = BinaryByteStream(Data.getBuffer().drop_front(LeadingSize),
4549 support::little);
4650 }
4751
4852 Expected>
4953 WindowsResource::createWindowsResource(MemoryBufferRef Source) {
50 if (Source.getBufferSize() < WIN_RES_MAGIC_SIZE + WIN_RES_NULL_ENTRY_SIZE)
54 if (Source.getBufferSize() < ResourceMagicSize + NullEntrySize)
5155 return make_error(
5256 "File too small to be a resource file",
5357 object_error::invalid_file_type);
100104 }
101105
102106 Error ResourceEntryRef::loadNext() {
103 const WinResHeaderPrefix *Prefix;
104 RETURN_IF_ERROR(Reader.readObject(Prefix));
105
106 if (Prefix->HeaderSize < MIN_HEADER_SIZE)
107 uint32_t DataSize;
108 RETURN_IF_ERROR(Reader.readInteger(DataSize));
109 uint32_t HeaderSize;
110 RETURN_IF_ERROR(Reader.readInteger(HeaderSize));
111
112 if (HeaderSize < MIN_HEADER_SIZE)
107113 return make_error("Header size is too small.",
108114 object_error::parse_failed);
109115
111117
112118 RETURN_IF_ERROR(readStringOrId(Reader, NameID, Name, IsStringName));
113119
114 RETURN_IF_ERROR(Reader.padToAlignment(WIN_RES_HEADER_ALIGNMENT));
120 RETURN_IF_ERROR(Reader.padToAlignment(sizeof(uint32_t)));
115121
116122 RETURN_IF_ERROR(Reader.readObject(Suffix));
117123
118 RETURN_IF_ERROR(Reader.readArray(Data, Prefix->DataSize));
119
120 RETURN_IF_ERROR(Reader.padToAlignment(WIN_RES_DATA_ALIGNMENT));
124 RETURN_IF_ERROR(Reader.readArray(Data, DataSize));
125
126 RETURN_IF_ERROR(Reader.padToAlignment(sizeof(uint32_t)));
121127
122128 return Error::success();
123129 }
318324 void writeDirectoryTree();
319325 void writeDirectoryStringTable();
320326 void writeFirstSectionRelocations();
327
321328 std::unique_ptr OutputBuffer;
322329 char *BufferStart;
323330 uint64_t CurrentOffset = 0;
461468 SectionOneHeader->PointerToLinenumbers = 0;
462469 SectionOneHeader->NumberOfRelocations = Data.size();
463470 SectionOneHeader->NumberOfLinenumbers = 0;
471 SectionOneHeader->Characteristics = COFF::IMAGE_SCN_ALIGN_1BYTES;
472 SectionOneHeader->Characteristics += COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
464473 SectionOneHeader->Characteristics += COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
465474 SectionOneHeader->Characteristics += COFF::IMAGE_SCN_MEM_READ;
466475 }
7575 "\xfe\xed\xfa\xce........\x00\x00\x00\x0a............";
7676 const char macho_kext_bundle[] =
7777 "\xfe\xed\xfa\xce........\x00\x00\x00\x0b............";
78 const char windows_resource[] =
79 "\x00\x00\x00\x00\x020\x00\x00\x00\xff\xff\x00\x00\xff\xff\x00\x00";
78 const char windows_resource[] = "\x00\x00\x00\x00\x020\x00\x00\x00\xff";
8079 const char macho_dynamically_linked_shared_lib_stub[] =
8180 "\xfe\xed\xfa\xce........\x00\x00\x00\x09............";
8281