1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-24 03:33:20 +01:00

Object, Mach-O: Refactor and clean code up

Don't assert if we can return an error code, reuse existing
functionality like is64Bit().

llvm-svn: 221915
This commit is contained in:
David Majnemer 2014-11-13 19:48:56 +00:00
parent a2f5d7b42b
commit 8e7c697444
2 changed files with 32 additions and 18 deletions

View File

@ -242,20 +242,40 @@ MachOObjectFile::MachOObjectFile(MemoryBufferRef Object, bool IsLittleEndian,
MachOObjectFile::LoadCommandInfo Load = getFirstLoadCommandInfo();
for (unsigned I = 0; ; ++I) {
if (Load.C.cmd == MachO::LC_SYMTAB) {
assert(!SymtabLoadCmd && "Multiple symbol tables");
// Multiple symbol tables
if (SymtabLoadCmd) {
EC = object_error::parse_failed;
return;
}
SymtabLoadCmd = Load.Ptr;
} else if (Load.C.cmd == MachO::LC_DYSYMTAB) {
assert(!DysymtabLoadCmd && "Multiple dynamic symbol tables");
// Multiple dynamic symbol tables
if (DysymtabLoadCmd) {
EC = object_error::parse_failed;
return;
}
DysymtabLoadCmd = Load.Ptr;
} else if (Load.C.cmd == MachO::LC_DATA_IN_CODE) {
assert(!DataInCodeLoadCmd && "Multiple data in code tables");
// Multiple data in code tables
if (DataInCodeLoadCmd) {
EC = object_error::parse_failed;
return;
}
DataInCodeLoadCmd = Load.Ptr;
} else if (Load.C.cmd == MachO::LC_DYLD_INFO ||
Load.C.cmd == MachO::LC_DYLD_INFO_ONLY) {
assert(!DyldInfoLoadCmd && "Multiple dyldinfo load commands");
// Multiple dyldinfo load commands
if (DyldInfoLoadCmd) {
EC = object_error::parse_failed;
return;
}
DyldInfoLoadCmd = Load.Ptr;
} else if (Load.C.cmd == MachO::LC_UUID) {
assert(!UuidLoadCmd && "Multiple UUID load commands");
// Multiple UUID load commands
if (UuidLoadCmd) {
EC = object_error::parse_failed;
return;
}
UuidLoadCmd = Load.Ptr;
} else if (Load.C.cmd == SegmentLoadType) {
uint32_t NumSections = getSegmentLoadCommandNumSections(this, Load);
@ -1227,17 +1247,10 @@ StringRef MachOObjectFile::getFileFormatName() const {
case llvm::MachO::CPU_TYPE_POWERPC:
return "Mach-O 32-bit ppc";
default:
assert((CPUType & llvm::MachO::CPU_ARCH_ABI64) == 0 &&
"64-bit object file when we're not 64-bit?");
return "Mach-O 32-bit unknown";
}
}
// Make sure the cpu type has the correct mask.
assert((CPUType & llvm::MachO::CPU_ARCH_ABI64)
== llvm::MachO::CPU_ARCH_ABI64 &&
"32-bit object file when we're 64-bit?");
switch (CPUType) {
case llvm::MachO::CPU_TYPE_X86_64:
return "Mach-O 64-bit x86-64";

View File

@ -2826,7 +2826,7 @@ static void PrintSection(const char *sectname, const char *segname,
outs() << "\n";
}
static void PrintSymtabLoadCommand(MachO::symtab_command st, uint32_t cputype,
static void PrintSymtabLoadCommand(MachO::symtab_command st, bool Is64Bit,
uint32_t object_size) {
outs() << " cmd LC_SYMTAB\n";
outs() << " cmdsize " << st.cmdsize;
@ -2841,7 +2841,7 @@ static void PrintSymtabLoadCommand(MachO::symtab_command st, uint32_t cputype,
outs() << "\n";
outs() << " nsyms " << st.nsyms;
uint64_t big_size;
if (cputype & MachO::CPU_ARCH_ABI64) {
if (Is64Bit) {
big_size = st.nsyms;
big_size *= sizeof(struct MachO::nlist_64);
big_size += st.symoff;
@ -2874,7 +2874,7 @@ static void PrintSymtabLoadCommand(MachO::symtab_command st, uint32_t cputype,
static void PrintDysymtabLoadCommand(MachO::dysymtab_command dyst,
uint32_t nsyms, uint32_t object_size,
uint32_t cputype) {
bool Is64Bit) {
outs() << " cmd LC_DYSYMTAB\n";
outs() << " cmdsize " << dyst.cmdsize;
if (dyst.cmdsize != sizeof(struct MachO::dysymtab_command))
@ -2938,7 +2938,7 @@ static void PrintDysymtabLoadCommand(MachO::dysymtab_command dyst,
outs() << "\n";
outs() << " nmodtab " << dyst.nmodtab;
uint64_t modtabend;
if (cputype & MachO::CPU_ARCH_ABI64) {
if (Is64Bit) {
modtabend = dyst.nmodtab;
modtabend *= sizeof(struct MachO::dylib_module_64);
modtabend += dyst.modtaboff;
@ -3310,11 +3310,12 @@ static void PrintLoadCommands(const MachOObjectFile *Obj, uint32_t ncmds,
}
} else if (Command.C.cmd == MachO::LC_SYMTAB) {
MachO::symtab_command Symtab = Obj->getSymtabLoadCommand();
PrintSymtabLoadCommand(Symtab, cputype, Buf.size());
PrintSymtabLoadCommand(Symtab, Obj->is64Bit(), Buf.size());
} else if (Command.C.cmd == MachO::LC_DYSYMTAB) {
MachO::dysymtab_command Dysymtab = Obj->getDysymtabLoadCommand();
MachO::symtab_command Symtab = Obj->getSymtabLoadCommand();
PrintDysymtabLoadCommand(Dysymtab, Symtab.nsyms, Buf.size(), cputype);
PrintDysymtabLoadCommand(Dysymtab, Symtab.nsyms, Buf.size(),
Obj->is64Bit());
} else if (Command.C.cmd == MachO::LC_DYLD_INFO ||
Command.C.cmd == MachO::LC_DYLD_INFO_ONLY) {
MachO::dyld_info_command DyldInfo = Obj->getDyldInfoLoadCommand(Command);