Skip to content

Commit

Permalink
[GR-30353] Fix RemoveUnusedSymbols on Windows.
Browse files Browse the repository at this point in the history
PullRequest: graal/8577
  • Loading branch information
pejovica committed Mar 25, 2021
2 parents 0d44023 + b142a39 commit d4ff57f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,12 @@ public static boolean useLLVMBackend() {
@Option(help = "Determines if VM operations should be executed in a dedicated thread.", type = OptionType.Expert)//
public static final HostedOptionKey<Boolean> UseDedicatedVMOperationThread = new HostedOptionKey<>(false);

/*
* RemoveUnusedSymbols is not enabled on Darwin by default, because the linker sometimes
* segfaults when the -dead_strip option is used.
*/
@Option(help = "Use linker option to prevent unreferenced symbols in image.")//
public static final HostedOptionKey<Boolean> RemoveUnusedSymbols = new HostedOptionKey<>(false);
public static final HostedOptionKey<Boolean> RemoveUnusedSymbols = new HostedOptionKey<>(OS.getCurrent() != OS.DARWIN);
@Option(help = "Use linker option to remove all local symbols from image.")//
public static final HostedOptionKey<Boolean> DeleteLocalSymbols = new HostedOptionKey<>(true);
@Option(help = "Compatibility option to make symbols used for the image heap global. " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,6 @@ public NativeImageViaCC(NativeImageKind k, HostedUniverse universe, HostedMetaAc
super(k, universe, metaAccess, nativeLibs, heap, codeCache, entryPoints, imageClassLoader);
}

private static boolean removeUnusedSymbols() {
if (SubstrateOptions.RemoveUnusedSymbols.hasBeenSet()) {
return SubstrateOptions.RemoveUnusedSymbols.getValue();
}
/*
* The Darwin linker sometimes segfaults when option -dead_strip is used. Thus, Linux is the
* only platform were RemoveUnusedSymbols can be safely enabled per default.
*/
return Platform.includedIn(Platform.LINUX.class);
}

class BinutilsCCLinkerInvocation extends CCLinkerInvocation {

private final boolean staticExecWithDynamicallyLinkLibC = SubstrateOptions.StaticExecutableWithDynamicLibC.getValue();
Expand All @@ -100,7 +89,7 @@ class BinutilsCCLinkerInvocation extends CCLinkerInvocation {
additionalPreOptions.add("-Wl,--rosegment");
}

if (removeUnusedSymbols()) {
if (SubstrateOptions.RemoveUnusedSymbols.getValue()) {
/* Perform garbage collection of unused input sections. */
additionalPreOptions.add("-Wl,--gc-sections");
}
Expand Down Expand Up @@ -189,7 +178,7 @@ class DarwinCCLinkerInvocation extends CCLinkerInvocation {
additionalPreOptions.add("-Wl,-no_compact_unwind");
}

if (removeUnusedSymbols()) {
if (SubstrateOptions.RemoveUnusedSymbols.getValue()) {
/* Remove functions and data unreachable by entry points. */
additionalPreOptions.add("-Wl,-dead_strip");
}
Expand Down Expand Up @@ -306,8 +295,9 @@ public List<String> getCommand() {
}
}

if (removeUnusedSymbols()) {
cmd.add("/OPT:REF");
if (!SubstrateOptions.RemoveUnusedSymbols.getValue()) {
/* Disable removal as it is on by default. */
cmd.add("/OPT:NOREF,NOICF");
}

// Add clibrary paths to command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec
}

void registerLibrary(String libname) {
if (libname != null && registeredLibraries.putIfAbsent(libname, Boolean.TRUE) != Boolean.TRUE) {
if (libname != null && registeredLibraries.putIfAbsent(libname, Boolean.TRUE) == null) {
/*
* If a library is in our list of static standard libraries, add the library to the
* linker command.
Expand Down

0 comments on commit d4ff57f

Please sign in to comment.