6 cd $MOZ_FETCHES_DIR/winchecksec
11 x86_64-pc-windows-msvc
)
13 export PATH
="$MOZ_FETCHES_DIR/clang/bin:$PATH"
15 .
$GECKO_PATH/taskcluster
/scripts
/misc
/vs-setup.sh
17 # Patch pe-parse because clang-cl doesn't support /analyze.
19 --- a/pe-parse/cmake/compilation_flags.cmake
20 +++ b/pe-parse/cmake/compilation_flags.cmake
23 - list(APPEND DEFAULT_CXX_FLAGS /W4 /analyze)
24 + list(APPEND DEFAULT_CXX_FLAGS /W4)
26 if (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
27 list(APPEND DEFAULT_CXX_FLAGS /Zi)
31 -DCMAKE_CXX_COMPILER=clang-cl
32 -DCMAKE_C_COMPILER=clang-cl
33 -DCMAKE_LINKER=lld-link
34 -DCMAKE_C_FLAGS="-fuse-ld=lld -Xclang -ivfsoverlay -Xclang $MOZ_FETCHES_DIR/vs/overlay.yaml"
35 -DCMAKE_CXX_FLAGS="-fuse-ld=lld -EHsc -Xclang -ivfsoverlay -Xclang $MOZ_FETCHES_DIR/vs/overlay.yaml"
36 -DCMAKE_RC_COMPILER=llvm-rc
38 -DCMAKE_SYSTEM_NAME=Windows
39 -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded
44 # Apply https://github.com/trailofbits/pe-parse/commit/d9e72af81e832330c111e07b98d34877469445f5
45 # And https://github.com/trailofbits/pe-parse/commit/eecdb3d36eb44e306398a2e66e85490f9bdcc74c
47 --- a/pe-parse/pe-parser-library/src/buffer.cpp
48 +++ b/pe-parse/pe-parser-library/src/buffer.cpp
49 @@ -112,11 +112,12 @@ bool readWord(bounded_buffer *b, std::uint32_t offset, std::uint16_t &out) {
53 - std::uint16_t *tmp = reinterpret_cast<std::uint16_t *>(b->buf + offset);
55 + memcpy(&tmp, (b->buf + offset), sizeof(std::uint16_t));
57 - out = byteSwapUint16(*tmp);
58 + out = byteSwapUint16(tmp);
65 @@ -133,11 +134,12 @@ bool readDword(bounded_buffer *b, std::uint32_t offset, std::uint32_t &out) {
69 - std::uint32_t *tmp = reinterpret_cast<std::uint32_t *>(b->buf + offset);
71 + memcpy(&tmp, (b->buf + offset), sizeof(std::uint32_t));
73 - out = byteSwapUint32(*tmp);
74 + out = byteSwapUint32(tmp);
81 @@ -154,11 +156,12 @@ bool readQword(bounded_buffer *b, std::uint32_t offset, std::uint64_t &out) {
85 - std::uint64_t *tmp = reinterpret_cast<std::uint64_t *>(b->buf + offset);
87 + memcpy(&tmp, (b->buf + offset), sizeof(std::uint64_t));
89 - out = byteSwapUint64(*tmp);
90 + out = byteSwapUint64(tmp);
97 @@ -175,16 +178,16 @@ bool readChar16(bounded_buffer *b, std::uint32_t offset, char16_t &out) {
101 - char16_t *tmp = nullptr;
104 std::uint8_t tmpBuf[2];
105 tmpBuf[0] = *(b->buf + offset + 1);
106 tmpBuf[1] = *(b->buf + offset);
107 - tmp = reinterpret_cast<char16_t *>(tmpBuf);
108 + memcpy(&tmp, tmpBuf, sizeof(std::uint16_t));
110 - tmp = reinterpret_cast<char16_t *>(b->buf + offset);
111 + memcpy(&tmp, (b->buf + offset), sizeof(std::uint16_t));
118 --- a/pe-parse/pe-parser-library/include/parser-library/parse.h
119 +++ b/pe-parse/pe-parser-library/include/parser-library/parse.h
120 @@ -40,28 +40,38 @@ THE SOFTWARE.
121 err_loc.assign(__func__); \
122 err_loc += ":" + to_string<std::uint32_t>(__LINE__, std::dec);
124 -#define READ_WORD(b, o, inst, member) \
125 - if (!readWord(b, o + _offset(__typeof__(inst), member), inst.member)) { \
126 - PE_ERR(PEERR_READ); \
128 +#define READ_WORD(b, o, inst, member) \
130 + o + static_cast<uint32_t>(offsetof(__typeof__(inst), member)), \
132 + PE_ERR(PEERR_READ); \
136 -#define READ_DWORD(b, o, inst, member) \
137 - if (!readDword(b, o + _offset(__typeof__(inst), member), inst.member)) { \
138 - PE_ERR(PEERR_READ); \
140 +#define READ_DWORD(b, o, inst, member) \
143 + o + static_cast<uint32_t>(offsetof(__typeof__(inst), member)), \
145 + PE_ERR(PEERR_READ); \
149 -#define READ_QWORD(b, o, inst, member) \
150 - if (!readQword(b, o + _offset(__typeof__(inst), member), inst.member)) { \
151 - PE_ERR(PEERR_READ); \
153 +#define READ_QWORD(b, o, inst, member) \
156 + o + static_cast<uint32_t>(offsetof(__typeof__(inst), member)), \
158 + PE_ERR(PEERR_READ); \
162 -#define READ_BYTE(b, o, inst, member) \
163 - if (!readByte(b, o + _offset(__typeof__(inst), member), inst.member)) { \
164 - PE_ERR(PEERR_READ); \
166 +#define READ_BYTE(b, o, inst, member) \
168 + o + static_cast<uint32_t>(offsetof(__typeof__(inst), member)), \
170 + PE_ERR(PEERR_READ); \
174 #define TEST_MACHINE_CHARACTERISTICS(h, m, ch) \
175 --- a/pe-parse/pe-parser-library/src/parse.cpp
176 +++ b/pe-parse/pe-parser-library/src/parse.cpp
177 @@ -1777,7 +1777,7 @@ bool getRelocations(parsed_pe *p) {
178 // Mask out the type and assign
180 // Mask out the offset and assign
181 - offset = entry & ~0xf000;
182 + offset = entry & static_cast<std::uint16_t>(~0xf000);
184 // Produce the VA of the relocation
190 -DCMAKE_BUILD_TYPE=Release \
191 -DBUILD_SHARED_LIBS=Off \
197 tar -caf winchecksec.
tar.zst winchecksec
/winchecksec
${SUFFIX}
198 cp winchecksec.
tar.zst
$UPLOAD_DIR/