Fail to build due to compile flag -Wcast-align
LithiumTins opened this issue · 1 comments
LithiumTins commented
I tried to build p2pool on RISCV64 ArchLinux
but failed. The errors are like:
/build/p2pool/src/p2pool/src/common.h: In member function ‘bool p2pool::raw_ip::operator==(const p2pool::raw_ip&) const’:
/build/p2pool/src/p2pool/src/common.h:443:37: error: cast from ‘const uint8_t*’ {aka ‘const unsigned char*’} to ‘const uint64_t*’ {aka ‘const long unsigned int*’} increases required alignment of target type [-Werror=cast-align]
443 | const uint64_t* a = reinterpret_cast<const uint64_t*>(data);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
It seems the warning is caused by cast from uint8_t*
to uint64_t*
increases the alignment, and with -Wcast-align
and -Werror
the compilation is terminated.
I've carefully looked into this problem and found that:
- The compiler doesn't give out warnings on
x86_64
no matter whether the alignment is increased and is well treated. However, it gives out warnings onRISCV64
when the alignment is increased even when the operand has been aligned as target type. For example, in the following codedata
is well-aligned and the warning above is still caused(the line number doesn't match):
Lines 426 to 439 in 5988acb
- I manually check every line that causes warning like this and almost all of them are well-aligned. There are some exceptions using function
read_unaligned()
insrc\util.h
, but I think it's ok because they do intend touse the pointer as an unaligned one. Here is one example:
Lines 1600 to 1604 in 5988acb
Due to the reasons above, the compile flag -Wcast-align
actually help nothing because the project indeed use casts that increase the alignment , while it does stop p2pool to build on RISCV64. Thus I suggest remove this compile flag.