Move error handling down to getSymbolNMTypeChar.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200727 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2014-02-04 00:21:18 +00:00
parent e4d1a3e352
commit 819536857f

View File

@ -307,8 +307,7 @@ static void dumpSymbolNamesFromModule(Module *M) {
} }
template <class ELFT> template <class ELFT>
static error_code getSymbolNMTypeChar(ELFObjectFile<ELFT> &Obj, static char getSymbolNMTypeChar(ELFObjectFile<ELFT> &Obj, symbol_iterator I) {
symbol_iterator I, char &Result) {
typedef typename ELFObjectFile<ELFT>::Elf_Sym Elf_Sym; typedef typename ELFObjectFile<ELFT>::Elf_Sym Elf_Sym;
typedef typename ELFObjectFile<ELFT>::Elf_Shdr Elf_Shdr; typedef typename ELFObjectFile<ELFT>::Elf_Shdr Elf_Shdr;
@ -371,41 +370,35 @@ static error_code getSymbolNMTypeChar(ELFObjectFile<ELFT> &Obj,
if (Ret == '?' && ESym->getType() == ELF::STT_SECTION) { if (Ret == '?' && ESym->getType() == ELF::STT_SECTION) {
StringRef Name; StringRef Name;
error_code EC = I->getName(Name); if (error(I->getName(Name)))
if (EC) return '?';
return EC; return StringSwitch<char>(Name)
Result = StringSwitch<char>(Name) .StartsWith(".debug", 'N')
.StartsWith(".debug", 'N') .StartsWith(".note", 'n')
.StartsWith(".note", 'n') .Default('?');
.Default('?');
return object_error::success;
} }
Result = Ret; return Ret;
return object_error::success;
} }
static error_code getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I, static char getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I) {
char &Result) {
const coff_symbol *Symb = Obj.getCOFFSymbol(I); const coff_symbol *Symb = Obj.getCOFFSymbol(I);
StringRef Name; StringRef Name;
if (error_code EC = I->getName(Name)) if (error(I->getName(Name)))
return EC; return '?';
char Ret = StringSwitch<char>(Name) char Ret = StringSwitch<char>(Name)
.StartsWith(".debug", 'N') .StartsWith(".debug", 'N')
.StartsWith(".sxdata", 'N') .StartsWith(".sxdata", 'N')
.Default('?'); .Default('?');
if (Ret != '?') { if (Ret != '?')
Result = Ret; return Ret;
return object_error::success;
}
uint32_t Characteristics = 0; uint32_t Characteristics = 0;
if (Symb->SectionNumber > 0) { if (Symb->SectionNumber > 0) {
section_iterator SecI = Obj.end_sections(); section_iterator SecI = Obj.end_sections();
if (error_code EC = I->getSection(SecI)) if (error(I->getSection(SecI)))
return EC; return '?';
const coff_section *Section = Obj.getCOFFSection(SecI); const coff_section *Section = Obj.getCOFFSection(SecI);
Characteristics = Section->Characteristics; Characteristics = Section->Characteristics;
} }
@ -414,8 +407,7 @@ static error_code getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I,
case COFF::IMAGE_SYM_UNDEFINED: case COFF::IMAGE_SYM_UNDEFINED:
// Check storage classes. // Check storage classes.
if (Symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL) { if (Symb->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL) {
Result = 'w'; return 'w'; // Don't do ::toupper.
return object_error::success; // Don't do ::toupper.
} else if (Symb->Value != 0) // Check for common symbols. } else if (Symb->Value != 0) // Check for common symbols.
Ret = 'c'; Ret = 'c';
else else
@ -450,8 +442,7 @@ static error_code getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I,
if (Symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL) if (Symb->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL)
Ret = ::toupper(static_cast<unsigned char>(Ret)); Ret = ::toupper(static_cast<unsigned char>(Ret));
Result = Ret; return Ret;
return object_error::success;
} }
static uint8_t getNType(MachOObjectFile &Obj, DataRefImpl Symb) { static uint8_t getNType(MachOObjectFile &Obj, DataRefImpl Symb) {
@ -463,8 +454,7 @@ static uint8_t getNType(MachOObjectFile &Obj, DataRefImpl Symb) {
return STE.n_type; return STE.n_type;
} }
static error_code getSymbolNMTypeChar(MachOObjectFile &Obj, symbol_iterator I, static char getSymbolNMTypeChar(MachOObjectFile &Obj, symbol_iterator I) {
char &Res) {
DataRefImpl Symb = I->getRawDataRefImpl(); DataRefImpl Symb = I->getRawDataRefImpl();
uint8_t NType = getNType(Obj, Symb); uint8_t NType = getNType(Obj, Symb);
@ -495,36 +485,22 @@ static error_code getSymbolNMTypeChar(MachOObjectFile &Obj, symbol_iterator I,
if (NType & (MachO::N_EXT | MachO::N_PEXT)) if (NType & (MachO::N_EXT | MachO::N_PEXT))
Char = toupper(static_cast<unsigned char>(Char)); Char = toupper(static_cast<unsigned char>(Char));
Res = Char; return Char;
return object_error::success;
} }
static char getNMTypeChar(ObjectFile *Obj, symbol_iterator I) { static char getNMTypeChar(ObjectFile *Obj, symbol_iterator I) {
char Res = '?'; if (COFFObjectFile *COFF = dyn_cast<COFFObjectFile>(Obj))
if (COFFObjectFile *COFF = dyn_cast<COFFObjectFile>(Obj)) { return getSymbolNMTypeChar(*COFF, I);
error(getSymbolNMTypeChar(*COFF, I, Res)); if (MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(Obj))
return Res; return getSymbolNMTypeChar(*MachO, I);
} if (ELF32LEObjectFile *ELF = dyn_cast<ELF32LEObjectFile>(Obj))
if (MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(Obj)) { return getSymbolNMTypeChar(*ELF, I);
error(getSymbolNMTypeChar(*MachO, I, Res)); if (ELF64LEObjectFile *ELF = dyn_cast<ELF64LEObjectFile>(Obj))
return Res; return getSymbolNMTypeChar(*ELF, I);
} if (ELF32BEObjectFile *ELF = dyn_cast<ELF32BEObjectFile>(Obj))
return getSymbolNMTypeChar(*ELF, I);
if (ELF32LEObjectFile *ELF = dyn_cast<ELF32LEObjectFile>(Obj)) {
error(getSymbolNMTypeChar(*ELF, I, Res));
return Res;
}
if (ELF64LEObjectFile *ELF = dyn_cast<ELF64LEObjectFile>(Obj)) {
error(getSymbolNMTypeChar(*ELF, I, Res));
return Res;
}
if (ELF32BEObjectFile *ELF = dyn_cast<ELF32BEObjectFile>(Obj)) {
error(getSymbolNMTypeChar(*ELF, I, Res));
return Res;
}
ELF64BEObjectFile *ELF = cast<ELF64BEObjectFile>(Obj); ELF64BEObjectFile *ELF = cast<ELF64BEObjectFile>(Obj);
error(getSymbolNMTypeChar(*ELF, I, Res)); return getSymbolNMTypeChar(*ELF, I);
return Res;
} }
static void getDynamicSymbolIterators(ObjectFile *Obj, symbol_iterator &Begin, static void getDynamicSymbolIterators(ObjectFile *Obj, symbol_iterator &Begin,