-fno-semantic-interposition (only effective with -fpic) can optimize default
visibility external linkage (non-ifunc-non-COMDAT) variable access and function
calls to avoid GOT/PLT, by using local aliases, e.g.
int var; __attribute__((optnone)) int fun(int x) { return x * x; } int test() { return fun(var); }
-fpic (var and fun are dso_preemptable)
test: .LBB1_1: auipc a0, %got_pcrel_hi(var) ld a0, %pcrel_lo(.LBB1_1)(a0) lw a0, 0(a0) // fun is preemptible by default in ld -shared mode. ld will create a PLT. tail fun@plt
vs -fpic -fno-semantic-interposition (var and fun are dso_local)
test: .Ltest$local: .LBB1_1: auipc a0, %pcrel_hi(.Lvar$local) addi a0, a0, %pcrel_lo(.LBB1_1) lw a0, 0(a0) // The assembler either resolves .Lfun$local at assembly time (-mno-relax // -fno-function-sections), or produces a relocation referencing a non-preemptible // local symbol (which can avoid PLT). tail .Lfun$local
Note: Clang's default -fpic is more aggressive than GCC -fpic: interprocedural
optimizations (including inlining) are available but local aliases are not used.
-fpic -fsemantic-interposition can disable interprocedural optimizations.
Depends on D101875