diff options
author | Aiden Grossman <aidengrossman@google.com> | 2025-02-10 10:58:56 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-10 10:58:56 -0800 |
commit | 56b760cc472fd2e919e5046575b6c537cb7f3d0b (patch) | |
tree | 5103f05c14c34cebf4531712d084eb04320119eb /llvm/lib/Object/ELF.cpp | |
parent | 808b1c11a26ba986a4148e10f30a5ba995766f83 (diff) | |
download | llvm-56b760cc472fd2e919e5046575b6c537cb7f3d0b.zip llvm-56b760cc472fd2e919e5046575b6c537cb7f3d0b.tar.gz llvm-56b760cc472fd2e919e5046575b6c537cb7f3d0b.tar.bz2 |
[ELF] Add support for CREL locations for SHT_LLVM_BB_ADDR_MAP
This patch adds support for properly decoding SHT_LLVM_BB_ADDR_MAP
sections in relocatable object files when the relocation format is CREL.
Reviewers: rlavaee, jh7370, red1bluelost, MaskRay
Reviewed By: MaskRay
Pull Request: https://github.com/llvm/llvm-project/pull/126446
Diffstat (limited to 'llvm/lib/Object/ELF.cpp')
-rw-r--r-- | llvm/lib/Object/ELF.cpp | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/llvm/lib/Object/ELF.cpp b/llvm/lib/Object/ELF.cpp index 8cb3d7e..bf42c92a 100644 --- a/llvm/lib/Object/ELF.cpp +++ b/llvm/lib/Object/ELF.cpp @@ -747,20 +747,25 @@ decodeBBAddrMapImpl(const ELFFile<ELFT> &EF, assert(RelaSec && "Can't read a SHT_LLVM_BB_ADDR_MAP section in a relocatable " "object file without providing a relocation section."); - // We might end up with relocations in CREL here. If we do, return an - // error since we do not currently support them. - if (RelaSec->sh_type == ELF::SHT_CREL) - return createError("unable to read relocations for section " + - describe(EF, Sec) + - " as the corresponding relocation section format is " - "CREL, which is not currently supported."); - Expected<typename ELFFile<ELFT>::Elf_Rela_Range> Relas = EF.relas(*RelaSec); - if (!Relas) - return createError("unable to read relocations for section " + - describe(EF, Sec) + ": " + - toString(Relas.takeError())); - for (typename ELFFile<ELFT>::Elf_Rela Rela : *Relas) - FunctionOffsetTranslations[Rela.r_offset] = Rela.r_addend; + if (RelaSec->sh_type == ELF::SHT_CREL) { + Expected<typename ELFFile<ELFT>::RelsOrRelas> Relas = EF.crels(*RelaSec); + if (!Relas) + return createError("unable to read CREL relocations for section " + + describe(EF, Sec) + ": " + + toString(Relas.takeError())); + for (typename ELFFile<ELFT>::Elf_Rela Rela : std::get<1>(*Relas)) { + FunctionOffsetTranslations[Rela.r_offset] = Rela.r_addend; + } + } else { + Expected<typename ELFFile<ELFT>::Elf_Rela_Range> Relas = + EF.relas(*RelaSec); + if (!Relas) + return createError("unable to read relocations for section " + + describe(EF, Sec) + ": " + + toString(Relas.takeError())); + for (typename ELFFile<ELFT>::Elf_Rela Rela : *Relas) + FunctionOffsetTranslations[Rela.r_offset] = Rela.r_addend; + } } auto GetAddressForRelocation = [&](unsigned RelocationOffsetInSection) -> Expected<unsigned> { |