NativeAOT: LinkNative target fails with MSB4086 when NativeLib=Static and LinkerFlavor=lld
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 68/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- android, csharp
- Domain
- build-system
Research direction
Inspect Microsoft.NETCore.Native.targets around the LinkNative conditions and Microsoft.NETCore.Native.Unix.targets around _LinkerVersion detection. Reproduce a Static build with LinkerFlavor=lld, then verify both numeric comparisons are guarded consistently and the build no longer reports MSB4086.
Written by the indexing model from the issue text.
Description
This content was created with assistance from AI.
Description
When NativeLib=Static is set (to have ILC produce a .a archive instead of a shared library), the LinkNative target in Microsoft.NETCore.Native.targets fails with:
Microsoft.NETCore.Native.targets(351,96): error MSB4086: A numeric comparison was attempted on "$(_LinkerVersion)" that evaluates to "" instead of a number, in condition '$(LinkerFlavor)' == 'lld' and '$(_LinkerVersion)' > '12'"
Root Cause
In Microsoft.NETCore.Native.Unix.targets, the _LinkerVersion detection is correctly skipped when NativeLib=Static:
<!-- Line ~332: version detection is skipped for static builds -->
<Exec Command=""$(CppLinker)" -fuse-ld=lld -Wl,--version"
Condition="'$(LinkerFlavor)' == 'lld' and '$(NativeLib)' != 'Static'" ...>
However, in Microsoft.NETCore.Native.targets, the CustomLinkerArg item group inside LinkNative evaluates _LinkerVersion without the same NativeLib guard:
<!-- Line ~351: no NativeLib guard on this condition -->
<CustomLinkerArg Include="-Wl,-T,"$(NativeIntermediateOutputPath)sections.ld""
Condition="'$(LinkerFlavor)' == 'lld' and '$(_LinkerVersion)' > '12'" />
The same issue exists on line ~368:
<WriteLinesToFile ... Condition="... '$(LinkerFlavor)' == 'lld' and '$(_LinkerVersion)' > '12'" />
Since _LinkerVersion is empty (detection was skipped), the numeric comparison '' > '12' causes MSBuild error MSB4086.
When This Triggers
This triggers when:
NativeLib=Static(so version detection is skipped), ANDLinkerFlavor=lld(set automatically forandroid,linux-bionic, andfreebsdtargets)
This combination occurs when Android or other platforms set NativeLib=Static to take ownership of the final native link step (producing their own shared library from the ILC .o output), following the same pattern used by xamarin-macios.
Suggested Fix
Add '$(NativeLib)' != 'Static' to the conditions on lines ~351 and ~368, consistent with the guard on the version detection itself:
<CustomLinkerArg Include="-Wl,-T,"$(NativeIntermediateOutputPath)sections.ld""
Condition="'$(LinkerFlavor)' == 'lld' and '$(NativeLib)' != 'Static' and '$(_LinkerVersion)' > '12'" />
Alternatively, the version detection could default _LinkerVersion to 0 when skipped, so the comparison always succeeds safely.
Workaround
Clear LinkerFlavor before LinkNative runs:
<PropertyGroup>
<LinkerFlavor />
</PropertyGroup>
This must be done inside a target (not a static PropertyGroup) because the ILC Unix targets set LinkerFlavor in a static PropertyGroup that evaluates after the consumer's import.
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 589
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
agentic-workflows untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
area-System.Reflection blocking-clean-ci-optional Known Build Error os-mac-os-x untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
area-CodeGen-coreclr untriaged
Difficulty 1/5 Under an hour Newbie friendliness 92/100
-
agentic-workflows untriaged
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
area-VM-meta-mono untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
type/automation type/tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
t/bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
ci-failure-cause test-failure
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
area:auth FE mvp P3
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
klasolsson81/jobbliggaren#1788 ·