Skip to content

Fix CXX initializers #269

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

Open
DymOK93 opened this issue Jan 12, 2022 · 1 comment
Open

Fix CXX initializers #269

DymOK93 opened this issue Jan 12, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@DymOK93
Copy link
Owner

DymOK93 commented Jan 12, 2022

Recent MSVC compiler uses

using ktl::crt::global_c_handler_t = int(__cdecl*)();
using ktl::crt::global_cxx_handler_t = void(__cdecl*)();

CRTALLOC(".CRT$XIA")
ktl::crt::global_c_handler_t __xi_a[] {nullptr};  // C initializers (first)
CRTALLOC(".CRT$XIZ")
ktl::crt::global_c_handler_t __xi_z[] {nullptr};  // C initializers (last)
CRTALLOC(".CRT$XCA")
ktl::crt::global__cxx_handler_t __xc_a[] {nullptr};  // C++ initializers (first)
CRTALLOC(".CRT$XCZ")
ktl::crt::global_cxx_handler_t __xc_z[] {nullptr};  // C++ initializers (last)
CRTALLOC(".CRT$XPA")
ktl::crt::global_cxx_handler_t __xp_a[] {nullptr};  // C pre-terminators (first)
CRTALLOC(".CRT$XPZ")
ktl::crt::global_cxx_handler_t __xp_z[] {nullptr};  // C pre-terminators (last)
CRTALLOC(".CRT$XTA")
ktl::crt::global_cxx_handler_t __xt_a[] {nullptr};  // C terminators (first)
CRTALLOC(".CRT$XTZ")
ktl::crt::global_cxx_handler_t __xt_z[] {nullptr};  // C terminators (last)

instead of old initializers provided by KTL.

Usually MSVC places C++ initializers between __cxx_ctors_begin__ and __cxx_ctors_end__ symbols as expected, but with LTO enabled (/GL compiler option) includes these symbols in reverse order into a weird ?__cxx_c section without the initializers themselves:

изображение

Reproducible on MSVC 19.28+

@DymOK93 DymOK93 self-assigned this Jan 12, 2022
@DymOK93 DymOK93 added the bug Something isn't working label Jan 12, 2022
@DymOK93
Copy link
Owner Author

DymOK93 commented Jan 12, 2022

The problem turned out to be simpler ...
Symbol names aren't important: a bug occurs only if these symbols are marked as inline and LTO is enabled.
Without an inline specifier (symbols can be left in the header file since it is included in one TU) - everything is OK.
I suppose it is due to the fact that the phase of forming the section of dynamic initializers in .rodata occurs before the resolution of symbols with a weak linkage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant