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

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Thu May 9 23:36:32 PDT 2024


================
@@ -1117,9 +1166,11 @@ void ELFObjectFile<ELFT>::getRelocationTypeName(
 template <class ELFT>
 Expected<int64_t>
 ELFObjectFile<ELFT>::getRelocationAddend(DataRefImpl Rel) const {
-  if (getRelSection(Rel)->sh_type != ELF::SHT_RELA)
-    return createError("Section is not SHT_RELA");
-  return (int64_t)getRela(Rel)->r_addend;
+  if (getRelSection(Rel)->sh_type == ELF::SHT_RELA)
+    return (int64_t)getRela(Rel)->r_addend;
+  if (getRelSection(Rel)->sh_type == ELF::SHT_CREL)
----------------
MaskRay wrote:

I have reverted this file. Sorry for leaving it in the initial patch.

This code is used by `.getAddend()` in the files (not core binary utilities).

* llvm/lib/Object/RelocationResolver.cpp
* llvm/lib/XRay/InstrumentationMap.cpp
* llvm/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldELF.cpp

Since they are all for static relocations, we can assume `r_addend`.
However, I agree that having an error checking would be nice.


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


More information about the cfe-commits mailing list