Freebsd Toolchain

Freebsd Toolchain

SEE TEXT ONLY FreeBSD Toolchain As with other BSD distributions, FreeBSD has the concept of a base system, an integrated kernel, and core userland, which are developed, tested, and released together by a common team. The userland includes the C lan- guage runtime, the build toolchain, basic system utilities, and some third- party libraries and applications. The toolchain includes the compiler and linker, which translate source code into executable objects, and related utilities for inspecting or modifying those objects. In addition to this base system, there’s a third-party software ecosystem man- aged through the FreeBSD ports tree and binary packages. Over 26,000 third- party software packages exist in the ports tree. For most of its history FreeBSD relied on the full GNU toolchain suite, includ- ing the GNU Compiler Collection (GCC) compiler and GNU binutils. They served the FreeBSD Project well from 1993 until 2007, when the GNU project migrated to releasing its software under the General Public License, version 3 (GPLv3). In contrast to version 2 of the license, GPLv3 places a number of new restrictions on software users, and FreeBSD developers and users found these objectionable. As a result, the GNU toolchain in FreeBSD was not updated to a new upstream version and quickly became outdated. BY Beginning shortly after that transition, a number of developers in the FreeBSD ED Project started updating components of the FreeBSD toolchain to modern, copy- free alternatives. Some aspects of the toolchain are architecture-dependent, and MASTE in general the tools described below apply to FreeBSD’s Tier-1 architectures. Compiler The LLVM project is a collection of modular and reusable components used to build compilers and other toolchain utilities. It began as a research project at the University of Illinois and has since grown to become a production-quality tool set used in proprietary and open-source software and academic settings. Clang is the C and C++ compiler included in the LLVM suite. 30 FreeBSD Journal We’ve experimented with Clang in FreeBSD (ABIs), other linker optimizations, debugging fea- since 2009, starting with a snapshot from the tures, and much faster link times. upstream project’s Subversion repository. When As with early experiments with Clang, LLD will first added, it was made available as an option to first be added to FreeBSD as an option and will facilitate testing and development, but it was not not be installed as the system linker enabled as the default compiler for some time. (/usr/bin/ld). It will be available by adding When FreeBSD 10 released in January 2014, it -fuse-ld=lld to the compiler’s command included Clang as the system compiler (that is, line arguments (for example, via the CFLAGS installed as /usr/bin/cc) for the 32- and 64- variable). bit Intel x86 architectures. It was later made the We’ve included LLD 3.9 alongside the Clang default for the 32-bit FreeBSD ARM port. The 64- 3.9 update and expect it to be available in bit ARM port began with Clang as the system FreeBSD-CURRENT in October or November compiler. 2016. It is expected to be added to FreeBSD 11.1 Clang includes some support for the MIPS and as well. PowerPC architectures, but is not yet capable of replacing the system compiler there; those archi- Binary Utilities tectures continue to use GCC. The toolchain includes a number of small binary FreeBSD 11 includes Clang 3.8.0, and work is utilities for inspecting or modifying object files, underway in FreeBSD-CURRENT to update to binaries, and libraries. These are tools that report Clang 3.9.0. information about an object, binary, or library, or transform an object’s contents or format. These Linker tools were historically provided by GNU binutils. The linker takes as input individual object files The ELF Tool Chain Project maintains BSD- produced by a compiler or assembler and links licensed implementations of essential compilation them into an executable binary or library. To date tools and libraries for working with ELF object we’ve used the GNU linker in FreeBSD, most files and binaries, and DWARF debugging infor- recently updated to version 2.17.50 in February mation. It began as part of the FreeBSD Project, 2011. This linker lacks link-time optimizations and but became a standalone project in order to facil- support for certain debugging features. itate collaboration with the wider open-source GNU ld in the base system also lacks support community. for AArch64 (arm64) and RISC-V, two CPU archi- For FreeBSD 11 we have migrated to ELF Tool tectures recently added to FreeBSD. Building Chain’s implementation of addr2line, FreeBSD for these currently requires the linker be c++filt, objcopy, nm, readelf, size, installed from the ports tree or as a package, in strip, and strings. The libelf and which case it will be used automatically. libdwarf libraries also come from ELF Tool Chain. The LLVM family of projects includes a linker: ELF Tool Chain also includes a version of LLD. It is a high-performance linker with support FreeBSD’s ar, brandelf, and elfdump utilities. for ELF, COFF, and Mach-O. Where possible, it We will migrate to those in the future if they gain maintains command-line and functional compati- compelling new features or improvements. bility with existing linkers such as GNU ld, but LLD’s authors are not constrained by strict com- Runtime Libraries patibility where it hampers performance or A number of libraries are required to provide run- desired functionality. time support for the toolchain. The compiler-rt Work began on LLD’s ELF support in July 2015 library comes from the LLVM project and includes and has progressed very quickly; it currently self- several components. Low-level target-specific hosts on several of LLVM’s supported architec- hooks required by GCC or Clang’s code genera- tures and includes almost all of the functionality tion are known as “builtins.” These are routines required to build the FreeBSD base system. that perform operations that the compiler will not In comparison with GNU ld, in FreeBSD LLD emit directly into the output object code. will provide AArch64 and eventually RISC-V sup- Compiler-rt includes sanitizer runtimes that port, full-program Link-Time Optimization (LTO), provide Clang’s runtime support for identifying support for new Application Binary Interfaces Sept/Oct 2016 31 erroneous software behaviour. AddressSanitizer Tracing (FBT) probes can have typed arguments (asan) detects out-of-bounds access to heap, when the corresponding executable or libraries stack, and globals, use-after-free and related are compiled with CTF. The FreeBSD base system errors, and double and invalid free. It is available build infrastructure includes support for compil- by adding -fsanitize=address to the com- ing with CTF with a setting in the piler’s command line. /etc/src.conf file. The UndefinedBehaviourSanitizer (ubsan) FreeBSD 11 also adds support for Statically catches undefined behaviour; that is, an opera- Defined Tracing (STD) probes in userland. A .d tion for which the language does not have speci- file containing probe definitions can be included fied behaviour. Examples include overflowing in the list of source files, and the build infrastruc- integer operations (such as addition and bit shift- ture will automatically generate a header contain- ing), division by zero, and using uninitialized vari- ing probe macros that can be referenced in ables. The -fsanitize=undefined com- source files. mand line argument enables ubsan. Clang includes other sanitizers in the upstream Future Work repository, including ThreadSanitizer for detecting Work is underway on a number of additional data races in multithreaded applications and toolchain components which will become avail- MemorySanitizer for detecting uninitialized reads. able in FreeBSD in the future. LLVM provides a Work is underway to make these available with code coverage tool llvm-cov, which can operate the system compiler in a later FreeBSD version. in a mode similar to GNU gcov, and can operate For C++ runtime support we use a combina- with Clang’s instrumentation-based profiling. tion of PathScale’s libcxxrt for low-level LLVM also provides an OpenMP runtime (libomp), Application Binary Interface (ABI) support. This an Application Programming Interface (API) for includes Run-Time Type Information (RTTI), excep- shared memory multiprocessing. tion handling, and thread-safe initializers. The With LLD as the linker, two GNU binutils tools C++ standard library is LLVM’s libc++. remain: the assembler (as) and objdump. There is currently no candidate to replace as. However, it Debugger is actually not required to build the FreeBSD base A replacement debugger also comes from the system on Tier-1 architectures: Clang’s integrated LLVM project: LLDB. As with the rest of LLVM, assembler is used to build assembly source files. LLDB is built as a set of reusable components, GNU as could simply be removed, or a GNU as- and builds on other parts of LLVM and Clang. compatible driver could be built from the inte- LLDB has access to a full Clang compiler, which it grated assembler. Objdump is also not required uses as the expression parser. This provides high by the base system build and could be removed. fidelity in interpreting the user’s expressions: LLDB LLVM provides an llvm-objdump that is currently is capable of parsing any expression valid in the limited in functionality, but will likely be a viable original source code being debugged. replacement in due course. LLDB is included in FreeBSD 11 for the 32- and Ongoing efforts in the FreeBSD community 64-bit ARM architectures, and 64-bit Intel and in the upstream Clang/LLVM project are (amd64). attempting to bring the Clang, LLD, and LLDB In addition to LLDB in the base system, the suite to the lower-tier FreeBSD architectures that GNU GDB debugger is available by building from are still using GCC today.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us