[llvm] [llvm-readobj][COFF] Implement --coff-pseudoreloc in llvm-readobj to dump runtime pseudo-relocation records (PR #151816)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 11 01:15:03 PDT 2025
================
@@ -2015,80 +2016,102 @@ void COFFDumper::printCOFFPseudoReloc() {
? "___RUNTIME_PSEUDO_RELOC_LIST_END__"
: "__RUNTIME_PSEUDO_RELOC_LIST_END__";
- auto Count = Obj->getNumberOfSymbols();
- if (Count == 0) {
- W.startLine() << "the symbol table has been stripped\n";
+ uint32_t Count = Obj->getNumberOfSymbols();
+ // Skip if no symbol was found (maybe stripped).
+ if (Count == 0)
return;
- }
struct SymbolEntry {
+ uint32_t RVA;
COFFSymbolRef Symbol;
const coff_section *Section;
StringRef SymbolName;
};
- std::map<uint32_t, SymbolEntry> RVASymbolMap;
+ SmallVector<SymbolEntry> RVASymbolMap;
COFFSymbolRef RelocBegin, RelocEnd;
- for (auto i = 0u; i < Count; ++i) {
- auto Sym = Obj->getSymbol(i);
- if (!Sym) {
- consumeError(Sym.takeError());
+ for (uint32_t i = 0; i < Count; ++i) {
+ COFFSymbolRef Sym;
+ if (Expected<COFFSymbolRef> SymOrErr = Obj->getSymbol(i))
+ Sym = *SymOrErr;
+ else {
+ reportWarning(SymOrErr.takeError(), Obj->getFileName());
continue;
}
- i += Sym->getNumberOfAuxSymbols();
- if (Sym->getSectionNumber() <= 0)
+ i += Sym.getNumberOfAuxSymbols();
+
+ if (Sym.getSectionNumber() <= 0)
continue;
- auto Name = Obj->getSymbolName(*Sym);
- if (!Name) {
- consumeError(Name.takeError());
+
+ StringRef Name;
+ if (Expected<StringRef> NameOrErr = Obj->getSymbolName(Sym))
+ Name = *NameOrErr;
+ else {
+ reportWarning(NameOrErr.takeError(), Obj->getFileName());
continue;
}
- if (*Name == RelocBeginName)
- RelocBegin = *Sym;
- else if (*Name == RelocEndName)
- RelocEnd = *Sym;
-
- auto Sec = Obj->getSection(Sym->getSectionNumber());
- if (!Sec) {
- consumeError(Sec.takeError());
+ if (Name == RelocBeginName)
+ RelocBegin = Sym;
+ else if (Name == RelocEndName)
+ RelocEnd = Sym;
+
+ const coff_section *Sec = nullptr;
+ if (Expected<const coff_section *> SecOrErr =
+ Obj->getSection(Sym.getSectionNumber()))
+ Sec = *SecOrErr;
+ else {
----------------
jh7370 wrote:
Same as above re. braces.
https://github.com/llvm/llvm-project/pull/151816
More information about the llvm-commits
mailing list