@@ -53,7 +53,12 @@ public class NativeImageDebugInfoStripFeature implements InternalFeature {
5353
5454 @ Override
5555 public boolean isInConfiguration (IsInConfigurationAccess access ) {
56- return SubstrateOptions .StripDebugInfo .getValue ();
56+ /*
57+ * Make sure this feature always runs for ELF object files to fix the object file's
58+ * alignment with objcopy. This is a temporary workaround; a proper fix will be provided
59+ * with GR-68594.
60+ */
61+ return SubstrateOptions .StripDebugInfo .getValue () || ObjectFile .getNativeFormat () == ObjectFile .Format .ELF ;
5762 }
5863
5964 @ SuppressWarnings ("try" )
@@ -112,20 +117,35 @@ private static boolean stripLinux(AfterImageWriteAccessImpl accessImpl) {
112117 try {
113118 Path outputDirectory = imagePath .getParent ();
114119 String imageFilePath = outputDirectory .resolve (imageName ).toString ();
115- if (SubstrateOptions .useDebugInfoGeneration ()) {
116- /* Generate a separate debug file before stripping the executable. */
117- String debugInfoName = imageName + debugExtension ;
118- Path debugInfoFilePath = outputDirectory .resolve (debugInfoName );
119- FileUtils .executeCommand (objcopyExe , "--only-keep-debug" , imageFilePath , debugInfoFilePath .toString ());
120- BuildArtifacts .singleton ().add (ArtifactType .DEBUG_INFO , debugInfoFilePath );
121- FileUtils .executeCommand (objcopyExe , "--add-gnu-debuglink=" + debugInfoFilePath , imageFilePath );
122- }
123- if (SubstrateOptions .DeleteLocalSymbols .getValue ()) {
124- /* Strip debug info and local symbols. */
125- FileUtils .executeCommand (objcopyExe , "--strip-all" , imageFilePath );
120+ if (SubstrateOptions .StripDebugInfo .getValue ()) {
121+ if (SubstrateOptions .useDebugInfoGeneration ()) {
122+ /* Generate a separate debug file before stripping the executable. */
123+ String debugInfoName = imageName + debugExtension ;
124+ Path debugInfoFilePath = outputDirectory .resolve (debugInfoName );
125+ FileUtils .executeCommand (objcopyExe , "--only-keep-debug" , imageFilePath , debugInfoFilePath .toString ());
126+ BuildArtifacts .singleton ().add (ArtifactType .DEBUG_INFO , debugInfoFilePath );
127+ FileUtils .executeCommand (objcopyExe , "--add-gnu-debuglink=" + debugInfoFilePath , imageFilePath );
128+ }
129+ if (SubstrateOptions .DeleteLocalSymbols .getValue ()) {
130+ /* Strip debug info and local symbols. */
131+ FileUtils .executeCommand (objcopyExe , "--strip-all" , imageFilePath );
132+ } else {
133+ /* Strip debug info only. */
134+ FileUtils .executeCommand (objcopyExe , "--strip-debug" , imageFilePath );
135+ }
126136 } else {
127- /* Strip debug info only. */
128- FileUtils .executeCommand (objcopyExe , "--strip-debug" , imageFilePath );
137+ /*
138+ * Make sure the object file is properly aligned. This step creates a temporary
139+ * file and then destructively renames it to the original image file name. In
140+ * effect, the original native image object file is copied and replaced with the
141+ * output of objcopy.
142+ *
143+ * This is a temporary workaround; a proper fix will be provided with GR-68594.
144+ */
145+ FileUtils .executeCommand (objcopyExe , imageFilePath );
146+
147+ /* Nothing was actually stripped here. */
148+ return false ;
129149 }
130150 return true ;
131151 } catch (IOException e ) {
0 commit comments