@@ -197,6 +197,10 @@ class PartialSectionKey {
197
197
}
198
198
};
199
199
200
+ struct ChunkRange {
201
+ Chunk *first = nullptr , *last;
202
+ };
203
+
200
204
// The writer writes a SymbolTable result to a file.
201
205
class Writer {
202
206
public:
@@ -247,7 +251,7 @@ class Writer {
247
251
void writeBuildId ();
248
252
void writePEChecksum ();
249
253
void sortSections ();
250
- template <typename T> void sortExceptionTable (Chunk *first, Chunk *last );
254
+ template <typename T> void sortExceptionTable (ChunkRange &exceptionTable );
251
255
void sortExceptionTables ();
252
256
void sortCRTSectionChunks (std::vector<Chunk *> &chunks);
253
257
void addSyntheticIdata ();
@@ -311,7 +315,7 @@ class Writer {
311
315
OutputSection *ctorsSec;
312
316
OutputSection *dtorsSec;
313
317
314
- // The first and last .pdata sections in the output file.
318
+ // The range of .pdata sections in the output file.
315
319
//
316
320
// We need to keep track of the location of .pdata in whichever section it
317
321
// gets merged into so that we can sort its contents and emit a correct data
@@ -320,8 +324,7 @@ class Writer {
320
324
// are entirely linker-generated we can keep track of their locations using
321
325
// the chunks that the linker creates. All .pdata chunks come from input
322
326
// files, so we need to keep track of them separately.
323
- Chunk *firstPdata = nullptr ;
324
- Chunk *lastPdata;
327
+ ChunkRange pdata;
325
328
326
329
COFFLinkerContext &ctx;
327
330
};
@@ -1408,8 +1411,8 @@ void Writer::createSymbolAndStringTable() {
1408
1411
void Writer::mergeSections () {
1409
1412
llvm::TimeTraceScope timeScope (" Merge sections" );
1410
1413
if (!pdataSec->chunks .empty ()) {
1411
- firstPdata = pdataSec->chunks .front ();
1412
- lastPdata = pdataSec->chunks .back ();
1414
+ pdata. first = pdataSec->chunks .front ();
1415
+ pdata. last = pdataSec->chunks .back ();
1413
1416
}
1414
1417
1415
1418
for (auto &p : ctx.config .merge ) {
@@ -1665,10 +1668,10 @@ template <typename PEHeaderTy> void Writer::writeHeader() {
1665
1668
dir[RESOURCE_TABLE].RelativeVirtualAddress = rsrcSec->getRVA ();
1666
1669
dir[RESOURCE_TABLE].Size = rsrcSec->getVirtualSize ();
1667
1670
}
1668
- if (firstPdata ) {
1669
- dir[EXCEPTION_TABLE].RelativeVirtualAddress = firstPdata ->getRVA ();
1671
+ if (pdata. first ) {
1672
+ dir[EXCEPTION_TABLE].RelativeVirtualAddress = pdata. first ->getRVA ();
1670
1673
dir[EXCEPTION_TABLE].Size =
1671
- lastPdata ->getRVA () + lastPdata ->getSize () - firstPdata ->getRVA ();
1674
+ pdata. last ->getRVA () + pdata. last ->getSize () - pdata. first ->getRVA ();
1672
1675
}
1673
1676
if (relocSec->getVirtualSize ()) {
1674
1677
dir[BASE_RELOCATION_TABLE].RelativeVirtualAddress = relocSec->getRVA ();
@@ -2166,15 +2169,18 @@ void Writer::writeBuildId() {
2166
2169
2167
2170
// Sort .pdata section contents according to PE/COFF spec 5.5.
2168
2171
template <typename T>
2169
- void Writer::sortExceptionTable (Chunk *first, Chunk *last) {
2172
+ void Writer::sortExceptionTable (ChunkRange &exceptionTable) {
2173
+ if (!exceptionTable.first )
2174
+ return ;
2175
+
2170
2176
// We assume .pdata contains function table entries only.
2171
2177
auto bufAddr = [&](Chunk *c) {
2172
2178
OutputSection *os = ctx.getOutputSection (c);
2173
2179
return buffer->getBufferStart () + os->getFileOff () + c->getRVA () -
2174
2180
os->getRVA ();
2175
2181
};
2176
- uint8_t *begin = bufAddr (first);
2177
- uint8_t *end = bufAddr (last) + last->getSize ();
2182
+ uint8_t *begin = bufAddr (exceptionTable. first );
2183
+ uint8_t *end = bufAddr (exceptionTable. last ) + exceptionTable. last ->getSize ();
2178
2184
if ((end - begin) % sizeof (T) != 0 ) {
2179
2185
fatal (" unexpected .pdata size: " + Twine (end - begin) +
2180
2186
" is not a multiple of " + Twine (sizeof (T)));
@@ -2198,16 +2204,14 @@ void Writer::sortExceptionTables() {
2198
2204
2199
2205
switch (ctx.config .machine ) {
2200
2206
case AMD64:
2201
- if (firstPdata)
2202
- sortExceptionTable<EntryX64>(firstPdata, lastPdata);
2207
+ sortExceptionTable<EntryX64>(pdata);
2203
2208
break ;
2204
2209
case ARMNT:
2205
2210
case ARM64:
2206
- if (firstPdata)
2207
- sortExceptionTable<EntryArm>(firstPdata, lastPdata);
2211
+ sortExceptionTable<EntryArm>(pdata);
2208
2212
break ;
2209
2213
default :
2210
- if (firstPdata )
2214
+ if (pdata. first )
2211
2215
lld::errs () << " warning: don't know how to handle .pdata.\n " ;
2212
2216
break ;
2213
2217
}
0 commit comments