Skip to content

Commit 7ab6cb0

Browse files
committed
also extract undefined globals besides functions
1 parent d9afedc commit 7ab6cb0

File tree

2 files changed

+25
-13
lines changed
  • graalpython

2 files changed

+25
-13
lines changed

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/GraalPythonLD.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ private Collection<? extends String> arMembers(String path) throws IOException,
246246
// definitions that overlap what's defined in explicitly include .o files
247247
for (String f : members) {
248248
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+
250252
ProcessBuilder nm = new ProcessBuilder();
251253
nm.command(LLVM_NM, "--defined-only", f);
252254
nm.redirectInput(Redirect.INHERIT);
@@ -256,33 +258,43 @@ private Collection<? extends String> arMembers(String path) throws IOException,
256258
try (BufferedReader buffer = new BufferedReader(new InputStreamReader(nmProc.getInputStream()))) {
257259
String line = null;
258260
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+
}
262271
}
263272
}
264273
}
265274
nmProc.waitFor();
266275

267276
ArrayList<String> extractCmd = new ArrayList<>();
268-
HashSet<String> droppedDefinitions = new HashSet<>(definedHere);
269277
extractCmd.add("llvm-extract");
270-
for (String def : definedHere) {
278+
for (String def : definedFuncs) {
271279
if (!definedSymbols.contains(def)) {
272280
definedSymbols.add(def);
273281
undefinedSymbols.remove(def);
274-
droppedDefinitions.remove(def);
275282
extractCmd.add("-func");
276283
extractCmd.add(def);
277284
}
278285
}
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+
}
285293
}
294+
extractCmd.add(f);
295+
extractCmd.add("-o");
296+
extractCmd.add(f);
297+
exec(extractCmd);
286298
}
287299
}
288300

graalpython/lib-python/3/site-packages/.keep

Whitespace-only changes.

0 commit comments

Comments
 (0)