@@ -79,7 +79,7 @@ def getSectionSizeAndOffset(sectionName, filename):
79
79
continue
80
80
81
81
# The needed section could not be found
82
- logging .error ('Could not find "{0}" ELF section in "{1}"' .format (sectionName ,filename ))
82
+ logging .warning ('Could not find "{0}" ELF section in "{1}", so skipping this entry. ' .format (sectionName ,filename ))
83
83
return None
84
84
85
85
# Read the entire content of an ELF section into a string
@@ -140,24 +140,9 @@ def extract_section_linux(inputFile):
140
140
return contents
141
141
142
142
143
- def handleExecutable (inputFile , outputFile , extractor , llvmLinker , manifestFlag ):
144
-
145
- fileNames = extractor (inputFile )
146
-
147
- if not fileNames :
148
- return 1
149
-
150
- if manifestFlag :
151
- manifestFile = '{0}.wllvm.manifest' .format (inputFile )
152
- with open (manifestFile , 'w' ) as output :
153
- for f in fileNames :
154
- output .write ('{0}\n ' .format (f ))
155
-
156
- if outputFile == None :
157
- outputFile = inputFile + '.' + moduleExtension
158
-
143
+ def linkFiles (outputFile , llvmLinker , fileNames ):
159
144
linkCmd = [ llvmLinker , '-v' ] if verboseFlag else [ llvmLinker ]
160
-
145
+
161
146
linkCmd .extend (['-o' , outputFile ])
162
147
163
148
linkCmd .extend ([x for x in fileNames if x != '' ])
@@ -171,12 +156,69 @@ def handleExecutable(inputFile, outputFile, extractor, llvmLinker, manifestFlag)
171
156
errorMsg = "OS error({0}): {1}" .format (e .errno , e .strerror )
172
157
logging .error (errorMsg )
173
158
raise Exception (errorMsg )
174
-
159
+
175
160
else :
176
161
exitCode = linkProc .wait ()
177
162
logging .info ('{0} returned {1}' .format (llvmLinker , str (exitCode )))
178
163
return exitCode
179
164
165
+
166
+ def archiveFiles (outputFile , llvmArchiver , fileNames ):
167
+ retCode = 0
168
+ # We do not want full paths in the archive so we need to chdir into each
169
+ # bitcode's folder. Handle this by calling llvm-ar once for all bitcode
170
+ # files in the same directory
171
+
172
+ # Map of directory names to list of bitcode files in that directory
173
+ dirToBCMap = {}
174
+ for bitCodeFile in fileNames :
175
+ dirName = os .path .dirname (bitCodeFile )
176
+ basename = os .path .basename (bitCodeFile )
177
+ if dirName in dirToBCMap :
178
+ dirToBCMap [dirName ].append (basename )
179
+ else :
180
+ dirToBCMap [dirName ] = [ basename ]
181
+
182
+ logging .debug ('Built up directory to bitcode file list map:\n {0}' .format (
183
+ pprint .pformat (dirToBCMap )))
184
+
185
+ for (dirname , bcList ) in dirToBCMap .items ():
186
+ logging .debug ('Changing directory to "{0}"' .format (dirname ))
187
+ os .chdir (dirname )
188
+ larCmd = [llvmArchiver , 'rs' , outputFile ] + bcList
189
+ larProc = Popen (larCmd )
190
+ retCode = larProc .wait ()
191
+ if retCode != 0 :
192
+ logging .error ('Failed to execute:\n {0}' .format (pprint .pformat (larCmd )))
193
+ break
194
+
195
+ if retCode == 0 :
196
+ logging .info ('Generated LLVM bitcode archive {0}' .format (outputFile ))
197
+ else :
198
+ logging .error ('Failed to generate LLVM bitcode archive' )
199
+
200
+ return retCode
201
+ pass
202
+
203
+
204
+ def handleExecutable (inputFile , outputFile , extractor , llvmLinker , manifestFlag ):
205
+
206
+ fileNames = extractor (inputFile )
207
+
208
+ if not fileNames :
209
+ return 1
210
+
211
+ if manifestFlag :
212
+ manifestFile = '{0}.wllvm.manifest' .format (inputFile )
213
+ with open (manifestFile , 'w' ) as output :
214
+ for f in fileNames :
215
+ output .write ('{0}\n ' .format (f ))
216
+
217
+ if outputFile == None :
218
+ outputFile = inputFile + '.' + moduleExtension
219
+
220
+ return linkFiles (outputFile , llvmLinker , fileNames )
221
+
180
222
181
223
182
224
@@ -252,7 +294,6 @@ def handleArchive(inputFile, outputFile, arCmd, fileType, extractor, llvmArchive
252
294
return buildArchive (inputFile , outputFile , llvmArchiver , bitCodeFiles )
253
295
254
296
def buildArchive (inputFile , outputFile , llvmArchiver , bitCodeFiles ):
255
- retCode = 0
256
297
# Pick output file path if outputFile not set
257
298
if outputFile == None :
258
299
if inputFile .endswith ('.a' ):
@@ -264,39 +305,7 @@ def buildArchive(inputFile, outputFile, llvmArchiver, bitCodeFiles):
264
305
265
306
logging .info ('Writing output to {0}' .format (outputFile ))
266
307
267
- # We do not want full paths in the archive so we need to chdir into each
268
- # bitcode's folder. Handle this by calling llvm-ar once for all bitcode
269
- # files in the same directory
270
-
271
- # Map of directory names to list of bitcode files in that directory
272
- dirToBCMap = {}
273
- for bitCodeFile in bitCodeFiles :
274
- dirName = os .path .dirname (bitCodeFile )
275
- basename = os .path .basename (bitCodeFile )
276
- if dirName in dirToBCMap :
277
- dirToBCMap [dirName ].append (basename )
278
- else :
279
- dirToBCMap [dirName ] = [ basename ]
280
-
281
- logging .debug ('Built up directory to bitcode file list map:\n {0}' .format (
282
- pprint .pformat (dirToBCMap )))
283
-
284
- for (dirname , bcList ) in dirToBCMap .items ():
285
- logging .debug ('Changing directory to "{0}"' .format (dirname ))
286
- os .chdir (dirname )
287
- larCmd = [llvmArchiver , 'rs' , outputFile ] + bcList
288
- larProc = Popen (larCmd )
289
- retCode = larProc .wait ()
290
- if retCode != 0 :
291
- logging .error ('Failed to execute:\n {0}' .format (pprint .pformat (larCmd )))
292
- break
293
-
294
- if retCode == 0 :
295
- logging .info ('Generated LLVM bitcode archive {0}' .format (outputFile ))
296
- else :
297
- logging .error ('Failed to generate LLVM bitcode archive' )
298
-
299
- return retCode
308
+ return archiveFiles (outputFile , llvmArchiver , bitCodeFiles )
300
309
301
310
302
311
0 commit comments