[clang] [llvm] [MC,llvm-readobj,yaml2obj] Support CREL relocation format (PR #91280)

James Henderson via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 19 06:39:05 PDT 2024


================
@@ -392,6 +393,73 @@ ELFFile<ELFT>::decode_relrs(Elf_Relr_Range relrs) const {
   return Relocs;
 }
 
+template <class ELFT>
+Expected<uint64_t>
+ELFFile<ELFT>::getCrelHeader(ArrayRef<uint8_t> Content) const {
+  DataExtractor Data(Content, isLE(), ELFT::Is64Bits ? 8 : 4);
+  Error Err = Error::success();
+  uint64_t Hdr = 0;
+  Hdr = Data.getULEB128(&Hdr, &Err);
+  if (Err)
+    return Err;
+  return Hdr;
+}
+
+template <class ELFT>
+Expected<typename ELFFile<ELFT>::RelsOrRelas>
+ELFFile<ELFT>::decodeCrel(ArrayRef<uint8_t> Content) const {
+  DataExtractor Data(Content, isLE(), ELFT::Is64Bits ? 8 : 4);
+  DataExtractor::Cursor Cur(0);
+  const uint64_t Hdr = Data.getULEB128(Cur);
+  const size_t Count = Hdr / 8;
+  const size_t FlagBits = Hdr & ELF::CREL_HDR_ADDEND ? 3 : 2;
+  const size_t Shift = Hdr % ELF::CREL_HDR_ADDEND;
+  std::vector<Elf_Rel> Rels;
+  std::vector<Elf_Rela> Relas;
+  if (Hdr & ELF::CREL_HDR_ADDEND)
+    Relas.resize(Count);
+  else
+    Rels.resize(Count);
+  typename ELFT::uint Offset = 0, Addend = 0;
+  uint32_t Symidx = 0, Type = 0;
----------------
jh7370 wrote:

Nit, since it is short for symbol index (i.e. two words). Same below.
```suggestion
  uint32_t SymIdx = 0, Type = 0;
```

https://github.com/llvm/llvm-project/pull/91280


More information about the cfe-commits mailing list