-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[ELF] Rename IsRela to HasAddend #96592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ELF] Rename IsRela to HasAddend #96592
Conversation
Created using spr 1.3.5-bogner
@llvm/pr-subscribers-lld @llvm/pr-subscribers-llvm-binary-utilities Author: Fangrui Song (MaskRay) Changes
Full diff: https://github.com/llvm/llvm-project/pull/96592.diff 3 Files Affected:
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index be12218d9948c..35247ebb7b55e 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);
@@ -1010,7 +1010,7 @@ 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))
+ 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..e09914cb3b276 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -492,7 +492,7 @@ 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)
+ if (RelTy::HasAddend)
return 0;
RelType type = rel.getType(config->isMips64EL);
@@ -1448,7 +1448,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.
};
|
@llvm/pr-subscribers-lld-elf Author: Fangrui Song (MaskRay) Changes
Full diff: https://github.com/llvm/llvm-project/pull/96592.diff 3 Files Affected:
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index be12218d9948c..35247ebb7b55e 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);
@@ -1010,7 +1010,7 @@ 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))
+ 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..e09914cb3b276 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -492,7 +492,7 @@ 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)
+ if (RelTy::HasAddend)
return 0;
RelType type = rel.getType(config->isMips64EL);
@@ -1448,7 +1448,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.
};
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No objections from me, a couple of places where some adjacent comments might be worth updating. Not got a particularly strong opinion on that though.
@@ -1010,7 +1010,7 @@ 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)) | |||
if (config->relocatable && (RelTy::HasAddend || sym.type != STT_SECTION)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comment above might be worth updating assuming CREL will behave in the same way. Perhaps something like:
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.
@@ -492,7 +492,7 @@ 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) | |||
if (RelTy::HasAddend) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming MIPS will support CREL, but the ABI won't be updated to explicitly mention it, could be worth a small addition at the end.
The ABI says 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 this generalises to relocation types with implicit addends.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thx. Added. (I think MIPS will die before anyone implements CREL for it...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, pending @smithp35's comments. (I note the buildkite failure, but assume it to be unrelated)
`IsRela` is used by lld to differentiate REL and RELA static relocations. The proposed CREL patch will reuse `IsRela` for CREL (llvm#91280). Rename `IsRela` to be more appropriate. Pull Request: llvm#96592
IsRela
is used by lld to differentiate REL and RELA staticrelocations. The proposed CREL patch will reuse
IsRela
for CREL(#91280). Rename
IsRela
to be more appropriate.