Skip to content

Commit 06fd738

Browse files
committed
use libc++ for c++ compilation, and just skip it for sandboxed
1 parent 7ab6cb0 commit 06fd738

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class GraalPythonCC extends GraalPythonCompiler {
6060
private List<String> clangArgs;
6161
private List<String> execLinkArgs;
6262
private List<String> fileInputs;
63+
private boolean isCpp;
6364

6465
GraalPythonCC() {
6566
}
@@ -103,6 +104,15 @@ static void main(String[] args) {
103104

104105
private void run(String[] args) {
105106
parseOptions(args);
107+
if (isCpp && clangArgs.stream().anyMatch(s -> s.contains("--sysroot"))) {
108+
// nasty, nasty
109+
logV("Refusing to compile C++ code in sandboxed mode, because we cannot actually do it");
110+
try {
111+
Files.createFile(Paths.get(outputFilename));
112+
} catch (IOException e) {
113+
}
114+
return;
115+
}
106116
launchCC();
107117
}
108118

@@ -116,6 +126,7 @@ private void parseOptions(String[] args) {
116126
clangArgs = new ArrayList<>(clangPrefix);
117127
execLinkArgs = new ArrayList<>(execLinkPrefix);
118128
fileInputs = new ArrayList<>();
129+
isCpp = false;
119130
for (int i = 0; i < args.length; i++) {
120131
String arg = args[i];
121132
switch (arg) {
@@ -152,6 +163,9 @@ private void parseOptions(String[] args) {
152163
}
153164
fileInputs.add(arg);
154165
} else if (arg.endsWith(".c") || arg.endsWith(".cpp") || arg.endsWith(".cxx")) {
166+
if (arg.endsWith(".cpp") || arg.endsWith(".cxx")) {
167+
isCpp = true;
168+
}
155169
if (compile == null) {
156170
compile = true;
157171
} else if (compile != true) {
@@ -168,6 +182,9 @@ private void parseOptions(String[] args) {
168182
if (targetFlags != null) {
169183
clangArgs.addAll(Arrays.asList(targetFlags.split(" ")));
170184
}
185+
if (isCpp) {
186+
clangArgs.add("-stdlib=libc++");
187+
}
171188
}
172189

173190
private void launchCC() {

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ private Collection<? extends String> arMembers(String path) throws IOException,
244244
// in the build process, because such a smart linker should not be assumed for POSIX, but it
245245
// seems ok to emulate this at least for the very common case of ar archives with symbol
246246
// definitions that overlap what's defined in explicitly include .o files
247-
for (String f : members) {
247+
outer: for (String f : members) {
248248
if (Files.probeContentType(Paths.get(f)).contains(LLVM_IR_BITCODE)) {
249249
HashSet<String> definedFuncs = new HashSet<>();
250250
HashSet<String> definedGlobals = new HashSet<>();
@@ -266,7 +266,9 @@ private Collection<? extends String> arMembers(String path) throws IOException,
266266
} else if (symboldef[1].toLowerCase().equals("d")) {
267267
definedGlobals.add(symboldef[2].trim());
268268
} else {
269-
// ignore
269+
// keep all if we have symbols that we wouldn't know what to do with
270+
logV("Not extracting from ", f, " because there are non-strong function or global symbols");
271+
continue outer;
270272
}
271273
}
272274
}

0 commit comments

Comments
 (0)