@@ -102,17 +102,24 @@ def getSectionContent(size, offset, filename):
102
102
# otool -X -s __LLVM __llvm_bc inputFile | xxd -r
103
103
# to work this can be simplified.
104
104
def extract_section_darwin (inputFile ):
105
+
105
106
otoolCmd = ['otool' , '-X' , '-s' , darwinSegmentName , darwinSectionName , inputFile ]
106
- output = sp .check_output (otoolCmd )
107
- lines = output .splitlines ()
107
+ otoolProc = Popen (otoolCmd , stdout = sp .PIPE )
108
+
109
+ otoolOutput = otoolProc .communicate ()[0 ]
110
+ if otoolProc .returncode != 0 :
111
+ logging .error ('otool failed on %s' % inputFile )
112
+ sys .exit (- 1 )
113
+
114
+ lines = otoolOutput .splitlines ()
108
115
octets = []
109
116
for line in lines :
110
117
(_ , octetline ) = line .split ('\t ' )
111
118
octets .extend (octetline .split ())
112
119
octets = '' .join (octets )
113
120
contents = octets .decode ('hex' ).splitlines ()
114
121
if not contents :
115
- logging .error ('{0} contained no {1} section is empty ' .format (inputFile , darwinSegmentName ))
122
+ logging .error ('{0} contained no {1} segment ' .format (inputFile , darwinSegmentName ))
116
123
return contents
117
124
118
125
#analagous procedure for linux (relying on objcopy)
@@ -325,7 +332,7 @@ def main(args):
325
332
process_file_darwin (inputFile , outputFile , llvmLinker , llvmArchiver )
326
333
327
334
else :
328
- #iam: do we work on anything else?
335
+ #iam: do we work on anything else?
329
336
logging .error ('Unsupported or unrecognized platform: {0}' .format (sys .platform ))
330
337
return 1
331
338
@@ -335,15 +342,15 @@ def process_file_unix(inputFile, outputFile, llvmLinker, llvmArchiver):
335
342
logging .debug ('Detected file type is {0}' .format (FileType .revMap [ft ]))
336
343
337
344
extractor = extract_section_linux
345
+ arCmd = ['ar' ,'x' ]
346
+ ofileType = FileType .ELF_OBJECT
338
347
339
348
if ft == FileType .ELF_EXECUTABLE or ft == FileType .ELF_SHARED :
340
349
logging .info ('Generating LLVM Bitcode module' )
341
350
return handleExecutable (inputFile , outputFile , extractor , llvmLinker )
342
351
elif ft == FileType .ARCHIVE :
343
- arCmd = ['ar' ,'x' ]
344
- fileType = FileType .ELF_OBJECT
345
352
logging .info ('Generating LLVM Bitcode archive' )
346
- return handleArchive (inputFile , outputFile , arCmd , fileType , extractor , llvmArchiver )
353
+ return handleArchive (inputFile , outputFile , arCmd , ofileType , extractor , llvmArchiver )
347
354
else :
348
355
logging .error ('File "{0}" of type {1} cannot be used' .format (inputFile ,FileType .revMap [ft ]))
349
356
return 1
@@ -355,15 +362,15 @@ def process_file_darwin(inputFile, outputFile, llvmLinker, llvmArchiver):
355
362
logging .debug ('Detected file type is {0}' .format (FileType .revMap [ft ]))
356
363
357
364
extractor = extract_section_darwin
365
+ arCmd = ['ar' ,'-x' ]
366
+ ofileType = FileType .MACH_OBJECT
358
367
359
368
if ft == FileType .MACH_EXECUTABLE or ft == FileType .MACH_SHARED :
360
369
logging .info ('Generating LLVM Bitcode module' )
361
370
return handleExecutable (inputFile , outputFile , extractor , llvmLinker )
362
371
elif ft == FileType .ARCHIVE :
363
- arCmd = ['ar' ,'-x' ]
364
- fileType = FileType .MACH_OBJECT
365
372
logging .info ('Generating LLVM Bitcode archive' )
366
- return handleArchive (inputFile , outputFile , arCmd , fileType , extractor , llvmArchiver )
373
+ return handleArchive (inputFile , outputFile , arCmd , ofileType , extractor , llvmArchiver )
367
374
else :
368
375
logging .error ('File "{0}" of type {1} cannot be used' .format (inputFile ,FileType .revMap [ft ]))
369
376
return 1
0 commit comments