|
14 | 14 | #include "llvm/Object/COFF.h" |
15 | 15 | #include "llvm/Support/CRC.h" |
16 | 16 | #include "llvm/Support/Errc.h" |
| 17 | +#include "llvm/Support/Endian.h" |
17 | 18 | #include "llvm/Support/ErrorHandling.h" |
18 | 19 | #include <cstddef> |
19 | 20 | #include <cstdint> |
@@ -94,9 +95,13 @@ Error COFFWriter::finalizeSymbolContents() { |
94 | 95 | } |
95 | 96 |
|
96 | 97 | Error COFFWriter::finalizeCFGuardContents() { |
| 98 | + // CFGuards shouldn't be present in PE |
| 99 | + if (Obj.IsPE) |
| 100 | + return Error::success(); |
| 101 | + |
97 | 102 | DenseMap<size_t, size_t> SymIdMap; |
98 | 103 | bool NeedUpdate = false; |
99 | | - for (Symbol &Sym : Obj.getMutableSymbols()) { |
| 104 | + for (const auto &Sym : Obj.getSymbols()) { |
100 | 105 | NeedUpdate |= Sym.OriginalRawIndex == Sym.RawIndex; |
101 | 106 | SymIdMap[Sym.OriginalRawIndex] = Sym.RawIndex; |
102 | 107 | } |
@@ -128,14 +133,14 @@ Error COFFWriter::finalizeCFGuardContents() { |
128 | 133 | // Nothing to do and also CheckSum will be -1 instead of 0 if we recalculate |
129 | 134 | // it on empty input. |
130 | 135 | if (RawIds.size() == 0) |
131 | | - return Error::success(); |
| 136 | + continue; |
132 | 137 |
|
133 | 138 | // Create updated content |
134 | | - ArrayRef<uint32_t> Ids(reinterpret_cast<const uint32_t *>(RawIds.data()), |
135 | | - RawIds.size() / 4); |
136 | | - std::vector<uint32_t> NewIds; |
| 139 | + ArrayRef<support::ulittle32_t> Ids(reinterpret_cast<const support::ulittle32_t *>(RawIds.data()), |
| 140 | + RawIds.size() / 4); |
| 141 | + std::vector<support::ulittle32_t> NewIds; |
137 | 142 | for (auto Id : Ids) |
138 | | - NewIds.push_back(SymIdMap[Id]); |
| 143 | + NewIds.push_back(support::ulittle32_t(SymIdMap[Id])); |
139 | 144 | ArrayRef<uint8_t> NewRawIds(reinterpret_cast<uint8_t *>(NewIds.data()), |
140 | 145 | RawIds.size()); |
141 | 146 | // Update check sum |
|
0 commit comments