LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of...
Transcript of LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of...
![Page 1: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/1.jpg)
LLVMLinux for the Real World
Bryce Adelstein-Lelbach, LSU Undergraduate
llvm.linuxfoundation.org
![Page 2: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/2.jpg)
Overview
• I ask you some questions
• Introduction to LLVM and Clang
• History of the LLVMLinux project
• Applications of LLVMLinux
– Diagnostics
– Source Transformation
– Cross Compilation
• You ask me some questions
llvm.linuxfoundation.org 2
![Page 3: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/3.jpg)
Have you ever used a search-and-replace tool to update deprecated or incorrect code?
How big was the codebase?
llvm.linuxfoundation.org 3
![Page 4: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/4.jpg)
Have you ever manually performed a tedious update of deprecated or incorrect code?
How big was the codebase?
llvm.linuxfoundation.org 4
![Page 5: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/5.jpg)
Raise your hand if you’ve used a cross compiler
llvm.linuxfoundation.org 5
![Page 6: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/6.jpg)
LLVM and Clang
• LLVM
– A modular and extensible compiler framework
– Uses a common intermediate representation known as LLVM IR
• Clang
– An LLVM frontend for C, C++ and other C-like languages
– Highly standard compliant
– GCC compatible
llvm.linuxfoundation.org 6
Open Source (BSD style license)
![Page 7: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/7.jpg)
Library Architecture
• Both LLVM and Clang are designed with a library architecture – Instead of traditional, monolithic drivers, LLVM
and Clang provide a series of libraries which can be used to implement compiler tools
• This design makes LLVM and Clang modular and extensible
• Facilitates the development of domain-specific solutions to toolchain problems
llvm.linuxfoundation.org 7
![Page 8: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/8.jpg)
Beginning
• October, 2010 – First working Clang-compiled Linux kernel
• December 2010 – Most of the major initial bugs are resolved
• April, 2011 – Work from initial collaborators is unified on Github
llvm.linuxfoundation.org 8
![Page 9: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/9.jpg)
Linux Foundation
• May, 2011 – Linux Foundation begins supporting development
• May, 2012 – All existing work is consolidated under the LLVMLinux project (hosted by LF)
llvm.linuxfoundation.org 9
![Page 10: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/10.jpg)
Diagnostics
• Superb diagnostics
– Column numbers for all diagnostics
– Caret/Point diagnostics
• Range highlighting
– Intelligent typedef preservation and unwrapping
– Macro expansion
– Wide range of CFG-based warnings
• Example: –Wtautological-compare warns about checking if an unsigned integer is less than 0
llvm.linuxfoundation.org 10
![Page 11: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/11.jpg)
Diagnostics
llvm.linuxfoundation.org 11
Suggested fix
Carrot and range
Source line Flag
Source location
Diagnostic type
![Page 12: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/12.jpg)
Static Analyzer
• The Clang Static Analyzer is a tool built with the Clang libraries that detects bugs – Supports plugins
• A static analyzer uses techniques similar to those used to generate compiler warnings – Static analyzers perform far more exhaustive
analysis
– Static analyzers can detect bugs that would typically only manifest at runtime
llvm.linuxfoundation.org 12
![Page 13: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/13.jpg)
Static Analyzer
llvm.linuxfoundation.org 13
![Page 14: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/14.jpg)
Fixits
• Clang’s diagnostic framework can suggest solutions (fixits) to common syntactical mistakes and even simple semantic errors
– Fixits can fix the source files itself
– Can copy the source files and apply the fixes to the copy
• Fixits are the first iteration of a still evolving framework for automatic refactoring
llvm.linuxfoundation.org 14
![Page 15: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/15.jpg)
Refactoring
• Clang developers are currently developing infrastructure for automatic source refactoring
• Automatic refactoring with a compiler framework is more powerful than refactoring with regex-based tools – Most refactoring tools only refactor syntax, Clang-
based tools can refactor semantics and syntax
• The framework could potentially be utilized to replace tools like coccinelle with something more robust
llvm.linuxfoundation.org 15
![Page 16: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/16.jpg)
Universal Driver
• Clang has, from the start, been capable of generating code for multiple platforms
• The universal driver model is a new initiative which Clang is pursuing to make cross compiling easier – The basic idea is to have one driver application for all
targets
– The user would specify a target via a command line option and the driver would handle the rest
• This technique would simplify the deployment of Linux to embedded platforms such as smartphones and tablets
llvm.linuxfoundation.org 16
![Page 17: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/17.jpg)
Acknowledgments
• Linux Foundation – Mike Woster – Jan-Simon Möller – Behan Webster
• Early Colloborators – PaX Team – Alp Toker – Török Edwin – Sedat Dilek
• Mark Charlebois • Various LLVM/Clang developers • Various Linux kernel developers
llvm.linuxfoundation.org 17
![Page 18: LLVMLinux for the Real World · Universal Driver •Clang has, from the start, been capable of generating code for multiple platforms •The universal driver model is a new initiative](https://reader034.fdocuments.us/reader034/viewer/2022042221/5ec7f07bf1986c3a96455405/html5/thumbnails/18.jpg)
llvm.linuxfoundation.org 18