]>
git.saurik.com Git - apple/ld64.git/blob - unit-tests/test-cases/efi-basic/mtoctest.py
7 print "Unkown command line args"
12 opts
, args
= getopt
.getopt(sys
.argv
[1:],"ha:v",["help","arch=","verbose"])
13 except getopt
.GetoptError
:
14 print "Unkown command line args"
20 if o
in ("-h", "--help"):
23 elif o
in ("-a", "--arch"):
25 elif o
in ("-v", "--verbose"):
32 print "\nmach-o load commands:"
33 otoolload
= open("otool-load.log", "r")
34 data
= otoolload
.read()
37 # extract extry point from ' ss 0x00000000 eflags 0x00000000 eip 0x00000259 cs 0x00000000'
39 eip
= data
.find("eip")
41 EntryPoint
= int (data
[eip
+ 4:eip
+ 4 + 10], 16)
44 r15
= data
.find("r15")
46 EntryPoint
= int (data
[r15
+ 4:r15
+ 4 + 10], 16)
49 rip
= data
.find("rip")
51 EntryPoint
= int (data
[rip
+ 4:rip
+ 4 + 18], 16)
56 EntryPoint
= int (data
[pc
+ 3:pc
+ 3 + 18], 16)
59 print "FAIL - no entry point for PE/COFF image"
63 print "Entry Point = 0x%08x" % EntryPoint
67 print "\nPE/COFF dump:"
68 objdump
= open("efi-pecoff-util-raw.log", "r")
72 # Extract 'SizeOfImage 00000360'
73 Index
= data
.find("SizeOfImage")
74 Index
+= data
[Index
:].find("=")
75 End
= data
[Index
:].find("\n")
76 SizeOfImage
= int (data
[Index
+1:Index
+ End
], 16)
78 print "SizeOfImage = 0x%08x" % SizeOfImage
80 # We used to parse output from objdump...
81 #Parse ' 0 .text 00000080 00000240 00000240 00000240 2**2'
82 # ' CONTENTS, ALLOC, LOAD, READONLY, CODE '
84 # But now we parse efi-pecoff-util
87 # 'VirtualSize = 0x00000100
88 # 'VirtualAddress = 0x00000240
89 # 'SizeOfRawData = 0x00000100
90 # 'PointerToRawData = 0x00000240
91 # 'PointerToRelocations = 0x00000000
92 # 'PointerToLinenumbers = 0x00000000
93 # 'NumberOfRelocations = 0x0000
94 # 'NumberOfLinenumbers = 0x0000
95 # 'Characteristics = 0x60000020
96 EndOfTable
= data
.find("PdbPointer")
97 Index
= data
.find("Sections:");
98 Index
+= data
[Index
:].find("\n");
106 while Index
< EndOfTable
:
107 End
= data
[Index
:].find("\n")
108 Split
= data
[Index
:Index
+End
].split()
113 # blank line, we've finished reading a section. process results
115 # make sure we've found everything
117 print "FAIL - %s Size missing" % Name
120 print "FAIL - %s VMA missing" % Name
123 print "FAIL - %s LMA missing" % Name
126 print "FAIL - %s FileOff missing" % Name
130 print "FAIL - %s VMA %08x not equal File off %08x XIP will not work" % (Name
, VMA
, FileOff
)
135 if SecEnd
> PeCoffEnd
:
139 if (EntryPoint
< SecStart
) or (EntryPoint
> SecEnd
):
140 print "FAIL - Entry point (0x%x) not in .text section (0x%x - 0x%x)" % (EntryPoint
, SecStart
, SecEnd
)
144 print "%10s %08x %016x %016x %08x" % (Name
, Size
, VMA
, LMA
, FileOff
) + " End = %x" % PeCoffEnd
146 # clear values for next time
152 elif len(Split
) == 3:
158 if Key
== "VirtualSize":
160 if Key
== "VirtualAddress":
162 LMA
= VMA
# BUG: on our platform the virtual memory address and the load memory address are the same?
163 if Key
== "PointerToRawData":
164 FileOff
= int(Value
,16)
166 print "FAIL - Line is not (key = value): '%s'" % data
[Index
:Index
+End
]
169 Index
+= data
[Index
:].find("\n") + 1
171 if SizeOfImage
< PeCoffEnd
:
172 print "FAIL - PE/COFF Header SizeOfImage (0x%x) is not correct. Image larger than size (0x%x)." % (SizeOfImage
, PeCoffEnd
)
176 print "\nmach-o relocations:"
177 otoolreloc
= open("otool-reloc.log", "r")
178 lines
= otoolreloc
.readlines()
187 if line
.find ("address") > -1:
194 if __name__
== "__main__":