serge-sans-paille updated this revision to Diff 239286. serge-sans-paille added a comment.
Take into account review Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D72829/new/ https://reviews.llvm.org/D72829 Files: clang/include/clang/Basic/LangOptions.def clang/include/clang/Driver/Options.td clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/lib/Frontend/CompilerInvocation.cpp llvm/include/llvm/IR/GlobalValue.h llvm/include/llvm/IR/Module.h llvm/lib/IR/Globals.cpp llvm/lib/IR/Module.cpp
Index: llvm/lib/IR/Module.cpp =================================================================== --- llvm/lib/IR/Module.cpp +++ llvm/lib/IR/Module.cpp @@ -554,6 +554,20 @@ : getModuleFlag("ProfileSummary")); } +bool Module::getSemanticInterposition() const { + auto *Val = + cast_or_null<ConstantAsMetadata>(getModuleFlag("SemanticInterposition")); + + if (!Val) + return false; + + return cast<ConstantInt>(Val->getValue())->getZExtValue(); +} + +void Module::setSemanticInterposition(bool SI) { + addModuleFlag(ModFlagBehavior::Error, "SemanticInterposition", SI); +} + void Module::setOwnedMemoryBuffer(std::unique_ptr<MemoryBuffer> MB) { OwnedMemoryBuffer = std::move(MB); } Index: llvm/lib/IR/Globals.cpp =================================================================== --- llvm/lib/IR/Globals.cpp +++ llvm/lib/IR/Globals.cpp @@ -94,6 +94,20 @@ llvm_unreachable("not a global"); } +bool GlobalValue::isInterposable() const { + + if (isInterposableLinkage(getLinkage())) + return true; + + bool const HonorSemanticInterposition = + getParent() && getParent()->getSemanticInterposition(); + + if (HonorSemanticInterposition && !isDSOLocal()) + return true; + + return false; +} + unsigned GlobalValue::getAlignment() const { if (auto *GA = dyn_cast<GlobalAlias>(this)) { // In general we cannot compute this at the IR level, but we try. Index: llvm/include/llvm/IR/Module.h =================================================================== --- llvm/include/llvm/IR/Module.h +++ llvm/include/llvm/IR/Module.h @@ -848,6 +848,17 @@ Metadata *getProfileSummary(bool IsCS); /// @} + /// @name Utility functions for querying and setting semantic interposition + /// @{ + + /// Returns whether semantic interposition is to be respected. + bool getSemanticInterposition() const; + + /// Set whether semantic interposition is to be respected. + void setSemanticInterposition(bool); + + /// @} + /// Returns true if PLT should be avoided for RTLib calls. bool getRtLibUseGOT() const; Index: llvm/include/llvm/IR/GlobalValue.h =================================================================== --- llvm/include/llvm/IR/GlobalValue.h +++ llvm/include/llvm/IR/GlobalValue.h @@ -284,6 +284,8 @@ return IsDSOLocal; } + bool isDSOPreemptable() const { return !IsDSOLocal; } + bool hasPartition() const { return HasPartition; } @@ -426,7 +428,7 @@ /// *arbitrary* definition at link time. We cannot do any IPO or inlinining /// across interposable call edges, since the callee can be replaced with /// something arbitrary at link time. - bool isInterposable() const { return isInterposableLinkage(getLinkage()); } + bool isInterposable() const; bool hasExternalLinkage() const { return isExternalLinkage(getLinkage()); } bool hasAvailableExternallyLinkage() const { Index: clang/lib/Frontend/CompilerInvocation.cpp =================================================================== --- clang/lib/Frontend/CompilerInvocation.cpp +++ clang/lib/Frontend/CompilerInvocation.cpp @@ -2685,6 +2685,9 @@ Opts.setValueVisibilityMode(DefaultVisibility); } + if (Args.hasArg(OPT_fsemantic_interposition)) + Opts.SemanticInterposition = 1; + // The type-visibility mode defaults to the value-visibility mode. if (Arg *typeVisOpt = Args.getLastArg(OPT_ftype_visibility)) { Opts.setTypeVisibilityMode(parseVisibility(typeVisOpt, Args, Diags)); Index: clang/lib/Driver/ToolChains/Clang.cpp =================================================================== --- clang/lib/Driver/ToolChains/Clang.cpp +++ clang/lib/Driver/ToolChains/Clang.cpp @@ -5037,6 +5037,10 @@ options::OPT_fno_emulated_tls); Args.AddLastArg(CmdArgs, options::OPT_fkeep_static_consts); + if (Args.hasFlag(options::OPT_fsemantic_interposition, + options::OPT_fno_semantic_interposition, false)) + CmdArgs.push_back("-fsemantic-interposition"); + // AltiVec-like language extensions aren't relevant for assembling. if (!isa<PreprocessJobAction>(JA) || Output.getType() != types::TY_PP_Asm) Args.AddLastArg(CmdArgs, options::OPT_fzvector); Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -483,6 +483,11 @@ getModule().addModuleFlag(llvm::Module::Max, "Dwarf Version", CodeGenOpts.DwarfVersion); } + + if (Context.getLangOpts().SemanticInterposition) + // Require various optimization to respect semantic interposition. + getModule().setSemanticInterposition(1); + if (CodeGenOpts.EmitCodeView) { // Indicate that we want CodeView in the metadata. getModule().addModuleFlag(llvm::Module::Warning, "CodeView", 1); @@ -857,7 +862,7 @@ if (isa<llvm::Function>(GV) && !CGOpts.NoPLT && RM == llvm::Reloc::Static) return true; - // Otherwise don't assue it is local. + // Otherwise don't assume it is local. return false; } Index: clang/include/clang/Driver/Options.td =================================================================== --- clang/include/clang/Driver/Options.td +++ clang/include/clang/Driver/Options.td @@ -3277,7 +3277,8 @@ defm ipa_cp : BooleanFFlag<"ipa-cp">, Group<clang_ignored_gcc_optimization_f_Group>; defm ivopts : BooleanFFlag<"ivopts">, Group<clang_ignored_gcc_optimization_f_Group>; -def : Flag<["-"], "fno-semantic-interposition">, Group<clang_ignored_f_Group>; +def fsemantic_interposition : Flag<["-"], "fsemantic-interposition">, Group<f_Group>, Flags<[CC1Option]>; +def fno_semantic_interposition: Flag<["-"], "fno-semantic-interposition">, Group<f_Group>; defm non_call_exceptions : BooleanFFlag<"non-call-exceptions">, Group<clang_ignored_f_Group>; defm peel_loops : BooleanFFlag<"peel-loops">, Group<clang_ignored_gcc_optimization_f_Group>; defm permissive : BooleanFFlag<"permissive">, Group<clang_ignored_f_Group>; Index: clang/include/clang/Basic/LangOptions.def =================================================================== --- clang/include/clang/Basic/LangOptions.def +++ clang/include/clang/Basic/LangOptions.def @@ -284,6 +284,7 @@ "default visibility for types [-ftype-visibility]") LANGOPT(SetVisibilityForExternDecls, 1, 0, "apply global symbol visibility to external declarations without an explicit visibility") +BENIGN_LANGOPT(SemanticInterposition , 1, 0, "semantic interposition") ENUM_LANGOPT(StackProtector, StackProtectorMode, 2, SSPOff, "stack protector mode") ENUM_LANGOPT(TrivialAutoVarInit, TrivialAutoVarInitKind, 2, TrivialAutoVarInitKind::Uninitialized,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits