llvm.org GIT mirror llvm / 7cacca2
Revert "Replace trivial use of external rc.exe by writing our own .res file." This patch still seems to break CrWinClangLLD, reverting this once more until I can discover root problem. This reverts commit 3dbbc8ce43be50ffde2b1c655c6d3a25796fe78b. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@307188 91177308-0d34-0410-b5e6-96231b3b80d8 Eric Beckmann 2 years ago
5 changed file(s) with 29 addition(s) and 59 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.
4646
4747 class WindowsResource;
4848
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 };
86
8749 class ResourceEntryRef {
8850 public:
8951 Error moveNext(bool &End);
10769
10870 Error loadNext();
10971
72 struct HeaderSuffix {
73 support::ulittle32_t DataVersion;
74 support::ulittle16_t MemoryFlags;
75 support::ulittle16_t Language;
76 support::ulittle32_t Version;
77 support::ulittle32_t Characteristics;
78 };
79
11080 BinaryStreamReader Reader;
11181 bool IsStringType;
11282 ArrayRef Type;
11484 bool IsStringName;
11585 ArrayRef Name;
11686 uint16_t NameID;
117 const WinResHeaderSuffix *Suffix = nullptr;
87 const HeaderSuffix *Suffix = nullptr;
11888 ArrayRef Data;
11989 const WindowsResource *OwningRes = nullptr;
12090 };
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 }
461467 SectionOneHeader->PointerToLinenumbers = 0;
462468 SectionOneHeader->NumberOfRelocations = Data.size();
463469 SectionOneHeader->NumberOfLinenumbers = 0;
470 SectionOneHeader->Characteristics = COFF::IMAGE_SCN_ALIGN_1BYTES;
471 SectionOneHeader->Characteristics += COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
464472 SectionOneHeader->Characteristics += COFF::IMAGE_SCN_CNT_INITIALIZED_DATA;
465473 SectionOneHeader->Characteristics += COFF::IMAGE_SCN_MEM_READ;
466474 }
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