Skip to content

Conversation

@AaronRobinsonMSFT
Copy link
Member

@AaronRobinsonMSFT AaronRobinsonMSFT commented Oct 26, 2025

The clang and gcc tool chains defines 'unix' during compilation - clang doesn't on macOS. This means that during the data contract generation the "unix" string was converted to "1" and interpreted as "windows". See ./src/mono/browser/emsdk/emscripten/emcc -dM -E - < /dev/null | grep unix or clang -dM -E - < /dev/null | grep unix on a linux distro.

The first step is to create a specific OS for the browser and then make all string definitions case sensitive so the "unix" define doesn't convert. We also place some defensive checks in place for the OS names that aren't all that unique either.

Alternative 1 Set the enum values as opposed to the "string" names - "1" as opposed to "Windows". This would be more difficult to maintain, but unlikely to be conflicting defines.

Alternative 2 Define the RuntimeInfoOperatingSystem values to not be low values so they would rarely resolve to "valid" enumeration values. This would create easy to find failures at run-time.

The Emscripten tool chain defines 'unix' during compilation.
This meant that during the data contract generation the "unix"
string was converted to "1" and interpreted as "windows".
See `./src/mono/browser/emsdk/emscripten/emcc -dM -E - < /dev/null | grep unix`.

The fix here is to create a specific OS for the browser and
have that run first. Place some defensive checks in place
for the other OS names that aren't all that unique either.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a bug where the Emscripten toolchain's definition of unix during compilation caused incorrect operating system detection in the data contract generation, making "unix" resolve to "1" which was then interpreted as "windows". The fix introduces a specific Browser operating system value and reorders the OS detection to check for browser first, while adding defensive compile-time checks for all OS name defines.

Key Changes:

  • Added Browser as a new RuntimeInfoOperatingSystem enum value
  • Changed OS comparisons from == Unix to != Windows to handle the new Browser OS
  • Added compile-time checks to detect and fail early if OS names are defined as macros

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
datadescriptor.inc Added Browser OS target detection (checked first), defensive #error directives for OS name defines
IRuntimeInfo.cs Added Browser enum value to RuntimeInfoOperatingSystem
SOSDacImpl.cs Changed condition from == Unix to != Windows to handle Browser OS
X86Unwinder.cs Changed Unix ABI detection from == Unix to != Windows
AMD64Unwinder.cs Changed Unix detection from == Unix to != Windows

This hopefully avoids the common case of defining
unix on many compilers.
@AaronRobinsonMSFT AaronRobinsonMSFT changed the title Handle emscripten define of "unix" during compilation Handle clang/gcc defining "unix" during compilation Oct 26, 2025
@kg
Copy link
Member

kg commented Oct 26, 2025

Apparently specifying a standard like c99 will suppress definition of the unix keyword, but it's probably for the best to handle it explicitly like you're doing here.

@kg
Copy link
Member

kg commented Oct 26, 2025

LGTM but will leave the green check to someone who knows cdac better

Copy link
Member

@max-charlamb max-charlamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change looks reasonable to me.

@AaronRobinsonMSFT
Copy link
Member Author

Apparently specifying a standard like c99 will suppress definition of the unix keyword, but it's probably for the best to handle it explicitly like you're doing here.

Oh didn't realize that. I agree I don't think it should change the defensive checks made in this PR, but it is good to know - Thanks!

@AaronRobinsonMSFT AaronRobinsonMSFT enabled auto-merge (squash) October 26, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants