Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-58571] Preserve local symbols if post-link stripping follows. #9888

Merged
merged 1 commit into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -942,12 +942,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;
}
}
Loading