-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Identify OSArchitecture at run-time #60910
Conversation
Tagging subscribers to this area: @Anipik, @safern, @ViktorHofer Issue DetailsThe 32-bit .NET application running on 64-bit Unix OS reports same values from This PR fixes the issue by querying architecture info at run-time..
|
2764e77
to
e05245b
Compare
src/libraries/Native/Unix/System.Native/pal_runtimeinformation.c
Outdated
Show resolved
Hide resolved
src/libraries/Native/Unix/System.Native/pal_runtimeinformation.c
Outdated
Show resolved
Hide resolved
src/libraries/Native/Unix/System.Native/pal_runtimeinformation.c
Outdated
Show resolved
Hide resolved
What are the cases where this works vs. still does not work? For example, is this fix going to kick in when running arm64 under qemu on physical x64 machine? |
I extracted out this function in a standalone program and ran it in a few VMs, qemu/binfmt, libvirt environments. It seems to be reporting the true architecture of kernel (considering containers use host kernel unless multiarch is configured). e.g. with qemu/binfmt (or on Alpine host, $ ID=mcr.microsoft.com/dotnet-buildtools/prereqs:alpine-3.14-helix-arm32v7-20210910135806-8a6f4f3
$ docker run --platform linux/arm $ID \
sh -c 'curl -s http://sprunge.us/63eiY6 | \
clang -xc - -o /tmp/x && /tmp/x' outputs |
Qemu is trying to overwrite Why is this emulation not kicking? |
Qemu seems to be overwriting |
Ah ok, I misread your comment. I was expecting that this will return the underlying machine architecture when running on qemu. Is it correct that this change is only going to make difference in practice for Linux x86 binaries running on Linux x64 - because qemu is not involved in that case? |
Yes, that is the only difference. It will report x64 from dotnet x86 process running on x64 system. That is basically a direct emulation support in kernel (controlled by a build-time config |
Should we keep this under Linux x86 ifdef then? It does not have to be as generic as it is. |
Is there a reason why we shouldn't rely on run-time lookup?
|
The Windows implementation is specific to x86 on x64 emulation. It does not work for the new true emulation targets, like arm on x64. There is a different API for those. |
Correct. My understanding is this:
I think it is ok not to make any change for 2. and go against the wishes of underlying technology stack. Other platforms (python, go etc.) use the same approach AFAICT. |
src/libraries/Native/Unix/System.Native/pal_runtimeinformation.c
Outdated
Show resolved
Hide resolved
src/libraries/Native/Unix/System.Native/pal_runtimeinformation.c
Outdated
Show resolved
Hide resolved
src/libraries/Native/Unix/System.Native/pal_runtimeinformation.c
Outdated
Show resolved
Hide resolved
044ef9d
to
ab8f9e0
Compare
src/libraries/Native/Unix/System.Native/pal_runtimeinformation.c
Outdated
Show resolved
Hide resolved
src/libraries/Native/Unix/System.Native/pal_runtimeinformation.c
Outdated
Show resolved
Hide resolved
I still keep coming back to whether this change is an improvement. This API is fundamentally broken since it only handles subset of emulated OSes. Is there anything useful people can do with it outside Windows x86/x64? |
2e7a583
to
eb4567e
Compare
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 do think this API has value. I share Jan's concern around this thing being hard to get right predictively.
The way we deal with that is that we document the behavior and expectations for how the API changes over time.
If we encounter some new architecture we don't know about, we report unknown. Callers can decide to fallback to the process architecture if that's their preference. When we have a chance to update the API we can add a mapping for the new architecture.
If we encounter a new layer of emulation that lies to us, then we can say that we'll update in a later version to understand that emulation and report the correct result.
src/libraries/Native/Unix/System.Native/pal_runtimeinformation.c
Outdated
Show resolved
Hide resolved
This is not possible in the current design. The native function always reports one of the architecture which runtime supports.
OK, if we want to report the host OS architecture in case of emulation rather than "whatever underlying layer is reporting", i.e. output in #60910 (comment) is not what we want, then we need to find another way to handle qemu scenario. I don't think any other platform (python, golang, java etc.) walk this extra mile, so I am not clear about the motivation. |
ac8ce43
to
a63af79
Compare
...ries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.Windows.cs
Outdated
Show resolved
Hide resolved
|
||
s_osArchPlusOne = osArch + 1; | ||
|
||
Debug.Assert(osArch >= 0); |
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.
Is there any meed to moving this line? - It will be optimised out in Release/retail builds anyway during compilation.
a63af79
to
d092afd
Compare
...ries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.Windows.cs
Show resolved
Hide resolved
...ries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.Windows.cs
Outdated
Show resolved
Hide resolved
d092afd
to
abe8ec8
Compare
...ries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.Windows.cs
Outdated
Show resolved
Hide resolved
…pServices/RuntimeInformation.Windows.cs Co-authored-by: Jan Kotas <jkotas@microsoft.com>
...ries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.Windows.cs
Outdated
Show resolved
Hide resolved
…pServices/RuntimeInformation.Windows.cs
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.
LGTM. Thank you!
...ries/System.Private.CoreLib/src/System/Runtime/InteropServices/RuntimeInformation.Windows.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Jan Kotas <jkotas@microsoft.com>
Test failure is #68477 |
Per discussion offline, this needs a brief breaking change note. Essentially, documenting what @richlander observed here #73974 |
Submitted dotnet/docs#30894 |
The 32-bit .NET application running on 64-bit Unix OS reports same values from
RuntimeInformation.OSArchitecture
andProcessArchitecture
, rather than the run-time OS' actual architecture.This PR fixes the issue by querying architecture info at run-time..