|
@@ -0,0 +1,140 @@
|
|
|
+>[TOC]
|
|
|
+
|
|
|
+# 编译JVM遇见的问题
|
|
|
+
|
|
|
+环境:ubuntu20.04TSL
|
|
|
+
|
|
|
+## 1、安装gcc
|
|
|
+
|
|
|
+```shell
|
|
|
+sudo apt-get install build-essential
|
|
|
+```
|
|
|
+
|
|
|
+## 2、接着安装以下依赖库:
|
|
|
+
|
|
|
+| 命令 | 工具 |
|
|
|
+| ------------------------------------------------------------ | ---------- |
|
|
|
+| sudo apt-get install libfreetype6-dev | FreeType |
|
|
|
+| sudo apt-get install libcups2-dev | CUPS |
|
|
|
+| sudo apt-get install libx11-dev libxext-dev libxrender-dev libxrandr-dev libxtst-dev libxt-dev | X11 |
|
|
|
+| sudo apt-get install libasound2-dev | ALSA |
|
|
|
+| sudo apt-get install libffi-dev | libffi |
|
|
|
+| sudo apt-get install autoconf | Autoconf |
|
|
|
+| sudo apt-get install libfontconfig1-dev | fontconfig |
|
|
|
+
|
|
|
+## 3、安装JDK11
|
|
|
+
|
|
|
+由于openjdk很多部分由java实现的,假设需要编译的版本为N,需要装一个版本号大于等于N-1的jdk,我们需要编译openjdk12,所以需要装JDK11及之后的版本,命令如下:
|
|
|
+
|
|
|
+```shell
|
|
|
+sudo apt-get install openjdk-11-jdk
|
|
|
+```
|
|
|
+
|
|
|
+## 4、编译
|
|
|
+
|
|
|
+```shell
|
|
|
+# 1.检查编译环境
|
|
|
+bash configure --enable-debug --with-jvm-variants=server
|
|
|
+# 2.显示如下代码
|
|
|
+
|
|
|
+A new configuration has been successfully created in
|
|
|
+/home/xiang/win_d/java/jdk12-06222165c35f/build/linux-x86_64-server-fastdebug
|
|
|
+using configure arguments '--enable-debug --with-jvm-variants=server'.
|
|
|
+
|
|
|
+Configuration summary:
|
|
|
+* Debug level: fastdebug
|
|
|
+* HS debug level: fastdebug
|
|
|
+* JVM variants: server
|
|
|
+* JVM features: server: 'aot cds cmsgc compiler1 compiler2 epsilongc g1gc graal jfr jni-check jvmci jvmti management nmt parallelgc serialgc services shenandoahgc vm-structs zgc'
|
|
|
+* OpenJDK target: OS: linux, CPU architecture: x86, address length: 64
|
|
|
+* Version string: 12-internal+0-adhoc.xiang.jdk12-06222165c35f (12-internal)
|
|
|
+
|
|
|
+Tools summary:
|
|
|
+* Boot JDK: openjdk version "11.0.7" 2020-04-14 OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1) OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing) (at /usr/lib/jvm/java-11-openjdk-amd64)
|
|
|
+* Toolchain: gcc (GNU Compiler Collection)
|
|
|
+* C Compiler: Version 9.3.0 (at /usr/bin/gcc)
|
|
|
+* C++ Compiler: Version 9.3.0 (at /usr/bin/g++)
|
|
|
+
|
|
|
+Build performance summary:
|
|
|
+* Cores to use: 4
|
|
|
+* Memory limit: 7858 MB
|
|
|
+
|
|
|
+# 3.接着执行
|
|
|
+make images
|
|
|
+
|
|
|
+# 4.报错
|
|
|
+ERROR: Build failed for target 'images' in configuration 'linux-x86_64-server-fastdebug' (exit code 2)
|
|
|
+Stopping sjavac server
|
|
|
+
|
|
|
+=== Output from failing command(s) repeated here ===
|
|
|
+* For target hotspot_variant-server_libjvm_objs_arguments.o:
|
|
|
+In file included from /usr/include/string.h:495,
|
|
|
+ from /home/xiang/win_d/java/jdk12-06222165c35f/src/hotspot/share/utilities/globalDefinitions_gcc.hpp:35,
|
|
|
+ from /home/xiang/win_d/java/jdk12-06222165c35f/src/hotspot/share/utilities/globalDefinitions.hpp:32,
|
|
|
+ from /home/xiang/win_d/java/jdk12-06222165c35f/src/hotspot/share/utilities/align.hpp:28,
|
|
|
+ from /home/xiang/win_d/java/jdk12-06222165c35f/src/hotspot/share/runtime/globals.hpp:29,
|
|
|
+ from /home/xiang/win_d/java/jdk12-06222165c35f/src/hotspot/share/memory/allocation.hpp:28,
|
|
|
+ from /home/xiang/win_d/java/jdk12-06222165c35f/src/hotspot/share/classfile/classLoaderData.hpp:28,
|
|
|
+ from /home/xiang/win_d/java/jdk12-06222165c35f/src/hotspot/share/precompiled/precompiled.hpp:34:
|
|
|
+In function ‘char* strncpy(char*, const char*, size_t)’,
|
|
|
+ inlined from ‘static jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs*, bool*, JVMFlag::Flags)’ at /home/xiang/win_d/java/jdk12-06222165c35f/src/hotspot/share/runtime/arguments.cpp:2472:29:
|
|
|
+/usr/include/x86_64-linux-gnu/bits/string_fortified.h:106:34: error: ‘char* __builtin_strncpy(char*, const char*, long unsigned int)’ output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
|
|
|
+ 106 | return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
|
|
|
+ ... (rest of output omitted)
|
|
|
+
|
|
|
+* All command lines available in /home/xiang/win_d/java/jdk12-06222165c35f/build/linux-x86_64-server-fastdebug/make-support/failure-logs.
|
|
|
+=== End of repeated output ===
|
|
|
+
|
|
|
+No indication of failed target found.
|
|
|
+Hint: Try searching the build log for '] Error'.
|
|
|
+Hint: See doc/building.html#troubleshooting for assistance.
|
|
|
+
|
|
|
+```
|
|
|
+
|
|
|
+## 5、解决问题
|
|
|
+
|
|
|
+1. gcc和g++版本过高,需要更换版本
|
|
|
+
|
|
|
+```shell
|
|
|
+# 1.安装gcc7
|
|
|
+sudo apt-get install gcc-7 gcc-7-multilib g++-7 g++-7-multilib
|
|
|
+
|
|
|
+# 2.查看gcc和g++分别有那些软件:
|
|
|
+ll /usr/bin/gcc*
|
|
|
+ll /usr/bin/g++*
|
|
|
+
|
|
|
+# 3.最后将/usr/bin下面以下文件通过软连接重新指向版本7
|
|
|
+/usr/bin/gcc
|
|
|
+/usr/bin/gcc-ar
|
|
|
+/usr/bin/gcc-nm
|
|
|
+/usr/bin/gcc-ranlib
|
|
|
+/usr/bin/g++
|
|
|
+```
|
|
|
+
|
|
|
+2. 执行shell脚本
|
|
|
+
|
|
|
+```shell
|
|
|
+
|
|
|
+COMMAND=(/usr/bin/gcc /usr/bin/gcc-ar /usr/bin/gcc-nm /usr/bin/gcc-ranlib /usr/bin/g++)
|
|
|
+
|
|
|
+for command in "${COMMAND[@]}"
|
|
|
+do
|
|
|
+ rm $command
|
|
|
+ ln -s "$command"-7 $command
|
|
|
+done
|
|
|
+
|
|
|
+```
|
|
|
+
|
|
|
+3. 重新编译
|
|
|
+
|
|
|
+```shell
|
|
|
+make clean
|
|
|
+make dist-clean
|
|
|
+
|
|
|
+bash configure --enable-debug --with-jvm-variants=server
|
|
|
+make images
|
|
|
+```
|
|
|
+
|
|
|
+输出一下内容编译成功
|
|
|
+
|
|
|
+
|