|
36 | 36 | import java.util.regex.Pattern;
|
37 | 37 |
|
38 | 38 | import jdk.graal.compiler.code.CompilationResult.CodeAnnotation;
|
| 39 | +import jdk.graal.compiler.core.common.NativeImageSupport; |
| 40 | +import jdk.graal.compiler.debug.GraalError; |
| 41 | +import jdk.graal.compiler.debug.TTY; |
39 | 42 | import jdk.graal.compiler.options.Option;
|
40 | 43 | import jdk.graal.compiler.options.OptionKey;
|
41 | 44 | import jdk.graal.compiler.options.OptionType;
|
@@ -91,6 +94,9 @@ public boolean isAvailable(OptionValues options) {
|
91 | 94 |
|
92 | 95 | @Override
|
93 | 96 | public String disassembleCompiledCode(OptionValues options, CodeCacheProvider codeCache, CompilationResult compResult) {
|
| 97 | + if (NativeImageSupport.inRuntimeCode() && !ENABLE_OBJDUMP) { |
| 98 | + throw new GraalError("Objdump not available"); |
| 99 | + } |
94 | 100 | String objdump = getObjdump(options);
|
95 | 101 | if (objdump == null) {
|
96 | 102 | return null;
|
@@ -206,13 +212,36 @@ public static String quoteShellArg(String arg) {
|
206 | 212 | return "'" + arg.replace("'", "'\"'\"'") + "'";
|
207 | 213 | }
|
208 | 214 |
|
| 215 | + private static final String ENABLE_OBJDUMP_PROP = "debug.jdk.graal.enableObjdump"; |
| 216 | + |
| 217 | + /** |
| 218 | + * Support for objdump is excluded by default from native images (including libgraal) to reduce |
| 219 | + * the image size. It also reduces security concerns related to running subprocesses. |
| 220 | + * |
| 221 | + * To objdump during development, set the {@value #ENABLE_OBJDUMP_PROP} system property to true |
| 222 | + * when building native images. |
| 223 | + */ |
| 224 | + private static final boolean ENABLE_OBJDUMP = Boolean.parseBoolean(GraalServices.getSavedProperty(ENABLE_OBJDUMP_PROP)); |
| 225 | + |
| 226 | + private static boolean objdumpUnsupportedWarned; |
| 227 | + |
209 | 228 | /**
|
210 | 229 | * Searches for a valid GNU objdump executable.
|
211 | 230 | */
|
212 |
| - private String getObjdump(OptionValues options) { |
| 231 | + private static String getObjdump(OptionValues options) { |
213 | 232 | // for security, user must provide the possible objdump locations.
|
214 | 233 | String candidates = Options.ObjdumpExecutables.getValue(options);
|
215 | 234 | if (candidates != null && !candidates.isEmpty()) {
|
| 235 | + if (NativeImageSupport.inRuntimeCode() && !ENABLE_OBJDUMP) { |
| 236 | + if (!objdumpUnsupportedWarned) { |
| 237 | + // Ignore races or multiple isolates - an extra warning is ok |
| 238 | + objdumpUnsupportedWarned = true; |
| 239 | + TTY.printf("WARNING: Objdump not supported as the %s system property was false when building.%n", |
| 240 | + ENABLE_OBJDUMP_PROP); |
| 241 | + } |
| 242 | + return null; |
| 243 | + } |
| 244 | + |
216 | 245 | for (String candidate : candidates.split(",")) {
|
217 | 246 | synchronized (objdumpCache) {
|
218 | 247 | // first checking to see if a cached verdict for this candidate exists.
|
|
0 commit comments