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 #518

Open
eli-schwartz opened this issue Apr 5, 2024 · 1 comment
Open

Build fails with strict-aliasing violations #518

eli-schwartz opened this issue Apr 5, 2024 · 1 comment

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:

x86_64-pc-linux-gnu-g++ -std=gnu++17 -march=native -fstack-protector-all -O2 -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing  -Wformat -Werror=format-security -Wall -Wno-deprecated-declarations -Wno-format-truncation -Wno-unused-local-typedefs -Wno-unused-function -Wno-infinite-recursion -g -I. -fPIE -march=native -fstack-protector-all  -pipe -fdiagnostics-color=always -frecord-gcc-switches -flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing -Wformat -Werror=format-security   -DKS_STR_ENCODING_NONE -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include   -c kaitaistream.cc -o kaitaistream.cc.o
kaitaistream.cc: In member function ‘float kaitai::kstream::read_f4be()’:
kaitaistream.cc:256:38: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  256 |     return reinterpret_cast<float &>(t);
      |                                      ^
kaitaistream.cc: In member function ‘double kaitai::kstream::read_f8be()’:
kaitaistream.cc:265:39: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  265 |     return reinterpret_cast<double &>(t);
      |                                       ^
kaitaistream.cc: In member function ‘float kaitai::kstream::read_f4le()’:
kaitaistream.cc:278:38: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  278 |     return reinterpret_cast<float &>(t);
      |                                      ^
kaitaistream.cc: In member function ‘double kaitai::kstream::read_f8le()’:
kaitaistream.cc:287:39: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  287 |     return reinterpret_cast<double &>(t);
      |                                       ^
cc1plus: some warnings being treated as errors
make: *** [Makefile:822: kaitaistream.cc.o] Error 1

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

@generalmimon
Copy link

FYI, this has been fixed in our upstream repo https://github.com/kaitai-io/kaitai_struct_cpp_stl_runtime (kaitai-io/kaitai_struct_cpp_stl_runtime#73), so you may want to update your copy.

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

2 participants