[ARM32/Linux] stable default clang version for cross compilation
From last week, Arm32 (armhf) packages of Coreclr for Ubuntu 14.04 and Ubuntu 16.04 are published on myget. https://github.com/dotnet/coreclr/issues/8549#issuecomment-275252583.
However they can not be ran correcly when built with -O3 optimization, since default clang version used to build ARM32 binaries is 3.6 and it has problem with -O3 optimization as described at https://github.com/dotnet/coreclr/blob/master/Documentation/building/linux-instructions.md#how-to-enable--o3-optimization-level-for-armlinux. As a workaround, we are now using -O1 optimization for Linux arm32 Release instead of -O3 optimization.
Related issues: https://github.com/dotnet/core-setup/issues/790#issuecomment-275326153 https://github.com/dotnet/core-setup/issues/725#issuecomment-275324269
To address this clang problem,
- It is necessary to change default clang version when compiling Linux arm32 targets, i.e. using recent version of clang with fix
- Same clang should be used for all core-setup, coreclr and corefx.
- Test with packaging all core-setup, coreclr and corefx
This issue will track all issues regarding clang version for core-setup, coreclr and corefx.
One of possible candiadates is clang-3.9 and clang-3.9 will be tested for a while.
/cc: @gkhanna79 @janvorli @jyoungyun @hseok-oh @chunseoklee
FYI. Previous discussion on clang version was made at Core-Setup(https://github.com/dotnet/core-setup/issues/790#issuecomment-275326153) and CoreCLR(https://github.com/dotnet/coreclr/pull/9211)
Thank you @hqueue. Can you please link this issue at https://github.com/dotnet/core-setup/issues/725 as well?
@gkhanna79 I've already add this item in a "common" section :)
We have tested with clang 3.9 with -O3 optimization.
- For coreclr and corefx, no problem is found when cross building for Linux/ARM32 with clang 3.9 after enabling
-O3optimization. - For coreclr, no regression is found in unit test. All failing tests are also failed with current infra, i.e. clang-3.6 with -O1 option. Test is performed on rpi3 with ubuntu.16.04-arm.
- For core-setup, no problem is found when cross building for Linux/ARM32 with clang 3.9.
Threfore fortunately, we can simply choose clang 3.9 for cross compiling for Linux/ARM and don't have to investigate other version if there is no new requirement.
@janvorli @gkhanna79 What do you think of it?
If you agree I will make PRs to make clang-3.9 as a default compiler for cross compiling for Linux/ARM and also enable -O3 optimization for Release build for Linux/ARM.
Thanks for validating these scenarios @hqueue. To drive for simplicity, it will be good to have a single clang version we could use - not just for Arm but also for x64. Do you think 3.9 is good for x64 as well?
Aside from that, is 3.9 publicly released (and not under development)?
@gkhanna79 I also agree that using clang 3.9 for all dotnet platform will be ideal and I expect no problem using 3.9. However we need more verfication from developers of x64 dotnet for using 3.9, since I don't have much experience in x64 dotnet yet.
Aside from that, is 3.9 publicly released (and not under development)?
It seems that llvm 3.9.1 is officially released on Dec. 23, 2016 as in http://releases.llvm.org/. I've also installed stable 3.9.1 on host machine (Ubuntu 14.04) as described in http://apt.llvm.org/ as below.
# /etc/apt/sources.list
# 3.9
deb http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main
deb-src http://apt.llvm.org/trusty/ llvm-toolchain-trusty-3.9 main
$ wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
$ apt-get install clang-3.9
BTW We have to install clang-3.9 on CI machine before we merge PRs using clang 3.9 as a default, since CI also use default compilers.
@gkhanna79 I have recently changed CoreRT to use clang 3.9 by default too and the CI machines that CoreRT use were already updated to contain clang 3.9. So moving CoreCLR and other related projects to that version as well would be nice. We would need to update more VMs in the CI though, since for CoreRT, only Ubuntu 14.04 is used and so only those VMs were updated, as far as I know.
@hqueue Thanks for the details. Looks like http://apt.llvm.org/ also has links for 16.04 and 16.10. Is there a reason you used the above approach to install as opposed to the instructions in Install (stable branch) section?
@janvorli Thanks for the confirmation.
@gkhanna79 I think I followed the instrtuction in Install (stable branch) and Ubuntu section. We have to update /etc/apt/source.list to locate and install clang-3.9 with apt-get install clang-3.9. If not, apt-get can't locate clang-3.9 package.
@gkhanna79 As you may already know, arm32 binary is still built using clang 3.6 with -O1 optimization, not -O3. And I think it's same for the official pipeline build for arm32. (right?) Is is ok to use this approach for the official pipeline build which may be used for 2.0.0 release ? Or should we move to clang 3.9 for arm32 cross build and enable -O3 optimiozation to prepare 2.0.0 ? For other architectures, I'm not sure about whether it's stable for other architectures.
I think it would be the best to switch our build to clang 3.9 now all over the board.
If we're going to do this, we need to do it soon.
And I think it's same for the official pipeline build for arm32. (right?)
Yes, this is correct since official images do not carry clang 3.9. Before switching whole sale to 3.9, can you please help confirm that CoreCLR tests are passing with it for x64 as well? Once you can help confirm that, we can look into transitioning to 3.9.
For other architectures, I'm not sure about whether it's stable for other architectures.
@janvorli Have you validated that this works as expected for x64 on Linux (since on OSX we endup using whatever clang comes with XCode)?
@gkhanna79 I have not done a full validation yet. But I can do an easy way of validation - create a PR that makes clang 3.9 the default and let the lab run the tests. We already have clang3.9 installed in the lab for Ubuntu to support CoreRT builds.
@janvorli If you can give it a shot, that will be great and will help us get answers soon.
CoreCLR cross build (linux arm) depends on docker images: microsoft/dotnet-buildtools-prereqs:ubuntu1404_cross_prereqs_v3, microsoft/dotnet-buildtools-prereqs:ubuntu1604_cross_prereqs_v3
But these docker images look like don't have clang-3.9 yet.
@gkhanna79 my clang3.9 test build in the CI ran ok (with help from @mmitche to ensure that it is built on a VM that has clang3.9 installed), all the CoreCLR tests passed (except for the spanbench that's failing on all jobs now).
Thanks @janvorli. how about we bring this up in stages:
- Stage 1 - Update the Arm build definitions to carry clang 3.9 and transition the builds to it.
- Stage 2 - once (1) is stable, we update X64 docker images to use clang 3.9 as well.
With this, we could even stop after stage (1) and yet use -O3 across the board without switching x64 to 3.9, if required.
What do you think?
@gkhanna79 that sounds good to me. We would just need to make the clang3.9 the default optionally for arm.