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

James Henderson via cfe-commits cfe-commits at lists.llvm.org
Thu May 23 02:38:16 PDT 2024


================
@@ -392,6 +393,70 @@ ELFFile<ELFT>::decode_relrs(Elf_Relr_Range relrs) const {
   return Relocs;
 }
 
+template <class ELFT>
+uint64_t ELFFile<ELFT>::crelHeader(ArrayRef<uint8_t> Content) const {
+  DataExtractor Data(Content, true, 8); // endian/class is irrelevant
+  DataExtractor::Cursor Cur(0);
+  uint64_t Hdr = Data.getULEB128(Cur);
+  // In case of an error, return 0 and postpone error reporting to decodeCrel.
+  consumeError(Cur.takeError());
+  return Hdr;
+}
+
+template <class ELFT>
+Expected<typename ELFFile<ELFT>::RelsOrRelas>
+ELFFile<ELFT>::decodeCrel(ArrayRef<uint8_t> Content) const {
+  DataExtractor Data(Content, true, 8); // endian/class is irrelevant
+  DataExtractor::Cursor Cur(0);
+  const uint64_t Hdr = Data.getULEB128(Cur);
+  const size_t Count = Hdr / 8, FlagBits = Hdr & ELF::CREL_HDR_ADDEND ? 3 : 2,
+               Shift = Hdr % ELF::CREL_HDR_ADDEND;
----------------
jh7370 wrote:

This line is unnecessarily complicated. It would be much clearer to just define each variable on a separate line.

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


More information about the cfe-commits mailing list