@@ -246,7 +246,9 @@ private Collection<? extends String> arMembers(String path) throws IOException,
246
246
// definitions that overlap what's defined in explicitly include .o files
247
247
for (String f : members ) {
248
248
if (Files .probeContentType (Paths .get (f )).contains (LLVM_IR_BITCODE )) {
249
- HashSet <String > definedHere = new HashSet <>();
249
+ HashSet <String > definedFuncs = new HashSet <>();
250
+ HashSet <String > definedGlobals = new HashSet <>();
251
+
250
252
ProcessBuilder nm = new ProcessBuilder ();
251
253
nm .command (LLVM_NM , "--defined-only" , f );
252
254
nm .redirectInput (Redirect .INHERIT );
@@ -256,33 +258,43 @@ private Collection<? extends String> arMembers(String path) throws IOException,
256
258
try (BufferedReader buffer = new BufferedReader (new InputStreamReader (nmProc .getInputStream ()))) {
257
259
String line = null ;
258
260
while ((line = buffer .readLine ()) != null ) {
259
- String [] symboldef = line .split (" [Tt]" );
260
- if (symboldef .length >= 2 ) {
261
- definedHere .add (symboldef [symboldef .length - 1 ].trim ());
261
+ String [] symboldef = line .split (" " );
262
+ if (symboldef .length == 3 ) {
263
+ // format is ------- CHAR FUNCNAME
264
+ if (symboldef [1 ].toLowerCase ().equals ("t" )) {
265
+ definedFuncs .add (symboldef [2 ].trim ());
266
+ } else if (symboldef [1 ].toLowerCase ().equals ("d" )) {
267
+ definedGlobals .add (symboldef [2 ].trim ());
268
+ } else {
269
+ // ignore
270
+ }
262
271
}
263
272
}
264
273
}
265
274
nmProc .waitFor ();
266
275
267
276
ArrayList <String > extractCmd = new ArrayList <>();
268
- HashSet <String > droppedDefinitions = new HashSet <>(definedHere );
269
277
extractCmd .add ("llvm-extract" );
270
- for (String def : definedHere ) {
278
+ for (String def : definedFuncs ) {
271
279
if (!definedSymbols .contains (def )) {
272
280
definedSymbols .add (def );
273
281
undefinedSymbols .remove (def );
274
- droppedDefinitions .remove (def );
275
282
extractCmd .add ("-func" );
276
283
extractCmd .add (def );
277
284
}
278
285
}
279
- if (!droppedDefinitions .isEmpty ()) {
280
- // only run the extractor if we actually need to drop something
281
- extractCmd .add (f );
282
- extractCmd .add ("-o" );
283
- extractCmd .add (f );
284
- exec (extractCmd );
286
+ for (String def : definedGlobals ) {
287
+ if (!definedSymbols .contains (def )) {
288
+ definedSymbols .add (def );
289
+ undefinedSymbols .remove (def );
290
+ extractCmd .add ("-glob" );
291
+ extractCmd .add (def );
292
+ }
285
293
}
294
+ extractCmd .add (f );
295
+ extractCmd .add ("-o" );
296
+ extractCmd .add (f );
297
+ exec (extractCmd );
286
298
}
287
299
}
288
300
0 commit comments