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

Only use objcopy in Linux environments #20297

Merged
merged 1 commit into from
Sep 28, 2021
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 @@ -4,6 +4,8 @@
import java.util.List;
import java.util.stream.Stream;

import org.apache.commons.lang3.SystemUtils;

public class NativeImageBuildLocalRunner extends NativeImageBuildRunner {

private final String nativeImageExecutable;
Expand Down Expand Up @@ -34,6 +36,10 @@ protected void objcopy(String... args) {

@Override
protected boolean objcopyExists() {
if (!SystemUtils.IS_OS_LINUX) {
return false;
}

// System path
String systemPath = System.getenv("PATH");
if (systemPath != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.commons.lang3.SystemUtils;
import org.jboss.logging.Logger;

import io.quarkus.deployment.util.ProcessUtil;
Expand Down Expand Up @@ -75,12 +76,10 @@ public Result build(List<String> args, String nativeImageName, String resultingE
// Strip debug symbols regardless, because the underlying JDK might contain them
objcopy("--strip-debug", resultingExecutableName);
}
} else {
if (!debugSymbolsEnabled) {
log.warn(
"objcopy executable not found in PATH. Debug symbols will therefore not be separated from the executable.");
log.warn("That also means that resulting native executable is larger as it embeds the debug symbols.");
}
} else if (SystemUtils.IS_OS_LINUX) {
log.warn(
"objcopy executable not found in PATH. Debug symbols will therefore not be separated from the executable.");
log.warn("That also means that resulting native executable is larger as it embeds the debug symbols.");
}
return new Result(0, objcopyExists);
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,7 @@ public NativeImageBuildItem build(NativeConfig nativeConfig, NativeImageSourceJa
Path finalSymbolsPath = outputTargetBuildItem.getOutputDirectory().resolve(symbolsName);
IoUtils.copy(generatedSymbols, finalSymbolsPath);
Files.delete(generatedSymbols);
} else {
log.warn(
"objcopy executable not found in PATH. Debug symbols therefore cannot be placed into the dedicated directory.");
log.warn("That also means that resulting native executable is larger as it embeds the debug symbols.");
}
Copy link
Contributor

@zakkak zakkak Sep 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, it looks like you were a bit more aggressive here, we need that } back :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll fix this shortly.


}
System.setProperty("native.image.path", finalExecutablePath.toAbsolutePath().toString());

Expand Down
7 changes: 2 additions & 5 deletions docs/src/main/asciidoc/building-native-image.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ Depending on what the final desired output of the CI/CD pipeline is, the generat

Starting with Oracle GraalVM 20.2 or Mandrel 20.1,
debug symbols for native executables can be generated for Linux environments
(Windows support is still under development).
(Windows support is still under development, macOS is not supported).
These symbols can be used to debug native executables with tools such as `gdb`.

To generate debug symbols,
Expand All @@ -713,17 +713,14 @@ You will find the debug symbols for the native executable in a `.debug` file nex
[NOTE]
====
The generation of the `.debug` file depends on `objcopy`.
On common Linux distributions and macOS you will need to install the `binutils` package:
On common Linux distributions you will need to install the `binutils` package:
[source,bash]
----
# dnf (rpm-based)
sudo dnf install binutils
# Debian-based distributions
sudo apt-get install binutils
# macOS
brew install binutils
export PATH=/usr/local/opt/binutils/bin:$PATH
----
When `objcopy` is not available debug symbols are embedded in the executable.
Expand Down