Skip to content

Fix ODR violation when LTO is enabled#59

Merged
danvratil merged 1 commit intomainfrom
fix-gcc-odr-violation-lto
Apr 27, 2022
Merged

Fix ODR violation when LTO is enabled#59
danvratil merged 1 commit intomainfrom
fix-gcc-odr-violation-lto

Conversation

@danvratil
Copy link
Collaborator

@danvratil danvratil commented Apr 27, 2022

There are two classes called SocketReadySignalHelper in two
anonymous namespaces in two distinct TUs. Since they are both
used as arguments to a coroutine, the compiler has generated for
each invocation of the coroutine a stackframe struct, which
contained SocketReadySignalHelper in its name. However, the frame
structs are not stored in an anonymous namespace, and due to the
classes both having the same name, we ended up with two distict
classes with the same name in two different TUs. Because they are
not in an anonymous namespace, the link time optimizer tries to
solve the duplication and runs into an ODR violation.

To workaround this, what I believe is a GCC bug, this change renames
the structures to each have a unique name.

The name of the generated frame struct was
_Z5qCoroIN12_GLOBAL__N_123SocketReadySignalHelperEMN5QCoro6detail16WaitSignalHelperEFvbEENS2_4TaskINS3_11QCoroSignalIT_T0_E11result_typeEEEPS9_OSA_NSt6chrono8durationIlSt5ratioILl1ELl1000EEEE.Frame

Edit: it is a known GCC bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101118

There are two classes called SocketReadySignalHelper in two
anonymous namespaces in two distinct TUs. Since they are both
used as arguments to a coroutine, the compiler has generated for
each invocation of the coroutine a stackframe struct, which
contained SocketReadySignalHelper in its name. However, the frame
structs are not stored in an anonymous namespace, and due to the
classes both having the same name, we ended up with two distict
classes with the same name in two different TUs. Because they are
not in an anonymous namespace, the link time optimizer tries to
solve the duplication and runs into an ODR violation.

To workaround this, what I believe is a GCC bug, this change renames
the structures to each have a unique name.

The name of the generated frame struct was
_Z5qCoroIN12_GLOBAL__N_123SocketReadySignalHelperEMN5QCoro6detail16WaitSignalHelperEFvbEENS2_4TaskINS3_11QCoroSignalIT_T0_E11result_typeEEEPS9_OSA_NSt6chrono8durationIlSt5ratioILl1ELl1000EEEE.Frame
@github-actions
Copy link
Contributor

github-actions bot commented Apr 27, 2022

Unit Test Results

  6 files   -   1    6 suites   - 1   4m 8s ⏱️ -42s
14 tests ±  0  14 ✔️ +  1  0 💤 ±0  0  - 1 
80 runs   - 14  80 ✔️  - 13  0 💤 ±0  0  - 1 

Results for commit 35d449c. ± Comparison against base commit 826dbb5.

♻️ This comment has been updated with latest results.

@danvratil danvratil merged commit 4786acf into main Apr 27, 2022
@danvratil danvratil deleted the fix-gcc-odr-violation-lto branch April 27, 2022 14:41
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

Successfully merging this pull request may close these issues.

1 participant