[llvm] f71f95d - [ELF] Rename IsRela to HasAddend
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 25 20:11:30 PDT 2024
Author: Fangrui Song
Date: 2024-06-25T20:11:27-07:00
New Revision: f71f95d6aa27057f4fc10695ee9c8eb1ec77b763
URL: https://github.com/llvm/llvm-project/commit/f71f95d6aa27057f4fc10695ee9c8eb1ec77b763
DIFF: https://github.com/llvm/llvm-project/commit/f71f95d6aa27057f4fc10695ee9c8eb1ec77b763.diff
LOG: [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: https://github.com/llvm/llvm-project/pull/96592
Added:
Modified:
lld/ELF/InputSection.cpp
lld/ELF/Relocations.cpp
llvm/include/llvm/Object/ELFTypes.h
Removed:
################################################################################
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index be12218d9948c..4420be77f6685 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -411,7 +411,7 @@ void InputSection::copyRelocations(uint8_t *buf,
auto *p = reinterpret_cast<typename ELFT::Rela *>(buf);
buf += sizeof(RelTy);
- if (RelTy::IsRela)
+ if (RelTy::HasAddend)
p->r_addend = rel.addend;
// 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,
int64_t addend = rel.addend;
const uint8_t *bufLoc = sec->content().begin() + rel.offset;
- if (!RelTy::IsRela)
+ if (!RelTy::HasAddend)
addend = target.getImplicitAddend(bufLoc, type);
if (config->emachine == EM_MIPS &&
@@ -471,7 +471,7 @@ void InputSection::copyRelocations(uint8_t *buf,
addend += sec->getFile<ELFT>()->mipsGp0;
}
- if (RelTy::IsRela)
+ if (RelTy::HasAddend)
p->r_addend = sym.getVA(addend) - section->getOutputSection()->addr;
// For SHF_ALLOC sections relocated by REL, append a relocation to
// sec->relocations so that relocateAlloc transitively called by
@@ -934,7 +934,7 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
const uint64_t offset = rel.r_offset;
uint8_t *bufLoc = buf + offset;
int64_t addend = getAddend<ELFT>(rel);
- if (!RelTy::IsRela)
+ if (!RelTy::HasAddend)
addend += target.getImplicitAddend(bufLoc, type);
Symbol &sym = f->getRelocTargetSym(rel);
@@ -1007,10 +1007,11 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
}
}
- // For a relocatable link, content relocated by RELA remains unchanged and
- // we can stop here, while content relocated by REL referencing STT_SECTION
- // needs updating implicit addends.
- if (config->relocatable && (RelTy::IsRela || sym.type != STT_SECTION))
+ // For a relocatable link, content relocated by relocation types with an
+ // explicit addend, such as RELA, remain unchanged and we can stop here.
+ // While content relocated by relocation types with an implicit addend, such
+ // as REL, needs the implicit addend updated.
+ if (config->relocatable && (RelTy::HasAddend || sym.type != STT_SECTION))
continue;
// R_ABS/R_DTPREL and some other relocations can be used from non-SHF_ALLOC
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 1b08339e3996a..f0f37c8ebc0b4 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -492,7 +492,8 @@ int64_t RelocationScanner::computeMipsAddend(const RelTy &rel, RelExpr expr,
// The ABI says that the paired relocation is used only for REL.
// See p. 4-17 at ftp://www.linux-mips.org/pub/linux/mips/doc/ABI/mipsabi.pdf
- if (RelTy::IsRela)
+ // This generalises to relocation types with implicit addends.
+ if (RelTy::HasAddend)
return 0;
RelType type = rel.getType(config->isMips64EL);
@@ -1448,7 +1449,7 @@ template <class ELFT, class RelTy> void RelocationScanner::scanOne(RelTy *&i) {
return;
RelExpr expr = target->getRelExpr(type, sym, sec->content().data() + offset);
- int64_t addend = RelTy::IsRela
+ int64_t addend = RelTy::HasAddend
? getAddend<ELFT>(rel)
: target->getImplicitAddend(
sec->content().data() + rel.r_offset, type);
diff --git a/llvm/include/llvm/Object/ELFTypes.h b/llvm/include/llvm/Object/ELFTypes.h
index 4ab23e4ea81b1..ec10762a5df3f 100644
--- a/llvm/include/llvm/Object/ELFTypes.h
+++ b/llvm/include/llvm/Object/ELFTypes.h
@@ -384,7 +384,7 @@ struct Elf_Dyn_Impl : Elf_Dyn_Base<ELFT> {
template <endianness Endianness>
struct Elf_Rel_Impl<ELFType<Endianness, false>, false> {
LLVM_ELF_IMPORT_TYPES(Endianness, false)
- static const bool IsRela = false;
+ static const bool HasAddend = false;
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
Elf_Word r_info; // Symbol table index and type of relocation to apply
@@ -420,14 +420,14 @@ template <endianness Endianness>
struct Elf_Rel_Impl<ELFType<Endianness, false>, true>
: public Elf_Rel_Impl<ELFType<Endianness, false>, false> {
LLVM_ELF_IMPORT_TYPES(Endianness, false)
- static const bool IsRela = true;
+ static const bool HasAddend = true;
Elf_Sword r_addend; // Compute value for relocatable field by adding this
};
template <endianness Endianness>
struct Elf_Rel_Impl<ELFType<Endianness, true>, false> {
LLVM_ELF_IMPORT_TYPES(Endianness, true)
- static const bool IsRela = false;
+ static const bool HasAddend = false;
Elf_Addr r_offset; // Location (file byte offset, or program virtual addr)
Elf_Xword r_info; // Symbol table index and type of relocation to apply
@@ -473,7 +473,7 @@ template <endianness Endianness>
struct Elf_Rel_Impl<ELFType<Endianness, true>, true>
: public Elf_Rel_Impl<ELFType<Endianness, true>, false> {
LLVM_ELF_IMPORT_TYPES(Endianness, true)
- static const bool IsRela = true;
+ static const bool HasAddend = true;
Elf_Sxword r_addend; // Compute value for relocatable field by adding this.
};
More information about the llvm-commits
mailing list