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

Jolt: Fix multiple definition LTO linking issue with mingw-gcc #100331

Merged

Conversation

akien-mga
Copy link
Member

This fixes the following errors when building with mingw-gcc for Windows with scons p=windows lto=full:

/usr/lib/gcc/x86_64-w64-mingw32/14.1.1/../../../../x86_64-w64-mingw32/bin/ld: modules/jolt_physics/spaces/jolt_layers.windows.editor.x86_64.o (symbol from plugin):(.gnu.linkonce.t._ZN10JoltLayersD1Ev[_ZThn16_N10JoltLayersD1Ev]+0x0): multiple definition of `JoltLayers::~JoltLayers()'; modules/jolt_physics/spaces/jolt_space_3d.windows.editor.x86_64.o (symbol from plugin):(.gnu.linkonce.t._ZN10JoltLayersD1Ev[_ZThn8_N10JoltLayersD1Ev]+0x0): first defined here
/usr/lib/gcc/x86_64-w64-mingw32/14.1.1/../../../../x86_64-w64-mingw32/bin/ld: modules/jolt_physics/spaces/jolt_layers.windows.editor.x86_64.o (symbol from plugin):(.gnu.linkonce.t._ZN10JoltLayersD1Ev[_ZThn16_N10JoltLayersD1Ev]+0x0): multiple definition of `non-virtual thunk to JoltLayers::~JoltLayers()'; modules/jolt_physics/spaces/jolt_space_3d.windows.editor.x86_64.o (symbol from plugin):(.gnu.linkonce.t._ZN10JoltLayersD1Ev[_ZThn8_N10JoltLayersD1Ev]+0x0): first defined here
/usr/lib/gcc/x86_64-w64-mingw32/14.1.1/../../../../x86_64-w64-mingw32/bin/ld: modules/jolt_physics/spaces/jolt_layers.windows.editor.x86_64.o (symbol from plugin):(.gnu.linkonce.t._ZN10JoltLayersD1Ev[_ZThn16_N10JoltLayersD1Ev]+0x0): multiple definition of `non-virtual thunk to JoltLayers::~JoltLayers()'; modules/jolt_physics/spaces/jolt_space_3d.windows.editor.x86_64.o (symbol from plugin):(.gnu.linkonce.t._ZN10JoltLayersD1Ev[_ZThn8_N10JoltLayersD1Ev]+0x0): first defined here
/usr/lib/gcc/x86_64-w64-mingw32/14.1.1/../../../../x86_64-w64-mingw32/bin/ld: modules/jolt_physics/spaces/jolt_layers.windows.editor.x86_64.o (symbol from plugin):(.gnu.linkonce.t._ZN10JoltLayersD0Ev[_ZThn16_N10JoltLayersD0Ev]+0x0): multiple definition of `JoltLayers::~JoltLayers()'; modules/jolt_physics/spaces/jolt_space_3d.windows.editor.x86_64.o (symbol from plugin):(.gnu.linkonce.t._ZN10JoltLayersD0Ev[_ZThn8_N10JoltLayersD0Ev]+0x0): first defined here
/usr/lib/gcc/x86_64-w64-mingw32/14.1.1/../../../../x86_64-w64-mingw32/bin/ld: modules/jolt_physics/spaces/jolt_layers.windows.editor.x86_64.o (symbol from plugin):(.gnu.linkonce.t._ZN10JoltLayersD0Ev[_ZThn16_N10JoltLayersD0Ev]+0x0): multiple definition of `non-virtual thunk to JoltLayers::~JoltLayers()'; modules/jolt_physics/spaces/jolt_space_3d.windows.editor.x86_64.o (symbol from plugin):(.gnu.linkonce.t._ZN10JoltLayersD0Ev[_ZThn8_N10JoltLayersD0Ev]+0x0): first defined here
/usr/lib/gcc/x86_64-w64-mingw32/14.1.1/../../../../x86_64-w64-mingw32/bin/ld: modules/jolt_physics/spaces/jolt_layers.windows.editor.x86_64.o (symbol from plugin):(.gnu.linkonce.t._ZN10JoltLayersD0Ev[_ZThn16_N10JoltLayersD0Ev]+0x0): multiple definition of `non-virtual thunk to JoltLayers::~JoltLayers()'; modules/jolt_physics/spaces/jolt_space_3d.windows.editor.x86_64.o (symbol from plugin):(.gnu.linkonce.t._ZN10JoltLayersD0Ev[_ZThn8_N10JoltLayersD0Ev]+0x0): first defined here

@hpvb gave me this advice:

This means that during the LTO step we end up with multiple symbols of the same name, probably means something has to be moved out of a header to a .cpp file

And indeed defining the empty destructor in the .cpp file solved it. Previous attempts at adding ~JoltLayers(); or ~JoltLayers = default; in the header wouldn't work.

For the record, this sounds related to this GCC bug report: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94156
But it's unconfirmed upstream so I don't know if it's indeed a GCC bug or just a spec caveat.

@hpvb
Copy link
Member

hpvb commented Dec 12, 2024

Yeah, I'm also not entirely clear if this is a bug in the linker, or just something that only works when you don't use LTO by accident. Maybe without LTO these duplicate symbols get folded together by the linker but with LTO not? I really don't know.

@akien-mga akien-mga force-pushed the jolt-fix-mingw-lto-multiple-definitions branch from 1bc17da to 0ba875e Compare December 12, 2024 20:31
@akien-mga akien-mga requested a review from mihe December 12, 2024 20:31
@Repiteo Repiteo merged commit 6acb58d into godotengine:master Dec 12, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Dec 12, 2024

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants