[llvm] [Object][COFF][llvm-readobj] Add support for ARM64X dynamic relocations. (PR #97229)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 26 11:51:21 PDT 2024


================
@@ -800,6 +800,218 @@ Error COFFObjectFile::initLoadConfigPtr() {
     }
   }
 
+  // Interpret and validate dynamic relocations.
+  uint32_t DynamicRelocTableOffset = 0, DynamicRelocTableSection = 0;
+  if (is64()) {
+    auto Config = getLoadConfig64();
+    if (Config->Size >=
+        offsetof(coff_load_configuration64, DynamicValueRelocTableSection) +
+            sizeof(Config->DynamicValueRelocTableSection)) {
+      DynamicRelocTableSection = Config->DynamicValueRelocTableSection;
+      DynamicRelocTableOffset = Config->DynamicValueRelocTableOffset;
+    }
+  } else {
+    auto Config = getLoadConfig32();
+    if (Config->Size >=
+        offsetof(coff_load_configuration32, DynamicValueRelocTableSection) +
+            sizeof(Config->DynamicValueRelocTableSection)) {
+      DynamicRelocTableSection = Config->DynamicValueRelocTableSection;
+      DynamicRelocTableOffset = Config->DynamicValueRelocTableOffset;
+    }
+  }
+
+  Expected<const coff_section *> Section = getSection(DynamicRelocTableSection);
+  if (!Section)
+    return Section.takeError();
+  if (*Section) {
+    ArrayRef<uint8_t> Contents;
+    if (Error E = getSectionContents(*Section, Contents))
+      return E;
+
+    Contents = Contents.drop_front(DynamicRelocTableOffset);
+    if (Contents.size() < sizeof(coff_dynamic_reloc_table))
+      return createStringError(object_error::parse_failed,
+                               "Too large DynamicValueRelocTableOffset (" +
+                                   Twine(DynamicRelocTableOffset) + ")");
+
+    DynamicRelocTable =
+        reinterpret_cast<const coff_dynamic_reloc_table *>(Contents.data());
+
+    if (DynamicRelocTable->Version != 1 && DynamicRelocTable->Version != 2) {
+      DynamicRelocTable = nullptr;
+      return Error::success();
----------------
efriedma-quic wrote:

For objdump, I can see an argument for continuing to dump (ideally with a warning), but other uses of object files likely want to bail out of they can't parse an important part of the object file.  And the API doesn't really provide any way to tell what happened.

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


More information about the llvm-commits mailing list