r362829 - Driver, IRGen: Set partitions on GlobalValues according to -fsymbol-partition flag.

Peter Collingbourne via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 7 12:10:08 PDT 2019


Author: pcc
Date: Fri Jun  7 12:10:08 2019
New Revision: 362829

URL: http://llvm.org/viewvc/llvm-project?rev=362829&view=rev
Log:
Driver, IRGen: Set partitions on GlobalValues according to -fsymbol-partition flag.

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

Added:
    cfe/trunk/test/CodeGenCXX/symbol-partition.cpp
    cfe/trunk/test/Driver/symbol-partition.c
Modified:
    cfe/trunk/include/clang/Basic/CodeGenOptions.h
    cfe/trunk/include/clang/Driver/Options.td
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h
    cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
    cfe/trunk/lib/Driver/ToolChains/Clang.cpp
    cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Basic/CodeGenOptions.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CodeGenOptions.h?rev=362829&r1=362828&r2=362829&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Basic/CodeGenOptions.h Fri Jun  7 12:10:08 2019
@@ -243,6 +243,10 @@ public:
   /// records.
   std::string OptRecordPasses;
 
+  /// The name of the partition that symbols are assigned to, specified with
+  /// -fsymbol-partition (see https://lld.llvm.org/Partitions.html).
+  std::string SymbolPartition;
+
   /// Regular expression to select optimizations for which we should enable
   /// optimization remarks. Transformation passes whose name matches this
   /// expression (and support this feature), will emit a diagnostic

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=362829&r1=362828&r2=362829&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Jun  7 12:10:08 2019
@@ -935,6 +935,8 @@ def fno_cxx_static_destructors : Flag<["
   Group<f_Group>,
   Flags<[CC1Option]>,
   HelpText<"Disable C++ static destructor registration">;
+def fsymbol_partition_EQ : Joined<["-"], "fsymbol-partition=">, Group<f_Group>,
+  Flags<[CC1Option]>;
 
 // Begin sanitizer flags. These should all be core options exposed in all driver
 // modes.

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=362829&r1=362828&r2=362829&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Jun  7 12:10:08 2019
@@ -875,19 +875,20 @@ void CodeGenModule::setDLLImportDLLExpor
 void CodeGenModule::setGVProperties(llvm::GlobalValue *GV,
                                     GlobalDecl GD) const {
   setDLLImportDLLExport(GV, GD);
-  setGlobalVisibilityAndLocal(GV, dyn_cast<NamedDecl>(GD.getDecl()));
+  setGVPropertiesAux(GV, dyn_cast<NamedDecl>(GD.getDecl()));
 }
 
 void CodeGenModule::setGVProperties(llvm::GlobalValue *GV,
                                     const NamedDecl *D) const {
   setDLLImportDLLExport(GV, D);
-  setGlobalVisibilityAndLocal(GV, D);
+  setGVPropertiesAux(GV, D);
 }
 
-void CodeGenModule::setGlobalVisibilityAndLocal(llvm::GlobalValue *GV,
-                                                const NamedDecl *D) const {
+void CodeGenModule::setGVPropertiesAux(llvm::GlobalValue *GV,
+                                       const NamedDecl *D) const {
   setGlobalVisibility(GV, D);
   setDSOLocal(GV);
+  GV->setPartition(CodeGenOpts.SymbolPartition);
 }
 
 static llvm::GlobalVariable::ThreadLocalMode GetLLVMTLSModel(StringRef S) {

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=362829&r1=362828&r2=362829&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Fri Jun  7 12:10:08 2019
@@ -759,9 +759,6 @@ public:
   /// Set the visibility for the given LLVM GlobalValue.
   void setGlobalVisibility(llvm::GlobalValue *GV, const NamedDecl *D) const;
 
-  void setGlobalVisibilityAndLocal(llvm::GlobalValue *GV,
-                                   const NamedDecl *D) const;
-
   void setDSOLocal(llvm::GlobalValue *GV) const;
 
   void setDLLImportDLLExport(llvm::GlobalValue *GV, GlobalDecl D) const;
@@ -771,6 +768,8 @@ public:
   void setGVProperties(llvm::GlobalValue *GV, GlobalDecl GD) const;
   void setGVProperties(llvm::GlobalValue *GV, const NamedDecl *D) const;
 
+  void setGVPropertiesAux(llvm::GlobalValue *GV, const NamedDecl *D) const;
+
   /// Set the TLS mode for the given LLVM GlobalValue for the thread-local
   /// variable declaration D.
   void setTLSMode(llvm::GlobalValue *GV, const VarDecl &D) const;

Modified: cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp?rev=362829&r1=362828&r2=362829&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp (original)
+++ cfe/trunk/lib/CodeGen/ItaniumCXXABI.cpp Fri Jun  7 12:10:08 2019
@@ -3420,6 +3420,9 @@ llvm::Constant *ItaniumRTTIBuilder::Buil
   TypeName->setDLLStorageClass(DLLStorageClass);
   GV->setDLLStorageClass(DLLStorageClass);
 
+  TypeName->setPartition(CGM.getCodeGenOpts().SymbolPartition);
+  GV->setPartition(CGM.getCodeGenOpts().SymbolPartition);
+
   return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
 }
 

Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=362829&r1=362828&r2=362829&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Fri Jun  7 12:10:08 2019
@@ -5410,6 +5410,14 @@ void Clang::ConstructJob(Compilation &C,
                        TC.useIntegratedAs()))
     CmdArgs.push_back("-faddrsig");
 
+  if (Arg *A = Args.getLastArg(options::OPT_fsymbol_partition_EQ)) {
+    std::string Str = A->getAsString(Args);
+    if (!TC.getTriple().isOSBinFormatELF())
+      D.Diag(diag::err_drv_unsupported_opt_for_target)
+          << Str << TC.getTripleString();
+    CmdArgs.push_back(Args.MakeArgString(Str));
+  }
+
   // Add the "-o out -x type src.c" flags last. This is done primarily to make
   // the -cc1 command easier to edit when reproducing compiler crashes.
   if (Output.getType() == types::TY_Dependencies) {

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=362829&r1=362828&r2=362829&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Fri Jun  7 12:10:08 2019
@@ -1345,6 +1345,8 @@ static bool ParseCodeGenArgs(CodeGenOpti
 
   Opts.PassPlugins = Args.getAllArgValues(OPT_fpass_plugin_EQ);
 
+  Opts.SymbolPartition = Args.getLastArgValue(OPT_fsymbol_partition_EQ);
+
   return Success;
 }
 

Added: cfe/trunk/test/CodeGenCXX/symbol-partition.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/symbol-partition.cpp?rev=362829&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/symbol-partition.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/symbol-partition.cpp Fri Jun  7 12:10:08 2019
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsymbol-partition=foo -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: @gv = {{.*}}, partition "foo"
+// CHECK: @_ZTV1S = {{.*}}, partition "foo"
+// CHECK: @_ZTS1S = {{.*}}, partition "foo"
+// CHECK: @_ZTI1S = {{.*}}, partition "foo"
+
+// CHECK: @_Z5ifuncv = {{.*}}, partition "foo"
+
+// CHECK: define {{.*}} @_ZN1S1fEv({{.*}} partition "foo"
+// CHECK: define {{.*}} @f({{.*}} partition "foo"
+
+struct S {
+  virtual void f();
+};
+
+void S::f() {}
+
+int gv;
+extern "C" void *f() { return 0; }
+void ifunc() __attribute__((ifunc("f")));

Added: cfe/trunk/test/Driver/symbol-partition.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/symbol-partition.c?rev=362829&view=auto
==============================================================================
--- cfe/trunk/test/Driver/symbol-partition.c (added)
+++ cfe/trunk/test/Driver/symbol-partition.c Fri Jun  7 12:10:08 2019
@@ -0,0 +1,5 @@
+// RUN: %clang -### -target x86_64-unknown-linux -c -fsymbol-partition=foo %s 2>&1 | FileCheck %s
+// RUN: %clang -### -target x86_64-pc-win32 -c -fsymbol-partition=foo %s 2>&1 | FileCheck --check-prefix=ERROR %s
+
+// CHECK: "-fsymbol-partition=foo"
+// ERROR: clang: error: unsupported option '-fsymbol-partition=foo' for target 'x86_64-pc-windows-msvc'




More information about the cfe-commits mailing list