charmplusplus / charm

The Charm++ parallel programming system. Visit https://charmplusplus.org/ for more information.
Apache License 2.0
199 stars 50 forks source link

Build fails with strict-aliasing violations #3789

Open eli-schwartz opened 3 months ago

eli-schwartz commented 3 months ago

I tried to compile with LTO: -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing

The -Werror=* flags are important to detect cases where the compiler can try to optimize based on assuming UB cannot happen, and miscompile code that has UB in it. strict-aliasing issues are always bad but LTO can make them even worse.

I got this error:

../bin/charmc  -build-shared  -I/usr/include/tirpc -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=incompatible-pointer-types -I.  -I/usr/include/tirpc  -c -o queueing.o queueing.C
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<built-in>: note: this is the location of the previous definition
cc1plus: warning: ‘-Werror=’ argument ‘-Werror=implicit-function-declaration’ is not valid for C++
cc1plus: warning: ‘-Werror=’ argument ‘-Werror=implicit-int’ is not valid for C++
cc1plus: warning: ‘-Werror=’ argument ‘-Werror=int-conversion’ is not valid for C++
cc1plus: warning: ‘-Werror=’ argument ‘-Werror=incompatible-pointer-types’ is not valid for C++
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<built-in>: note: this is the location of the previous definition
../bin/charmc  -build-shared  -I/usr/include/tirpc -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 -fstack-clash-protection -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=incompatible-pointer-types -I.  -I/usr/include/tirpc  -c -o msgmgr.o msgmgr.c
queueing.C: In function ‘void CqsEnqueueGeneral(Queue, void*, int, int, unsigned int*)’:
queueing.C:675:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  675 |       lprio =(((CmiUInt4 *)&lprio0)[0]*1LL)<<CINTBITS | ((CmiUInt4 *)&lprio0)[1];
      |               ~^~~~~~~~~~~~~~~~~~~~
queueing.C:690:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  690 |       lprio =(((CmiUInt4 *)&lprio0)[0]*1LL)<<CINTBITS | ((CmiUInt4 *)&lprio0)[1];
      |               ~^~~~~~~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors
Fatal Error by charmc in directory /var/tmp/portage/sys-cluster/charm-6.8.2/work/charm-v6.8.2/net-linux-amd64/tmp
   Command g++ -I../bin/../include -D__CHARMC__=1 -I/usr/include/tirpc -D_FORTIFY_SOURCE=3 -I. -I/usr/include/tirpc -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -U_FORTIFY_SOURCE -fstack-clash-protection -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wformat -Werror=format-security -Werror=implicit-function-declaration -Werror=implicit-int -Werror=int-conversion -Werror=incompatible-pointer-types -fno-stack-protector -fno-lifetime-dse -fPIC -c queueing.C -o queueing.o returned error code 1
charmc exiting...
<command-line>: warning: "_FORTIFY_SOURCE" redefined
<built-in>: note: this is the location of the previous definition
make: *** [<builtin>: queueing.o] Error 1
make: *** Waiting for unfinished jobs....

Downstream report: https://bugs.gentoo.org/863725 Full build log: build.log.txt

evan-charmworks commented 3 months ago

Thanks for the report. I agree these should be fixed.

Using the command ./buildold LIBS netlrts-linux-x86_64-smp -k -j4 -g3 -O2 -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing, I was able to get a longer list of strict-aliasing violations:

queueing.C: In function ‘void CqsEnqueueGeneral(Queue, void*, int, int, unsigned int*)’:
queueing.C:682:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  682 |       lprio =(((CmiUInt4 *)&lprio0)[0]*1LL)<<CINTBITS | ((CmiUInt4 *)&lprio0)[1];
      |               ~^~~~~~~~~~~~~~~~~~~~
queueing.C:697:16: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  697 |       lprio =(((CmiUInt4 *)&lprio0)[0]*1LL)<<CINTBITS | ((CmiUInt4 *)&lprio0)[1];
      |               ~^~~~~~~~~~~~~~~~~~~~
In file included from sockRoutines.h:128,
                 from conv-ccs.h:10,
                 from debug-conv.C:12:
debug-conv.C: In function ‘void CpdSearchLeaks(char*)’:
debug-conv.C:83:26: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   83 |       (((CmiUInt8)ntohl(((int*)&info->begin_data)[0]))<<32) + ntohl(((int*)&info->begin_data)[1]));
      |                         ~^~~~~~~~~~~~~~~~~~~~~~~~
debug-conv.C:85:26: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   85 |       (((CmiUInt8)ntohl(((int*)&info->end_data)[0]))<<32) + ntohl(((int*)&info->end_data)[1]));
      |                         ~^~~~~~~~~~~~~~~~~~~~~~
debug-conv.C:87:26: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   87 |       (((CmiUInt8)ntohl(((int*)&info->begin_bss)[0]))<<32) + ntohl(((int*)&info->begin_bss)[1]));
      |                         ~^~~~~~~~~~~~~~~~~~~~~~~
debug-conv.C:89:26: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   89 |       (((CmiUInt8)ntohl(((int*)&info->end_bss)[0]))<<32) + ntohl(((int*)&info->end_bss)[1]));
      |                         ~^~~~~~~~~~~~~~~~~~~~~
In file included from ccs-builtins.C:14:
pup_toNetwork.h: In member function ‘void* PUP_toNetwork_unpack::read_CMK_POINTER_SIZED_INT()’:
pup_toNetwork.h:117:21: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  117 |             return *(void **)&i;
      |                     ^~~~~~~~~~~
In file included from pup_toNetwork.C:11:
pup_toNetwork.h: In member function ‘void* PUP_toNetwork_unpack::read_CMK_POINTER_SIZED_INT()’:
pup_toNetwork.h:117:21: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  117 |             return *(void **)&i;
      |                     ^~~~~~~~~~~
In file included from pup_c.C:14:
pup_toNetwork.h: In member function ‘void* PUP_toNetwork_unpack::read_CMK_POINTER_SIZED_INT()’:
pup_toNetwork.h:117:21: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  117 |             return *(void **)&i;
      |                     ^~~~~~~~~~~
In file included from machine.C:209:
machine-eth.C: In function ‘void AssembleDatagram(OtherNode, ExplicitDgram)’:
machine-common-core.C:131:29: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  131 | #define CMI_MSG_SIZE(msg)  ((CmiMsgHeaderBasic *)msg)->size
      |                            ~^~~~~~~~~~~~~~~~~~~~~~~~~
machine-eth.C:384:12: note: in expansion of macro ‘CMI_MSG_SIZE’
  384 |     size = CMI_MSG_SIZE(dg->data);
      |            ^~~~~~~~~~~~
md/setjmp64_.c: In function ‘qt_args_1’:
md/setjmp64_.c:72:15: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   72 |     _longjmp(*(jmp_buf *)&rjb, push_buf((void *)jb));
      |               ^~~~~~~~~~~~~~~
md/setjmp64_.c: In function ‘qt_block’:
md/setjmp64_.c:109:15: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  109 |     _longjmp(*(jmp_buf *)&sp, push_buf((void *)&help));
      |               ^~~~~~~~~~~~~~
md/setjmp64_.c: In function ‘qt_abort’:
md/setjmp64_.c:123:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  123 |   _longjmp(*(jmp_buf *)&sp, push_buf((void *)&help));
      |             ^~~~~~~~~~~~~~