28
28
import java .nio .file .Files ;
29
29
import java .nio .file .Path ;
30
30
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
-
36
31
import com .oracle .graal .pointsto .util .GraalAccess ;
37
32
import com .oracle .objectfile .ObjectFile ;
38
33
import com .oracle .svm .core .BuildArtifacts ;
47
42
import com .oracle .svm .hosted .c .util .FileUtils ;
48
43
import com .oracle .svm .util .LogUtils ;
49
44
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
+
50
50
@ AutomaticallyRegisteredFeature
51
51
public class NativeImageDebugInfoStripFeature implements InternalFeature {
52
52
53
53
@ Override
54
54
public boolean isInConfiguration (IsInConfigurationAccess access ) {
55
- return SubstrateOptions .useDebugInfoGeneration () && SubstrateOptions . StripDebugInfo .getValue ();
55
+ return SubstrateOptions .StripDebugInfo .getValue ();
56
56
}
57
57
58
58
@ SuppressWarnings ("try" )
@@ -82,8 +82,6 @@ private static void stripLinux(AfterImageWriteAccessImpl accessImpl) {
82
82
String debugExtension = ".debug" ;
83
83
Path imagePath = accessImpl .getImagePath ();
84
84
Path imageName = imagePath .getFileName ();
85
- Path outputDirectory = imagePath .getParent ();
86
- String debugInfoName = imageName + debugExtension ;
87
85
boolean objcopyAvailable = false ;
88
86
try {
89
87
objcopyAvailable = FileUtils .executeCommand (objcopyExe , "--version" ) == 0 ;
@@ -94,16 +92,21 @@ private static void stripLinux(AfterImageWriteAccessImpl accessImpl) {
94
92
}
95
93
96
94
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 );
98
96
} else {
99
97
try {
98
+ Path outputDirectory = imagePath .getParent ();
100
99
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
+ }
104
108
Path exportedSymbolsPath = createKeepSymbolsListFile (accessImpl );
105
109
FileUtils .executeCommand (objcopyExe , "--strip-all" , "--keep-symbols=" + exportedSymbolsPath , imageFilePath );
106
- FileUtils .executeCommand (objcopyExe , "--add-gnu-debuglink=" + debugInfoFilePath , imageFilePath );
107
110
} catch (IOException e ) {
108
111
throw UserError .abort ("Generation of separate debuginfo file failed" , e );
109
112
} catch (InterruptedException e ) {
0 commit comments