[all-commits] [llvm/llvm-project] 2075f2: [clang] Support -fpic -fno-semantic-interposition ...
Fangrui Song via All-commits
all-commits at lists.llvm.org
Tue May 11 11:38:58 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 2075f2b296b0fa90cb7597f0f318232940d29e95
https://github.com/llvm/llvm-project/commit/2075f2b296b0fa90cb7597f0f318232940d29e95
Author: Fangrui Song <i at maskray.me>
Date: 2021-05-11 (Tue, 11 May 2021)
Changed paths:
M clang/lib/Driver/ToolChains/Clang.cpp
M clang/test/Driver/fsemantic-interposition.c
Log Message:
-----------
[clang] Support -fpic -fno-semantic-interposition for RISCV
-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 at 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
Reviewed By: luismarques
Differential Revision: https://reviews.llvm.org/D101876
More information about the All-commits
mailing list