.text.unlikely 在 ELF 目标文件中是什么意思?

What does .text.unlikely mean in ELF object files?

在我的 objdump -t 输出中,我看到以下两行:

00000000000004d2 l     F .text.unlikely 00000000000000ec function-signature-goes-here [clone .cold.427]

00000000000018e0 g     F .text  0000000000000690 function-signature-goes-here

我知道 l 表示本地,g 表示全球。我还知道 .text 是目标文件中的一个部分或一种类型的部分,包含已编译的程序指令。但是 .text.unlikely 是什么?假设它是与 .text 不同的部分(或部分类型)——有什么区别?

在我的 GCC v5.4.0 联机帮助页中,我发现了以下开关:

-freorder-functions 其中说:

Reorder functions in the object file in order to improve code locality. This is implemented by using special subsections ".text.hot" for most frequently executed functions and ".text.unlikely" for unlikely executed functions. Reordering is done by the linker so object file format must support named sections and linker must place them in a reasonable way.

Also profile feedback must be available to make this option effective. See -fprofile-arcs for details.

Enabled at levels -O2, -O3, -Os.

看起来编译器 运行 带有优化标志或此二进制文件的开关,函数被组织在小节中以优化空间局部性。