Arch Linux

Please read this before reporting a bug:

Do NOT report bugs when a package is just outdated, or it is in the AUR. Use the 'flag out of date' link on the package page, or the Mailing List.

REPEAT: Do NOT report bugs for outdated packages!

FS#71139 - [gcc] Enable default -fno-semantic-interposition

Attached to Project: Arch Linux
Opened by Ray Song (MaskRay) - Sunday, 06 June 2021, 03:29 GMT
Last edited by Allan McRae (Allan) - Thursday, 01 July 2021, 01:06 GMT
Task Type Feature Request
Category Packages: Core
Status Assigned
Assigned To Giancarlo Razzolini (grazzolini)
freswa (frederik)
Architecture All
Severity Low
Priority Normal
Reported Version
Due in Version Undecided
Due Date Undecided
Percent Complete 0%
Votes 1
Private No


GCC -fpic disables interprocedural optimizations (including inlining) for non-vague-linkage function definitions by default.
This is the biggest difference between -fpic/-fpie.
-fno-semantic-interposition can bring back the lost performance.

* cpython has defaulted to -fno-semantic-interposition. It was reported to have up to 30% speedup.
* The LLVM build system will default to -fno-semantic-interposition since 13.0.0. GCC built Clang will be 3% faster and 1~2% smaller (see
* See for more technical details.

Actually, Clang -fpic has always been allowing interprocedural optimizations.
FreeBSD uses Clang, so it's well tested that most pieces of software work.
I am going to create a GCC patch (--enable-default-no-semantic-interposition) to enable default -fno-semantic-interposition.
I think it will be a great addition to Arch Linux for any software which uses -fpic/-fPIC.
This task depends upon

Comment by Allan McRae (Allan) - Sunday, 06 June 2021, 04:37 GMT
I think that optimization kills LD_PRELOAD... Not great as a default.
Comment by Ray Song (MaskRay) - Sunday, 06 June 2021, 05:25 GMT
> I think that optimization kills LD_PRELOAD... Not great as a default.

This is common misconception. Please read
I noticed that is **severely flawed** and may be the source of many people's misconception.
I've emailed them to fix the information.

For a vague-linkage function definition, a call site in the same translation unit may inline the callee. Whether -fno-semantic-interposition is enabled/disabled does no affect the inline decision.

For a non-vague-linkage function definition, by default (-fsemantic-interposition) the -fpic mode does not allow a call site in the same translation unit to inline the callee or perform other interprocedural optimizations.
-fno-semantic-interposition re-enables interprocedural optimizations including inling.

If a caller inlines a callee, apparently using LD_PRELOAD to interpose the callee will not affect the caller.
But many other LD_PRELOAD usage still work.
For example, glibc interposition (malloc/fakeroot) works.

If the function you interpose is large, it's likely it will not be inlined into its callers anyway and LD_PRELOAD still works fine.
If a function is inlined, you can interpose both it and its call sites in the same TU.
You can add __attribute__((noinline)) to make it not inlinable so that interposition will definitely work.