DISTRHO / Cardinal

Virtual modular synthesizer plugin
https://cardinal.kx.studio/
GNU General Public License v3.0
2.29k stars 154 forks source link

Can't build 24.05 with LTO #671

Closed iv-m closed 6 months ago

iv-m commented 6 months ago

Version

24.05

Plugin type

LV2

OS

Linux

DAW / Host (if applicable)

No response

Description

When I'm trying to build Cardinal 24.05 with LTO enabled with gcc 13.2.1, I get the following error:

/build//Cardinal-24.05/include/plugincontext.hpp:76:8: error: type 'struct CardinalPluginContext' violates the C++ One Definition Rule [-Werror=odr]
   76 | struct CardinalPluginContext : rack::Context {
      |        ^
/build//Cardinal-24.05/include/plugincontext.hpp:76:8: note: a different type is defined in another translation unit
   76 | struct CardinalPluginContext : rack::Context {
      |        ^
/build//Cardinal-24.05/include/plugincontext.hpp:93:38: note: the first difference of corresponding definitions is field 'tlw'
   93 |     CardinalDGL::NanoTopLevelWidget* tlw;
      |                                      ^
/build//Cardinal-24.05/include/plugincontext.hpp:76:8: note: a type with different number of fields is defined in another translation unit
   76 | struct CardinalPluginContext : rack::Context {
      |        ^
/build//Cardinal-24.05/include/plugincontext.hpp:97:10: error: type of 'writeMidiMessage' does not match original declaration [-Werror=lto-type-mismatch]
   97 |     void writeMidiMessage(const rack::midi::Message& message, uint8_t channel);
      |          ^
../CardinalCommon.cpp:203:6: note: 'writeMidiMessage' was previously declared here
  203 | void CardinalPluginContext::writeMidiMessage(const rack::midi::Message& message, const uint8_t channel)
      |      ^
../CardinalCommon.cpp:203:6: note: code may be misoptimized unless '-fno-strict-aliasing' is used
lto1: some warnings being treated as errors
lto-wrapper: fatal error: x86_64-alt-linux-g++ returned 1 exit status
compilation terminated.
ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status
falkTX commented 6 months ago

is this from a fresh clone?

iv-m commented 6 months ago

The second error is probably the consequence of the first one, as CardinalPluginContext is, from the compiler perspective, two different types.

My guess is that code compiled with -DHEADLESS is mixed with code that is compiled without it, and whith LTO the compiler becomes able to detect it.

iv-m commented 6 months ago

is this from a fresh clone?

Not yet, just after git clean -fxd. I'll try to build a fresh clone but I don't see how the result can be different.

iv-m commented 6 months ago

I'll try to build a fresh clone

Ok, done, and it fails in the same way. Here's what I've done:

git clone  --recurse-submodules 'https://github.com/DISTRHO/Cardinal'
cd Cardinal
make -j8 SKIP_STRIPPING=true SYSDEPS=true WITH_LTO=true AR=gcc-ar VERBOSE=1 lv2

It successfully builds full Cardinal plugins, but can't build the mini plugin dsp part:

$ find ./bin -type f | grep -iv resources
./bin/Cardinal.lv2/Cardinal.so
./bin/CardinalFX.lv2/CardinalFX.so
./bin/CardinalSynth.lv2/CardinalSynth.so
./bin/CardinalMini.lv2/CardinalMini_ui.so
iv-m commented 6 months ago

My guess is that code compiled with -DHEADLESS is mixed with code that is compiled without it

Here is the failed g++ command:

g++ ../../build/CardinalMini-sep/CardinalPlugin.cpp.o ../../build/CardinalMini-sep/CardinalCommon.cpp.o ../../build/CardinalMini-sep/CardinalRemote.cpp.o ../../build/CardinalMini-sep/common.cpp.o ../../build/CardinalMini-sep/RemoteNanoVG.cpp.o ../../build/CardinalMini-sep/RemoteWindow.cpp.o ../../build/CardinalMini-sep/DistrhoPluginMain_LV2.cpp.o -Wall -Wextra -pipe -MD -MP -fno-gnu-unique -g -fPIC -DPIC -DNDEBUG -O3 -ffast-math -fdata-sections -ffunction-sections -mtune=generic -msse -msse2 -mfpmath=sse -fvisibility=hidden -fno-strict-aliasing -flto -DUSING_CARDINAL_NOT_RACK -I/tmp/.private/iv/Cardinal/include -I/tmp/.private/iv/Cardinal/include/simd-compat -I/tmp/.private/iv/Cardinal/deps/sysroot/include -msse -msse2 -msse3 -DCARDINAL_SYSDEPS  -pthread -I/tmp/.private/iv/Cardinal/src/Rack/dep/simde -DSIMDE_ACCURACY_PREFERENCE=0 -DSIMDE_FAST_CONVERSION_RANGE -DSIMDE_FAST_MATH -DSIMDE_FAST_NANS -DSIMDE_FAST_ROUND_MODE -DSIMDE_FAST_ROUND_TIES -Wno-unused-parameter -Wno-unused-variable -DARCH_LIN -I/tmp/.private/iv/Cardinal/dpf/dgl/src/nanovg -I/tmp/.private/iv/Cardinal/dpf/distrho -I/tmp/.private/iv/Cardinal/src -I/tmp/.private/iv/Cardinal/src/Rack/include -I/tmp/.private/iv/Cardinal/src/Rack/include/dsp -I/tmp/.private/iv/Cardinal/src/Rack/dep/filesystem/include -I/tmp/.private/iv/Cardinal/src/Rack/dep/fuzzysearchdatabase/src -I/tmp/.private/iv/Cardinal/src/Rack/dep/glfw/include -I/tmp/.private/iv/Cardinal/src/Rack/dep/nanosvg/src -I/tmp/.private/iv/Cardinal/src/Rack/dep/oui-blendish -I/tmp/.private/iv/Cardinal/src/Rack/dep/pffft -I/tmp/.private/iv/Cardinal/src/Rack/dep/tinyexpr -DHAVE_ALSA -DHAVE_JACK -DHAVE_LIBLO -DHAVE_PULSEAUDIO -DHAVE_RTAUDIO -DHAVE_SDL2 -DDISTRHO_PLUGIN_MODGUI_CLASS_NAME='"distrho_cardinal_mini"' -I/usr/include/dbus-1.0 -I/usr/lib64/dbus-1.0/include -DHAVE_DBUS  -DHAVE_X11  -DHAVE_XCURSOR  -DHAVE_XEXT -DHAVE_XSYNC  -DHAVE_XRANDR -DHAVE_CAIRO -DHAVE_OPENGL -DDGL_OPENGL -DHAVE_DGL  -DPRIVATE= -DDISTRHO_PLUGIN_MINIMUM_BUFFER_SIZE=0xffff  -std=gnu++11 -fvisibility-inlines-hidden -fexceptions -DDISTRHO_NAMESPACE=CardinalDISTRHO -DDGL_NAMESPACE=CardinalDGL -DNVG_DISABLE_SKIPPING_WHITESPACE -DNVG_FONT_TEXTURE_FLAGS=NVG_IMAGE_NEAREST -DDGL_WINDOWS_ICON_ID=401 -DDGL_X11_WINDOW_ICON_NAME=gCardinalX11Icon -DDGL_X11_WINDOW_ICON_SIZE=18950 -DDGL_USE_NANOVG_FBO -DDGL_USE_FILE_BROWSER -fno-finite-math-only -fno-strict-aliasing -U_GLIBCXX_ASSERTIONS -Wp,-U_GLIBCXX_ASSERTIONS -Wno-format-security -faligned-new -Wno-abi -I. -I../../dpf/distrho -I../../dpf/dgl -I../../dpf/dgl/src/pugl-upstream/include -DCARDINAL_PLUGIN_PREFIX='"/usr/local"' -fdata-sections -ffunction-sections -Wl,-O1,--as-needed,--gc-sections -fno-strict-aliasing -flto -Werror=odr -Werror=lto-type-mismatch  -Wl,--no-undefined -fexceptions -ldl -pthread -ldl -Wno-alloc-size-larger-than  ../../plugins/plugins-mini-headless.a ../rack-headless.a /tmp/.private/iv/Cardinal/deps/surge-build/src/common/libsurge-common.a /tmp/.private/iv/Cardinal/deps/surge-build/src/common/libjuce_dsp_rack_sub.a /tmp/.private/iv/Cardinal/deps/surge-build/libs/airwindows/libairwindows.a /tmp/.private/iv/Cardinal/deps/surge-build/libs/eurorack/libeurorack.a /tmp/.private/iv/Cardinal/deps/surge-build/libs/fmt/libfmt.a /tmp/.private/iv/Cardinal/deps/surge-build/libs/sqlite-3.23.3/libsqlite.a /tmp/.private/iv/Cardinal/deps/surge-build/libs/sst/sst-plugininfra/libsst-plugininfra.a /tmp/.private/iv/Cardinal/deps/surge-build/libs/sst/sst-plugininfra/libs/filesystem/libfilesystem.a /tmp/.private/iv/Cardinal/deps/surge-build/libs/sst/sst-plugininfra/libs/strnatcmp/libstrnatcmp.a /tmp/.private/iv/Cardinal/deps/surge-build/libs/sst/sst-plugininfra/libs/tinyxml/libtinyxml.a   -ljansson -larchive -lsamplerate -lspeexdsp -llo -shared -Wl,--version-script=../../dpf/utils/symbols/lv2-dsp.version -o ../../bin/CardinalMini.lv2/CardinalMini_dsp.so

From what I can tell from build logs, build/CardinalMini-sep/CardinalCommon.cpp.o was build without -DHEADLESS. Also, it knows something about removeIdleCallback:

$ strings build/CardinalMini-sep/CardinalCommon.cpp.o  | grep removeIdleCallback | c++filt
CardinalPluginContext::removeIdleCallback(CardinalDGL::IdleCallback*) const
.gnu.lto__ZNK21CardinalPluginContext18removeIdleCallbackEPN11CardinalDGL12IdleCallbackE.2727.132aeeec34bb4750
falkTX commented 6 months ago

yeah I see the issue, the mix of headless with non-headless builds is a mess sometimes. it is only 2 pointers and 2 functions, not enough to bother.

Should be fixed in 77b5becf75c8842cd30ee99d326782894fb334d3 please confirm.

iv-m commented 6 months ago

Should be fixed in 77b5bec please confirm.

Yes, applying 77b5becf75c8842cd30ee99d326782894fb334d3 fixes the issue for me. As it's already in master, I think this issue can be closed.

Thank you for the quick fix!