Windows 10 + WSL(ubuntu 20.04) + CLion 编译JDK12

1. 编译JDK

参考:

《深入理解Java虚拟机(第三版)》

ubuntu20.04.2环境下openjdk12源码编译相关问题

Tips & Tricks: Develop OpenJDK in CLion with Pleasure

平台及工具:
Windows 10 + WSL(ubuntu 20.04) + CLion

1.1 编译问题

根据《深入理解Java虚拟机(第三版)》的步骤下载JDK源码以及安装各种编译工具,然后需要执行

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 ===

原因是gcc高版本会默认把warning当作error来处理,这样导致编译无法通过,解决方法是修改执行为

bash configure --disable-warnings-as-errors --enable-debug --with-jvm-variants=server

在执行make images之前记得执行make cleanmake dist-clean清除build文件

1.2 CLion配置问题

如果我们需要使用CLion来Debug或者编译修改后的JDK,可以按照Tips & Tricks: Develop OpenJDK in CLion with Pleasure来操作,但是在Step 3: Generate Run Configurations and Build Targets这一步会有所不同,因为示例使用的是MacOS,而WSL有所不同

Windows 10 + WSL(ubuntu 20.04) + CLion 编译JDK12_第1张图片
Windows 10 + WSL(ubuntu 20.04) + CLion 编译JDK12_第2张图片

  • Program:表示需要使用Windows上某个程序,显然这里如果填make则使用的是Windows下的make,而不是WSL中的make,所以这里需要填wsl
  • Arguments:表示Program后跟着的参数,而在Windows命令行工具中是可以通过wsl make来调用WSL中的程序的,所以参数部分填make即可;
  • CONF:这里没有使用CONF参数,因为之前我们在bash configure时已经指定了编译--enable-debug,所以这里不需要重复指定,默认会编译linux-x86_64-server-fastdebug

1.3 CLion断点调试问题

一般我们的WSL工具里使用的是GDB调试,所以在断点调试时会遇到sigsegv segmentation fault问题,需要配置GDB忽略项,编辑文件~/.gdbinit

handle SIGSEGV nostop noprint pass
handle SIGBUS nostop noprint pass
handle SIGFPE nostop noprint pass
handle SIGPIPE nostop noprint pass
handle SIGILL nostop noprint pass

你可能感兴趣的:(笔记,java,jdk,wsl,CLion)