@@ -459,10 +459,12 @@ class OffsetGetter {
459
459
// InputSectionBase.
460
460
class RelocationScanner {
461
461
public:
462
+ RelocationScanner (Ctx &ctx) : ctx(ctx) {}
462
463
template <class ELFT >
463
464
void scanSection (InputSectionBase &s, bool isEH = false );
464
465
465
466
private:
467
+ Ctx &ctx;
466
468
InputSectionBase *sec;
467
469
OffsetGetter getter;
468
470
@@ -476,6 +478,9 @@ class RelocationScanner {
476
478
uint64_t relOff) const ;
477
479
void processAux (RelExpr expr, RelType type, uint64_t offset, Symbol &sym,
478
480
int64_t addend) const ;
481
+ unsigned handleTlsRelocation (RelExpr expr, RelType type, uint64_t offset,
482
+ Symbol &sym, int64_t addend);
483
+
479
484
template <class ELFT , class RelTy >
480
485
void scanOne (typename Relocs<RelTy>::const_iterator &i);
481
486
template <class ELFT , class RelTy > void scan (Relocs<RelTy> rels);
@@ -1294,20 +1299,21 @@ static unsigned handleMipsTlsRelocation(RelType type, Symbol &sym,
1294
1299
// symbol in TLS block.
1295
1300
//
1296
1301
// Returns the number of relocations processed.
1297
- static unsigned handleTlsRelocation (RelType type, Symbol &sym ,
1298
- InputSectionBase &c, uint64_t offset,
1299
- int64_t addend, RelExpr expr ) {
1302
+ unsigned RelocationScanner:: handleTlsRelocation (RelExpr expr, RelType type ,
1303
+ uint64_t offset, Symbol &sym ,
1304
+ int64_t addend ) {
1300
1305
if (expr == R_TPREL || expr == R_TPREL_NEG) {
1301
1306
if (ctx.arg .shared ) {
1302
1307
errorOrWarn (" relocation " + toString (type) + " against " + toString (sym) +
1303
- " cannot be used with -shared" + getLocation (c, sym, offset));
1308
+ " cannot be used with -shared" +
1309
+ getLocation (*sec, sym, offset));
1304
1310
return 1 ;
1305
1311
}
1306
1312
return 0 ;
1307
1313
}
1308
1314
1309
1315
if (ctx.arg .emachine == EM_MIPS)
1310
- return handleMipsTlsRelocation (type, sym, c , offset, addend, expr);
1316
+ return handleMipsTlsRelocation (type, sym, *sec , offset, addend, expr);
1311
1317
1312
1318
// LoongArch does not yet implement transition from TLSDESC to LE/IE, so
1313
1319
// generate TLSDESC dynamic relocation for the dynamic linker to handle.
@@ -1316,7 +1322,7 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym,
1316
1322
R_TLSDESC_CALL>(expr)) {
1317
1323
if (expr != R_TLSDESC_CALL) {
1318
1324
sym.setFlags (NEEDS_TLSDESC);
1319
- c. addReloc ({expr, type, offset, addend, &sym});
1325
+ sec-> addReloc ({expr, type, offset, addend, &sym});
1320
1326
}
1321
1327
return 1 ;
1322
1328
}
@@ -1331,7 +1337,7 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym,
1331
1337
if (expr != R_TLSDESC_CALL) {
1332
1338
if (!isRISCV || type == R_RISCV_TLSDESC_HI20)
1333
1339
sym.setFlags (NEEDS_TLSDESC);
1334
- c. addReloc ({expr, type, offset, addend, &sym});
1340
+ sec-> addReloc ({expr, type, offset, addend, &sym});
1335
1341
}
1336
1342
return 1 ;
1337
1343
}
@@ -1345,10 +1351,11 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym,
1345
1351
!ctx.arg .shared && ctx.arg .emachine != EM_ARM &&
1346
1352
ctx.arg .emachine != EM_HEXAGON && ctx.arg .emachine != EM_LOONGARCH &&
1347
1353
!(isRISCV && expr != R_TLSDESC_PC && expr != R_TLSDESC_CALL) &&
1348
- !c. file ->ppc64DisableTLSRelax ;
1354
+ !sec-> file ->ppc64DisableTLSRelax ;
1349
1355
1350
1356
// If we are producing an executable and the symbol is non-preemptable, it
1351
- // must be defined and the code sequence can be optimized to use Local-Exec.
1357
+ // must be defined and the code sequence can be optimized to use
1358
+ // Local-Exesec->
1352
1359
//
1353
1360
// ARM and RISC-V do not support any relaxations for TLS relocations, however,
1354
1361
// we can omit the DTPMOD dynamic relocations and resolve them at link time
@@ -1361,33 +1368,33 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym,
1361
1368
// module index, with a special value of 0 for the current module. GOT[e1] is
1362
1369
// unused. There only needs to be one module index entry.
1363
1370
if (oneof<R_TLSLD_GOT, R_TLSLD_GOTPLT, R_TLSLD_PC, R_TLSLD_HINT>(expr)) {
1364
- // Local-Dynamic relocs can be optimized to Local-Exec.
1371
+ // Local-Dynamic relocs can be optimized to Local-Exesec->
1365
1372
if (execOptimize) {
1366
- c. addReloc ({ctx.target ->adjustTlsExpr (type, R_RELAX_TLS_LD_TO_LE), type ,
1367
- offset, addend, &sym});
1373
+ sec-> addReloc ({ctx.target ->adjustTlsExpr (type, R_RELAX_TLS_LD_TO_LE),
1374
+ type, offset, addend, &sym});
1368
1375
return ctx.target ->getTlsGdRelaxSkip (type);
1369
1376
}
1370
1377
if (expr == R_TLSLD_HINT)
1371
1378
return 1 ;
1372
1379
ctx.needsTlsLd .store (true , std::memory_order_relaxed);
1373
- c. addReloc ({expr, type, offset, addend, &sym});
1380
+ sec-> addReloc ({expr, type, offset, addend, &sym});
1374
1381
return 1 ;
1375
1382
}
1376
1383
1377
- // Local-Dynamic relocs can be optimized to Local-Exec.
1384
+ // Local-Dynamic relocs can be optimized to Local-Exesec->
1378
1385
if (expr == R_DTPREL) {
1379
1386
if (execOptimize)
1380
1387
expr = ctx.target ->adjustTlsExpr (type, R_RELAX_TLS_LD_TO_LE);
1381
- c. addReloc ({expr, type, offset, addend, &sym});
1388
+ sec-> addReloc ({expr, type, offset, addend, &sym});
1382
1389
return 1 ;
1383
1390
}
1384
1391
1385
1392
// Local-Dynamic sequence where offset of tls variable relative to dynamic
1386
1393
// thread pointer is stored in the got. This cannot be optimized to
1387
- // Local-Exec.
1394
+ // Local-Exesec->
1388
1395
if (expr == R_TLSLD_GOT_OFF) {
1389
1396
sym.setFlags (NEEDS_GOT_DTPREL);
1390
- c. addReloc ({expr, type, offset, addend, &sym});
1397
+ sec-> addReloc ({expr, type, offset, addend, &sym});
1391
1398
return 1 ;
1392
1399
}
1393
1400
@@ -1396,7 +1403,7 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym,
1396
1403
R_LOONGARCH_TLSGD_PAGE_PC>(expr)) {
1397
1404
if (!execOptimize) {
1398
1405
sym.setFlags (NEEDS_TLSGD);
1399
- c. addReloc ({expr, type, offset, addend, &sym});
1406
+ sec-> addReloc ({expr, type, offset, addend, &sym});
1400
1407
return 1 ;
1401
1408
}
1402
1409
@@ -1405,14 +1412,14 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym,
1405
1412
//
1406
1413
// R_RISCV_TLSDESC_{LOAD_LO12,ADD_LO12_I,CALL} reference a non-preemptible
1407
1414
// label, so TLSDESC=>IE will be categorized as R_RELAX_TLS_GD_TO_LE. We fix
1408
- // the categorization in RISCV::relocateAlloc.
1415
+ // the categorization in RISCV::relocateAllosec->
1409
1416
if (sym.isPreemptible ) {
1410
1417
sym.setFlags (NEEDS_TLSGD_TO_IE);
1411
- c. addReloc ({ctx.target ->adjustTlsExpr (type, R_RELAX_TLS_GD_TO_IE), type ,
1412
- offset, addend, &sym});
1418
+ sec-> addReloc ({ctx.target ->adjustTlsExpr (type, R_RELAX_TLS_GD_TO_IE),
1419
+ type, offset, addend, &sym});
1413
1420
} else {
1414
- c. addReloc ({ctx.target ->adjustTlsExpr (type, R_RELAX_TLS_GD_TO_LE), type ,
1415
- offset, addend, &sym});
1421
+ sec-> addReloc ({ctx.target ->adjustTlsExpr (type, R_RELAX_TLS_GD_TO_LE),
1422
+ type, offset, addend, &sym});
1416
1423
}
1417
1424
return ctx.target ->getTlsGdRelaxSkip (type);
1418
1425
}
@@ -1423,15 +1430,15 @@ static unsigned handleTlsRelocation(RelType type, Symbol &sym,
1423
1430
// Initial-Exec relocs can be optimized to Local-Exec if the symbol is
1424
1431
// locally defined. This is not supported on SystemZ.
1425
1432
if (execOptimize && isLocalInExecutable && ctx.arg .emachine != EM_S390) {
1426
- c. addReloc ({R_RELAX_TLS_IE_TO_LE, type, offset, addend, &sym});
1433
+ sec-> addReloc ({R_RELAX_TLS_IE_TO_LE, type, offset, addend, &sym});
1427
1434
} else if (expr != R_TLSIE_HINT) {
1428
1435
sym.setFlags (NEEDS_TLSIE);
1429
1436
// R_GOT needs a relative relocation for PIC on i386 and Hexagon.
1430
1437
if (expr == R_GOT && ctx.arg .isPic &&
1431
1438
!ctx.target ->usesOnlyLowPageBits (type))
1432
- addRelativeReloc<true >(c , offset, sym, addend, expr, type);
1439
+ addRelativeReloc<true >(*sec , offset, sym, addend, expr, type);
1433
1440
else
1434
- c. addReloc ({expr, type, offset, addend, &sym});
1441
+ sec-> addReloc ({expr, type, offset, addend, &sym});
1435
1442
}
1436
1443
return 1 ;
1437
1444
}
@@ -1539,7 +1546,7 @@ void RelocationScanner::scanOne(typename Relocs<RelTy>::const_iterator &i) {
1539
1546
// but we need to process them in handleTlsRelocation.
1540
1547
if (sym.isTls () || oneof<R_TLSDESC_PC, R_TLSDESC_CALL>(expr)) {
1541
1548
if (unsigned processed =
1542
- handleTlsRelocation (type, sym, *sec, offset, addend, expr )) {
1549
+ handleTlsRelocation (expr, type, offset, sym, addend )) {
1543
1550
i += processed - 1 ;
1544
1551
return ;
1545
1552
}
@@ -1635,7 +1642,7 @@ void RelocationScanner::scanSection(InputSectionBase &s, bool isEH) {
1635
1642
scan<ELFT>(rels.relas );
1636
1643
}
1637
1644
1638
- template <class ELFT > void elf::scanRelocations () {
1645
+ template <class ELFT > void elf::scanRelocations (Ctx &ctx ) {
1639
1646
// Scan all relocations. Each relocation goes through a series of tests to
1640
1647
// determine if it needs special treatment, such as creating GOT, PLT,
1641
1648
// copy relocations, etc. Note that relocations for non-alloc sections are
@@ -1649,8 +1656,8 @@ template <class ELFT> void elf::scanRelocations() {
1649
1656
parallel::TaskGroup tg;
1650
1657
auto outerFn = [&]() {
1651
1658
for (ELFFileBase *f : ctx.objectFiles ) {
1652
- auto fn = [f]() {
1653
- RelocationScanner scanner;
1659
+ auto fn = [f, &ctx ]() {
1660
+ RelocationScanner scanner (ctx) ;
1654
1661
for (InputSectionBase *s : f->getSections ()) {
1655
1662
if (s && s->kind () == SectionBase::Regular && s->isLive () &&
1656
1663
(s->flags & SHF_ALLOC) &&
@@ -1663,8 +1670,8 @@ template <class ELFT> void elf::scanRelocations() {
1663
1670
else
1664
1671
tg.spawn (fn);
1665
1672
}
1666
- auto scanEH = [] {
1667
- RelocationScanner scanner;
1673
+ auto scanEH = [& ] {
1674
+ RelocationScanner scanner (ctx) ;
1668
1675
for (Partition &part : ctx.partitions ) {
1669
1676
for (EhInputSection *sec : part.ehFrame ->sections )
1670
1677
scanner.template scanSection <ELFT>(*sec, /* isEH=*/ true );
@@ -1771,8 +1778,8 @@ static bool handleNonPreemptibleIfunc(Symbol &sym, uint16_t flags) {
1771
1778
return true ;
1772
1779
}
1773
1780
1774
- void elf::postScanRelocations () {
1775
- auto fn = [](Symbol &sym) {
1781
+ void elf::postScanRelocations (Ctx &ctx ) {
1782
+ auto fn = [& ](Symbol &sym) {
1776
1783
auto flags = sym.flags .load (std::memory_order_relaxed);
1777
1784
if (handleNonPreemptibleIfunc (sym, flags))
1778
1785
return ;
@@ -2453,10 +2460,10 @@ template <class ELFT> void elf::checkNoCrossRefs() {
2453
2460
}
2454
2461
}
2455
2462
2456
- template void elf::scanRelocations<ELF32LE>();
2457
- template void elf::scanRelocations<ELF32BE>();
2458
- template void elf::scanRelocations<ELF64LE>();
2459
- template void elf::scanRelocations<ELF64BE>();
2463
+ template void elf::scanRelocations<ELF32LE>(Ctx & );
2464
+ template void elf::scanRelocations<ELF32BE>(Ctx & );
2465
+ template void elf::scanRelocations<ELF64LE>(Ctx & );
2466
+ template void elf::scanRelocations<ELF64BE>(Ctx & );
2460
2467
2461
2468
template void elf::checkNoCrossRefs<ELF32LE>();
2462
2469
template void elf::checkNoCrossRefs<ELF32BE>();
0 commit comments