summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/CodeGenOptions.h4
-rw-r--r--clang/include/clang/Driver/Options.td2
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp9
-rw-r--r--clang/lib/CodeGen/CodeGenModule.h5
-rw-r--r--clang/lib/CodeGen/ItaniumCXXABI.cpp3
-rw-r--r--clang/lib/Driver/ToolChains/Clang.cpp8
-rw-r--r--clang/lib/Frontend/CompilerInvocation.cpp2
-rw-r--r--clang/test/CodeGenCXX/symbol-partition.cpp21
-rw-r--r--clang/test/Driver/symbol-partition.c5
9 files changed, 52 insertions, 7 deletions
diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index 6bd939aee30..1aaa04efd61 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -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
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 2c426660e15..90b6092b1ba 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -935,6 +935,8 @@ def fno_cxx_static_destructors : Flag<["-"], "fno-c++-static-destructors">,
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.
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index e79eb71b793..bd44a493a28 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -875,19 +875,20 @@ void CodeGenModule::setDLLImportDLLExport(llvm::GlobalValue *GV,
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) {
diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h
index 6ab454fe6da..8c1bc0777de 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -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;
diff --git a/clang/lib/CodeGen/ItaniumCXXABI.cpp b/clang/lib/CodeGen/ItaniumCXXABI.cpp
index 3fac8d60fd2..bd399b25c3f 100644
--- a/clang/lib/CodeGen/ItaniumCXXABI.cpp
+++ b/clang/lib/CodeGen/ItaniumCXXABI.cpp
@@ -3420,6 +3420,9 @@ llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(
TypeName->setDLLStorageClass(DLLStorageClass);
GV->setDLLStorageClass(DLLStorageClass);
+ TypeName->setPartition(CGM.getCodeGenOpts().SymbolPartition);
+ GV->setPartition(CGM.getCodeGenOpts().SymbolPartition);
+
return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
}
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 650f73d36f2..29bdaf067f5 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5410,6 +5410,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
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) {
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index ca0f2fc845a..1b475dc0370 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1345,6 +1345,8 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
Opts.PassPlugins = Args.getAllArgValues(OPT_fpass_plugin_EQ);
+ Opts.SymbolPartition = Args.getLastArgValue(OPT_fsymbol_partition_EQ);
+
return Success;
}
diff --git a/clang/test/CodeGenCXX/symbol-partition.cpp b/clang/test/CodeGenCXX/symbol-partition.cpp
new file mode 100644
index 00000000000..ecc58e2a847
--- /dev/null
+++ b/clang/test/CodeGenCXX/symbol-partition.cpp
@@ -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")));
diff --git a/clang/test/Driver/symbol-partition.c b/clang/test/Driver/symbol-partition.c
new file mode 100644
index 00000000000..9556faf15d5
--- /dev/null
+++ b/clang/test/Driver/symbol-partition.c
@@ -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'
OpenPOWER on IntegriCloud