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

Build fails with strict-aliasing violations #145

Open
eli-schwartz opened this issue Jul 7, 2024 · 0 comments
Open

Build fails with strict-aliasing violations #145

eli-schwartz opened this issue Jul 7, 2024 · 0 comments

Comments

@eli-schwartz
Copy link

I tried to build with the following *FLAGS to optimize the build: -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:

[1/7] /usr/bin/x86_64-pc-linux-gnu-gcc -DARRAY_IMPORTS -DCCSYSYEM_IMPORTS -DCHARCONVERT_IMPORTS -DDATE_IMPORTS -DEBML2_UGLY_HACKS_API -DFILE_IMPORTS -DHAS_EBML2 -DMD5_IMPORTS -DMULTITHREAD_IMPORTS -DNODE_IMPORTS -DSTR_IMPORTS -Debml2_EXPORTS -Debml2_IMPORTS -I/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0_build/libebml2 -I/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2 -I/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec -I/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/helpers -I/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/.. -I/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0_build/corec/corec  -pipe -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -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 -Wno-error=format-security -fPIC -MD -MT libebml2/CMakeFiles/ebml2.dir/ebmlnumber.c.o -MF libebml2/CMakeFiles/ebml2.dir/ebmlnumber.c.o.d -o libebml2/CMakeFiles/ebml2.dir/ebmlnumber.c.o -c /var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2/ebmlnumber.c
FAILED: libebml2/CMakeFiles/ebml2.dir/ebmlnumber.c.o 
/usr/bin/x86_64-pc-linux-gnu-gcc -DARRAY_IMPORTS -DCCSYSYEM_IMPORTS -DCHARCONVERT_IMPORTS -DDATE_IMPORTS -DEBML2_UGLY_HACKS_API -DFILE_IMPORTS -DHAS_EBML2 -DMD5_IMPORTS -DMULTITHREAD_IMPORTS -DNODE_IMPORTS -DSTR_IMPORTS -Debml2_EXPORTS -Debml2_IMPORTS -I/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0_build/libebml2 -I/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2 -I/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec -I/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/helpers -I/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/.. -I/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0_build/corec/corec  -pipe -march=native -fstack-protector-all -O2 -fdiagnostics-color=always -frecord-gcc-switches -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 -Wno-error=format-security -fPIC -MD -MT libebml2/CMakeFiles/ebml2.dir/ebmlnumber.c.o -MF libebml2/CMakeFiles/ebml2.dir/ebmlnumber.c.o.d -o libebml2/CMakeFiles/ebml2.dir/ebmlnumber.c.o -c /var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2/ebmlnumber.c
In file included from /var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/corec.h:46,
                 from /var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/node/node.h:33,
                 from /var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2/ebml2/ebml.h:32,
                 from /var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2/ebmlnumber.c:28:
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2/ebmlnumber.c: In function ‘RenderDataFloat’:
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:42: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                          ^~~~~~~~~~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:54:33: note: in definition of macro ‘SWAP32’
   54 | #define SWAP32(a) ((((uint32_t)(a) >> 24) & 0x000000FF) | (((uint32_t)(a) >> 8)  & 0x0000FF00)|\
      |                                 ^
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:75:20: note: in expansion of macro ‘SWAP64’
   75 | #define INT64BE(a) SWAP64(a)
      |                    ^~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:33: note: in expansion of macro ‘INT64BE’
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                 ^~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2/ebmlnumber.c:187:15: note: in expansion of macro ‘LOAD64BE’
  187 |         Buf = LOAD64BE(&data.i);
      |               ^~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:42: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                          ^~~~~~~~~~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:54:72: note: in definition of macro ‘SWAP32’
   54 | #define SWAP32(a) ((((uint32_t)(a) >> 24) & 0x000000FF) | (((uint32_t)(a) >> 8)  & 0x0000FF00)|\
      |                                                                        ^
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:75:20: note: in expansion of macro ‘SWAP64’
   75 | #define INT64BE(a) SWAP64(a)
      |                    ^~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:33: note: in expansion of macro ‘INT64BE’
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                 ^~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2/ebmlnumber.c:187:15: note: in expansion of macro ‘LOAD64BE’
  187 |         Buf = LOAD64BE(&data.i);
      |               ^~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:42: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                          ^~~~~~~~~~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:55:32: note: in definition of macro ‘SWAP32’
   55 |                   (((uint32_t)(a) << 8)  & 0x00FF0000) | (((uint32_t)(a) << 24) & 0xFF000000))
      |                                ^
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:75:20: note: in expansion of macro ‘SWAP64’
   75 | #define INT64BE(a) SWAP64(a)
      |                    ^~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:33: note: in expansion of macro ‘INT64BE’
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                 ^~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2/ebmlnumber.c:187:15: note: in expansion of macro ‘LOAD64BE’
  187 |         Buf = LOAD64BE(&data.i);
      |               ^~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:42: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                          ^~~~~~~~~~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:55:71: note: in definition of macro ‘SWAP32’
   55 |                   (((uint32_t)(a) << 8)  & 0x00FF0000) | (((uint32_t)(a) << 24) & 0xFF000000))
      |                                                                       ^
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:75:20: note: in expansion of macro ‘SWAP64’
   75 | #define INT64BE(a) SWAP64(a)
      |                    ^~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:33: note: in expansion of macro ‘INT64BE’
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                 ^~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2/ebmlnumber.c:187:15: note: in expansion of macro ‘LOAD64BE’
  187 |         Buf = LOAD64BE(&data.i);
      |               ^~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:42: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                          ^~~~~~~~~~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:54:33: note: in definition of macro ‘SWAP32’
   54 | #define SWAP32(a) ((((uint32_t)(a) >> 24) & 0x000000FF) | (((uint32_t)(a) >> 8)  & 0x0000FF00)|\
      |                                 ^
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:75:20: note: in expansion of macro ‘SWAP64’
   75 | #define INT64BE(a) SWAP64(a)
      |                    ^~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:33: note: in expansion of macro ‘INT64BE’
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                 ^~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2/ebmlnumber.c:187:15: note: in expansion of macro ‘LOAD64BE’
  187 |         Buf = LOAD64BE(&data.i);
      |               ^~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:42: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                          ^~~~~~~~~~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:54:72: note: in definition of macro ‘SWAP32’
   54 | #define SWAP32(a) ((((uint32_t)(a) >> 24) & 0x000000FF) | (((uint32_t)(a) >> 8)  & 0x0000FF00)|\
      |                                                                        ^
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:75:20: note: in expansion of macro ‘SWAP64’
   75 | #define INT64BE(a) SWAP64(a)
      |                    ^~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:33: note: in expansion of macro ‘INT64BE’
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                 ^~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2/ebmlnumber.c:187:15: note: in expansion of macro ‘LOAD64BE’
  187 |         Buf = LOAD64BE(&data.i);
      |               ^~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:42: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                          ^~~~~~~~~~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:55:32: note: in definition of macro ‘SWAP32’
   55 |                   (((uint32_t)(a) << 8)  & 0x00FF0000) | (((uint32_t)(a) << 24) & 0xFF000000))
      |                                ^
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:75:20: note: in expansion of macro ‘SWAP64’
   75 | #define INT64BE(a) SWAP64(a)
      |                    ^~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:33: note: in expansion of macro ‘INT64BE’
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                 ^~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2/ebmlnumber.c:187:15: note: in expansion of macro ‘LOAD64BE’
  187 |         Buf = LOAD64BE(&data.i);
      |               ^~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:42: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                          ^~~~~~~~~~~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:55:71: note: in definition of macro ‘SWAP32’
   55 |                   (((uint32_t)(a) << 8)  & 0x00FF0000) | (((uint32_t)(a) << 24) & 0xFF000000))
      |                                                                       ^
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:75:20: note: in expansion of macro ‘SWAP64’
   75 | #define INT64BE(a) SWAP64(a)
      |                    ^~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/corec/corec/../corec/helper.h:89:33: note: in expansion of macro ‘INT64BE’
   89 | #define LOAD64BE(ptr)           INT64BE(*(uint64_t*)(ptr))
      |                                 ^~~~~~~
/var/tmp/portage/media-video/mkclean-0.9.0/work/mkclean-0.9.0/libebml2/ebmlnumber.c:187:15: note: in expansion of macro ‘LOAD64BE’
  187 |         Buf = LOAD64BE(&data.i);
      |               ^~~~~~~~
cc1: some warnings being treated as errors
ninja: build stopped: cannot make progress due to previous errors.
 * ERROR: media-video/mkclean-0.9.0::gentoo failed (compile phase):

Originally reported downstream: https://bugs.gentoo.org/861134
Full build log: build.log

Reproduced with 0.8.10, 0.9.0, and git master.

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

1 participant