mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-01 15:17:25 +00:00
Object, COFF: Tighten the object file parser
We were a little lax in a few areas: - We pretended that import libraries were like any old COFF file, they are not. In fact, they aren't really COFF files at all, we should probably grow some specialized functionality to handle them smarter. - Our symbol iterators were more than happy to attempt to go past the end of the symbol table if you had a symbol with a bad list of auxiliary symbols. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222124 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -825,22 +825,22 @@ void COFFDumper::printSymbols() {
|
||||
|
||||
void COFFDumper::printDynamicSymbols() { ListScope Group(W, "DynamicSymbols"); }
|
||||
|
||||
static StringRef getSectionName(const llvm::object::COFFObjectFile *Obj,
|
||||
COFFSymbolRef Symbol,
|
||||
const coff_section *Section) {
|
||||
static ErrorOr<StringRef>
|
||||
getSectionName(const llvm::object::COFFObjectFile *Obj, int32_t SectionNumber,
|
||||
const coff_section *Section) {
|
||||
if (Section) {
|
||||
StringRef SectionName;
|
||||
Obj->getSectionName(Section, SectionName);
|
||||
if (std::error_code EC = Obj->getSectionName(Section, SectionName))
|
||||
return EC;
|
||||
return SectionName;
|
||||
}
|
||||
int32_t SectionNumber = Symbol.getSectionNumber();
|
||||
if (SectionNumber == llvm::COFF::IMAGE_SYM_DEBUG)
|
||||
return "IMAGE_SYM_DEBUG";
|
||||
return StringRef("IMAGE_SYM_DEBUG");
|
||||
if (SectionNumber == llvm::COFF::IMAGE_SYM_ABSOLUTE)
|
||||
return "IMAGE_SYM_ABSOLUTE";
|
||||
return StringRef("IMAGE_SYM_ABSOLUTE");
|
||||
if (SectionNumber == llvm::COFF::IMAGE_SYM_UNDEFINED)
|
||||
return "IMAGE_SYM_UNDEFINED";
|
||||
return "";
|
||||
return StringRef("IMAGE_SYM_UNDEFINED");
|
||||
return StringRef("");
|
||||
}
|
||||
|
||||
void COFFDumper::printSymbol(const SymbolRef &Sym) {
|
||||
@@ -858,7 +858,11 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) {
|
||||
if (Obj->getSymbolName(Symbol, SymbolName))
|
||||
SymbolName = "";
|
||||
|
||||
StringRef SectionName = getSectionName(Obj, Symbol, Section);
|
||||
StringRef SectionName = "";
|
||||
ErrorOr<StringRef> Res =
|
||||
getSectionName(Obj, Symbol.getSectionNumber(), Section);
|
||||
if (Res)
|
||||
SectionName = *Res;
|
||||
|
||||
W.printString("Name", SymbolName);
|
||||
W.printNumber("Value", Symbol.getValue());
|
||||
@@ -929,10 +933,14 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) {
|
||||
if (Section && Section->Characteristics & COFF::IMAGE_SCN_LNK_COMDAT
|
||||
&& Aux->Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) {
|
||||
const coff_section *Assoc;
|
||||
StringRef AssocName;
|
||||
std::error_code EC;
|
||||
if ((EC = Obj->getSection(AuxNumber, Assoc)) ||
|
||||
(EC = Obj->getSectionName(Assoc, AssocName))) {
|
||||
StringRef AssocName = "";
|
||||
std::error_code EC = Obj->getSection(AuxNumber, Assoc);
|
||||
ErrorOr<StringRef> Res = getSectionName(Obj, AuxNumber, Assoc);
|
||||
if (Res)
|
||||
AssocName = *Res;
|
||||
if (!EC)
|
||||
EC = Res.getError();
|
||||
if (EC) {
|
||||
AssocName = "";
|
||||
error(EC);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user