Summary
Add a new jlink
option --strip-native-debug-symbols
so as to be able to strip native debug symbols from executables and shared libraries. The intention would be to also integrate this with the existing --strip-debug
option.
Problem
Currently it's not possible to get debug symbols stripped from native libraries and executables. While this is most visible when creating custom JDK images from a build configured with --with-native-debug-symbols=internal
, it's also conceivable that third-party Java module developers would want to compile their native libraries with full debug symbols. Then in a later step, a custom image could get packaged in two ways. Once with debug information available, a second time without debug symbols for reduced file size. The proposed new --strip-native-debug-symbols
option allows for this.
Solution
Implement a new jlink
Linux-only plugin available via --strip-native-debug-symbols
. In addition, the new native library stripping plugin would integrate with the existing --strip-debug
option so as to also strip native debug symbols from binaries and shared libraries (where available).
Additional motivation for adding such an option is available in the bug for this CSR.
Specification
The jlink --list-plugins
output for the proposed new --strip-native-debug-symbols
would look like this:
Plugin Name: strip-native-debug-symbols
Option: --strip-native-debug-symbols=<exclude-debuginfo-files|keep-debuginfo-files|objcopy=/path/to/objcopy>
Description: Strip debug symbols from native libraries (if any).
This plugin requires at least one option:
objcopy: The path to the objcopy binary. Defaults to objcopy in PATH.
exclude-debuginfo-files: Exclude debug info files. Defaults to true.
keep-debuginfo-files[=<ext>]: Keep debug info files in <file>.<ext>.
Defaults to <file>.debuginfo
Examples: --strip-native-debug-symbols keep-debuginfo-files:objcopy=/usr/bin/objcopy
--strip-native-debug-symbols=exclude-debuginfo-files
If both --strip-debug
and --strip-native-debug-symbols
are specified on available platforms when creating an image, the command will fail. Example:
$ jlink --add-modules java.base --strip-native-debug-symbols keep-debuginfo-files --strip-debug --output jdk-image
Error: --strip-debug (-G) conflicts with --strip-native-debug-symbols. Please use one or the other, but not both.
This is to avoid potentially conflicting configurations: --strip-debug
invokes --strip-native-debug-symbols
with parameter exclude-debuginfo-files
and another explicit invocation of --strip-native-debug-symbols
might specify keep-debuginfo-symbols
. A conflicting combination.
- csr of
-
JDK-8214796 Create a jlink plugin for stripping debug info symbols from native libraries
- Resolved