Skip to content

Commit

Permalink
Only use objcopy in Linux environments quarkusio#13856
Browse files Browse the repository at this point in the history
* `objcopy` invocations in macOS make the executable crash on startup.
* Debug info is only available for Linux,
so avoid `objcopy` altogether on macOS,
even if present in PATH.
* Updated documentation to avoid confusion.
* Adjusted warning messages about `objcopy`.
  • Loading branch information
galderz authored and gsmet committed Sep 27, 2021
1 parent 4c39153 commit 7c12f02
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
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.");
}

}
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

0 comments on commit 7c12f02

Please sign in to comment.