Repository navigation
Work around MSVC 14.52 converting to empty bases with the wrong offset - #390
Open
gennaroprota wants to merge 1 commit into
Open
gennaroprota wants to merge 1 commit into
gennaroprota wants to merge 1 commit into
Conversation
MSVC 14.52 converts a pointer to an empty base which ends its derived class with an offset one less than earlier versions use, although the layout it reports is unchanged (https://developercommunity.visualstudio.com/t/C-object-layout-places-empty-non-first/11175160). The interface base of every archive is such a base. A program built with 14.52 and linked statically with the official 1.92.0 binaries, which were built with an earlier version, gets some of the inline archive functions from the library and some from its own object files, and the two disagree on where the archive is: for instance, constructing a `binary_oarchive` or a `binary_iarchive` crashes in Debug builds. The DLL isn't affected, because it doesn't export those functions, so a program always uses its own copies. We now give `interface_oarchive` and `interface_iarchive` a data member when `_MSC_VER` is defined, so that they are no longer empty and all versions convert with the same offset. I've checked every archive type, linking a library built with MSVC 14.44 into a program built with 14.52 and vice versa. Note that the fix needs the library and the program to have it, so it can't help with the 1.92.0 binaries, and that it makes every archive a few bytes larger on MSVC. There's no test, as reproducing the problem needs two compilers. Microsoft has fixed the bug for a later release, so we can drop the member once 14.52 is no longer in use. Closes #389.
jmairboeck
reviewed
Nov 19, 2026
| class interface_oarchive | ||
| { | ||
| protected: | ||
| #if defined(_MSC_VER) |
Contributor
There was a problem hiding this comment.
I initally wanted to add the following:
Suggested change
| #if defined(_MSC_VER) | |
| #if defined(_MSC_VER) && _MSC_VER == 1952 |
because Microsoft said they are already working on a fix, but for supporting linking different versions together, we can't be that specific I guess. But the following should work:
Suggested change
| #if defined(_MSC_VER) | |
| #if defined(_MSC_VER) && _MSC_VER >= 1900 && _MSC_VER < 2000 |
Other versions (older ones) are not ABI compatible anyway and can't be linked together with the affected version. Maybe the minimum version can even be increased to 1950.
The same change needs also be done in the other file.
Collaborator
Author
There was a problem hiding this comment.
What would that change buy?
Contributor
There was a problem hiding this comment.
Not adding the member unnecessarily for older MSVC versions (before 2015 in the _MSC_VER == 1900 case).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MSVC 14.52 converts a pointer to an empty base which ends its derived class with an offset one less than earlier versions use, although the layout it reports is unchanged
(https://developercommunity.visualstudio.com/t/C-object-layout-places-empty-non-first/11175160). The interface base of every archive is such a base. A program built with 14.52 and linked statically with the official 1.92.0 binaries, which were built with an earlier version, gets some of the inline archive functions from the library and some from its own object files, and the two disagree on where the archive is: for instance, constructing a
binary_oarchiveor abinary_iarchivecrashes in Debug builds. The DLL isn't affected, because it doesn't export those functions, so a program always uses its own copies.We now give
interface_oarchiveandinterface_iarchivea data member when_MSC_VERis defined, so that they are no longer empty and all versions convert with the same offset. I've checked every archive type, linking a library built with MSVC 14.44 into a program built with 14.52 and vice versa. Note that the fix needs the library and the program to have it, so it can't help with the 1.92.0 binaries, and that it makes every archive a few bytes larger on MSVC. There's no test, as reproducing the problem needs two compilers. Microsoft has fixed the bug for a later release, so we can drop the member once 14.52 is no longer in use.Closes #389.