[clang] b95646f - Revert "Use-after-return sanitizer binary metadata"

Marco Elver via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 30 14:38:25 PST 2022


Author: Marco Elver
Date: 2022-11-30T23:35:50+01:00
New Revision: b95646fe7058471cc0ecda1efa25003009af0317

URL: https://github.com/llvm/llvm-project/commit/b95646fe7058471cc0ecda1efa25003009af0317
DIFF: https://github.com/llvm/llvm-project/commit/b95646fe7058471cc0ecda1efa25003009af0317.diff

LOG: Revert "Use-after-return sanitizer binary metadata"

This reverts commit d3c851d3fc8b69dda70bf5f999c5b39dc314dd73.

Some bots broke:

- https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8796062278266465473/overview
- https://lab.llvm.org/buildbot/#/builders/124/builds/5759/steps/7/logs/stdio

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
    llvm/test/CodeGen/AArch64/O0-pipeline.ll
    llvm/test/CodeGen/AArch64/O3-pipeline.ll
    llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
    llvm/test/CodeGen/ARM/O3-pipeline.ll
    llvm/test/CodeGen/M68k/pipeline.ll
    llvm/test/CodeGen/PowerPC/O3-pipeline.ll
    llvm/test/CodeGen/RISCV/O0-pipeline.ll
    llvm/test/CodeGen/RISCV/O3-pipeline.ll
    llvm/test/CodeGen/X86/O0-pipeline.ll
    llvm/test/CodeGen/X86/opt-pipeline.ll

Removed: 
    clang/test/Instrumentation/SanitizerBinaryMetadata/common.h
    clang/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp
    clang/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp
    llvm/lib/CodeGen/SanitizerBinaryMetadata.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/clang/test/Instrumentation/SanitizerBinaryMetadata/common.h b/clang/test/Instrumentation/SanitizerBinaryMetadata/common.h
deleted file mode 100644
index 71e7f2bcf0259..0000000000000
--- a/clang/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/clang/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp b/clang/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp
deleted file mode 100644
index ff296b09688d6..0000000000000
--- a/clang/test/Instrumentation/SanitizerBinaryMetadata/covered.cpp
+++ /dev/null
@@ -1,79 +0,0 @@
-// REQUIRES: native && x86_64-linux
-// RUN: %clangxx %s -o %t && %t | FileCheck %s
-// RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=covered && %t | FileCheck -check-prefix=CHECK-C %s
-// RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=atomics && %t | FileCheck -check-prefix=CHECK-A %s
-// RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=uar && %t | FileCheck -check-prefix=CHECK-U %s
-// RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=covered,atomics && %t | FileCheck -check-prefix=CHECK-CA %s
-// RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=covered,uar && %t | FileCheck -check-prefix=CHECK-CU %s
-// RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=atomics,uar && %t | FileCheck -check-prefix=CHECK-AU %s
-// RUN: %clangxx %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/clang/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp b/clang/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp
deleted file mode 100644
index b95e99737b93c..0000000000000
--- a/clang/test/Instrumentation/SanitizerBinaryMetadata/uar.cpp
+++ /dev/null
@@ -1,60 +0,0 @@
-// We run the compiled binary + sizes of stack arguments depend on the arch
-// + binary metadata is currently emited only for ELF binaries.
-// REQUIRES: native && x86_64-linux
-// RUN: %clangxx %s -o %t -fexperimental-sanitize-metadata=covered,uar && %t | 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"

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 f9e608fe0f107..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.getNumOperands() == 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.
-  F.setMetadata(LLVMContext::MD_pcsections,
-                MDB.createPCSections(
-                    {{Section.getString(), {Features, IRB.getInt32(Size)}}}));
-  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/CodeGen/AArch64/O0-pipeline.ll b/llvm/test/CodeGen/AArch64/O0-pipeline.ll
index 72792cd1ffc5c..64661fc2f1c6a 100644
--- a/llvm/test/CodeGen/AArch64/O0-pipeline.ll
+++ b/llvm/test/CodeGen/AArch64/O0-pipeline.ll
@@ -70,7 +70,6 @@
 ; CHECK-NEXT:       Contiguously Lay Out Funclets
 ; CHECK-NEXT:       StackMap Liveness Analysis
 ; CHECK-NEXT:       Live DEBUG_VALUE analysis
-; CHECK-NEXT:       Machine Sanitizer Binary Metadata
 ; CHECK-NEXT:       Insert CFI remember/restore state instructions
 ; CHECK-NEXT:       Unpack machine instruction bundles
 ; CHECK-NEXT:       Lazy Machine Block Frequency Analysis

diff  --git a/llvm/test/CodeGen/AArch64/O3-pipeline.ll b/llvm/test/CodeGen/AArch64/O3-pipeline.ll
index c5bb30e00eaee..c792f8ed18f93 100644
--- a/llvm/test/CodeGen/AArch64/O3-pipeline.ll
+++ b/llvm/test/CodeGen/AArch64/O3-pipeline.ll
@@ -214,7 +214,6 @@
 ; CHECK-NEXT:       Contiguously Lay Out Funclets
 ; CHECK-NEXT:       StackMap Liveness Analysis
 ; CHECK-NEXT:       Live DEBUG_VALUE analysis
-; CHECK-NEXT:       Machine Sanitizer Binary Metadata
 ; CHECK-NEXT:     Machine Outliner
 ; CHECK-NEXT:     FunctionPass Manager
 ; CHECK-NEXT:       Insert CFI remember/restore state instructions

diff  --git a/llvm/test/CodeGen/AMDGPU/llc-pipeline.ll b/llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
index 324d62d6fa665..9055e5c9ba799 100644
--- a/llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
+++ b/llvm/test/CodeGen/AMDGPU/llc-pipeline.ll
@@ -139,7 +139,6 @@
 ; GCN-O0-NEXT:        Branch relaxation pass
 ; GCN-O0-NEXT:        Register Usage Information Collector Pass
 ; GCN-O0-NEXT:        Live DEBUG_VALUE analysis
-; GCN-O0-NEXT:        Machine Sanitizer Binary Metadata
 ; GCN-O0-NEXT:    Function register usage analysis
 ; GCN-O0-NEXT:    FunctionPass Manager
 ; GCN-O0-NEXT:      Lazy Machine Block Frequency Analysis
@@ -403,7 +402,6 @@
 ; GCN-O1-NEXT:        Branch relaxation pass
 ; GCN-O1-NEXT:        Register Usage Information Collector Pass
 ; GCN-O1-NEXT:        Live DEBUG_VALUE analysis
-; GCN-O1-NEXT:        Machine Sanitizer Binary Metadata
 ; GCN-O1-NEXT:    Function register usage analysis
 ; GCN-O1-NEXT:    FunctionPass Manager
 ; GCN-O1-NEXT:      Lazy Machine Block Frequency Analysis
@@ -699,7 +697,6 @@
 ; GCN-O1-OPTS-NEXT:        Branch relaxation pass
 ; GCN-O1-OPTS-NEXT:        Register Usage Information Collector Pass
 ; GCN-O1-OPTS-NEXT:        Live DEBUG_VALUE analysis
-; GCN-O1-OPTS-NEXT:        Machine Sanitizer Binary Metadata
 ; GCN-O1-OPTS-NEXT:    Function register usage analysis
 ; GCN-O1-OPTS-NEXT:    FunctionPass Manager
 ; GCN-O1-OPTS-NEXT:      Lazy Machine Block Frequency Analysis
@@ -998,7 +995,6 @@
 ; GCN-O2-NEXT:        Branch relaxation pass
 ; GCN-O2-NEXT:        Register Usage Information Collector Pass
 ; GCN-O2-NEXT:        Live DEBUG_VALUE analysis
-; GCN-O2-NEXT:        Machine Sanitizer Binary Metadata
 ; GCN-O2-NEXT:    Function register usage analysis
 ; GCN-O2-NEXT:    FunctionPass Manager
 ; GCN-O2-NEXT:      Lazy Machine Block Frequency Analysis
@@ -1309,7 +1305,6 @@
 ; GCN-O3-NEXT:        Branch relaxation pass
 ; GCN-O3-NEXT:        Register Usage Information Collector Pass
 ; GCN-O3-NEXT:        Live DEBUG_VALUE analysis
-; GCN-O3-NEXT:        Machine Sanitizer Binary Metadata
 ; GCN-O3-NEXT:    Function register usage analysis
 ; GCN-O3-NEXT:    FunctionPass Manager
 ; GCN-O3-NEXT:      Lazy Machine Block Frequency Analysis

diff  --git a/llvm/test/CodeGen/ARM/O3-pipeline.ll b/llvm/test/CodeGen/ARM/O3-pipeline.ll
index 0c1f7f783e215..1f2e962579e7f 100644
--- a/llvm/test/CodeGen/ARM/O3-pipeline.ll
+++ b/llvm/test/CodeGen/ARM/O3-pipeline.ll
@@ -189,7 +189,6 @@
 ; CHECK-NEXT:      Contiguously Lay Out Funclets
 ; CHECK-NEXT:      StackMap Liveness Analysis
 ; CHECK-NEXT:      Live DEBUG_VALUE analysis
-; CHECK-NEXT:      Machine Sanitizer Binary Metadata
 ; CHECK-NEXT:    Machine Outliner
 ; CHECK-NEXT:    FunctionPass Manager
 ; CHECK-NEXT:      ReachingDefAnalysis

diff  --git a/llvm/test/CodeGen/M68k/pipeline.ll b/llvm/test/CodeGen/M68k/pipeline.ll
index 088def7edcf4a..c2ca336442153 100644
--- a/llvm/test/CodeGen/M68k/pipeline.ll
+++ b/llvm/test/CodeGen/M68k/pipeline.ll
@@ -129,7 +129,6 @@
 ; CHECK-NEXT:      Contiguously Lay Out Funclets
 ; CHECK-NEXT:      StackMap Liveness Analysis
 ; CHECK-NEXT:      Live DEBUG_VALUE analysis
-; CHECK-NEXT:      Machine Sanitizer Binary Metadata
 ; CHECK-NEXT:      Lazy Machine Block Frequency Analysis
 ; CHECK-NEXT:      Machine Optimization Remark Emitter
 ; CHECK-NEXT:      M68k Assembly Printer

diff  --git a/llvm/test/CodeGen/PowerPC/O3-pipeline.ll b/llvm/test/CodeGen/PowerPC/O3-pipeline.ll
index 172c379a0e240..d331aa305e205 100644
--- a/llvm/test/CodeGen/PowerPC/O3-pipeline.ll
+++ b/llvm/test/CodeGen/PowerPC/O3-pipeline.ll
@@ -206,7 +206,6 @@
 ; CHECK-NEXT:       Contiguously Lay Out Funclets
 ; CHECK-NEXT:       StackMap Liveness Analysis
 ; CHECK-NEXT:       Live DEBUG_VALUE analysis
-; CHECK-NEXT:       Machine Sanitizer Binary Metadata
 ; CHECK-NEXT:       PowerPC Expand Atomic
 ; CHECK-NEXT:       PowerPC Branch Selector
 ; CHECK-NEXT:       Lazy Machine Block Frequency Analysis

diff  --git a/llvm/test/CodeGen/RISCV/O0-pipeline.ll b/llvm/test/CodeGen/RISCV/O0-pipeline.ll
index 6226bc292ed1a..b6568582962a4 100644
--- a/llvm/test/CodeGen/RISCV/O0-pipeline.ll
+++ b/llvm/test/CodeGen/RISCV/O0-pipeline.ll
@@ -56,7 +56,6 @@
 ; CHECK-NEXT:       Contiguously Lay Out Funclets
 ; CHECK-NEXT:       StackMap Liveness Analysis
 ; CHECK-NEXT:       Live DEBUG_VALUE analysis
-; CHECK-NEXT:       Machine Sanitizer Binary Metadata
 ; CHECK-NEXT:       RISCV pseudo instruction expansion pass
 ; CHECK-NEXT:       RISCV atomic pseudo instruction expansion pass
 ; CHECK-NEXT:       Lazy Machine Block Frequency Analysis

diff  --git a/llvm/test/CodeGen/RISCV/O3-pipeline.ll b/llvm/test/CodeGen/RISCV/O3-pipeline.ll
index 8865ee80da32b..2ff7dee26ef7c 100644
--- a/llvm/test/CodeGen/RISCV/O3-pipeline.ll
+++ b/llvm/test/CodeGen/RISCV/O3-pipeline.ll
@@ -163,7 +163,6 @@
 ; CHECK-NEXT:       Contiguously Lay Out Funclets
 ; CHECK-NEXT:       StackMap Liveness Analysis
 ; CHECK-NEXT:       Live DEBUG_VALUE analysis
-; CHECK-NEXT:       Machine Sanitizer Binary Metadata
 ; CHECK-NEXT:     Machine Outliner
 ; CHECK-NEXT:     FunctionPass Manager
 ; CHECK-NEXT:       RISCV pseudo instruction expansion pass

diff  --git a/llvm/test/CodeGen/X86/O0-pipeline.ll b/llvm/test/CodeGen/X86/O0-pipeline.ll
index 6f1301af796db..d762a5212fd2c 100644
--- a/llvm/test/CodeGen/X86/O0-pipeline.ll
+++ b/llvm/test/CodeGen/X86/O0-pipeline.ll
@@ -71,7 +71,6 @@
 ; CHECK-NEXT:       Contiguously Lay Out Funclets
 ; CHECK-NEXT:       StackMap Liveness Analysis
 ; CHECK-NEXT:       Live DEBUG_VALUE analysis
-; CHECK-NEXT:       Machine Sanitizer Binary Metadata
 ; CHECK-NEXT:       X86 Speculative Execution Side Effect Suppression
 ; CHECK-NEXT:       X86 Indirect Thunks
 ; CHECK-NEXT:       X86 Return Thunks

diff  --git a/llvm/test/CodeGen/X86/opt-pipeline.ll b/llvm/test/CodeGen/X86/opt-pipeline.ll
index d0cd4b945fbc8..b4db563bd5660 100644
--- a/llvm/test/CodeGen/X86/opt-pipeline.ll
+++ b/llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -205,7 +205,6 @@
 ; CHECK-NEXT:       Contiguously Lay Out Funclets
 ; CHECK-NEXT:       StackMap Liveness Analysis
 ; CHECK-NEXT:       Live DEBUG_VALUE analysis
-; CHECK-NEXT:       Machine Sanitizer Binary Metadata
 ; CHECK-NEXT:       X86 Speculative Execution Side Effect Suppression
 ; CHECK-NEXT:       X86 Indirect Thunks
 ; CHECK-NEXT:       X86 Return Thunks


        


More information about the cfe-commits mailing list