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

Use /ALTERNATENAME instead of checked-in OBJ files generated by aliasobj #2381

Merged
merged 6 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions stl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -433,11 +433,6 @@ set(SATELLITE_DLL_SOURCES
${CMAKE_CURRENT_LIST_DIR}/src/dllmain_satellite.cpp
)

add_library(std_init_once_begin_initialize OBJECT IMPORTED)
add_library(std_init_once_complete OBJECT IMPORTED)
set_target_properties(std_init_once_begin_initialize PROPERTIES IMPORTED_OBJECTS "${CMAKE_CURRENT_LIST_DIR}/aliases/${VCLIBS_I386_OR_AMD64}/std_init_once_begin_initialize.obj")
set_target_properties(std_init_once_complete PROPERTIES IMPORTED_OBJECTS "${CMAKE_CURRENT_LIST_DIR}/aliases/${VCLIBS_I386_OR_AMD64}/std_init_once_complete.obj")

add_compile_definitions(_CRTBLD _VCRT_ALLOW_INTERNALS _HAS_OLD_IOSTREAMS_MEMBERS=1 _STL_CONCRT_SUPPORT)

include_directories(BEFORE
Expand Down Expand Up @@ -495,7 +490,7 @@ function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIO
target_link_libraries(msvcp_2${D_SUFFIX}_objects PRIVATE Boost::math)

add_library(msvcp_2${D_SUFFIX} SHARED)
target_link_libraries(msvcp_2${D_SUFFIX} PRIVATE msvcp_2${D_SUFFIX}_objects msvcp${D_SUFFIX}_satellite_objects msvcp${D_SUFFIX}_implib_objects std_init_once_begin_initialize std_init_once_complete "msvcp${D_SUFFIX}" "${TOOLSET_LIB}/vcruntime${D_SUFFIX}.lib" "${TOOLSET_LIB}/msvcrt${D_SUFFIX}.lib" "ucrt${D_SUFFIX}.lib")
target_link_libraries(msvcp_2${D_SUFFIX} PRIVATE msvcp_2${D_SUFFIX}_objects msvcp${D_SUFFIX}_satellite_objects msvcp${D_SUFFIX}_implib_objects "msvcp${D_SUFFIX}" "${TOOLSET_LIB}/vcruntime${D_SUFFIX}.lib" "${TOOLSET_LIB}/msvcrt${D_SUFFIX}.lib" "ucrt${D_SUFFIX}.lib")
set_target_properties(msvcp_2${D_SUFFIX} PROPERTIES ARCHIVE_OUTPUT_NAME "msvcp140_2${D_SUFFIX}${VCLIBS_SUFFIX}")
set_target_properties(msvcp_2${D_SUFFIX} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
set_target_properties(msvcp_2${D_SUFFIX} PROPERTIES OUTPUT_NAME "msvcp140_2${D_SUFFIX}${VCLIBS_SUFFIX}")
Expand Down Expand Up @@ -537,7 +532,7 @@ function(add_stl_dlls D_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPILE_OPTIO

# import library
add_library(msvcp${D_SUFFIX}_implib STATIC ${HEADERS})
target_link_libraries(msvcp${D_SUFFIX}_implib msvcp${D_SUFFIX}_implib_objects std_init_once_begin_initialize std_init_once_complete)
target_link_libraries(msvcp${D_SUFFIX}_implib msvcp${D_SUFFIX}_implib_objects)
add_dependencies(msvcp${D_SUFFIX}_implib msvcp${D_SUFFIX} msvcp_1${D_SUFFIX} msvcp_2${D_SUFFIX} msvcp${D_SUFFIX}_atomic_wait msvcp${D_SUFFIX}_codecvt_ids)
set_target_properties(msvcp${D_SUFFIX}_implib PROPERTIES STATIC_LIBRARY_OPTIONS "/NOLOGO;/NODEFAULTLIB;/IGNORE:4006;$<TARGET_LINKER_FILE:msvcp${D_SUFFIX}>;$<TARGET_LINKER_FILE:msvcp_1${D_SUFFIX}>;$<TARGET_LINKER_FILE:msvcp_2${D_SUFFIX}>;$<TARGET_LINKER_FILE:msvcp${D_SUFFIX}_codecvt_ids>;$<TARGET_LINKER_FILE:msvcp${D_SUFFIX}_atomic_wait>")
set_target_properties(msvcp${D_SUFFIX}_implib PROPERTIES ARCHIVE_OUTPUT_NAME "msvcprt${D_SUFFIX}")
Expand All @@ -554,7 +549,7 @@ function(add_stl_statics FLAVOR_SUFFIX THIS_CONFIG_DEFINITIONS THIS_CONFIG_COMPI
add_library(libcpmt${FLAVOR_SUFFIX} STATIC ${HEADERS} ${IMPLIB_SOURCES} ${SOURCES} ${INITIALIZER_SOURCES} ${STATIC_SOURCES})
target_compile_definitions(libcpmt${FLAVOR_SUFFIX} PRIVATE "${THIS_CONFIG_DEFINITIONS};_ANNOTATE_VECTOR")
target_compile_options(libcpmt${FLAVOR_SUFFIX} PRIVATE "${THIS_CONFIG_COMPILE_OPTIONS};/EHsc")
target_link_libraries(libcpmt${FLAVOR_SUFFIX} PRIVATE Boost::math libcpmt${FLAVOR_SUFFIX}_eha std_init_once_begin_initialize std_init_once_complete)
target_link_libraries(libcpmt${FLAVOR_SUFFIX} PRIVATE Boost::math libcpmt${FLAVOR_SUFFIX}_eha)
endfunction()

add_stl_statics("" "_ITERATOR_DEBUG_LEVEL=0" "${VCLIBS_RELEASE_OPTIONS}")
Expand Down
Binary file removed stl/aliases/amd64/std_init_once_begin_initialize.obj
Binary file not shown.
Binary file removed stl/aliases/amd64/std_init_once_complete.obj
Binary file not shown.
Binary file removed stl/aliases/arm/std_init_once_begin_initialize.obj
Binary file not shown.
Binary file removed stl/aliases/arm/std_init_once_complete.obj
Binary file not shown.
Binary file removed stl/aliases/arm64/std_init_once_begin_initialize.obj
Binary file not shown.
Binary file removed stl/aliases/arm64/std_init_once_complete.obj
Binary file not shown.
Binary file not shown.
Binary file removed stl/aliases/arm64ec/std_init_once_complete.obj
Binary file not shown.
Binary file removed stl/aliases/chpe/std_init_once_begin_initialize.obj
Binary file not shown.
Binary file removed stl/aliases/chpe/std_init_once_complete.obj
Binary file not shown.
75 changes: 0 additions & 75 deletions stl/aliases/generate.cmd

This file was deleted.

Binary file removed stl/aliases/i386/std_init_once_begin_initialize.obj
Binary file not shown.
Binary file removed stl/aliases/i386/std_init_once_complete.obj
Binary file not shown.
2 changes: 0 additions & 2 deletions stl/aliases/std_init_once_begin_initialize-arm64ec.txt

This file was deleted.

2 changes: 0 additions & 2 deletions stl/aliases/std_init_once_complete-arm64ec.txt

This file was deleted.

11 changes: 7 additions & 4 deletions stl/inc/mutex
Original file line number Diff line number Diff line change
Expand Up @@ -495,13 +495,14 @@ public:
};
#endif // _HAS_CXX17

#ifdef _M_CEE
#if defined(_M_CEE) || defined(_M_ARM64EC) || defined(_M_HYBRID) \
|| defined(__clang__) // TRANSITION, Clang doesn't recognize /ALTERNATENAME, not yet reported
#define _WINDOWS_API __stdcall
#define _RENAME_WINDOWS_API(_Api) _Api##_clr
#else // ^^^ _M_CEE // !_M_CEE vvv
#else // ^^^ use forwarders / use /ALTERNATENAME vvv
#define _WINDOWS_API __declspec(dllimport) __stdcall
#define _RENAME_WINDOWS_API(_Api) _Api
#endif // _M_CEE
#endif // ^^^ use /ALTERNATENAME ^^^

// WINBASEAPI
// BOOL
Expand All @@ -526,6 +527,8 @@ extern "C" _NODISCARD int _WINDOWS_API _RENAME_WINDOWS_API(__std_init_once_begin
extern "C" _NODISCARD int _WINDOWS_API _RENAME_WINDOWS_API(__std_init_once_complete)(
void** _LpInitOnce, unsigned long _DwFlags, void* _LpContext) noexcept;

extern "C" [[noreturn]] void __stdcall __std_init_once_link_alternate_names_and_abort() noexcept;

// #define RTL_RUN_ONCE_INIT_FAILED 0x00000004UL
// #define INIT_ONCE_INIT_FAILED RTL_RUN_ONCE_INIT_FAILED
_INLINE_VAR constexpr unsigned long _Init_once_init_failed = 0x4UL;
Expand All @@ -535,7 +538,7 @@ struct _Init_once_completer {
unsigned long _DwFlags;
~_Init_once_completer() {
if (_RENAME_WINDOWS_API(__std_init_once_complete)(&_Once._Opaque, _DwFlags, nullptr) == 0) {
_CSTD abort();
__std_init_once_link_alternate_names_and_abort();
}
}
};
Expand Down
5 changes: 0 additions & 5 deletions stl/msbuild/stl_base/stl.files.settings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
</BuildFiles>
</ItemGroup>

<ItemGroup Condition="'$(CrtBuildModelIsDll)' != 'true'">
<Lib Include="$(MSBuildThisFileDirectory)\..\..\aliases\$(BuildArchitecture)\std_init_once_begin_initialize.obj" />
<Lib Include="$(MSBuildThisFileDirectory)\..\..\aliases\$(BuildArchitecture)\std_init_once_complete.obj" />
</ItemGroup>

<Choose>
<When Condition="'$(CrtBuildModel)' != 'md'">
<!-- Only check exports of release, DLL, builds -->
Expand Down
2 changes: 0 additions & 2 deletions stl/msbuild/stl_post/msvcp_post.settings.targets
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
<Lib Include="$(CrtLibPath)\msvcprt$(BuildSuffix)_atomic_wait$(ClrLibSuffix).lib">
<IncludeInChameleonLib>false</IncludeInChameleonLib>
</Lib>
<Lib Include="$(MSBuildThisFileDirectory)\..\..\aliases\$(BuildArchitecture)\std_init_once_begin_initialize.obj" />
<Lib Include="$(MSBuildThisFileDirectory)\..\..\aliases\$(BuildArchitecture)\std_init_once_complete.obj" />
</ItemGroup>

<Import Project="$(VCToolsRootPath)\crt\crt_build.targets"/>
Expand Down
20 changes: 19 additions & 1 deletion stl/src/xonce2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <yvals_core.h>

#include <stdlib.h>
#include <synchapi.h>

// This must be as small as possible, because its contents are
Expand All @@ -11,7 +12,8 @@
// In particular, basic_string must not be included here.

// Provides forwarders for InitOnceBeginInitialize and InitOnceComplete for
// environments that can't use aliasobj, like /clr.
// environments that can't use /ALTERNATENAME.
// They were originally specific to /clr but are now used in other scenarios.

_EXTERN_C

Expand All @@ -24,4 +26,20 @@ int __stdcall __std_init_once_complete_clr(void** _LpInitOnce, unsigned long _Dw
return InitOnceComplete(reinterpret_cast<LPINIT_ONCE>(_LpInitOnce), _DwFlags, _LpContext);
}

[[noreturn]] void __stdcall __std_init_once_link_alternate_names_and_abort() noexcept {
_CSTD abort();
}

#if defined(_M_ARM64EC) || defined(_M_HYBRID)
// <mutex> uses the forwarder fallbacks for ARM64EC and CHPE.
#elif defined(_M_IX86)
#pragma comment(linker, "/ALTERNATENAME:__imp____std_init_once_begin_initialize@16=__imp__InitOnceBeginInitialize@16")
#pragma comment(linker, "/ALTERNATENAME:__imp____std_init_once_complete@12=__imp__InitOnceComplete@12")
#elif defined(_M_X64) || defined(_M_ARM) || defined(_M_ARM64)
#pragma comment(linker, "/ALTERNATENAME:__imp___std_init_once_begin_initialize=__imp_InitOnceBeginInitialize")
#pragma comment(linker, "/ALTERNATENAME:__imp___std_init_once_complete=__imp_InitOnceComplete")
#else // ^^^ known architecture / unknown architecture vvv
#error Unknown architecture
#endif // ^^^ unknown architecture ^^^

_END_EXTERN_C