Bug 466767 - kwayland 5.103.0 fails to compile with LTO enabled due to ODR violations and lto type mismatch
Summary: kwayland 5.103.0 fails to compile with LTO enabled due to ODR violations and ...
Status: REPORTED
Alias: None
Product: kwayland
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.93.0
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Martin Flöser
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-03-03 14:26 UTC by kocelfc
Modified: 2024-02-07 15:12 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
full build log (318.27 KB, text/x-log)
2023-03-03 14:26 UTC, kocelfc
Details

Note You need to log in before you can comment on or make changes to this bug.
Description kocelfc 2023-03-03 14:26:07 UTC
Created attachment 156958 [details]
full build log

SUMMARY

kwayland 5.103.0 fails to compile when building with -flto -Werror=odr and -Werror=lto-type-mismatch on Gentoo using gcc 12.2.1


/var/tmp/portage/kde-frameworks/kwayland-5.103.0/work/kwayland-5.103.0/src/client/buffer_p.h:17:29: error: type ‘struct Private’ violates the C++ One Definition Rule [-Werror=odr]
   17 | class Q_DECL_HIDDEN Buffer::Private
      |                             ^
/var/tmp/portage/kde-frameworks/kwayland-5.103.0/work/kwayland-5.103.0/src/client/buffer_p.h:17:29: note: a different type is defined in another translation unit
   17 | class Q_DECL_HIDDEN Buffer::Private
      |                             ^
/var/tmp/portage/kde-frameworks/kwayland-5.103.0/work/kwayland-5.103.0/src/client/buffer_p.h:25:50: note: the first difference of corresponding definitions is field ‘nativeBuffer’
   25 |     WaylandPointer<wl_buffer, wl_buffer_destroy> nativeBuffer;
      |                                                  ^
/var/tmp/portage/kde-frameworks/kwayland-5.103.0/work/kwayland-5.103.0/src/client/buffer_p.h:25:50: note: a field of same name but different type is defined in another translation unit
   25 |     WaylandPointer<wl_buffer, wl_buffer_destroy> nativeBuffer;
      |                                                  ^
/var/tmp/portage/kde-frameworks/kwayland-5.103.0/work/kwayland-5.103.0/src/client/wayland_pointer_p.h:16:7: note: type ‘struct WaylandPointer’ defined in anonymous namespace cannot match across the translation unit boundary
   16 | class WaylandPointer
      |       ^
/var/tmp/portage/kde-frameworks/kwayland-5.103.0/work/kwayland-5.103.0/src/client/surface_p.h:18:30: error: type ‘struct Private’ violates the C++ One Definition Rule [-Werror=odr]
   18 | class Q_DECL_HIDDEN Surface::Private
      |                              ^
/var/tmp/portage/kde-frameworks/kwayland-5.103.0/work/kwayland-5.103.0/src/client/surface_p.h:18:30: note: a different type is defined in another translation unit
   18 | class Q_DECL_HIDDEN Surface::Private
      |                              ^
/var/tmp/portage/kde-frameworks/kwayland-5.103.0/work/kwayland-5.103.0/src/client/surface_p.h:24:52: note: the first difference of corresponding definitions is field ‘surface’
   24 |     WaylandPointer<wl_surface, wl_surface_destroy> surface;
      |                                                    ^
/var/tmp/portage/kde-frameworks/kwayland-5.103.0/work/kwayland-5.103.0/src/client/surface_p.h:24:52: note: a field of same name but different type is defined in another translation unit
   24 |     WaylandPointer<wl_surface, wl_surface_destroy> surface;
      |                                                    ^
/var/tmp/portage/kde-frameworks/kwayland-5.103.0/work/kwayland-5.103.0/src/client/wayland_pointer_p.h:16:7: note: type ‘struct WaylandPointer’ defined in anonymous namespace cannot match across the translation unit boundary
   16 | class WaylandPointer
      |       ^
/var/tmp/portage/kde-frameworks/kwayland-5.103.0/work/kwayland-5.103.0/src/client/buffer_p.h:22:10: error: type of ‘destroy’ does not match original declaration [-Werror=lto-type-mismatch]
   22 |     void destroy();
      |          ^
/var/tmp/portage/kde-frameworks/kwayland-5.103.0/work/kwayland-5.103.0/src/client/buffer.cpp:41:6: note: ‘destroy’ was previously declared here
   41 | void Buffer::Private::destroy()
      |      ^
/var/tmp/portage/kde-frameworks/kwayland-5.103.0/work/kwayland-5.103.0/src/client/buffer.cpp:41:6: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used
lto1: some warnings being treated as errors
lto-wrapper: fatal error: /usr/sbin/x86_64-pc-linux-gnu-g++ returned 1 exit status
compilation terminated.


STEPS TO REPRODUCE
1. add -flto -Werror=odr -Werror=lto-type-mismatch to CFLAGS and CXXFLAGS
2. Try to build
3. Build failure
Comment 1 Erik Quaeghebeur 2024-01-30 06:52:03 UTC
Downstream bug report: https://bugs.gentoo.org/866575
Comment 2 kocelfc 2024-02-07 15:12:03 UTC
This UB is still present with 5.93.0:

[ 70%] Linking CXX shared library ../../bin/libKWaylandClient.so
/home/kostadin/kwayland/src/client/buffer_p.h:17:29: warning: type ‘struct Private’ violates the C++ One Definition Rule [-Wodr]
   17 | class Q_DECL_HIDDEN Buffer::Private
      |                             ^
/home/kostadin/kwayland/src/client/buffer_p.h:17:29: note: a different type is defined in another translation unit
   17 | class Q_DECL_HIDDEN Buffer::Private
      |                             ^
/home/kostadin/kwayland/src/client/buffer_p.h:25:50: note: the first difference of corresponding definitions is field ‘nativeBuffer’
   25 |     WaylandPointer<wl_buffer, wl_buffer_destroy> nativeBuffer;
      |                                                  ^
/home/kostadin/kwayland/src/client/buffer_p.h:25:50: note: a field of same name but different type is defined in another translation unit
   25 |     WaylandPointer<wl_buffer, wl_buffer_destroy> nativeBuffer;
      |                                                  ^
/home/kostadin/kwayland/src/client/wayland_pointer_p.h:16:7: note: type ‘struct WaylandPointer’ defined in anonymous namespace cannot match across the translation unit boundary
   16 | class WaylandPointer
      |       ^
/home/kostadin/kwayland/src/client/surface_p.h:18:30: warning: type ‘struct Private’ violates the C++ One Definition Rule [-Wodr]
   18 | class Q_DECL_HIDDEN Surface::Private
      |                              ^
/home/kostadin/kwayland/src/client/surface_p.h:18:30: note: a different type is defined in another translation unit
   18 | class Q_DECL_HIDDEN Surface::Private
      |                              ^
/home/kostadin/kwayland/src/client/surface_p.h:24:52: note: the first difference of corresponding definitions is field ‘surface’
   24 |     WaylandPointer<wl_surface, wl_surface_destroy> surface;
      |                                                    ^
/home/kostadin/kwayland/src/client/surface_p.h:24:52: note: a field of same name but different type is defined in another translation unit
   24 |     WaylandPointer<wl_surface, wl_surface_destroy> surface;
      |                                                    ^
/home/kostadin/kwayland/src/client/wayland_pointer_p.h:16:7: note: type ‘struct WaylandPointer’ defined in anonymous namespace cannot match across the translation unit boundary
   16 | class WaylandPointer
      |       ^
/home/kostadin/kwayland/src/client/buffer_p.h:22:10: warning: type of ‘destroy’ does not match original declaration [-Wlto-type-mismatch]
   22 |     void destroy();
      |          ^
/home/kostadin/kwayland/src/client/buffer.cpp:41:6: note: ‘destroy’ was previously declared here
   41 | void Buffer::Private::destroy()
      |      ^
/home/kostadin/kwayland/src/client/buffer.cpp:41:6: note: code may be misoptimized unless ‘-fno-strict-aliasing’ is used