X-Git-Url: https://git.saurik.com/apple/ld64.git/blobdiff_plain/183622f619ad30b834c5e6a73fa00244d5b035c0..2f2f92e40575142405a1caa9bcf847f7ad011c92:/src/ObjectDump.cpp?ds=sidebyside diff --git a/src/ObjectDump.cpp b/src/ObjectDump.cpp old mode 100644 new mode 100755 index ce9801a..b104dda --- a/src/ObjectDump.cpp +++ b/src/ObjectDump.cpp @@ -27,15 +27,14 @@ #include #include #include -#include -#include -#include #include "MachOReaderRelocatable.hpp" +#include "LTOReader.hpp" static bool sDumpContent= true; static bool sDumpStabs = false; static bool sSort = true; +static bool sNMmode = false; static cpu_type_t sPreferredArch = CPU_TYPE_POWERPC64; static const char* sMatchName; static int sPrintRestrict; @@ -56,6 +55,16 @@ void throwf(const char* format, ...) throw t; } +void warning(const char* format, ...) +{ + va_list list; + fprintf(stderr, "warning: "); + va_start(list, format); + vfprintf(stderr, format, list); + va_end(list); + fprintf(stderr, "\n"); +} + static void dumpStabs(std::vector* stabs) { // debug info @@ -154,6 +163,49 @@ static void dumpStabs(std::vector* stabs) } +static void dumpAtomLikeNM(ObjectFile::Atom* atom) +{ + uint32_t size = atom->getSize(); + + const char* visibility; + switch ( atom->getScope() ) { + case ObjectFile::Atom::scopeTranslationUnit: + visibility = "internal"; + break; + case ObjectFile::Atom::scopeLinkageUnit: + visibility = "hidden "; + break; + case ObjectFile::Atom::scopeGlobal: + visibility = "global "; + break; + default: + visibility = " "; + break; + } + + const char* kind; + switch ( atom->getDefinitionKind() ) { + case ObjectFile::Atom::kRegularDefinition: + kind = "regular "; + break; + case ObjectFile::Atom::kTentativeDefinition: + kind = "tentative"; + break; + case ObjectFile::Atom::kWeakDefinition: + kind = "weak "; + break; + case ObjectFile::Atom::kAbsoluteSymbol: + kind = "absolute "; + break; + default: + kind = " "; + break; + } + + printf("0x%08X %s %s %s\n", size, visibility, kind, atom->getDisplayName()); +} + + static void dumpAtom(ObjectFile::Atom* atom) { if(sMatchName && strcmp(sMatchName, atom->getDisplayName())) @@ -207,7 +259,7 @@ static void dumpAtom(ObjectFile::Atom* atom) } // segment and section - if(!sPrintRestrict) + if(!sPrintRestrict && (atom->getSectionName() != NULL) ) printf("section: %s,%s\n", atom->getSegment().getName(), atom->getSectionName()); // attributes @@ -217,6 +269,8 @@ static void dumpAtom(ObjectFile::Atom* atom) printf("dont-dead-strip "); if ( atom->isZeroFill() ) printf("zero-fill "); + if ( atom->isThumb() ) + printf("thumb "); printf("\n"); } @@ -307,8 +361,12 @@ static void dumpFile(ObjectFile::Reader* reader) if ( sSort ) std::sort(sortedAtoms.begin(), sortedAtoms.end(), AtomSorter()); - for(std::vector::iterator it=sortedAtoms.begin(); it != sortedAtoms.end(); ++it) - dumpAtom(*it); + for(std::vector::iterator it=sortedAtoms.begin(); it != sortedAtoms.end(); ++it) { + if ( sNMmode ) + dumpAtomLikeNM(*it); + else + dumpAtom(*it); + } } @@ -341,6 +399,12 @@ static ObjectFile::Reader* createReader(const char* path, const ObjectFile::Read return new mach_o::relocatable::Reader::Reader(p, path, 0, options, 0); else if ( mach_o::relocatable::Reader::validFile(p) ) return new mach_o::relocatable::Reader::Reader(p, path, 0, options, 0); + else if ( mach_o::relocatable::Reader::validFile(p) ) + return new mach_o::relocatable::Reader::Reader(p, path, 0, options, 0); + if ( lto::Reader::validFile(p, stat_buf.st_size, 0) ) { + return new lto::Reader(p, stat_buf.st_size, path, 0, options, 0); + } + throwf("not a mach-o object file: %s", path); } @@ -373,6 +437,9 @@ int main(int argc, const char* argv[]) if ( strcmp(arg, "-no_content") == 0 ) { sDumpContent = false; } + else if ( strcmp(arg, "-nm") == 0 ) { + sNMmode = true; + } else if ( strcmp(arg, "-stabs") == 0 ) { sDumpStabs = true; }