diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java index 3a7a5c5cbc90..42a553ded691 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java @@ -943,12 +943,8 @@ public static int codeAlignment() { public static final HostedOptionKey GenerateDebugInfo = new HostedOptionKey<>(0, SubstrateOptions::validateGenerateDebugInfo) { @Override protected void onValueUpdate(EconomicMap, Object> values, Integer oldValue, Integer newValue) { - if (!OS.DARWIN.isCurrent()) { - /* - * Keep the symbol table, as it may be used by debugging or profiling tools (e.g., - * perf). On Windows, the symbol table is included in the pdb-file, while on Linux, - * it is part of the .debug file. - */ + if (OS.WINDOWS.isCurrent()) { + /* Keep symbols on Windows. The symbol table is part of the pdb-file. */ DeleteLocalSymbols.update(values, newValue == 0); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java index f476c2d3dee4..7a7e6d226951 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/CCLinkerInvocation.java @@ -304,7 +304,7 @@ private static class BinutilsCCLinkerInvocation extends CCLinkerInvocation { additionalPreOptions.addAll(HostedLibCBase.singleton().getAdditionalLinkerOptions(imageKind)); - if (SubstrateOptions.DeleteLocalSymbols.getValue()) { + if (SubstrateOptions.DeleteLocalSymbols.getValue() && !SubstrateOptions.StripDebugInfo.getValue()) { additionalPreOptions.add("-Wl,-x"); } } @@ -414,7 +414,7 @@ private void setLinkerFlags(NativeLibraries nativeLibs, boolean useFallback) { VMError.shouldNotReachHere(e); } - if (SubstrateOptions.DeleteLocalSymbols.getValue()) { + if (SubstrateOptions.DeleteLocalSymbols.getValue() && !SubstrateOptions.StripDebugInfo.getValue()) { additionalPreOptions.add("-Wl,-x"); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoStripFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoStripFeature.java index 4002cccf2cbf..740873693b91 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoStripFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoStripFeature.java @@ -24,10 +24,7 @@ */ package com.oracle.svm.hosted.image; -import static com.oracle.svm.core.SubstrateOptions.DeleteLocalSymbols; - import java.io.IOException; -import java.nio.file.Files; import java.nio.file.Path; import org.graalvm.nativeimage.Platform; @@ -117,8 +114,13 @@ private static void stripLinux(AfterImageWriteAccessImpl accessImpl) { BuildArtifacts.singleton().add(ArtifactType.DEBUG_INFO, debugInfoFilePath); FileUtils.executeCommand(objcopyExe, "--add-gnu-debuglink=" + debugInfoFilePath, imageFilePath); } - Path exportedSymbolsPath = createKeepSymbolsListFile(accessImpl); - FileUtils.executeCommand(objcopyExe, "--strip-all", "--keep-symbols=" + exportedSymbolsPath, imageFilePath); + if (SubstrateOptions.DeleteLocalSymbols.getValue()) { + /* Strip debug info and local symbols. */ + FileUtils.executeCommand(objcopyExe, "--strip-all", imageFilePath); + } else { + /* Strip debug info only. */ + FileUtils.executeCommand(objcopyExe, "--strip-debug", imageFilePath); + } } catch (IOException e) { throw UserError.abort("Generation of separate debuginfo file failed", e); } catch (InterruptedException e) { @@ -126,10 +128,4 @@ private static void stripLinux(AfterImageWriteAccessImpl accessImpl) { } } } - - private static Path createKeepSymbolsListFile(AfterImageWriteAccessImpl accessImpl) throws IOException { - Path exportedSymbolsPath = accessImpl.getTempDirectory().resolve("keep-symbols.list").toAbsolutePath(); - Files.write(exportedSymbolsPath, accessImpl.getImageSymbols(DeleteLocalSymbols.getValue())); - return exportedSymbolsPath; - } }