Index: llvm/trunk/include/llvm/CodeGen/CommandFlags.inc =================================================================== --- llvm/trunk/include/llvm/CodeGen/CommandFlags.inc +++ llvm/trunk/include/llvm/CodeGen/CommandFlags.inc @@ -261,6 +261,10 @@ "stack-size-section", cl::desc("Emit a section containing stack size metadata"), cl::init(false)); +static cl::opt + EnableAddrsig("addrsig", cl::desc("Emit an address-significance table"), + cl::init(false)); + // Common utility function tightly tied to the options listed here. Initializes // a TargetOptions object with CodeGen flags and returns it. static TargetOptions InitTargetOptionsFromCodeGenFlags() { @@ -289,6 +293,7 @@ Options.ExplicitEmulatedTLS = EmulatedTLS.getNumOccurrences() > 0; Options.ExceptionModel = ExceptionModel; Options.EmitStackSizeSection = EnableStackSizeSection; + Options.EmitAddrsig = EnableAddrsig; Options.MCOptions = InitMCTargetOptionsFromFlags(); Index: llvm/trunk/include/llvm/Target/TargetOptions.h =================================================================== --- llvm/trunk/include/llvm/Target/TargetOptions.h +++ llvm/trunk/include/llvm/Target/TargetOptions.h @@ -108,10 +108,10 @@ DisableIntegratedAS(false), RelaxELFRelocations(false), FunctionSections(false), DataSections(false), UniqueSectionNames(true), TrapUnreachable(false), - NoTrapAfterNoreturn(false), - EmulatedTLS(false), ExplicitEmulatedTLS(false), - EnableIPRA(false), EmitStackSizeSection(false), - EnableMachineOutliner(false), SupportsDefaultOutlining(false) {} + NoTrapAfterNoreturn(false), EmulatedTLS(false), + ExplicitEmulatedTLS(false), EnableIPRA(false), + EmitStackSizeSection(false), EnableMachineOutliner(false), + SupportsDefaultOutlining(false), EmitAddrsig(false) {} /// PrintMachineCode - This flag is enabled when the -print-machineinstrs /// option is specified on the command line, and should enable debugging @@ -238,6 +238,9 @@ /// Set if the target supports default outlining behaviour. unsigned SupportsDefaultOutlining : 1; + /// Emit address-significance table. + unsigned EmitAddrsig : 1; + /// FloatABIType - This setting is set by -float-abi=xxx option is specfied /// on the command line. This setting may either be Default, Soft, or Hard. /// Default selects the target's default behavior. Soft selects the ABI for Index: llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ llvm/trunk/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1529,6 +1529,14 @@ } } + if (TM.Options.EmitAddrsig) { + // Emit address-significance attributes for all globals. + OutStreamer->EmitAddrsig(); + for (const GlobalValue &GV : M.global_values()) + if (!GV.getName().startswith("llvm.") && !GV.hasAtLeastLocalUnnamedAddr()) + OutStreamer->EmitAddrsigSym(getSymbol(&GV)); + } + // Allow the target to emit any magic that it wants at the end of the file, // after everything else has gone out. EmitEndOfAsmFile(M); Index: llvm/trunk/test/CodeGen/X86/addrsig.ll =================================================================== --- llvm/trunk/test/CodeGen/X86/addrsig.ll +++ llvm/trunk/test/CodeGen/X86/addrsig.ll @@ -0,0 +1,36 @@ +; RUN: llc < %s -mtriple=x86_64-unknown-linux | FileCheck --check-prefix=NO-ADDRSIG %s +; RUN: llc < %s -mtriple=x86_64-unknown-linux -addrsig | FileCheck %s + +; NO-ADDRSIG-NOT: .addrsig + +; CHECK: .addrsig + +; CHECK: .addrsig_sym f1 +define void @f1() { + unreachable +} + +; CHECK-NOT: .addrsig_sym f2 +define internal void @f2() local_unnamed_addr { + unreachable +} + +; CHECK-NOT: .addrsig_sym f3 +declare void @f3() unnamed_addr + +; CHECK: .addrsig_sym g1 +@g1 = global i32 0 +; CHECK-NOT: .addrsig_sym g2 +@g2 = internal local_unnamed_addr global i32 0 +; CHECK-NOT: .addrsig_sym g3 +@g3 = external unnamed_addr global i32 + +; CHECK: .addrsig_sym a1 +@a1 = alias i32, i32* @g1 +; CHECK-NOT: .addrsig_sym a2 +@a2 = internal local_unnamed_addr alias i32, i32* @g2 + +; CHECK: .addrsig_sym i1 +@i1 = ifunc void(), void()* @f1 +; CHECK-NOT: .addrsig_sym i2 +@i2 = internal local_unnamed_addr ifunc void(), void()* @f2