GCC 5.3中的新选项:-fno-semantic-interposition [英] New option in GCC 5.3: -fno-semantic-interposition

查看:553
本文介绍了GCC 5.3中的新选项:-fno-semantic-interposition的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GCC 5.3增加了一个新选项: -fno-semantic-interposition


新的-fno-semantic-interposition选项可用于改进共享库的代码
质量,其中导出符号的插入不允许为


这听起来像是对C ++项目有用的地方,因为无论出于什么原因都无法使用插入,但是延迟是一个问题。



但是,描述相当模糊。是否有人能够澄清这个选项是如何工作的?

code>可以显着提高共享库中代码的性能,但很少会改变语义。



默认编译器尊重 ELF函数中介语义。简而言之,任何导出的函数(即任何函数,如果使用默认编译器标记编译的话)都可以在运行时通过 LD_PRELOAD 替换,或者简单地由共享库替换连接。这可以防止编译器进行大量有用的分析和优化(特别是内联和克隆),因为它们可能会打断插入。

-fno-semantic -interposition 赋予编译器许可忽略潜在的插入和更积极地进行优化。正如我所说,使用<$ c有一些注意事项$ c> -fno-semantic-interposition :




  • 它可能会改变程序的行为实际上依赖于插入,有时你没有意识到这一点)

  • 它只能使共享库受益

  • 如果你已经做了适当的优化您的库(即使用 -fvisibility = hidden >进行编译,并使用 __ attribute __((visibility(default))显式注释所有导出的符号c $ c

    $ p
    $ b

    第一项防止 fno-semantic-interposition 。例如。据我所知,没有Linux发行版在广泛的范围内使用它(这将是一个伟大的项目顺便说一句)。


    GCC 5.3 has added a new option: -fno-semantic-interposition

    A new -fno-semantic-interposition option can be used to improve code quality of shared libraries where interposition of exported symbols is not allowed.

    This sounds like this is something useful for C++ projects where interposition can't be used for whatever reason, but where latency is a concern.

    However, the description is fairly vague. Is anyone able to clarify how this option works exactly?

    解决方案

    -fno-semantic-interposition can significantly improve performance of code in shared libraries but may rarely change semantics.

    By default compiler respects ELF function interposition semantics. In short, any exported function (i.e. any function if compiled with default compiler flags) can be replaced at runtime via LD_PRELOAD or simply by shared library which happens to be loaded earlier by dynamic linker. This prevents compiler from doing a lot of useful analyses and optimizations (most notably inlining and cloning) because they may break interposition.

    -fno-semantic-interposition gives compiler permission to ignore potential interposition and optimize much more aggressively.

    As I said, there are some caveats in using -fno-semantic-interposition:

    • it might change behavior of your program (when it was actually relying on interposition, sometimes without you realizing this)
    • it can only benefit shared libraries
    • it's much less useful if you already do proper optimization of your libraries (i.e. compile with -fvisibility=hidden and explicitly annotate all exported symbols with __attribute__((visibility("default"))))

    The first item prevents wide deployment of fno-semantic-interposition. E.g. to my knowledge no Linux distro uses it at wide scale (it would be a great project btw).

    这篇关于GCC 5.3中的新选项:-fno-semantic-interposition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆