Closed jonpryor closed 6 months ago
Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas See info in area-owners.md if you want to be subscribed.
Related: attempting to follow the NativeAOT+Bionic instructions at https://github.com/dotnet/runtime/blob/017593d90781d797df8b2241f6d1f83c236c442b/src/coreclr/nativeaot/docs/android-bionic.md from macOS + x64 results in similar errors described above:
% dotnet new console -o HelloBionic --aot
% cd HelloBionic
# the xamarin-android NDK install directory; update as appropriate…
% export PATH=$HOME/android-toolchain/ndk/toolchains/llvm/prebuilt/darwin-x86_64/bin:$PATH
% dotnet publish -r linux-bionic-arm64 -p:DisableUnsupportedError=true -p:PublishAotUsingRuntimePack=true
Results in the errors:
ld.lld : error : version script assignment of 'V1.0' to symbol '_init' failed: symbol not defined ld.lld : error : version script assignment of 'V1.0' to symbol '_fini' failed: symbol not defined clang-17 : error : linker command failed with exit code 1 (use -v to see invocation) $HOME/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.4/build/Microsoft.NETCore.Native.targets(367,5): error MSB3073: The command ""clang" "obj/Release/net8.0/linux-bionic-arm64/native/HelloBionic.o" -o "bin/Release/net8.0/linux-bionic-arm64/native/HelloBionic" -Wl,--version-script=obj/Release/net8.0/linux-bionic-arm64/native/HelloBionic.exports -Wl,--export-dynamic -gz=zlib -fuse-ld=lld $HOME/.nuget/packages/microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64/8.0.4/runtimes/linux-bionic-arm64/native/libbootstrapper.o $HOME/.nuget/packages/microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64/8.0.4/runtimes/linux-bionic-arm64/native/libRuntime.WorkstationGC.a $HOME/.nuget/packages/microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64/8.0.4/runtimes/linux-bionic-arm64/native/libeventpipe-disabled.a $HOME/.nuget/packages/microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64/8.0.4/runtimes/linux-bionic-arm64/native/libstdc++compat.a $HOME/.nuget/packages/microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64/8.0.4/runtimes/linux-bionic-arm64/native/libSystem.Native.a $HOME/.nuget/packages/microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64/8.0.4/runtimes/linux-bionic-arm64/native/libSystem.IO.Compression.Native.a $HOME/.nuget/packages/microsoft.netcore.app.runtime.nativeaot.linux-bionic-arm64/8.0.4/runtimes/linux-bionic-arm64/native/libSystem.Security.Cryptography.Native.OpenSsl.a --target=aarch64-linux-android21 -g -Wl,-rpath,'$ORIGIN' -Wl,--build-id=sha1 -Wl,--as-needed -pthread -ldl -lz -llog -lm -pie -Wl,-pie -Wl,-z,relro -Wl,-z,now -Wl,--eh-frame-hdr -Wl,--discard-all -Wl,--gc-sections -Wl,-T,"obj/Release/net8.0/linux-bionic-arm64/native/sections.ld"" exited with code 1.
(Speaking of reading comprehension…)
android-bionic.md has a Known issues section section, which has a much better & simpler fix:
<ItemGroup Condition="$(RuntimeIdentifier.StartsWith('linux-bionic'))">
<LinkerArg Include="-Wl,--undefined-version" />
</ItemGroup>
I've updated the original report to take my previous comment into consideration.
Yes, neither llvm-objcopy nor objcopy are in $PATH, but the first line "hides" the second; invalid linker name in argument '-fuse-ld=lld' looks like the "root" error, and doesn't really make sense by itself.
What's your build logging verbosity? I believe the error message you're seeing comes from this line, since that's the line that precedes the objcopy checks:
clang potentially erroring out is expected and handled, the logic just wants to know if it will fail. The output is logged with Low
output importance, so normally shouldn't be visible. Or can you attach a binlog (pass -bl
to the publish
line and grab the resulting .binlog in the current directory) so we know for sure where it's coming from?
@MichalStrehovsky asked:
What's your build logging verbosity?
"Default"; no verbosity specified. All commands were specified in the original comment:
% dotnet new classlib -n HelloBionicSharedLib
% cd HelloBionicSharedLib
% dotnet publish -c Release -r linux-bionic-arm64 -p:PublishAotUsingRuntimePack=true -p:PublishAot=true
can you attach a binlog
Attached.
The output is logged with Low output importance
That's not quite true; this line: https://github.com/dotnet/runtime/blob/9b088ab8287a77c52ff7c4ed6fa96be6d3eb87f1/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets#L214
sets Exec.StandardOutputImportance
, which controls the importance of stdout.
The "offending" clang : error : invalid linker name in argument '-fuse-ld=lld'
message is written to stderr.
Additionally, it contains the string "error", which means that the default "error warning format" will detect this as an error.
Locally, if I set Exec.IgnoreStandardErrorWarningFormat
=true, then the clang: error: …
line becomes a non-error message. However, it's still printed:
# with local patch to add IgnoreStandardErrorWarningFormat=true:
% dotnet publish -c Release -r linux-bionic-arm64 -p:PublishAotUsingRuntimePack=true -p:PublishAot=true
MSBuild version 17.9.8+b34f75857 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
HelloBionicSharedLib -> /private/tmp/HelloBionicSharedLib/bin/Release/net8.0/linux-bionic-arm64/HelloBionicSharedLib.dll
clang: error: invalid linker name in argument '-fuse-ld=lld'
/Users/jon/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.4/build/Microsoft.NETCore.Native.Unix.targets(236,5): error : Symbol stripping tool ('llvm-objcopy' or 'objcopy') not found in PATH. Try installing appropriate package for llvm-objcopy or objcopy to resolve the problem or set the StripSymbols property to false to disable symbol stripping. [/private/tmp/HelloBionicSharedLib/HelloBionicSharedLib.csproj]
If the idea is to entirely remove clang: error: …
from the default output verbosity, then you also need to set StandardErrorImportance="Low"
, a'la this patch:
diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
index 7441f7da0f6..575caae39ae 100644
--- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
+++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
@@ -285,7 +285,7 @@ The .NET Foundation licenses this file to you under the MIT license.
<Error Condition="'$(_WhereLinker)' != '0' and '$(CppCompilerAndLinkerAlternative)' == '' and '$(_IsApplePlatform)' != 'true'"
Text="Requested linker ('$(CppLinker)') not found in PATH." />
- <Exec Command=""$(CppLinker)" -fuse-ld=lld -Wl,--version" Condition="'$(LinkerFlavor)' == 'lld'" IgnoreExitCode="true" StandardOutputImportance="Low" ConsoleToMSBuild="true">
+ <Exec Command=""$(CppLinker)" -fuse-ld=lld -Wl,--version" Condition="'$(LinkerFlavor)' == 'lld'" IgnoreExitCode="true" StandardOutputImportance="Low" StandardErrorImportance="Low" IgnoreStandardErrorWarningFormat="true" ConsoleToMSBuild="true">
<Output TaskParameter="ExitCode" PropertyName="_LinkerVersionStringExitCode" />
<Output TaskParameter="ConsoleOutput" PropertyName="_LinkerVersionString" />
</Exec>
Thank you! The binlog confirms that it comes from that line. The patch in your comment looks good to me - would you mind submitting a PR with it? I can do it myself, but I thought that since you already did the work, I shouldn't steal your credit.
@MichalStrehovsky: PR filed as: https://github.com/dotnet/runtime/pull/102000
This doesn't work because the
$(RuntimeIdentifier)
comparison is wrong, but if we fix that:
It was later corrected https://github.com/dotnet/runtime/issues/92272#issuecomment-2041640782 and afterwards the whole thing was removed in https://github.com/dotnet/runtime/pull/100755. The docs suggest this workaround for .NET 8 https://github.com/dotnet/runtime/blob/0fb0188a137f3d53a2ebd719d7a684327938609a/src/coreclr/nativeaot/docs/android-bionic.md#known-issues
@am11: I later noticed that.
The current problem is that the clang: error: …
output shouldn't be emitted by default, as it's a "useless" error message which misleads developers.
PR #102000 attempts to improve its behavior.
I'm closing as this is expected based on our documentation: we do not support cross-os publishing with Native AOT. https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/cross-compile has the information.
Description
Trying to use NativeAOT to build a linux-bionic-arm64 shared library from macOS does not work out of the box.
Reproduction Steps
Expected behavior
Above
dotnet publish
should produce a.so
file.Actual behavior
Yes, neither
llvm-objcopy
norobjcopy
are in$PATH
, but the first line "hides" the second;invalid linker name in argument '-fuse-ld=lld'
looks like the "root" error, and doesn't really make sense by itself.The second line is actually explanatory, if you get past reading the first. (Yes, reading comprehension is hard. Regardless, error messages should be actionable, and the first line is not actionable.)
If we fix that up:
…then it still fails to build:
https://github.com/dotnet/runtime/issues/92272#issuecomment-1732352537 suggests adding the following snippet to the
.csproj
:This doesn't work because the
$(RuntimeIdentifier)
comparison is wrong, but if we fix that:…then it still fails to build:
Regression?
No.
Known Workarounds
A cause of the original
ld.lld : error : version script assignment of 'V1.0' to symbol '_init' failed: symbol not defined
is that none of the.a
files used in the link command provide that symbol. Perhaps one of them should?In the meantime,
android-bionic.md
has a Known issues section which suggests adding a-Wl,--undefined-version
linker argument.Update
HelloBionicSharedLib.csproj
to end with:then add
HelloBionicSharedLib.targets
to theHelloBionicSharedLib
directory with contents:and the
dotnet publish
command now succeeds without error, producing abin/Release/net8.0/linux-bionic-arm64/publish/HelloBionicSharedLib.so
artifact.Configuration
.NET Configuration:
I have no idea if it's specific to this configuration.
Other information
No response