================ @@ -940,6 +940,92 @@ ELFFile<ELFT>::decodeBBAddrMap(const Elf_Shdr &Sec, const Elf_Shdr *RelaSec, return std::move(AddrMapsOrErr); } +template <class ELFT> +Expected<std::vector<FuncMap>> +ELFFile<ELFT>::decodeFuncMap(const Elf_Shdr &Sec, + const Elf_Shdr *RelaSec) const { + bool IsRelocatable = this->getHeader().e_type == ELF::ET_REL; + + // This DenseMap maps the offset of each function (the location of the + // reference to the function in the SHT_LLVM_FUNC_MAP section) to the + // addend (the location of the function in the text section). + llvm::DenseMap<uint64_t, uint64_t> FunctionOffsetTranslations; + if (IsRelocatable && RelaSec) { + assert(RelaSec && + "Can't read a SHT_LLVM_FUNC_ADDR_MAP section in a relocatable " + "object file without providing a relocation section."); + Expected<typename ELFFile<ELFT>::Elf_Rela_Range> Relas = + this->relas(*RelaSec); + if (!Relas) + return createError("unable to read relocations for section " + + describe(*this, Sec) + ": " + + toString(Relas.takeError())); + for (typename ELFFile<ELFT>::Elf_Rela Rela : *Relas) + FunctionOffsetTranslations[Rela.r_offset] = Rela.r_addend; ---------------- jh7370 wrote:
Not all relocations function in the same way. Naively assuming that the `r_addend` and `r_offset` work like this is not going to be correct in some cases. The ELF gABI only describes `r_addend` as a "constant addend used to compute the value". Have you looked into the Object/RelocationResolver.h? It's used elsewhere by llvm-readobj to calculate the values of relocations and may be of some use (see `printRelocatableStackSizes` for an example usage). https://github.com/llvm/llvm-project/pull/124333 _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits