Skip to content

Commit f71f95d

Browse files
authored
[ELF] Rename IsRela to HasAddend
`IsRela` is used by lld to differentiate REL and RELA static relocations. The proposed CREL patch will reuse `IsRela` for CREL (#91280). Rename `IsRela` to be more appropriate. Pull Request: #96592
1 parent b347a72 commit f71f95d

File tree

3 files changed

+16
-14
lines changed

3 files changed

+16
-14
lines changed

lld/ELF/InputSection.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ void InputSection::copyRelocations(uint8_t *buf,
411411
auto *p = reinterpret_cast<typename ELFT::Rela *>(buf);
412412
buf += sizeof(RelTy);
413413

414-
if (RelTy::IsRela)
414+
if (RelTy::HasAddend)
415415
p->r_addend = rel.addend;
416416

417417
// Output section VA is zero for -r, so r_offset is an offset within the
@@ -452,7 +452,7 @@ void InputSection::copyRelocations(uint8_t *buf,
452452

453453
int64_t addend = rel.addend;
454454
const uint8_t *bufLoc = sec->content().begin() + rel.offset;
455-
if (!RelTy::IsRela)
455+
if (!RelTy::HasAddend)
456456
addend = target.getImplicitAddend(bufLoc, type);
457457

458458
if (config->emachine == EM_MIPS &&
@@ -471,7 +471,7 @@ void InputSection::copyRelocations(uint8_t *buf,
471471
addend += sec->getFile<ELFT>()->mipsGp0;
472472
}
473473

474-
if (RelTy::IsRela)
474+
if (RelTy::HasAddend)
475475
p->r_addend = sym.getVA(addend) - section->getOutputSection()->addr;
476476
// For SHF_ALLOC sections relocated by REL, append a relocation to
477477
// sec->relocations so that relocateAlloc transitively called by
@@ -934,7 +934,7 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
934934
const uint64_t offset = rel.r_offset;
935935
uint8_t *bufLoc = buf + offset;
936936
int64_t addend = getAddend<ELFT>(rel);
937-
if (!RelTy::IsRela)
937+
if (!RelTy::HasAddend)
938938
addend += target.getImplicitAddend(bufLoc, type);
939939

940940
Symbol &sym = f->getRelocTargetSym(rel);
@@ -1007,10 +1007,11 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
10071007
}
10081008
}
10091009

1010-
// For a relocatable link, content relocated by RELA remains unchanged and
1011-
// we can stop here, while content relocated by REL referencing STT_SECTION
1012-
// needs updating implicit addends.
1013-
if (config->relocatable && (RelTy::IsRela || sym.type != STT_SECTION))
1010+
// For a relocatable link, content relocated by relocation types with an
1011+
// explicit addend, such as RELA, remain unchanged and we can stop here.
1012+
// While content relocated by relocation types with an implicit addend, such
1013+
// as REL, needs the implicit addend updated.
1014+
if (config->relocatable && (RelTy::HasAddend || sym.type != STT_SECTION))
10141015
continue;
10151016

10161017
// R_ABS/R_DTPREL and some other relocations can be used from non-SHF_ALLOC

lld/ELF/Relocations.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,8 @@ int64_t RelocationScanner::computeMipsAddend(const RelTy &rel, RelExpr expr,
492492

493493
// The ABI says that the paired relocation is used only for REL.
494494
// See p. 4-17 at ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
495-
if (RelTy::IsRela)
495+
// This generalises to relocation types with implicit addends.
496+
if (RelTy::HasAddend)
496497
return 0;
497498

498499
RelType type = rel.getType(config->isMips64EL);
@@ -1448,7 +1449,7 @@ template <class ELFT, class RelTy> void RelocationScanner::scanOne(RelTy *&i) {
14481449
return;
14491450

14501451
RelExpr expr = target->getRelExpr(type, sym, sec->content().data() + offset);
1451-
int64_t addend = RelTy::IsRela
1452+
int64_t addend = RelTy::HasAddend
14521453
? getAddend<ELFT>(rel)
14531454
: target->getImplicitAddend(
14541455
sec->content().data() + rel.r_offset, type);

llvm/include/llvm/Object/ELFTypes.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ struct Elf_Dyn_Impl : Elf_Dyn_Base<ELFT> {
384384
template <endianness Endianness>
385385
struct Elf_Rel_Impl<ELFType<Endianness, false>, false> {
386386
LLVM_ELF_IMPORT_TYPES(Endianness, false)
387-
static const bool IsRela = false;
387+
static const bool HasAddend = false;
388388
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
389389
Elf_Word r_info; // Symbol table index and type of relocation to apply
390390

@@ -420,14 +420,14 @@ template <endianness Endianness>
420420
struct Elf_Rel_Impl<ELFType<Endianness, false>, true>
421421
: public Elf_Rel_Impl<ELFType<Endianness, false>, false> {
422422
LLVM_ELF_IMPORT_TYPES(Endianness, false)
423-
static const bool IsRela = true;
423+
static const bool HasAddend = true;
424424
Elf_Sword r_addend; // Compute value for relocatable field by adding this
425425
};
426426

427427
template <endianness Endianness>
428428
struct Elf_Rel_Impl<ELFType<Endianness, true>, false> {
429429
LLVM_ELF_IMPORT_TYPES(Endianness, true)
430-
static const bool IsRela = false;
430+
static const bool HasAddend = false;
431431
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
432432
Elf_Xword r_info; // Symbol table index and type of relocation to apply
433433

@@ -473,7 +473,7 @@ template <endianness Endianness>
473473
struct Elf_Rel_Impl<ELFType<Endianness, true>, true>
474474
: public Elf_Rel_Impl<ELFType<Endianness, true>, false> {
475475
LLVM_ELF_IMPORT_TYPES(Endianness, true)
476-
static const bool IsRela = true;
476+
static const bool HasAddend = true;
477477
Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
478478
};
479479

0 commit comments

Comments
 (0)