Fāng-ruì Sòng via llvm-dev
2021-Jun-04 22:26 UTC
[llvm-dev] -fpic ELF default: reclaim some -fno-semantic-interposition optimization opportunities?
Circling back here. The Clang default -fpic behavior is actually similar to gcc -fpic -fno-semantic-interposition: interprocedural optimizations are allowed. Clang just doesn't use local aliases. It turned out that suppressing variable interposition was my misread of GCC's -fno-semantic-interposition documentation. https://reviews.llvm.org/D102583 made the Clang behavior mostly match GCC. There is only one compatibility thing left: Clang -fpic -fno-semantic-interposition uses local aliases when taking the address of a function, this can be incompatible with -fno-pic code causing canonical PLT entries. Such a pointer equality property for functions is rarely relied on in practice (Windows require deliberate dllimport/dllexport; --icf=all can break this from a different angle) so -fno-semantic-interposition is generally fine. Fixing the last point is actually easy: let -fno-pic use GOT when taking the address of an non-definition function. This is preferable on most architectures (only i386/ppc32 (and some other exotic arches which may not be supported by llvm at all) may take some performance hit, but taking the address of an non-definition function is rare and should not be a performance bottleneck.) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100593 I guess it may be difficult to even get an agreed upon option from the GCC side as they may not be fans fixing these fundamental issues. On Fri, May 7, 2021 at 3:24 PM Fangrui Song <maskray at google.com> wrote:> > I have a write-up about -fno-semantic-interposition in GCC and Clang. > <https://gist.github.com/MaskRay/2d4dfcfc897341163f734afb59f689c6> > > The preemptible by default property is perhaps one of default ELF properties which I favor the least. > (not an issue of ELF, but more of a toolchain default). > Clang is in a somewhat better situation than GCC because our default longstanding -fpic behavior > diverges a lot from -fsemantic-interposition and is closer to -fno-semantic-interposition. > Especially on non-x86, the function semantic interposition likely never works in > -fno-function-sections mode. > > Sending this message to get some thoughts on relaiming some -fno-semantic-interposition optimization > opportunities for ELF -fpic default, at least for non-x86. We could start from a > clang/CMakeLists.txt cmake variable. > > dogfood: https://lists.llvm.org/pipermail/llvm-dev/2021-May/150465.html build llvm-project itself with -fno-semantic-interposition-- 宋方睿
Joerg Sonnenberger via llvm-dev
2021-Jun-05 23:54 UTC
[llvm-dev] -fpic ELF default: reclaim some -fno-semantic-interposition optimization opportunities?
On Fri, Jun 04, 2021 at 03:26:53PM -0700, Fāng-ruì Sòng via llvm-dev wrote:> Fixing the last point is actually easy: let -fno-pic use GOT when > taking the address of an non-definition function.I'd far prefer to have an attribute to explicitly say that the address of a given symbol should always be computed indirectly (e.g. via GOT). That gives the explicit control necessary for libraries without penalizing the larger executables like clang. Joerg