Skip to content

Commit 0dde8a6

Browse files
authored
Merge pull request #156 from bulasevich/GR-58571
[Backport][GR-58571] Preserve local symbols if post-link stripping follows.
2 parents 6a3e2cb + 6ebe9ea commit 0dde8a6

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateOptions.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -749,12 +749,8 @@ public static int codeAlignment() {
749749
public static final HostedOptionKey<Integer> GenerateDebugInfo = new HostedOptionKey<>(0, SubstrateOptions::validateGenerateDebugInfo) {
750750
@Override
751751
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Integer oldValue, Integer newValue) {
752-
if (!OS.DARWIN.isCurrent()) {
753-
/*
754-
* Keep the symbol table, as it may be used by debugging or profiling tools (e.g.,
755-
* perf). On Windows, the symbol table is included in the pdb-file, while on Linux,
756-
* it is part of the .debug file.
757-
*/
752+
if (OS.WINDOWS.isCurrent()) {
753+
/* Keep symbols on Windows. The symbol table is part of the pdb-file. */
758754
DeleteLocalSymbols.update(values, newValue == 0);
759755
}
760756
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ private static class BinutilsCCLinkerInvocation extends CCLinkerInvocation {
289289

290290
additionalPreOptions.addAll(HostedLibCBase.singleton().getAdditionalLinkerOptions(imageKind));
291291

292-
if (SubstrateOptions.DeleteLocalSymbols.getValue()) {
292+
if (SubstrateOptions.DeleteLocalSymbols.getValue() && !SubstrateOptions.StripDebugInfo.getValue()) {
293293
additionalPreOptions.add("-Wl,-x");
294294
}
295295
}
@@ -396,7 +396,7 @@ private void setLinkerFlags(NativeLibraries nativeLibs, boolean useFallback) {
396396
VMError.shouldNotReachHere(e);
397397
}
398398

399-
if (SubstrateOptions.DeleteLocalSymbols.getValue()) {
399+
if (SubstrateOptions.DeleteLocalSymbols.getValue() && !SubstrateOptions.StripDebugInfo.getValue()) {
400400
additionalPreOptions.add("-Wl,-x");
401401
}
402402

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
package com.oracle.svm.hosted.image;
2626

2727
import java.io.IOException;
28-
import java.nio.file.Files;
2928
import java.nio.file.Path;
3029

3130
import org.graalvm.compiler.core.common.SuppressFBWarnings;
@@ -114,19 +113,18 @@ private static void stripLinux(AfterImageWriteAccessImpl accessImpl) {
114113
BuildArtifacts.singleton().add(ArtifactType.DEBUG_INFO, debugInfoFilePath);
115114
FileUtils.executeCommand(objcopyExe, "--add-gnu-debuglink=" + debugInfoFilePath, imageFilePath);
116115
}
117-
Path exportedSymbolsPath = createKeepSymbolsListFile(accessImpl);
118-
FileUtils.executeCommand(objcopyExe, "--strip-all", "--keep-symbols=" + exportedSymbolsPath, imageFilePath);
116+
if (SubstrateOptions.DeleteLocalSymbols.getValue()) {
117+
/* Strip debug info and local symbols. */
118+
FileUtils.executeCommand(objcopyExe, "--strip-all", imageFilePath);
119+
} else {
120+
/* Strip debug info only. */
121+
FileUtils.executeCommand(objcopyExe, "--strip-debug", imageFilePath);
122+
}
119123
} catch (IOException e) {
120124
throw UserError.abort("Generation of separate debuginfo file failed", e);
121125
} catch (InterruptedException e) {
122126
throw new InterruptImageBuilding("Interrupted during debuginfo file splitting of image " + imageName);
123127
}
124128
}
125129
}
126-
127-
private static Path createKeepSymbolsListFile(AfterImageWriteAccessImpl accessImpl) throws IOException {
128-
Path exportedSymbolsPath = accessImpl.getTempDirectory().resolve("keep-symbols.list").toAbsolutePath();
129-
Files.write(exportedSymbolsPath, accessImpl.getImageSymbols(true));
130-
return exportedSymbolsPath;
131-
}
132130
}

0 commit comments

Comments
 (0)