Skip to content
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

Merged
merged 6 commits into from
Jul 1, 2022

Conversation

am11
Copy link
Member

@am11 am11 commented Jun 30, 2022

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.

@am11 am11 requested a review from MichalStrehovsky as a code owner June 30, 2022 16:53
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jun 30, 2022
@am11 am11 requested review from jkotas and janvorli June 30, 2022 16:53
@am11
Copy link
Member Author

am11 commented Jun 30, 2022

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 -p:StripSymbols=true .dbg file is not produced and nativelib1.so size is enlarges)

@@ -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>
Copy link
Member

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.

Copy link
Member Author

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. :)

Copy link
Member

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.

Copy link
Member

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.

Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

@janvorli janvorli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@jkotas
Copy link
Member

jkotas commented Jul 1, 2022

The test failure is Helix timeout - the test succeeded.

@jkotas jkotas merged commit 4591820 into dotnet:main Jul 1, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jul 31, 2022
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.

3 participants