[clang] dbb1130 - Revert "Use-after-return sanitizer binary metadata"
Kazu Hirata via cfe-commits
cfe-commits at lists.llvm.org
Tue Nov 29 09:04:06 PST 2022
Author: Kazu Hirata
Date: 2022-11-29T09:04:00-08:00
New Revision: dbb11309665fdf7d411d25cc8f2e6a0c8f658143
URL: https://github.com/llvm/llvm-project/commit/dbb11309665fdf7d411d25cc8f2e6a0c8f658143
DIFF: https://github.com/llvm/llvm-project/commit/dbb11309665fdf7d411d25cc8f2e6a0c8f658143.diff
LOG: Revert "Use-after-return sanitizer binary metadata"
This reverts commit a1255dc467f7ce57a966efa76bbbb4ee91d9115a.
This patch results in:
llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp:57:17: error: no member
named 'size' in 'llvm::MDTuple'
Added:
Modified:
clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Basic/CodeGenOptions.h
clang/include/clang/Driver/Options.td
clang/lib/CodeGen/BackendUtil.cpp
clang/lib/Driver/SanitizerArgs.cpp
llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
llvm/include/llvm/CodeGen/MachinePassRegistry.def
llvm/include/llvm/CodeGen/Passes.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/Transforms/Instrumentation.h
llvm/include/llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h
llvm/lib/CodeGen/CMakeLists.txt
llvm/lib/CodeGen/CodeGen.cpp
llvm/lib/CodeGen/TargetPassConfig.cpp
llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
Removed:
llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
llvm/test/Instrumentation/SanitizerBinaryMetadata/common.h
llvm/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp
llvm/test/Instrumentation/SanitizerBinaryMetadata/lit.local.cfg
llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp
################################################################################
diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def
index 81d5ccd4856d4..43521b76652db 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -288,8 +288,6 @@ CODEGENOPT(SanitizeCoverageTraceLoads, 1, 0) ///< Enable tracing of loads.
CODEGENOPT(SanitizeCoverageTraceStores, 1, 0) ///< Enable tracing of stores.
CODEGENOPT(SanitizeBinaryMetadataCovered, 1, 0) ///< Emit PCs for covered functions.
CODEGENOPT(SanitizeBinaryMetadataAtomics, 1, 0) ///< Emit PCs for atomic operations.
-CODEGENOPT(SanitizeBinaryMetadataUAR, 1, 0) ///< Emit PCs for start of functions
- ///< that are subject for use-after-return checking.
CODEGENOPT(SanitizeStats , 1, 0) ///< Collect statistics for sanitizers.
CODEGENOPT(SimplifyLibCalls , 1, 1) ///< Set when -fbuiltin is enabled.
CODEGENOPT(SoftFloat , 1, 0) ///< -soft-float.
diff --git a/clang/include/clang/Basic/CodeGenOptions.h b/clang/include/clang/Basic/CodeGenOptions.h
index a1a20995f211d..13794035c9076 100644
--- a/clang/include/clang/Basic/CodeGenOptions.h
+++ b/clang/include/clang/Basic/CodeGenOptions.h
@@ -497,8 +497,7 @@ class CodeGenOptions : public CodeGenOptionsBase {
// Check if any one of SanitizeBinaryMetadata* is enabled.
bool hasSanitizeBinaryMetadata() const {
- return SanitizeBinaryMetadataCovered || SanitizeBinaryMetadataAtomics ||
- SanitizeBinaryMetadataUAR;
+ return SanitizeBinaryMetadataCovered || SanitizeBinaryMetadataAtomics;
}
};
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 1d577ab70788e..8da5e25bd38d0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5575,10 +5575,6 @@ def fexperimental_sanitize_metadata_EQ_atomics
: Flag<["-"], "fexperimental-sanitize-metadata=atomics">,
HelpText<"Emit PCs for atomic operations used by binary analysis sanitizers">,
MarshallingInfoFlag<CodeGenOpts<"SanitizeBinaryMetadataAtomics">>;
-def fexperimental_sanitize_metadata_EQ_uar
- : Flag<["-"], "fexperimental-sanitize-metadata=uar">,
- HelpText<"Emit PCs for start of functions that are subject for use-after-return checking.">,
- MarshallingInfoFlag<CodeGenOpts<"SanitizeBinaryMetadataUAR">>;
def fpatchable_function_entry_offset_EQ
: Joined<["-"], "fpatchable-function-entry-offset=">, MetaVarName<"<M>">,
HelpText<"Generate M NOPs before function entry">,
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 717ec33441232..2b241967f5e7b 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -234,7 +234,6 @@ getSanitizerBinaryMetadataOptions(const CodeGenOptions &CGOpts) {
SanitizerBinaryMetadataOptions Opts;
Opts.Covered = CGOpts.SanitizeBinaryMetadataCovered;
Opts.Atomics = CGOpts.SanitizeBinaryMetadataAtomics;
- Opts.UAR = CGOpts.SanitizeBinaryMetadataUAR;
return Opts;
}
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index 96a701366e37b..af27dbc92c8e6 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -104,7 +104,6 @@ enum CoverageFeature {
enum BinaryMetadataFeature {
BinaryMetadataCovered = 1 << 0,
BinaryMetadataAtomics = 1 << 1,
- BinaryMetadataUAR = 1 << 2,
};
/// Parse a -fsanitize= or -fno-sanitize= argument's values, diagnosing any
@@ -1134,8 +1133,7 @@ void SanitizerArgs::addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args,
// flags. Does not depend on any other sanitizers.
const std::pair<int, std::string> BinaryMetadataFlags[] = {
std::make_pair(BinaryMetadataCovered, "covered"),
- std::make_pair(BinaryMetadataAtomics, "atomics"),
- std::make_pair(BinaryMetadataUAR, "uar")};
+ std::make_pair(BinaryMetadataAtomics, "atomics")};
for (const auto &F : BinaryMetadataFlags) {
if (BinaryMetadataFeatures & F.first)
CmdArgs.push_back(
@@ -1401,7 +1399,6 @@ int parseBinaryMetadataFeatures(const Driver &D, const llvm::opt::Arg *A,
int F = llvm::StringSwitch<int>(Value)
.Case("covered", BinaryMetadataCovered)
.Case("atomics", BinaryMetadataAtomics)
- .Case("uar", BinaryMetadataUAR)
.Case("all", ~0)
.Default(0);
if (F == 0 && DiagnoseErrors)
diff --git a/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h b/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
index fbaa1b229f55a..48aa4b034fee0 100644
--- a/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
+++ b/llvm/include/llvm/CodeGen/CodeGenPassBuilder.h
@@ -926,7 +926,6 @@ Error CodeGenPassBuilder<Derived>::addMachinePasses(
addPass(StackMapLivenessPass());
addPass(LiveDebugValuesPass());
- addPass(MachineSanitizerBinaryMetadata());
if (TM.Options.EnableMachineOutliner && getOptLevel() != CodeGenOpt::None &&
Opt.EnableMachineOutliner != RunOutliner::NeverOutline) {
diff --git a/llvm/include/llvm/CodeGen/MachinePassRegistry.def b/llvm/include/llvm/CodeGen/MachinePassRegistry.def
index 0e5a8d64d1ee3..617214aaca3c1 100644
--- a/llvm/include/llvm/CodeGen/MachinePassRegistry.def
+++ b/llvm/include/llvm/CodeGen/MachinePassRegistry.def
@@ -202,5 +202,4 @@ DUMMY_MACHINE_FUNCTION_PASS("instruction-select", InstructionSelectPass, ())
DUMMY_MACHINE_FUNCTION_PASS("reset-machine-function", ResetMachineFunctionPass, ())
DUMMY_MACHINE_FUNCTION_PASS("machineverifier", MachineVerifierPass, ())
DUMMY_MACHINE_FUNCTION_PASS("print-machine-cycles", MachineCycleInfoPrinterPass, ())
-DUMMY_MACHINE_FUNCTION_PASS("machine-sanmd", MachineSanitizerBinaryMetadata, ())
#undef DUMMY_MACHINE_FUNCTION_PASS
diff --git a/llvm/include/llvm/CodeGen/Passes.h b/llvm/include/llvm/CodeGen/Passes.h
index cdace28c7def7..5fcbc8ed9abe1 100644
--- a/llvm/include/llvm/CodeGen/Passes.h
+++ b/llvm/include/llvm/CodeGen/Passes.h
@@ -409,10 +409,6 @@ namespace llvm {
/// the intrinsic for later emission to the StackMap.
extern char &StackMapLivenessID;
- // MachineSanitizerBinaryMetadata - appends/finalizes sanitizer binary
- // metadata after llvm SanitizerBinaryMetadata pass.
- extern char &MachineSanitizerBinaryMetadataID;
-
/// RemoveRedundantDebugValues pass.
extern char &RemoveRedundantDebugValuesID;
diff --git a/llvm/include/llvm/InitializePasses.h b/llvm/include/llvm/InitializePasses.h
index c123d483caf72..2e6b497d06930 100644
--- a/llvm/include/llvm/InitializePasses.h
+++ b/llvm/include/llvm/InitializePasses.h
@@ -285,7 +285,6 @@ void initializeMachineOutlinerPass(PassRegistry&);
void initializeMachinePipelinerPass(PassRegistry&);
void initializeMachinePostDominatorTreePass(PassRegistry&);
void initializeMachineRegionInfoPassPass(PassRegistry&);
-void initializeMachineSanitizerBinaryMetadataPass(PassRegistry &);
void initializeMachineSchedulerPass(PassRegistry&);
void initializeMachineSinkingPass(PassRegistry&);
void initializeMachineTraceMetricsPass(PassRegistry&);
diff --git a/llvm/include/llvm/Transforms/Instrumentation.h b/llvm/include/llvm/Transforms/Instrumentation.h
index 392983a198444..2497b3d40d0b0 100644
--- a/llvm/include/llvm/Transforms/Instrumentation.h
+++ b/llvm/include/llvm/Transforms/Instrumentation.h
@@ -150,6 +150,13 @@ struct SanitizerCoverageOptions {
SanitizerCoverageOptions() = default;
};
+/// Options for SanitizerBinaryMetadata.
+struct SanitizerBinaryMetadataOptions {
+ bool Covered = false;
+ bool Atomics = false;
+ SanitizerBinaryMetadataOptions() = default;
+};
+
/// Calculate what to divide by to scale counts.
///
/// Given the maximum count, calculate a divisor that will scale all the
diff --git a/llvm/include/llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h b/llvm/include/llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h
index 67e22d1aa6818..a54801309c1d8 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h
@@ -19,27 +19,6 @@
namespace llvm {
-struct SanitizerBinaryMetadataOptions {
- bool Covered = false;
- bool Atomics = false;
- bool UAR = false;
- SanitizerBinaryMetadataOptions() = default;
-};
-
-inline constexpr int kSanitizerBinaryMetadataAtomicsBit = 0;
-inline constexpr int kSanitizerBinaryMetadataUARBit = 1;
-
-inline constexpr uint32_t kSanitizerBinaryMetadataNone = 0;
-inline constexpr uint32_t kSanitizerBinaryMetadataAtomics =
- 1 << kSanitizerBinaryMetadataAtomicsBit;
-inline constexpr uint32_t kSanitizerBinaryMetadataUAR =
- 1 << kSanitizerBinaryMetadataUARBit;
-
-inline constexpr char kSanitizerBinaryMetadataCoveredSection[] =
- "sanmd_covered";
-inline constexpr char kSanitizerBinaryMetadataAtomicsSection[] =
- "sanmd_atomics";
-
/// Public interface to the SanitizerBinaryMetadata module pass for emitting
/// metadata for binary analysis sanitizers.
//
diff --git a/llvm/lib/CodeGen/CMakeLists.txt b/llvm/lib/CodeGen/CMakeLists.txt
index 35eb8ba40ba08..2289ea5de82e3 100644
--- a/llvm/lib/CodeGen/CMakeLists.txt
+++ b/llvm/lib/CodeGen/CMakeLists.txt
@@ -196,7 +196,6 @@ add_llvm_component_library(LLVMCodeGen
RegisterBankInfo.cpp
SafeStack.cpp
SafeStackLayout.cpp
- SanitizerBinaryMetadata.cpp
ScheduleDAG.cpp
ScheduleDAGInstrs.cpp
ScheduleDAGPrinter.cpp
diff --git a/llvm/lib/CodeGen/CodeGen.cpp b/llvm/lib/CodeGen/CodeGen.cpp
index 076d91f95aa42..5d30e82f49dba 100644
--- a/llvm/lib/CodeGen/CodeGen.cpp
+++ b/llvm/lib/CodeGen/CodeGen.cpp
@@ -83,7 +83,6 @@ void llvm::initializeCodeGen(PassRegistry &Registry) {
initializeMachineOptimizationRemarkEmitterPassPass(Registry);
initializeMachineOutlinerPass(Registry);
initializeMachinePipelinerPass(Registry);
- initializeMachineSanitizerBinaryMetadataPass(Registry);
initializeModuloScheduleTestPass(Registry);
initializeMachinePostDominatorTreePass(Registry);
initializeMachineRegionInfoPassPass(Registry);
diff --git a/llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp b/llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
deleted file mode 100644
index 57470b4218a2d..0000000000000
--- a/llvm/lib/CodeGen/SanitizerBinaryMetadata.cpp
+++ /dev/null
@@ -1,78 +0,0 @@
-//===- SanitizerBinaryMetadata.cpp
-//----------------------------------------------===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of SanitizerBinaryMetadata.
-//
-//===----------------------------------------------------------------------===//
-
-#include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
-#include "llvm/CodeGen/MachineFrameInfo.h"
-#include "llvm/CodeGen/MachineFunction.h"
-#include "llvm/CodeGen/MachineFunctionPass.h"
-#include "llvm/CodeGen/Passes.h"
-#include "llvm/IR/IRBuilder.h"
-#include "llvm/IR/MDBuilder.h"
-#include "llvm/InitializePasses.h"
-#include "llvm/Pass.h"
-#include <algorithm>
-
-using namespace llvm;
-
-class MachineSanitizerBinaryMetadata : public MachineFunctionPass {
-public:
- static char ID;
-
- MachineSanitizerBinaryMetadata();
- bool runOnMachineFunction(MachineFunction &F) override;
-};
-
-INITIALIZE_PASS(MachineSanitizerBinaryMetadata, "machine-sanmd",
- "Machine Sanitizer Binary Metadata", false, false)
-
-char MachineSanitizerBinaryMetadata::ID = 0;
-char &llvm::MachineSanitizerBinaryMetadataID =
- MachineSanitizerBinaryMetadata::ID;
-
-MachineSanitizerBinaryMetadata::MachineSanitizerBinaryMetadata()
- : MachineFunctionPass(ID) {
- initializeMachineSanitizerBinaryMetadataPass(
- *PassRegistry::getPassRegistry());
-}
-
-bool MachineSanitizerBinaryMetadata::runOnMachineFunction(MachineFunction &MF) {
- MDNode *MD = MF.getFunction().getMetadata(LLVMContext::MD_pcsections);
- if (!MD)
- return false;
- const auto &Section = *cast<MDString>(MD->getOperand(0));
- if (!Section.getString().equals(kSanitizerBinaryMetadataCoveredSection))
- return false;
- auto &AuxMDs = *cast<MDTuple>(MD->getOperand(1));
- // Assume it currently only has features.
- assert(AuxMDs.size() == 1);
- auto *Features = cast<ConstantAsMetadata>(AuxMDs.getOperand(0))->getValue();
- if (!Features->getUniqueInteger()[kSanitizerBinaryMetadataUARBit])
- return false;
- // Calculate size of stack args for the function.
- int64_t Size = 0;
- uint64_t Align = 0;
- const MachineFrameInfo &MFI = MF.getFrameInfo();
- for (int i = -1; i >= (int)-MFI.getNumFixedObjects(); --i) {
- Size = std::max(Size, MFI.getObjectOffset(i) + MFI.getObjectSize(i));
- Align = std::max(Align, MFI.getObjectAlign(i).value());
- }
- Size = (Size + Align - 1) & ~(Align - 1);
- auto &F = MF.getFunction();
- IRBuilder<> IRB(F.getContext());
- MDBuilder MDB(F.getContext());
- // Keep the features and append size of stack args to the metadata.
- const auto *NewMD = MDB.createPCSections(
- {{Section.getString(), {Features, IRB.getInt32(Size)}}});
- MD->replaceOperandWith(1, NewMD->getOperand(1));
- return false;
-}
diff --git a/llvm/lib/CodeGen/TargetPassConfig.cpp b/llvm/lib/CodeGen/TargetPassConfig.cpp
index 13e2ba6ce4ada..cb109745d291b 100644
--- a/llvm/lib/CodeGen/TargetPassConfig.cpp
+++ b/llvm/lib/CodeGen/TargetPassConfig.cpp
@@ -1269,7 +1269,6 @@ void TargetPassConfig::addMachinePasses() {
addPass(&StackMapLivenessID);
addPass(&LiveDebugValuesID);
- addPass(&MachineSanitizerBinaryMetadataID);
if (TM->Options.EnableMachineOutliner && getOptLevel() != CodeGenOpt::None &&
EnableMachineOutliner != RunOutliner::NeverOutline) {
diff --git a/llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp b/llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
index 29be14c21b8e6..58c29d8b211e2 100644
--- a/llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
+++ b/llvm/lib/Transforms/Instrumentation/SanitizerBinaryMetadata.cpp
@@ -67,16 +67,14 @@ class MetadataInfo {
private:
// Forbid construction elsewhere.
explicit constexpr MetadataInfo(StringRef FunctionPrefix,
- StringRef SectionSuffix, uint32_t Feature)
+ StringRef SectionSuffix, int Feature)
: FunctionPrefix(FunctionPrefix), SectionSuffix(SectionSuffix),
- FeatureMask(Feature) {}
+ FeatureMask(Feature != -1 ? (1u << Feature) : 0) {}
};
const MetadataInfo MetadataInfo::Covered{"__sanitizer_metadata_covered",
- kSanitizerBinaryMetadataCoveredSection,
- kSanitizerBinaryMetadataNone};
+ "sanmd_covered", -1};
const MetadataInfo MetadataInfo::Atomics{"__sanitizer_metadata_atomics",
- kSanitizerBinaryMetadataAtomicsSection,
- kSanitizerBinaryMetadataAtomics};
+ "sanmd_atomics", 0};
// The only instances of MetadataInfo are the constants above, so a set of
// them may simply store pointers to them. To deterministically generate code,
@@ -91,16 +89,11 @@ cl::opt<bool> ClEmitCovered("sanitizer-metadata-covered",
cl::opt<bool> ClEmitAtomics("sanitizer-metadata-atomics",
cl::desc("Emit PCs for atomic operations."),
cl::Hidden, cl::init(false));
-cl::opt<bool> ClEmitUAR("sanitizer-metadata-uar",
- cl::desc("Emit PCs for start of functions that are "
- "subject for use-after-return checking"),
- cl::Hidden, cl::init(false));
//===--- Statistics -------------------------------------------------------===//
STATISTIC(NumMetadataCovered, "Metadata attached to covered functions");
STATISTIC(NumMetadataAtomics, "Metadata attached to atomics");
-STATISTIC(NumMetadataUAR, "Metadata attached to UAR functions");
//===----------------------------------------------------------------------===//
@@ -109,7 +102,6 @@ SanitizerBinaryMetadataOptions &&
transformOptionsFromCl(SanitizerBinaryMetadataOptions &&Opts) {
Opts.Covered |= ClEmitCovered;
Opts.Atomics |= ClEmitAtomics;
- Opts.UAR |= ClEmitUAR;
return std::move(Opts);
}
@@ -150,8 +142,7 @@ class SanitizerBinaryMetadata {
// function with memory operations (atomic or not) requires covered metadata
// to determine if a memory operation is atomic or not in modules compiled
// with SanitizerBinaryMetadata.
- bool runOn(Instruction &I, MetadataInfoSet &MIS, MDBuilder &MDB,
- uint32_t &FeatureMask);
+ bool runOn(Instruction &I, MetadataInfoSet &MIS, MDBuilder &MDB);
// Get start/end section marker pointer.
GlobalVariable *getSectionMarker(const Twine &MarkerName, Type *Ty);
@@ -241,58 +232,36 @@ void SanitizerBinaryMetadata::runOn(Function &F, MetadataInfoSet &MIS) {
// The metadata features enabled for this function, stored along covered
// metadata (if enabled).
- uint32_t FeatureMask = getEnabledPerInstructionFeature();
+ uint32_t PerInstrFeatureMask = getEnabledPerInstructionFeature();
// Don't emit unnecessary covered metadata for all functions to save space.
bool RequiresCovered = false;
- // We can only understand if we need to set UAR feature after looking
- // at the instructions. So we need to check instructions even if FeatureMask
- // is empty.
- if (FeatureMask || Options.UAR) {
+ if (PerInstrFeatureMask) {
for (BasicBlock &BB : F)
for (Instruction &I : BB)
- RequiresCovered |= runOn(I, MIS, MDB, FeatureMask);
+ RequiresCovered |= runOn(I, MIS, MDB);
}
- if (F.isVarArg())
- FeatureMask &= ~kSanitizerBinaryMetadataUAR;
- if (FeatureMask & kSanitizerBinaryMetadataUAR)
- NumMetadataUAR++;
-
// Covered metadata is always emitted if explicitly requested, otherwise only
// if some other metadata requires it to unambiguously interpret it for
// modules compiled with SanitizerBinaryMetadata.
- if (Options.Covered || (FeatureMask && RequiresCovered)) {
+ if (Options.Covered || RequiresCovered) {
NumMetadataCovered++;
const auto *MI = &MetadataInfo::Covered;
MIS.insert(MI);
const StringRef Section = getSectionName(MI->SectionSuffix);
// The feature mask will be placed after the size (32 bit) of the function,
// so in total one covered entry will use `sizeof(void*) + 4 + 4`.
- Constant *CFM = IRB.getInt32(FeatureMask);
+ Constant *CFM = IRB.getInt32(PerInstrFeatureMask);
F.setMetadata(LLVMContext::MD_pcsections,
MDB.createPCSections({{Section, {CFM}}}));
}
}
bool SanitizerBinaryMetadata::runOn(Instruction &I, MetadataInfoSet &MIS,
- MDBuilder &MDB, uint32_t &FeatureMask) {
+ MDBuilder &MDB) {
SmallVector<const MetadataInfo *, 1> InstMetadata;
bool RequiresCovered = false;
- if (Options.UAR) {
- for (unsigned i = 0; i < I.getNumOperands(); ++i) {
- const Value *V = I.getOperand(i);
- // TODO(dvyukov): check if V is an address of alloca/function arg.
- // See isSafeAndProfitableToSinkLoad for addr-taken allocas
- // and DeadArgumentEliminationPass::removeDeadStuffFromFunction
- // for iteration over function args.
- if (V) {
- RequiresCovered = true;
- FeatureMask |= kSanitizerBinaryMetadataUAR;
- }
- }
- }
-
if (Options.Atomics && I.mayReadOrWriteMemory()) {
auto SSID = getAtomicSyncScopeID(&I);
if (SSID.has_value() && SSID.value() != SyncScope::SingleThread) {
diff --git a/llvm/test/Instrumentation/SanitizerBinaryMetadata/common.h b/llvm/test/Instrumentation/SanitizerBinaryMetadata/common.h
deleted file mode 100644
index 71e7f2bcf0259..0000000000000
--- a/llvm/test/Instrumentation/SanitizerBinaryMetadata/common.h
+++ /dev/null
@@ -1,72 +0,0 @@
-#include <stdint.h>
-#include <stdio.h>
-#include <assert.h>
-
-int main() {
- printf("main\n");
-}
-
-typedef unsigned long uptr;
-
-#define FN(X) if (pc == reinterpret_cast<uptr>(X)) return #X
-
-const char* symbolize(uptr pc) {
- FUNCTIONS;
- return nullptr;
-}
-
-template<typename T>
-T consume(const char*& pos, const char* end) {
- T v = *reinterpret_cast<const T*>(pos);
- pos += sizeof(T);
- assert(pos <= end);
- return v;
-}
-
-uint32_t meta_version;
-const char* meta_start;
-const char* meta_end;
-
-extern "C" {
-void __sanitizer_metadata_covered_add(uint32_t version, const char* start, const char* end) {
- printf("metadata add version %u\n", version);
- for (const char* pos = start; pos < end;) {
- const uptr base = reinterpret_cast<uptr>(pos);
- const long offset = (version & (1 << 16)) ?
- consume<long>(pos, end) : consume<int>(pos, end);
- const uint32_t size = consume<uint32_t>(pos, end);
- const uint32_t features = consume<uint32_t>(pos, end);
- uint32_t stack_args = 0;
- if (features & (1 << 1))
- stack_args = consume<uint32_t>(pos, end);
- if (const char* name = symbolize(base + offset))
- printf("%s: features=%x stack_args=%u\n", name, features, stack_args);
- }
- meta_version = version;
- meta_start = start;
- meta_end = end;
-}
-
-void __sanitizer_metadata_covered_del(uint32_t version, const char* start, const char* end) {
- assert(version == meta_version);
- assert(start == meta_start);
- assert(end == meta_end);
-}
-
-const char* atomics_start;
-const char* atomics_end;
-
-void __sanitizer_metadata_atomics_add(uint32_t version, const char* start, const char* end) {
- assert(version == meta_version);
- assert(start);
- assert(end >= end);
- atomics_start = start;
- atomics_end = end;
-}
-
-void __sanitizer_metadata_atomics_del(uint32_t version, const char* start, const char* end) {
- assert(version == meta_version);
- assert(atomics_start == start);
- assert(atomics_end == end);
-}
-}
diff --git a/llvm/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp b/llvm/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp
deleted file mode 100644
index 70337e0a7ee0b..0000000000000
--- a/llvm/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-// REQUIRES: native && target-x86_64
-// RUN: clang++ %s -o %t && %t | FileCheck %s
-// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered && %t | FileCheck -check-prefix=CHECK-C %s
-// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=atomics && %t | FileCheck -check-prefix=CHECK-A %s
-// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=uar && %t | FileCheck -check-prefix=CHECK-U %s
-// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered,atomics && %t | FileCheck -check-prefix=CHECK-CA %s
-// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered,uar && %t | FileCheck -check-prefix=CHECK-CU %s
-// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=atomics,uar && %t | FileCheck -check-prefix=CHECK-AU %s
-// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered,atomics,uar && %t | FileCheck -check-prefix=CHECK-CAU %s
-
-// CHECK-NOT: metadata add
-// CHECK: main
-// CHECK-NOT: metadata del
-
-// CHECK-C: empty: features=0
-// CHECK-A-NOT: empty:
-// CHECK-U-NOT: empty:
-// CHECK-CA: empty: features=1
-// CHECK-CU: empty: features=0
-// CHECK-AU-NOT: empty:
-// CHECK-CAU: empty: features=1
-void empty() {
-}
-
-// CHECK-C: normal: features=0
-// CHECK-A: normal: features=1
-// CHECK-U: normal: features=2
-// CHECK-CA: normal: features=1
-// CHECK-CU: normal: features=2
-// CHECK-AU: normal: features=3
-// CHECK-CAU:normal: features=3
-void normal() {
- volatile int x;
- x = 0;
-}
-
-// CHECK-C: with_atomic: features=0
-// CHECK-A: with_atomic: features=1
-// CHECK-U: with_atomic: features=2
-// CHECK-CA: with_atomic: features=1
-// CHECK-CU: with_atomic: features=2
-// CHECK-AU: with_atomic: features=3
-// CHECK-CAU: with_atomic: features=3
-int with_atomic(int* p) {
- return __atomic_load_n(p, __ATOMIC_RELAXED);
-}
-
-// CHECK-C: ellipsis: features=0
-// CHECK-A: ellipsis: features=1
-// CHECK-U-NOT: ellipsis:
-// CHECK-CA: ellipsis: features=1
-// CHECK-CU: ellipsis: features=0
-// CHECK-AU: ellipsis: features=1
-// CHECK-CAU: ellipsis: features=1
-void ellipsis(int* p, ...) {
- volatile int x;
- x = 0;
-}
-
-// CHECK-C: ellipsis_with_atomic: features=0
-// CHECK-A: ellipsis_with_atomic: features=1
-// CHECK-U-NOT: ellipsis_with_atomic:
-// CHECK-CA: ellipsis_with_atomic: features=1
-// CHECK-CU: ellipsis_with_atomic: features=0
-// CHECK-AU: ellipsis_with_atomic: features=1
-// CHECK-CAU: ellipsis_with_atomic: features=1
-int ellipsis_with_atomic(int* p, ...) {
- return __atomic_load_n(p, __ATOMIC_RELAXED);
-}
-
-#define FUNCTIONS \
- FN(empty); \
- FN(normal); \
- FN(with_atomic); \
- FN(ellipsis); \
- FN(ellipsis_with_atomic); \
-/**/
-
-#include "common.h"
diff --git a/llvm/test/Instrumentation/SanitizerBinaryMetadata/lit.local.cfg b/llvm/test/Instrumentation/SanitizerBinaryMetadata/lit.local.cfg
deleted file mode 100644
index 0ce1134ac1d47..0000000000000
--- a/llvm/test/Instrumentation/SanitizerBinaryMetadata/lit.local.cfg
+++ /dev/null
@@ -1 +0,0 @@
-config.suffixes = ['.ll', '.cpp']
diff --git a/llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp b/llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp
deleted file mode 100644
index bb7c3542277e2..0000000000000
--- a/llvm/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-// We run the compiled binary + sizes of stack arguments depend on the arch.
-// REQUIRES: native && target-x86_64
-// RUN: clang++ %s -o %t -fexperimental-sanitize-metadata=covered,uar && %t | tee /dev/stderr | FileCheck %s
-
-// CHECK: metadata add version 1
-
-// CHECK: empty: features=0 stack_args=0
-void empty() {
-}
-
-// CHECK: ellipsis: features=0 stack_args=0
-void ellipsis(const char* fmt, ...) {
- volatile int x;
- x = 1;
-}
-
-// CHECK: non_empty_function: features=2 stack_args=0
-void non_empty_function() {
- // Completely empty functions don't get uar metadata.
- volatile int x;
- x = 1;
-}
-
-// CHECK: no_stack_args: features=2 stack_args=0
-void no_stack_args(long a0, long a1, long a2, long a3, long a4, long a5) {
- volatile int x;
- x = 1;
-}
-
-// CHECK: stack_args: features=2 stack_args=16
-void stack_args(long a0, long a1, long a2, long a3, long a4, long a5, long a6) {
- volatile int x;
- x = 1;
-}
-
-// CHECK: more_stack_args: features=2 stack_args=32
-void more_stack_args(long a0, long a1, long a2, long a3, long a4, long a5, long a6, long a7, long a8) {
- volatile int x;
- x = 1;
-}
-
-// CHECK: struct_stack_args: features=2 stack_args=144
-struct large { char x[131]; };
-void struct_stack_args(large a) {
- volatile int x;
- x = 1;
-}
-
-#define FUNCTIONS \
- FN(empty); \
- FN(ellipsis); \
- FN(non_empty_function); \
- FN(no_stack_args); \
- FN(stack_args); \
- FN(more_stack_args); \
- FN(struct_stack_args); \
-/**/
-
-#include "common.h"
More information about the cfe-commits
mailing list