@@ -247,7 +247,8 @@ class Writer {
247
247
void writeBuildId ();
248
248
void writePEChecksum ();
249
249
void sortSections ();
250
- void sortExceptionTable ();
250
+ template <typename T> void sortExceptionTable (Chunk *first, Chunk *last);
251
+ void sortExceptionTables ();
251
252
void sortCRTSectionChunks (std::vector<Chunk *> &chunks);
252
253
void addSyntheticIdata ();
253
254
void sortBySectionOrder (std::vector<Chunk *> &chunks);
@@ -751,7 +752,7 @@ void Writer::run() {
751
752
}
752
753
writeSections ();
753
754
prepareLoadConfig ();
754
- sortExceptionTable ();
755
+ sortExceptionTables ();
755
756
756
757
// Fix up the alignment in the TLS Directory's characteristic field,
757
758
// if a specific alignment value is needed
@@ -2164,41 +2165,52 @@ void Writer::writeBuildId() {
2164
2165
}
2165
2166
2166
2167
// Sort .pdata section contents according to PE/COFF spec 5.5.
2167
- void Writer::sortExceptionTable () {
2168
- if (!firstPdata)
2169
- return ;
2170
- llvm::TimeTraceScope timeScope (" Sort exception table" );
2168
+ template <typename T>
2169
+ void Writer::sortExceptionTable (Chunk *first, Chunk *last) {
2171
2170
// We assume .pdata contains function table entries only.
2172
2171
auto bufAddr = [&](Chunk *c) {
2173
2172
OutputSection *os = ctx.getOutputSection (c);
2174
2173
return buffer->getBufferStart () + os->getFileOff () + c->getRVA () -
2175
2174
os->getRVA ();
2176
2175
};
2177
- uint8_t *begin = bufAddr (firstPdata);
2178
- uint8_t *end = bufAddr (lastPdata) + lastPdata->getSize ();
2179
- if (ctx.config .machine == AMD64) {
2180
- struct Entry { ulittle32_t begin, end, unwind; };
2181
- if ((end - begin) % sizeof (Entry) != 0 ) {
2182
- fatal (" unexpected .pdata size: " + Twine (end - begin) +
2183
- " is not a multiple of " + Twine (sizeof (Entry)));
2184
- }
2185
- parallelSort (
2186
- MutableArrayRef<Entry>((Entry *)begin, (Entry *)end),
2187
- [](const Entry &a, const Entry &b) { return a.begin < b.begin ; });
2188
- return ;
2176
+ uint8_t *begin = bufAddr (first);
2177
+ uint8_t *end = bufAddr (last) + last->getSize ();
2178
+ if ((end - begin) % sizeof (T) != 0 ) {
2179
+ fatal (" unexpected .pdata size: " + Twine (end - begin) +
2180
+ " is not a multiple of " + Twine (sizeof (T)));
2189
2181
}
2190
- if (ctx.config .machine == ARMNT || ctx.config .machine == ARM64) {
2191
- struct Entry { ulittle32_t begin, unwind; };
2192
- if ((end - begin) % sizeof (Entry) != 0 ) {
2193
- fatal (" unexpected .pdata size: " + Twine (end - begin) +
2194
- " is not a multiple of " + Twine (sizeof (Entry)));
2195
- }
2196
- parallelSort (
2197
- MutableArrayRef<Entry>((Entry *)begin, (Entry *)end),
2198
- [](const Entry &a, const Entry &b) { return a.begin < b.begin ; });
2199
- return ;
2182
+
2183
+ parallelSort (MutableArrayRef<T>(reinterpret_cast <T *>(begin),
2184
+ reinterpret_cast <T *>(end)),
2185
+ [](const T &a, const T &b) { return a.begin < b.begin ; });
2186
+ }
2187
+
2188
+ // Sort .pdata section contents according to PE/COFF spec 5.5.
2189
+ void Writer::sortExceptionTables () {
2190
+ llvm::TimeTraceScope timeScope (" Sort exception table" );
2191
+
2192
+ struct EntryX64 {
2193
+ ulittle32_t begin, end, unwind;
2194
+ };
2195
+ struct EntryArm {
2196
+ ulittle32_t begin, unwind;
2197
+ };
2198
+
2199
+ switch (ctx.config .machine ) {
2200
+ case AMD64:
2201
+ if (firstPdata)
2202
+ sortExceptionTable<EntryX64>(firstPdata, lastPdata);
2203
+ break ;
2204
+ case ARMNT:
2205
+ case ARM64:
2206
+ if (firstPdata)
2207
+ sortExceptionTable<EntryArm>(firstPdata, lastPdata);
2208
+ break ;
2209
+ default :
2210
+ if (firstPdata)
2211
+ lld::errs () << " warning: don't know how to handle .pdata.\n " ;
2212
+ break ;
2200
2213
}
2201
- lld::errs () << " warning: don't know how to handle .pdata.\n " ;
2202
2214
}
2203
2215
2204
2216
// The CRT section contains, among other things, the array of function
0 commit comments