LLVM daily talk of forty-one assemble a complete tool chain

EDITORIAL words: This is an official document LLVM, the English document Address:

Assembling a Complete Toolchain

When we read the document before, after another translation of some, the weekend took some time to sort out this article. Because they were readily turned, and then finished the translation, but also do not want to take the time to be considered, so there are a lot of words are not so strict.

LLVM official documents in great detail, what need is best to directly read the official English documents. This casually own translation of documents released, is hoping to give some students do not want to read English documents that reference.

------------------------------------------------------------------------------------

Assembling a complete tool chain

Introduction:

Clang is just a component of the programming language C series complete tool chain. In order to form a complete tool chain, you need some additional tools and runtime. Clang is designed to be interoperable platforms and target existing tools and libraries, and LLVM project provides many such alternative components.

This document describes a complete tool chain necessary and optional components, provided where to get these components, and provides support for version and limitations of each option.

caveat:

Clang configuration described in this document is now on the POSIX-compatible operating systems and the GCC and the clang drive. When the target platform becomes a Windows system compatible with MSVC clang-cl drive, some of the details will be different.

tool

Complete the process of compiling a series of C programming language, usually call the next line of tools, some tools will be omitted in some cases compiled.

  • Pretreatment: This action shows the pre-C: Initiation #includes and #defeins. -E identification allows Clang stop after this step.
  • Parsing: This syntax analysis and semantic analysis, the source and the establishment of a source-level intermediate representation ( "AST"), produced a precompiled header (precompiled header, PCH), preamble, or pre-compiled module file (Precompiled module file, PCM), which depends on the input. -precompile identification allows Clang stop after this step. If the input is a header file, which is the default setting (Clang stop after this step).
  • Generating intermediate code: This intermediate source-level identification into a special intermediate representation optimizer (the IR); for Clang, which is LLVM intermediate representation. -emit-llvm identification allows Clang stop after this step. If -S and together, can generate text Clang LLVM IR; in addition, it may generate a binary form of LLVM IR.
  • The compiler back-end: This indicates to the title intermediate platform-specific assembler code. -S identification allows Clang stop after this step.
  • Assembler: This target platform-specific assembler code into machine code for the target specific. -c identification allows Clang stop after this step.
  • Linker: This will more object files into one image file (an executable or a shared object file).

Clang provides all the parts except for the linker. When a plurality of steps are executed when the same tool, those steps usually are fused together, to avoid intermediate file.

When the output of a step in the above step as an input, then this step will be before the step is skipped. (For example, a .s file input will be compiled and linked.)

Clang driver can be - ### identifies the call (this parameter is required in most shell escaped), in the end to see what the command will be run above step, without running these commands. -v (verbose) identifies the print command to run on the basis of the command is run on.

Clang front end

Clang front end (clang -cc1) used to compile the C series of programming languages. The front end of the command line interface is considered to be an implementation detail, deliberately does not provide an external interface, and can be used without modification reminded subjective.

Other front-end programming languages

Clang can accept input non-C language series of programming languages. In this case, the input need to go through an external compiler tool. Now Supported languages ​​are:

  • There are (-x there, .ad [bs])
  • Fortran (-x f95, .f, .f9[05], .for, .fpp, case-insensitive)
  • Java (-x java)

In each example, the GCC will be called to compile input.

Assembler

May be used Clang LLVM integrated assembler, or tools associated with an external system (for example, on assembler GUN the GNU operating system) to generate machine code from the assembly language. By default, Clang LLVM using integrated assembler on all supported target platforms. If you wish to use an alternative system assembler LLVM integrated assembler, use -fno-intergrated-as option.

Linker

Clang can be configured to use at several different linker:

  • GNU ld
  • GNU gold
  • LLVM’s lld
  • MSVC’s link.exe

Lld natural link optimization support, and the use of gold when you can link via a plug-in support.

Different target platforms have different default linker, which linker is provided by -fuse-ld = <linker name> identification rewritten.

Runtime library

C family of programs need a lot of different run-time libraries to provide different levels of support. Clang implicitly links each runtime library to achieve a suitable, this choice is often based on the target platform selected by default, or by -rtlib = and -stdlib = This identifies an explicit choice.

Set link library, language-dependent model. For as a result, then when you link a C ++ program, in order to ensure that the C ++ runtime library is provided, you need to use clang ++.

note:

Perhaps there are other components to achieve these, the following part of this document does not describe them. Please let us know how these and other implementations are Clang work together, so that we may add these parts to this list.

Compiler Runtime

Compiler run-time library provides a function definition, these functions are those compilers to support native underlying hardware supported operations (e.g., 128-bit integer multiplication) does not implicitly invoked, inline expansion of these operations It is considered to be inappropriate.

The default runtime library is related targets. In the GCC is the main target platform compiler, Clang is now used by default libgcc_s. On most other target platform is used by default compiler-rt.

compiler-rt(LLVM)

LLVM compiler run-time library provides a set of library functions of a complete run-time, this collection contains all the functions Clang will implicitly call and put libclang_rt.builtins. <Arch> .a.

You can use -rtlib-compiler-rt use this identifier to command Clang compiler-rt. However, not every target platform can support.

If you use libc ++ and / or libc ++ abi, you may need to set them to use the compiler-rt instead libgcc_s, set the mode to: deliver -DLIBCXX_USE_COMPILER_RT = YES and / or

-DLIBCXXABI_USE_COMPILER_RT = YES to cmake. On the other hand, you will probably need to run-time libraries to link to your program as the end (strictly speaking, do not bring any harm, but it really is a waste).

libgcc_s(GNU)

GCC runtime libraries can be used to replace the compiler-rt. However, it lacks a few functions, these functions are likely to generate LLVM references, particularly when using Clang of __builtin _ * _ overflow instruction family time.

You can use -rtlib = libgcc identifies let Clang use libgcc_s. This is not all platforms are supported.

Atomic library

If your program uses atomic operations, and the compiler can not convert them directly into their instruction (because, perhaps because there is no suitable machine instruction or operand no way good alignment), a call to the runtime library _atomic_ * function will be generated. A runtime library contains these atomic functions which is such an application (a program using the principle of operation) necessary.

compiler-rt(LLVM)

compiler-rt atom contains an implementation library.

libatomic (GNU)

libgcc_s no implementation of a library atoms. Alternatively, GCC libatomic library can be used to provide the function library atoms when using the libgcc_s.

note:

Clang is currently in the use of libgcc_s, and will not automatically connect libatomic. When using non-native atomic operation (if you see the link misdirection _atomic_ * function), you may need to manually add -latomic to support this configuration.

Unwind Library

unwind library provides a set of _Uwind_ * functions that implement a language-neutral Itanium C ++ ABI (Level I) of rollback part of the stack. It is a library of C ++ ABI dependent, dependent and sometimes also other runtime.

libunwind(LLVM)

The unwinder LLVM libraries can be obtained from SVN:

llvm-src$ svn co https://llvm.org/svn/llvm-project/libunwind/trunk projects/libunwind

When the code is detected in the detecting system to LLVM projects / libunwind directory, LLVM build system will automatically construct into libunwind.

If you use libc ++ abi, you may need to configure the use of libunwind instead libgcc_s, way configuration is passed -DLIBCXXABI_USE_LLVM_UNWINDER = YES to cmake. If libc ++ abi is set to use a version of libunwind, the library will have an implicit link to link libc ++ abi binaries.

libgcc_s(GNU)

libgcc_s has an integrated unwinder, no additional unwind provide a library.

libunwind(http://nongun.org)

This is another realization libunwind specification. Referring specifically to libunwind ( http://nongnu.org ).

libunwind(PathScale)

This is another realization libunwind specification. Referring specifically to libunwind (pathscale).

Sanitizer runtime

Clang command of sanitizers (-fsanitize = ...) Add implicit call to a runtime library, in order to ensure the border state of program execution, and found that the formation of diagnostic information when problems.

The only realize this is a run-time support of the LLVM compiler-rt, and the library (libclang_rt. <Sanitizer>. <Arch> .a) will use the relevant part of -fsanitize = ... when the identification of an implicit link to link.

C standard library

Clang supports a wide variety of standard C library implementation.

C ++ ABI library

C ++ ABI library provides an implementation of a portion of the Itanium C ++ ABI libraries, covering the major Itanium C ++ ABI documentation necessary to support and exception handling functionality to support Level II. Generating references to these functions, primarily Clang compiled C ++ code when implicitly generated.

When the link using libstdc ++ C ++ code and use libc ++ C ++ code into a program made possible time (as long as you do not try to pass C ++ Standard Library objects across the border), usually you can not use more than one in a program in C ++ ABI library.

Version of the C ++ ABI library Clang used is usually chosen C ++ standard library, which is to link the library. Several implementations available:

libc++abi(LLVM)

libc ++ abi is LLVM implement this specification.

libsupc++(GNU)

libsupc ++ is the standard GCC to achieve. However, this only libstdc ++ library is statically linked when it will be used. libstdc ++ DLL version includes a libsupc ++ copy.

note:

Clang now and not in a static link libstdc ++ automatically when the link libstomic. Or when using -static -static-libstdc ++, you need to manually add -lsupc ++ to support this setting.

libcxxrt(PathScale)

This is the Itanium C ++ ABI specification of another realization. Referring specifically to libcxxrt.

C ++ Standard Library

Clang LLVM supports the use of the C ++ standard library libc ++ or GCC's libstdc ++ implementation.

libc++ (LLVM)

libc ++ is to achieve LLVM C ++ standard library, focused on becoming the C ++ standard (C ++ 11 forward from) a fully realized.

You can use -stdlib = libc ++ logo to make Clang use libc ++.

libstdc++ (GNU)

libstdc ++ is the realization of the GCC C ++ standard library. Clang libstdc ++ version supports a wide range, back to version4.2, and will implicitly solve some of the problems the old version of libstdc ++.

You can use -stdlib = libstdc ++ logo Clang make use of libstdc ++.

Guess you like

Origin blog.csdn.net/snsn1984/article/details/86438880