[CMake][ELF] Add -fno-semantic-interposition for GCC and Clang>=13

Authored by MaskRay on Jun 3 2021, 3:26 PM.


[CMake][ELF] Add -fno-semantic-interposition for GCC and Clang>=13

build, libLLVM-13git.so is 2% smaller and libclang-cpp.so is 1% smaller (on top of -Wl,-Bsymbolic-functions).
There may be some small performance improvement as well because GCC
-fPIC suppresses interprocedural optimizations for non-inline
definitions by default.

Note: we cannot add -fno-semantic-interposition for Clang<13. Clang<13's
implementation additionally optimizes global variables, which is incompatible
with unfortunate ELF -fno-pic default: direct access relocations for external
data. If the executable has a -fno-pic object file referencing a global variable
declared in a public header, the direct access relocation will cause a copy
relocation. The executable and libLLVM.so/libclang-cpp.so will disagree on the

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D102453