Skip to content

Commit

Permalink
[Driver] Adjust -fsanitize=function & -mexecute-only interop after D1…
Browse files Browse the repository at this point in the history
…58614

clangDriver depends on clangBasic, so clangBasic should not depend on
clangDriver, even just its header. Also remove clangBasic's dependency
on LLVMOption.

The issue can be seen through the bazel commit
d26dd681f9726ed7d43d7c0bdd8ee3cb2db69a2b which is reverted now.

Add hasFlagNoClaim and use it as we don't want to suppress
-Wunused-command-line-argument for -mexecute-only just because
-fsanitize= is specified.
  • Loading branch information
MaskRay authored and tru committed Sep 1, 2023
1 parent c138c8a commit 051aa17
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
5 changes: 0 additions & 5 deletions clang/include/clang/Basic/Sanitizers.h
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,6 @@ StringRef AsanDetectStackUseAfterReturnModeToString(
llvm::AsanDetectStackUseAfterReturnMode
AsanDetectStackUseAfterReturnModeFromString(StringRef modeStr);

/// Return true if an execute-only target disallows data access to code
/// sections.
bool isExecuteOnlyTarget(const llvm::Triple &Triple,
const llvm::opt::ArgList &Args);

} // namespace clang

#endif // LLVM_CLANG_BASIC_SANITIZERS_H
1 change: 0 additions & 1 deletion clang/lib/Basic/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
set(LLVM_LINK_COMPONENTS
Option
Support
TargetParser
)
Expand Down
13 changes: 0 additions & 13 deletions clang/lib/Basic/Sanitizers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@
//===----------------------------------------------------------------------===//

#include "clang/Basic/Sanitizers.h"
#include "clang/Driver/Options.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/TargetParser/Triple.h"

using namespace clang;

Expand Down Expand Up @@ -115,14 +112,4 @@ AsanDetectStackUseAfterReturnModeFromString(StringRef modeStr) {
.Default(llvm::AsanDetectStackUseAfterReturnMode::Invalid);
}

bool isExecuteOnlyTarget(const llvm::Triple &Triple,
const llvm::opt::ArgList &Args) {
if (Triple.isPS5())
return true;

// On Arm, the clang `-mexecute-only` option is used to generate the
// execute-only output (no data access to code sections).
return Args.hasFlag(clang::driver::options::OPT_mexecute_only,
clang::driver::options::OPT_mno_execute_only, false);
}
} // namespace clang
10 changes: 10 additions & 0 deletions clang/lib/Driver/SanitizerArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,16 @@ static std::string describeSanitizeArg(const llvm::opt::Arg *A,
/// Sanitizers set.
static std::string toString(const clang::SanitizerSet &Sanitizers);

/// Return true if an execute-only target disallows data access to code
/// sections.
static bool isExecuteOnlyTarget(const llvm::Triple &Triple,
const llvm::opt::ArgList &Args) {
if (Triple.isPS5())
return true;
return Args.hasFlagNoClaim(options::OPT_mexecute_only,
options::OPT_mno_execute_only, false);
}

static void validateSpecialCaseListFormat(const Driver &D,
std::vector<std::string> &SCLFiles,
unsigned MalformedSCLErrorDiagID,
Expand Down
1 change: 1 addition & 0 deletions llvm/include/llvm/Option/ArgList.h
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ class ArgList {
/// \p Default if neither option is given. If both the option and its
/// negation are present, the last one wins.
bool hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const;
bool hasFlagNoClaim(OptSpecifier Pos, OptSpecifier Neg, bool Default) const;

/// hasFlag - Given an option \p Pos, an alias \p PosAlias and its negative
/// form \p Neg, return true if the option or its alias is present, false if
Expand Down
7 changes: 7 additions & 0 deletions llvm/lib/Option/ArgList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const {
return Default;
}

bool ArgList::hasFlagNoClaim(OptSpecifier Pos, OptSpecifier Neg,
bool Default) const {
if (Arg *A = getLastArgNoClaim(Pos, Neg))
return A->getOption().matches(Pos);
return Default;
}

bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg,
bool Default) const {
if (Arg *A = getLastArg(Pos, PosAlias, Neg))
Expand Down

0 comments on commit 051aa17

Please sign in to comment.