[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Sun May 19 11:38:10 PDT 2024
================
@@ -1278,29 +1285,69 @@ void ELFState<ELFT>::writeSectionContent(
if (!Section.Relocations)
return;
+ const bool IsCrel = Section.Type == llvm::ELF::SHT_CREL;
const bool IsRela = Section.Type == llvm::ELF::SHT_RELA;
+ typename ELFT::uint OffsetMask = 8, Offset = 0, Addend = 0;
+ uint32_t Symidx = 0, Type = 0;
+ uint64_t CurrentOffset = CBA.getOffset();
+ if (IsCrel)
+ for (const ELFYAML::Relocation &Rel : *Section.Relocations)
+ OffsetMask |= Rel.Offset;
+ const int Shift = llvm::countr_zero(OffsetMask);
+ if (IsCrel)
+ CBA.writeULEB128(Section.Relocations->size() * 8 + 4 + Shift);
for (const ELFYAML::Relocation &Rel : *Section.Relocations) {
const bool IsDynamic = Section.Link && (*Section.Link == ".dynsym");
- unsigned SymIdx =
+ uint32_t CurSymidx =
Rel.Symbol ? toSymbolIndex(*Rel.Symbol, Section.Name, IsDynamic) : 0;
- if (IsRela) {
+ if (IsCrel) {
----------------
MaskRay wrote:
I've thought about an abstraction. However, the variable and `toSymbolIndex` mechanism are different, making me feel that code sharing would be cumbersome...
https://github.com/llvm/llvm-project/pull/91280
More information about the cfe-commits
mailing list