package/openjdk: fix installation with merged usr directories
PATCH v2 1/3 package/openjdk: fix installation with merged usr directories
From: Adam Duskett <[email protected]>
Currently, Buildroot installs the jre libraries using
cp -dprf /build/linux-*-release/images/jre/lib/* $(TARGET_DIR)/usr/lib/
However, if a system has a merged /usr directory, and there is a built kernel before installing OpenJDK, the installation fails because jre/lib has binary modules file, which causes the following error: cp: cannot overwrite directory '/usr/lib/modules with non-directory
The obvious fix is to install the modules to /usr/lib/jvm/ and set the appropriate rpaths via the --with-extra-ldflags conf option. However, this fix does not work because the built binaries themselves do not link against libjava.so
Indeed, running readelf on the built java binary reports the following:
"(RUNPATH) Library runpath: [/usr/lib/jvm]" and /usr/lib/jvm/libjava.so exists. However, when running the Java binary on the target, the following error
occurs: "Error: could not find libjava.so."
The following is the result of "strace java" ran on the target:faccessat(AT_FDCWD, "/usr/lib/libjava.so", F_OK) = -1 ENOENT faccessat(AT_FDCWD, "/usr/jre/lib/libjava.so", F_OK) = -1 ENOENT newfstatat(AT_FDCWD, "/usr/lib/libjava.so", 0x7ffe7b4af8, 0) = -1 ENOENT newfstatat(AT_FDCWD, "/usr/lib/jvm/libjli.so", [sic] AT_SYMLINK_NOFOLLOW) = 0
As seen above, the java binary searches for libjli.so in /usr/lib/jvm, but libjava.so has the search paths hardcoded to the following directories:
- /usr/lib/
- /usr/jre/lib/
- $(dirname $0)/../lib/
The reason behind the hardcoded paths given by the maintainers is due to historical purposes for the need to support several java versions at the same time on a single system, and that changing the above behavior is not likely to ever happen.
As such, most distributions such as Redhat do the following:
- Create the directory /usr/lib/jvm/java-$(JAVA_VERSION)/
- Install all directories and files found in images/jre to that directory.
- Symlink the binaries to in /usr/lib/jvm/java-$(JAVA_VERSION)/bin to
/usr/bin.
However, because Buildroot does not need to support multiple versions of java concurrently, there is no need for the additional java-$(JAVA_VERSION) directory.
To fix the above issue, the following changes are performed:
- Introduce the variable "OPENJDK_INSTALL_BASE" which points to /usr/lib/jvm
- Set the --with-extra-ldflags conf_opt to
"-Wl,-rpath,$(OPENJDK_INSTALL_BASE)/lib,-rpath,
$(OPENJDK_INSTALL_BASE)/lib/$(OPENJDK_JVM_VARIANT)" - Run "mkdir -p $(TARGET_DIR)/usr/lib/jvm/" in the INSTALL_TARGET_CMDS step.
- Copy both the lib and bin directories to /usr/lib/jvm/
- Symlink the binaries in /usr/lib/jvm/bin/ to /usr/bin.
---
Changes v1 -> v2:
- Fixed comments in openjdk.mk (Yann)
- Added spaces around the = sign for OPENJDK_INSTALL_BASE (Yann)
- Added trailing /'s for copying (Yann)
- Added a more complete commit message.
package/openjdk/openjdk.mk | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
package/openjdk/openjdk.mk +14 -2
@@ -46,6 +46,13 @@ OPENJDK_JVM_VARIANT = zero OPENJDK_DEPENDENCIES += libffi endif +# OpenJDK installs a file named 'modules' in jre/lib, which gets installed as +# /usr/lib/modules. However, with a merged /usr, this conflicts with the +# directory named 'modules' installed by the kernel. If OpenJDK gets built +# after the kernel, this manifests itself with: "cp: cannot overwrite +# directory '/usr/lib/modules with non-directory." +OPENJDK_INSTALL_BASE = /usr/lib/jvm + # OpenJDK ignores some variables unless passed via the environment. # These variables are PATH, LD, CC, CXX, and CPP. # OpenJDK defaults ld to the ld binary but passes -Xlinker and -z as
@@ -75,6 +82,7 @@ OPENJDK_CONF_OPTS = \ --with-devkit=$(HOST_DIR) \ --with-extra-cflags="$(TARGET_CFLAGS)" \ --with-extra-cxxflags="$(TARGET_CXXFLAGS)" \ + --with-extra-ldflags="-Wl,-rpath,$(OPENJDK_INSTALL_BASE)/lib,-rpath,$(OPENJDK_INSTALL_BASE)/lib/$(OPENJDK_JVM_VARIANT)" \ --with-giflib=system \ --with-jobs=$(PARALLEL_JOBS) \ --with-jvm-variants=$(OPENJDK_JVM_VARIANT) \
@@ -114,8 +122,12 @@ endef # Calling make install always builds and installs the JDK instead of the JRE, # which makes manual installation necessary. define OPENJDK_INSTALL_TARGET_CMDS - cp -dpfr $(@D)/build/linux-*-release/images/jre/bin/* $(TARGET_DIR)/usr/bin/ - cp -dpfr $(@D)/build/linux-*-release/images/jre/lib/* $(TARGET_DIR)/usr/lib/ + mkdir -p $(TARGET_DIR)$(OPENJDK_INSTALL_BASE) + cp -dpfr $(@D)/build/linux-*-release/images/jre/bin/ \ + $(TARGET_DIR)$(OPENJDK_INSTALL_BASE) + cp -dpfr $(@D)/build/linux-*-release/images/jre/lib/ \ + $(TARGET_DIR)/$(OPENJDK_INSTALL_BASE)/ + cd $(TARGET_DIR)/usr/bin && ln -snf ../..$(OPENJDK_INSTALL_BASE)/bin/* . endef $(eval $(generic-package))
Signature · 1 line
2.25.2
PATCH v2 2/3 package/openjdk: copy all directories and files when installing
From: Adam Duskett <[email protected]>
Several directories and files are currently not installed during the target installation, these include:
- conf
Several configuration files, including security configuration files which may be necessary for running various java applications.
- legal
This directory contains legal notices that some java applications may require, as they may print legal information and will throw exceptions at runtime if the legal files are not present on the system.
- release
This file contains a list of modules included in the image.
Because these directories take up less than of megabyte extra, it is not an issue to install all of them.
---
Changes v1 -> v2:
- Added a better explination for why the legal directory is necessary.
package/openjdk/openjdk.mk | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
package/openjdk/openjdk.mk +2 -4
@@ -123,10 +123,8 @@ endef # which makes manual installation necessary. define OPENJDK_INSTALL_TARGET_CMDS mkdir -p $(TARGET_DIR)$(OPENJDK_INSTALL_BASE) - cp -dpfr $(@D)/build/linux-*-release/images/jre/bin/ \ - $(TARGET_DIR)$(OPENJDK_INSTALL_BASE) - cp -dpfr $(@D)/build/linux-*-release/images/jre/lib/ \ - $(TARGET_DIR)/$(OPENJDK_INSTALL_BASE)/ + cp -dpfr $(@D)/build/linux-*-release/images/jre/* \ + $(TARGET_DIR)$(OPENJDK_INSTALL_BASE)/ cd $(TARGET_DIR)/usr/bin && ln -snf ../..$(OPENJDK_INSTALL_BASE)/bin/* . endef
Signature · 1 line
2.25.2
PATCH v2 2/3 package/openjdk: copy all directories and files when installing
Adam/All,
Quoted 20 lines · On Sat, Apr 18, 2020 at 2:10 PM <[email protected]> wrote:
From: Adam Duskett <[email protected]>
Several directories and files are currently not installed during the target installation, these include:
- conf
Several configuration files, including security configuration files which may be necessary for running various java applications.- legal
This directory contains legal notices that some java applications may require, as they may print legal information and will throw exceptions at runtime if the legal files are not present on the system.- release
This file contains a list of modules included in the image.Because these directories take up less than of megabyte extra, it is not an issue to install all of them.
Quoted 7 lines
Signed-off-by Adam Duskett <[email protected]>---
Changes v1 -> v2:
- Added a better explination for why the legal directory is necessary.package/openjdk/openjdk.mk | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
Built and runtime tested on x86-64 platform.
Thanks,
-Ryan
---
Ryan Barnett | Sr Systems Engineer | Commercial Avionics COLLINS AEROSPACE
400 Collins Rd NE, Cedar Rapids, IA 52498 USA ryan.barnett at collins.com | collinsaerospace.com
CONFIDENTIALITY WARNING: This message may contain proprietary and/or privileged information of Collins Aerospace and its affiliated companies. If you are not the intended recipient, please 1) Do not disclose, copy, distribute or use this message or its contents. 2) Advise the sender by return email. 3) Delete all copies (including all attachments) from your computer. Your cooperation is greatly appreciated.
PATCH v2 2/3 package/openjdk: copy all directories and files when installing
In reply to aduskett at gmail.comQuoted 17 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"aduskett" == aduskett <[email protected]> writes:
From: Adam Duskett <[email protected]>
Several directories and files are currently not installed during the target installation, these include:
- conf
Several configuration files, including security configuration files which may be necessary for running various java applications.- legal
This directory contains legal notices that some java applications may require, as they may print legal information and will throw exceptions at runtime if the legal files are not present on the system.- release
This file contains a list of modules included in the image.
Quoted 7 lines
Because these directories take up less than of megabyte extra, it is not an issue to install all of them.
Signed-off-by Adam Duskett <[email protected]>---
Changes v1 -> v2:
- Added a better explination for why the legal directory is necessary.
Committed to 2020.02.x, thanks.
Signature · 1 line
Bye, Peter Korsgaard
PATCH v2 3/3 packageJopenjdk: add support for building the full jdk
In reply to aduskett at gmail.comFrom: Adam Duskett <[email protected]>
Some users may require the full JDK on the target to debug their programs. This change is relatively trivial to add.
While the full JDK does have programs used for compiling on a target, which is against Buildroot policy, the JDK also has several utilities used for debugging purposes, which the JRE target does not build, and Buildroot supports applications used for debugging purposes such as GDB.
As such, JDK support should be available for debugging purposes, and a note in the Config.in file has been added under the JDK section, which informs the user that JDK support is for debugging purposes only and that developing on a target is not supported by Buildroot.
---
Changes v1 -> v2:
- Added a much more thurough commit message as to why the JDK may be useful.
- Added a note in the Config.in file explaining that full JDK support is only for debugging purposes.
- Added a target_finalize_hook which removes the include and demo directory from the target.
package/openjdk/Config.in | 54 ++++++++++++++++++++++++++++++++++++++ package/openjdk/openjdk.mk | 21 +++++++++++++-- 2 files changed, 73 insertions(+), 2 deletions(-)
package/openjdk/Config.in +54 -0
@@ -49,6 +49,60 @@ config BR2_PACKAGE_OPENJDK if BR2_PACKAGE_OPENJDK +config BR2_PACKAGE_OPENJDK_FULL_JDK + bool "Build the full JDK" + help + Install the full JDK instead of just the run time. + The full JDK includes several packages used for debugging and + development. Some useful tools included with the JDK are: + - javaws + Command line tool for launching Java Web Start and setting + various options. + + - jcmd: + JVM Diagnostic Commands tool: Sends diagnostic command + requests to a running Java Virtual Machine. + + - jinfo + Configuration Info for Java: Prints configuration + information for a given process or core file or a remote + debug server. + + - jmap + Memory Map for Java: Prints shared object memory maps or + heap memory details of a given process or core file or a + remote debug server. + + - jsadebugd + Serviceability Agent Debug Daemon for Java: Attaches to a + process or core file and acts as a debug server. + + - jstack + Stack Trace for Java - Prints a stack trace of threads for + a given process or core file or remote debug server. + + - jstat + JVM Statistics Monitoring Tool: Attaches to an + instrumented HotSpot Java virtual machine and collects and + logs performance statistics as specified by the command + line options. + + - jstatd + JVM jstat Daemon - Launches an RMI server application that + monitors for the creation and termination of instrumented + HotSpot Java virtual machines and provides an interface to + allow remote monitoring tools to attach to Java virtual + machines running on the local system. + + Note: + While the JDK also comes with several tools which can be used + for developing java applications on a target, Buildroot + does not support development on a target. Building the + full JDK is supported for debugging purposes only. + + Selecting this option increases the file system by + approximately 110M. + choice prompt "openjdk variant" default BR2_PACKAGE_OPENJDK_JVM_VARIANT_SERVER if !BR2_powerpc
package/openjdk/openjdk.mk +19 -2
@@ -46,6 +46,14 @@ OPENJDK_JVM_VARIANT = zero OPENJDK_DEPENDENCIES += libffi endif +ifeq ($(BR2_PACKAGE_OPENJDK_FULL_JDK),y) +OPENJDK_INSTALL_DIR = jdk +OPENJDK_MAKE_TARGET=jdk-image +else +OPENJDK_INSTALL_DIR = jre +OPENJDK_MAKE_TARGET=legacy-jre-image +endif + # OpenJDK installs a file named 'modules' in jre/lib, which gets installed as # /usr/lib/modules. However, with a merged /usr, this conflicts with the # directory named 'modules' installed by the kernel. If OpenJDK gets built
@@ -116,16 +124,25 @@ endef # Make -jn is unsupported. Instead, set the "--with-jobs=" configure option, # and use $(MAKE1). define OPENJDK_BUILD_CMDS - $(TARGET_MAKE_ENV) $(MAKE1) -C $(@D) legacy-jre-image + $(TARGET_MAKE_ENV) $(OPENJDK_CONF_ENV) $(MAKE1) -C $(@D) $(OPENJDK_MAKE_TARGET) endef # Calling make install always builds and installs the JDK instead of the JRE, # which makes manual installation necessary. define OPENJDK_INSTALL_TARGET_CMDS mkdir -p $(TARGET_DIR)$(OPENJDK_INSTALL_BASE) - cp -dpfr $(@D)/build/linux-*-release/images/jre/* \ + cp -dpfr $(@D)/build/linux-*-release/images/$(OPENJDK_INSTALL_DIR)/* \ $(TARGET_DIR)$(OPENJDK_INSTALL_BASE)/ cd $(TARGET_DIR)/usr/bin && ln -snf ../..$(OPENJDK_INSTALL_BASE)/bin/* . endef +# Demos and includes are not needed on the target +ifeq ($(BR2_PACKAGE_OPENJDK_FULL_JDK),y) +define OPENJDK_REMOVE_UNEEDED_JDK_DIRECTORIES + $(RM) -r $(TARGET_DIR)$(OPENJDK_INSTALL_BASE)/include/ + $(RM) -r $(TARGET_DIR)$(OPENJDK_INSTALL_BASE)/demo/ +endef +OPENJDK_TARGET_FINALIZE_HOOKS += OPENJDK_REMOVE_UNEEDED_JDK_DIRECTORIES +endif + $(eval $(generic-package))
Signature · 1 line
2.25.2
PATCH v2 3/3 packageJopenjdk: add support for building the full jdk
Adam,
Thank you for posting this series of patches. Below is some minor feedback:
Title has a misspelling:
s:packageJopenjd:package/openjdk:
Quoted 16 lines · On Sat, Apr 18, 2020 at 2:12 PM <[email protected]> wrote:
From: Adam Duskett <[email protected]>
Some users may require the full JDK on the target to debug their programs. This change is relatively trivial to add.
While the full JDK does have programs used for compiling on a target, which is against Buildroot policy, the JDK also has several utilities used for debugging purposes, which the JRE target does not build, and Buildroot supports applications used for debugging purposes such as GDB.
As such, JDK support should be available for debugging purposes, and a note in the Config.in file has been added under the JDK section, which informs the user that JDK support is for debugging purposes only and that developing on a target is not supported by Buildroot.
Quoted 4 lines
Signed-off-by Adam Duskett <[email protected]>---
Changes v1 -> v2:
- Added a much more thurough commit message as to why the JDK may be useful.
s/thurough/through/
Quoted 8 lines
- Added a note in the Config.in file explaining that full JDK support is only for debugging purposes.
- Added atarget_finalize_hookwhich removes the include and demo directory from the target.package/openjdk/Config.in | 54 ++++++++++++++++++++++++++++++++++++++ package/openjdk/openjdk.mk | 21 +++++++++++++-- 2 files changed, 73 insertions(+), 2 deletions(-)
Built and runtime tested on x86-64 platform.
Thanks,
-Ryan
Yann E. MORIN
AppliedPATCH v2 3/3 packageJopenjdk: add support for building the full jdk
In reply to aduskett at gmail.comAdam, all,
On 2020-04-18 12:07 -0700, aduskett at gmail.com spake thusly:
Quoted 10 lines
From: Adam Duskett <[email protected]>
Some users may require the full JDK on the target to debug their programs. This change is relatively trivial to add.
While the full JDK does have programs used for compiling on a target, which is against Buildroot policy, the JDK also has several utilities used for debugging purposes, which the JRE target does not build, and Buildroot supports applications used for debugging purposes such as GDB.
Quoted 6 lines
As such, JDK support should be available for debugging purposes, and a note in the Config.in file has been added under the JDK section, which informs the user that JDK support is for debugging purposes only and that developing on a target is not supported by Buildroot.
Signed-off-by Adam Duskett <[email protected]>
Applied to master, with two minor changes, see below...
Quoted 60 lines
---
Changes v1 -> v2:
- Added a much more thurough commit message as to why the JDK may be useful.
- Added a note in the Config.in file explaining that full JDK support is only for debugging purposes.
- Added atarget_finalize_hookwhich removes the include and demo directory from the target.package/openjdk/Config.in | 54 ++++++++++++++++++++++++++++++++++++++ package/openjdk/openjdk.mk | 21 +++++++++++++-- 2 files changed, 73 insertions(+), 2 deletions(-)package/openjdk/Config.in +40
-0@@ -49,6 +49,60 @@ config BR2_PACKAGE_OPENJDK if BR2_PACKAGE_OPENJDK +config BR2_PACKAGE_OPENJDK_FULL_JDK + bool "Build the full JDK" + help + Install the full JDK instead of just the run time. + The full JDK includes several packages used for debugging and + development. Some useful tools included with the JDK are: + - javaws + Command line tool for launching Java Web Start and setting + various options. + + - jcmd: + JVM Diagnostic Commands tool: Sends diagnostic command + requests to a running Java Virtual Machine. + + - jinfo + Configuration Info for Java: Prints configuration + information for a given process or core file or a remote + debug server. + + - jmap + Memory Map for Java: Prints shared object memory maps or + heap memory details of a given process or core file or a + remote debug server. + + - jsadebugd + Serviceability Agent Debug Daemon for Java: Attaches to a + process or core file and acts as a debug server. + + - jstack + Stack Trace for Java - Prints a stack trace of threads for + a given process or core file or remote debug server. + + - jstat + JVM Statistics Monitoring Tool: Attaches to an + instrumented HotSpot Java virtual machine and collects and + logs performance statistics as specified by the command + line options. + + - jstatd + JVM jstat Daemon - Launches an RMI server application that
package/openjdk/Config.in config BR2_PACKAGE_OPENJDK · line 101
Quoted 10 lines
package/openjdk/Config.in +10
-0+ monitors for the creation and termination of instrumented + HotSpot Java virtual machines and provides an interface to + allow remote monitoring tools to attach to Java virtual + machines running on the local system. + + Note: + While the JDK also comes with several tools which can be used + for developing java applications on a target, Buildroot + does not support development on a target. Building the + full JDK is supported for debugging purposes only.
I've rewrapped that section so that it uses the full-width on all lines.
Quoted 11 lines
package/openjdk/Config.in +3
-0+ Selecting this option increases the file system by + approximately 110M. + choice prompt "openjdk variant" default BR2_PACKAGE_OPENJDK_JVM_VARIANT_SERVER if !BR2_powerpcpackage/openjdk/openjdk.mk +0
-0
package/openjdk/openjdk.mk OPENJDK_JVM_VARIANT = zero · line 55
Quoted 10 lines
package/openjdk/openjdk.mk +7
-0@@ -46,6 +46,14 @@ OPENJDK_JVM_VARIANT = zero OPENJDK_DEPENDENCIES += libffi endif +ifeq ($(BR2_PACKAGE_OPENJDK_FULL_JDK),y) +OPENJDK_INSTALL_DIR = jdk +OPENJDK_MAKE_TARGET=jdk-image +else +OPENJDK_INSTALL_DIR = jre +OPENJDK_MAKE_TARGET=legacy-jre-image +endif
I've changed OPENJDK_INSTALL_DIR to OPENJDK_VARIANT, because"
- the former sounded too generic
- the former looked like it was the directory it was installed into
- it risked too much collision with similarly-named _DIR variables from the infra
Pushed to master now, thanks! :-)
Regards,
Yann E. MORIN.
Quoted 38 lines
package/openjdk/openjdk.mk +11
-2# OpenJDK installs a file named 'modules' in jre/lib, which gets installed as # /usr/lib/modules. However, with a merged /usr, this conflicts with the # directory named 'modules' installed by the kernel. If OpenJDK gets built@@ -116,16 +124,25 @@ endef # Make -jn is unsupported. Instead, set the "--with-jobs=" configure option, # and use $(MAKE1). define OPENJDK_BUILD_CMDS - $(TARGET_MAKE_ENV) $(MAKE1) -C $(@D) legacy-jre-image + $(TARGET_MAKE_ENV) $(OPENJDK_CONF_ENV) $(MAKE1) -C $(@D) $(OPENJDK_MAKE_TARGET) endef # Calling make install always builds and installs the JDK instead of the JRE, # which makes manual installation necessary. define OPENJDK_INSTALL_TARGET_CMDS mkdir -p $(TARGET_DIR)$(OPENJDK_INSTALL_BASE) - cp -dpfr $(@D)/build/linux-*-release/images/jre/* \ + cp -dpfr $(@D)/build/linux-*-release/images/$(OPENJDK_INSTALL_DIR)/* \ $(TARGET_DIR)$(OPENJDK_INSTALL_BASE)/ cd $(TARGET_DIR)/usr/bin && ln -snf ../..$(OPENJDK_INSTALL_BASE)/bin/* . endef +# Demos and includes are not needed on the target +ifeq ($(BR2_PACKAGE_OPENJDK_FULL_JDK),y) +define OPENJDK_REMOVE_UNEEDED_JDK_DIRECTORIES + $(RM) -r $(TARGET_DIR)$(OPENJDK_INSTALL_BASE)/include/ + $(RM) -r $(TARGET_DIR)$(OPENJDK_INSTALL_BASE)/demo/ +endef +OPENJDK_TARGET_FINALIZE_HOOKS += OPENJDK_REMOVE_UNEEDED_JDK_DIRECTORIES +endif + $(eval $(generic-package))Signature · 6 lines
2.25.2 _______________________________________________ buildroot mailing list buildroot at busybox.net http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
PATCH v2 1/3 package/openjdk: fix installation with merged usr directories
In reply to aduskett at gmail.comAdam/All,
Quoted 67 lines · On Sat, Apr 18, 2020 at 2:12 PM <[email protected]> wrote:
From: Adam Duskett <[email protected]>
Currently, Buildroot installs the jre libraries using
cp -dprf /build/linux-*-release/images/jre/lib/* $(TARGET_DIR)/usr/lib/However, if a system has a merged /usr directory, and there is a built kernel before installing OpenJDK, the installation fails because jre/lib has binary modules file, which causes the following error: cp: cannot overwrite directory '
/usr/lib/moduleswith non-directoryThe obvious fix is to install the modules to
/usr/lib/jvm/and set the appropriate rpaths via the --with-extra-ldflags conf option. However, this fix does not work because the built binaries themselves do not link against libjava.soIndeed, running readelf on the built java binary reports the following:
"(RUNPATH) Library runpath: [/usr/lib/jvm]" and/usr/lib/jvm/libjava.soexists. However, when running the Java binary on the target, the following error
occurs: "Error: could not find libjava.so."The following is the result of "strace java" ran on the target:
faccessat(AT_FDCWD, "/usr/lib/libjava.so", F_OK)= -1 ENOENTfaccessat(AT_FDCWD, "/usr/jre/lib/libjava.so", F_OK)= -1 ENOENTnewfstatat(AT_FDCWD, "/usr/lib/libjava.so", 0x7ffe7b4af8, 0)= -1 ENOENTnewfstatat(AT_FDCWD, "/usr/lib/jvm/libjli.so", [sic] AT_SYMLINK_NOFOLLOW)= 0As seen above, the java binary searches for libjli.so in
/usr/lib/jvm, but libjava.so has the search paths hardcoded to the following directories:
-/usr/lib/
-/usr/jre/lib/
- $(dirname $0)/../lib/The reason behind the hardcoded paths given by the maintainers is due to historical purposes for the need to support several java versions at the same time on a single system, and that changing the above behavior is not likely to ever happen.
As such, most distributions such as Redhat do the following:
- Create the directory /usr/lib/jvm/java-$(JAVA_VERSION)/
- Install all directories and files found in images/jre to that directory.
- Symlink the binaries to in /usr/lib/jvm/java-$(JAVA_VERSION)/bin to/usr/bin.However, because Buildroot does not need to support multiple versions of java concurrently, there is no need for the additional java-$(JAVA_VERSION) directory.
To fix the above issue, the following changes are performed:
- Introduce the variable "OPENJDK_INSTALL_BASE" which points to/usr/lib/jvm
- Set the --with-extra-ldflagsconf_optto"-Wl,-rpath,$(OPENJDK_INSTALL_BASE)/lib,-rpath, $(OPENJDK_INSTALL_BASE)/lib/$(OPENJDK_JVM_VARIANT)"- Run "mkdir -p $(TARGET_DIR)/usr/lib/jvm/" in the
INSTALL_TARGET_CMDSstep.
- Copy both the lib and bin directories to/usr/lib/jvm/
- Symlink the binaries in/usr/lib/jvm/bin/to/usr/bin.Signed-off-by Adam Duskett <[email protected]>---
Changes v1 -> v2:
- Fixed comments in openjdk.mk (Yann)
- Added spaces around the = sign forOPENJDK_INSTALL_BASE(Yann)
- Added trailing /'s for copying (Yann)
- Added a more complete commit message.
Quoted 2 lines
package/openjdk/openjdk.mk | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
Built and runtime tested on x86-64 platform.
Thanks,
-Ryan
---
Ryan Barnett | Sr Systems Engineer | Commercial Avionics COLLINS AEROSPACE
400 Collins Rd NE, Cedar Rapids, IA 52498 USA ryan.barnett at collins.com | collinsaerospace.com
CONFIDENTIALITY WARNING: This message may contain proprietary and/or privileged information of Collins Aerospace and its affiliated companies. If you are not the intended recipient, please 1) Do not disclose, copy, distribute or use this message or its contents. 2) Advise the sender by return email. 3) Delete all copies (including all attachments) from your computer. Your cooperation is greatly appreciated.
PATCH v2 1/3 package/openjdk: fix installation with merged usr directories
In reply to aduskett at gmail.comAdam, All,
On 2020-04-18 12:06 -0700, aduskett at gmail.com spake thusly:
Quoted 9 lines
From: Adam Duskett <[email protected]>
Currently, Buildroot installs the jre libraries using
cp -dprf /build/linux-*-release/images/jre/lib/* $(TARGET_DIR)/usr/lib/However, if a system has a merged /usr directory, and there is a built kernel before installing OpenJDK, the installation fails because jre/lib has binary modules file, which causes the following error: cp: cannot overwrite directory '
/usr/lib/moduleswith non-directory
Patch applied to master, after extending a bit one of the explanations as discussed on IRC. Thanks! :-)
Regards,
Yann E. MORIN.
Quoted 107 lines
The obvious fix is to install the modules to
/usr/lib/jvm/and set the appropriate rpaths via the --with-extra-ldflags conf option. However, this fix does not work because the built binaries themselves do not link against libjava.soIndeed, running readelf on the built java binary reports the following:
"(RUNPATH) Library runpath: [/usr/lib/jvm]" and/usr/lib/jvm/libjava.soexists. However, when running the Java binary on the target, the following error
occurs: "Error: could not find libjava.so."The following is the result of "strace java" ran on the target:
faccessat(AT_FDCWD, "/usr/lib/libjava.so", F_OK)= -1 ENOENTfaccessat(AT_FDCWD, "/usr/jre/lib/libjava.so", F_OK)= -1 ENOENTnewfstatat(AT_FDCWD, "/usr/lib/libjava.so", 0x7ffe7b4af8, 0)= -1 ENOENTnewfstatat(AT_FDCWD, "/usr/lib/jvm/libjli.so", [sic] AT_SYMLINK_NOFOLLOW)= 0As seen above, the java binary searches for libjli.so in
/usr/lib/jvm, but libjava.so has the search paths hardcoded to the following directories:
-/usr/lib/
-/usr/jre/lib/
- $(dirname $0)/../lib/The reason behind the hardcoded paths given by the maintainers is due to historical purposes for the need to support several java versions at the same time on a single system, and that changing the above behavior is not likely to ever happen.
As such, most distributions such as Redhat do the following:
- Create the directory /usr/lib/jvm/java-$(JAVA_VERSION)/
- Install all directories and files found in images/jre to that directory.
- Symlink the binaries to in /usr/lib/jvm/java-$(JAVA_VERSION)/bin to/usr/bin.However, because Buildroot does not need to support multiple versions of java concurrently, there is no need for the additional java-$(JAVA_VERSION) directory.
To fix the above issue, the following changes are performed:
- Introduce the variable "OPENJDK_INSTALL_BASE" which points to/usr/lib/jvm
- Set the --with-extra-ldflagsconf_optto"-Wl,-rpath,$(OPENJDK_INSTALL_BASE)/lib,-rpath, $(OPENJDK_INSTALL_BASE)/lib/$(OPENJDK_JVM_VARIANT)"- Run "mkdir -p $(TARGET_DIR)/usr/lib/jvm/" in the
INSTALL_TARGET_CMDSstep.
- Copy both the lib and bin directories to/usr/lib/jvm/
- Symlink the binaries in/usr/lib/jvm/bin/to/usr/bin.Signed-off-by Adam Duskett <[email protected]>---
Changes v1 -> v2:
- Fixed comments in openjdk.mk (Yann)
- Added spaces around the = sign forOPENJDK_INSTALL_BASE(Yann)
- Added trailing /'s for copying (Yann)
- Added a more complete commit message.package/openjdk/openjdk.mk | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)package/openjdk/openjdk.mk +14
-2@@ -46,6 +46,13 @@ OPENJDK_JVM_VARIANT = zero OPENJDK_DEPENDENCIES += libffi endif +# OpenJDK installs a file named 'modules' in jre/lib, which gets installed as +# /usr/lib/modules. However, with a merged /usr, this conflicts with the +# directory named 'modules' installed by the kernel. If OpenJDK gets built +# after the kernel, this manifests itself with: "cp: cannot overwrite +# directory '/usr/lib/modules with non-directory." +OPENJDK_INSTALL_BASE = /usr/lib/jvm + # OpenJDK ignores some variables unless passed via the environment. # These variables are PATH, LD, CC, CXX, and CPP. # OpenJDK defaults ld to the ld binary but passes -Xlinker and -z as@@ -75,6 +82,7 @@ OPENJDK_CONF_OPTS = \ --with-devkit=$(HOST_DIR) \ --with-extra-cflags="$(TARGET_CFLAGS)" \ --with-extra-cxxflags="$(TARGET_CXXFLAGS)" \ + --with-extra-ldflags="-Wl,-rpath,$(OPENJDK_INSTALL_BASE)/lib,-rpath,$(OPENJDK_INSTALL_BASE)/lib/$(OPENJDK_JVM_VARIANT)" \ --with-giflib=system \ --with-jobs=$(PARALLEL_JOBS) \ --with-jvm-variants=$(OPENJDK_JVM_VARIANT) \@@ -114,8 +122,12 @@ endef # Calling make install always builds and installs the JDK instead of the JRE, # which makes manual installation necessary. define OPENJDK_INSTALL_TARGET_CMDS - cp -dpfr $(@D)/build/linux-*-release/images/jre/bin/* $(TARGET_DIR)/usr/bin/ - cp -dpfr $(@D)/build/linux-*-release/images/jre/lib/* $(TARGET_DIR)/usr/lib/ + mkdir -p $(TARGET_DIR)$(OPENJDK_INSTALL_BASE) + cp -dpfr $(@D)/build/linux-*-release/images/jre/bin/ \ + $(TARGET_DIR)$(OPENJDK_INSTALL_BASE) + cp -dpfr $(@D)/build/linux-*-release/images/jre/lib/ \ + $(TARGET_DIR)/$(OPENJDK_INSTALL_BASE)/ + cd $(TARGET_DIR)/usr/bin && ln -snf ../..$(OPENJDK_INSTALL_BASE)/bin/* . endef $(eval $(generic-package))Signature · 6 lines
2.25.2 _______________________________________________ buildroot mailing list buildroot at busybox.net http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'