#include <sys/mman.h>
#include <fcntl.h>
#include <fcntl.h>
-#include <mach-o/loader.h>
-#include <mach-o/fat.h>
-#include <mach-o/stab.h>
#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;
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<ObjectFile::Reader::Stab>* stabs)
{
// debug info
}
+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()))
}
// segment and section
- if(!sPrintRestrict)
+ if(!sPrintRestrict && (atom->getSectionName() != NULL) )
printf("section: %s,%s\n", atom->getSegment().getName(), atom->getSectionName());
// attributes
printf("dont-dead-strip ");
if ( atom->isZeroFill() )
printf("zero-fill ");
+ if ( atom->isThumb() )
+ printf("thumb ");
printf("\n");
}
if ( sSort )
std::sort(sortedAtoms.begin(), sortedAtoms.end(), AtomSorter());
- for(std::vector<ObjectFile::Atom*>::iterator it=sortedAtoms.begin(); it != sortedAtoms.end(); ++it)
- dumpAtom(*it);
+ for(std::vector<ObjectFile::Atom*>::iterator it=sortedAtoms.begin(); it != sortedAtoms.end(); ++it) {
+ if ( sNMmode )
+ dumpAtomLikeNM(*it);
+ else
+ dumpAtom(*it);
+ }
}
return new mach_o::relocatable::Reader<ppc64>::Reader(p, path, 0, options, 0);
else if ( mach_o::relocatable::Reader<x86_64>::validFile(p) )
return new mach_o::relocatable::Reader<x86_64>::Reader(p, path, 0, options, 0);
+ else if ( mach_o::relocatable::Reader<arm>::validFile(p) )
+ return new mach_o::relocatable::Reader<arm>::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);
}
if ( strcmp(arg, "-no_content") == 0 ) {
sDumpContent = false;
}
+ else if ( strcmp(arg, "-nm") == 0 ) {
+ sNMmode = true;
+ }
else if ( strcmp(arg, "-stabs") == 0 ) {
sDumpStabs = true;
}