Skip to content

Commit a21a3e2

Browse files
author
Luca Di Grazia
committed
Don't pass --enable-all-security-services to GraalVM >= 21.1
The option was removed in GraalVM 21.1 oracle/graal#3258
1 parent 25b7775 commit a21a3e2

File tree

2 files changed

+80
-46
lines changed

2 files changed

+80
-46
lines changed

dataset/GitHub_Java/quarkusio.quarkus/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/GraalVM.java

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,12 @@
88
final class GraalVM {
99
static final class Version implements Comparable<Version> {
1010
private static final Pattern PATTERN = Pattern.compile(
11-
"GraalVM Version (([1-9][0-9]*)\\.([0-9]+)\\.[0-9]+|\\p{XDigit}*)[^(\n$]*(\\(Mandrel Distribution\\))?\\s*");
11+
"(GraalVM|native-image)( Version)? ([1-9][0-9]*)\\.([0-9]+)\\.[0-9]+(-dev\\p{XDigit}*)?([^\n$]*)\\s*");
1212

1313
static final Version UNVERSIONED = new Version("Undefined", -1, -1, Distribution.ORACLE);
14-
static final Version SNAPSHOT_ORACLE = new Version("Snapshot", Integer.MAX_VALUE, Integer.MAX_VALUE,
15-
Distribution.ORACLE);
16-
static final Version SNAPSHOT_MANDREL = new Version("Snapshot", Integer.MAX_VALUE, Integer.MAX_VALUE,
17-
Distribution.MANDREL);
18-
1914
static final Version VERSION_20_3 = new Version("GraalVM 20.3", 20, 3, Distribution.ORACLE);
2015
static final Version VERSION_21_0 = new Version("GraalVM 21.0", 21, 0, Distribution.ORACLE);
16+
static final Version VERSION_21_1 = new Version("GraalVM 21.1", 21, 1, Distribution.ORACLE);
2117

2218
static final Version MINIMUM = VERSION_20_3;
2319
static final Version CURRENT = VERSION_21_0;
@@ -50,14 +46,14 @@ boolean isMandrel() {
5046
return distribution == Distribution.MANDREL;
5147
}
5248

53-
boolean isSnapshot() {
54-
return this == SNAPSHOT_ORACLE || this == SNAPSHOT_MANDREL;
55-
}
56-
5749
boolean isNewerThan(Version version) {
5850
return this.compareTo(version) > 0;
5951
}
6052

53+
boolean isOlderThan(Version version) {
54+
return this.compareTo(version) < 0;
55+
}
56+
6157
@Override
6258
public int compareTo(Version o) {
6359
if (major > o.major) {
@@ -81,27 +77,21 @@ static Version of(Stream<String> lines) {
8177
final String line = it.next();
8278
final Matcher matcher = PATTERN.matcher(line);
8379
if (matcher.find() && matcher.groupCount() >= 3) {
84-
final String distro = matcher.group(4);
85-
if (isSnapshot(matcher.group(2))) {
86-
return isMandrel(distro) ? SNAPSHOT_MANDREL : SNAPSHOT_ORACLE;
87-
} else {
88-
return new Version(
89-
line,
90-
Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3)),
91-
isMandrel(distro) ? Distribution.MANDREL : Distribution.ORACLE);
92-
}
80+
final String major = matcher.group(3);
81+
final String minor = matcher.group(4);
82+
final String distro = matcher.group(6);
83+
return new Version(
84+
line,
85+
Integer.parseInt(major), Integer.parseInt(minor),
86+
isMandrel(distro) ? Distribution.MANDREL : Distribution.ORACLE);
9387
}
9488
}
9589

9690
return UNVERSIONED;
9791
}
9892

99-
private static boolean isSnapshot(String s) {
100-
return s == null;
101-
}
102-
10393
private static boolean isMandrel(String s) {
104-
return "(Mandrel Distribution)".equals(s);
94+
return s.contains("Mandrel Distribution");
10595
}
10696

10797
@Override

dataset/GitHub_Java/quarkusio.quarkus/core/deployment/src/main/java/io/quarkus/deployment/pkg/steps/NativeImageBuildStep.java

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import java.nio.file.Paths;
1111
import java.nio.file.StandardCopyOption;
1212
import java.util.ArrayList;
13+
import java.util.Arrays;
1314
import java.util.Collections;
1415
import java.util.HashMap;
1516
import java.util.List;
@@ -150,8 +151,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa
150151
String nativeImageName = getNativeImageName(outputTargetBuildItem, packageConfig);
151152
String resultingExecutableName = getResultingExecutableName(nativeImageName, isContainerBuild);
152153

153-
NativeImageBuildRunner buildRunner = getNativeImageBuildRunner(nativeConfig, outputDir,
154-
nativeImageName, resultingExecutableName);
154+
NativeImageBuildRunner buildRunner = getNativeImageBuildRunner(nativeConfig, outputDir, resultingExecutableName);
155155
buildRunner.setup(processInheritIODisabled.isPresent());
156156
final GraalVM.Version graalVMVersion = buildRunner.getGraalVMVersion();
157157

@@ -184,8 +184,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa
184184

185185
List<String> nativeImageArgs = commandAndExecutable.args;
186186

187-
int exitCode = buildRunner.build(nativeImageArgs, nativeImageName, resultingExecutableName, outputDir,
188-
nativeConfig.debug.enabled, processInheritIODisabled.isPresent());
187+
int exitCode = buildRunner.build(nativeImageArgs, outputDir, processInheritIODisabled.isPresent());
189188
if (exitCode != 0) {
190189
throw imageGenerationFailed(exitCode, nativeImageArgs);
191190
}
@@ -194,11 +193,6 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa
194193
IoUtils.copy(generatedExecutablePath, finalExecutablePath);
195194
Files.delete(generatedExecutablePath);
196195
if (nativeConfig.debug.enabled) {
197-
final String symbolsName = String.format("%s.debug", nativeImageName);
198-
Path generatedSymbols = outputDir.resolve(symbolsName);
199-
Path finalSymbolsPath = outputTargetBuildItem.getOutputDirectory().resolve(symbolsName);
200-
IoUtils.copy(generatedSymbols, finalSymbolsPath);
201-
Files.delete(generatedSymbols);
202196
final String sources = "sources";
203197
final Path generatedSources = outputDir.resolve(sources);
204198
final Path finalSources = outputTargetBuildItem.getOutputDirectory().resolve(sources);
@@ -207,6 +201,17 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa
207201
}
208202
System.setProperty("native.image.path", finalExecutablePath.toAbsolutePath().toString());
209203

204+
if (objcopyExists()) {
205+
if (nativeConfig.debug.enabled) {
206+
splitDebugSymbols(finalExecutablePath);
207+
}
208+
// Strip debug symbols regardless, because the underlying JDK might contain them
209+
objcopy("--strip-debug", finalExecutablePath.toString());
210+
} else {
211+
log.warn("objcopy executable not found in PATH. Debug symbols will not be separated from executable.");
212+
log.warn("That will result in a larger native image with debug symbols embedded in it.");
213+
}
214+
210215
return new NativeImageBuildItem(finalExecutablePath,
211216
new NativeImageBuildItem.GraalVMVersion(graalVMVersion.fullVersion, graalVMVersion.major,
212217
graalVMVersion.minor,
@@ -239,9 +244,9 @@ public static boolean isContainerBuild(NativeConfig nativeConfig) {
239244
}
240245

241246
private static NativeImageBuildRunner getNativeImageBuildRunner(NativeConfig nativeConfig, Path outputDir,
242-
String nativeImageName, String resultingExecutableName) {
247+
String resultingExecutableName) {
243248
if (!isContainerBuild(nativeConfig)) {
244-
NativeImageBuildLocalRunner localRunner = getNativeImageBuildLocalRunner(nativeConfig, outputDir.toFile());
249+
NativeImageBuildLocalRunner localRunner = getNativeImageBuildLocalRunner(nativeConfig);
245250
if (localRunner != null) {
246251
return localRunner;
247252
}
@@ -254,8 +259,7 @@ private static NativeImageBuildRunner getNativeImageBuildRunner(NativeConfig nat
254259
log.warn(errorMessage + " Attempting to fall back to container build.");
255260
}
256261
if (nativeConfig.remoteContainerBuild) {
257-
return new NativeImageBuildRemoteContainerRunner(nativeConfig, outputDir,
258-
nativeImageName, resultingExecutableName);
262+
return new NativeImageBuildRemoteContainerRunner(nativeConfig, outputDir, resultingExecutableName);
259263
}
260264
return new NativeImageBuildLocalContainerRunner(nativeConfig, outputDir);
261265
}
@@ -368,12 +372,12 @@ private void checkGraalVMVersion(GraalVM.Version version) {
368372
}
369373
}
370374

371-
private static NativeImageBuildLocalRunner getNativeImageBuildLocalRunner(NativeConfig nativeConfig, File outputDir) {
375+
private static NativeImageBuildLocalRunner getNativeImageBuildLocalRunner(NativeConfig nativeConfig) {
372376
String executableName = getNativeImageExecutableName();
373377
if (nativeConfig.graalvmHome.isPresent()) {
374378
File file = Paths.get(nativeConfig.graalvmHome.get(), "bin", executableName).toFile();
375379
if (file.exists()) {
376-
return new NativeImageBuildLocalRunner(file.getAbsolutePath(), outputDir);
380+
return new NativeImageBuildLocalRunner(file.getAbsolutePath());
377381
}
378382
}
379383

@@ -395,7 +399,7 @@ private static NativeImageBuildLocalRunner getNativeImageBuildLocalRunner(Native
395399
if (javaHome != null) {
396400
File file = new File(javaHome, "bin/" + executableName);
397401
if (file.exists()) {
398-
return new NativeImageBuildLocalRunner(file.getAbsolutePath(), outputDir);
402+
return new NativeImageBuildLocalRunner(file.getAbsolutePath());
399403
}
400404
}
401405

@@ -408,7 +412,7 @@ private static NativeImageBuildLocalRunner getNativeImageBuildLocalRunner(Native
408412
if (dir.isDirectory()) {
409413
File file = new File(dir, executableName);
410414
if (file.exists()) {
411-
return new NativeImageBuildLocalRunner(file.getAbsolutePath(), outputDir);
415+
return new NativeImageBuildLocalRunner(file.getAbsolutePath());
412416
}
413417
}
414418
}
@@ -442,6 +446,51 @@ private static String testGCCArgument(String argument) {
442446
return "";
443447
}
444448

449+
private boolean objcopyExists() {
450+
// System path
451+
String systemPath = System.getenv(PATH);
452+
if (systemPath != null) {
453+
String[] pathDirs = systemPath.split(File.pathSeparator);
454+
for (String pathDir : pathDirs) {
455+
File dir = new File(pathDir);
456+
if (dir.isDirectory()) {
457+
File file = new File(dir, "objcopy");
458+
if (file.exists()) {
459+
return true;
460+
}
461+
}
462+
}
463+
}
464+
465+
return false;
466+
}
467+
468+
private void splitDebugSymbols(Path executable) {
469+
Path symbols = Paths.get(String.format("%s.debug", executable.toString()));
470+
objcopy("--only-keep-debug", executable.toString(), symbols.toString());
471+
objcopy(String.format("--add-gnu-debuglink=%s", symbols.toString()), executable.toString());
472+
}
473+
474+
private static void objcopy(String... args) {
475+
final List<String> command = new ArrayList<>(args.length + 1);
476+
command.add("objcopy");
477+
command.addAll(Arrays.asList(args));
478+
if (log.isDebugEnabled()) {
479+
log.debugf("Execute %s", String.join(" ", command));
480+
}
481+
Process process = null;
482+
try {
483+
process = new ProcessBuilder(command).start();
484+
process.waitFor();
485+
} catch (IOException | InterruptedException e) {
486+
throw new RuntimeException("Unable to invoke objcopy", e);
487+
} finally {
488+
if (process != null) {
489+
process.destroy();
490+
}
491+
}
492+
}
493+
445494
private static class NativeImageInvokerInfo {
446495
private final List<String> args;
447496

@@ -662,11 +711,6 @@ public NativeImageInvokerInfo build() {
662711
nativeImageArgs.add("-H:+DashboardAll");
663712
}
664713

665-
// Disable single parsing of compiler graphs till https://github.com/oracle/graal/issues/3435 gets fixed
666-
if (graalVMVersion.isNewerThan(GraalVM.Version.VERSION_21_1)) {
667-
nativeImageArgs.add("-H:-ParseOnce");
668-
}
669-
670714
nativeImageArgs.add(nativeImageName);
671715

672716
return new NativeImageInvokerInfo(nativeImageArgs);

0 commit comments

Comments
 (0)