Skip to content

Commit

Permalink
[GR-58571] Preserve local symbols if post-link stripping follows.
Browse files Browse the repository at this point in the history
PullRequest: graal/19012
  • Loading branch information
pejovica committed Oct 16, 2024
2 parents 0518461 + 2784e64 commit dbe7efa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -943,12 +943,8 @@ public static int codeAlignment() {
public static final HostedOptionKey<Integer> GenerateDebugInfo = new HostedOptionKey<>(0, SubstrateOptions::validateGenerateDebugInfo) {
@Override
protected void onValueUpdate(EconomicMap<OptionKey<?>, 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down Expand Up @@ -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");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -117,19 +114,18 @@ 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) {
throw new InterruptImageBuilding("Interrupted during debuginfo file splitting of image " + imageName);
}
}
}

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;
}
}

0 comments on commit dbe7efa

Please sign in to comment.