-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use llvm-objcopy with StripSymbols=true and clang #71495
Conversation
Tested on linux-x64 with: $ mkdir ~/.dotnet7
$ curl -sSL https://aka.ms/dotnet/7.0.1xx/daily/dotnet-sdk-linux-x64.tar.gz | tar xzf - -C ~/.dotnet7
$ cat > nuget.config << EOF
<configuration>
<packageSources><add key="dotnet7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" /></packageSources>
</configuration>
EOF
$ alias dotnet7=~/.dotnet7/dotnet
# overwrite the two modified files in
# ~/.dotnet7/sdk/7.0.100-preview.7.22324.4/Sdks/Microsoft.DotNet.ILCompiler/build
$ dotnet7 new classlib -n nativelib1
$ dotnet7 publish nativelib1 -o dist -c Release --use-current-runtime -p:PublishAot=true -p:StripSymbols=true
$ ls -la dist
total 14496
drwxrwxr-x 2 am11 am11 4096 Jun 30 19:58 .
drwxrwxr-x 5 am11 am11 4096 Jun 30 19:58 ..
-rwxrwxr-x 1 am11 am11 4587888 Jun 30 19:58 nativelib1.so
-rwxrwxr-x 1 am11 am11 10240432 Jun 30 19:58 nativelib1.so.dbg (without |
@@ -21,6 +21,8 @@ The .NET Foundation licenses this file to you under the MIT license. | |||
<CppLinker>$(CppCompilerAndLinker)</CppLinker> | |||
<CppLibCreator>ar</CppLibCreator> | |||
<DsymUtilOptions Condition="'$(TargetOS)' == 'OSX'">--flat</DsymUtilOptions> | |||
<ObjCopyName Condition="'$(TargetOS)' != 'OSX' and '$(CppCompilerAndLinker)' != 'clang'">objcopy</ObjCopyName> | |||
<ObjCopyName Condition="'$(TargetOS)' != 'OSX' and '$(CppCompilerAndLinker)' == 'clang'">llvm-objcopy</ObjCopyName> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about the version suffix? On my Linux devbox, I don't have any version of llvm tools (including clang) without the suffix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good point.
Currently, with auto-detection, we only support toolchain selection without the version suffix in NativeAOT. On Ubuntu, for example, when we install clang/llvm from package manager, it installs a package called llvm-defaults, which installs llvm-objcopy (along other tools) in /usr/bin:
$ command -v llvm-objcopy
/usr/bin/llvm-objcopy
However, for versioned clang
or gcc
user can set a property -p:CppCompilerAndLinker=clang-10
, but for objcopy, we don't have it.
I can add support to set ObjCopyName
property externally similar to CppCompilerAndLinker
. But I think it is better if we implement the complete autodetection properly (by packaging init-compiler.sh
). That is in my TODO list. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add support to set ObjCopyName property externally similar to CppCompilerAndLinker
Yes, that would be good. We should always have an option to explicitly control these names and override what the auto-detection thinks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@am11 Thank you for the details, that makes sense. Let's keep this change as is and implement the version detection separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modulo @jkotas's comment, so let's add the ObjCopyName
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have changed it so it is set conditionally. -p:ObjCopyName=llvm-objcopy-10
or -p:ObjCopyName=/path/to/llvm-objcopy
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you!
src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Windows.targets
Outdated
Show resolved
Hide resolved
src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets
Show resolved
Hide resolved
The test failure is Helix timeout - the test succeeded. |
Make NativeAOT publishing adapt to changes made in #71446.
If llvm-toolchain is used for AOT compilation, the symbol stripping step will now use llvm-objcopy on Linux. Otherwise it will use binutils' (unprefixed)
objcopy
.