CodeGen: Add a target option for emitting .addrsig directives for all address-significant symbols.

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

llvm-svn: 337331
This commit is contained in:
Peter Collingbourne 2018-07-17 22:40:08 +00:00
parent 7027ffa85f
commit bd9d313d5c
4 changed files with 56 additions and 4 deletions

View File

@ -261,6 +261,10 @@ static cl::opt<bool> EnableStackSizeSection(
"stack-size-section",
cl::desc("Emit a section containing stack size metadata"), cl::init(false));
static cl::opt<bool>
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 @@ static TargetOptions InitTargetOptionsFromCodeGenFlags() {
Options.ExplicitEmulatedTLS = EmulatedTLS.getNumOccurrences() > 0;
Options.ExceptionModel = ExceptionModel;
Options.EmitStackSizeSection = EnableStackSizeSection;
Options.EmitAddrsig = EnableAddrsig;
Options.MCOptions = InitMCTargetOptionsFromFlags();

View File

@ -108,10 +108,10 @@ namespace llvm {
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 @@ namespace llvm {
/// 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

View File

@ -1529,6 +1529,14 @@ bool AsmPrinter::doFinalization(Module &M) {
}
}
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);

View File

@ -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