This is an archive of the discontinued LLVM Phabricator instance.

[clang] Support -fpic -fno-semantic-interposition for RISCV
ClosedPublic

Authored by MaskRay on May 4 2021, 5:26 PM.

Details

Summary

-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

Diff Detail

Event Timeline

MaskRay created this revision.May 4 2021, 5:26 PM
MaskRay requested review of this revision.May 4 2021, 5:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 4 2021, 5:26 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
This revision is now accepted and ready to land.May 10 2021, 3:10 PM
MaskRay updated this revision to Diff 344234.May 10 2021, 4:28 PM

rebase after aarch64 support

This revision was landed with ongoing or failed builds.May 11 2021, 11:38 AM
This revision was automatically updated to reflect the committed changes.