[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:15:04 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();
----------------
mstorsjo wrote:
FWIW, this distinction between verifying all aspects, or just reading as much as possible with as little judgement as possible, is indeed quite frustrating at times.
If you have an object file that our tools reject, our tools also are quite unfriendly in helping you figure out what really is wrong. (I remember doing a WIP/throwaway branch sometime to make all the COFFObjectFile errors much more verbose, and to continue parsing as far as possible, to let me analyze some file.)
https://github.com/llvm/llvm-project/pull/97229
More information about the llvm-commits
mailing list