Skip to content

Commit 9593e0e

Browse files
Strip debug sections unconditionally.
1 parent eeae085 commit 9593e0e

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoStripFeature.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@
2828
import java.nio.file.Files;
2929
import java.nio.file.Path;
3030

31-
import jdk.graal.compiler.debug.DebugContext;
32-
import jdk.graal.compiler.debug.DebugContext.Builder;
33-
import jdk.graal.compiler.debug.Indent;
34-
import jdk.graal.compiler.printer.GraalDebugHandlersFactory;
35-
3631
import com.oracle.graal.pointsto.util.GraalAccess;
3732
import com.oracle.objectfile.ObjectFile;
3833
import com.oracle.svm.core.BuildArtifacts;
@@ -47,12 +42,17 @@
4742
import com.oracle.svm.hosted.c.util.FileUtils;
4843
import com.oracle.svm.util.LogUtils;
4944

45+
import jdk.graal.compiler.debug.DebugContext;
46+
import jdk.graal.compiler.debug.DebugContext.Builder;
47+
import jdk.graal.compiler.debug.Indent;
48+
import jdk.graal.compiler.printer.GraalDebugHandlersFactory;
49+
5050
@AutomaticallyRegisteredFeature
5151
public class NativeImageDebugInfoStripFeature implements InternalFeature {
5252

5353
@Override
5454
public boolean isInConfiguration(IsInConfigurationAccess access) {
55-
return SubstrateOptions.useDebugInfoGeneration() && SubstrateOptions.StripDebugInfo.getValue();
55+
return SubstrateOptions.StripDebugInfo.getValue();
5656
}
5757

5858
@SuppressWarnings("try")
@@ -82,8 +82,6 @@ private static void stripLinux(AfterImageWriteAccessImpl accessImpl) {
8282
String debugExtension = ".debug";
8383
Path imagePath = accessImpl.getImagePath();
8484
Path imageName = imagePath.getFileName();
85-
Path outputDirectory = imagePath.getParent();
86-
String debugInfoName = imageName + debugExtension;
8785
boolean objcopyAvailable = false;
8886
try {
8987
objcopyAvailable = FileUtils.executeCommand(objcopyExe, "--version") == 0;
@@ -94,16 +92,21 @@ private static void stripLinux(AfterImageWriteAccessImpl accessImpl) {
9492
}
9593

9694
if (!objcopyAvailable) {
97-
LogUtils.warning("%s not available. Skipping generation of separate debuginfo file %s, debuginfo will remain embedded in the executable.", objcopyExe, debugInfoName);
95+
LogUtils.warning("%s not available. The debuginfo will remain embedded in the executable.", objcopyExe);
9896
} else {
9997
try {
98+
Path outputDirectory = imagePath.getParent();
10099
String imageFilePath = outputDirectory.resolve(imageName).toString();
101-
Path debugInfoFilePath = outputDirectory.resolve(debugInfoName);
102-
FileUtils.executeCommand(objcopyExe, "--only-keep-debug", imageFilePath, debugInfoFilePath.toString());
103-
BuildArtifacts.singleton().add(ArtifactType.DEBUG_INFO, debugInfoFilePath);
100+
if (SubstrateOptions.useDebugInfoGeneration()) {
101+
/* Generate a separate debug file before stripping the executable. */
102+
String debugInfoName = imageName + debugExtension;
103+
Path debugInfoFilePath = outputDirectory.resolve(debugInfoName);
104+
FileUtils.executeCommand(objcopyExe, "--only-keep-debug", imageFilePath, debugInfoFilePath.toString());
105+
BuildArtifacts.singleton().add(ArtifactType.DEBUG_INFO, debugInfoFilePath);
106+
FileUtils.executeCommand(objcopyExe, "--add-gnu-debuglink=" + debugInfoFilePath, imageFilePath);
107+
}
104108
Path exportedSymbolsPath = createKeepSymbolsListFile(accessImpl);
105109
FileUtils.executeCommand(objcopyExe, "--strip-all", "--keep-symbols=" + exportedSymbolsPath, imageFilePath);
106-
FileUtils.executeCommand(objcopyExe, "--add-gnu-debuglink=" + debugInfoFilePath, imageFilePath);
107110
} catch (IOException e) {
108111
throw UserError.abort("Generation of separate debuginfo file failed", e);
109112
} catch (InterruptedException e) {

0 commit comments

Comments
 (0)