Index: include/llvm/IR/DiagnosticInfo.h =================================================================== --- include/llvm/IR/DiagnosticInfo.h +++ include/llvm/IR/DiagnosticInfo.h @@ -72,6 +72,7 @@ DK_MIRParser, DK_PGOProfile, DK_Unsupported, + DK_SSPReason, DK_FirstPluginKind }; @@ -875,6 +876,36 @@ void print(DiagnosticPrinter &DP) const override; }; +/// Diagnostic information for why SSP was applied. +class DiagnosticInfoSSP : public DiagnosticInfoWithDebugLocBase { +public: + enum SSPReason { + Unknown = 0, + Alloca = 1, + BufferOrStruct = 2, + AddressTaken = 3, + Attribute = 4 + }; + + /// \p Fn is the function where the diagnostic is being emitted. \p Reason is + /// an enum value representing why the function has stack protection. + DiagnosticInfoSSP(const Function &Fn, SSPReason Reason) + : DiagnosticInfoWithDebugLocBase(DK_SSPReason, DS_Remark, Fn, DebugLoc()), + Func(Fn), Why(Reason) {} + + static bool classof(const DiagnosticInfo *DI) { + return DI->getKind() == DK_SSPReason; + } + + void print(DiagnosticPrinter &DP) const override; + + SSPReason Reason() const { return Why; } + +private: + const Function &Func; + const SSPReason Why; +}; + /// Emit a warning when loop vectorization is specified but fails. \p Fn is the /// function triggering the warning, \p DLoc is the debug location where the /// diagnostic is generated. \p Msg is the message string to use. Index: lib/CodeGen/StackProtector.cpp =================================================================== --- lib/CodeGen/StackProtector.cpp +++ lib/CodeGen/StackProtector.cpp @@ -26,6 +26,7 @@ #include "llvm/IR/DataLayout.h" #include "llvm/IR/DebugInfo.h" #include "llvm/IR/DerivedTypes.h" +#include "llvm/IR/DiagnosticInfo.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalVariable.h" @@ -51,7 +52,7 @@ char StackProtector::ID = 0; INITIALIZE_TM_PASS(StackProtector, "stack-protector", "Insert stack protectors", - false, true) + false, true) FunctionPass *llvm::createStackProtectorPass(const TargetMachine *TM) { return new StackProtector(TM); @@ -223,6 +224,8 @@ return false; if (F->hasFnAttribute(Attribute::StackProtectReq)) { + F->getContext().diagnose( + DiagnosticInfoSSP(*F, DiagnosticInfoSSP::SSPReason::Attribute)); NeedsProtector = true; Strong = true; // Use the same heuristic as strong to determine SSPLayout } else if (F->hasFnAttribute(Attribute::StackProtectStrong)) @@ -241,15 +244,21 @@ // A call to alloca with size >= SSPBufferSize requires // stack protectors. Layout.insert(std::make_pair(AI, SSPLK_LargeArray)); + F->getContext().diagnose( + DiagnosticInfoSSP(*F, DiagnosticInfoSSP::SSPReason::Alloca)); NeedsProtector = true; } else if (Strong) { // Require protectors for all alloca calls in strong mode. Layout.insert(std::make_pair(AI, SSPLK_SmallArray)); + F->getContext().diagnose( + DiagnosticInfoSSP(*F, DiagnosticInfoSSP::SSPReason::Alloca)); NeedsProtector = true; } } else { // A call to alloca with a variable size requires protectors. Layout.insert(std::make_pair(AI, SSPLK_LargeArray)); + F->getContext().diagnose( + DiagnosticInfoSSP(*F, DiagnosticInfoSSP::SSPReason::Alloca)); NeedsProtector = true; } continue; @@ -259,6 +268,8 @@ if (ContainsProtectableArray(AI->getAllocatedType(), IsLarge, Strong)) { Layout.insert(std::make_pair(AI, IsLarge ? SSPLK_LargeArray : SSPLK_SmallArray)); + F->getContext().diagnose(DiagnosticInfoSSP( + *F, DiagnosticInfoSSP::SSPReason::BufferOrStruct)); NeedsProtector = true; continue; } @@ -266,6 +277,8 @@ if (Strong && HasAddressTaken(AI)) { ++NumAddrTaken; Layout.insert(std::make_pair(AI, SSPLK_AddrOf)); + F->getContext().diagnose(DiagnosticInfoSSP( + *F, DiagnosticInfoSSP::SSPReason::AddressTaken)); NeedsProtector = true; } } Index: lib/IR/DiagnosticInfo.cpp =================================================================== --- lib/IR/DiagnosticInfo.cpp +++ lib/IR/DiagnosticInfo.cpp @@ -336,6 +336,16 @@ DP << Str; } +void DiagnosticInfoSSP::print(DiagnosticPrinter &DP) const { + std::string Str; + raw_string_ostream OS(Str); + + OS << getLocationStr() << ": SSP applied to function " << Func.getName() + << " due to " << Reason() << '\n'; + OS.flush(); + DP << Str; +} + void llvm::emitLoopVectorizeWarning(LLVMContext &Ctx, const Function &Fn, const DebugLoc &DLoc, const Twine &Msg) { Ctx.diagnose(DiagnosticInfoOptimizationFailure( Index: test/lit.cfg =================================================================== --- test/lit.cfg +++ test/lit.cfg @@ -231,7 +231,7 @@ config.substitutions.append( ('%ocamlc', "%s ocamlc -cclib -L%s %s" % (config.ocamlfind_executable, llvm_lib_dir, config.ocaml_flags)) ) -if config.have_ocamlopt: +if config.have_ocamlopt in ('1', 'TRUE'): config.substitutions.append( ('%ocamlopt', "%s ocamlopt -cclib -L%s -cclib -Wl,-rpath,%s %s" % (config.ocamlfind_executable, llvm_lib_dir, llvm_lib_dir, config.ocaml_flags)) ) @@ -269,6 +269,9 @@ tool_path = lit.util.which(tool_name, llvm_tools_dir) if tool_path is None: return tool_name, tool_path, tool_pipe + else: + tool_path = '"' + tool_path + '"' + if (tool_name == "llc" and 'LLVM_ENABLE_MACHINE_VERIFIER' in os.environ and os.environ['LLVM_ENABLE_MACHINE_VERIFIER'] == "1"): @@ -377,10 +380,6 @@ if loadable_module: config.available_features.add('loadable_module') -# Static libraries are not built if BUILD_SHARED_LIBS is ON. -if not config.build_shared_libs: - config.available_features.add("static-libs") - # Sanitizers. if 'Address' in config.llvm_use_sanitizer: config.available_features.add("asan") @@ -403,7 +402,7 @@ if not 'hexagon' in config.target_triple: config.available_features.add("object-emission") -if config.have_zlib: +if config.have_zlib == "1": config.available_features.add("zlib") else: config.available_features.add("nozlib") @@ -459,7 +458,7 @@ config.available_features.add('ld_plugin') def have_ld64_plugin_support(): - if not config.llvm_tool_lto_build or config.ld64_executable == '': + if (config.llvm_tool_lto_build == 'OFF' or config.ld64_executable == ''): return False ld_cmd = subprocess.Popen([config.ld64_executable, '-v'], stderr = subprocess.PIPE)