r337333 - Teach Clang to emit address-significance tables.
Peter Collingbourne via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 17 16:17:16 PDT 2018
Author: pcc
Date: Tue Jul 17 16:17:16 2018
New Revision: 337333
URL: http://llvm.org/viewvc/llvm-project?rev=337333&view=rev
Log:
Teach Clang to emit address-significance tables.
By default, we emit an address-significance table on all ELF
targets when the integrated assembler is enabled. The emission of an
address-significance table can be controlled with the -faddrsig and
-fno-addrsig flags.
Differential Revision: https://reviews.llvm.org/D48155
Added:
cfe/trunk/test/CodeGen/addrsig.c
cfe/trunk/test/Driver/addrsig.c
Modified:
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/docs/UsersManual.rst
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=337333&r1=337332&r2=337333&view=diff
==============================================================================
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Tue Jul 17 16:17:16 2018
@@ -98,6 +98,14 @@ Non-comprehensive list of changes in thi
finding out the warning hierarchy, and which of them are enabled by default
or for a particular compiler invocation.
+- By default, Clang emits an address-significance table into
+ every ELF object file when using the integrated assembler.
+ Address-significance tables allow linkers to implement `safe ICF
+ <https://research.google.com/pubs/archive/36912.pdf>`_ without the false
+ positives that can result from other implementation techniques such as
+ relocation scanning. The ``-faddrsig`` and ``-fno-addrsig`` flags can be
+ used to control whether to emit the address-significance table.
+
- ...
New Compiler Flags
Modified: cfe/trunk/docs/UsersManual.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=337333&r1=337332&r2=337333&view=diff
==============================================================================
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Tue Jul 17 16:17:16 2018
@@ -1382,6 +1382,15 @@ are listed below.
// value of -fmax-type-align.
}
+.. option:: -faddrsig, -fno-addrsig
+
+ Controls whether Clang emits an address-significance table into the object
+ file. Address-significance tables allow linkers to implement `safe ICF
+ <https://research.google.com/pubs/archive/36912.pdf>`_ without the false
+ positives that can result from other implementation techniques such as
+ relocation scanning. Address-significance tables are enabled by default
+ on ELF targets when using the integrated assembler. This flag currently
+ only has an effect on ELF targets.
Profile Guided Optimization
---------------------------
Modified: cfe/trunk/include/clang/Driver/Options.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=337333&r1=337332&r2=337333&view=diff
==============================================================================
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Jul 17 16:17:16 2018
@@ -758,6 +758,10 @@ def fno_profile_instr_use : Flag<["-"],
def fno_profile_use : Flag<["-"], "fno-profile-use">,
Alias<fno_profile_instr_use>;
+def faddrsig : Flag<["-"], "faddrsig">, Group<f_Group>, Flags<[CoreOption, CC1Option]>,
+ HelpText<"Emit an address-significance table">;
+def fno_addrsig : Flag<["-"], "fno-addrsig">, Group<f_Group>, Flags<[CoreOption]>,
+ HelpText<"Don't emit an address-significance table">;
def fblocks : Flag<["-"], "fblocks">, Group<f_Group>, Flags<[CC1Option]>,
HelpText<"Enable the 'blocks' language feature">;
def fbootclasspath_EQ : Joined<["-"], "fbootclasspath=">, Group<f_Group>;
Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=337333&r1=337332&r2=337333&view=diff
==============================================================================
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Tue Jul 17 16:17:16 2018
@@ -335,6 +335,9 @@ CODEGENOPT(EmbedSource, 1, 0)
/// Whether to emit all vtables
CODEGENOPT(ForceEmitVTables, 1, 0)
+/// Whether to emit an address-significance table into the object file.
+CODEGENOPT(Addrsig, 1, 0)
+
#undef CODEGENOPT
#undef ENUM_CODEGENOPT
Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=337333&r1=337332&r2=337333&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Tue Jul 17 16:17:16 2018
@@ -454,6 +454,7 @@ static void initTargetOptions(llvm::Targ
Options.ExplicitEmulatedTLS = CodeGenOpts.ExplicitEmulatedTLS;
Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
+ Options.EmitAddrsig = CodeGenOpts.Addrsig;
if (CodeGenOpts.EnableSplitDwarf)
Options.MCOptions.SplitDwarfFile = CodeGenOpts.SplitDwarfFile;
Modified: cfe/trunk/lib/Driver/ToolChains/Clang.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains/Clang.cpp?rev=337333&r1=337332&r2=337333&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains/Clang.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp Tue Jul 17 16:17:16 2018
@@ -4777,6 +4777,11 @@ void Clang::ConstructJob(Compilation &C,
}
}
+ if (Args.hasFlag(options::OPT_faddrsig, options::OPT_fno_addrsig,
+ getToolChain().getTriple().isOSBinFormatELF() &&
+ getToolChain().useIntegratedAs()))
+ CmdArgs.push_back("-faddrsig");
+
// Finally add the compile command to the compilation.
if (Args.hasArg(options::OPT__SLASH_fallback) &&
Output.getType() == types::TY_Object &&
Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=337333&r1=337332&r2=337333&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Tue Jul 17 16:17:16 2018
@@ -1119,6 +1119,8 @@ static bool ParseCodeGenArgs(CodeGenOpti
Opts.EmitVersionIdentMetadata = Args.hasFlag(OPT_Qy, OPT_Qn, true);
+ Opts.Addrsig = Args.hasArg(OPT_faddrsig);
+
return Success;
}
Added: cfe/trunk/test/CodeGen/addrsig.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/addrsig.c?rev=337333&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/addrsig.c (added)
+++ cfe/trunk/test/CodeGen/addrsig.c Tue Jul 17 16:17:16 2018
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -S %s -faddrsig -O -o - | FileCheck --check-prefix=ADDRSIG %s
+// RUN: %clang_cc1 -triple=x86_64-unknown-linux -S %s -O -o - | FileCheck --check-prefix=NO-ADDRSIG %s
+
+// ADDRSIG: .addrsig
+// ADDRSIG: .addrsig_sym g1
+// ADDRSIG-NOT: .addrsig_sym g2
+
+// NO-ADDRSIG-NOT: .addrsig
+
+extern const int g1[], g2[];
+
+const int *f1() {
+ return g1;
+}
+
+int f2() {
+ return g2[0];
+}
Added: cfe/trunk/test/Driver/addrsig.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/addrsig.c?rev=337333&view=auto
==============================================================================
--- cfe/trunk/test/Driver/addrsig.c (added)
+++ cfe/trunk/test/Driver/addrsig.c Tue Jul 17 16:17:16 2018
@@ -0,0 +1,8 @@
+// RUN: %clang -### -target x86_64-unknown-linux -c %s 2>&1 | FileCheck -check-prefix=ADDRSIG %s
+// RUN: %clang -### -target x86_64-unknown-linux -fno-integrated-as -c %s 2>&1 | FileCheck -check-prefix=NO-ADDRSIG %s
+// RUN: %clang -### -target x86_64-unknown-linux -fno-integrated-as -faddrsig -c %s 2>&1 | FileCheck -check-prefix=ADDRSIG %s
+// RUN: %clang -### -target x86_64-unknown-linux -fno-addrsig -c %s 2>&1 | FileCheck -check-prefix=NO-ADDRSIG %s
+// RUN: %clang -### -target x86_64-apple-darwin -c %s 2>&1 | FileCheck -check-prefix=NO-ADDRSIG %s
+
+// ADDRSIG: -faddrsig
+// NO-ADDRSIG-NOT: -faddrsig
More information about the cfe-commits
mailing list