-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Build] Limit libunwind fake stdatomic/stdalign generation to Windows-target builds #127814
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,36 +2,41 @@ include(CheckCSourceCompiles) | |
| include(CheckIncludeFiles) | ||
| include(CheckFunctionExists) | ||
|
|
||
| if(CLR_CMAKE_HOST_WIN32) | ||
| if(MSVC) | ||
| # Our posix abstraction layer will provide these headers | ||
| set(HAVE_ELF_H 1) | ||
| set(HAVE_ENDIAN_H 1) | ||
|
|
||
| # MSVC compiler is currently missing C11 stdalign.h header | ||
| # Fake it until support is added | ||
| # Fake it until support is added. Place fakes under a msvc-shim | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Has an issue been filed?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, I haven't filed an issue yet, and I don't know if it was filed when the fakes were initially added. And it seems like Given this, should we pivot to cleaning up those stdalign.h and stdatomic.h fakes and trying to add |
||
| # subdir that is added to the include path only for libunwind's own | ||
| # compile (see libunwind_extras/CMakeLists.txt) and not for libunwind | ||
| # consumers (e.g. CoreCLR PAL when cross-compiling for Android), which | ||
| # would otherwise risk shadowing the real headers from the target | ||
| # sysroot. | ||
| check_include_files(stdalign.h HAVE_STDALIGN_H) | ||
| if (NOT HAVE_STDALIGN_H) | ||
| configure_file(${CLR_SRC_NATIVE_DIR}/external/libunwind/include/remote/win/fakestdalign.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/stdalign.h COPYONLY) | ||
| configure_file(${CLR_SRC_NATIVE_DIR}/external/libunwind/include/remote/win/fakestdalign.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/msvc-shim/stdalign.h COPYONLY) | ||
| endif (NOT HAVE_STDALIGN_H) | ||
|
|
||
| # MSVC compiler is currently missing C11 stdatomic.h header | ||
| check_c_source_compiles("#include <stdatomic.h> void main() { _Atomic int a; }" HAVE_STDATOMIC_H) | ||
| if (NOT HAVE_STDATOMIC_H) | ||
| configure_file(${CLR_SRC_NATIVE_DIR}/external/libunwind/include/remote/win/fakestdatomic.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/stdatomic.h COPYONLY) | ||
| configure_file(${CLR_SRC_NATIVE_DIR}/external/libunwind/include/remote/win/fakestdatomic.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/msvc-shim/stdatomic.h COPYONLY) | ||
| endif (NOT HAVE_STDATOMIC_H) | ||
|
mdh1418 marked this conversation as resolved.
|
||
|
|
||
| # MSVC compiler is currently missing C11 _Thread_local | ||
| check_c_source_compiles("void main() { _Thread_local int a; }" HAVE_THREAD_LOCAL) | ||
| if (NOT HAVE_THREAD_LOCAL) | ||
| add_definitions(-D_Thread_local=) | ||
| endif (NOT HAVE_THREAD_LOCAL) | ||
| else(CLR_CMAKE_HOST_WIN32) | ||
| else(MSVC) | ||
| check_include_files(elf.h HAVE_ELF_H) | ||
| check_include_files(sys/elf.h HAVE_SYS_ELF_H) | ||
|
|
||
| check_include_files(endian.h HAVE_ENDIAN_H) | ||
| check_include_files(sys/endian.h HAVE_SYS_ENDIAN_H) | ||
| endif(CLR_CMAKE_HOST_WIN32) | ||
| endif(MSVC) | ||
|
|
||
| check_include_files(link.h HAVE_LINK_H) | ||
| check_include_files(sys/link.h HAVE_SYS_LINK_H) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these changes needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, android is a cross building scenario on windows and in this case we want the else block to run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds like we need
CLR_CMAKE_TARGET_WIN32. We generally tend to use our own flags for consistency, which is why they are provided in the first place. :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use standard host/target conventions: https://gcc.gnu.org/onlinedocs/gccint/Configure-Terms.html
HOSTis meant to describe the platform where the binary is going to run. If you are cross-building binaries that are going to run on Android device, it should not be defined. If you are seeing CLR_CMAKE_HOST_WIN32 defined when building binaries that are going to run Android device, we may have a problem in the build setup.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That convention has three parts:
build,hostandtargetwhile we only havehostandtarget. In their convention host=null means host=build. We are trying host=null to mean the code is for foreign target (crossbuild).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think there are any others in the android path that I can see. There are some others lurking that would only be felt if you were targeting windows-like platforms.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went through a few build scenarios, and it looks like a clean android cross-build does not reproduce the bug, the values set during the build were:
It seems like I had some stale artifacts from either building CrossDac or building all subsets at somepoint, leading to the fake
stdatomic.hand affecting incremental android coreclr builds.So, if we want to prevent stale-state shadowing in mixed Windows/Android dev workflows, this msvc-shim isolation change would reduce someone else also hitting the issue in the description.
Otherwise, we can just expect folks to recognize the issue as a stale-state issue and clean their artifacts and close this PR.
Or look to do away with the fake stdalign.h + stdatomic.h altogether (#127814 (comment))