LLVMLinux: Embracing the Dragon



Similar documents
Applying Clang Static Analyzer to Linux Kernel

RISC-V Software Ecosystem. Andrew Waterman UC Berkeley

C Programming Review & Productivity Tools

Valgrind BoF Ideas, new features and directions

RED HAT DEVELOPER TOOLSET Build, Run, & Analyze Applications On Multiple Versions of Red Hat Enterprise Linux

Developing Embedded Linux Devices Using the Yocto Project

Continuous Integration/Testing and why you should assume every change breaks your code

LLVM on IBM POWER processors A progress report

Developing Embedded Linux Devices Using the Yocto Project

Status and Direction of Kernel Development

IOTIVITY AND EMBEDDED LINUX SUPPORT. Kishen Maloor Intel Open Source Technology Center

Software configuration management

umps software development

Binary compatibility for library developers. Thiago Macieira, Qt Core Maintainer LinuxCon North America, New Orleans, Sept. 2013

Five standard procedures for building the android system. Figure1. Procedures for building android embedded systems

Version Control using Git and Github. Joseph Rivera

Fully Automated Static Analysis of Fedora Packages

Common Errors in C/C++ Code and Static Analysis

WIND RIVER DIAB COMPILER

gcc link time optimization and the Linux kernel Andi Kleen Intel OTC Apr 2013

Týr: a dependent type system for spatial memory safety in LLVM

Android Development: a System Perspective. Javier Orensanz

Compilers and Tools for Software Stack Optimisation

Version Control with Svn, Git and git-svn. Kate Hedstrom ARSC, UAF

QEMU, a Fast and Portable Dynamic Translator

Using Code Coverage Tools in the Linux Kernel

Going Linux on Massive Multicore

Android Renderscript. Stephen Hines, Shih-wei Liao, Jason Sams, Alex Sakhartchouk November 18, 2011

Release Notes for Open Grid Scheduler/Grid Engine. Version: Grid Engine

MOOSE-Based Application Development on GitLab

Frysk The Systems Monitoring and Debugging Tool. Andrew Cagney

CSC230 Getting Starting in C. Tyler Bletsch

kgraft Live patching of the Linux kernel

Common clock framework: how to use it

Version Control with Git. Kate Hedstrom ARSC, UAF

Virtual Servers. Virtual machines. Virtualization. Design of IBM s VM. Virtual machine systems can give everyone the OS (and hardware) that they want.

MatrixSSL Porting Guide

Yocto Project ADT, Eclipse plug-in and Developer Tools

Distributed Version Control

EMSCRIPTEN - COMPILING LLVM BITCODE TO JAVASCRIPT (?!)

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Introduction to Version Control

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

I Control Your Code Attack Vectors Through the Eyes of Software-based Fault Isolation. Mathias Payer, ETH Zurich

Embedded Linux Platform Developer

Development With ARM DS-5. Mervyn Liu FAE Aug. 2015

CS 377: Operating Systems. Outline. A review of what you ve learned, and how it applies to a real operating system. Lecture 25 - Linux Case Study

Using Intel C++ Compiler in Eclipse* for Embedded Linux* targets

Android Sensors This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. CC-BY Google

Linux Foundation Automotive Summit - Yokohama, Japan

Visualizing Information Flow through C Programs

RVDS 3.x with Eclipse IDE

Reminders. Lab opens from today. Many students want to use the extra I/O pins on

Data Types in the Kernel

Integer Set Library: Manual

Android Programming and Security

SQLITE C/C++ TUTORIAL

Pattern Insight Clone Detection

Research and Design of Universal and Open Software Development Platform for Digital Home

Cloud Computing Performance Benchmarking Report. Comparing ProfitBricks and Amazon EC2 using standard open source tools UnixBench, DBENCH and Iperf

Channel Access Client Programming. Andrew Johnson Computer Scientist, AES-SSG

NEON. Support in Compilation Tools. Development Article. Copyright 2009 ARM Limited. All rights reserved. DHT 0004A (ID081609)

NVIDIA CUDA GETTING STARTED GUIDE FOR MAC OS X

Developer Workshop Marc Dumontier McMaster/OSCAR-EMR

How To Write A Program In Anieme Frontend (For A Non-Programmable Language)

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer GIT

Developing tests for the KVM autotest framework

CPSC 491. Today: Source code control. Source Code (Version) Control. Exercise: g., no git, subversion, cvs, etc.)

RTI Monitoring Library Getting Started Guide

Project Discussion Multi-Core Architectures and Programming

How To Write Portable Programs In C

For a 64-bit system. I - Presentation Of The Shellcode

MontaVista Linux 6. Streamlining the Embedded Linux Development Process

MatrixSSL Developer s Guide

Fast Arithmetic Coding (FastAC) Implementations

Git Basics. Christian Hanser. Institute for Applied Information Processing and Communications Graz University of Technology. 6.

Version control with GIT

opensuse.org Build Service

Yocto Project Experience: Continuous Integration

Introducing PgOpenCL A New PostgreSQL Procedural Language Unlocking the Power of the GPU! By Tim Child

CS 33. Multithreaded Programming V. CS33 Intro to Computer Systems XXXVII 1 Copyright 2015 Thomas W. Doeppner. All rights reserved.

Cloud Computing Performance. Benchmark Testing Report. Comparing ProfitBricks vs. Amazon EC2

Yocto Project Eclipse plug-in and Developer Tools Hands-on Lab

Using Git for Project Management with µvision

Run-Time Type Checking for Binary Programs

Software Development Processes For Embedded Development A checklist for efficient development using open-source tools

Linux Powered Storage:

ANDROID DEVELOPER TOOLS TRAINING GTC Sébastien Dominé, NVIDIA

Leak Check Version 2.1 for Linux TM

Transcription:

LLVMLinux: Embracing the Dragon Presented by: Behan Webster ( lead) Presentation Date: 2014.08.22

Clang/LLVM LLVM is a Toolchain Toolkit (libraries from which compilers and related technologies can be built) Clang is a C/C++ toolchain

New Clang Benchmarks (compilation) Timed ImageMagick Compilation v6.8.1-10 Time To Compile Seconds, Less Is Better OpenBenchmarking.org GCC 4.8.2 60.35 SE +/- 0.36 GCC 4.9.0 RC1 60.59 SE +/- 0.04 LLVM Clang 3.5 20140413 29.61 SE +/- 0.14 14 28 42 56 70 Powered By Phoronix Test Suite 5.0.1 http://www.phoronix.com/scan.php?page=article&item=gcc49_compiler_llvm35&num=1

New Clang Benchmarks (execution) ebizzy v0.3 Records/s Seconds, More Is Better OpenBenchmarking.org GCC 4.8.2 42849 SE +/- 109.85 GCC 4.9.0 RC1 42950 SE +/- 44.08 LLVM Clang 3.5 20140413 43202 SE +/- 53.03 9000 18000 27000 36000 45000 Powered By Phoronix Test Suite 5.0.1 1. (CC) gcc options: -pthread -lpthread -O3 -march=native http://www.phoronix.com/scan.php?page=article&item=gcc49_compiler_llvm35&num=1

Other Interesting LLVM Related Projects Clang Static Analyzer Energy consumption analysis of programs using LLVM CUDA llvmpipe (Galium3D) OpenCL (most implementations are based on LLVM) Clang is one of the Android NDK compilers Renderscript in Android is based on LLVM Code transformation tools

The LLVMLinux Project Goals Fully build the Linux kernel for multiple architectures, using the Clang/LLVM toolchain Discover LLVM/Kernel issues early and find fixes quickly across both communities Upstream patches to the Linux Kernel and LLVM projects Bring together like-minded developers Enable the kernel community to do more in depth analysis of the kernel code

LLVMLinux Build/Test System Fetches, patches, builds, tests: clang, kernel, qemu, etc git clone http://git.linuxfoundation.org/llvmlinux.git cd llvmlinux/target/vexpress (or x86_64) make

Patched Mainline Kernel Tree A mainline kernel tree with all LLVMLinux patches applied on top is now available: git://git.linuxfoundation.org/llvmlinux/kernel.git Dated llvmlinux branches remotes/origin/llvmlinux-2014.07.30 The master branch is rebased regularly

Supported Architectures X86 (i586 and x86_64) ARM AARCH64 And now MIPS (Work in progress)

Linux-Next now has a branch which is pulled into Linux-Next git://git.linuxfoundation.org/llvmlinux/kernel.git remotes/origin/for-next Broader testing of our patches by more people Last step before being submitted to mainline

Improved Buildbot Farm New better buildbot master 4 slave build servers (2 more on the way) More CI builds for targets are in the works Configs for known good compiler versions and kernels

Other Avenues of Interest Clang Static Analysis of the Linux kernel Kernel specific Checkers (GSoC) Compiling the Android kernel and AOSP with clang Supporting Linaro LLVM team Adding clang support to yocto Building better tools based on LLVM for the kernel community

LLVMLinux Project Status LLVM/clang: All LLVMLinux patches for LLVM are Upstream Newer LLVM patches to support the Linux kernel are mostly being added by upstream maintainers Linux Kernel: Roughly 47 kernel patches for various arches LLVMLinux branch in linux-next

Kernel Patches Patches still working their way upstream Architecture all arm aarch64 x86_64 TOTALS Number of patches 13 10 16 8 47 Submitted 1 8 4 0 13

Kbuild Basic Kbuild support for clang and x86 has been upstreamed Specific support for ARM and aarch64 ready to be upstreamed

Integrated Assembly Status David Woodhouse added.code16 support for X86 ASM Renato Golin, Vicinius Tinti, Saleem Abdulrasool and Stepan Dyatkovskiy are working on fixing IA issues in clang to support the Linux ARM kernel code (and ultimately AARCH64) For now we disable the IA and use GNU as instead

Different option passing gcc passes -march to GNU as clang doesn't... (Bug submitted PR) -CFLAGS_aes-ce-cipher.o += -march=armv8-a+crypto +CFLAGS_aes-ce-cipher.o += -march=armv8-a+crypto -Wa,-march=armv8-a+crypto

extern inline: Different for gnu89 and gnu99 GNU89/GNU90 (used by gcc) Function will be inlined where it is used No function definition is emitted A non-inlined function may also be provided GNU99/C99 (used by clang) Function will be inlined where it is used An external function is emitted No other function of the same name may be provided. Solution? Use static inline instead. Only still an issue for ARM support for ftrace (submitted)

Attribute Order gcc is less picky about placement of attribute (()) clang requires it at the end of the type or variable -struct read_mostly va_alignment va_align = { +struct va_alignment read_mostly va_align = {

Named Registers Named registers for X86 kernel have been fixed in mainline kernel by Andi Kleen clang now supports using a globally named register for the stack pointer For ARM/AARCH64 move to using a global in asm/thread_info.h register unsigned long current_stack_pointer asm ("sp");

ARM percpu patch One of the uses of Named Registers in the ARM code is due to a deficiency in gcc. The new code which works with gcc fails in clang. Solution, provide routines for both, and choose at compile time Gcc: asm("mrc p15, 0, %0, c13, c0, 4" : "=r" (off) : "Q" (*sp)); Clang: asm("mrc p15, 0, %0, c13, c0, 4" : "=r" (off) : : "memory");

Section Mismatch Issues (MergedGlobals) By default clang merges globals with internal linkage into one: MergedGlobals Allows globals to be addressed using offsets from a base pointer Can reduce the number of registers used Modpost uses symbol names to look for section mismatches MergedGlobals breaks modpost (false positive section mismatches) Current solution: use -mno-global-merge to stop global merging Updates to modpost may allow this optimization to be enabled again

Deprecated clang options clang options have been deprecated -KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior) +KBUILD_CFLAGS += $(call cc-option, -fsanitize=undefined-trap) +KBUILD_CFLAGS += $(call cc-option, -fsanitize-undefined-trap-on-error)

ARM eabi support Clang emits code which uses the aeabi ARM calls which are implemented in compiler-rt (equivalient to libgcc) Compiler-rt doesn't easily cross compile yet... void aeabi_memcpy(void *dest, const void *src, size_t n) void aeabi_memmove(void *dest, const void *src, size_t n) void aeabi_memset(void *s, size_t n, int c)

Variable Length Arrays In Structs VLAIS isn't supported by Clang (undocumented gcc extension) char vla[n]; /* Supported, C99/C11 */ struct { char flexible_member[]; /* Supported, C99/C11 */ } struct_with_flexible_member; struct { char vlais[n]; /* Explicitly not allowed by C99/C11 */ } variable_length_array_in_struct; VLAIS is used in the Linux kernel in a number of places, spreading mostly through reusing patterns from data structures found in crypto

VLAIS Removal Example - struct { - struct shash_desc shash; - char ctx[crypto_shash_descsize(hash)]; - } desc; + char desc[sizeof(struct shash_desc) + + crypto_shash_descsize(hash)] CRYPTO_MINALIGN_ATTR; + struct shash_desc *shash = (struct shash_desc *)desc; unsigned int i; - desc.shash.tfm = hash; + shash->tfm = hash; (from crypto/hmac.c)

VLAIS Removal Example (cont.) (the missing pieces) #define ARCH_KMALLOC_MINALIGN alignof (unsigned long long) #define CRYPTO_MINALIGN ARCH_KMALLOC_MINALIGN #define CRYPTO_MINALIGN_ATTR attribute (( aligned (CRYPTO_MINALIGN))) struct shash_desc { struct crypto_shash *tfm; u32 flags; void * ctx[] CRYPTO_MINALIGN_ATTR; };

Status of VLAIS in the Linux Kernel USB Gadget patch is in mainline Mac80211 patch is in mainline Netfilter patch is in mainline Only the VLAIS patches for crypto are left: (apparmor, btrfs, dm-crypt, hmac, libcrc32c, testmgr)

How Can You Help? Make it known you want to be able to use Clang to compile the kernel Test LLVMLinux patches Report bugs to the mailing list Help get LLVMLinux patches upstream Work on unsupported features and Bugs Submit new targets and arch support Patches welcome

Embrace the Dragon. He's cuddly. Thank you http://llvm.linuxfoundation.org

Contribute to the LLVMLinux Project Project wiki page Project Mailing List http://lists.linuxfoundation.org/mailman/listinfo/llvmlinux http://lists.linuxfoundation.org/pipermail/llvmlinux/ IRC Channel #llvmlinux on OFTC http://llvm.linuxfoundation.org http://buildbot.llvm.linuxfoundation.org/irclogs/oftc/%23llvmlinux/ LLVMLinux Community on Google Plus