Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the CodeModel in Clang / LLVM refer to?

I have been looking through the Clang / LLVM source-code and I came across the CodeModel property of CodeGenOptions.

Based on this method, the valid values appear to be: "small", "kernel", "medium" and "large".

What do this property control?

How do I go about choosing the correct value for my application?

like image 550
sdgfsdh Avatar asked Nov 08 '16 17:11

sdgfsdh


People also ask

Does Clang define __ GNUC __?

(GNU C is a language, GCC is a compiler for that language.Clang defines __GNUC__ / __GNUC_MINOR__ / __GNUC_PATCHLEVEL__ according to the version of gcc that it claims full compatibility with.

What is Clang command line?

Introduction. The Clang Compiler is an open-source compiler for the C family of programming languages, aiming to be the best in class implementation of these languages. Clang builds on the LLVM optimizer and code generator, allowing it to provide high-quality optimization and code generation support for many targets.

What is Clang LLVM?

Clang is an "LLVM native" C/C++/Objective-C compiler, which aims to deliver amazingly fast compiles, extremely useful error and warning messages and to provide a platform for building great source level tools.

What is Clang ++ command?

clang is a C, C++, and Objective-C compiler which encompasses preprocessing, parsing, optimization, code generation, assembly, and linking.


Video Answer


1 Answers

Code model is a term from AMD64 ABI (see 3.5.1 from https://software.intel.com/sites/default/files/article/402129/mpx-linux64-abi.pdf for more information).

In short - the majority of the offsets inside x64-64 instructions are PC-relative, however the immediate field inside instructions is only 32-bit long. Therefore if the data is located "far" from the code (more than 32-bit apart), then one could not use immediate field inside the instructions to efficiently encode the offset and should calculate the address explicitly. The code model provides various restrictions on the relative location of code and data.

If you're compiling everything statically, then 'small' is safe (and default). If you're JIT'ing, then everything is possible especially if ASLR is enabled and you'd need to use medium / large code model.

like image 171
Anton Korobeynikov Avatar answered Sep 21 '22 15:09

Anton Korobeynikov