Skip to content

Fix Tizen linking flags used during ILCompiler build - #129844

Merged
MichalStrehovsky merged 1 commit into
dotnet:mainfrom
gbalykov:fix-tizen-link-args
Jun 30, 2026
Merged

MichalStrehovsky merged 1 commit into
dotnet:mainfrom
gbalykov:fix-tizen-link-args

Conversation

@gbalykov

Copy link
Copy Markdown
Member

Without this change linker flags set in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets in SetupOSSpecificProps do not consider tizen platform specifics, which are set in toolchain.cmake.

@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Jun 25, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib
See info in area-owners.md if you want to be subscribed.

@am11

am11 commented Jun 25, 2026

Copy link
Copy Markdown
Member

Looks good. Is it for cross-publish only or does it work on Tizen machine as well (assuming SDK works on Tizen)?

@gbalykov

Copy link
Copy Markdown
Member Author

Is it for cross-publish only or does it work on Tizen machine as well (assuming SDK works on Tizen)?

Currently I'm checking cross build case. CrossCompileArch is used for cross/native builds check in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets, however, CrossCompileArch is only set if _hostArchitecture != _targetArchitecture. This is not true for cross build to tizen x64, that's why there's no such check in this patch.

Without this change linker flags set in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
in SetupOSSpecificProps do not consider tizen platform specifics, which are set in toolchain.cmake.
@gbalykov
gbalykov force-pushed the fix-tizen-link-args branch from cb38d60 to 5460876 Compare June 26, 2026 14:58
@MichalStrehovsky

Copy link
Copy Markdown
Member

Currently I'm checking cross build case. CrossCompileArch is used for cross/native builds check in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets, however, CrossCompileArch is only set if _hostArchitecture != _targetArchitecture. This is not true for cross build to tizen x64, that's why there's no such check in this patch.

Re-reading this part, are you saying that it's only tizen x64 that has the problem and this is because we don't set CrossCompileArch (the TargetTriple property ends up being empty and we're not passing

<LinkerArg Include="--target=$(TargetTriple)" Condition="'$(TargetTriple)' != ''" Shim="true" />

If so, does adding --target fix this? The lib/lib64 directories are pretty standard and I'm surprised clang wouldn't be setting up the linker correctly if --target is passed. If that's the case, the fix would be around how we decide whether TargetTriple is needed.

@am11

am11 commented Jun 29, 2026

Copy link
Copy Markdown
Member

Cross-compiling linux-musl-x64, openbsd-x64 or freebsd-x64 on linux-x64 would infer cross build based on composite "target and host OS + arch combination are not same". Tizen is odd one out because we decided to identify. I don't think what we have in main is flawed, but rather, it's either:

  1. our calling "tizen" a "linux" is wrong because it's structurally different
  2. or we are confused that "tizen" is structurally different when it's not (it's just another distro with glibc)

If it's 2, then we shouldn't detect distros. There are over 600 linux distros and we will end up maintaining the database here. Best to figure out why we think tizen needs a different flag.

If it's 1. then we should just support tizen-x64 RID and treat it like linux-musl-x64, linux-bionic-x64 (while tizen is glibc based it's structurally different or different in "other ways").

@MichalStrehovsky

Copy link
Copy Markdown
Member

Cross-compiling linux-musl-x64, openbsd-x64 or freebsd-x64 on linux-x64 would infer cross build based on composite "target and host OS + arch combination are not same"

What I wonder is if SysRoot being provided should contribute to the decision about whether this is a crosscompilation.

E.g. what if we updated this line to also check if a SysRoot was provided:

<CrossCompileRid Condition="'$(_hostOS)' != '$(_originalTargetOS)' or '$(_hostArchitecture)' != '$(_targetArchitecture)'">$(RuntimeIdentifier)</CrossCompileRid>

@am11

am11 commented Jun 29, 2026

Copy link
Copy Markdown
Member

In our engineering infra (to build runtime), we set <SysRoot based on CrossBuild. There are two types of cross builds, one which use ROOTFS_DIR infra (like linux, freebsd, illumos, tizen etc.) and then there are those which don't (like osx, ios, android etc.). The latter group infer the cross build implicitly. Long time ago, Jan Vorli brought Android to same plan as the rest of the platforms, but then mono merge overwrote it and we have couple of hacks / weird conditions to make it work.

In BuildIntegration, we can make it all pinned to Sysroot and update these as well:

eng/common/native/LocateNativeCompiler.targets:      <SysRoot Condition="'$(CrossBuild)' == 'true'">$(ROOTFS_DIR)</SysRoot>
eng/targetingpacks.targets:    <SysRoot Condition="('$(CrossBuild)' == 'true' or '$(BuildArchitecture)' != '$(TargetArchitecture)') and '$(HostOS)' != 'windows'">$(ROOTFS_DIR)</SysRoot>

(needs testing)

TL;DR, it is not straight-forward CrossBuild=>Sysroot currently, but it can be done.

@gbalykov

Copy link
Copy Markdown
Member Author

Re-reading this part, are you saying that it's only tizen x64 that has the problem

Yes, only x64 tizen build has this problem. However, adding --target=x86_64-linux-gnu doesn't help, error is still the same.

Initially I also thought whether cross compilation can just be set based on presence of SysRoot, but decided to not do this since it will affect other platforms.

@MichalStrehovsky

Copy link
Copy Markdown
Member

In our engineering infra (to build runtime), we set <SysRoot based on CrossBuild. There are two types of cross builds, one which use ROOTFS_DIR infra (like linux, freebsd, illumos, tizen etc.) and then there are those which don't (like osx, ios, android etc.).

I meant more in the shipping native AOT targets. If one invokes the native AOT targets with a SysRoot, we probably should be in a "this is a crossbuild" mode as far as invoking the linker is concerned.

Yes, only x64 tizen build has this problem. However, adding --target=x86_64-linux-gnu doesn't help, error is still the same.

If that doesn't work, it kind of seems like the cross toolchain is broken. We already have a precedent for reading os-release elsewhere and this is now a fairly minimal change, so I'm okay merging it, but I still consider it suspicious.

(Now that I'm looking at it, I find the Alpine os-release precedent also suspicious because we know we're targeting Alpine from the RID and now we're constructing part of the Alpine triple from the RID and the other part from reading os-release. But that's also pre-existing so...)

@MichalStrehovsky
MichalStrehovsky merged commit 811a5bf into dotnet:main Jun 30, 2026
111 checks passed
@am11

am11 commented Jun 30, 2026

Copy link
Copy Markdown
Member

I meant more in the shipping native AOT targets. If one invokes the native AOT targets with a SysRoot, we probably should be in a "this is a crossbuild" mode as far as invoking the linker is concerned.

Point was, only changing that condition will break runtime CI because Sysroot and target os/arch !=host are not on same parity. Android invokes NDK provided compiler instead of host's and Sysroot isn't set, but at the same time we need to set triplet for Android.

I find the Alpine os-release precedent also suspicious because we know we're targeting Alpine from the RID and now we're constructing part of the Alpine triple from the RID and the other part from reading os-release.

That's because of a bug in clang driver that we had to use -alpine- (vendored) triplet on armv7 that doesn't work for non-Alpine linux-musl targets #101213.

@gbalykov

Copy link
Copy Markdown
Member Author

Thank you!

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview7 milestone Jun 30, 2026
eiriktsarpalis pushed a commit that referenced this pull request Jul 15, 2026
Without this change linker flags set in
src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
in SetupOSSpecificProps do not consider tizen platform specifics, which
are set in toolchain.cmake.
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 31, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants