ubuntu20.04.2环境下openjdk12源码编译相关问题Werror=stringop-truncation

ubuntu20.04.2环境下openjdk12源码编译相关问题Werror=stringop-truncation

按照《深入理解Java虚拟机:JVM高级特性与最佳实践(第3版)》的编译openjdk步骤指示,出现了一些问题,导致无法完成编译。

环境

Ubuntu 20.04.2 LTS

其余组件安装命令

sudo apt-get install build-essential

在这里插入图片描述

bootstrap jdk:
sudo apt-get install openjdk-11-jdk

编译前准备

configure命令
bash configure --enable-debug --with-jvm-variants=server
编译命令:
make images

报错信息

=== 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/hx/OpenJDK12/src/hotspot/share/utilities/globalDefinitions_gcc.hpp:35,
                 from /home/hx/OpenJDK12/src/hotspot/share/utilities/globalDefinitions.hpp:32,
                 from /home/hx/OpenJDK12/src/hotspot/share/utilities/align.hpp:28,
                 from /home/hx/OpenJDK12/src/hotspot/share/runtime/globals.hpp:29,
                 from /home/hx/OpenJDK12/src/hotspot/share/memory/allocation.hpp:28,
                 from /home/hx/OpenJDK12/src/hotspot/share/classfile/classLoaderData.hpp:28,
                 from /home/hx/OpenJDK12/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/hx/OpenJDK12/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/hx/OpenJDK12/build/linux-x86_64-server-fastdebug/make-support/failure-logs.
=== End of repeated output ===

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
直接百度,根据 https://segmentfault.com/a/1190000022669252的做法

引发错误的原因是这段[-Werror=stringop-truncation],GCC在8.0之后的版本加入了
stringop truncation的验证警告,这里是因为出现了警告导致编译不通过,那就禁止
掉警告再进行编译。

查看GCC版本,

gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)

果然如此

解决方案

configure命令增加参数–disable-warnings-as-errors,即变更为
bash configure --disable-warnings-as-errors --enable-debug --with-jvm-variants=server
然后进行make images,顺利完成编译。

P.S:按照书中的方法下载的openjdk12的zip格式的源码文件,大小不对且无法解压。
可用下载地址如下:
https://download.java.net/openjdk/jdk12/ri/openjdk-12+32_src.zip

  • 10
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值