ampas / CTL

The Color Transformation Language (CTL)
Other
220 stars 78 forks source link

Build fails with strict-aliasing violations #146

Closed eli-schwartz closed 6 months ago

eli-schwartz commented 6 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:

[8/18] /usr/bin/x86_64-pc-linux-gnu-g++ -DPACKAGE=\"CTL\" -DVERSION=\"1.5.3\" -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/dpx -isystem /usr/include/Imath  -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 -std=gnu++11 -MD -MT lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o -MF lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o.d -o lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o -c /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/dpx/dpx_raw.cc
FAILED: lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o 
/usr/bin/x86_64-pc-linux-gnu-g++ -DPACKAGE=\"CTL\" -DVERSION=\"1.5.3\" -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/dpx -isystem /usr/include/Imath  -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 -std=gnu++11 -MD -MT lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o -MF lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o.d -o lib/dpx/CMakeFiles/ctldpx.dir/dpx_raw.cc.o -c /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/dpx/dpx_raw.cc
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/dpx/dpx_raw.cc: In static member function ‘static bool ctl::dpx::isnull(float32_t)’:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/dpx/dpx_raw.cc:209:18: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
  209 |         return *((uint32_t *)&v)==(uint32_t)-1;
      |                 ~^~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors
[9/18] /usr/bin/x86_64-pc-linux-gnu-g++ -DIlmCtlSimd_EXPORTS -DPACKAGE=\"CTL\" -DVERSION=\"1.5.3\" -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3_build/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlMath -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtl -isystem /usr/include/OpenEXR -isystem /usr/include/Imath  -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 -std=gnu++11 -fPIC -MD -MT lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o -MF lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o.d -o lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o -c /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdStdLibMath.cpp
FAILED: lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o 
/usr/bin/x86_64-pc-linux-gnu-g++ -DIlmCtlSimd_EXPORTS -DPACKAGE=\"CTL\" -DVERSION=\"1.5.3\" -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3_build/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlMath -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtl -isystem /usr/include/OpenEXR -isystem /usr/include/Imath  -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 -std=gnu++11 -fPIC -MD -MT lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o -MF lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o.d -o lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdStdLibMath.cpp.o -c /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdStdLibMath.cpp
In file included from /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdHalfExpLog.h:70,
                 from /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdStdLibMath.cpp:69:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h: In function ‘float Ctl::log10_h(half)’:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h:15:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   15 |     return *(float *)(&log10Table[x.bits()]);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h: In function ‘float Ctl::log_h(half)’:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h:22:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   22 |     return *(float *)(&logTable[x.bits()]);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors
[10/18] /usr/bin/x86_64-pc-linux-gnu-g++ -DIlmCtlSimd_EXPORTS -DPACKAGE=\"CTL\" -DVERSION=\"1.5.3\" -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3_build/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlMath -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtl -isystem /usr/include/OpenEXR -isystem /usr/include/Imath  -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 -std=gnu++11 -fPIC -MD -MT lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o -MF lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o.d -o lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o -c /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdHalfExpLog.cpp
FAILED: lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o 
/usr/bin/x86_64-pc-linux-gnu-g++ -DIlmCtlSimd_EXPORTS -DPACKAGE=\"CTL\" -DVERSION=\"1.5.3\" -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3_build/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlMath -I/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtl -isystem /usr/include/OpenEXR -isystem /usr/include/Imath  -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 -std=gnu++11 -fPIC -MD -MT lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o -MF lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o.d -o lib/IlmCtlSimd/CMakeFiles/IlmCtlSimd.dir/CtlSimdHalfExpLog.cpp.o -c /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdHalfExpLog.cpp
In file included from /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdHalfExpLog.h:70,
                 from /var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/CtlSimdHalfExpLog.cpp:63:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h: In function ‘float Ctl::log10_h(half)’:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h:15:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   15 |     return *(float *)(&log10Table[x.bits()]);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h: In function ‘float Ctl::log_h(half)’:
/var/tmp/portage/media-libs/ctl-1.5.3/work/CTL-ctl-1.5.3/lib/IlmCtlSimd/halfExpLog.h:22:13: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
   22 |     return *(float *)(&logTable[x.bits()]);
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: some warnings being treated as errors
ninja: build stopped: subcommand failed.

Downtream report: https://bugs.gentoo.org/926823 Full build log: build.log

michaeldsmith commented 6 months ago

@eli-schwartz thank you for reporting this issue. I think I have addressed the issue you have reported with PR #147. Please let us know if that PR resolves the issue for you or if you have any other suggestions or input, etc.

eli-schwartz commented 6 months ago

Thanks. I tried applying the patches from that PR onto the 1.5.3 release and everything compiled fine.

No more commments in particular (though I guess I am a bit surprised that vcpkg hasn't gone and pinned to say an archive.org copy of the tarball for the version they reverted to).

michaeldsmith commented 6 months ago

thanks - i agree that the vcpkg thing is a surprise. I think the XV backdoor issue will probably take some time to resolve since the bad actor may have been contributing for a while. Wired has a long piece on it here https://www.wired.com/story/xz-backdoor-everything-you-need-to-know/

eli-schwartz commented 6 months ago

FWIW it may not be as bad as all that. The bad actor has been contributing since 2021 but it's only since the beginning of 2024 or thereabouts that the original author's guard was lowered enough to put these pieces into place. Status updates will be at https://tukaani.org/xz-backdoor/ and indicate we may not have to wait too long...

michaeldsmith commented 6 months ago

closed by 7133fc29f4057c9d05415097a10a89fc58ecdaf3