llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import struct
|
|
|
|
import sys
|
2009-08-22 09:22:36 +02:00
|
|
|
import StringIO
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
|
2010-09-11 17:25:58 +02:00
|
|
|
import common_dump
|
|
|
|
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
class Reader:
|
|
|
|
def __init__(self, path):
|
|
|
|
if path == '-':
|
2009-08-22 09:22:36 +02:00
|
|
|
# Snarf all the data so we can seek.
|
|
|
|
self.file = StringIO.StringIO(sys.stdin.read())
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
else:
|
|
|
|
self.file = open(path,'rb')
|
|
|
|
self.isLSB = None
|
2010-03-13 23:10:11 +01:00
|
|
|
self.is64Bit = None
|
2009-08-22 09:22:36 +02:00
|
|
|
|
|
|
|
self.string_table = None
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
|
|
|
|
def tell(self):
|
2009-08-22 09:22:36 +02:00
|
|
|
return self.file.tell()
|
|
|
|
|
|
|
|
def seek(self, pos):
|
|
|
|
self.file.seek(pos)
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
|
|
|
|
def read(self, N):
|
|
|
|
data = self.file.read(N)
|
|
|
|
if len(data) != N:
|
|
|
|
raise ValueError,"Out of data!"
|
|
|
|
return data
|
|
|
|
|
2009-08-22 09:22:36 +02:00
|
|
|
def read8(self):
|
|
|
|
return ord(self.read(1))
|
|
|
|
|
|
|
|
def read16(self):
|
|
|
|
return struct.unpack('><'[self.isLSB] + 'H', self.read(2))[0]
|
|
|
|
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
def read32(self):
|
2009-08-22 11:28:33 +02:00
|
|
|
# Force to 32-bit, if possible; otherwise these might be long ints on a
|
|
|
|
# big-endian platform. FIXME: Why???
|
|
|
|
Value = struct.unpack('><'[self.isLSB] + 'I', self.read(4))[0]
|
|
|
|
return int(Value)
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
|
2010-03-13 23:10:11 +01:00
|
|
|
def read64(self):
|
2010-10-29 03:14:16 +02:00
|
|
|
Value = struct.unpack('><'[self.isLSB] + 'Q', self.read(8))[0]
|
|
|
|
if Value == int(Value):
|
|
|
|
Value = int(Value)
|
|
|
|
return Value
|
2010-03-13 23:10:11 +01:00
|
|
|
|
2009-08-22 09:22:36 +02:00
|
|
|
def registerStringTable(self, strings):
|
|
|
|
if self.string_table is not None:
|
|
|
|
raise ValueError,"%s: warning: multiple string tables" % sys.argv[0]
|
|
|
|
|
|
|
|
self.string_table = strings
|
|
|
|
|
|
|
|
def getString(self, index):
|
|
|
|
if self.string_table is None:
|
|
|
|
raise ValueError,"%s: warning: no string table registered" % sys.argv[0]
|
|
|
|
|
|
|
|
end = self.string_table.index('\x00', index)
|
|
|
|
return self.string_table[index:end]
|
|
|
|
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
def dumpmacho(path, opts):
|
|
|
|
f = Reader(path)
|
|
|
|
|
|
|
|
magic = f.read(4)
|
|
|
|
if magic == '\xFE\xED\xFA\xCE':
|
2010-03-13 23:10:11 +01:00
|
|
|
f.isLSB, f.is64Bit = False, False
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
elif magic == '\xCE\xFA\xED\xFE':
|
2010-03-13 23:10:11 +01:00
|
|
|
f.isLSB, f.is64Bit = True, False
|
|
|
|
elif magic == '\xFE\xED\xFA\xCF':
|
|
|
|
f.isLSB, f.is64Bit = False, True
|
|
|
|
elif magic == '\xCF\xFA\xED\xFE':
|
|
|
|
f.isLSB, f.is64Bit = True, True
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
else:
|
|
|
|
raise ValueError,"Not a Mach-O object file: %r (bad magic)" % path
|
|
|
|
|
|
|
|
print "('cputype', %r)" % f.read32()
|
|
|
|
print "('cpusubtype', %r)" % f.read32()
|
|
|
|
filetype = f.read32()
|
|
|
|
print "('filetype', %r)" % filetype
|
|
|
|
|
|
|
|
numLoadCommands = f.read32()
|
|
|
|
print "('num_load_commands', %r)" % filetype
|
|
|
|
|
|
|
|
loadCommandsSize = f.read32()
|
|
|
|
print "('load_commands_size', %r)" % loadCommandsSize
|
|
|
|
|
|
|
|
print "('flag', %r)" % f.read32()
|
|
|
|
|
2010-03-13 23:10:11 +01:00
|
|
|
if f.is64Bit:
|
|
|
|
print "('reserved', %r)" % f.read32()
|
|
|
|
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
start = f.tell()
|
|
|
|
|
|
|
|
print "('load_commands', ["
|
|
|
|
for i in range(numLoadCommands):
|
|
|
|
dumpLoadCommand(f, i, opts)
|
|
|
|
print "])"
|
|
|
|
|
|
|
|
if f.tell() - start != loadCommandsSize:
|
2010-03-13 23:10:11 +01:00
|
|
|
raise ValueError,"%s: warning: invalid load commands size: %r" % (
|
|
|
|
sys.argv[0], loadCommandsSize)
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
|
|
|
|
def dumpLoadCommand(f, i, opts):
|
|
|
|
start = f.tell()
|
|
|
|
|
|
|
|
print " # Load Command %r" % i
|
|
|
|
cmd = f.read32()
|
|
|
|
print " (('command', %r)" % cmd
|
|
|
|
cmdSize = f.read32()
|
|
|
|
print " ('size', %r)" % cmdSize
|
|
|
|
|
|
|
|
if cmd == 1:
|
2010-03-13 23:10:11 +01:00
|
|
|
dumpSegmentLoadCommand(f, opts, False)
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
elif cmd == 2:
|
|
|
|
dumpSymtabCommand(f, opts)
|
|
|
|
elif cmd == 11:
|
|
|
|
dumpDysymtabCommand(f, opts)
|
2010-03-13 23:10:11 +01:00
|
|
|
elif cmd == 25:
|
|
|
|
dumpSegmentLoadCommand(f, opts, True)
|
2009-10-24 22:32:36 +02:00
|
|
|
elif cmd == 27:
|
|
|
|
import uuid
|
|
|
|
print " ('uuid', %s)" % uuid.UUID(bytes=f.read(16))
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
else:
|
2010-03-13 23:10:11 +01:00
|
|
|
print >>sys.stderr,"%s: warning: unknown load command: %r" % (
|
|
|
|
sys.argv[0], cmd)
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
f.read(cmdSize - 8)
|
|
|
|
print " ),"
|
|
|
|
|
|
|
|
if f.tell() - start != cmdSize:
|
2010-03-13 23:10:11 +01:00
|
|
|
raise ValueError,"%s: warning: invalid load command size: %r" % (
|
|
|
|
sys.argv[0], cmdSize)
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
|
2010-03-13 23:10:11 +01:00
|
|
|
def dumpSegmentLoadCommand(f, opts, is64Bit):
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
print " ('segment_name', %r)" % f.read(16)
|
2010-03-13 23:10:11 +01:00
|
|
|
if is64Bit:
|
|
|
|
print " ('vm_addr', %r)" % f.read64()
|
|
|
|
print " ('vm_size', %r)" % f.read64()
|
|
|
|
print " ('file_offset', %r)" % f.read64()
|
|
|
|
print " ('file_size', %r)" % f.read64()
|
|
|
|
else:
|
|
|
|
print " ('vm_addr', %r)" % f.read32()
|
|
|
|
print " ('vm_size', %r)" % f.read32()
|
|
|
|
print " ('file_offset', %r)" % f.read32()
|
|
|
|
print " ('file_size', %r)" % f.read32()
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
print " ('maxprot', %r)" % f.read32()
|
|
|
|
print " ('initprot', %r)" % f.read32()
|
|
|
|
numSections = f.read32()
|
|
|
|
print " ('num_sections', %r)" % numSections
|
|
|
|
print " ('flags', %r)" % f.read32()
|
|
|
|
|
|
|
|
print " ('sections', ["
|
|
|
|
for i in range(numSections):
|
2010-03-13 23:10:11 +01:00
|
|
|
dumpSection(f, i, opts, is64Bit)
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
print " ])"
|
|
|
|
|
|
|
|
def dumpSymtabCommand(f, opts):
|
2009-08-22 09:22:36 +02:00
|
|
|
symoff = f.read32()
|
|
|
|
print " ('symoff', %r)" % symoff
|
|
|
|
nsyms = f.read32()
|
|
|
|
print " ('nsyms', %r)" % nsyms
|
|
|
|
stroff = f.read32()
|
|
|
|
print " ('stroff', %r)" % stroff
|
|
|
|
strsize = f.read32()
|
|
|
|
print " ('strsize', %r)" % strsize
|
|
|
|
|
|
|
|
prev_pos = f.tell()
|
|
|
|
|
|
|
|
f.seek(stroff)
|
|
|
|
string_data = f.read(strsize)
|
|
|
|
print " ('_string_data', %r)" % string_data
|
|
|
|
|
|
|
|
f.registerStringTable(string_data)
|
|
|
|
|
|
|
|
f.seek(symoff)
|
|
|
|
print " ('_symbols', ["
|
|
|
|
for i in range(nsyms):
|
|
|
|
dumpNlist32(f, i, opts)
|
|
|
|
print " ])"
|
|
|
|
|
|
|
|
f.seek(prev_pos)
|
|
|
|
|
|
|
|
def dumpNlist32(f, i, opts):
|
|
|
|
print " # Symbol %r" % i
|
|
|
|
n_strx = f.read32()
|
|
|
|
print " (('n_strx', %r)" % n_strx
|
|
|
|
n_type = f.read8()
|
|
|
|
print " ('n_type', %#x)" % n_type
|
|
|
|
n_sect = f.read8()
|
2009-08-22 12:09:17 +02:00
|
|
|
print " ('n_sect', %r)" % n_sect
|
2009-08-22 09:22:36 +02:00
|
|
|
n_desc = f.read16()
|
|
|
|
print " ('n_desc', %r)" % n_desc
|
2010-03-13 23:49:35 +01:00
|
|
|
if f.is64Bit:
|
|
|
|
n_value = f.read64()
|
|
|
|
print " ('n_value', %r)" % n_value
|
|
|
|
else:
|
|
|
|
n_value = f.read32()
|
|
|
|
print " ('n_value', %r)" % n_value
|
2009-08-22 09:22:36 +02:00
|
|
|
print " ('_string', %r)" % f.getString(n_strx)
|
|
|
|
print " ),"
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
|
|
|
|
def dumpDysymtabCommand(f, opts):
|
|
|
|
print " ('ilocalsym', %r)" % f.read32()
|
|
|
|
print " ('nlocalsym', %r)" % f.read32()
|
|
|
|
print " ('iextdefsym', %r)" % f.read32()
|
|
|
|
print " ('nextdefsym', %r)" % f.read32()
|
|
|
|
print " ('iundefsym', %r)" % f.read32()
|
|
|
|
print " ('nundefsym', %r)" % f.read32()
|
|
|
|
print " ('tocoff', %r)" % f.read32()
|
|
|
|
print " ('ntoc', %r)" % f.read32()
|
|
|
|
print " ('modtaboff', %r)" % f.read32()
|
|
|
|
print " ('nmodtab', %r)" % f.read32()
|
|
|
|
print " ('extrefsymoff', %r)" % f.read32()
|
|
|
|
print " ('nextrefsyms', %r)" % f.read32()
|
2009-08-22 09:22:36 +02:00
|
|
|
indirectsymoff = f.read32()
|
|
|
|
print " ('indirectsymoff', %r)" % indirectsymoff
|
|
|
|
nindirectsyms = f.read32()
|
|
|
|
print " ('nindirectsyms', %r)" % nindirectsyms
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
print " ('extreloff', %r)" % f.read32()
|
|
|
|
print " ('nextrel', %r)" % f.read32()
|
|
|
|
print " ('locreloff', %r)" % f.read32()
|
|
|
|
print " ('nlocrel', %r)" % f.read32()
|
|
|
|
|
2009-08-22 09:22:36 +02:00
|
|
|
prev_pos = f.tell()
|
|
|
|
|
|
|
|
f.seek(indirectsymoff)
|
|
|
|
print " ('_indirect_symbols', ["
|
|
|
|
for i in range(nindirectsyms):
|
|
|
|
print " # Indirect Symbol %r" % i
|
2009-08-26 06:28:45 +02:00
|
|
|
print " (('symbol_index', %#x),)," % f.read32()
|
2009-08-22 09:22:36 +02:00
|
|
|
print " ])"
|
|
|
|
|
|
|
|
f.seek(prev_pos)
|
|
|
|
|
2010-03-13 23:10:11 +01:00
|
|
|
def dumpSection(f, i, opts, is64Bit):
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
print " # Section %r" % i
|
|
|
|
print " (('section_name', %r)" % f.read(16)
|
|
|
|
print " ('segment_name', %r)" % f.read(16)
|
2010-03-13 23:10:11 +01:00
|
|
|
if is64Bit:
|
|
|
|
print " ('address', %r)" % f.read64()
|
|
|
|
size = f.read64()
|
|
|
|
print " ('size', %r)" % size
|
|
|
|
else:
|
|
|
|
print " ('address', %r)" % f.read32()
|
|
|
|
size = f.read32()
|
|
|
|
print " ('size', %r)" % size
|
2009-08-26 15:57:44 +02:00
|
|
|
offset = f.read32()
|
|
|
|
print " ('offset', %r)" % offset
|
|
|
|
print " ('alignment', %r)" % f.read32()
|
|
|
|
reloc_offset = f.read32()
|
|
|
|
print " ('reloc_offset', %r)" % reloc_offset
|
|
|
|
num_reloc = f.read32()
|
|
|
|
print " ('num_reloc', %r)" % num_reloc
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
print " ('flags', %#x)" % f.read32()
|
|
|
|
print " ('reserved1', %r)" % f.read32()
|
|
|
|
print " ('reserved2', %r)" % f.read32()
|
2010-03-13 23:10:11 +01:00
|
|
|
if is64Bit:
|
|
|
|
print " ('reserved3', %r)" % f.read32()
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
print " ),"
|
2009-08-26 15:57:44 +02:00
|
|
|
|
|
|
|
prev_pos = f.tell()
|
|
|
|
|
|
|
|
f.seek(reloc_offset)
|
|
|
|
print " ('_relocations', ["
|
|
|
|
for i in range(num_reloc):
|
|
|
|
print " # Relocation %r" % i
|
|
|
|
print " (('word-0', %#x)," % f.read32()
|
|
|
|
print " ('word-1', %#x))," % f.read32()
|
|
|
|
print " ])"
|
|
|
|
|
|
|
|
if opts.dumpSectionData:
|
|
|
|
f.seek(offset)
|
2010-09-11 17:25:58 +02:00
|
|
|
print " ('_section_data', '%s')" % common_dump.dataToHex(f.read(size))
|
2009-08-26 15:57:44 +02:00
|
|
|
|
|
|
|
f.seek(prev_pos)
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
|
|
|
|
def main():
|
|
|
|
from optparse import OptionParser, OptionGroup
|
|
|
|
parser = OptionParser("usage: %prog [options] {files}")
|
2009-08-26 15:57:44 +02:00
|
|
|
parser.add_option("", "--dump-section-data", dest="dumpSectionData",
|
|
|
|
help="Dump the contents of sections",
|
|
|
|
action="store_true", default=False)
|
llvm-mc: Start MCAssembler and MCMachOStreamer.
- Together these form the (Mach-O) back end of the assembler.
- MCAssembler is the actual assembler backend, which is designed to have a
reasonable API. This will eventually grow to support multiple object file
implementations, but for now its Mach-O/i386 only.
- MCMachOStreamer adapts the MCStreamer "actions" API to the MCAssembler API,
e.g. converting the various directives into fragments, managing state like
the current section, and so on.
- llvm-mc will use the new backend via '-filetype=obj', which may eventually
be, but is not yet, since I hear that people like assemblers which actually
assemble.
- The only thing that works at the moment is changing sections. For the time
being I have a Python Mach-O dumping tool in test/scripts so this stuff can
be easily tested, eventually I expect to replace this with a real LLVM tool.
- More doxyments to come.
I assume that since this stuff doesn't touch any of the things which are part of
2.6 that it is ok to put this in not so long before the freeze, but if someone
objects let me know, I can pull it.
llvm-svn: 79612
2009-08-21 11:11:24 +02:00
|
|
|
(opts, args) = parser.parse_args()
|
|
|
|
|
|
|
|
if not args:
|
|
|
|
args.append('-')
|
|
|
|
|
|
|
|
for arg in args:
|
|
|
|
dumpmacho(arg, opts)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|