[llvm] [Object][COFF][llvm-readobj] Add support for ARM64X dynamic relocations. (PR #97229)
Martin Storsjö via llvm-commits
llvm-commits at lists.llvm.org
Sun Jul 28 14:12:41 PDT 2024
================
@@ -800,6 +800,219 @@ 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)
+ return createStringError(
+ object_error::parse_failed,
+ "Unsupported dynamic relocations table version (" +
+ Twine(DynamicRelocTable->Version) + ")");
+
+ Contents = Contents.drop_front(sizeof(*DynamicRelocTable));
+ if (DynamicRelocTable->Size > Contents.size())
+ return createStringError(object_error::parse_failed,
+ "Indvalid dynamic relocations directory size (" +
+ Twine(DynamicRelocTable->Size) + ")");
+ Contents = Contents.take_front(DynamicRelocTable->Size);
+
+ while (!Contents.empty()) {
----------------
mstorsjo wrote:
This whole parsing o the dynamic reloc table feels like quite a lot of code, and it inflates the enclosing function, `initLoadConfigPtr`, quite significantly. I think this would be more readable if split out to a separate function for parsing the dynamic reloc table.
After seeing that some amount of the parsing code here is unused, I'm not quite convinced that this needs to be split, but if the dynamic reloc table handling stuff here is more than maybe 30-50 lines, I'd still favour splitting to a separate function.
https://github.com/llvm/llvm-project/pull/97229
More information about the llvm-commits
mailing list