Index: llvm/include/llvm/CodeGen/CommandFlags.inc =================================================================== --- llvm/include/llvm/CodeGen/CommandFlags.inc +++ llvm/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/include/llvm/Target/TargetOptions.h =================================================================== --- llvm/include/llvm/Target/TargetOptions.h +++ llvm/include/llvm/Target/TargetOptions.h @@ -107,9 +107,9 @@ EnableFastISel(false), EnableGlobalISel(false), UseInitArray(false), DisableIntegratedAS(false), RelaxELFRelocations(false), FunctionSections(false), DataSections(false), - UniqueSectionNames(true), TrapUnreachable(false), - EmulatedTLS(false), ExplicitEmulatedTLS(false), - EnableIPRA(false), EmitStackSizeSection(false) {} + UniqueSectionNames(true), TrapUnreachable(false), EmulatedTLS(false), + ExplicitEmulatedTLS(false), EnableIPRA(false), + EmitStackSizeSection(false), EmitAddrsig(false) {} /// PrintMachineCode - This flag is enabled when the -print-machineinstrs /// option is specified on the command line, and should enable debugging @@ -226,6 +226,9 @@ /// Emit section containing metadata on function stack sizes. unsigned EmitStackSizeSection : 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/lib/CodeGen/AsmPrinter/AsmPrinter.cpp =================================================================== --- llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -1528,6 +1528,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/test/CodeGen/X86/addrsig.ll =================================================================== --- /dev/null +++ llvm/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