Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

编译过程中的warning整理 #164

Closed
DingliZhang opened this issue Aug 9, 2021 · 7 comments
Closed

编译过程中的warning整理 #164

DingliZhang opened this issue Aug 9, 2021 · 7 comments

Comments

@DingliZhang
Copy link

DingliZhang commented Aug 9, 2021

编译的原始记录:make.log
pastebin:https://paste.ubuntu.com/p/HcKj6wx9rp/

@DingliZhang
Copy link
Author

主要warning分类:

comparison of unsigned expression in 'xxx' is always true [-Wtype-limits]

src/hotspot/share/jfr/utilities/jfrHashtable.hpp:86:14: warning: comparison of unsigned expression in '>= 0' is always true [-Wtype-limits]
   86 |     assert(h >= 0 && h < _table_size, "Illegal hash value");
      |            ~~^~~~
src/hotspot/share/jfr/utilities/jfrDoublyLinkedList.hpp:138:17: warning: comparison of unsigned expression in '>= 0' is always true [-Wtype-limits]
  138 |   assert(_count >= 0, "invariant");

#warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time" [-Wcpp]

src/hotspot/os/linux/os_linux.cpp:1356:6: warning: #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time" [-Wcpp]
 1356 |     #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
      |      ^~~~~~~

no return statement in function returning non-void [-Wreturn-type]

src/hotspot/os_cpu/linux_riscv32/atomic_linux_riscv32.hpp:115:76: warning: no return statement in function returning non-void [-Wreturn-type]
  115 | inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const {}
      |                                                                            ^

cast between incompatible function types from 'xxx' to 'xxx' [-Wcast-function-type]

src/java.base/unix/native/libjli/java_md_solinux.c:748:37: warning: cast between incompatible function types from 'int (*)(void *)' to 'void * (*)(void *)' [-Wcast-function-type]
  748 |     if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) {
      | 

'xxx' clearing an object of non-trivial type 'xxx'; use assignment or value-initialization instead [-Wclass-memaccess]

src/java.desktop/share/native/libfontmanager/harfbuzz/hb-aat-map.hh:41:36: warning: 'void* memset(void*, int, size_t)' clearing an object of non-trivial type 'struct hb_aat_map_t'; use assignment or value-initialization instead [-Wclass-memaccess]
   41 |     memset (this, 0, sizeof (*this));
      |                            

'xxx' writing to an object of type 'xxx' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]

src/java.desktop/share/native/libfontmanager/harfbuzz/hb-null.hh:160:10: warning: 'void* memcpy(void*, const void*, size_t)' writing to an object of type 'struct CFF::byte_str_t' with no trivial copy-assignment; use copy-assignment or copy-initialization instead [-Wclass-memaccess]
  160 |   memcpy (obj, &Null(Type), sizeof (*obj));
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

'xxx' moving an object of non-trivially copyable type 'xxx'; use 'new' and 'delete' instead [-Wclass-memaccess]

src/java.desktop/share/native/libfontmanager/harfbuzz/hb-vector.hh:164:36: warning: 'void* realloc(void*, size_t)' moving an object of non-trivially copyable type 'struct CFF::cff1_private_dict_values_base_t<CFF::op_str_t>'; use 'new' and 'delete' instead [-Wclass-memaccess]
  164 |       new_array = (Type *) realloc (arrayZ_, new_allocated * sizeof (Type));
      |                            ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@DingliZhang
Copy link
Author

DingliZhang commented Aug 9, 2021

[-Wtype-limits]

上述示例中的变量hcount数据类型都为size_t,则hcount为无符号整型,恒大于零。
ps: 这里是GCC10+中才会出现的,之前构建的时候有用的GCC9.2,所以没有出现此warning。
已提交PR #165 ,编译过程中相关warning已不再出现,jdk运行结果没有变化,请 @shining1984 review并验证。

@shining1984
Copy link

shining1984 commented Aug 9, 2021

我在本地验证的Log,似乎比 @DingliZhang 整理出来的还要多一些Log,先保存一份,后续可以用来更新warning列表。

http://paste.ubuntu.com/p/cbRCfm8fpq/

@DingliZhang
Copy link
Author

DingliZhang commented Aug 10, 2021

[-Wclass-memaccess]

这类主要是 GCC 8+版本会在使用memcpy/memcpy 等操作类指针 ( -Wclass-memaccess)弹出warning,可以通过将目标指针强制转换为void*来避免警告。
已提交PR #166 ,编译过程中相关warning已不再出现,jdk运行结果没有变化

@axiangyushanhaijing
Copy link

axiangyushanhaijing commented Aug 10, 2021

关于“src/hotspot/os/linux/os_linux.cpp:1356:6: warning: #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time" [-Wcpp]
1356 | #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
| ^~~~~~~
”告警处理:
在毕昇jdk中加log
image

发现最后的编译过程中,都没有出现“#warning”的相关打印,意味着“SYS_clock_getres”是被定义的。
而在rv32的开发分支中,出现了 #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"的相关打印,产生了矛盾。
尚未解决。


关于“src/hotspot/os_cpu/linux_riscv32/atomic_linux_riscv32.hpp:115:76: warning: no return statement in function returning non-void [-Wreturn-type]
115 | inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const {}
| ^
”的告警处理:
了解到该指令暂时还未写,所以处理它的意义暂时不大,可以暂时不用考虑修改。


8.12更新关于“src/hotspot/os_cpu/linux_riscv32/atomic_linux_riscv32.hpp:115:76: warning: no return statement in function returning non-void [-Wreturn-type]
115 | inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const {}
| ^
”的告警处理:

注释掉两个空模板以及对应函数的指针大小比较的判断即可消除warning
图1

图2
由于毕昇jdk的处理流程是没有图1的两个模板,但是保留了图2的判断,再结合 #117的分析,arm等是保留图1的模板的
@DingliZhang 沟通得出结论:是由于rv32与rv64指针长度不同,导致在图2处出错.

进一步分析:需要证明,在rv32的平台wide atomics need specialization是否需要保留,查阅了rv32的资料,目前没有发现相关的介绍,需要继续跟进。


在调用告警产生处新加warning
image
发现报错之前并不会打印出来
image

所以可以暂时消除这个告警,不会影响调试进程。

已提交#170,编译过程中相关warning已不再出现,jdk运行结果没有变化

@DingliZhang
Copy link
Author

DingliZhang commented Aug 11, 2021

[-Wcast-function-type]

解决的时候参考了 openjdk@3870110
已提交PR #167,编译过程中相关warning已不再出现,jdk运行结果没有变化。

2021/08/12更新

已提交PR #168,更新了src/java.base/unix/native/libjli/java_md_solinux.c,jdk运行结果没有变化。

@DingliZhang
Copy link
Author

DingliZhang commented Aug 12, 2021

[-Wcpp]

#ifndef SYS_clock_getres
  #if defined(X86) || defined(PPC64) || defined(S390)
    #define SYS_clock_getres AMD64_ONLY(229) IA32_ONLY(266) PPC64_ONLY(247) S390_ONLY(261)
    #define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
  #else
    #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
    #define sys_clock_getres(x,y)  -1
  #endif
#else

由源码可以看出,这里报出warning的原因是SYS_clock_getres未定义。
在kernel5.10版本中,宏的调用路径:syscall.h -> sys/syscall.h -> bits/syscall.h,asm/unistd.h -> asm-generic/unistd.h,而
SYS_clock_getres是在工具链riscv32/sysroot/usr/include/bits/syscall.h中定义的:

#ifdef __NR_clock_getres
# define SYS_clock_getres __NR_clock_getres
#endif

__NR_clock_getres是在工具链riscv32/sysroot/usr/include/asm-generic/unistd.h中定义的

#if defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32
#define __NR_clock_settime 112
__SC_3264(__NR_clock_settime, sys_clock_settime32, sys_clock_settime)
#define __NR_clock_gettime 113
__SC_3264(__NR_clock_gettime, sys_clock_gettime32, sys_clock_gettime)
#define __NR_clock_getres 114
__SC_3264(__NR_clock_getres, sys_clock_getres_time32, sys_clock_getres)
#define __NR_clock_nanosleep 115
__SC_3264(__NR_clock_nanosleep, sys_clock_nanosleep_time32, \
	  sys_clock_nanosleep)
#endif

Make time32 syscall numbers optional中,由于不希望新架构提供旧的 32 位基于 time_t 的系统调用或定义系统调用号宏,因此添加一个新的 __ARCH_WANT_TIME32_SYSCALLS宏,这个宏通常在linux/arch/<arch_name>/include/uapi/asm/unistd.h中定义,而linux/arch/riscv/include/uapi/asm/unistd.h中没有对这个宏做定义;
除此之外,对于riscv32来说,__BITS_PER_LONG会被拓展为4 * 8,因此defined(__ARCH_WANT_TIME32_SYSCALLS) || __BITS_PER_LONG != 32为false,导致warning出现。

目前工具链的kernel版本为5.10.5,而upstream的kernel在5.10.57版本中为riscv添加了__ARCH_WANT_TIME32_SYSCALLS宏:
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/arch/riscv/include/uapi/asm/unistd.h?h=v5.10.57&id=c8ce48f06503eee20f189eed5b2aa736272b7344

所以这里并不是JDK源码导致的的warning,可以暂时通过在工具链的riscv32/sysroot/usr/include/asm/unistd.h中添加#define __ARCH_WANT_TIME32_SYSCALLS来避免warning。
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants