@@ -400,18 +400,20 @@ InputSectionBase *InputSection::getRelocatedSection() const {
400
400
}
401
401
402
402
template <class ELFT , class RelTy >
403
- void InputSection::copyRelocations (uint8_t *buf) {
403
+ void InputSection::copyRelocations (Ctx &ctx, uint8_t *buf) {
404
404
if (ctx.arg .relax && !ctx.arg .relocatable &&
405
405
(ctx.arg .emachine == EM_RISCV || ctx.arg .emachine == EM_LOONGARCH)) {
406
406
// On LoongArch and RISC-V, relaxation might change relocations: copy
407
407
// from internal ones that are updated by relaxation.
408
408
InputSectionBase *sec = getRelocatedSection ();
409
- copyRelocations<ELFT, RelTy>(buf, llvm::make_range (sec->relocations .begin (),
410
- sec->relocations .end ()));
409
+ copyRelocations<ELFT, RelTy>(
410
+ ctx, buf,
411
+ llvm::make_range (sec->relocations .begin (), sec->relocations .end ()));
411
412
} else {
412
413
// Convert the raw relocations in the input section into Relocation objects
413
414
// suitable to be used by copyRelocations below.
414
415
struct MapRel {
416
+ Ctx &ctx;
415
417
const ObjFile<ELFT> &file;
416
418
Relocation operator ()(const RelTy &rel) const {
417
419
// RelExpr is not used so set to a dummy value.
@@ -423,21 +425,20 @@ void InputSection::copyRelocations(uint8_t *buf) {
423
425
using RawRels = ArrayRef<RelTy>;
424
426
using MapRelIter =
425
427
llvm::mapped_iterator<typename RawRels::iterator, MapRel>;
426
- auto mapRel = MapRel{*getFile<ELFT>()};
428
+ auto mapRel = MapRel{ctx, *getFile<ELFT>()};
427
429
RawRels rawRels = getDataAs<RelTy>();
428
430
auto rels = llvm::make_range (MapRelIter (rawRels.begin (), mapRel),
429
431
MapRelIter (rawRels.end (), mapRel));
430
- copyRelocations<ELFT, RelTy>(buf, rels);
432
+ copyRelocations<ELFT, RelTy>(ctx, buf, rels);
431
433
}
432
434
}
433
435
434
436
// This is used for -r and --emit-relocs. We can't use memcpy to copy
435
437
// relocations because we need to update symbol table offset and section index
436
438
// for each relocation. So we copy relocations one by one.
437
439
template <class ELFT , class RelTy , class RelIt >
438
- void InputSection::copyRelocations (uint8_t *buf,
440
+ void InputSection::copyRelocations (Ctx &ctx, uint8_t *buf,
439
441
llvm::iterator_range<RelIt> rels) {
440
- Ctx &ctx = getCtx ();
441
442
const TargetInfo &target = *ctx.target ;
442
443
InputSectionBase *sec = getRelocatedSection ();
443
444
(void )sec->contentMaybeDecompress (); // uncompress if needed
@@ -973,9 +974,10 @@ uint64_t InputSectionBase::getRelocTargetVA(Ctx &ctx, const Relocation &r,
973
974
// So, we handle relocations for non-alloc sections directly in this
974
975
// function as a performance optimization.
975
976
template <class ELFT , class RelTy >
976
- void InputSection::relocateNonAlloc (uint8_t *buf, Relocs<RelTy> rels) {
977
+ void InputSection::relocateNonAlloc (Ctx &ctx, uint8_t *buf,
978
+ Relocs<RelTy> rels) {
977
979
const unsigned bits = sizeof (typename ELFT::uint) * 8 ;
978
- const TargetInfo &target = *elf:: ctx.target ;
980
+ const TargetInfo &target = *ctx.target ;
979
981
const auto emachine = ctx.arg .emachine ;
980
982
const bool isDebug = isDebugSection (*this );
981
983
const bool isDebugLine = isDebug && name == " .debug_line" ;
@@ -1123,9 +1125,9 @@ void InputSection::relocateNonAlloc(uint8_t *buf, Relocs<RelTy> rels) {
1123
1125
}
1124
1126
1125
1127
template <class ELFT >
1126
- void InputSectionBase::relocate (uint8_t *buf, uint8_t *bufEnd) {
1128
+ void InputSectionBase::relocate (Ctx &ctx, uint8_t *buf, uint8_t *bufEnd) {
1127
1129
if ((flags & SHF_EXECINSTR) && LLVM_UNLIKELY (getFile<ELFT>()->splitStack ))
1128
- adjustSplitStackFunctionPrologues<ELFT>(buf, bufEnd);
1130
+ adjustSplitStackFunctionPrologues<ELFT>(ctx, buf, bufEnd);
1129
1131
1130
1132
if (flags & SHF_ALLOC) {
1131
1133
ctx.target ->relocateAlloc (*this , buf);
@@ -1135,13 +1137,13 @@ void InputSectionBase::relocate(uint8_t *buf, uint8_t *bufEnd) {
1135
1137
auto *sec = cast<InputSection>(this );
1136
1138
// For a relocatable link, also call relocateNonAlloc() to rewrite applicable
1137
1139
// locations with tombstone values.
1138
- invokeOnRelocs (*sec, sec->relocateNonAlloc <ELFT>, buf);
1140
+ invokeOnRelocs (*sec, sec->relocateNonAlloc <ELFT>, ctx, buf);
1139
1141
}
1140
1142
1141
1143
// For each function-defining prologue, find any calls to __morestack,
1142
1144
// and replace them with calls to __morestack_non_split.
1143
1145
static void switchMorestackCallsToMorestackNonSplit (
1144
- DenseSet<Defined *> &prologues,
1146
+ Ctx &ctx, DenseSet<Defined *> &prologues,
1145
1147
SmallVector<Relocation *, 0 > &morestackCalls) {
1146
1148
1147
1149
// If the target adjusted a function's prologue, all calls to
@@ -1189,7 +1191,7 @@ static bool enclosingPrologueAttempted(uint64_t offset,
1189
1191
// adjusted to ensure that the called function will have enough stack
1190
1192
// available. Find those functions, and adjust their prologues.
1191
1193
template <class ELFT >
1192
- void InputSectionBase::adjustSplitStackFunctionPrologues (uint8_t *buf,
1194
+ void InputSectionBase::adjustSplitStackFunctionPrologues (Ctx &ctx, uint8_t *buf,
1193
1195
uint8_t *end) {
1194
1196
DenseSet<Defined *> prologues;
1195
1197
SmallVector<Relocation *, 0 > morestackCalls;
@@ -1234,20 +1236,20 @@ void InputSectionBase::adjustSplitStackFunctionPrologues(uint8_t *buf,
1234
1236
}
1235
1237
1236
1238
if (ctx.target ->needsMoreStackNonSplit )
1237
- switchMorestackCallsToMorestackNonSplit (prologues, morestackCalls);
1239
+ switchMorestackCallsToMorestackNonSplit (ctx, prologues, morestackCalls);
1238
1240
}
1239
1241
1240
- template <class ELFT > void InputSection::writeTo (uint8_t *buf) {
1242
+ template <class ELFT > void InputSection::writeTo (Ctx &ctx, uint8_t *buf) {
1241
1243
if (LLVM_UNLIKELY (type == SHT_NOBITS))
1242
1244
return ;
1243
1245
// If -r or --emit-relocs is given, then an InputSection
1244
1246
// may be a relocation section.
1245
1247
if (LLVM_UNLIKELY (type == SHT_RELA)) {
1246
- copyRelocations<ELFT, typename ELFT::Rela>(buf);
1248
+ copyRelocations<ELFT, typename ELFT::Rela>(ctx, buf);
1247
1249
return ;
1248
1250
}
1249
1251
if (LLVM_UNLIKELY (type == SHT_REL)) {
1250
- copyRelocations<ELFT, typename ELFT::Rel>(buf);
1252
+ copyRelocations<ELFT, typename ELFT::Rel>(ctx, buf);
1251
1253
return ;
1252
1254
}
1253
1255
@@ -1270,14 +1272,14 @@ template <class ELFT> void InputSection::writeTo(uint8_t *buf) {
1270
1272
fatal (toString (this ) +
1271
1273
" : decompress failed: " + llvm::toString (std::move (e)));
1272
1274
uint8_t *bufEnd = buf + size;
1273
- relocate<ELFT>(buf, bufEnd);
1275
+ relocate<ELFT>(ctx, buf, bufEnd);
1274
1276
return ;
1275
1277
}
1276
1278
1277
1279
// Copy section contents from source object file to output file
1278
1280
// and then apply relocations.
1279
1281
memcpy (buf, content ().data (), content ().size ());
1280
- relocate<ELFT>(buf, buf + content ().size ());
1282
+ relocate<ELFT>(ctx, buf, buf + content ().size ());
1281
1283
}
1282
1284
1283
1285
void InputSection::replace (InputSection *other) {
@@ -1415,7 +1417,7 @@ void MergeInputSection::splitNonStrings(ArrayRef<uint8_t> data,
1415
1417
size_t entSize) {
1416
1418
size_t size = data.size ();
1417
1419
assert ((size % entSize) == 0 );
1418
- const bool live = !(flags & SHF_ALLOC) || !ctx .arg .gcSections ;
1420
+ const bool live = !(flags & SHF_ALLOC) || !getCtx () .arg .gcSections ;
1419
1421
1420
1422
pieces.resize_for_overwrite (size / entSize);
1421
1423
for (size_t i = 0 , j = 0 ; i != size; i += entSize, j++)
@@ -1471,10 +1473,10 @@ template InputSection::InputSection(ObjFile<ELF64LE> &, const ELF64LE::Shdr &,
1471
1473
template InputSection::InputSection(ObjFile<ELF64BE> &, const ELF64BE::Shdr &,
1472
1474
StringRef);
1473
1475
1474
- template void InputSection::writeTo<ELF32LE>(uint8_t *);
1475
- template void InputSection::writeTo<ELF32BE>(uint8_t *);
1476
- template void InputSection::writeTo<ELF64LE>(uint8_t *);
1477
- template void InputSection::writeTo<ELF64BE>(uint8_t *);
1476
+ template void InputSection::writeTo<ELF32LE>(Ctx &, uint8_t *);
1477
+ template void InputSection::writeTo<ELF32BE>(Ctx &, uint8_t *);
1478
+ template void InputSection::writeTo<ELF64LE>(Ctx &, uint8_t *);
1479
+ template void InputSection::writeTo<ELF64BE>(Ctx &, uint8_t *);
1478
1480
1479
1481
template RelsOrRelas<ELF32LE>
1480
1482
InputSectionBase::relsOrRelas<ELF32LE>(bool ) const ;
0 commit comments