#include "llvm/ADT/Triple.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/Archive.h"
+#include "llvm/Object/MachO.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/MachO.h"
ObjectForArch getNext() const { return ObjectForArch(Parent, Index + 1); }
uint32_t getCPUType() const { return Header.cputype; }
+ std::string getArchTypeName() const {
+ return Triple::getArchTypeName(MachOObjectFile::getArch(Header.cputype));
+ }
std::error_code getAsObjectFile(std::unique_ptr<ObjectFile> &Result) const;
if (Parent) {
StringRef ParentData = Parent->getData();
StringRef ObjectData = ParentData.substr(Header.offset, Header.size);
- std::string ObjectName =
- Parent->getFileName().str() + ":" +
- Triple::getArchTypeName(MachOObjectFile::getArch(Header.cputype));
+ std::string ObjectName = Parent->getFileName().str();
MemoryBuffer *ObjBuffer = MemoryBuffer::getMemBuffer(
ObjectData, ObjectName, false);
ErrorOr<ObjectFile *> Obj = ObjectFile::createMachOObjectFile(ObjBuffer);
if (Parent) {
StringRef ParentData = Parent->getData();
StringRef ObjectData = ParentData.substr(Header.offset, Header.size);
- std::string ObjectName =
- Parent->getFileName().str() + ":" +
- Triple::getArchTypeName(MachOObjectFile::getArch(Header.cputype));
+ std::string ObjectName = Parent->getFileName().str();
MemoryBuffer *ObjBuffer = MemoryBuffer::getMemBuffer(
ObjectData, ObjectName, false);
ErrorOr<Archive *> Obj = Archive::create(ObjBuffer);
RUN: llvm-nm %p/Inputs/macho-universal-archive.x86_64.i386 \
RUN: | FileCheck %s -check-prefix CHECK-AR
-CHECK-OBJ: macho-universal.x86_64.i386:x86_64
+CHECK-OBJ: macho-universal.x86_64.i386 (for architecture x86_64):
CHECK-OBJ: 0000000100000f60 T _main
-CHECK-OBJ: macho-universal.x86_64.i386:i386
+CHECK-OBJ: macho-universal.x86_64.i386 (for architecture i386):
CHECK-OBJ: 00001fa0 T _main
-CHECK-AR: macho-universal-archive.x86_64.i386:x86_64:hello.o:
+CHECK-AR: macho-universal-archive.x86_64.i386(hello.o) (for architecture x86_64):
CHECK-AR: 0000000000000068 s EH_frame0
CHECK-AR: 000000000000003b s L_.str
CHECK-AR: 0000000000000000 T _main
CHECK-AR: 0000000000000080 S _main.eh
CHECK-AR: U _printf
-CHECK-AR: macho-universal-archive.x86_64.i386:i386:foo.o:
+CHECK-AR: macho-universal-archive.x86_64.i386(foo.o) (for architecture i386):
CHECK-AR: 00000008 S _bar
CHECK-AR: 00000000 T _foo
mxl: total 0x100003000
u: __TEXT __DATA __OBJC others dec hex
-u: 4096 0 0 4294971392 4294975488 100002000 {{.*}}/macho-universal.x86_64.i386:x86_64
-u: 4096 0 0 8192 12288 3000 {{.*}}/macho-universal.x86_64.i386:i386
+u: 4096 0 0 4294971392 4294975488 100002000 {{.*}}/macho-universal.x86_64.i386 (for architecture x86_64)
+u: 4096 0 0 8192 12288 3000 {{.*}}/macho-universal.x86_64.i386 (for architecture i386)
uAR: __TEXT __DATA __OBJC others dec hex
-uAR: 136 0 0 32 168 a8 {{.*}}/macho-universal-archive.x86_64.i386:x86_64(hello.o)
-uAR: 5 4 0 0 9 9 {{.*}}/macho-universal-archive.x86_64.i386:i386(foo.o)
+uAR: 136 0 0 32 168 a8 {{.*}}/macho-universal-archive.x86_64.i386(hello.o) (for architecture x86_64)
+uAR: 5 4 0 0 9 9 {{.*}}/macho-universal-archive.x86_64.i386(foo.o) (for architecture i386)
if (ChildOrErr.getError())
continue;
if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) {
- outs() << O->getFileName() << ":\n";
+ if (isa<MachOObjectFile>(O)) {
+ outs() << Filename << "(" << O->getFileName() << ")";
+ } else
+ outs() << O->getFileName();
+ outs() << ":\n";
dumpSymbolNamesFromObject(O);
}
}
return;
}
if (MachOUniversalBinary *UB = dyn_cast<MachOUniversalBinary>(Bin.get())) {
+ bool moreThanOneArch = UB->getNumberOfObjects() > 1;
for (MachOUniversalBinary::object_iterator I = UB->begin_objects(),
E = UB->end_objects();
I != E; ++I) {
std::unique_ptr<ObjectFile> Obj;
std::unique_ptr<Archive> A;
if (!I->getAsObjectFile(Obj)) {
- outs() << Obj->getFileName() << ":\n";
+ outs() << Obj->getFileName();
+ if (isa<MachOObjectFile>(Obj.get()) && moreThanOneArch)
+ outs() << " (for architecture " << I->getArchTypeName() << ")";
+ outs() << ":\n";
dumpSymbolNamesFromObject(Obj.get());
}
else if (!I->getAsArchive(A)) {
if (ChildOrErr.getError())
continue;
if (SymbolicFile *O = dyn_cast<SymbolicFile>(&*ChildOrErr.get())) {
- outs() << A->getFileName() << ":";
- outs() << O->getFileName() << ":\n";
+ outs() << A->getFileName();
+ if (isa<MachOObjectFile>(O)) {
+ outs() << "(" << O->getFileName() << ")";
+ if (moreThanOneArch)
+ outs() << " (for architecture " << I->getArchTypeName() << ")";
+ } else
+ outs() << ":" << O->getFileName();
+ outs() << ":\n";
dumpSymbolNamesFromObject(O);
}
}
std::unique_ptr<Archive> UA;
if (!I->getAsObjectFile(UO)) {
if (ObjectFile *o = dyn_cast<ObjectFile>(&*UO.get())) {
+ MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
if (OutputFormat == sysv)
outs() << o->getFileName() << " :\n";
+ else if(MachO && OutputFormat == darwin) {
+ if (moreThanOneFile || moreThanOneArch)
+ outs() << o->getFileName() << " (for architecture "
+ << I->getArchTypeName() << "):";
+ outs() << "\n";
+ }
PrintObjectSectionSizes(o);
if (OutputFormat == berkeley) {
- MachOObjectFile *MachO = dyn_cast<MachOObjectFile>(o);
if (!MachO || moreThanOneFile || moreThanOneArch)
- outs() << o->getFileName();
+ outs() << o->getFileName() << " (for architecture "
+ << I->getArchTypeName() << ")";
outs() << "\n";
}
}
outs() << o->getFileName() << " (ex " << UA->getFileName()
<< "):\n";
else if(MachO && OutputFormat == darwin)
- outs() << UA->getFileName() << "(" << o->getFileName() << "):\n";
+ outs() << UA->getFileName() << "(" << o->getFileName() << ")"
+ << " (for architecture " << I->getArchTypeName()
+ << "):\n";
PrintObjectSectionSizes(o);
if (OutputFormat == berkeley) {
if (MachO)
- outs() << UA->getFileName() << "(" << o->getFileName() << ")\n";
+ outs() << UA->getFileName() << "(" << o->getFileName() << ")"
+ << " (for architecture " << I->getArchTypeName()
+ << ")\n";
else
outs() << o->getFileName() << " (ex " << UA->getFileName()
<< ")\n";