Skip to content

Fix linking flags used during ILCompiler build#17043

Closed
gbalykov wants to merge 1 commit into
dotnet:mainfrom
gbalykov:fix-cross-build-linker-args
Closed

Fix linking flags used during ILCompiler build#17043
gbalykov wants to merge 1 commit into
dotnet:mainfrom
gbalykov:fix-cross-build-linker-args

Conversation

@gbalykov

Copy link
Copy Markdown
Member

Linker flags set in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets in SetupOSSpecificProps do not consider platform specifics, which are set in toolchain.cmake. At the same time, LocateNativeCompiler in ./eng/toolAot.targets does similar job to get linker, and now GetCrossToolchainInfoAot in ./eng/toolAot.targets does same to get linker flags based on toolchain.cmake.

toolchain.cmake is already used this way in src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj

Related PR: dotnet/dotnet#6802

Linker flags set in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets in SetupOSSpecificProps do not consider
platform specifics, which are set in toolchain.cmake. At the same time, LocateNativeCompiler in ./eng/toolAot.targets does similar job
to get linker, and now GetCrossToolchainInfoAot in ./eng/toolAot.targets does same to get linker flags based on toolchain.cmake.

toolchain.cmake is already used this way in src/libraries/System.Runtime.InteropServices/tests/TestAssets/NativeExports/NativeExports.csproj
@gbalykov

Copy link
Copy Markdown
Member Author

cc @am11 @DamianEdwards @akoeplinger

@am11

am11 commented Jun 24, 2026

Copy link
Copy Markdown
Member

Can you show the error and which runtime commit you were trying with (latest main in runtime should have all the changes which we have here)? This is exactly what we had before, so I'm not sure how is it broken.

Related PR: dotnet/dotnet#6802

That PR moved the code to a shared location without changing the logic except for include semantics. It's unclear what has it broken that we are fixing here.

@gbalykov

Copy link
Copy Markdown
Member Author

Can you show the error and which runtime commit you were trying with (latest main in runtime should have all the changes which we have here)? This is exactly what we had before, so I'm not sure how is it broken.

Sorry for confusion, this is not a newly introduced issue. dotnet/dotnet#6802 is related only in sense that it moves similar logic to eng/common/native/LocateNativeCompiler.targets, and changes should get here and not in runtime repo. Actually, this issue is present in release/10.0 branch of runtime too.

Error below happens during tizen cross build, because tizen rootfs requires additional linker flags, which are specified in toolchain.cmake.

  Generating native code
ld.lld : error : /home/runtime/.tools/rootfs/x64/usr/lib/../lib64/libc.so:5: unable to find libc.so.6 [/home/runtime/src/coreclr/tools/aot/ILCompiler/ILCompiler_publish.csproj]
  >>> GROUP ( libc.so.6 libc_nonshared.a  AS_NEEDED ( ld-linux-x86-64.so.2 ) )
  >>>         ^

@am11

am11 commented Jun 24, 2026

Copy link
Copy Markdown
Member

Thanks for the clarification.

because tizen rootfs requires additional linker flags

The linker flags in LocateNativeCompiler is basically just to capture a high-level "which compiler and which linker to use" (name/path and version). The actual linker flags per-platform are coded in runtime/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets. All other platform's cross-build rootfs are mimicking the actual OS structure, so whether we are publishing an AOT app locally on the platform or cross-publishing via this rootfs (or any other "standard-looking" cross-build toolchain), it works. Is tizen rootfs following the structure of original operating system? If so, we can just encode them in Microsoft.NETCore.Native.Unix.targets like we have for FreeBSD, OpenBSD etc.

@gbalykov

Copy link
Copy Markdown
Member Author

Is tizen rootfs following the structure of original operating system?

Yes

If so, we can just encode them in Microsoft.NETCore.Native.Unix.targets like we have for FreeBSD, OpenBSD etc.

There would be some duplication in toolchain.cmake and src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets. Maybe GetCrossToolchainInfoAot can be called in case of native build too (currently it has cross build check), then FreeBSD, OpenBSD etc. won't need explicit -L flags in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets.

Another problem I see with this is that _targetOS is just linux in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets, not tizen.

@am11

am11 commented Jun 24, 2026

Copy link
Copy Markdown
Member

We already have duplication in BuildIntegration, because we ship it in nuget package for PublishAot, that's why we were very careful about depending on anything outside the directory (except for LocateNativeCompiler for .NET CI/CD minimal overrides).

_targetOS is just linux in src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets, not tizen.

We can sub-classify Tizen like this https://github.com/dotnet/runtime/blob/5e3dadb4a2b39e6e32127ecd0038854a338773e7/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets#L63.

@gbalykov

Copy link
Copy Markdown
Member Author

Thanks for explanation, I'll update based on your suggestions

@gbalykov

Copy link
Copy Markdown
Member Author

Closing this in favor of dotnet/runtime#129844

@gbalykov gbalykov closed this Jun 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants