[PATCH] D101876: [clang] Support -fpic -fno-semantic-interposition for RISCV

Fangrui Song via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 4 17:26:44 PDT 2021


MaskRay created this revision.
MaskRay added reviewers: craig.topper, jrtc27, luismarques, serge-sans-paille.
Herald added subscribers: StephenFan, vkmr, evandro, sameer.abuasal, s.egerton, Jim, benna, psnobl, rogfer01, shiva0217, kito-cheng, simoncook.
MaskRay requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

-fno-semantic-interposition can optimize default visibility external
linkage (non-ifunc-non-COMDAT) access to not use GOT, e.g.

  int var;
  int load() { return var; }

-fpic (var is dso_preemptable) vs -fpic -fno-semantic-interposition (var is dso_local)

  -       auipc   a0, %got_pcrel_hi(var)
  -       ld      a0, %pcrel_lo(.LBB2_1)(a0)
  +       auipc   a0, %pcrel_hi(.Lvar$local)
  +       addi    a0, a0, %pcrel_lo(.LBB2_1)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101876

Files:
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/test/Driver/fsemantic-interposition.c


Index: clang/test/Driver/fsemantic-interposition.c
===================================================================
--- clang/test/Driver/fsemantic-interposition.c
+++ clang/test/Driver/fsemantic-interposition.c
@@ -10,6 +10,8 @@
 
 /// If -fno-semantic-interposition is specified and the target supports local
 /// aliases, neither CC1 option is set.
+// RUN: %clang -target riscv32 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
+// RUN: %clang -target riscv64 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
 // RUN: %clang -target i386 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
 // RUN: %clang -target x86_64 %s -Werror -fPIC -fno-semantic-interposition -c -### 2>&1 | FileCheck --check-prefix=NO %s
 // NO-NOT: "-fsemantic-interposition"
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -4718,7 +4718,7 @@
                              options::OPT_fno_semantic_interposition);
     if (RelocationModel != llvm::Reloc::Static && !IsPIE) {
       // The supported targets need to call AsmPrinter::getSymbolPreferLocal.
-      bool SupportsLocalAlias = Triple.isX86();
+      bool SupportsLocalAlias = Triple.isRISCV() || Triple.isX86();
       if (!A)
         CmdArgs.push_back("-fhalf-no-semantic-interposition");
       else if (A->getOption().matches(options::OPT_fsemantic_interposition))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101876.342917.patch
Type: text/x-patch
Size: 1588 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210505/5eaf4617/attachment.bin>


More information about the cfe-commits mailing list