LLVM中的CodeModel指的是什么

LLVM中的CodeModel指的是什么

本文介绍了Clang/LLVM中的CodeModel指的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在浏览Clang/LLVM源代码,遇到了 CodeGenOptions .

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

基于此方法,有效值似乎是:,"kernel""medium""large".

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

此属性控制什么?

如何为应用程序选择正确的值?

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

推荐答案

代码模型是AMD64 ABI的术语(请参阅 https://software.intel.com/sites/default/files/article/402129/mpx-linux64-abi.pdf 了解更多信息).

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).

简而言之-x64-64指令内的大多数偏移都是相对于PC的,但是指令内的立即数字段只有32位长.因此,如果数据位于距代码远"(相距超过32位)的位置,则无法使用指令内部的立即数字段有效地编码偏移量,而应显式计算地址.代码模型对代码和数据的相对位置提供了各种限制.

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.

如果您要静态地编译所有内容,则"small"是安全的(默认情况下).如果您正在准时使用,那么一切皆有可能,特别是如果启用了ASLR并且您需要使用中/大型代码模型.

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.

这篇关于Clang/LLVM中的CodeModel指的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 06:07