diff options
author | Fangrui Song <i@maskray.me> | 2024-07-08 09:14:34 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-08 09:14:34 -0700 |
commit | 2f37a22f10a1128c695bc469871a9101edce853e (patch) | |
tree | 7c135f7f5d61bd4f632dbaa1d3f4938543032725 /llvm/tools/llvm-objdump | |
parent | 12e47aabd4e4c6cec15092183b91ec279a0a7ab4 (diff) | |
download | llvm-2f37a22f10a1128c695bc469871a9101edce853e.zip llvm-2f37a22f10a1128c695bc469871a9101edce853e.tar.gz llvm-2f37a22f10a1128c695bc469871a9101edce853e.tar.bz2 |
[llvm-objdump] -r: support CREL
Extract the llvm-readelf decoder to `decodeCrel` (#91280) and reuse it
for llvm-objdump.
Because the section representation of LLVMObject (`SectionRef`) is
64-bit, insufficient to hold all decoder states, `section_rel_begin` is
modified to decode CREL eagerly and hold the decoded relocations inside
ELFObjectFile<ELFT>.
The test is adapted from llvm/test/tools/llvm-readobj/ELF/crel.test.
Pull Request: https://github.com/llvm/llvm-project/pull/97382
Diffstat (limited to 'llvm/tools/llvm-objdump')
-rw-r--r-- | llvm/tools/llvm-objdump/ELFDump.cpp | 6 | ||||
-rw-r--r-- | llvm/tools/llvm-objdump/llvm-objdump.cpp | 10 |
2 files changed, 15 insertions, 1 deletions
diff --git a/llvm/tools/llvm-objdump/ELFDump.cpp b/llvm/tools/llvm-objdump/ELFDump.cpp index 8c184fc..5ac1349 100644 --- a/llvm/tools/llvm-objdump/ELFDump.cpp +++ b/llvm/tools/llvm-objdump/ELFDump.cpp @@ -104,7 +104,11 @@ static Error getRelocationValueString(const ELFObjectFile<ELFT> *Obj, // In SHT_REL case we would need to read the addend from section data. // GNU objdump does not do that and we just follow for simplicity atm. bool Undef = false; - if ((*SecOrErr)->sh_type == ELF::SHT_RELA) { + if ((*SecOrErr)->sh_type == ELF::SHT_CREL) { + auto ERela = Obj->getCrel(Rel); + Addend = ERela.r_addend; + Undef = ERela.getSymbol(false) == 0; + } else if ((*SecOrErr)->sh_type == ELF::SHT_RELA) { const typename ELFT::Rela *ERela = Obj->getRela(Rel); Addend = ERela->r_addend; Undef = ERela->getSymbol(false) == 0; diff --git a/llvm/tools/llvm-objdump/llvm-objdump.cpp b/llvm/tools/llvm-objdump/llvm-objdump.cpp index 6249be4..d124002 100644 --- a/llvm/tools/llvm-objdump/llvm-objdump.cpp +++ b/llvm/tools/llvm-objdump/llvm-objdump.cpp @@ -2687,6 +2687,16 @@ void Dumper::printRelocations() { << "VALUE\n"; for (SectionRef Section : P.second) { + // CREL sections require decoding, each section may have its own specific + // decode problems. + if (O.isELF() && ELFSectionRef(Section).getType() == ELF::SHT_CREL) { + StringRef Err = + cast<const ELFObjectFileBase>(O).getCrelDecodeProblem(Section); + if (!Err.empty()) { + reportUniqueWarning(Err); + continue; + } + } for (const RelocationRef &Reloc : Section.relocations()) { uint64_t Address = Reloc.getOffset(); SmallString<32> RelocName; |