mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-07-18 10:24:45 +00:00
Return ErrorOr from getSection.
This also improves the logic of what is an error: * getSection(uint_32): only return an error if the index is out of bounds. The index 0 corresponds to a perfectly valid entry. * getSection(Elf_Sym): Returns null for symbols that normally don't have sections and error for out of bound indexes. In many places this just moves the report_fatal_error up the stack, but those can then be fixed in smaller patches. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@241156 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -319,12 +319,20 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
|
||||
typedef typename ELFObjectFile<ELFT>::Elf_Shdr Elf_Shdr;
|
||||
const ELFFile<ELFT> &EF = *Obj->getELFFile();
|
||||
|
||||
const Elf_Shdr *sec = EF.getSection(Rel.d.a);
|
||||
const Elf_Shdr *SymTab = EF.getSection(sec->sh_link);
|
||||
ErrorOr<const Elf_Shdr *> SecOrErr = EF.getSection(Rel.d.a);
|
||||
if (std::error_code EC = SecOrErr.getError())
|
||||
return EC;
|
||||
const Elf_Shdr *Sec = *SecOrErr;
|
||||
ErrorOr<const Elf_Shdr *> SymTabOrErr = EF.getSection(Sec->sh_link);
|
||||
if (std::error_code EC = SymTabOrErr.getError())
|
||||
return EC;
|
||||
const Elf_Shdr *SymTab = *SymTabOrErr;
|
||||
assert(SymTab->sh_type == ELF::SHT_SYMTAB ||
|
||||
SymTab->sh_type == ELF::SHT_DYNSYM);
|
||||
const Elf_Shdr *StrTabSec = EF.getSection(SymTab->sh_link);
|
||||
ErrorOr<StringRef> StrTabOrErr = EF.getStringTable(StrTabSec);
|
||||
ErrorOr<const Elf_Shdr *> StrTabSec = EF.getSection(SymTab->sh_link);
|
||||
if (std::error_code EC = StrTabSec.getError())
|
||||
return EC;
|
||||
ErrorOr<StringRef> StrTabOrErr = EF.getStringTable(*StrTabSec);
|
||||
if (std::error_code EC = StrTabOrErr.getError())
|
||||
return EC;
|
||||
StringRef StrTab = *StrTabOrErr;
|
||||
@@ -332,7 +340,7 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
|
||||
StringRef res;
|
||||
int64_t addend = 0;
|
||||
uint16_t symbol_index = 0;
|
||||
switch (sec->sh_type) {
|
||||
switch (Sec->sh_type) {
|
||||
default:
|
||||
return object_error::parse_failed;
|
||||
case ELF::SHT_REL: {
|
||||
@@ -349,11 +357,13 @@ static std::error_code getRelocationValueString(const ELFObjectFile<ELFT> *Obj,
|
||||
}
|
||||
}
|
||||
const Elf_Sym *symb =
|
||||
EF.template getEntry<Elf_Sym>(sec->sh_link, symbol_index);
|
||||
EF.template getEntry<Elf_Sym>(Sec->sh_link, symbol_index);
|
||||
StringRef Target;
|
||||
const Elf_Shdr *SymSec = EF.getSection(symb);
|
||||
ErrorOr<const Elf_Shdr *> SymSec = EF.getSection(symb);
|
||||
if (std::error_code EC = SymSec.getError())
|
||||
return EC;
|
||||
if (symb->getType() == ELF::STT_SECTION) {
|
||||
ErrorOr<StringRef> SecName = EF.getSectionName(SymSec);
|
||||
ErrorOr<StringRef> SecName = EF.getSectionName(*SymSec);
|
||||
if (std::error_code EC = SecName.getError())
|
||||
return EC;
|
||||
Target = *SecName;
|
||||
|
Reference in New Issue
Block a user